summaryrefslogtreecommitdiffabout
path: root/microkde/kresources/manager.h
authorMichael Krelin <hacker@klever.net>2007-07-04 11:23:42 (UTC)
committer Michael Krelin <hacker@klever.net>2007-07-04 11:23:42 (UTC)
commita08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (unidiff)
tree8ee90d686081c52e7c69b5ce946e9b1a7d690001 /microkde/kresources/manager.h
parent11edc920afe4f274c0964436633aa632c8288a40 (diff)
downloadkdepimpi-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.h8
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,84 +1,86 @@
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/*
26Enhanced Version of the file for platform independent KDE tools. 26Enhanced Version of the file for platform independent KDE tools.
27Copyright (c) 2004 Ulf Schenk 27Copyright (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
41namespace KRES { 43namespace KRES {
42 44
43class Resource; 45class Resource;
44 46
45template<class T> 47template<class T>
46class ManagerListener 48class 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
63template<class T> 65template<class T>
64class Manager : private ManagerImplListener 66class 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 };
@@ -130,97 +132,97 @@ class Manager : private ManagerImplListener
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 {
@@ -285,54 +287,54 @@ class Manager : private ManagerImplListener
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