summaryrefslogtreecommitdiffabout
path: root/microkde
Unidiff
Diffstat (limited to 'microkde') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kconfig.cpp22
-rw-r--r--microkde/kconfig.h4
-rw-r--r--microkde/kresources/managerimpl.cpp11
-rw-r--r--microkde/kresources/resource.cpp7
4 files changed, 36 insertions, 8 deletions
diff --git a/microkde/kconfig.cpp b/microkde/kconfig.cpp
index 737b3f2..4cbec94 100644
--- a/microkde/kconfig.cpp
+++ b/microkde/kconfig.cpp
@@ -1,509 +1,521 @@
1#include <qfile.h> 1#include <qfile.h>
2#include <qtextstream.h> 2#include <qtextstream.h>
3#include <qwidget.h> 3#include <qwidget.h>
4 4
5#include "kdebug.h" 5#include "kdebug.h"
6 6
7#include "kurl.h" 7#include "kurl.h"
8#include "kstandarddirs.h" 8#include "kstandarddirs.h"
9#include "kconfig.h" 9#include "kconfig.h"
10 10
11QString KConfig::mGroup = ""; 11QString KConfig::mGroup = "";
12//QString KConfig::mGroup = "General"; 12//QString KConfig::mGroup = "General";
13 13
14KConfig::KConfig( const QString &fileName ) 14KConfig::KConfig( const QString &fileName )
15 : mFileName( fileName ), mDirty( false ) 15 : mFileName( fileName ), mDirty( false )
16{ 16{
17 kdDebug() << "KConfig::KConfig(): '" << fileName << "'" << endl; 17
18 18 mTempGroup = "";
19 load(); 19 load();
20 20
21} 21}
22 22
23 23
24KConfig::~KConfig() 24KConfig::~KConfig()
25{ 25{
26 sync(); 26 sync();
27} 27}
28// we need the temp group for plugins on windows
29void KConfig::setTempGroup( const QString &group )
30{
31 mTempGroup = group;
32
33 if ( mTempGroup.right( 1 ) != "/" ) mTempGroup += "/";
34}
35
36
37QString KConfig::tempGroup() const {
38 return mTempGroup;
39}
28 40
29void KConfig::setGroup( const QString &group ) 41void KConfig::setGroup( const QString &group )
30{ 42{
31 kdDebug() << "KConfig::setGroup(): '" << group << "'" << endl; 43
32 44
33 mGroup = group; 45 mGroup = group;
34 46
35 if ( mGroup.right( 1 ) != "/" ) mGroup += "/"; 47 if ( mGroup.right( 1 ) != "/" ) mGroup += "/";
36} 48}
37 49
38//US 50//US
39QString KConfig::group() const { 51QString KConfig::group() const {
40 return mGroup; 52 return mGroup;
41} 53}
42 54
43//US added method 55//US added method
44QValueList<int> KConfig::readIntListEntry( const QString & key) 56QValueList<int> KConfig::readIntListEntry( const QString & key)
45{ 57{
46// qDebug("KConfig::readIntListEntry key=%s:", key.latin1()); 58// qDebug("KConfig::readIntListEntry key=%s:", key.latin1());
47 59
48 QValueList<int> result; 60 QValueList<int> result;
49 61
50 QMap<QString,QString>::ConstIterator mit = mStringMap.find( mGroup + key ); 62 QMap<QString,QString>::ConstIterator mit = mStringMap.find( mGroup + key );
51 63
52 if ( mit == mStringMap.end() ) { 64 if ( mit == mStringMap.end() ) {
53 return result; 65 return result;
54 } 66 }
55 67
56 QStringList valuesAsStrings = QStringList::split(":", *mit ); 68 QStringList valuesAsStrings = QStringList::split(":", *mit );
57 bool ok = false; 69 bool ok = false;
58 bool ok2 = true; 70 bool ok2 = true;
59 int val; 71 int val;
60 72
61 for ( QStringList::Iterator sit = valuesAsStrings.begin(); sit != valuesAsStrings.end(); ++sit ) { 73 for ( QStringList::Iterator sit = valuesAsStrings.begin(); sit != valuesAsStrings.end(); ++sit ) {
62 val = (*sit).toInt(&ok); 74 val = (*sit).toInt(&ok);
63 result << val; 75 result << val;
64 if (ok == false) { 76 if (ok == false) {
65 qDebug("KConfig::readIntListEntry str=%s , int=%n:", (*sit).latin1(), &val); 77 qDebug("KConfig::readIntListEntry str=%s , int=%n:", (*sit).latin1(), &val);
66 ok2 = false; 78 ok2 = false;
67 } 79 }
68 } 80 }
69 81
70 if (ok2 == false) 82 if (ok2 == false)
71 { 83 {
72 kdDebug() << "KConfig::readIntListEntry: error while reading one of the intvalues." << endl; 84
73 qDebug("KConfig::readIntListEntry: error while reading one of the intvalues."); 85 qDebug("KConfig::readIntListEntry: error while reading one of the intvalues.");
74 } 86 }
75 87
76 return result; 88 return result;
77} 89}
78 90
79int KConfig::readNumEntry( const QString & key, int def ) 91int KConfig::readNumEntry( const QString & key, int def )
80{ 92{
81 QString res = readEntry(key, QString::number(def ) ); 93 QString res = readEntry(key, QString::number(def ) );
82 bool ok = false; 94 bool ok = false;
83 int result = res.toInt(&ok); 95 int result = res.toInt(&ok);
84 if ( ok ) 96 if ( ok )
85 return result; 97 return result;
86 return def; 98 return def;
87} 99}
88 100
89QString KConfig::readEntry( const QString &key, const QString &def ) 101QString KConfig::readEntry( const QString &key, const QString &def )
90{ 102{
91 QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key ); 103 QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key );
92 104
93 if ( it == mStringMap.end() ) { 105 if ( it == mStringMap.end() ) {
94 return def; 106 return def;
95 } 107 }
96 108
97 return *it; 109 return *it;
98} 110}
99 111
100QStringList KConfig::readListEntry( const QString &key ) 112QStringList KConfig::readListEntry( const QString &key )
101{ 113{
102 QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key ); 114 QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key );
103 115
104 if ( it == mStringMap.end() ) { 116 if ( it == mStringMap.end() ) {
105 return QStringList(); 117 return QStringList();
106 } 118 }
107 return QStringList::split(":", *it ); 119 return QStringList::split(":", *it );
108 120
109} 121}
110 122
111bool KConfig::readBoolEntry( const QString &key, bool def ) 123bool KConfig::readBoolEntry( const QString &key, bool def )
112{ 124{
113 QMap<QString,bool>::ConstIterator it = mBoolMap.find( mGroup + key ); 125 QMap<QString,bool>::ConstIterator it = mBoolMap.find( mGroup + key );
114 126
115 if ( it == mBoolMap.end() ) { 127 if ( it == mBoolMap.end() ) {
116 return def; 128 return def;
117 } 129 }
118 130
119 return *it; 131 return *it;
120} 132}
121 133
122QColor KConfig::readColorEntry( const QString & e, QColor *def ) 134QColor KConfig::readColorEntry( const QString & e, QColor *def )
123{ 135{
124 136
125 QStringList l; 137 QStringList l;
126 l = readListEntry( e ); 138 l = readListEntry( e );
127 if (l.count() != 3 ) { 139 if (l.count() != 3 ) {
128 if ( def ) 140 if ( def )
129 return *def; 141 return *def;
130 else 142 else
131 return QColor(); 143 return QColor();
132 } 144 }
133 QColor c ( l[0].toInt(), l[1].toInt(), l[2].toInt() ); 145 QColor c ( l[0].toInt(), l[1].toInt(), l[2].toInt() );
134 return c; 146 return c;
135} 147}
136 148
137QFont KConfig::readFontEntry( const QString & e, QFont *def ) 149QFont KConfig::readFontEntry( const QString & e, QFont *def )
138{ 150{
139 QStringList font = readListEntry( e ); 151 QStringList font = readListEntry( e );
140 if ( font.isEmpty() ) 152 if ( font.isEmpty() )
141 return *def; 153 return *def;
142 QFont f; 154 QFont f;
143 f.setFamily( font[0]); 155 f.setFamily( font[0]);
144 f.setBold ( font[1] == "bold"); 156 f.setBold ( font[1] == "bold");
145 f.setPointSize ( font[2].toInt()); 157 f.setPointSize ( font[2].toInt());
146 f.setItalic( font[3] == "italic" ); 158 f.setItalic( font[3] == "italic" );
147 return f; 159 return f;
148} 160}
149 161
150QDateTime KConfig::readDateTimeEntry( const QString &key, const QDateTime *def ) 162QDateTime KConfig::readDateTimeEntry( const QString &key, const QDateTime *def )
151{ 163{
152 QMap<QString,QDateTime>::ConstIterator it = mDateTimeMap.find( mGroup + key ); 164 QMap<QString,QDateTime>::ConstIterator it = mDateTimeMap.find( mGroup + key );
153 165
154 if ( it == mDateTimeMap.end() ) { 166 if ( it == mDateTimeMap.end() ) {
155 if ( def ) return *def; 167 if ( def ) return *def;
156 else return QDateTime(); 168 else return QDateTime();
157 } 169 }
158 170
159 return *it; 171 return *it;
160} 172}
161 173
162//US added method 174//US added method
163void KConfig::writeEntry( const QString &key, const QValueList<int> &value) 175void KConfig::writeEntry( const QString &key, const QValueList<int> &value)
164{ 176{
165 QStringList valuesAsStrings; 177 QStringList valuesAsStrings;
166 178
167 QValueList<int>::ConstIterator it; 179 QValueList<int>::ConstIterator it;
168 180
169 for( it = value.begin(); it != value.end(); ++it ) 181 for( it = value.begin(); it != value.end(); ++it )
170 { 182 {
171 valuesAsStrings << QString::number(*it); 183 valuesAsStrings << QString::number(*it);
172 } 184 }
173 185
174 mStringMap.insert( mGroup + key, valuesAsStrings.join(":") ); 186 mStringMap.insert( mGroup + key, valuesAsStrings.join(":") );
175 mDirty = true; 187 mDirty = true;
176} 188}
177 189
178void KConfig::writeEntry( const QString & key , int num ) 190void KConfig::writeEntry( const QString & key , int num )
179{ 191{
180 writeEntry( key, QString::number ( num ) ); 192 writeEntry( key, QString::number ( num ) );
181} 193}
182 194
183void KConfig::writeEntry( const QString &key, const QString &value ) 195void KConfig::writeEntry( const QString &key, const QString &value )
184{ 196{
185 mStringMap.insert( mGroup + key, value ); 197 mStringMap.insert( mGroup + key, value );
186 198
187 mDirty = true; 199 mDirty = true;
188} 200}
189 201
190void KConfig::writeEntry( const QString &key, const QStringList &value ) 202void KConfig::writeEntry( const QString &key, const QStringList &value )
191{ 203{
192 mStringMap.insert( mGroup + key, value.join(":") ); 204 mStringMap.insert( mGroup + key, value.join(":") );
193 205
194 mDirty = true; 206 mDirty = true;
195} 207}
196 208
197void KConfig::writeEntry( const QString &key, bool value) 209void KConfig::writeEntry( const QString &key, bool value)
198{ 210{
199 mBoolMap.insert( mGroup + key, value ); 211 mBoolMap.insert( mGroup + key, value );
200 212
201 mDirty = true; 213 mDirty = true;
202} 214}
203 215
204void KConfig::writeEntry( const QString & e, const QColor & c ) 216void KConfig::writeEntry( const QString & e, const QColor & c )
205{ 217{
206 QStringList l; 218 QStringList l;
207 l.append( QString::number ( c.red() ) ); 219 l.append( QString::number ( c.red() ) );
208 l.append( QString::number ( c.green() ) ); 220 l.append( QString::number ( c.green() ) );
209 l.append( QString::number ( c.blue() ) ); 221 l.append( QString::number ( c.blue() ) );
210 writeEntry( e, l ); 222 writeEntry( e, l );
211} 223}
212 224
213void KConfig::writeEntry( const QString & e , const QFont & f ) 225void KConfig::writeEntry( const QString & e , const QFont & f )
214{ 226{
215 QStringList font; 227 QStringList font;
216 font.append( f.family()); 228 font.append( f.family());
217 font.append( (!f.bold ()?"nonbold":"bold") ); 229 font.append( (!f.bold ()?"nonbold":"bold") );
218 font.append( QString::number ( f.pointSize () ) ); 230 font.append( QString::number ( f.pointSize () ) );
219 font.append( !f.italic ()?"nonitalic":"italic" ); 231 font.append( !f.italic ()?"nonitalic":"italic" );
220 writeEntry( e, font ); 232 writeEntry( e, font );
221} 233}
222 234
223void KConfig::writeEntry( const QString &key, const QDateTime &dt ) 235void KConfig::writeEntry( const QString &key, const QDateTime &dt )
224{ 236{
225 mDateTimeMap.insert( mGroup + key, dt ); 237 mDateTimeMap.insert( mGroup + key, dt );
226} 238}
227 239
228void KConfig::load() 240void KConfig::load()
229{ 241{
230 kdDebug() << "KConfig::load(): " << mFileName << endl; 242
231 243
232 QFile f( mFileName ); 244 QFile f( mFileName );
233 if ( !f.open( IO_ReadOnly ) ) { 245 if ( !f.open( IO_ReadOnly ) ) {
234 qDebug("KConfig: could not open file %s ",mFileName.latin1() ); 246 qDebug("KConfig: could not open file %s ",mFileName.latin1() );
235 return; 247 return;
236 } 248 }
237 249
238 mBoolMap.clear(); 250 mBoolMap.clear();
239 mStringMap.clear(); 251 mStringMap.clear();
240 252
241 QTextStream t( &f ); 253 QTextStream t( &f );
242 254
243 QString line = t.readLine(); 255 QString line = t.readLine();
244 256
245 while ( !line.isNull() ) { 257 while ( !line.isNull() ) {
246 QStringList tokens = QStringList::split( ",", line ); 258 QStringList tokens = QStringList::split( ",", line );
247 if ( tokens[0] == "bool" ) { 259 if ( tokens[0] == "bool" ) {
248 bool value = false; 260 bool value = false;
249 if ( tokens[2] == "1" ) value = true; 261 if ( tokens[2] == "1" ) value = true;
250 mBoolMap.insert( tokens[1], value ); 262 mBoolMap.insert( tokens[1], value );
251 } else if ( tokens[0] == "QString" ) { 263 } else if ( tokens[0] == "QString" ) {
252 QString value = tokens[2]; 264 QString value = tokens[2];
253 mStringMap.insert( tokens[1], value ); 265 mStringMap.insert( tokens[1], value );
254 } else if ( tokens[0] == "QDateTime" ) { 266 } else if ( tokens[0] == "QDateTime" ) {
255#if 0 267#if 0
256 int year = tokens[2].toInt(); 268 int year = tokens[2].toInt();
257 QDateTime dt( QDate( year, 269 QDateTime dt( QDate( year,
258 tokens[3].toInt(), 270 tokens[3].toInt(),
259 tokens[4].toInt() ), 271 tokens[4].toInt() ),
260 QTime( tokens[5].toInt(), tokens[6].toInt(), 272 QTime( tokens[5].toInt(), tokens[6].toInt(),
261 tokens[7].toInt() ) ); 273 tokens[7].toInt() ) );
262 mDateTimeMap.insert( tokens[1], dt ); 274 mDateTimeMap.insert( tokens[1], dt );
263#endif 275#endif
264 } 276 }
265 277
266 line = t.readLine(); 278 line = t.readLine();
267 } 279 }
268} 280}
269 281
270void KConfig::sync() 282void KConfig::sync()
271{ 283{
272 284
273 if ( !mDirty ) return; 285 if ( !mDirty ) return;
274 //qDebug("KConfig::sync() %s ",mFileName.latin1() ); 286 //qDebug("KConfig::sync() %s ",mFileName.latin1() );
275 //kdDebug() << "KConfig::sync(): " << mFileName << endl; 287 //kdDebug() << "KConfig::sync(): " << mFileName << endl;
276 288
277//US I took the following code from a newer version of KDE 289//US I took the following code from a newer version of KDE
278 // Create the containing dir if needed 290 // Create the containing dir if needed
279 KURL path; 291 KURL path;
280 path.setPath(mFileName); 292 path.setPath(mFileName);
281 QString dir=path.directory(); 293 QString dir=path.directory();
282 KStandardDirs::makeDir(dir); 294 KStandardDirs::makeDir(dir);
283 295
284 QFile f( mFileName ); 296 QFile f( mFileName );
285 if ( !f.open( IO_WriteOnly ) ) { 297 if ( !f.open( IO_WriteOnly ) ) {
286 298
287 qDebug("KConfig::sync() Can't open file %s ",mFileName.latin1() ); 299 qDebug("KConfig::sync() Can't open file %s ",mFileName.latin1() );
288 300
289 return; 301 return;
290 } 302 }
291 303
292 QTextStream t( &f ); 304 QTextStream t( &f );
293 305
294 QMap<QString,bool>::ConstIterator itBool; 306 QMap<QString,bool>::ConstIterator itBool;
295 for( itBool = mBoolMap.begin(); itBool != mBoolMap.end(); ++itBool ) { 307 for( itBool = mBoolMap.begin(); itBool != mBoolMap.end(); ++itBool ) {
296 t << "bool," << itBool.key() << "," << ( *itBool ? "1" : "0" ) << endl; 308 t << "bool," << itBool.key() << "," << ( *itBool ? "1" : "0" ) << endl;
297 } 309 }
298 310
299 QMap<QString,QString>::ConstIterator itString; 311 QMap<QString,QString>::ConstIterator itString;
300 for( itString = mStringMap.begin(); itString != mStringMap.end(); ++itString ) { 312 for( itString = mStringMap.begin(); itString != mStringMap.end(); ++itString ) {
301 t << "QString," << itString.key() << "," << (*itString ) << endl; 313 t << "QString," << itString.key() << "," << (*itString ) << endl;
302 } 314 }
303 315
304 QMap<QString,QDateTime>::ConstIterator itDateTime; 316 QMap<QString,QDateTime>::ConstIterator itDateTime;
305 for( itDateTime = mDateTimeMap.begin(); itDateTime != mDateTimeMap.end(); ++itDateTime ) { 317 for( itDateTime = mDateTimeMap.begin(); itDateTime != mDateTimeMap.end(); ++itDateTime ) {
306 QDateTime dt = *itDateTime; 318 QDateTime dt = *itDateTime;
307 t << "QDateTime," << itDateTime.key() << "," 319 t << "QDateTime," << itDateTime.key() << ","
308 << dt.date().year() << "," 320 << dt.date().year() << ","
309 << dt.date().month() << "," 321 << dt.date().month() << ","
310 << dt.date().day() << "," 322 << dt.date().day() << ","
311 << dt.time().hour() << "," 323 << dt.time().hour() << ","
312 << dt.time().minute() << "," 324 << dt.time().minute() << ","
313 << dt.time().second() << endl; 325 << dt.time().second() << endl;
314 } 326 }
315 327
316 f.close(); 328 f.close();
317 329
318 mDirty = false; 330 mDirty = false;
319} 331}
320 332
321 333
322//US I took the following deleteGroup method from a newer version from KDE. 334//US I took the following deleteGroup method from a newer version from KDE.
323/** 335/**
324 * Deletes a configuration entry group 336 * Deletes a configuration entry group
325 * 337 *
326 * If the group is not empty and bDeep is false, nothing gets 338 * If the group is not empty and bDeep is false, nothing gets
327 * deleted and false is returned. 339 * deleted and false is returned.
328 * If this group is the current group and it is deleted, the 340 * If this group is the current group and it is deleted, the
329 * current group is undefined and should be set with setGroup() 341 * current group is undefined and should be set with setGroup()
330 * before the next operation on the configuration object. 342 * before the next operation on the configuration object.
331 * 343 *
332 * @param group The name of the group 344 * @param group The name of the group
333 * returns true if we deleted at least one entry. 345 * returns true if we deleted at least one entry.
334 */ 346 */
335bool KConfig::deleteGroup( const QString& group) 347bool KConfig::deleteGroup( const QString& group)
336{ 348{
337 bool dirty = false; 349 bool dirty = false;
338 int pos; 350 int pos;
339 351
340 QMap<QString,bool>::Iterator itBool = mBoolMap.begin(); 352 QMap<QString,bool>::Iterator itBool = mBoolMap.begin();
341 QMap<QString,bool>::Iterator delBool; 353 QMap<QString,bool>::Iterator delBool;
342 354
343 while ( itBool != mBoolMap.end() ) { 355 while ( itBool != mBoolMap.end() ) {
344 pos = itBool.key().find( group ); 356 pos = itBool.key().find( group );
345 if (pos == 0) { 357 if (pos == 0) {
346 delBool = itBool; 358 delBool = itBool;
347 ++itBool; 359 ++itBool;
348 mBoolMap.remove(delBool); 360 mBoolMap.remove(delBool);
349 dirty = true; 361 dirty = true;
350 } else 362 } else
351 ++itBool; 363 ++itBool;
352 364
353 } 365 }
354 /* 366 /*
355 for( itBool = mBoolMap.begin(); itBool != mBoolMap.end(); ++itBool ) 367 for( itBool = mBoolMap.begin(); itBool != mBoolMap.end(); ++itBool )
356 { 368 {
357 pos = itBool.key().find( group ); 369 pos = itBool.key().find( group );
358 if (pos == 0) { 370 if (pos == 0) {
359 mBoolMap.remove(itBool); 371 mBoolMap.remove(itBool);
360 dirty = true; 372 dirty = true;
361 } 373 }
362 } 374 }
363 */ 375 */
364 QMap<QString,QString>::Iterator itString = mStringMap.begin(); 376 QMap<QString,QString>::Iterator itString = mStringMap.begin();
365 QMap<QString,QString>::Iterator delString ; 377 QMap<QString,QString>::Iterator delString ;
366 while( itString != mStringMap.end() ) { 378 while( itString != mStringMap.end() ) {
367 pos = itString.key().find( group ); 379 pos = itString.key().find( group );
368 if (pos == 0) { 380 if (pos == 0) {
369 delString = itString; 381 delString = itString;
370 ++itString; 382 ++itString;
371 mStringMap.remove(delString); 383 mStringMap.remove(delString);
372 //qDebug("delte++++++++++++++++++ "); 384 //qDebug("delte++++++++++++++++++ ");
373 dirty = true; 385 dirty = true;
374 } else 386 } else
375 ++itString; 387 ++itString;
376 388
377 } 389 }
378 /* this leads to a memory access violation 390 /* this leads to a memory access violation
379 for( itString = mStringMap.begin(); itString != mStringMap.end(); ++itString ) 391 for( itString = mStringMap.begin(); itString != mStringMap.end(); ++itString )
380 { 392 {
381 pos = itString.key().find( group ); 393 pos = itString.key().find( group );
382 if (pos == 0) { 394 if (pos == 0) {
383 mStringMap.remove(itString); 395 mStringMap.remove(itString);
384 dirty = true; 396 dirty = true;
385 } 397 }
386 } 398 }
387 */ 399 */
388 QMap<QString,QDateTime>::Iterator itDateTime= mDateTimeMap.begin(); 400 QMap<QString,QDateTime>::Iterator itDateTime= mDateTimeMap.begin();
389 QMap<QString,QDateTime>::Iterator delDateTime; 401 QMap<QString,QDateTime>::Iterator delDateTime;
390 while ( itDateTime != mDateTimeMap.end() ) { 402 while ( itDateTime != mDateTimeMap.end() ) {
391 pos = itDateTime.key().find( group ); 403 pos = itDateTime.key().find( group );
392 if (pos == 0) { 404 if (pos == 0) {
393 delDateTime = itDateTime; 405 delDateTime = itDateTime;
394 ++itDateTime; 406 ++itDateTime;
395 mDateTimeMap.remove(delDateTime); 407 mDateTimeMap.remove(delDateTime);
396 dirty = true; 408 dirty = true;
397 } else 409 } else
398 ++itDateTime; 410 ++itDateTime;
399 411
400 } 412 }
401 /* 413 /*
402 for( itDateTime = mDateTimeMap.begin(); itDateTime != mDateTimeMap.end(); ++itDateTime ) 414 for( itDateTime = mDateTimeMap.begin(); itDateTime != mDateTimeMap.end(); ++itDateTime )
403 { 415 {
404 pos = itDateTime.key().find( group ); 416 pos = itDateTime.key().find( group );
405 if (pos == 0) { 417 if (pos == 0) {
406 mDateTimeMap.remove(itDateTime); 418 mDateTimeMap.remove(itDateTime);
407 dirty = true; 419 dirty = true;
408 } 420 }
409 } 421 }
410 */ 422 */
411 423
412 if (dirty) 424 if (dirty)
413 mDirty = true; 425 mDirty = true;
414 426
415 return dirty; 427 return dirty;
416 428
417} 429}
418 430
419//US I took the following hasGroup method from a newer version from KDE. 431//US I took the following hasGroup method from a newer version from KDE.
420 /** 432 /**
421 * Returns true if the specified group is known about. 433 * Returns true if the specified group is known about.
422 * 434 *
423 * @param group The group to search for. 435 * @param group The group to search for.
424 * @return Whether the group exists. 436 * @return Whether the group exists.
425 */ 437 */
426bool KConfig::hasGroup(const QString &group) const 438bool KConfig::hasGroup(const QString &group) const
427{ 439{
428 QMap<QString,bool>::ConstIterator itBool; 440 QMap<QString,bool>::ConstIterator itBool;
429 for( itBool = mBoolMap.begin(); itBool != mBoolMap.end(); ++itBool ) 441 for( itBool = mBoolMap.begin(); itBool != mBoolMap.end(); ++itBool )
430 { 442 {
431 if (itBool.key().find( group ) == 0) { 443 if (itBool.key().find( group ) == 0) {
432 return true; 444 return true;
433 } 445 }
434 } 446 }
435 447
436 QMap<QString,QString>::ConstIterator itString; 448 QMap<QString,QString>::ConstIterator itString;
437 for( itString = mStringMap.begin(); itString != mStringMap.end(); ++itString ) 449 for( itString = mStringMap.begin(); itString != mStringMap.end(); ++itString )
438 { 450 {
439 if (itString.key().find( group ) == 0) { 451 if (itString.key().find( group ) == 0) {
440 return true; 452 return true;
441 } 453 }
442 } 454 }
443 455
444 QMap<QString,QDateTime>::ConstIterator itDateTime; 456 QMap<QString,QDateTime>::ConstIterator itDateTime;
445 for( itDateTime = mDateTimeMap.begin(); itDateTime != mDateTimeMap.end(); ++itDateTime ) 457 for( itDateTime = mDateTimeMap.begin(); itDateTime != mDateTimeMap.end(); ++itDateTime )
446 { 458 {
447 if (itDateTime.key().find( group ) == 0) { 459 if (itDateTime.key().find( group ) == 0) {
448 return true; 460 return true;
449 } 461 }
450 } 462 }
451 463
452 return false; 464 return false;
453} 465}
454 466
455void KConfig::deleteEntry( const QString &key) 467void KConfig::deleteEntry( const QString &key)
456{ 468{
457 bool dirty = false; 469 bool dirty = false;
458 470
459 QMap<QString,bool>::Iterator itBool = mBoolMap.find( mGroup + key ); 471 QMap<QString,bool>::Iterator itBool = mBoolMap.find( mGroup + key );
460 if ( itBool != mBoolMap.end() ) { 472 if ( itBool != mBoolMap.end() ) {
461 mBoolMap.remove(itBool); 473 mBoolMap.remove(itBool);
462 dirty = true; 474 dirty = true;
463 } 475 }
464 476
465 477
466 QMap<QString,QString>::Iterator itString = mStringMap.find( mGroup + key ); 478 QMap<QString,QString>::Iterator itString = mStringMap.find( mGroup + key );
467 if ( itString != mStringMap.end() ) { 479 if ( itString != mStringMap.end() ) {
468 mStringMap.remove(itString); 480 mStringMap.remove(itString);
469 dirty = true; 481 dirty = true;
470 } 482 }
471 483
472 484
473 QMap<QString,QDateTime>::Iterator itDateTime = mDateTimeMap.find( mGroup + key ); 485 QMap<QString,QDateTime>::Iterator itDateTime = mDateTimeMap.find( mGroup + key );
474 if ( itDateTime != mDateTimeMap.end() ) { 486 if ( itDateTime != mDateTimeMap.end() ) {
475 mDateTimeMap.remove(itDateTime); 487 mDateTimeMap.remove(itDateTime);
476 dirty = true; 488 dirty = true;
477 } 489 }
478 490
479 if (dirty) 491 if (dirty)
480 mDirty = true; 492 mDirty = true;
481 493
482} 494}
483 495
484//US 496//US
485QString KConfig::getFileName() 497QString KConfig::getFileName()
486{ 498{
487 return mFileName; 499 return mFileName;
488} 500}
489 501
490bool KConfig::hasKey( const QString &key) 502bool KConfig::hasKey( const QString &key)
491{ 503{
492 QMap<QString,bool>::Iterator itBool = mBoolMap.find( mGroup + key ); 504 QMap<QString,bool>::Iterator itBool = mBoolMap.find( mGroup + key );
493 if ( itBool != mBoolMap.end() ) { 505 if ( itBool != mBoolMap.end() ) {
494 return true; 506 return true;
495 } 507 }
496 508
497 QMap<QString,QString>::Iterator itString = mStringMap.find( mGroup + key ); 509 QMap<QString,QString>::Iterator itString = mStringMap.find( mGroup + key );
498 if ( itString != mStringMap.end() ) { 510 if ( itString != mStringMap.end() ) {
499 return true; 511 return true;
500 } 512 }
501 513
502 QMap<QString,QDateTime>::Iterator itDateTime = mDateTimeMap.find( mGroup + key ); 514 QMap<QString,QDateTime>::Iterator itDateTime = mDateTimeMap.find( mGroup + key );
503 if ( itDateTime != mDateTimeMap.end() ) { 515 if ( itDateTime != mDateTimeMap.end() ) {
504 return true; 516 return true;
505 } 517 }
506 518
507 return false; 519 return false;
508} 520}
509 521
diff --git a/microkde/kconfig.h b/microkde/kconfig.h
index bfedf53..a01b1a5 100644
--- a/microkde/kconfig.h
+++ b/microkde/kconfig.h
@@ -1,100 +1,104 @@
1#ifndef MINIKDE_KCONFIG_H 1#ifndef MINIKDE_KCONFIG_H
2#define MINIKDE_KCONFIG_H 2#define MINIKDE_KCONFIG_H
3 3
4#include <qstring.h> 4#include <qstring.h>
5#include <qstringlist.h> 5#include <qstringlist.h>
6#include <qvaluelist.h> 6#include <qvaluelist.h>
7#include <qcolor.h> 7#include <qcolor.h>
8#include <qfont.h> 8#include <qfont.h>
9#include <qmap.h> 9#include <qmap.h>
10#include <qdatetime.h> 10#include <qdatetime.h>
11 11
12class KConfig 12class KConfig
13{ 13{
14 public: 14 public:
15 KConfig( const QString & ); 15 KConfig( const QString & );
16 ~KConfig(); 16 ~KConfig();
17 17
18 void setTempGroup( const QString &group );
19 QString tempGroup() const;
20
18 void setGroup( const QString & ); 21 void setGroup( const QString & );
19 22
20//US 23//US
21 /** 24 /**
22 * Returns the name of the group in which we are 25 * Returns the name of the group in which we are
23 * searching for keys and from which we are retrieving entries. 26 * searching for keys and from which we are retrieving entries.
24 * 27 *
25 * @return The current group. 28 * @return The current group.
26 */ 29 */
27 QString group() const; 30 QString group() const;
28 31
29//US I took the following deleteGroup method from a newer version from KDE. 32//US I took the following deleteGroup method from a newer version from KDE.
30/** 33/**
31 * Deletes a configuration entry group 34 * Deletes a configuration entry group
32 * 35 *
33 * If the group is not empty and bDeep is false, nothing gets 36 * If the group is not empty and bDeep is false, nothing gets
34 * deleted and false is returned. 37 * deleted and false is returned.
35 * If this group is the current group and it is deleted, the 38 * If this group is the current group and it is deleted, the
36 * current group is undefined and should be set with setGroup() 39 * current group is undefined and should be set with setGroup()
37 * before the next operation on the configuration object. 40 * before the next operation on the configuration object.
38 * 41 *
39 * @param group The name of the group 42 * @param group The name of the group
40 * returns true if we deleted at least one entry. 43 * returns true if we deleted at least one entry.
41 */ 44 */
42 bool deleteGroup( const QString& group); 45 bool deleteGroup( const QString& group);
43 46
44//US I took the following hasGroup method from a newer version from KDE. 47//US I took the following hasGroup method from a newer version from KDE.
45 /** 48 /**
46 * Returns true if the specified group is known about. 49 * Returns true if the specified group is known about.
47 * 50 *
48 * @param group The group to search for. 51 * @param group The group to search for.
49 * @return Whether the group exists. 52 * @return Whether the group exists.
50 */ 53 */
51 bool hasGroup(const QString &group) const; 54 bool hasGroup(const QString &group) const;
52 55
53 56
54 QString getFileName(); 57 QString getFileName();
55 58
56//US added method readIntListEntry 59//US added method readIntListEntry
57 QValueList<int> readIntListEntry( const QString &); 60 QValueList<int> readIntListEntry( const QString &);
58 61
59 int readNumEntry( const QString &, int def=0 ); 62 int readNumEntry( const QString &, int def=0 );
60 QString readEntry( const QString &, const QString &def=QString::null ); 63 QString readEntry( const QString &, const QString &def=QString::null );
61 QStringList readListEntry( const QString & ); 64 QStringList readListEntry( const QString & );
62 bool readBoolEntry( const QString &, bool def=false ); 65 bool readBoolEntry( const QString &, bool def=false );
63 QColor readColorEntry( const QString &, QColor * ); 66 QColor readColorEntry( const QString &, QColor * );
64 QFont readFontEntry( const QString &, QFont * ); 67 QFont readFontEntry( const QString &, QFont * );
65 QDateTime readDateTimeEntry( const QString &, const QDateTime *pDefault = 0 ); 68 QDateTime readDateTimeEntry( const QString &, const QDateTime *pDefault = 0 );
66 69
67 bool hasKey( const QString &); 70 bool hasKey( const QString &);
68 71
69 void writeEntry( const QString &, const QValueList<int>& ); 72 void writeEntry( const QString &, const QValueList<int>& );
70 void writeEntry( const QString &, int ); 73 void writeEntry( const QString &, int );
71 void writeEntry( const QString &key , unsigned int value) { writeEntry( key, int( value ) ); } 74 void writeEntry( const QString &key , unsigned int value) { writeEntry( key, int( value ) ); }
72 void writeEntry( const char *key , unsigned int value) { writeEntry( QString( key ), value ); } 75 void writeEntry( const char *key , unsigned int value) { writeEntry( QString( key ), value ); }
73 void writeEntry( const char *key, int value ) { writeEntry( QString( key ), value ); } 76 void writeEntry( const char *key, int value ) { writeEntry( QString( key ), value ); }
74 void writeEntry( const QString &, const QString & ); 77 void writeEntry( const QString &, const QString & );
75 void writeEntry( const char *key, const QString &value ) { writeEntry( QString( key ), value ); } 78 void writeEntry( const char *key, const QString &value ) { writeEntry( QString( key ), value ); }
76 void writeEntry( const QString &, const QStringList & ); 79 void writeEntry( const QString &, const QStringList & );
77 void writeEntry( const QString &, bool ); 80 void writeEntry( const QString &, bool );
78 void writeEntry( const char *key, bool value ) { writeEntry( QString( key ), value ); } 81 void writeEntry( const char *key, bool value ) { writeEntry( QString( key ), value ); }
79 void writeEntry( const QString &, const QColor & ); 82 void writeEntry( const QString &, const QColor & );
80 void writeEntry( const QString &, const QFont & ); 83 void writeEntry( const QString &, const QFont & );
81 void writeEntry( const QString &, const QDateTime & ); 84 void writeEntry( const QString &, const QDateTime & );
82 85
83 void deleteEntry( const QString &); 86 void deleteEntry( const QString &);
84 87
85 void load(); 88 void load();
86 void sync(); 89 void sync();
87 90
88 private: 91 private:
89 static QString mGroup; 92 static QString mGroup;
93 QString mTempGroup;
90 94
91 QString mFileName; 95 QString mFileName;
92 96
93 QMap<QString,bool> mBoolMap; 97 QMap<QString,bool> mBoolMap;
94 QMap<QString,QString> mStringMap; 98 QMap<QString,QString> mStringMap;
95 QMap<QString,QDateTime> mDateTimeMap; 99 QMap<QString,QDateTime> mDateTimeMap;
96 100
97 bool mDirty; 101 bool mDirty;
98}; 102};
99 103
100#endif 104#endif
diff --git a/microkde/kresources/managerimpl.cpp b/microkde/kresources/managerimpl.cpp
index 1baa6be..785b6b4 100644
--- a/microkde/kresources/managerimpl.cpp
+++ b/microkde/kresources/managerimpl.cpp
@@ -1,353 +1,358 @@
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#include <kglobal.h> 24#include <kglobal.h>
25 25
26#include <kapplication.h> 26#include <kapplication.h>
27#include <kdebug.h> 27#include <kdebug.h>
28#include <kconfig.h> 28#include <kconfig.h>
29#include <kstandarddirs.h> 29#include <kstandarddirs.h>
30 30
31#include "resource.h" 31#include "resource.h"
32#include "factory.h" 32#include "factory.h"
33#include "managerimpl.h" 33#include "managerimpl.h"
34 34
35using namespace KRES; 35using namespace KRES;
36 36
37ManagerImpl::ManagerImpl( const QString &family ) 37ManagerImpl::ManagerImpl( const QString &family )
38 : mFamily( family ), mConfig( 0 ), mStdConfig( 0 ), mStandard( 0 ), 38 : mFamily( family ), mConfig( 0 ), mStdConfig( 0 ), mStandard( 0 ),
39 mFactory( 0 ) 39 mFactory( 0 )
40 40
41{ 41{
42 kdDebug(5650) << "ManagerImpl::ManagerImpl()" << endl; 42 kdDebug(5650) << "ManagerImpl::ManagerImpl()" << endl;
43 43
44 44
45} 45}
46 46
47ManagerImpl::~ManagerImpl() 47ManagerImpl::~ManagerImpl()
48{ 48{
49 kdDebug(5650) << "ManagerImpl::~ManagerImpl()" << endl; 49 kdDebug(5650) << "ManagerImpl::~ManagerImpl()" << endl;
50 50
51 Resource::List::ConstIterator it; 51 Resource::List::ConstIterator it;
52 for ( it = mResources.begin(); it != mResources.end(); ++it ) { 52 for ( it = mResources.begin(); it != mResources.end(); ++it ) {
53 delete *it; 53 delete *it;
54 } 54 }
55 55
56 delete mStdConfig; 56 delete mStdConfig;
57} 57}
58 58
59void ManagerImpl::createStandardConfig() 59void ManagerImpl::createStandardConfig()
60{ 60{
61 if ( !mStdConfig ) { 61 if ( !mStdConfig ) {
62 QString file = locateLocal( "data", KGlobal::getAppName() 62 QString file = locateLocal( "data", KGlobal::getAppName()
63 + "/kresources/" + mFamily + "rc" ); 63 + "/kresources/" + mFamily + "rc" );
64 mStdConfig = new KConfig( file ); 64 mStdConfig = new KConfig( file );
65 } 65 }
66 66
67 mConfig = mStdConfig; 67 mConfig = mStdConfig;
68} 68}
69 69
70void ManagerImpl::readConfig( KConfig *cfg ) 70void ManagerImpl::readConfig( KConfig *cfg )
71{ 71{
72 kdDebug(5650) << "ManagerImpl::readConfig()" << endl; 72 kdDebug(5650) << "ManagerImpl::readConfig()" << endl;
73 73
74 delete mFactory; 74 delete mFactory;
75 mFactory = Factory::self( mFamily ); 75 mFactory = Factory::self( mFamily );
76 76
77 if ( !cfg ) { 77 if ( !cfg ) {
78 createStandardConfig(); 78 createStandardConfig();
79 } else { 79 } else {
80 mConfig = cfg; 80 mConfig = cfg;
81 } 81 }
82 82
83 mStandard = 0; 83 mStandard = 0;
84 84
85 mConfig->setGroup( "General" ); 85 mConfig->setGroup( "General" );
86 86
87 QStringList keys = mConfig->readListEntry( "ResourceKeys" ); 87 QStringList keys = mConfig->readListEntry( "ResourceKeys" );
88 keys += mConfig->readListEntry( "PassiveResourceKeys" ); 88 keys += mConfig->readListEntry( "PassiveResourceKeys" );
89 89
90 QString standardKey = mConfig->readEntry( "Standard" ); 90 QString standardKey = mConfig->readEntry( "Standard" );
91 91
92 for ( QStringList::Iterator it = keys.begin(); it != keys.end(); ++it ) { 92 for ( QStringList::Iterator it = keys.begin(); it != keys.end(); ++it ) {
93 readResourceConfig( *it, false ); 93 readResourceConfig( *it, false );
94 } 94 }
95 95
96} 96}
97 97
98void ManagerImpl::writeConfig( KConfig *cfg ) 98void ManagerImpl::writeConfig( KConfig *cfg )
99{ 99{
100//USqDebug("ManagerImpl::writeConfig begin this= %ul cfg=%ul", this, cfg); 100//USqDebug("ManagerImpl::writeConfig begin this= %ul cfg=%ul", this, cfg);
101 101
102 102
103 kdDebug(5650) << "ManagerImpl::writeConfig()" << endl; 103 kdDebug(5650) << "ManagerImpl::writeConfig()" << endl;
104 104
105 if ( !cfg ) { 105 if ( !cfg ) {
106 createStandardConfig(); 106 createStandardConfig();
107 } else { 107 } else {
108 mConfig = cfg; 108 mConfig = cfg;
109 } 109 }
110 110
111 QStringList activeKeys; 111 QStringList activeKeys;
112 QStringList passiveKeys; 112 QStringList passiveKeys;
113 113
114 // First write all keys, collect active and passive keys on the way 114 // First write all keys, collect active and passive keys on the way
115 Resource::List::Iterator it; 115 Resource::List::Iterator it;
116 for ( it = mResources.begin(); it != mResources.end(); ++it ) { 116 for ( it = mResources.begin(); it != mResources.end(); ++it ) {
117 writeResourceConfig( *it, false ); 117 writeResourceConfig( *it, false );
118 118
119 QString key = (*it)->identifier(); 119 QString key = (*it)->identifier();
120 if( (*it)->isActive() ) 120 if( (*it)->isActive() )
121 activeKeys.append( key ); 121 activeKeys.append( key );
122 else 122 else
123 passiveKeys.append( key ); 123 passiveKeys.append( key );
124 } 124 }
125 125
126 // And then the general group 126 // And then the general group
127 127
128 kdDebug(5650) << "Saving general info" << endl; 128 kdDebug(5650) << "Saving general info" << endl;
129 mConfig->setGroup( "General" ); 129 mConfig->setGroup( "General" );
130 mConfig->writeEntry( "ResourceKeys", activeKeys ); 130 mConfig->writeEntry( "ResourceKeys", activeKeys );
131 mConfig->writeEntry( "PassiveResourceKeys", passiveKeys ); 131 mConfig->writeEntry( "PassiveResourceKeys", passiveKeys );
132 if ( mStandard ) 132 if ( mStandard )
133 mConfig->writeEntry( "Standard", mStandard->identifier() ); 133 mConfig->writeEntry( "Standard", mStandard->identifier() );
134 else 134 else
135 mConfig->writeEntry( "Standard", "" ); 135 mConfig->writeEntry( "Standard", "" );
136 136
137 mConfig->sync(); 137 mConfig->sync();
138 kdDebug(5650) << "ManagerImpl::save() finished" << endl; 138 kdDebug(5650) << "ManagerImpl::save() finished" << endl;
139 139
140//US qDebug("ManagerImpl::writeConfig end this= %ul cfg=%ul", this, cfg); 140//US qDebug("ManagerImpl::writeConfig end this= %ul cfg=%ul", this, cfg);
141 141
142} 142}
143 143
144void ManagerImpl::add( Resource *resource, bool useDCOP ) 144void ManagerImpl::add( Resource *resource, bool useDCOP )
145{ 145{
146qDebug("ManagerImpl::add begin this= %ul resource=%ul", this, resource); 146qDebug("ManagerImpl::add begin this= %ul resource=%ul", this, resource);
147 147
148 resource->setActive( true ); 148 resource->setActive( true );
149 149
150 if ( mResources.isEmpty() ) { 150 if ( mResources.isEmpty() ) {
151 mStandard = resource; 151 mStandard = resource;
152 } 152 }
153 153
154 mResources.append( resource ); 154 mResources.append( resource );
155 155
156 writeResourceConfig( resource, true ); 156 writeResourceConfig( resource, true );
157 157
158 qDebug("ManagerImpl::add end this= %ul resource=%ul", this, resource); 158 qDebug("ManagerImpl::add end this= %ul resource=%ul", this, resource);
159 159
160} 160}
161 161
162void ManagerImpl::remove( Resource *resource, bool useDCOP ) 162void ManagerImpl::remove( Resource *resource, bool useDCOP )
163{ 163{
164 if ( mStandard == resource ) mStandard = 0; 164 if ( mStandard == resource ) mStandard = 0;
165 removeResource( resource ); 165 removeResource( resource );
166 166
167 mResources.remove( resource ); 167 mResources.remove( resource );
168 168
169 delete resource; 169 delete resource;
170 170
171 kdDebug(5650) << "Finished ManagerImpl::remove()" << endl; 171 kdDebug(5650) << "Finished ManagerImpl::remove()" << endl;
172} 172}
173 173
174void ManagerImpl::setActive( Resource *resource, bool active ) 174void ManagerImpl::setActive( Resource *resource, bool active )
175{ 175{
176 if ( resource && resource->isActive() != active ) { 176 if ( resource && resource->isActive() != active ) {
177 resource->setActive( active ); 177 resource->setActive( active );
178 } 178 }
179} 179}
180 180
181Resource *ManagerImpl::standardResource() 181Resource *ManagerImpl::standardResource()
182{ 182{
183 return mStandard; 183 return mStandard;
184} 184}
185 185
186void ManagerImpl::setStandardResource( Resource *resource ) 186void ManagerImpl::setStandardResource( Resource *resource )
187{ 187{
188 mStandard = resource; 188 mStandard = resource;
189} 189}
190 190
191void ManagerImpl::resourceChanged( Resource *resource ) 191void ManagerImpl::resourceChanged( Resource *resource )
192{ 192{
193 writeResourceConfig( resource, true ); 193 writeResourceConfig( resource, true );
194 194
195 195
196// ManagerIface_stub allManagers( "*", "ManagerIface_" + mFamily.utf8() ); 196// ManagerIface_stub allManagers( "*", "ManagerIface_" + mFamily.utf8() );
197// allManagers.dcopResourceModified( resource->identifier() ); 197// allManagers.dcopResourceModified( resource->identifier() );
198} 198}
199 199
200// DCOP asynchronous functions 200// DCOP asynchronous functions
201//US since we work from inside the application, we call the methods directly. 201//US since we work from inside the application, we call the methods directly.
202 202
203QStringList ManagerImpl::resourceNames() 203QStringList ManagerImpl::resourceNames()
204{ 204{
205 QStringList result; 205 QStringList result;
206 206
207 Resource::List::ConstIterator it; 207 Resource::List::ConstIterator it;
208 for ( it = mResources.begin(); it != mResources.end(); ++it ) { 208 for ( it = mResources.begin(); it != mResources.end(); ++it ) {
209 result.append( (*it)->resourceName() ); 209 result.append( (*it)->resourceName() );
210 } 210 }
211 return result; 211 return result;
212} 212}
213 213
214Resource::List *ManagerImpl::resourceList() 214Resource::List *ManagerImpl::resourceList()
215{ 215{
216 return &mResources; 216 return &mResources;
217} 217}
218 218
219QPtrList<Resource> ManagerImpl::resources() 219QPtrList<Resource> ManagerImpl::resources()
220{ 220{
221 QPtrList<Resource> result; 221 QPtrList<Resource> result;
222 222
223 Resource::List::ConstIterator it; 223 Resource::List::ConstIterator it;
224 for ( it = mResources.begin(); it != mResources.end(); ++it ) { 224 for ( it = mResources.begin(); it != mResources.end(); ++it ) {
225 result.append( *it ); 225 result.append( *it );
226 } 226 }
227 return result; 227 return result;
228} 228}
229 229
230QPtrList<Resource> ManagerImpl::resources( bool active ) 230QPtrList<Resource> ManagerImpl::resources( bool active )
231{ 231{
232 QPtrList<Resource> result; 232 QPtrList<Resource> result;
233 233
234 Resource::List::ConstIterator it; 234 Resource::List::ConstIterator it;
235 for ( it = mResources.begin(); it != mResources.end(); ++it ) { 235 for ( it = mResources.begin(); it != mResources.end(); ++it ) {
236 if ( (*it)->isActive() == active ) { 236 if ( (*it)->isActive() == active ) {
237 result.append( *it ); 237 result.append( *it );
238 } 238 }
239 } 239 }
240 return result; 240 return result;
241} 241}
242 242
243void ManagerImpl::setListener( ManagerImplListener *listener ) 243void ManagerImpl::setListener( ManagerImplListener *listener )
244{ 244{
245 mListener = listener; 245 mListener = listener;
246} 246}
247 247
248Resource* ManagerImpl::readResourceConfig( const QString& identifier, 248Resource* ManagerImpl::readResourceConfig( const QString& identifier,
249 bool checkActive ) 249 bool checkActive )
250{ 250{
251 kdDebug() << "ManagerImpl::readResourceConfig() " << identifier << endl; 251 kdDebug() << "ManagerImpl::readResourceConfig() " << identifier << endl;
252 252
253// qDebug("ManagerImpl::readResourceConfig() %s", identifier.latin1()); 253// qDebug("ManagerImpl::readResourceConfig() %s", identifier.latin1());
254 254
255 mConfig->setGroup( "Resource_" + identifier ); 255 mConfig->setGroup( "Resource_" + identifier );
256 256#ifdef _WIN32_
257 // we use plugins on win32. the group is stored in a static variable
258 // such that gourp info not avail on win32 plugins
259 // to fix that, it would be a looooot of work
260 mConfig->setTempGroup( "Resource_" + identifier );
261#endif
257 QString type = mConfig->readEntry( "ResourceType" ); 262 QString type = mConfig->readEntry( "ResourceType" );
258 QString name = mConfig->readEntry( "ResourceName" ); 263 QString name = mConfig->readEntry( "ResourceName" );
259 Resource *resource = mFactory->resource( type, mConfig ); 264 Resource *resource = mFactory->resource( type, mConfig );
260 if ( !resource ) { 265 if ( !resource ) {
261 kdDebug(5650) << "Failed to create resource with id " << identifier << endl; 266 qDebug("Failed to create resource with id %s ",identifier.latin1() );
262 return 0; 267 return 0;
263 } 268 }
264 269
265 if ( resource->identifier().isEmpty() ) 270 if ( resource->identifier().isEmpty() )
266 resource->setIdentifier( identifier ); 271 resource->setIdentifier( identifier );
267 272
268 mConfig->setGroup( "General" ); 273 mConfig->setGroup( "General" );
269 274
270 QString standardKey = mConfig->readEntry( "Standard" ); 275 QString standardKey = mConfig->readEntry( "Standard" );
271 if ( standardKey == identifier ) { 276 if ( standardKey == identifier ) {
272 mStandard = resource; 277 mStandard = resource;
273 } 278 }
274 279
275 if ( checkActive ) { 280 if ( checkActive ) {
276 QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" ); 281 QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" );
277 resource->setActive( activeKeys.contains( identifier ) ); 282 resource->setActive( activeKeys.contains( identifier ) );
278 } 283 }
279 mResources.append( resource ); 284 mResources.append( resource );
280 285
281 return resource; 286 return resource;
282} 287}
283 288
284void ManagerImpl::writeResourceConfig( Resource *resource, 289void ManagerImpl::writeResourceConfig( Resource *resource,
285 bool checkActive ) 290 bool checkActive )
286{ 291{
287 QString key = resource->identifier(); 292 QString key = resource->identifier();
288 293
289 kdDebug(5650) << "Saving resource " << key << endl; 294 kdDebug(5650) << "Saving resource " << key << endl;
290 295
291 if ( !mConfig ) createStandardConfig(); 296 if ( !mConfig ) createStandardConfig();
292 297
293 mConfig->setGroup( "Resource_" + key ); 298 mConfig->setGroup( "Resource_" + key );
294 resource->writeConfig( mConfig ); 299 resource->writeConfig( mConfig );
295 300
296 mConfig->setGroup( "General" ); 301 mConfig->setGroup( "General" );
297 QString standardKey = mConfig->readEntry( "Standard" ); 302 QString standardKey = mConfig->readEntry( "Standard" );
298 303
299 if ( resource == mStandard && standardKey != key ) 304 if ( resource == mStandard && standardKey != key )
300 mConfig->writeEntry( "Standard", resource->identifier() ); 305 mConfig->writeEntry( "Standard", resource->identifier() );
301 else if ( resource != mStandard && standardKey == key ) 306 else if ( resource != mStandard && standardKey == key )
302 mConfig->writeEntry( "Standard", "" ); 307 mConfig->writeEntry( "Standard", "" );
303 308
304 if ( checkActive ) { 309 if ( checkActive ) {
305 QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" ); 310 QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" );
306 if ( resource->isActive() && !activeKeys.contains( key ) ) { 311 if ( resource->isActive() && !activeKeys.contains( key ) ) {
307 activeKeys.append( resource->identifier() ); 312 activeKeys.append( resource->identifier() );
308 mConfig->writeEntry( "ResourceKeys", activeKeys ); 313 mConfig->writeEntry( "ResourceKeys", activeKeys );
309 } else if ( !resource->isActive() && activeKeys.contains( key ) ) { 314 } else if ( !resource->isActive() && activeKeys.contains( key ) ) {
310 activeKeys.remove( key ); 315 activeKeys.remove( key );
311 mConfig->writeEntry( "ResourceKeys", activeKeys ); 316 mConfig->writeEntry( "ResourceKeys", activeKeys );
312 } 317 }
313 } 318 }
314 319
315 mConfig->sync(); 320 mConfig->sync();
316} 321}
317 322
318void ManagerImpl::removeResource( Resource *resource ) 323void ManagerImpl::removeResource( Resource *resource )
319{ 324{
320 QString key = resource->identifier(); 325 QString key = resource->identifier();
321 326
322 if ( !mConfig ) createStandardConfig(); 327 if ( !mConfig ) createStandardConfig();
323 328
324 mConfig->setGroup( "General" ); 329 mConfig->setGroup( "General" );
325 QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" ); 330 QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" );
326 if ( activeKeys.contains( key ) ) { 331 if ( activeKeys.contains( key ) ) {
327 activeKeys.remove( key ); 332 activeKeys.remove( key );
328 mConfig->writeEntry( "ResourceKeys", activeKeys ); 333 mConfig->writeEntry( "ResourceKeys", activeKeys );
329 } else { 334 } else {
330 QStringList passiveKeys = mConfig->readListEntry( "PassiveResourceKeys" ); 335 QStringList passiveKeys = mConfig->readListEntry( "PassiveResourceKeys" );
331 passiveKeys.remove( key ); 336 passiveKeys.remove( key );
332 mConfig->writeEntry( "PassiveResourceKeys", passiveKeys ); 337 mConfig->writeEntry( "PassiveResourceKeys", passiveKeys );
333 } 338 }
334 339
335 QString standardKey = mConfig->readEntry( "Standard" ); 340 QString standardKey = mConfig->readEntry( "Standard" );
336 if ( standardKey == key ) { 341 if ( standardKey == key ) {
337 mConfig->writeEntry( "Standard", "" ); 342 mConfig->writeEntry( "Standard", "" );
338 } 343 }
339 344
340 mConfig->deleteGroup( "Resource_" + resource->identifier() ); 345 mConfig->deleteGroup( "Resource_" + resource->identifier() );
341 346
342 mConfig->sync(); 347 mConfig->sync();
343} 348}
344 349
345Resource* ManagerImpl::getResource( const QString& identifier ) 350Resource* ManagerImpl::getResource( const QString& identifier )
346{ 351{
347 Resource::List::ConstIterator it; 352 Resource::List::ConstIterator it;
348 for ( it = mResources.begin(); it != mResources.end(); ++it ) { 353 for ( it = mResources.begin(); it != mResources.end(); ++it ) {
349 if ( (*it)->identifier() == identifier ) 354 if ( (*it)->identifier() == identifier )
350 return *it; 355 return *it;
351 } 356 }
352 return 0; 357 return 0;
353} 358}
diff --git a/microkde/kresources/resource.cpp b/microkde/kresources/resource.cpp
index 7827a67..991d53d 100644
--- a/microkde/kresources/resource.cpp
+++ b/microkde/kresources/resource.cpp
@@ -1,186 +1,193 @@
1/* 1/*
2 This file is part of libkresources. 2 This file is part of libkresources.
3 3
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@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#include <kdebug.h> 24#include <kdebug.h>
25#include <kapplication.h> 25#include <kapplication.h>
26#include <kconfig.h> 26#include <kconfig.h>
27 27
28#include "resource.h" 28#include "resource.h"
29 29
30using namespace KRES; 30using namespace KRES;
31 31
32class Resource::ResourcePrivate 32class Resource::ResourcePrivate
33{ 33{
34 public: 34 public:
35#ifdef QT_THREAD_SUPPORT 35#ifdef QT_THREAD_SUPPORT
36 QMutex mMutex; 36 QMutex mMutex;
37#endif 37#endif
38 int mOpenCount; 38 int mOpenCount;
39 QString mType; 39 QString mType;
40 QString mIdentifier; 40 QString mIdentifier;
41 bool mReadOnly; 41 bool mReadOnly;
42 QString mName; 42 QString mName;
43 bool mActive; 43 bool mActive;
44 bool mIsOpen; 44 bool mIsOpen;
45}; 45};
46 46
47Resource::Resource( const KConfig* config ) 47Resource::Resource( const KConfig* config )
48 : QObject( 0, "" ), d( new ResourcePrivate ) 48 : QObject( 0, "" ), d( new ResourcePrivate )
49{ 49{
50 d->mOpenCount = 0; 50 d->mOpenCount = 0;
51 d->mIsOpen = false; 51 d->mIsOpen = false;
52 52
53 //US compiler claimed that const discards qualifier 53 //US compiler claimed that const discards qualifier
54 KConfig* cfg = (KConfig*)config; 54 KConfig* cfg = (KConfig*)config;
55 if ( cfg ) { 55 if ( cfg ) {
56#ifdef _WIN32_
57 // we use plugins on win32. the group is stored in a static variable
58 // such that group info not available on win32 plugins
59 // to fix that, it would be a looooot of work
60 if ( !cfg->tempGroup().isEmpty() )
61 cfg->setGroup( cfg->tempGroup() );
62#endif
56 d->mType = cfg->readEntry( "ResourceType" ); 63 d->mType = cfg->readEntry( "ResourceType" );
57 d->mName = cfg->readEntry( "ResourceName" ); 64 d->mName = cfg->readEntry( "ResourceName" );
58 d->mReadOnly = cfg->readBoolEntry( "ResourceIsReadOnly", false ); 65 d->mReadOnly = cfg->readBoolEntry( "ResourceIsReadOnly", false );
59 d->mActive = cfg->readBoolEntry( "ResourceIsActive", true ); 66 d->mActive = cfg->readBoolEntry( "ResourceIsActive", true );
60 d->mIdentifier = cfg->readEntry( "ResourceIdentifier" ); 67 d->mIdentifier = cfg->readEntry( "ResourceIdentifier" );
61 } else { 68 } else {
62 d->mType = "type"; 69 d->mType = "type";
63 d->mName = "resource-name"; 70 d->mName = "resource-name";
64 d->mReadOnly = false; 71 d->mReadOnly = false;
65 d->mActive = true; 72 d->mActive = true;
66 d->mIdentifier = KApplication::randomString( 10 ); 73 d->mIdentifier = KApplication::randomString( 10 );
67 } 74 }
68} 75}
69 76
70Resource::~Resource() 77Resource::~Resource()
71{ 78{
72 delete d; 79 delete d;
73 d = 0; 80 d = 0;
74} 81}
75 82
76void Resource::writeConfig( KConfig* config ) 83void Resource::writeConfig( KConfig* config )
77{ 84{
78 85
79 86
80 config->writeEntry( "ResourceType", d->mType ); 87 config->writeEntry( "ResourceType", d->mType );
81 config->writeEntry( "ResourceName", d->mName ); 88 config->writeEntry( "ResourceName", d->mName );
82 config->writeEntry( "ResourceIsReadOnly", d->mReadOnly ); 89 config->writeEntry( "ResourceIsReadOnly", d->mReadOnly );
83 config->writeEntry( "ResourceIsActive", d->mActive ); 90 config->writeEntry( "ResourceIsActive", d->mActive );
84 config->writeEntry( "ResourceIdentifier", d->mIdentifier ); 91 config->writeEntry( "ResourceIdentifier", d->mIdentifier );
85} 92}
86 93
87bool Resource::open() 94bool Resource::open()
88{ 95{
89 d->mIsOpen = true; 96 d->mIsOpen = true;
90#ifdef QT_THREAD_SUPPORT 97#ifdef QT_THREAD_SUPPORT
91 QMutexLocker guard( &(d->mMutex) ); 98 QMutexLocker guard( &(d->mMutex) );
92#endif 99#endif
93 if ( !d->mOpenCount ) { 100 if ( !d->mOpenCount ) {
94 kdDebug(5650) << "Opening resource " << resourceName() << endl; 101 kdDebug(5650) << "Opening resource " << resourceName() << endl;
95 d->mIsOpen = doOpen(); 102 d->mIsOpen = doOpen();
96 } 103 }
97 d->mOpenCount++; 104 d->mOpenCount++;
98 return d->mIsOpen; 105 return d->mIsOpen;
99} 106}
100 107
101void Resource::close() 108void Resource::close()
102{ 109{
103#ifdef QT_THREAD_SUPPORT 110#ifdef QT_THREAD_SUPPORT
104 QMutexLocker guard( &(d->mMutex) ); 111 QMutexLocker guard( &(d->mMutex) );
105#endif 112#endif
106 if ( !d->mOpenCount ) { 113 if ( !d->mOpenCount ) {
107 kdDebug(5650) << "ERROR: Resource " << resourceName() << " closed more times than previously opened" << endl; 114 kdDebug(5650) << "ERROR: Resource " << resourceName() << " closed more times than previously opened" << endl;
108 return; 115 return;
109 } 116 }
110 d->mOpenCount--; 117 d->mOpenCount--;
111 if ( !d->mOpenCount ) { 118 if ( !d->mOpenCount ) {
112 kdDebug(5650) << "Closing resource " << resourceName() << endl; 119 kdDebug(5650) << "Closing resource " << resourceName() << endl;
113 doClose(); 120 doClose();
114 d->mIsOpen = false; 121 d->mIsOpen = false;
115 } else { 122 } else {
116 kdDebug(5650) << "Not yet closing resource " << resourceName() << ", open count = " << d->mOpenCount << endl; 123 kdDebug(5650) << "Not yet closing resource " << resourceName() << ", open count = " << d->mOpenCount << endl;
117 } 124 }
118} 125}
119 126
120bool Resource::isOpen() const 127bool Resource::isOpen() const
121{ 128{
122 return d->mIsOpen; 129 return d->mIsOpen;
123} 130}
124 131
125void Resource::setIdentifier( const QString& identifier ) 132void Resource::setIdentifier( const QString& identifier )
126{ 133{
127 d->mIdentifier = identifier; 134 d->mIdentifier = identifier;
128} 135}
129 136
130QString Resource::identifier() const 137QString Resource::identifier() const
131{ 138{
132 return d->mIdentifier; 139 return d->mIdentifier;
133} 140}
134 141
135void Resource::setType( const QString& type ) 142void Resource::setType( const QString& type )
136{ 143{
137 d->mType = type; 144 d->mType = type;
138} 145}
139 146
140QString Resource::type() const 147QString Resource::type() const
141{ 148{
142 return d->mType; 149 return d->mType;
143} 150}
144 151
145void Resource::setReadOnly( bool value ) 152void Resource::setReadOnly( bool value )
146{ 153{
147 d->mReadOnly = value; 154 d->mReadOnly = value;
148} 155}
149 156
150bool Resource::readOnly() const 157bool Resource::readOnly() const
151{ 158{
152 return d->mReadOnly; 159 return d->mReadOnly;
153} 160}
154 161
155void Resource::setResourceName( const QString &name ) 162void Resource::setResourceName( const QString &name )
156{ 163{
157 d->mName = name; 164 d->mName = name;
158} 165}
159 166
160QString Resource::resourceName() const 167QString Resource::resourceName() const
161{ 168{
162 return d->mName; 169 return d->mName;
163} 170}
164 171
165void Resource::setActive( bool value ) 172void Resource::setActive( bool value )
166{ 173{
167 d->mActive = value; 174 d->mActive = value;
168} 175}
169 176
170bool Resource::isActive() const 177bool Resource::isActive() const
171{ 178{
172 return d->mActive; 179 return d->mActive;
173} 180}
174 181
175void Resource::dump() const 182void Resource::dump() const
176{ 183{
177 qDebug("Resource::dump() "); 184 qDebug("Resource::dump() ");
178 kdDebug(5650) << "Resource:" << endl; 185 kdDebug(5650) << "Resource:" << endl;
179 kdDebug(5650) << " Name: " << d->mName << endl; 186 kdDebug(5650) << " Name: " << d->mName << endl;
180 kdDebug(5650) << " Identifier: " << d->mIdentifier << endl; 187 kdDebug(5650) << " Identifier: " << d->mIdentifier << endl;
181 kdDebug(5650) << " Type: " << d->mType << endl; 188 kdDebug(5650) << " Type: " << d->mType << endl;
182 kdDebug(5650) << " OpenCount: " << d->mOpenCount << endl; 189 kdDebug(5650) << " OpenCount: " << d->mOpenCount << endl;
183 kdDebug(5650) << " ReadOnly: " << ( d->mReadOnly ? "yes" : "no" ) << endl; 190 kdDebug(5650) << " ReadOnly: " << ( d->mReadOnly ? "yes" : "no" ) << endl;
184 kdDebug(5650) << " Active: " << ( d->mActive ? "yes" : "no" ) << endl; 191 kdDebug(5650) << " Active: " << ( d->mActive ? "yes" : "no" ) << endl;
185 kdDebug(5650) << " IsOpen: " << ( d->mIsOpen ? "yes" : "no" ) << endl; 192 kdDebug(5650) << " IsOpen: " << ( d->mIsOpen ? "yes" : "no" ) << endl;
186} 193}