summaryrefslogtreecommitdiffabout
path: root/microkde/kresources/manager.h
Unidiff
Diffstat (limited to 'microkde/kresources/manager.h') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kresources/manager.h44
1 files changed, 29 insertions, 15 deletions
diff --git a/microkde/kresources/manager.h b/microkde/kresources/manager.h
index b5e97fc..7e9e19a 100644
--- a/microkde/kresources/manager.h
+++ b/microkde/kresources/manager.h
@@ -1,12 +1,13 @@
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 8
8 This library is free software; you can redistribute it and/or 9 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public 10 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either 11 License as published by the Free Software Foundation; either
11 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.
12 13
@@ -18,12 +19,19 @@
18 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
19 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
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. 22 Boston, MA 02111-1307, USA.
22*/ 23*/
23 24
25/*
26Enhanced Version of the file for platform independent KDE tools.
27Copyright (c) 2004 Ulf Schenk
28
29$Id$
30*/
31
24#ifndef KRESOURCES_MANAGER_H 32#ifndef KRESOURCES_MANAGER_H
25#define KRESOURCES_MANAGER_H 33#define KRESOURCES_MANAGER_H
26 34
27#include <qdict.h> 35#include <qdict.h>
28#include <qstringlist.h> 36#include <qstringlist.h>
29 37
@@ -45,13 +53,13 @@ class ManagerListener
45 53
46// TODO: 54// TODO:
47// The resource manager should provide some signals 55// The resource manager should provide some signals
48// to warn applications that resources have been added, 56// to warn applications that resources have been added,
49// removed or modified. 57// removed or modified.
50// 58//
51// The manager should also keep track of which (or at least 59// The manager should also keep track of which (or at least
52// how many) applications hve opened a resource, so that it 60// how many) applications hve opened a resource, so that it
53// is only closed if none of them is using it any more 61// is only closed if none of them is using it any more
54 62
55template<class T> 63template<class T>
56class Manager : private ManagerImplListener 64class Manager : private ManagerImplListener
57{ 65{
@@ -68,23 +76,23 @@ class Manager : private ManagerImplListener
68 Iterator &operator++(int) { mIt++; return *this; } 76 Iterator &operator++(int) { mIt++; return *this; }
69 Iterator &operator--() { mIt--; return *this; } 77 Iterator &operator--() { mIt--; return *this; }
70 Iterator &operator--(int) { mIt--; return *this; } 78 Iterator &operator--(int) { mIt--; return *this; }
71 bool operator==( const Iterator &it ) { return mIt == it.mIt; } 79 bool operator==( const Iterator &it ) { return mIt == it.mIt; }
72 bool operator!=( const Iterator &it ) { return mIt != it.mIt; } 80 bool operator!=( const Iterator &it ) { return mIt != it.mIt; }
73 81
74 private: 82 private:
75 Resource::List::Iterator mIt; 83 Resource::List::Iterator mIt;
76 }; 84 };
77 85
78 Iterator begin() 86 Iterator begin()
79 { 87 {
80 Iterator it; 88 Iterator it;
81 it.mIt = mImpl->resourceList()->begin(); 89 it.mIt = mImpl->resourceList()->begin();
82 return it; 90 return it;
83 } 91 }
84 92
85 Iterator end() 93 Iterator end()
86 { 94 {
87 Iterator it; 95 Iterator it;
88 it.mIt = mImpl->resourceList()->end(); 96 it.mIt = mImpl->resourceList()->end();
89 return it; 97 return it;
90 } 98 }
@@ -156,25 +164,30 @@ class Manager : private ManagerImplListener
156 it.mList = mImpl->resourceList(); 164 it.mList = mImpl->resourceList();
157 return it; 165 return it;
158 } 166 }
159 167
160 bool isEmpty() const { return mImpl->resourceList()->isEmpty(); } 168 bool isEmpty() const { return mImpl->resourceList()->isEmpty(); }
161 169
162 Manager( const QString &family ) 170 /**
171 Return true, if the manager manages syncable resources.
172 */
173 bool manageSyncable() { return mImpl->manageSyncable(); }
174
175 Manager( const QString &family, bool syncable )
163 { 176 {
164 mFactory = Factory::self( family ); 177 mFactory = Factory::self( family );
165 // The managerimpl will use the same Factory object as the manager 178 // The managerimpl will use the same Factory object as the manager
166 // because of the Factory::self() pattern 179 // because of the Factory::self() pattern
167 mImpl = new ManagerImpl( family ); 180 mImpl = new ManagerImpl( family, syncable );
168 mImpl->setListener( this ); 181 mImpl->setListener( this );
169 182
170 mListeners = new QPtrList<ManagerListener<T> >; 183 mListeners = new QPtrList<ManagerListener<T> >;
171 } 184 }
172 185
173 virtual ~Manager() 186 virtual ~Manager()
174 { 187 {
175 mImpl->setListener( 0 ); 188 mImpl->setListener( 0 );
176 delete mListeners; 189 delete mListeners;
177 delete mImpl; 190 delete mImpl;
178 } 191 }
179 192
180 /** 193 /**
@@ -236,24 +249,25 @@ class Manager : private ManagerImplListener
236 ConfigWidget *configWidget( const QString& type, QWidget *parent = 0 ) 249 ConfigWidget *configWidget( const QString& type, QWidget *parent = 0 )
237 { 250 {
238 return mFactory->resourceConfigWidget( type, parent ); 251 return mFactory->resourceConfigWidget( type, parent );
239 } 252 }
240 253
241 /** 254 /**
242 Creates a new resource of type @param type, with default 255 Creates a new resource of type @param type, with default
243 settings. The resource is 256 settings. The resource is
244 not added to the manager, the application has to do that. 257 not added to the manager, the application has to do that.
245 Returns a pointer to a resource object or a null pointer 258 Returns a pointer to a resource object or a null pointer
246 if resource type doesn't exist. 259 if resource type doesn't exist.
247 260
248 @param type The type of the resource, one of those returned 261 @param type The type of the resource, one of those returned
249 by @ref resourceTypeNames() 262 by @ref resourceTypeNames()
263 * @param syncable If the resource should support syncing capabilities.
250 */ 264 */
251 T *createResource( const QString& type ) 265 T *createResource( const QString& type )
252 { 266 {
253 return (T *)( mFactory->resource( type, 0 ) ); 267 return (T *)( mFactory->resource( type, 0, mImpl->manageSyncable() ) );
254 } 268 }
255 269
256 /** 270 /**
257 Returns a list of the names of all available resource types. 271 Returns a list of the names of all available resource types.
258 */ 272 */
259 QStringList resourceTypeNames() const 273 QStringList resourceTypeNames() const
@@ -275,14 +289,14 @@ class Manager : private ManagerImplListener
275 } 289 }
276 290
277 return typeDescs; 291 return typeDescs;
278 } 292 }
279 293
280 void resourceChanged( T *resource ) 294 void resourceChanged( T *resource )
281 { 295 {
282 mImpl->resourceChanged( resource ); 296 mImpl->resourceChanged( resource );
283 } 297 }
284 298
285 void addListener( ManagerListener<T> *listener ) 299 void addListener( ManagerListener<T> *listener )
286 { 300 {
287 mListeners->append( listener ); 301 mListeners->append( listener );
288 } 302 }
@@ -306,13 +320,13 @@ class Manager : private ManagerImplListener
306 kdDebug(5650) << "Manager::resourceModified " << res->resourceName() << endl; 320 kdDebug(5650) << "Manager::resourceModified " << res->resourceName() << endl;
307 T* resource = (T *)( res ); 321 T* resource = (T *)( res );
308 ManagerListener<T> *listener; 322 ManagerListener<T> *listener;
309 for ( listener = mListeners->first(); listener; listener = mListeners->next() ) 323 for ( listener = mListeners->first(); listener; listener = mListeners->next() )
310 listener->resourceModified( resource ); 324 listener->resourceModified( resource );
311 } 325 }
312 326
313 virtual void resourceDeleted( Resource *res ) 327 virtual void resourceDeleted( Resource *res )
314 { 328 {
315 kdDebug(5650) << "Manager::resourceDeleted " << res->resourceName() << endl; 329 kdDebug(5650) << "Manager::resourceDeleted " << res->resourceName() << endl;
316 T* resource = (T *)( res ); 330 T* resource = (T *)( res );
317 ManagerListener<T> *listener; 331 ManagerListener<T> *listener;
318 for ( listener = mListeners->first(); listener; listener = mListeners->next() ) { 332 for ( listener = mListeners->first(); listener; listener = mListeners->next() ) {