author | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
commit | a08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (unidiff) | |
tree | 8ee90d686081c52e7c69b5ce946e9b1a7d690001 /microkde/kresources/manager.h | |
parent | 11edc920afe4f274c0964436633aa632c8288a40 (diff) | |
download | kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.zip kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.gz kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.bz2 |
initial public commit of qt4 portp1
Diffstat (limited to 'microkde/kresources/manager.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | microkde/kresources/manager.h | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/microkde/kresources/manager.h b/microkde/kresources/manager.h index 69062da..88705d4 100644 --- a/microkde/kresources/manager.h +++ b/microkde/kresources/manager.h | |||
@@ -1,338 +1,340 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkresources. | 2 | This file is part of libkresources. |
3 | 3 | ||
4 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | 4 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> |
5 | Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org> | 5 | Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org> |
6 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> | 6 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> |
7 | Copyright (c) 2004 Ulf Schenk | 7 | Copyright (c) 2004 Ulf Schenk |
8 | 8 | ||
9 | This library is free software; you can redistribute it and/or | 9 | This library is free software; you can redistribute it and/or |
10 | modify it under the terms of the GNU Library General Public | 10 | modify it under the terms of the GNU Library General Public |
11 | License as published by the Free Software Foundation; either | 11 | License as published by the Free Software Foundation; either |
12 | version 2 of the License, or (at your option) any later version. | 12 | version 2 of the License, or (at your option) any later version. |
13 | 13 | ||
14 | This library is distributed in the hope that it will be useful, | 14 | This library is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 | Library General Public License for more details. | 17 | Library General Public License for more details. |
18 | 18 | ||
19 | You should have received a copy of the GNU Library General Public License | 19 | You should have received a copy of the GNU Library General Public License |
20 | along with this library; see the file COPYING.LIB. If not, write to | 20 | along with this library; see the file COPYING.LIB. If not, write to |
21 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 21 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
22 | Boston, MA 02111-1307, USA. | 22 | Boston, MA 02111-1307, USA. |
23 | */ | 23 | */ |
24 | 24 | ||
25 | /* | 25 | /* |
26 | Enhanced Version of the file for platform independent KDE tools. | 26 | Enhanced Version of the file for platform independent KDE tools. |
27 | Copyright (c) 2004 Ulf Schenk | 27 | Copyright (c) 2004 Ulf Schenk |
28 | 28 | ||
29 | $Id$ | 29 | $Id$ |
30 | */ | 30 | */ |
31 | 31 | ||
32 | #ifndef KRESOURCES_MANAGER_H | 32 | #ifndef KRESOURCES_MANAGER_H |
33 | #define KRESOURCES_MANAGER_H | 33 | #define KRESOURCES_MANAGER_H |
34 | 34 | ||
35 | #include <qdict.h> | 35 | #include <q3dict.h> |
36 | #include <qstringlist.h> | 36 | #include <qstringlist.h> |
37 | //Added by qt3to4: | ||
38 | #include <Q3PtrList> | ||
37 | 39 | ||
38 | #include "factory.h" | 40 | #include "factory.h" |
39 | #include "managerimpl.h" | 41 | #include "managerimpl.h" |
40 | 42 | ||
41 | namespace KRES { | 43 | namespace KRES { |
42 | 44 | ||
43 | class Resource; | 45 | class Resource; |
44 | 46 | ||
45 | template<class T> | 47 | template<class T> |
46 | class ManagerListener | 48 | class ManagerListener |
47 | { | 49 | { |
48 | public: | 50 | public: |
49 | virtual void resourceAdded( T *resource ) = 0; | 51 | virtual void resourceAdded( T *resource ) = 0; |
50 | virtual void resourceModified( T *resource ) = 0; | 52 | virtual void resourceModified( T *resource ) = 0; |
51 | virtual void resourceDeleted( T *resource ) = 0; | 53 | virtual void resourceDeleted( T *resource ) = 0; |
52 | }; | 54 | }; |
53 | 55 | ||
54 | // TODO: | 56 | // TODO: |
55 | // The resource manager should provide some signals | 57 | // The resource manager should provide some signals |
56 | // to warn applications that resources have been added, | 58 | // to warn applications that resources have been added, |
57 | // removed or modified. | 59 | // removed or modified. |
58 | // | 60 | // |
59 | // The manager should also keep track of which (or at least | 61 | // The manager should also keep track of which (or at least |
60 | // how many) applications hve opened a resource, so that it | 62 | // how many) applications hve opened a resource, so that it |
61 | // is only closed if none of them is using it any more | 63 | // is only closed if none of them is using it any more |
62 | 64 | ||
63 | template<class T> | 65 | template<class T> |
64 | class Manager : private ManagerImplListener | 66 | class Manager : private ManagerImplListener |
65 | { | 67 | { |
66 | public: | 68 | public: |
67 | class Iterator | 69 | class Iterator |
68 | { | 70 | { |
69 | friend class Manager; | 71 | friend class Manager; |
70 | public: | 72 | public: |
71 | Iterator() {}; | 73 | Iterator() {}; |
72 | Iterator( const Iterator &it ) { mIt = it.mIt; } | 74 | Iterator( const Iterator &it ) { mIt = it.mIt; } |
73 | 75 | ||
74 | T *operator*() { return static_cast<T *>( *mIt ); } | 76 | T *operator*() { return static_cast<T *>( *mIt ); } |
75 | Iterator &operator++() { mIt++; return *this; } | 77 | Iterator &operator++() { mIt++; return *this; } |
76 | Iterator &operator++(int) { mIt++; return *this; } | 78 | Iterator &operator++(int) { mIt++; return *this; } |
77 | Iterator &operator--() { mIt--; return *this; } | 79 | Iterator &operator--() { mIt--; return *this; } |
78 | Iterator &operator--(int) { mIt--; return *this; } | 80 | Iterator &operator--(int) { mIt--; return *this; } |
79 | bool operator==( const Iterator &it ) { return mIt == it.mIt; } | 81 | bool operator==( const Iterator &it ) { return mIt == it.mIt; } |
80 | bool operator!=( const Iterator &it ) { return mIt != it.mIt; } | 82 | bool operator!=( const Iterator &it ) { return mIt != it.mIt; } |
81 | 83 | ||
82 | private: | 84 | private: |
83 | Resource::List::Iterator mIt; | 85 | Resource::List::Iterator mIt; |
84 | }; | 86 | }; |
85 | 87 | ||
86 | Iterator begin() | 88 | Iterator begin() |
87 | { | 89 | { |
88 | Iterator it; | 90 | Iterator it; |
89 | it.mIt = mImpl->resourceList()->begin(); | 91 | it.mIt = mImpl->resourceList()->begin(); |
90 | return it; | 92 | return it; |
91 | } | 93 | } |
92 | 94 | ||
93 | Iterator end() | 95 | Iterator end() |
94 | { | 96 | { |
95 | Iterator it; | 97 | Iterator it; |
96 | it.mIt = mImpl->resourceList()->end(); | 98 | it.mIt = mImpl->resourceList()->end(); |
97 | return it; | 99 | return it; |
98 | } | 100 | } |
99 | 101 | ||
100 | class ActiveIterator | 102 | class ActiveIterator |
101 | { | 103 | { |
102 | friend class Manager; | 104 | friend class Manager; |
103 | public: | 105 | public: |
104 | ActiveIterator() : mList( 0 ) {}; | 106 | ActiveIterator() : mList( 0 ) {}; |
105 | ActiveIterator( const ActiveIterator &it ) | 107 | ActiveIterator( const ActiveIterator &it ) |
106 | { | 108 | { |
107 | mIt = it.mIt; | 109 | mIt = it.mIt; |
108 | mList = it.mList; | 110 | mList = it.mList; |
109 | } | 111 | } |
110 | 112 | ||
111 | T *operator*() { return static_cast<T *>( *mIt ); } | 113 | T *operator*() { return static_cast<T *>( *mIt ); } |
112 | ActiveIterator &operator++() | 114 | ActiveIterator &operator++() |
113 | { | 115 | { |
114 | do { mIt++; } while ( checkActive() ); | 116 | do { mIt++; } while ( checkActive() ); |
115 | return *this; | 117 | return *this; |
116 | } | 118 | } |
117 | ActiveIterator &operator++(int) | 119 | ActiveIterator &operator++(int) |
118 | { | 120 | { |
119 | do { mIt++; } while ( checkActive() ); | 121 | do { mIt++; } while ( checkActive() ); |
120 | return *this; | 122 | return *this; |
121 | } | 123 | } |
122 | ActiveIterator &operator--() | 124 | ActiveIterator &operator--() |
123 | { | 125 | { |
124 | do { mIt--; } while ( checkActive() ); | 126 | do { mIt--; } while ( checkActive() ); |
125 | return *this; | 127 | return *this; |
126 | } | 128 | } |
127 | ActiveIterator &operator--(int) | 129 | ActiveIterator &operator--(int) |
128 | { | 130 | { |
129 | do { mIt--; } while ( checkActive() ); | 131 | do { mIt--; } while ( checkActive() ); |
130 | return *this; | 132 | return *this; |
131 | } | 133 | } |
132 | bool operator==( const ActiveIterator &it ) { return mIt == it.mIt; } | 134 | bool operator==( const ActiveIterator &it ) { return mIt == it.mIt; } |
133 | bool operator!=( const ActiveIterator &it ) { return mIt != it.mIt; } | 135 | bool operator!=( const ActiveIterator &it ) { return mIt != it.mIt; } |
134 | 136 | ||
135 | private: | 137 | private: |
136 | /** | 138 | /** |
137 | Check if iterator needs to be advanced once more. | 139 | Check if iterator needs to be advanced once more. |
138 | */ | 140 | */ |
139 | bool checkActive() | 141 | bool checkActive() |
140 | { | 142 | { |
141 | if ( !mList || mIt == mList->end() ) return false; | 143 | if ( !mList || mIt == mList->end() ) return false; |
142 | return !(*mIt)->isActive(); | 144 | return !(*mIt)->isActive(); |
143 | } | 145 | } |
144 | 146 | ||
145 | Resource::List::Iterator mIt; | 147 | Resource::List::Iterator mIt; |
146 | Resource::List *mList; | 148 | Resource::List *mList; |
147 | }; | 149 | }; |
148 | 150 | ||
149 | ActiveIterator activeBegin() | 151 | ActiveIterator activeBegin() |
150 | { | 152 | { |
151 | ActiveIterator it; | 153 | ActiveIterator it; |
152 | it.mIt = mImpl->resourceList()->begin(); | 154 | it.mIt = mImpl->resourceList()->begin(); |
153 | it.mList = mImpl->resourceList(); | 155 | it.mList = mImpl->resourceList(); |
154 | if ( it.mIt != mImpl->resourceList()->end() ) { | 156 | if ( it.mIt != mImpl->resourceList()->end() ) { |
155 | if ( !(*it)->isActive() ) it++; | 157 | if ( !(*it)->isActive() ) it++; |
156 | } | 158 | } |
157 | return it; | 159 | return it; |
158 | } | 160 | } |
159 | 161 | ||
160 | ActiveIterator activeEnd() | 162 | ActiveIterator activeEnd() |
161 | { | 163 | { |
162 | ActiveIterator it; | 164 | ActiveIterator it; |
163 | it.mIt = mImpl->resourceList()->end(); | 165 | it.mIt = mImpl->resourceList()->end(); |
164 | it.mList = mImpl->resourceList(); | 166 | it.mList = mImpl->resourceList(); |
165 | return it; | 167 | return it; |
166 | } | 168 | } |
167 | 169 | ||
168 | bool isEmpty() const { return mImpl->resourceList()->isEmpty(); } | 170 | bool isEmpty() const { return mImpl->resourceList()->isEmpty(); } |
169 | 171 | ||
170 | Manager( const QString &family ) | 172 | Manager( const QString &family ) |
171 | { | 173 | { |
172 | mFactory = Factory::self( family ); | 174 | mFactory = Factory::self( family ); |
173 | // The managerimpl will use the same Factory object as the manager | 175 | // The managerimpl will use the same Factory object as the manager |
174 | // because of the Factory::self() pattern | 176 | // because of the Factory::self() pattern |
175 | mImpl = new ManagerImpl( family ); | 177 | mImpl = new ManagerImpl( family ); |
176 | mImpl->setListener( this ); | 178 | mImpl->setListener( this ); |
177 | 179 | ||
178 | mListeners = new QPtrList<ManagerListener<T> >; | 180 | mListeners = new Q3PtrList<ManagerListener<T> >; |
179 | } | 181 | } |
180 | 182 | ||
181 | virtual ~Manager() | 183 | virtual ~Manager() |
182 | { | 184 | { |
183 | mImpl->setListener( 0 ); | 185 | mImpl->setListener( 0 ); |
184 | delete mListeners; | 186 | delete mListeners; |
185 | delete mImpl; | 187 | delete mImpl; |
186 | } | 188 | } |
187 | 189 | ||
188 | /** | 190 | /** |
189 | Recreate Resource objects from configuration file. If cfg is 0, read standard | 191 | Recreate Resource objects from configuration file. If cfg is 0, read standard |
190 | configuration file. | 192 | configuration file. |
191 | */ | 193 | */ |
192 | void readConfig( KConfig *cfg = 0 ) | 194 | void readConfig( KConfig *cfg = 0 ) |
193 | { | 195 | { |
194 | mImpl->readConfig( cfg ); | 196 | mImpl->readConfig( cfg ); |
195 | } | 197 | } |
196 | 198 | ||
197 | /** | 199 | /** |
198 | Write configuration of Resource objects to configuration file. If cfg is 0, write | 200 | Write configuration of Resource objects to configuration file. If cfg is 0, write |
199 | to standard configuration file. | 201 | to standard configuration file. |
200 | */ | 202 | */ |
201 | void writeConfig( KConfig *cfg = 0 ) | 203 | void writeConfig( KConfig *cfg = 0 ) |
202 | { | 204 | { |
203 | mImpl->writeConfig( cfg ); | 205 | mImpl->writeConfig( cfg ); |
204 | } | 206 | } |
205 | 207 | ||
206 | /** | 208 | /** |
207 | Add resource to manager. This passes ownership of the Resource object | 209 | Add resource to manager. This passes ownership of the Resource object |
208 | to the manager. | 210 | to the manager. |
209 | */ | 211 | */ |
210 | void add( Resource *resource ) | 212 | void add( Resource *resource ) |
211 | { | 213 | { |
212 | if ( resource ) mImpl->add( resource ); | 214 | if ( resource ) mImpl->add( resource ); |
213 | } | 215 | } |
214 | 216 | ||
215 | void remove( Resource *resource ) | 217 | void remove( Resource *resource ) |
216 | { | 218 | { |
217 | if ( resource ) mImpl->remove( resource ); | 219 | if ( resource ) mImpl->remove( resource ); |
218 | } | 220 | } |
219 | 221 | ||
220 | T* standardResource() | 222 | T* standardResource() |
221 | { | 223 | { |
222 | return static_cast<T *>( mImpl->standardResource() ); | 224 | return static_cast<T *>( mImpl->standardResource() ); |
223 | } | 225 | } |
224 | 226 | ||
225 | void setStandardResource( T *resource ) | 227 | void setStandardResource( T *resource ) |
226 | { | 228 | { |
227 | if ( resource ) mImpl->setStandardResource( resource ); | 229 | if ( resource ) mImpl->setStandardResource( resource ); |
228 | } | 230 | } |
229 | 231 | ||
230 | void setActive( Resource *resource, bool active ) | 232 | void setActive( Resource *resource, bool active ) |
231 | { | 233 | { |
232 | if ( resource ) mImpl->setActive( resource, active ); | 234 | if ( resource ) mImpl->setActive( resource, active ); |
233 | } | 235 | } |
234 | 236 | ||
235 | /** | 237 | /** |
236 | Returns a list of the names of the reources managed by the | 238 | Returns a list of the names of the reources managed by the |
237 | Manager for this family. | 239 | Manager for this family. |
238 | */ | 240 | */ |
239 | QStringList resourceNames() const | 241 | QStringList resourceNames() const |
240 | { | 242 | { |
241 | return mImpl->resourceNames(); | 243 | return mImpl->resourceNames(); |
242 | } | 244 | } |
243 | 245 | ||
244 | ConfigWidget *configWidget( const QString& type, QWidget *parent = 0 ) | 246 | ConfigWidget *configWidget( const QString& type, QWidget *parent = 0 ) |
245 | { | 247 | { |
246 | return mFactory->configWidget( type, parent ); | 248 | return mFactory->configWidget( type, parent ); |
247 | } | 249 | } |
248 | 250 | ||
249 | /** | 251 | /** |
250 | Creates a new resource of type @param type, with default | 252 | Creates a new resource of type @param type, with default |
251 | settings. The resource is | 253 | settings. The resource is |
252 | not added to the manager, the application has to do that. | 254 | not added to the manager, the application has to do that. |
253 | Returns a pointer to a resource object or a null pointer | 255 | Returns a pointer to a resource object or a null pointer |
254 | if resource type doesn't exist. | 256 | if resource type doesn't exist. |
255 | 257 | ||
256 | @param type The type of the resource, one of those returned | 258 | @param type The type of the resource, one of those returned |
257 | by @ref resourceTypeNames() | 259 | by @ref resourceTypeNames() |
258 | */ | 260 | */ |
259 | T *createResource( const QString& type ) | 261 | T *createResource( const QString& type ) |
260 | { | 262 | { |
261 | return (T *)( mFactory->resource( type, 0 ) ); | 263 | return (T *)( mFactory->resource( type, 0 ) ); |
262 | } | 264 | } |
263 | 265 | ||
264 | /** | 266 | /** |
265 | Returns a list of the names of all available resource types. | 267 | Returns a list of the names of all available resource types. |
266 | */ | 268 | */ |
267 | QStringList resourceTypeNames() const | 269 | QStringList resourceTypeNames() const |
268 | { | 270 | { |
269 | return mFactory->typeNames(); | 271 | return mFactory->typeNames(); |
270 | } | 272 | } |
271 | 273 | ||
272 | QStringList resourceTypeDescriptions() const | 274 | QStringList resourceTypeDescriptions() const |
273 | { | 275 | { |
274 | QStringList typeDescs; | 276 | QStringList typeDescs; |
275 | QStringList types = mFactory->typeNames(); | 277 | QStringList types = mFactory->typeNames(); |
276 | 278 | ||
277 | for ( QStringList::ConstIterator it = types.begin(); it != types.end(); ++it ) { | 279 | for ( QStringList::ConstIterator it = types.begin(); it != types.end(); ++it ) { |
278 | QString desc = mFactory->typeName( *it ); | 280 | QString desc = mFactory->typeName( *it ); |
279 | if ( !mFactory->typeDescription( *it ).isEmpty() ) | 281 | if ( !mFactory->typeDescription( *it ).isEmpty() ) |
280 | desc += " (" + mFactory->typeDescription( *it ) + ")"; | 282 | desc += " (" + mFactory->typeDescription( *it ) + ")"; |
281 | 283 | ||
282 | typeDescs.append( desc ); | 284 | typeDescs.append( desc ); |
283 | } | 285 | } |
284 | 286 | ||
285 | return typeDescs; | 287 | return typeDescs; |
286 | } | 288 | } |
287 | 289 | ||
288 | void resourceChanged( T *resource ) | 290 | void resourceChanged( T *resource ) |
289 | { | 291 | { |
290 | mImpl->resourceChanged( resource ); | 292 | mImpl->resourceChanged( resource ); |
291 | } | 293 | } |
292 | 294 | ||
293 | void addListener( ManagerListener<T> *listener ) | 295 | void addListener( ManagerListener<T> *listener ) |
294 | { | 296 | { |
295 | mListeners->append( listener ); | 297 | mListeners->append( listener ); |
296 | } | 298 | } |
297 | 299 | ||
298 | void removeListener( ManagerListener<T> *listener ) | 300 | void removeListener( ManagerListener<T> *listener ) |
299 | { | 301 | { |
300 | mListeners->remove( listener ); | 302 | mListeners->remove( listener ); |
301 | } | 303 | } |
302 | 304 | ||
303 | virtual void resourceAdded( Resource *res ) | 305 | virtual void resourceAdded( Resource *res ) |
304 | { | 306 | { |
305 | T* resource = (T *)( res ); | 307 | T* resource = (T *)( res ); |
306 | ManagerListener<T> *listener; | 308 | ManagerListener<T> *listener; |
307 | for ( listener = mListeners->first(); listener; listener = mListeners->next() ) | 309 | for ( listener = mListeners->first(); listener; listener = mListeners->next() ) |
308 | listener->resourceAdded( resource ); | 310 | listener->resourceAdded( resource ); |
309 | } | 311 | } |
310 | 312 | ||
311 | virtual void resourceModified( Resource *res ) | 313 | virtual void resourceModified( Resource *res ) |
312 | { | 314 | { |
313 | 315 | ||
314 | T* resource = (T *)( res ); | 316 | T* resource = (T *)( res ); |
315 | ManagerListener<T> *listener; | 317 | ManagerListener<T> *listener; |
316 | for ( listener = mListeners->first(); listener; listener = mListeners->next() ) | 318 | for ( listener = mListeners->first(); listener; listener = mListeners->next() ) |
317 | listener->resourceModified( resource ); | 319 | listener->resourceModified( resource ); |
318 | } | 320 | } |
319 | 321 | ||
320 | virtual void resourceDeleted( Resource *res ) | 322 | virtual void resourceDeleted( Resource *res ) |
321 | { | 323 | { |
322 | 324 | ||
323 | T* resource = (T *)( res ); | 325 | T* resource = (T *)( res ); |
324 | ManagerListener<T> *listener; | 326 | ManagerListener<T> *listener; |
325 | for ( listener = mListeners->first(); listener; listener = mListeners->next() ) { | 327 | for ( listener = mListeners->first(); listener; listener = mListeners->next() ) { |
326 | listener->resourceDeleted( resource ); | 328 | listener->resourceDeleted( resource ); |
327 | } | 329 | } |
328 | } | 330 | } |
329 | 331 | ||
330 | private: | 332 | private: |
331 | ManagerImpl *mImpl; | 333 | ManagerImpl *mImpl; |
332 | Factory *mFactory; | 334 | Factory *mFactory; |
333 | QPtrList<ManagerListener<T> > *mListeners; | 335 | Q3PtrList<ManagerListener<T> > *mListeners; |
334 | }; | 336 | }; |
335 | 337 | ||
336 | } | 338 | } |
337 | 339 | ||
338 | #endif | 340 | #endif |