summaryrefslogtreecommitdiffabout
path: root/microkde/kresources
authorzautrix <zautrix>2004-11-07 17:35:51 (UTC)
committer zautrix <zautrix>2004-11-07 17:35:51 (UTC)
commitd90d17044d7daf6677074b0964d59f94407157d5 (patch) (unidiff)
tree82bf4f2001465637572534650769a864c15a6f7c /microkde/kresources
parentb6ef669713ee1d52adcfc9754dd039a4ff6675da (diff)
downloadkdepimpi-d90d17044d7daf6677074b0964d59f94407157d5.zip
kdepimpi-d90d17044d7daf6677074b0964d59f94407157d5.tar.gz
kdepimpi-d90d17044d7daf6677074b0964d59f94407157d5.tar.bz2
some mail fixes and warnings removed
Diffstat (limited to 'microkde/kresources') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kresources/managerimpl.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/microkde/kresources/managerimpl.cpp b/microkde/kresources/managerimpl.cpp
index 5bd9eb7..566b8f4 100644
--- a/microkde/kresources/managerimpl.cpp
+++ b/microkde/kresources/managerimpl.cpp
@@ -1,374 +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/* 24/*
25Enhanced Version of the file for platform independent KDE tools. 25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk 26Copyright (c) 2004 Ulf Schenk
27 27
28$Id$ 28$Id$
29*/ 29*/
30 30
31#include <kglobal.h> 31#include <kglobal.h>
32 32
33#include <kapplication.h> 33#include <kapplication.h>
34#include <kdebug.h> 34#include <kdebug.h>
35#include <kconfig.h> 35#include <kconfig.h>
36#include <kstandarddirs.h> 36#include <kstandarddirs.h>
37#include <qfile.h> 37#include <qfile.h>
38 38
39#include "resource.h" 39#include "resource.h"
40#include "factory.h" 40#include "factory.h"
41#include "managerimpl.h" 41#include "managerimpl.h"
42 42
43using namespace KRES; 43using namespace KRES;
44 44
45ManagerImpl::ManagerImpl( const QString &family ) 45ManagerImpl::ManagerImpl( const QString &family )
46 : mFamily( family ), mConfig( 0 ), mStdConfig( 0 ), mStandard( 0 ), 46 : mFamily( family ), mConfig( 0 ), mStdConfig( 0 ), mStandard( 0 ),
47 mFactory( 0 ) 47 mFactory( 0 )
48 48
49{ 49{
50 kdDebug(5650) << "ManagerImpl::ManagerImpl()" << endl; 50 kdDebug(5650) << "ManagerImpl::ManagerImpl()" << endl;
51 51
52 52
53} 53}
54 54
55ManagerImpl::~ManagerImpl() 55ManagerImpl::~ManagerImpl()
56{ 56{
57 kdDebug(5650) << "ManagerImpl::~ManagerImpl()" << endl; 57 kdDebug(5650) << "ManagerImpl::~ManagerImpl()" << endl;
58 58
59 Resource::List::ConstIterator it; 59 Resource::List::ConstIterator it;
60 for ( it = mResources.begin(); it != mResources.end(); ++it ) { 60 for ( it = mResources.begin(); it != mResources.end(); ++it ) {
61 delete *it; 61 delete *it;
62 } 62 }
63 63
64 delete mStdConfig; 64 delete mStdConfig;
65} 65}
66 66
67void ManagerImpl::createStandardConfig() 67void ManagerImpl::createStandardConfig()
68{ 68{
69 if ( !mStdConfig ) { 69 if ( !mStdConfig ) {
70 QString file = locateLocal( "data", KGlobal::getAppName() 70 QString file = locateLocal( "data", KGlobal::getAppName()
71 + "/kresources/" + mFamily + "rc" ); 71 + "/kresources/" + mFamily + "rc" );
72 if ( mFamily == "tmpcontact" ) { 72 if ( mFamily == "tmpcontact" ) {
73 if (QFile::exists ( file ) ){ 73 if (QFile::exists ( file ) ){
74 QFile::remove ( file ); 74 QFile::remove ( file );
75 qDebug("removed tmp rc file: %s ", file.latin1()); 75 qDebug("removed tmp rc file: %s ", file.latin1());
76 } 76 }
77 } 77 }
78 mStdConfig = new KConfig( file ); 78 mStdConfig = new KConfig( file );
79 } 79 }
80 80
81 mConfig = mStdConfig; 81 mConfig = mStdConfig;
82} 82}
83 83
84void ManagerImpl::readConfig( KConfig *cfg ) 84void ManagerImpl::readConfig( KConfig *cfg )
85{ 85{
86 kdDebug(5650) << "ManagerImpl::readConfig()" << endl; 86 kdDebug(5650) << "ManagerImpl::readConfig()" << endl;
87 87
88 delete mFactory; 88 delete mFactory;
89 mFactory = Factory::self( mFamily ); 89 mFactory = Factory::self( mFamily );
90 90
91 if ( !cfg ) { 91 if ( !cfg ) {
92 createStandardConfig(); 92 createStandardConfig();
93 } else { 93 } else {
94 mConfig = cfg; 94 mConfig = cfg;
95 } 95 }
96 96
97 mStandard = 0; 97 mStandard = 0;
98 98
99 mConfig->setGroup( "General" ); 99 mConfig->setGroup( "General" );
100 100
101 QStringList keys = mConfig->readListEntry( "ResourceKeys" ); 101 QStringList keys = mConfig->readListEntry( "ResourceKeys" );
102 keys += mConfig->readListEntry( "PassiveResourceKeys" ); 102 keys += mConfig->readListEntry( "PassiveResourceKeys" );
103 103
104 QString standardKey = mConfig->readEntry( "Standard" ); 104 QString standardKey = mConfig->readEntry( "Standard" );
105 105
106 for ( QStringList::Iterator it = keys.begin(); it != keys.end(); ++it ) { 106 for ( QStringList::Iterator it = keys.begin(); it != keys.end(); ++it ) {
107 readResourceConfig( *it, false ); 107 readResourceConfig( *it, false );
108 } 108 }
109 109
110} 110}
111 111
112void ManagerImpl::writeConfig( KConfig *cfg ) 112void ManagerImpl::writeConfig( KConfig *cfg )
113{ 113{
114//USqDebug("ManagerImpl::writeConfig begin this= %ul cfg=%ul", this, cfg); 114//USqDebug("ManagerImpl::writeConfig begin this= %ul cfg=%ul", this, cfg);
115 115
116 116
117 kdDebug(5650) << "ManagerImpl::writeConfig()" << endl; 117 kdDebug(5650) << "ManagerImpl::writeConfig()" << endl;
118 118
119 if ( !cfg ) { 119 if ( !cfg ) {
120 createStandardConfig(); 120 createStandardConfig();
121 } else { 121 } else {
122 mConfig = cfg; 122 mConfig = cfg;
123 } 123 }
124 124
125 QStringList activeKeys; 125 QStringList activeKeys;
126 QStringList passiveKeys; 126 QStringList passiveKeys;
127 127
128 // First write all keys, collect active and passive keys on the way 128 // First write all keys, collect active and passive keys on the way
129 Resource::List::Iterator it; 129 Resource::List::Iterator it;
130 for ( it = mResources.begin(); it != mResources.end(); ++it ) { 130 for ( it = mResources.begin(); it != mResources.end(); ++it ) {
131 writeResourceConfig( *it, false ); 131 writeResourceConfig( *it, false );
132 132
133 QString key = (*it)->identifier(); 133 QString key = (*it)->identifier();
134 if( (*it)->isActive() ) 134 if( (*it)->isActive() )
135 activeKeys.append( key ); 135 activeKeys.append( key );
136 else 136 else
137 passiveKeys.append( key ); 137 passiveKeys.append( key );
138 } 138 }
139 139
140 // And then the general group 140 // And then the general group
141 141
142 kdDebug(5650) << "Saving general info" << endl; 142 kdDebug(5650) << "Saving general info" << endl;
143 mConfig->setGroup( "General" ); 143 mConfig->setGroup( "General" );
144 mConfig->writeEntry( "ResourceKeys", activeKeys ); 144 mConfig->writeEntry( "ResourceKeys", activeKeys );
145 mConfig->writeEntry( "PassiveResourceKeys", passiveKeys ); 145 mConfig->writeEntry( "PassiveResourceKeys", passiveKeys );
146 if ( mStandard ) 146 if ( mStandard )
147 mConfig->writeEntry( "Standard", mStandard->identifier() ); 147 mConfig->writeEntry( "Standard", mStandard->identifier() );
148 else 148 else
149 mConfig->writeEntry( "Standard", "" ); 149 mConfig->writeEntry( "Standard", "" );
150 150
151 mConfig->sync(); 151 mConfig->sync();
152 kdDebug(5650) << "ManagerImpl::save() finished" << endl; 152 kdDebug(5650) << "ManagerImpl::save() finished" << endl;
153 153
154//US qDebug("ManagerImpl::writeConfig end this= %ul cfg=%ul", this, cfg); 154//US qDebug("ManagerImpl::writeConfig end this= %ul cfg=%ul", this, cfg);
155 155
156} 156}
157 157
158void ManagerImpl::add( Resource *resource, bool useDCOP ) 158void ManagerImpl::add( Resource *resource, bool useDCOP )
159{ 159{
160qDebug("ManagerImpl::add begin this= %ul resource=%ul", this, resource); 160 //qDebug("ManagerImpl::add begin this= %ul resource=%ul", this, resource);
161 161
162 resource->setActive( true ); 162 resource->setActive( true );
163 163
164 if ( mResources.isEmpty() ) { 164 if ( mResources.isEmpty() ) {
165 mStandard = resource; 165 mStandard = resource;
166 } 166 }
167 167
168 mResources.append( resource ); 168 mResources.append( resource );
169 169
170 writeResourceConfig( resource, true ); 170 writeResourceConfig( resource, true );
171 171
172 qDebug("ManagerImpl::add end this= %ul resource=%ul", this, resource); 172 //qDebug("ManagerImpl::add end this= %ul resource=%ul", this, resource);
173 173
174} 174}
175 175
176void ManagerImpl::remove( Resource *resource, bool useDCOP ) 176void ManagerImpl::remove( Resource *resource, bool useDCOP )
177{ 177{
178 if ( mStandard == resource ) mStandard = 0; 178 if ( mStandard == resource ) mStandard = 0;
179 removeResource( resource ); 179 removeResource( resource );
180 180
181 mResources.remove( resource ); 181 mResources.remove( resource );
182 182
183 delete resource; 183 delete resource;
184 184
185 kdDebug(5650) << "Finished ManagerImpl::remove()" << endl; 185 kdDebug(5650) << "Finished ManagerImpl::remove()" << endl;
186} 186}
187 187
188void ManagerImpl::setActive( Resource *resource, bool active ) 188void ManagerImpl::setActive( Resource *resource, bool active )
189{ 189{
190 if ( resource && resource->isActive() != active ) { 190 if ( resource && resource->isActive() != active ) {
191 resource->setActive( active ); 191 resource->setActive( active );
192 } 192 }
193} 193}
194 194
195Resource *ManagerImpl::standardResource() 195Resource *ManagerImpl::standardResource()
196{ 196{
197 return mStandard; 197 return mStandard;
198} 198}
199 199
200void ManagerImpl::setStandardResource( Resource *resource ) 200void ManagerImpl::setStandardResource( Resource *resource )
201{ 201{
202 mStandard = resource; 202 mStandard = resource;
203} 203}
204 204
205void ManagerImpl::resourceChanged( Resource *resource ) 205void ManagerImpl::resourceChanged( Resource *resource )
206{ 206{
207 writeResourceConfig( resource, true ); 207 writeResourceConfig( resource, true );
208 208
209 209
210// ManagerIface_stub allManagers( "*", "ManagerIface_" + mFamily.utf8() ); 210// ManagerIface_stub allManagers( "*", "ManagerIface_" + mFamily.utf8() );
211// allManagers.dcopResourceModified( resource->identifier() ); 211// allManagers.dcopResourceModified( resource->identifier() );
212} 212}
213 213
214// DCOP asynchronous functions 214// DCOP asynchronous functions
215//US since we work from inside the application, we call the methods directly. 215//US since we work from inside the application, we call the methods directly.
216 216
217QStringList ManagerImpl::resourceNames() 217QStringList ManagerImpl::resourceNames()
218{ 218{
219 QStringList result; 219 QStringList result;
220 220
221 Resource::List::ConstIterator it; 221 Resource::List::ConstIterator it;
222 for ( it = mResources.begin(); it != mResources.end(); ++it ) { 222 for ( it = mResources.begin(); it != mResources.end(); ++it ) {
223 result.append( (*it)->resourceName() ); 223 result.append( (*it)->resourceName() );
224 } 224 }
225 return result; 225 return result;
226} 226}
227 227
228Resource::List *ManagerImpl::resourceList() 228Resource::List *ManagerImpl::resourceList()
229{ 229{
230 return &mResources; 230 return &mResources;
231} 231}
232 232
233QPtrList<Resource> ManagerImpl::resources() 233QPtrList<Resource> ManagerImpl::resources()
234{ 234{
235 QPtrList<Resource> result; 235 QPtrList<Resource> result;
236 236
237 Resource::List::ConstIterator it; 237 Resource::List::ConstIterator it;
238 for ( it = mResources.begin(); it != mResources.end(); ++it ) { 238 for ( it = mResources.begin(); it != mResources.end(); ++it ) {
239 result.append( *it ); 239 result.append( *it );
240 } 240 }
241 return result; 241 return result;
242} 242}
243 243
244QPtrList<Resource> ManagerImpl::resources( bool active ) 244QPtrList<Resource> ManagerImpl::resources( bool active )
245{ 245{
246 QPtrList<Resource> result; 246 QPtrList<Resource> result;
247 247
248 Resource::List::ConstIterator it; 248 Resource::List::ConstIterator it;
249 for ( it = mResources.begin(); it != mResources.end(); ++it ) { 249 for ( it = mResources.begin(); it != mResources.end(); ++it ) {
250 if ( (*it)->isActive() == active ) { 250 if ( (*it)->isActive() == active ) {
251 result.append( *it ); 251 result.append( *it );
252 } 252 }
253 } 253 }
254 return result; 254 return result;
255} 255}
256 256
257void ManagerImpl::setListener( ManagerImplListener *listener ) 257void ManagerImpl::setListener( ManagerImplListener *listener )
258{ 258{
259 mListener = listener; 259 mListener = listener;
260} 260}
261 261
262Resource* ManagerImpl::readResourceConfig( const QString& identifier, 262Resource* ManagerImpl::readResourceConfig( const QString& identifier,
263 bool checkActive ) 263 bool checkActive )
264{ 264{
265 kdDebug() << "ManagerImpl::readResourceConfig() " << identifier << endl; 265 kdDebug() << "ManagerImpl::readResourceConfig() " << identifier << endl;
266 266
267// qDebug("ManagerImpl::readResourceConfig() %s", identifier.latin1()); 267// qDebug("ManagerImpl::readResourceConfig() %s", identifier.latin1());
268 268
269 mConfig->setGroup( "Resource_" + identifier ); 269 mConfig->setGroup( "Resource_" + identifier );
270#ifdef _WIN32_ 270#ifdef _WIN32_
271 // we use plugins on win32. the group is stored in a static variable 271 // we use plugins on win32. the group is stored in a static variable
272 // such that gourp info not avail on win32 plugins 272 // such that gourp info not avail on win32 plugins
273 // to fix that, it would be a looooot of work 273 // to fix that, it would be a looooot of work
274 mConfig->setTempGroup( "Resource_" + identifier ); 274 mConfig->setTempGroup( "Resource_" + identifier );
275#endif 275#endif
276 QString type = mConfig->readEntry( "ResourceType" ); 276 QString type = mConfig->readEntry( "ResourceType" );
277 QString name = mConfig->readEntry( "ResourceName" ); 277 QString name = mConfig->readEntry( "ResourceName" );
278 Resource *resource = mFactory->resource( type, mConfig ); 278 Resource *resource = mFactory->resource( type, mConfig );
279 if ( !resource ) { 279 if ( !resource ) {
280 qDebug("Failed to create resource with id %s ",identifier.latin1() ); 280 qDebug("Failed to create resource with id %s ",identifier.latin1() );
281 return 0; 281 return 0;
282 } 282 }
283 283
284 if ( resource->identifier().isEmpty() ) 284 if ( resource->identifier().isEmpty() )
285 resource->setIdentifier( identifier ); 285 resource->setIdentifier( identifier );
286 286
287 mConfig->setGroup( "General" ); 287 mConfig->setGroup( "General" );
288 288
289 QString standardKey = mConfig->readEntry( "Standard" ); 289 QString standardKey = mConfig->readEntry( "Standard" );
290 if ( standardKey == identifier ) { 290 if ( standardKey == identifier ) {
291 mStandard = resource; 291 mStandard = resource;
292 } 292 }
293 293
294 if ( checkActive ) { 294 if ( checkActive ) {
295 QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" ); 295 QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" );
296 resource->setActive( activeKeys.contains( identifier ) ); 296 resource->setActive( activeKeys.contains( identifier ) );
297 } 297 }
298 mResources.append( resource ); 298 mResources.append( resource );
299 299
300 return resource; 300 return resource;
301} 301}
302 302
303void ManagerImpl::writeResourceConfig( Resource *resource, 303void ManagerImpl::writeResourceConfig( Resource *resource,
304 bool checkActive ) 304 bool checkActive )
305{ 305{
306 QString key = resource->identifier(); 306 QString key = resource->identifier();
307 307
308 kdDebug(5650) << "Saving resource " << key << endl; 308 kdDebug(5650) << "Saving resource " << key << endl;
309 309
310 if ( !mConfig ) createStandardConfig(); 310 if ( !mConfig ) createStandardConfig();
311 311
312 mConfig->setGroup( "Resource_" + key ); 312 mConfig->setGroup( "Resource_" + key );
313 resource->writeConfig( mConfig ); 313 resource->writeConfig( mConfig );
314 314
315 mConfig->setGroup( "General" ); 315 mConfig->setGroup( "General" );
316 QString standardKey = mConfig->readEntry( "Standard" ); 316 QString standardKey = mConfig->readEntry( "Standard" );
317 317
318 if ( resource == mStandard && standardKey != key ) 318 if ( resource == mStandard && standardKey != key )
319 mConfig->writeEntry( "Standard", resource->identifier() ); 319 mConfig->writeEntry( "Standard", resource->identifier() );
320 else if ( resource != mStandard && standardKey == key ) 320 else if ( resource != mStandard && standardKey == key )
321 mConfig->writeEntry( "Standard", "" ); 321 mConfig->writeEntry( "Standard", "" );
322 322
323 if ( checkActive ) { 323 if ( checkActive ) {
324 QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" ); 324 QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" );
325 if ( resource->isActive() && !activeKeys.contains( key ) ) { 325 if ( resource->isActive() && !activeKeys.contains( key ) ) {
326 activeKeys.append( resource->identifier() ); 326 activeKeys.append( resource->identifier() );
327 mConfig->writeEntry( "ResourceKeys", activeKeys ); 327 mConfig->writeEntry( "ResourceKeys", activeKeys );
328 } else if ( !resource->isActive() && activeKeys.contains( key ) ) { 328 } else if ( !resource->isActive() && activeKeys.contains( key ) ) {
329 activeKeys.remove( key ); 329 activeKeys.remove( key );
330 mConfig->writeEntry( "ResourceKeys", activeKeys ); 330 mConfig->writeEntry( "ResourceKeys", activeKeys );
331 } 331 }
332 } 332 }
333 333
334 mConfig->sync(); 334 mConfig->sync();
335} 335}
336 336
337void ManagerImpl::removeResource( Resource *resource ) 337void ManagerImpl::removeResource( Resource *resource )
338{ 338{
339 QString key = resource->identifier(); 339 QString key = resource->identifier();
340 340
341 if ( !mConfig ) createStandardConfig(); 341 if ( !mConfig ) createStandardConfig();
342 342
343 mConfig->setGroup( "General" ); 343 mConfig->setGroup( "General" );
344 QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" ); 344 QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" );
345 if ( activeKeys.contains( key ) ) { 345 if ( activeKeys.contains( key ) ) {
346 activeKeys.remove( key ); 346 activeKeys.remove( key );
347 mConfig->writeEntry( "ResourceKeys", activeKeys ); 347 mConfig->writeEntry( "ResourceKeys", activeKeys );
348 } else { 348 } else {
349 QStringList passiveKeys = mConfig->readListEntry( "PassiveResourceKeys" ); 349 QStringList passiveKeys = mConfig->readListEntry( "PassiveResourceKeys" );
350 passiveKeys.remove( key ); 350 passiveKeys.remove( key );
351 mConfig->writeEntry( "PassiveResourceKeys", passiveKeys ); 351 mConfig->writeEntry( "PassiveResourceKeys", passiveKeys );
352 } 352 }
353 353
354 QString standardKey = mConfig->readEntry( "Standard" ); 354 QString standardKey = mConfig->readEntry( "Standard" );
355 if ( standardKey == key ) { 355 if ( standardKey == key ) {
356 mConfig->writeEntry( "Standard", "" ); 356 mConfig->writeEntry( "Standard", "" );
357 } 357 }
358 358
359 mConfig->deleteGroup( "Resource_" + resource->identifier() ); 359 mConfig->deleteGroup( "Resource_" + resource->identifier() );
360 360
361 mConfig->sync(); 361 mConfig->sync();
362} 362}
363 363
364Resource* ManagerImpl::getResource( const QString& identifier ) 364Resource* ManagerImpl::getResource( const QString& identifier )
365{ 365{
366 Resource::List::ConstIterator it; 366 Resource::List::ConstIterator it;
367 for ( it = mResources.begin(); it != mResources.end(); ++it ) { 367 for ( it = mResources.begin(); it != mResources.end(); ++it ) {
368 if ( (*it)->identifier() == identifier ) 368 if ( (*it)->identifier() == identifier )
369 return *it; 369 return *it;
370 } 370 }
371 return 0; 371 return 0;
372} 372}
373 373
374 374