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