1 | /* This file is part of the KDE project |
2 | Copyright (C) 2001 Carsten Pfeiffer <pfeiffer@kde.org> |
3 | |
4 | This library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Library General Public |
6 | License as published by the Free Software Foundation; either |
7 | version 2 of the License, or (at your option) any later version. |
8 | |
9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Library General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to |
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 | Boston, MA 02110-1301, USA. |
18 | */ |
19 | |
20 | #include "historyprovider.h" |
21 | |
22 | #include <QtCore/QSet> |
23 | |
24 | #include <kapplication.h> |
25 | |
26 | using namespace KParts; |
27 | |
28 | class KParts::HistoryProviderPrivate |
29 | { |
30 | public: |
31 | HistoryProviderPrivate() |
32 | : q(0) |
33 | { |
34 | } |
35 | |
36 | ~HistoryProviderPrivate() |
37 | { |
38 | delete q; |
39 | } |
40 | |
41 | QSet<QString> dict; |
42 | HistoryProvider *q; |
43 | }; |
44 | |
45 | K_GLOBAL_STATIC(HistoryProviderPrivate, historyProviderPrivate) |
46 | |
47 | HistoryProvider * HistoryProvider::self() |
48 | { |
49 | if (!historyProviderPrivate->q) { |
50 | new HistoryProvider; |
51 | } |
52 | |
53 | return historyProviderPrivate->q; |
54 | } |
55 | |
56 | bool HistoryProvider::exists() |
57 | { |
58 | return historyProviderPrivate->q; |
59 | } |
60 | |
61 | HistoryProvider::HistoryProvider( QObject *parent ) |
62 | : QObject( parent ), d(historyProviderPrivate) |
63 | { |
64 | Q_ASSERT(!historyProviderPrivate->q); |
65 | historyProviderPrivate->q = this; |
66 | setObjectName("history provider" ); |
67 | } |
68 | |
69 | HistoryProvider::~HistoryProvider() |
70 | { |
71 | if (!historyProviderPrivate.isDestroyed() && |
72 | historyProviderPrivate->q == this) |
73 | historyProviderPrivate->q = 0; |
74 | } |
75 | |
76 | bool HistoryProvider::contains( const QString& item ) const |
77 | { |
78 | return d->dict.contains( item ); |
79 | } |
80 | |
81 | void HistoryProvider::insert( const QString& item ) |
82 | { |
83 | d->dict.insert( item ); |
84 | emit inserted( item ); |
85 | } |
86 | |
87 | void HistoryProvider::remove( const QString& item ) |
88 | { |
89 | d->dict.remove( item ); |
90 | } |
91 | |
92 | void HistoryProvider::clear() |
93 | { |
94 | d->dict.clear(); |
95 | emit cleared(); |
96 | } |
97 | |
98 | #include "historyprovider.moc" |
99 | |