author | ulf69 <ulf69> | 2004-08-02 18:12:49 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-08-02 18:12:49 (UTC) |
commit | b4203356adb6008a4b4e6782afdae7dd34178697 (patch) (unidiff) | |
tree | 13ec830c5748106467c2d610d65db5d1a2cf9263 /microkde/kresources | |
parent | 09e8e7e5d4c3cafcf2b05511e5c78717fb5380e7 (diff) | |
download | kdepimpi-b4203356adb6008a4b4e6782afdae7dd34178697.zip kdepimpi-b4203356adb6008a4b4e6782afdae7dd34178697.tar.gz kdepimpi-b4203356adb6008a4b4e6782afdae7dd34178697.tar.bz2 |
added support for syncing of resources
-rw-r--r-- | microkde/kresources/manager.h | 44 | ||||
-rw-r--r-- | microkde/kresources/managerimpl.cpp | 70 | ||||
-rw-r--r-- | microkde/kresources/syncwidget.cpp | 46 | ||||
-rw-r--r-- | microkde/kresources/syncwidget.h | 62 |
4 files changed, 180 insertions, 42 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,332 +1,346 @@ | |||
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 | ||
13 | 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, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | Library General Public License for more details. | 17 | Library General Public License for more details. |
17 | 18 | ||
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 | /* | ||
26 | Enhanced Version of the file for platform independent KDE tools. | ||
27 | Copyright (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 | ||
30 | #include "factory.h" | 38 | #include "factory.h" |
31 | #include "managerimpl.h" | 39 | #include "managerimpl.h" |
32 | 40 | ||
33 | namespace KRES { | 41 | namespace KRES { |
34 | 42 | ||
35 | class Resource; | 43 | class Resource; |
36 | 44 | ||
37 | template<class T> | 45 | template<class T> |
38 | class ManagerListener | 46 | class ManagerListener |
39 | { | 47 | { |
40 | public: | 48 | public: |
41 | virtual void resourceAdded( T *resource ) = 0; | 49 | virtual void resourceAdded( T *resource ) = 0; |
42 | virtual void resourceModified( T *resource ) = 0; | 50 | virtual void resourceModified( T *resource ) = 0; |
43 | virtual void resourceDeleted( T *resource ) = 0; | 51 | virtual void resourceDeleted( T *resource ) = 0; |
44 | }; | 52 | }; |
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 | ||
55 | template<class T> | 63 | template<class T> |
56 | class Manager : private ManagerImplListener | 64 | class Manager : private ManagerImplListener |
57 | { | 65 | { |
58 | public: | 66 | public: |
59 | class Iterator | 67 | class Iterator |
60 | { | 68 | { |
61 | friend class Manager; | 69 | friend class Manager; |
62 | public: | 70 | public: |
63 | Iterator() {}; | 71 | Iterator() {}; |
64 | Iterator( const Iterator &it ) { mIt = it.mIt; } | 72 | Iterator( const Iterator &it ) { mIt = it.mIt; } |
65 | 73 | ||
66 | T *operator*() { return static_cast<T *>( *mIt ); } | 74 | T *operator*() { return static_cast<T *>( *mIt ); } |
67 | Iterator &operator++() { mIt++; return *this; } | 75 | Iterator &operator++() { mIt++; return *this; } |
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 | } |
91 | 99 | ||
92 | class ActiveIterator | 100 | class ActiveIterator |
93 | { | 101 | { |
94 | friend class Manager; | 102 | friend class Manager; |
95 | public: | 103 | public: |
96 | ActiveIterator() : mList( 0 ) {}; | 104 | ActiveIterator() : mList( 0 ) {}; |
97 | ActiveIterator( const ActiveIterator &it ) | 105 | ActiveIterator( const ActiveIterator &it ) |
98 | { | 106 | { |
99 | mIt = it.mIt; | 107 | mIt = it.mIt; |
100 | mList = it.mList; | 108 | mList = it.mList; |
101 | } | 109 | } |
102 | 110 | ||
103 | T *operator*() { return static_cast<T *>( *mIt ); } | 111 | T *operator*() { return static_cast<T *>( *mIt ); } |
104 | ActiveIterator &operator++() | 112 | ActiveIterator &operator++() |
105 | { | 113 | { |
106 | do { mIt++; } while ( checkActive() ); | 114 | do { mIt++; } while ( checkActive() ); |
107 | return *this; | 115 | return *this; |
108 | } | 116 | } |
109 | ActiveIterator &operator++(int) | 117 | ActiveIterator &operator++(int) |
110 | { | 118 | { |
111 | do { mIt++; } while ( checkActive() ); | 119 | do { mIt++; } while ( checkActive() ); |
112 | return *this; | 120 | return *this; |
113 | } | 121 | } |
114 | ActiveIterator &operator--() | 122 | ActiveIterator &operator--() |
115 | { | 123 | { |
116 | do { mIt--; } while ( checkActive() ); | 124 | do { mIt--; } while ( checkActive() ); |
117 | return *this; | 125 | return *this; |
118 | } | 126 | } |
119 | ActiveIterator &operator--(int) | 127 | ActiveIterator &operator--(int) |
120 | { | 128 | { |
121 | do { mIt--; } while ( checkActive() ); | 129 | do { mIt--; } while ( checkActive() ); |
122 | return *this; | 130 | return *this; |
123 | } | 131 | } |
124 | bool operator==( const ActiveIterator &it ) { return mIt == it.mIt; } | 132 | bool operator==( const ActiveIterator &it ) { return mIt == it.mIt; } |
125 | bool operator!=( const ActiveIterator &it ) { return mIt != it.mIt; } | 133 | bool operator!=( const ActiveIterator &it ) { return mIt != it.mIt; } |
126 | 134 | ||
127 | private: | 135 | private: |
128 | /** | 136 | /** |
129 | Check if iterator needs to be advanced once more. | 137 | Check if iterator needs to be advanced once more. |
130 | */ | 138 | */ |
131 | bool checkActive() | 139 | bool checkActive() |
132 | { | 140 | { |
133 | if ( !mList || mIt == mList->end() ) return false; | 141 | if ( !mList || mIt == mList->end() ) return false; |
134 | return !(*mIt)->isActive(); | 142 | return !(*mIt)->isActive(); |
135 | } | 143 | } |
136 | 144 | ||
137 | Resource::List::Iterator mIt; | 145 | Resource::List::Iterator mIt; |
138 | Resource::List *mList; | 146 | Resource::List *mList; |
139 | }; | 147 | }; |
140 | 148 | ||
141 | ActiveIterator activeBegin() | 149 | ActiveIterator activeBegin() |
142 | { | 150 | { |
143 | ActiveIterator it; | 151 | ActiveIterator it; |
144 | it.mIt = mImpl->resourceList()->begin(); | 152 | it.mIt = mImpl->resourceList()->begin(); |
145 | it.mList = mImpl->resourceList(); | 153 | it.mList = mImpl->resourceList(); |
146 | if ( it.mIt != mImpl->resourceList()->end() ) { | 154 | if ( it.mIt != mImpl->resourceList()->end() ) { |
147 | if ( !(*it)->isActive() ) it++; | 155 | if ( !(*it)->isActive() ) it++; |
148 | } | 156 | } |
149 | return it; | 157 | return it; |
150 | } | 158 | } |
151 | 159 | ||
152 | ActiveIterator activeEnd() | 160 | ActiveIterator activeEnd() |
153 | { | 161 | { |
154 | ActiveIterator it; | 162 | ActiveIterator it; |
155 | it.mIt = mImpl->resourceList()->end(); | 163 | it.mIt = mImpl->resourceList()->end(); |
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 | /** |
181 | Recreate Resource objects from configuration file. If cfg is 0, read standard | 194 | Recreate Resource objects from configuration file. If cfg is 0, read standard |
182 | configuration file. | 195 | configuration file. |
183 | */ | 196 | */ |
184 | void readConfig( KConfig *cfg = 0 ) | 197 | void readConfig( KConfig *cfg = 0 ) |
185 | { | 198 | { |
186 | mImpl->readConfig( cfg ); | 199 | mImpl->readConfig( cfg ); |
187 | } | 200 | } |
188 | 201 | ||
189 | /** | 202 | /** |
190 | Write configuration of Resource objects to configuration file. If cfg is 0, write | 203 | Write configuration of Resource objects to configuration file. If cfg is 0, write |
191 | to standard configuration file. | 204 | to standard configuration file. |
192 | */ | 205 | */ |
193 | void writeConfig( KConfig *cfg = 0 ) | 206 | void writeConfig( KConfig *cfg = 0 ) |
194 | { | 207 | { |
195 | mImpl->writeConfig( cfg ); | 208 | mImpl->writeConfig( cfg ); |
196 | } | 209 | } |
197 | 210 | ||
198 | /** | 211 | /** |
199 | Add resource to manager. This passes ownership of the Resource object | 212 | Add resource to manager. This passes ownership of the Resource object |
200 | to the manager. | 213 | to the manager. |
201 | */ | 214 | */ |
202 | void add( Resource *resource ) | 215 | void add( Resource *resource ) |
203 | { | 216 | { |
204 | if ( resource ) mImpl->add( resource ); | 217 | if ( resource ) mImpl->add( resource ); |
205 | } | 218 | } |
206 | 219 | ||
207 | void remove( Resource *resource ) | 220 | void remove( Resource *resource ) |
208 | { | 221 | { |
209 | if ( resource ) mImpl->remove( resource ); | 222 | if ( resource ) mImpl->remove( resource ); |
210 | } | 223 | } |
211 | 224 | ||
212 | T* standardResource() | 225 | T* standardResource() |
213 | { | 226 | { |
214 | return static_cast<T *>( mImpl->standardResource() ); | 227 | return static_cast<T *>( mImpl->standardResource() ); |
215 | } | 228 | } |
216 | 229 | ||
217 | void setStandardResource( T *resource ) | 230 | void setStandardResource( T *resource ) |
218 | { | 231 | { |
219 | if ( resource ) mImpl->setStandardResource( resource ); | 232 | if ( resource ) mImpl->setStandardResource( resource ); |
220 | } | 233 | } |
221 | 234 | ||
222 | void setActive( Resource *resource, bool active ) | 235 | void setActive( Resource *resource, bool active ) |
223 | { | 236 | { |
224 | if ( resource ) mImpl->setActive( resource, active ); | 237 | if ( resource ) mImpl->setActive( resource, active ); |
225 | } | 238 | } |
226 | 239 | ||
227 | /** | 240 | /** |
228 | Returns a list of the names of the reources managed by the | 241 | Returns a list of the names of the reources managed by the |
229 | Manager for this family. | 242 | Manager for this family. |
230 | */ | 243 | */ |
231 | QStringList resourceNames() const | 244 | QStringList resourceNames() const |
232 | { | 245 | { |
233 | return mImpl->resourceNames(); | 246 | return mImpl->resourceNames(); |
234 | } | 247 | } |
235 | 248 | ||
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 |
260 | { | 274 | { |
261 | return mFactory->typeNames(); | 275 | return mFactory->typeNames(); |
262 | } | 276 | } |
263 | 277 | ||
264 | QStringList resourceTypeDescriptions() const | 278 | QStringList resourceTypeDescriptions() const |
265 | { | 279 | { |
266 | QStringList typeDescs; | 280 | QStringList typeDescs; |
267 | QStringList types = mFactory->typeNames(); | 281 | QStringList types = mFactory->typeNames(); |
268 | 282 | ||
269 | for ( QStringList::ConstIterator it = types.begin(); it != types.end(); ++it ) { | 283 | for ( QStringList::ConstIterator it = types.begin(); it != types.end(); ++it ) { |
270 | QString desc = mFactory->typeName( *it ); | 284 | QString desc = mFactory->typeName( *it ); |
271 | if ( !mFactory->typeDescription( *it ).isEmpty() ) | 285 | if ( !mFactory->typeDescription( *it ).isEmpty() ) |
272 | desc += " (" + mFactory->typeDescription( *it ) + ")"; | 286 | desc += " (" + mFactory->typeDescription( *it ) + ")"; |
273 | 287 | ||
274 | typeDescs.append( desc ); | 288 | typeDescs.append( desc ); |
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 | } |
289 | 303 | ||
290 | void removeListener( ManagerListener<T> *listener ) | 304 | void removeListener( ManagerListener<T> *listener ) |
291 | { | 305 | { |
292 | mListeners->remove( listener ); | 306 | mListeners->remove( listener ); |
293 | } | 307 | } |
294 | 308 | ||
295 | virtual void resourceAdded( Resource *res ) | 309 | virtual void resourceAdded( Resource *res ) |
296 | { | 310 | { |
297 | kdDebug(5650) << "Manager::resourceAdded " << res->resourceName() << endl; | 311 | kdDebug(5650) << "Manager::resourceAdded " << res->resourceName() << endl; |
298 | T* resource = (T *)( res ); | 312 | T* resource = (T *)( res ); |
299 | ManagerListener<T> *listener; | 313 | ManagerListener<T> *listener; |
300 | for ( listener = mListeners->first(); listener; listener = mListeners->next() ) | 314 | for ( listener = mListeners->first(); listener; listener = mListeners->next() ) |
301 | listener->resourceAdded( resource ); | 315 | listener->resourceAdded( resource ); |
302 | } | 316 | } |
303 | 317 | ||
304 | virtual void resourceModified( Resource *res ) | 318 | virtual void resourceModified( Resource *res ) |
305 | { | 319 | { |
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() ) { |
319 | kdDebug(5650) << "Notifying a listener to Manager..." << endl; | 333 | kdDebug(5650) << "Notifying a listener to Manager..." << endl; |
320 | listener->resourceDeleted( resource ); | 334 | listener->resourceDeleted( resource ); |
321 | } | 335 | } |
322 | } | 336 | } |
323 | 337 | ||
324 | private: | 338 | private: |
325 | ManagerImpl *mImpl; | 339 | ManagerImpl *mImpl; |
326 | Factory *mFactory; | 340 | Factory *mFactory; |
327 | QPtrList<ManagerListener<T> > *mListeners; | 341 | QPtrList<ManagerListener<T> > *mListeners; |
328 | }; | 342 | }; |
329 | 343 | ||
330 | } | 344 | } |
331 | 345 | ||
332 | #endif | 346 | #endif |
diff --git a/microkde/kresources/managerimpl.cpp b/microkde/kresources/managerimpl.cpp index 785b6b4..3655f50 100644 --- a/microkde/kresources/managerimpl.cpp +++ b/microkde/kresources/managerimpl.cpp | |||
@@ -1,358 +1,374 @@ | |||
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 | 7 | ||
8 | This library is free software; you can redistribute it and/or | 8 | This library is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU Library General Public | 9 | modify it under the terms of the GNU Library General Public |
10 | License as published by the Free Software Foundation; either | 10 | License as published by the Free Software Foundation; either |
11 | version 2 of the License, or (at your option) any later version. | 11 | version 2 of the License, or (at your option) any later version. |
12 | 12 | ||
13 | This library is distributed in the hope that it will be useful, | 13 | This library is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | Library General Public License for more details. | 16 | Library General Public License for more details. |
17 | 17 | ||
18 | You should have received a copy of the GNU Library General Public License | 18 | 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 | 19 | along with this library; see the file COPYING.LIB. If not, write to |
20 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 20 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
21 | Boston, MA 02111-1307, USA. | 21 | Boston, MA 02111-1307, USA. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | /* | ||
25 | Enhanced Version of the file for platform independent KDE tools. | ||
26 | Copyright (c) 2004 Ulf Schenk | ||
27 | |||
28 | $Id$ | ||
29 | */ | ||
30 | |||
24 | #include <kglobal.h> | 31 | #include <kglobal.h> |
25 | 32 | ||
26 | #include <kapplication.h> | 33 | #include <kapplication.h> |
27 | #include <kdebug.h> | 34 | #include <kdebug.h> |
28 | #include <kconfig.h> | 35 | #include <kconfig.h> |
29 | #include <kstandarddirs.h> | 36 | #include <kstandarddirs.h> |
30 | 37 | ||
31 | #include "resource.h" | 38 | #include "resource.h" |
32 | #include "factory.h" | 39 | #include "factory.h" |
33 | #include "managerimpl.h" | 40 | #include "managerimpl.h" |
34 | 41 | ||
35 | using namespace KRES; | 42 | using namespace KRES; |
36 | 43 | ||
37 | ManagerImpl::ManagerImpl( const QString &family ) | 44 | ManagerImpl::ManagerImpl( const QString &family, bool syncable ) |
38 | : mFamily( family ), mConfig( 0 ), mStdConfig( 0 ), mStandard( 0 ), | 45 | : mFamily( family ), mSyncable(syncable), mConfig( 0 ), mStdConfig( 0 ), mStandard( 0 ), |
39 | mFactory( 0 ) | 46 | mFactory( 0 ) |
40 | 47 | ||
41 | { | 48 | { |
42 | kdDebug(5650) << "ManagerImpl::ManagerImpl()" << endl; | 49 | kdDebug(5650) << "ManagerImpl::ManagerImpl()" << endl; |
43 | 50 | ||
44 | 51 | ||
45 | } | 52 | } |
46 | 53 | ||
47 | ManagerImpl::~ManagerImpl() | 54 | ManagerImpl::~ManagerImpl() |
48 | { | 55 | { |
49 | kdDebug(5650) << "ManagerImpl::~ManagerImpl()" << endl; | 56 | kdDebug(5650) << "ManagerImpl::~ManagerImpl()" << endl; |
50 | 57 | ||
51 | Resource::List::ConstIterator it; | 58 | Resource::List::ConstIterator it; |
52 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { | 59 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { |
53 | delete *it; | 60 | delete *it; |
54 | } | 61 | } |
55 | 62 | ||
56 | delete mStdConfig; | 63 | delete mStdConfig; |
57 | } | 64 | } |
58 | 65 | ||
59 | void ManagerImpl::createStandardConfig() | 66 | void ManagerImpl::createStandardConfig() |
60 | { | 67 | { |
61 | if ( !mStdConfig ) { | 68 | if ( !mStdConfig ) { |
62 | QString file = locateLocal( "data", KGlobal::getAppName() | 69 | QString file = locateLocal( "data", KGlobal::getAppName() |
63 | + "/kresources/" + mFamily + "rc" ); | 70 | + "/kresources/" + mFamily + "rc" ); |
64 | mStdConfig = new KConfig( file ); | 71 | mStdConfig = new KConfig( file ); |
65 | } | 72 | } |
66 | 73 | ||
67 | mConfig = mStdConfig; | 74 | mConfig = mStdConfig; |
68 | } | 75 | } |
69 | 76 | ||
70 | void ManagerImpl::readConfig( KConfig *cfg ) | 77 | void ManagerImpl::readConfig( KConfig *cfg ) |
71 | { | 78 | { |
72 | kdDebug(5650) << "ManagerImpl::readConfig()" << endl; | 79 | kdDebug(5650) << "ManagerImpl::readConfig()" << endl; |
73 | 80 | ||
74 | delete mFactory; | 81 | delete mFactory; |
75 | mFactory = Factory::self( mFamily ); | 82 | mFactory = Factory::self( mFamily ); |
76 | 83 | ||
77 | if ( !cfg ) { | 84 | if ( !cfg ) { |
78 | createStandardConfig(); | 85 | createStandardConfig(); |
79 | } else { | 86 | } else { |
80 | mConfig = cfg; | 87 | mConfig = cfg; |
81 | } | 88 | } |
82 | 89 | ||
83 | mStandard = 0; | 90 | mStandard = 0; |
84 | 91 | ||
85 | mConfig->setGroup( "General" ); | 92 | mConfig->setGroup( "General" ); |
86 | 93 | ||
87 | QStringList keys = mConfig->readListEntry( "ResourceKeys" ); | 94 | QStringList keys = mConfig->readListEntry( "ResourceKeys" ); |
88 | keys += mConfig->readListEntry( "PassiveResourceKeys" ); | 95 | keys += mConfig->readListEntry( "PassiveResourceKeys" ); |
89 | 96 | ||
90 | QString standardKey = mConfig->readEntry( "Standard" ); | 97 | QString standardKey = mConfig->readEntry( "Standard" ); |
91 | 98 | ||
92 | for ( QStringList::Iterator it = keys.begin(); it != keys.end(); ++it ) { | 99 | for ( QStringList::Iterator it = keys.begin(); it != keys.end(); ++it ) { |
93 | readResourceConfig( *it, false ); | 100 | readResourceConfig( *it, false ); |
94 | } | 101 | } |
95 | 102 | ||
96 | } | 103 | } |
97 | 104 | ||
98 | void ManagerImpl::writeConfig( KConfig *cfg ) | 105 | void ManagerImpl::writeConfig( KConfig *cfg ) |
99 | { | 106 | { |
100 | //USqDebug("ManagerImpl::writeConfig begin this= %ul cfg=%ul", this, cfg); | 107 | //USqDebug("ManagerImpl::writeConfig begin this= %ul cfg=%ul", this, cfg); |
101 | 108 | ||
102 | 109 | ||
103 | kdDebug(5650) << "ManagerImpl::writeConfig()" << endl; | 110 | kdDebug(5650) << "ManagerImpl::writeConfig()" << endl; |
104 | 111 | ||
105 | if ( !cfg ) { | 112 | if ( !cfg ) { |
106 | createStandardConfig(); | 113 | createStandardConfig(); |
107 | } else { | 114 | } else { |
108 | mConfig = cfg; | 115 | mConfig = cfg; |
109 | } | 116 | } |
110 | 117 | ||
111 | QStringList activeKeys; | 118 | QStringList activeKeys; |
112 | QStringList passiveKeys; | 119 | QStringList passiveKeys; |
113 | 120 | ||
114 | // First write all keys, collect active and passive keys on the way | 121 | // First write all keys, collect active and passive keys on the way |
115 | Resource::List::Iterator it; | 122 | Resource::List::Iterator it; |
116 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { | 123 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { |
117 | writeResourceConfig( *it, false ); | 124 | writeResourceConfig( *it, false ); |
118 | 125 | ||
119 | QString key = (*it)->identifier(); | 126 | QString key = (*it)->identifier(); |
120 | if( (*it)->isActive() ) | 127 | if( (*it)->isActive() ) |
121 | activeKeys.append( key ); | 128 | activeKeys.append( key ); |
122 | else | 129 | else |
123 | passiveKeys.append( key ); | 130 | passiveKeys.append( key ); |
124 | } | 131 | } |
125 | 132 | ||
126 | // And then the general group | 133 | // And then the general group |
127 | 134 | ||
128 | kdDebug(5650) << "Saving general info" << endl; | 135 | kdDebug(5650) << "Saving general info" << endl; |
129 | mConfig->setGroup( "General" ); | 136 | mConfig->setGroup( "General" ); |
130 | mConfig->writeEntry( "ResourceKeys", activeKeys ); | 137 | mConfig->writeEntry( "ResourceKeys", activeKeys ); |
131 | mConfig->writeEntry( "PassiveResourceKeys", passiveKeys ); | 138 | mConfig->writeEntry( "PassiveResourceKeys", passiveKeys ); |
132 | if ( mStandard ) | 139 | if ( mStandard ) |
133 | mConfig->writeEntry( "Standard", mStandard->identifier() ); | 140 | mConfig->writeEntry( "Standard", mStandard->identifier() ); |
134 | else | 141 | else |
135 | mConfig->writeEntry( "Standard", "" ); | 142 | mConfig->writeEntry( "Standard", "" ); |
136 | 143 | ||
137 | mConfig->sync(); | 144 | mConfig->sync(); |
138 | kdDebug(5650) << "ManagerImpl::save() finished" << endl; | 145 | kdDebug(5650) << "ManagerImpl::save() finished" << endl; |
139 | 146 | ||
140 | //US qDebug("ManagerImpl::writeConfig end this= %ul cfg=%ul", this, cfg); | 147 | //US qDebug("ManagerImpl::writeConfig end this= %ul cfg=%ul", this, cfg); |
141 | 148 | ||
142 | } | 149 | } |
143 | 150 | ||
144 | void ManagerImpl::add( Resource *resource, bool useDCOP ) | 151 | void ManagerImpl::add( Resource *resource, bool useDCOP ) |
145 | { | 152 | { |
146 | qDebug("ManagerImpl::add begin this= %ul resource=%ul", this, resource); | 153 | qDebug("ManagerImpl::add begin this= %ul resource=%ul", this, resource); |
147 | 154 | ||
148 | resource->setActive( true ); | 155 | resource->setActive( true ); |
149 | 156 | ||
150 | if ( mResources.isEmpty() ) { | 157 | if ( mResources.isEmpty() ) { |
151 | mStandard = resource; | 158 | mStandard = resource; |
152 | } | 159 | } |
153 | 160 | ||
154 | mResources.append( resource ); | 161 | mResources.append( resource ); |
155 | 162 | ||
156 | writeResourceConfig( resource, true ); | 163 | writeResourceConfig( resource, true ); |
157 | 164 | ||
158 | qDebug("ManagerImpl::add end this= %ul resource=%ul", this, resource); | 165 | qDebug("ManagerImpl::add end this= %ul resource=%ul", this, resource); |
159 | 166 | ||
160 | } | 167 | } |
161 | 168 | ||
162 | void ManagerImpl::remove( Resource *resource, bool useDCOP ) | 169 | void ManagerImpl::remove( Resource *resource, bool useDCOP ) |
163 | { | 170 | { |
164 | if ( mStandard == resource ) mStandard = 0; | 171 | if ( mStandard == resource ) mStandard = 0; |
165 | removeResource( resource ); | 172 | removeResource( resource ); |
166 | 173 | ||
167 | mResources.remove( resource ); | 174 | mResources.remove( resource ); |
168 | 175 | ||
169 | delete resource; | 176 | delete resource; |
170 | 177 | ||
171 | kdDebug(5650) << "Finished ManagerImpl::remove()" << endl; | 178 | kdDebug(5650) << "Finished ManagerImpl::remove()" << endl; |
172 | } | 179 | } |
173 | 180 | ||
174 | void ManagerImpl::setActive( Resource *resource, bool active ) | 181 | void ManagerImpl::setActive( Resource *resource, bool active ) |
175 | { | 182 | { |
176 | if ( resource && resource->isActive() != active ) { | 183 | if ( resource && resource->isActive() != active ) { |
177 | resource->setActive( active ); | 184 | resource->setActive( active ); |
178 | } | 185 | } |
179 | } | 186 | } |
180 | 187 | ||
181 | Resource *ManagerImpl::standardResource() | 188 | Resource *ManagerImpl::standardResource() |
182 | { | 189 | { |
183 | return mStandard; | 190 | return mStandard; |
184 | } | 191 | } |
185 | 192 | ||
186 | void ManagerImpl::setStandardResource( Resource *resource ) | 193 | void ManagerImpl::setStandardResource( Resource *resource ) |
187 | { | 194 | { |
188 | mStandard = resource; | 195 | mStandard = resource; |
189 | } | 196 | } |
190 | 197 | ||
191 | void ManagerImpl::resourceChanged( Resource *resource ) | 198 | void ManagerImpl::resourceChanged( Resource *resource ) |
192 | { | 199 | { |
193 | writeResourceConfig( resource, true ); | 200 | writeResourceConfig( resource, true ); |
194 | 201 | ||
195 | 202 | ||
196 | // ManagerIface_stub allManagers( "*", "ManagerIface_" + mFamily.utf8() ); | 203 | // ManagerIface_stub allManagers( "*", "ManagerIface_" + mFamily.utf8() ); |
197 | // allManagers.dcopResourceModified( resource->identifier() ); | 204 | // allManagers.dcopResourceModified( resource->identifier() ); |
198 | } | 205 | } |
199 | 206 | ||
200 | // DCOP asynchronous functions | 207 | // DCOP asynchronous functions |
201 | //US since we work from inside the application, we call the methods directly. | 208 | //US since we work from inside the application, we call the methods directly. |
202 | 209 | ||
203 | QStringList ManagerImpl::resourceNames() | 210 | QStringList ManagerImpl::resourceNames() |
204 | { | 211 | { |
205 | QStringList result; | 212 | QStringList result; |
206 | 213 | ||
207 | Resource::List::ConstIterator it; | 214 | Resource::List::ConstIterator it; |
208 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { | 215 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { |
209 | result.append( (*it)->resourceName() ); | 216 | result.append( (*it)->resourceName() ); |
210 | } | 217 | } |
211 | return result; | 218 | return result; |
212 | } | 219 | } |
213 | 220 | ||
214 | Resource::List *ManagerImpl::resourceList() | 221 | Resource::List *ManagerImpl::resourceList() |
215 | { | 222 | { |
216 | return &mResources; | 223 | return &mResources; |
217 | } | 224 | } |
218 | 225 | ||
219 | QPtrList<Resource> ManagerImpl::resources() | 226 | QPtrList<Resource> ManagerImpl::resources() |
220 | { | 227 | { |
221 | QPtrList<Resource> result; | 228 | QPtrList<Resource> result; |
222 | 229 | ||
223 | Resource::List::ConstIterator it; | 230 | Resource::List::ConstIterator it; |
224 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { | 231 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { |
225 | result.append( *it ); | 232 | result.append( *it ); |
226 | } | 233 | } |
227 | return result; | 234 | return result; |
228 | } | 235 | } |
229 | 236 | ||
230 | QPtrList<Resource> ManagerImpl::resources( bool active ) | 237 | QPtrList<Resource> ManagerImpl::resources( bool active ) |
231 | { | 238 | { |
232 | QPtrList<Resource> result; | 239 | QPtrList<Resource> result; |
233 | 240 | ||
234 | Resource::List::ConstIterator it; | 241 | Resource::List::ConstIterator it; |
235 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { | 242 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { |
236 | if ( (*it)->isActive() == active ) { | 243 | if ( (*it)->isActive() == active ) { |
237 | result.append( *it ); | 244 | result.append( *it ); |
238 | } | 245 | } |
239 | } | 246 | } |
240 | return result; | 247 | return result; |
241 | } | 248 | } |
242 | 249 | ||
243 | void ManagerImpl::setListener( ManagerImplListener *listener ) | 250 | void ManagerImpl::setListener( ManagerImplListener *listener ) |
244 | { | 251 | { |
245 | mListener = listener; | 252 | mListener = listener; |
246 | } | 253 | } |
247 | 254 | ||
248 | Resource* ManagerImpl::readResourceConfig( const QString& identifier, | 255 | Resource* ManagerImpl::readResourceConfig( const QString& identifier, |
249 | bool checkActive ) | 256 | bool checkActive ) |
250 | { | 257 | { |
251 | kdDebug() << "ManagerImpl::readResourceConfig() " << identifier << endl; | 258 | kdDebug() << "ManagerImpl::readResourceConfig() " << identifier << endl; |
252 | 259 | ||
253 | // qDebug("ManagerImpl::readResourceConfig() %s", identifier.latin1()); | 260 | // qDebug("ManagerImpl::readResourceConfig() %s", identifier.latin1()); |
254 | 261 | ||
255 | mConfig->setGroup( "Resource_" + identifier ); | 262 | mConfig->setGroup( "Resource_" + identifier ); |
256 | #ifdef _WIN32_ | 263 | #ifdef _WIN32_ |
257 | // we use plugins on win32. the group is stored in a static variable | 264 | // we use plugins on win32. the group is stored in a static variable |
258 | // such that gourp info not avail on win32 plugins | 265 | // such that gourp info not avail on win32 plugins |
259 | // to fix that, it would be a looooot of work | 266 | // to fix that, it would be a looooot of work |
260 | mConfig->setTempGroup( "Resource_" + identifier ); | 267 | mConfig->setTempGroup( "Resource_" + identifier ); |
261 | #endif | 268 | #endif |
262 | QString type = mConfig->readEntry( "ResourceType" ); | 269 | QString type = mConfig->readEntry( "ResourceType" ); |
263 | QString name = mConfig->readEntry( "ResourceName" ); | 270 | QString name = mConfig->readEntry( "ResourceName" ); |
264 | Resource *resource = mFactory->resource( type, mConfig ); | 271 | Resource *resource = mFactory->resource( type, mConfig, mSyncable ); |
265 | if ( !resource ) { | 272 | if ( !resource ) { |
266 | qDebug("Failed to create resource with id %s ",identifier.latin1() ); | 273 | qDebug("Failed to create resource with id %s ",identifier.latin1() ); |
267 | return 0; | 274 | return 0; |
268 | } | 275 | } |
269 | 276 | ||
270 | if ( resource->identifier().isEmpty() ) | 277 | if ( resource->identifier().isEmpty() ) |
271 | resource->setIdentifier( identifier ); | 278 | resource->setIdentifier( identifier ); |
272 | 279 | ||
273 | mConfig->setGroup( "General" ); | 280 | mConfig->setGroup( "General" ); |
274 | 281 | ||
275 | QString standardKey = mConfig->readEntry( "Standard" ); | 282 | QString standardKey = mConfig->readEntry( "Standard" ); |
276 | if ( standardKey == identifier ) { | 283 | if ( standardKey == identifier ) { |
277 | mStandard = resource; | 284 | mStandard = resource; |
278 | } | 285 | } |
279 | 286 | ||
280 | if ( checkActive ) { | 287 | if ( checkActive ) { |
281 | QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" ); | 288 | QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" ); |
282 | resource->setActive( activeKeys.contains( identifier ) ); | 289 | resource->setActive( activeKeys.contains( identifier ) ); |
283 | } | 290 | } |
284 | mResources.append( resource ); | 291 | mResources.append( resource ); |
285 | 292 | ||
286 | return resource; | 293 | return resource; |
287 | } | 294 | } |
288 | 295 | ||
289 | void ManagerImpl::writeResourceConfig( Resource *resource, | 296 | void ManagerImpl::writeResourceConfig( Resource *resource, |
290 | bool checkActive ) | 297 | bool checkActive ) |
291 | { | 298 | { |
292 | QString key = resource->identifier(); | 299 | QString key = resource->identifier(); |
293 | 300 | ||
294 | kdDebug(5650) << "Saving resource " << key << endl; | 301 | kdDebug(5650) << "Saving resource " << key << endl; |
295 | 302 | ||
296 | if ( !mConfig ) createStandardConfig(); | 303 | if ( !mConfig ) createStandardConfig(); |
297 | 304 | ||
298 | mConfig->setGroup( "Resource_" + key ); | 305 | mConfig->setGroup( "Resource_" + key ); |
299 | resource->writeConfig( mConfig ); | 306 | resource->writeConfig( mConfig ); |
300 | 307 | ||
301 | mConfig->setGroup( "General" ); | 308 | mConfig->setGroup( "General" ); |
302 | QString standardKey = mConfig->readEntry( "Standard" ); | 309 | QString standardKey = mConfig->readEntry( "Standard" ); |
303 | 310 | ||
304 | if ( resource == mStandard && standardKey != key ) | 311 | if ( resource == mStandard && standardKey != key ) |
305 | mConfig->writeEntry( "Standard", resource->identifier() ); | 312 | mConfig->writeEntry( "Standard", resource->identifier() ); |
306 | else if ( resource != mStandard && standardKey == key ) | 313 | else if ( resource != mStandard && standardKey == key ) |
307 | mConfig->writeEntry( "Standard", "" ); | 314 | mConfig->writeEntry( "Standard", "" ); |
308 | 315 | ||
309 | if ( checkActive ) { | 316 | if ( checkActive ) { |
310 | QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" ); | 317 | QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" ); |
311 | if ( resource->isActive() && !activeKeys.contains( key ) ) { | 318 | if ( resource->isActive() && !activeKeys.contains( key ) ) { |
312 | activeKeys.append( resource->identifier() ); | 319 | activeKeys.append( resource->identifier() ); |
313 | mConfig->writeEntry( "ResourceKeys", activeKeys ); | 320 | mConfig->writeEntry( "ResourceKeys", activeKeys ); |
314 | } else if ( !resource->isActive() && activeKeys.contains( key ) ) { | 321 | } else if ( !resource->isActive() && activeKeys.contains( key ) ) { |
315 | activeKeys.remove( key ); | 322 | activeKeys.remove( key ); |
316 | mConfig->writeEntry( "ResourceKeys", activeKeys ); | 323 | mConfig->writeEntry( "ResourceKeys", activeKeys ); |
317 | } | 324 | } |
318 | } | 325 | } |
319 | 326 | ||
320 | mConfig->sync(); | 327 | mConfig->sync(); |
321 | } | 328 | } |
322 | 329 | ||
323 | void ManagerImpl::removeResource( Resource *resource ) | 330 | void ManagerImpl::removeResource( Resource *resource ) |
324 | { | 331 | { |
325 | QString key = resource->identifier(); | 332 | QString key = resource->identifier(); |
326 | 333 | ||
327 | if ( !mConfig ) createStandardConfig(); | 334 | if ( !mConfig ) createStandardConfig(); |
328 | 335 | ||
329 | mConfig->setGroup( "General" ); | 336 | mConfig->setGroup( "General" ); |
330 | QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" ); | 337 | QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" ); |
331 | if ( activeKeys.contains( key ) ) { | 338 | if ( activeKeys.contains( key ) ) { |
332 | activeKeys.remove( key ); | 339 | activeKeys.remove( key ); |
333 | mConfig->writeEntry( "ResourceKeys", activeKeys ); | 340 | mConfig->writeEntry( "ResourceKeys", activeKeys ); |
334 | } else { | 341 | } else { |
335 | QStringList passiveKeys = mConfig->readListEntry( "PassiveResourceKeys" ); | 342 | QStringList passiveKeys = mConfig->readListEntry( "PassiveResourceKeys" ); |
336 | passiveKeys.remove( key ); | 343 | passiveKeys.remove( key ); |
337 | mConfig->writeEntry( "PassiveResourceKeys", passiveKeys ); | 344 | mConfig->writeEntry( "PassiveResourceKeys", passiveKeys ); |
338 | } | 345 | } |
339 | 346 | ||
340 | QString standardKey = mConfig->readEntry( "Standard" ); | 347 | QString standardKey = mConfig->readEntry( "Standard" ); |
341 | if ( standardKey == key ) { | 348 | if ( standardKey == key ) { |
342 | mConfig->writeEntry( "Standard", "" ); | 349 | mConfig->writeEntry( "Standard", "" ); |
343 | } | 350 | } |
344 | 351 | ||
345 | mConfig->deleteGroup( "Resource_" + resource->identifier() ); | 352 | mConfig->deleteGroup( "Resource_" + resource->identifier() ); |
346 | 353 | ||
347 | mConfig->sync(); | 354 | mConfig->sync(); |
348 | } | 355 | } |
349 | 356 | ||
350 | Resource* ManagerImpl::getResource( const QString& identifier ) | 357 | Resource* ManagerImpl::getResource( const QString& identifier ) |
351 | { | 358 | { |
352 | Resource::List::ConstIterator it; | 359 | Resource::List::ConstIterator it; |
353 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { | 360 | for ( it = mResources.begin(); it != mResources.end(); ++it ) { |
354 | if ( (*it)->identifier() == identifier ) | 361 | if ( (*it)->identifier() == identifier ) |
355 | return *it; | 362 | return *it; |
356 | } | 363 | } |
357 | return 0; | 364 | return 0; |
358 | } | 365 | } |
366 | |||
367 | /** | ||
368 | Return true, if the manager manages syncable resources. | ||
369 | */ | ||
370 | bool ManagerImpl::manageSyncable() const | ||
371 | { | ||
372 | return mSyncable; | ||
373 | } | ||
374 | |||
diff --git a/microkde/kresources/syncwidget.cpp b/microkde/kresources/syncwidget.cpp new file mode 100644 index 0000000..9bb0df6 --- a/dev/null +++ b/microkde/kresources/syncwidget.cpp | |||
@@ -0,0 +1,46 @@ | |||
1 | /* | ||
2 | This file is part of libkresources. | ||
3 | |||
4 | Copyright (c) 2004 Ulf Schenk | ||
5 | |||
6 | This library is free software; you can redistribute it and/or | ||
7 | modify it under the terms of the GNU Library General Public | ||
8 | License as published by the Free Software Foundation; either | ||
9 | version 2 of the License, or (at your option) any later version. | ||
10 | |||
11 | This library is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | Library General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU Library General Public License | ||
17 | along with this library; see the file COPYING.LIB. If not, write to | ||
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
19 | Boston, MA 02111-1307, USA. | ||
20 | */ | ||
21 | |||
22 | // $Id$ | ||
23 | |||
24 | #include "syncwidget.h" | ||
25 | |||
26 | using namespace KRES; | ||
27 | |||
28 | |||
29 | SyncWidget::SyncWidget( QWidget *parent, const char *name ) | ||
30 | : QWidget( parent, name ) | ||
31 | { | ||
32 | } | ||
33 | |||
34 | void SyncWidget::setInEditMode( bool ) | ||
35 | { | ||
36 | } | ||
37 | |||
38 | void SyncWidget::loadSettings( Resource * ) | ||
39 | { | ||
40 | } | ||
41 | |||
42 | void SyncWidget::saveSettings( Resource * ) | ||
43 | { | ||
44 | } | ||
45 | |||
46 | |||
diff --git a/microkde/kresources/syncwidget.h b/microkde/kresources/syncwidget.h new file mode 100644 index 0000000..e94252c --- a/dev/null +++ b/microkde/kresources/syncwidget.h | |||
@@ -0,0 +1,62 @@ | |||
1 | /* | ||
2 | This file is part of libkresources. | ||
3 | Copyright (c) 2004 Ulf Schenk | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Library General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Library General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Library General Public License | ||
16 | along with this library; see the file COPYING.LIB. If not, write to | ||
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | // $Id$ | ||
22 | |||
23 | #ifndef KRESOURCES_SYNCWIDGET_H | ||
24 | #define KRESOURCES_SYNCWIDGET_H | ||
25 | |||
26 | #include <qwidget.h> | ||
27 | |||
28 | #include <kconfig.h> | ||
29 | |||
30 | #include "resource.h" | ||
31 | |||
32 | namespace KRES { | ||
33 | |||
34 | class SyncWidget : public QWidget | ||
35 | { | ||
36 | Q_OBJECT | ||
37 | |||
38 | public: | ||
39 | SyncWidget( QWidget *parent = 0, const char *name = 0 ); | ||
40 | |||
41 | /** | ||
42 | Sets the widget to 'edit' mode. Reimplement this method if you are | ||
43 | interested in the mode change (to disable some GUI element for | ||
44 | example). By default the widget is in 'create new' mode. | ||
45 | */ | ||
46 | virtual void setInEditMode( bool value ); | ||
47 | |||
48 | public slots: | ||
49 | virtual void loadSettings( Resource *resource ); | ||
50 | virtual void saveSettings( Resource *resource ); | ||
51 | |||
52 | signals: | ||
53 | //US void setReadOnly( bool value ); | ||
54 | //US void setPersistentReadOnly( bool value ); | ||
55 | |||
56 | |||
57 | protected: | ||
58 | //US Resource* mResource; | ||
59 | }; | ||
60 | |||
61 | } | ||
62 | #endif | ||