summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-09-21 19:47:57 (UTC)
committer ulf69 <ulf69>2004-09-21 19:47:57 (UTC)
commitc2cce86fdb2d0b291c3d3bdfa9fac47452153d1a (patch) (unidiff)
tree6f8ac380b5db0831f02e4cc35cd0a6fd5ece5ff9
parent427906b75a4672531f2b7d86b2a4a27427f5d4a4 (diff)
downloadkdepimpi-c2cce86fdb2d0b291c3d3bdfa9fac47452153d1a.zip
kdepimpi-c2cce86fdb2d0b291c3d3bdfa9fac47452153d1a.tar.gz
kdepimpi-c2cce86fdb2d0b291c3d3bdfa9fac47452153d1a.tar.bz2
added prefwriting prefreading for size and font object
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdecore/kprefs.cpp50
-rw-r--r--microkde/kdecore/kprefs.h15
-rw-r--r--microkde/kutils/kcmultidialog.cpp20
-rw-r--r--microkde/kutils/kcmultidialog.h5
4 files changed, 87 insertions, 3 deletions
diff --git a/microkde/kdecore/kprefs.cpp b/microkde/kdecore/kprefs.cpp
index f5e5e5a..71050e7 100644
--- a/microkde/kdecore/kprefs.cpp
+++ b/microkde/kdecore/kprefs.cpp
@@ -1,463 +1,511 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21// $Id$ 21// $Id$
22 22
23#include <qcolor.h> 23#include <qcolor.h>
24 24
25#include <kconfig.h> 25#include <kconfig.h>
26#include <kstandarddirs.h> 26#include <kstandarddirs.h>
27#include <kglobal.h> 27#include <kglobal.h>
28#include <kdebug.h> 28#include <kdebug.h>
29 29
30#include "kprefs.h" 30#include "kprefs.h"
31 31
32class KPrefsItemBool : public KPrefsItem { 32class KPrefsItemBool : public KPrefsItem {
33 public: 33 public:
34 KPrefsItemBool(const QString &group,const QString &name,bool *,bool defaultValue=true); 34 KPrefsItemBool(const QString &group,const QString &name,bool *,bool defaultValue=true);
35 virtual ~KPrefsItemBool() {} 35 virtual ~KPrefsItemBool() {}
36 36
37 void setDefault(); 37 void setDefault();
38 void readConfig(KConfig *); 38 void readConfig(KConfig *);
39 void writeConfig(KConfig *); 39 void writeConfig(KConfig *);
40 40
41 private: 41 private:
42 bool *mReference; 42 bool *mReference;
43 bool mDefault; 43 bool mDefault;
44}; 44};
45 45
46class KPrefsItemInt : public KPrefsItem { 46class KPrefsItemInt : public KPrefsItem {
47 public: 47 public:
48 KPrefsItemInt(const QString &group,const QString &name,int *,int defaultValue=0); 48 KPrefsItemInt(const QString &group,const QString &name,int *,int defaultValue=0);
49 virtual ~KPrefsItemInt() {} 49 virtual ~KPrefsItemInt() {}
50 50
51 void setDefault(); 51 void setDefault();
52 void readConfig(KConfig *); 52 void readConfig(KConfig *);
53 void writeConfig(KConfig *); 53 void writeConfig(KConfig *);
54 54
55 private: 55 private:
56 int *mReference; 56 int *mReference;
57 int mDefault; 57 int mDefault;
58}; 58};
59 59
60 60
61class KPrefsItemColor : public KPrefsItem { 61class KPrefsItemColor : public KPrefsItem {
62 public: 62 public:
63 KPrefsItemColor(const QString &group,const QString &name,QColor *, 63 KPrefsItemColor(const QString &group,const QString &name,QColor *,
64 const QColor &defaultValue=QColor(128,128,128)); 64 const QColor &defaultValue=QColor(128,128,128));
65 virtual ~KPrefsItemColor() {} 65 virtual ~KPrefsItemColor() {}
66 66
67 void setDefault(); 67 void setDefault();
68 void readConfig(KConfig *); 68 void readConfig(KConfig *);
69 void writeConfig(KConfig *); 69 void writeConfig(KConfig *);
70 70
71 private: 71 private:
72 QColor *mReference; 72 QColor *mReference;
73 QColor mDefault; 73 QColor mDefault;
74}; 74};
75 75
76class KPrefsItemSize : public KPrefsItem {
77 public:
78 KPrefsItemSize(const QString &group,const QString &name,QSize *,
79 const QSize &defaultValue=QSize());
80 ~KPrefsItemSize() {}
81
82 void setDefault();
83 void readConfig(KConfig *);
84 void writeConfig(KConfig *);
85
86 private:
87 QSize *mReference;
88 QSize mDefault;
89};
90
76 91
77class KPrefsItemFont : public KPrefsItem { 92class KPrefsItemFont : public KPrefsItem {
78 public: 93 public:
79 KPrefsItemFont(const QString &group,const QString &name,QFont *, 94 KPrefsItemFont(const QString &group,const QString &name,QFont *,
80 const QFont &defaultValue=QFont("helvetica",12)); 95 const QFont &defaultValue=QFont("helvetica",12));
81 virtual ~KPrefsItemFont() {} 96 virtual ~KPrefsItemFont() {}
82 97
83 void setDefault(); 98 void setDefault();
84 void readConfig(KConfig *); 99 void readConfig(KConfig *);
85 void writeConfig(KConfig *); 100 void writeConfig(KConfig *);
86 101
87 private: 102 private:
88 QFont *mReference; 103 QFont *mReference;
89 QFont mDefault; 104 QFont mDefault;
90}; 105};
91 106
92 107
93class KPrefsItemString : public KPrefsItem { 108class KPrefsItemString : public KPrefsItem {
94 public: 109 public:
95 KPrefsItemString(const QString &group,const QString &name,QString *, 110 KPrefsItemString(const QString &group,const QString &name,QString *,
96 const QString &defaultValue="", bool isPassword=false); 111 const QString &defaultValue="", bool isPassword=false);
97 virtual ~KPrefsItemString() {} 112 virtual ~KPrefsItemString() {}
98 113
99 void setDefault(); 114 void setDefault();
100 void readConfig(KConfig *); 115 void readConfig(KConfig *);
101 void writeConfig(KConfig *); 116 void writeConfig(KConfig *);
102 117
103 private: 118 private:
104 QString *mReference; 119 QString *mReference;
105 QString mDefault; 120 QString mDefault;
106 bool mPassword; 121 bool mPassword;
107}; 122};
108 123
109 124
110class KPrefsItemStringList : public KPrefsItem { 125class KPrefsItemStringList : public KPrefsItem {
111 public: 126 public:
112 KPrefsItemStringList(const QString &group,const QString &name,QStringList *, 127 KPrefsItemStringList(const QString &group,const QString &name,QStringList *,
113 const QStringList &defaultValue=QStringList()); 128 const QStringList &defaultValue=QStringList());
114 virtual ~KPrefsItemStringList() {} 129 virtual ~KPrefsItemStringList() {}
115 130
116 void setDefault(); 131 void setDefault();
117 void readConfig(KConfig *); 132 void readConfig(KConfig *);
118 void writeConfig(KConfig *); 133 void writeConfig(KConfig *);
119 134
120 private: 135 private:
121 QStringList *mReference; 136 QStringList *mReference;
122 QStringList mDefault; 137 QStringList mDefault;
123}; 138};
124 139
125 140
126class KPrefsItemIntList : public KPrefsItem { 141class KPrefsItemIntList : public KPrefsItem {
127 public: 142 public:
128 KPrefsItemIntList(const QString &group,const QString &name,QValueList<int> *, 143 KPrefsItemIntList(const QString &group,const QString &name,QValueList<int> *,
129 const QValueList<int> &defaultValue=QValueList<int>()); 144 const QValueList<int> &defaultValue=QValueList<int>());
130 virtual ~KPrefsItemIntList() {} 145 virtual ~KPrefsItemIntList() {}
131 146
132 void setDefault(); 147 void setDefault();
133 void readConfig(KConfig *); 148 void readConfig(KConfig *);
134 void writeConfig(KConfig *); 149 void writeConfig(KConfig *);
135 150
136 private: 151 private:
137 QValueList<int> *mReference; 152 QValueList<int> *mReference;
138 QValueList<int> mDefault; 153 QValueList<int> mDefault;
139}; 154};
140 155
141 156
142KPrefsItemBool::KPrefsItemBool(const QString &group,const QString &name, 157KPrefsItemBool::KPrefsItemBool(const QString &group,const QString &name,
143 bool *reference,bool defaultValue) : 158 bool *reference,bool defaultValue) :
144 KPrefsItem(group,name) 159 KPrefsItem(group,name)
145{ 160{
146 mReference = reference; 161 mReference = reference;
147 mDefault = defaultValue; 162 mDefault = defaultValue;
148} 163}
149 164
150void KPrefsItemBool::setDefault() 165void KPrefsItemBool::setDefault()
151{ 166{
152 *mReference = mDefault; 167 *mReference = mDefault;
153} 168}
154 169
155void KPrefsItemBool::writeConfig(KConfig *config) 170void KPrefsItemBool::writeConfig(KConfig *config)
156{ 171{
157 config->setGroup(mGroup); 172 config->setGroup(mGroup);
158 config->writeEntry(mName,*mReference); 173 config->writeEntry(mName,*mReference);
159} 174}
160 175
161 176
162void KPrefsItemBool::readConfig(KConfig *config) 177void KPrefsItemBool::readConfig(KConfig *config)
163{ 178{
164 config->setGroup(mGroup); 179 config->setGroup(mGroup);
165 *mReference = config->readBoolEntry(mName,mDefault); 180 *mReference = config->readBoolEntry(mName,mDefault);
166} 181}
167 182
168 183
169KPrefsItemInt::KPrefsItemInt(const QString &group,const QString &name, 184KPrefsItemInt::KPrefsItemInt(const QString &group,const QString &name,
170 int *reference,int defaultValue) : 185 int *reference,int defaultValue) :
171 KPrefsItem(group,name) 186 KPrefsItem(group,name)
172{ 187{
173 mReference = reference; 188 mReference = reference;
174 mDefault = defaultValue; 189 mDefault = defaultValue;
175} 190}
176 191
177void KPrefsItemInt::setDefault() 192void KPrefsItemInt::setDefault()
178{ 193{
179 *mReference = mDefault; 194 *mReference = mDefault;
180} 195}
181 196
182void KPrefsItemInt::writeConfig(KConfig *config) 197void KPrefsItemInt::writeConfig(KConfig *config)
183{ 198{
184 config->setGroup(mGroup); 199 config->setGroup(mGroup);
185 config->writeEntry(mName,*mReference); 200 config->writeEntry(mName,*mReference);
186} 201}
187 202
188void KPrefsItemInt::readConfig(KConfig *config) 203void KPrefsItemInt::readConfig(KConfig *config)
189{ 204{
190 config->setGroup(mGroup); 205 config->setGroup(mGroup);
191 *mReference = config->readNumEntry(mName,mDefault); 206 *mReference = config->readNumEntry(mName,mDefault);
192} 207}
193 208
194 209
195KPrefsItemColor::KPrefsItemColor(const QString &group,const QString &name, 210KPrefsItemColor::KPrefsItemColor(const QString &group,const QString &name,
196 QColor *reference,const QColor &defaultValue) : 211 QColor *reference,const QColor &defaultValue) :
197 KPrefsItem(group,name) 212 KPrefsItem(group,name)
198{ 213{
199 mReference = reference; 214 mReference = reference;
200 mDefault = defaultValue; 215 mDefault = defaultValue;
201} 216}
202 217
203void KPrefsItemColor::setDefault() 218void KPrefsItemColor::setDefault()
204{ 219{
205 *mReference = mDefault; 220 *mReference = mDefault;
206} 221}
207 222
208void KPrefsItemColor::writeConfig(KConfig *config) 223void KPrefsItemColor::writeConfig(KConfig *config)
209{ 224{
210 config->setGroup(mGroup); 225 config->setGroup(mGroup);
211 config->writeEntry(mName,*mReference); 226 config->writeEntry(mName,*mReference);
212} 227}
213 228
214void KPrefsItemColor::readConfig(KConfig *config) 229void KPrefsItemColor::readConfig(KConfig *config)
215{ 230{
216 config->setGroup(mGroup); 231 config->setGroup(mGroup);
217 *mReference = config->readColorEntry(mName,&mDefault); 232 *mReference = config->readColorEntry(mName,&mDefault);
218 233
219} 234}
220 235
221 236
237KPrefsItemSize::KPrefsItemSize(const QString &group,const QString &name,
238 QSize *reference,const QSize &defaultValue) :
239 KPrefsItem(group,name)
240{
241 mReference = reference;
242 mDefault = defaultValue;
243}
244
245void KPrefsItemSize::setDefault()
246{
247 *mReference = mDefault;
248}
249
250void KPrefsItemSize::writeConfig(KConfig *config)
251{
252 config->setGroup(mGroup);
253 config->writeEntry(mName,*mReference);
254}
255
256void KPrefsItemSize::readConfig(KConfig *config)
257{
258 config->setGroup(mGroup);
259 *mReference = config->readSizeEntry(mName,&mDefault);
260
261}
262
263
222KPrefsItemFont::KPrefsItemFont(const QString &group,const QString &name, 264KPrefsItemFont::KPrefsItemFont(const QString &group,const QString &name,
223 QFont *reference,const QFont &defaultValue) : 265 QFont *reference,const QFont &defaultValue) :
224 KPrefsItem(group,name) 266 KPrefsItem(group,name)
225{ 267{
226 mReference = reference; 268 mReference = reference;
227 mDefault = defaultValue; 269 mDefault = defaultValue;
228} 270}
229 271
230void KPrefsItemFont::setDefault() 272void KPrefsItemFont::setDefault()
231{ 273{
232 *mReference = mDefault; 274 *mReference = mDefault;
233} 275}
234 276
235void KPrefsItemFont::writeConfig(KConfig *config) 277void KPrefsItemFont::writeConfig(KConfig *config)
236{ 278{
237 config->setGroup(mGroup); 279 config->setGroup(mGroup);
238 config->writeEntry(mName,*mReference); 280 config->writeEntry(mName,*mReference);
239} 281}
240 282
241void KPrefsItemFont::readConfig(KConfig *config) 283void KPrefsItemFont::readConfig(KConfig *config)
242{ 284{
243 config->setGroup(mGroup); 285 config->setGroup(mGroup);
244 *mReference = config->readFontEntry(mName,&mDefault); 286 *mReference = config->readFontEntry(mName,&mDefault);
245} 287}
246 288
247 289
248QString endecryptStr( const QString &aStr ) 290QString endecryptStr( const QString &aStr )
249{ 291{
250 QString result; 292 QString result;
251 uint i; 293 uint i;
252 for ( i = 0; i < aStr.length(); i++) 294 for ( i = 0; i < aStr.length(); i++)
253 result += (aStr.at(i).unicode() < 0x20) ? 295 result += (aStr.at(i).unicode() < 0x20) ?
254 aStr.at(i) : 296 aStr.at(i) :
255 QChar(0x1001F - aStr.at(i).unicode()); 297 QChar(0x1001F - aStr.at(i).unicode());
256 return result; 298 return result;
257} 299}
258 300
259 301
260KPrefsItemString::KPrefsItemString(const QString &group,const QString &name, 302KPrefsItemString::KPrefsItemString(const QString &group,const QString &name,
261 QString *reference,const QString &defaultValue, 303 QString *reference,const QString &defaultValue,
262 bool isPassword) : 304 bool isPassword) :
263 KPrefsItem(group,name) 305 KPrefsItem(group,name)
264{ 306{
265 mReference = reference; 307 mReference = reference;
266 mDefault = defaultValue; 308 mDefault = defaultValue;
267 mPassword = isPassword; 309 mPassword = isPassword;
268} 310}
269 311
270void KPrefsItemString::setDefault() 312void KPrefsItemString::setDefault()
271{ 313{
272 *mReference = mDefault; 314 *mReference = mDefault;
273} 315}
274 316
275void KPrefsItemString::writeConfig(KConfig *config) 317void KPrefsItemString::writeConfig(KConfig *config)
276{ 318{
277 config->setGroup(mGroup); 319 config->setGroup(mGroup);
278 if ( mPassword ) 320 if ( mPassword )
279 config->writeEntry(mName, endecryptStr( *mReference ) ); 321 config->writeEntry(mName, endecryptStr( *mReference ) );
280 else 322 else
281 config->writeEntry(mName,*mReference); 323 config->writeEntry(mName,*mReference);
282} 324}
283 325
284void KPrefsItemString::readConfig(KConfig *config) 326void KPrefsItemString::readConfig(KConfig *config)
285{ 327{
286 config->setGroup(mGroup); 328 config->setGroup(mGroup);
287 329
288 QString value; 330 QString value;
289 if ( mPassword ) { 331 if ( mPassword ) {
290 value = config->readEntry( mName, endecryptStr( mDefault ) ); 332 value = config->readEntry( mName, endecryptStr( mDefault ) );
291 *mReference = endecryptStr( value ); 333 *mReference = endecryptStr( value );
292 } else { 334 } else {
293 *mReference = config->readEntry( mName, mDefault ); 335 *mReference = config->readEntry( mName, mDefault );
294 } 336 }
295} 337}
296 338
297 339
298KPrefsItemStringList::KPrefsItemStringList(const QString &group,const QString &name, 340KPrefsItemStringList::KPrefsItemStringList(const QString &group,const QString &name,
299 QStringList *reference,const QStringList &defaultValue) : 341 QStringList *reference,const QStringList &defaultValue) :
300 KPrefsItem(group,name) 342 KPrefsItem(group,name)
301{ 343{
302 mReference = reference; 344 mReference = reference;
303 mDefault = defaultValue; 345 mDefault = defaultValue;
304} 346}
305 347
306void KPrefsItemStringList::setDefault() 348void KPrefsItemStringList::setDefault()
307{ 349{
308 *mReference = mDefault; 350 *mReference = mDefault;
309} 351}
310 352
311void KPrefsItemStringList::writeConfig(KConfig *config) 353void KPrefsItemStringList::writeConfig(KConfig *config)
312{ 354{
313 config->setGroup(mGroup); 355 config->setGroup(mGroup);
314 config->writeEntry(mName,*mReference); 356 config->writeEntry(mName,*mReference);
315} 357}
316 358
317void KPrefsItemStringList::readConfig(KConfig *config) 359void KPrefsItemStringList::readConfig(KConfig *config)
318{ 360{
319 config->setGroup(mGroup); 361 config->setGroup(mGroup);
320 *mReference = config->readListEntry(mName); 362 *mReference = config->readListEntry(mName);
321} 363}
322 364
323 365
324KPrefsItemIntList::KPrefsItemIntList(const QString &group,const QString &name, 366KPrefsItemIntList::KPrefsItemIntList(const QString &group,const QString &name,
325 QValueList<int> *reference,const QValueList<int> &defaultValue) : 367 QValueList<int> *reference,const QValueList<int> &defaultValue) :
326 KPrefsItem(group,name) 368 KPrefsItem(group,name)
327{ 369{
328 mReference = reference; 370 mReference = reference;
329 mDefault = defaultValue; 371 mDefault = defaultValue;
330} 372}
331 373
332void KPrefsItemIntList::setDefault() 374void KPrefsItemIntList::setDefault()
333{ 375{
334 *mReference = mDefault; 376 *mReference = mDefault;
335} 377}
336 378
337void KPrefsItemIntList::writeConfig(KConfig *config) 379void KPrefsItemIntList::writeConfig(KConfig *config)
338{ 380{
339 config->setGroup(mGroup); 381 config->setGroup(mGroup);
340 config->writeEntry(mName,*mReference); 382 config->writeEntry(mName,*mReference);
341} 383}
342 384
343void KPrefsItemIntList::readConfig(KConfig *config) 385void KPrefsItemIntList::readConfig(KConfig *config)
344{ 386{
345 config->setGroup(mGroup); 387 config->setGroup(mGroup);
346 *mReference = config->readIntListEntry(mName); 388 *mReference = config->readIntListEntry(mName);
347} 389}
348 390
349 391
350QString *KPrefs::mCurrentGroup = 0; 392QString *KPrefs::mCurrentGroup = 0;
351 393
352KPrefs::KPrefs(const QString &configname) 394KPrefs::KPrefs(const QString &configname)
353{ 395{
354 if (!configname.isEmpty()) { 396 if (!configname.isEmpty()) {
355 //qDebug("KPrefs::KPrefs %s",configname.latin1() ); 397 //qDebug("KPrefs::KPrefs %s",configname.latin1() );
356 mConfig = new KConfig(locateLocal("config",configname)); 398 mConfig = new KConfig(locateLocal("config",configname));
357 } else { 399 } else {
358 mConfig = KGlobal::config(); 400 mConfig = KGlobal::config();
359 } 401 }
360 402
361 mItems.setAutoDelete(true); 403 mItems.setAutoDelete(true);
362 404
363 // Set default group 405 // Set default group
364 if (mCurrentGroup == 0) mCurrentGroup = new QString("No Group"); 406 if (mCurrentGroup == 0) mCurrentGroup = new QString("No Group");
365} 407}
366 408
367KPrefs::~KPrefs() 409KPrefs::~KPrefs()
368{ 410{
369 if (mConfig != KGlobal::config()) { 411 if (mConfig != KGlobal::config()) {
370 delete mConfig; 412 delete mConfig;
371 } 413 }
372} 414}
373 415
374void KPrefs::setCurrentGroup(const QString &group) 416void KPrefs::setCurrentGroup(const QString &group)
375{ 417{
376 if (mCurrentGroup) delete mCurrentGroup; 418 if (mCurrentGroup) delete mCurrentGroup;
377 mCurrentGroup = new QString(group); 419 mCurrentGroup = new QString(group);
378} 420}
379 421
380KConfig *KPrefs::config() const 422KConfig *KPrefs::config() const
381{ 423{
382 return mConfig; 424 return mConfig;
383} 425}
384 426
385void KPrefs::setDefaults() 427void KPrefs::setDefaults()
386{ 428{
387 KPrefsItem *item; 429 KPrefsItem *item;
388 for(item = mItems.first();item;item = mItems.next()) { 430 for(item = mItems.first();item;item = mItems.next()) {
389 item->setDefault(); 431 item->setDefault();
390 } 432 }
391 433
392 usrSetDefaults(); 434 usrSetDefaults();
393} 435}
394 436
395void KPrefs::readConfig() 437void KPrefs::readConfig()
396{ 438{
397 KPrefsItem *item; 439 KPrefsItem *item;
398 for(item = mItems.first();item;item = mItems.next()) { 440 for(item = mItems.first();item;item = mItems.next()) {
399 item->readConfig(mConfig); 441 item->readConfig(mConfig);
400 } 442 }
401 443
402 usrReadConfig(); 444 usrReadConfig();
445 //qDebug("KPrefs::readConfig: %s", mConfig->getFileName().latin1());
403} 446}
404 447
405void KPrefs::writeConfig() 448void KPrefs::writeConfig()
406{ 449{
407 KPrefsItem *item; 450 KPrefsItem *item;
408 for(item = mItems.first();item;item = mItems.next()) { 451 for(item = mItems.first();item;item = mItems.next()) {
409 item->writeConfig(mConfig); 452 item->writeConfig(mConfig);
410 } 453 }
411 454
412 usrWriteConfig(); 455 usrWriteConfig();
413 456 //qDebug("KPrefs::WriteConfig: %s", mConfig->getFileName().latin1());
414 mConfig->sync(); 457 mConfig->sync();
415} 458}
416 459
417 460
418void KPrefs::addItem(KPrefsItem *item) 461void KPrefs::addItem(KPrefsItem *item)
419{ 462{
420 mItems.append(item); 463 mItems.append(item);
421} 464}
422 465
423void KPrefs::addItemBool(const QString &key,bool *reference,bool defaultValue) 466void KPrefs::addItemBool(const QString &key,bool *reference,bool defaultValue)
424{ 467{
425 addItem(new KPrefsItemBool(*mCurrentGroup,key,reference,defaultValue)); 468 addItem(new KPrefsItemBool(*mCurrentGroup,key,reference,defaultValue));
426} 469}
427 470
428void KPrefs::addItemInt(const QString &key,int *reference,int defaultValue) 471void KPrefs::addItemInt(const QString &key,int *reference,int defaultValue)
429{ 472{
430 addItem(new KPrefsItemInt(*mCurrentGroup,key,reference,defaultValue)); 473 addItem(new KPrefsItemInt(*mCurrentGroup,key,reference,defaultValue));
431} 474}
432 475
433void KPrefs::addItemColor(const QString &key,QColor *reference,const QColor &defaultValue) 476void KPrefs::addItemColor(const QString &key,QColor *reference,const QColor &defaultValue)
434{ 477{
435 addItem(new KPrefsItemColor(*mCurrentGroup,key,reference,defaultValue)); 478 addItem(new KPrefsItemColor(*mCurrentGroup,key,reference,defaultValue));
436} 479}
437 480
438void KPrefs::addItemFont(const QString &key,QFont *reference,const QFont &defaultValue) 481void KPrefs::addItemFont(const QString &key,QFont *reference,const QFont &defaultValue)
439{ 482{
440 addItem(new KPrefsItemFont(*mCurrentGroup,key,reference,defaultValue)); 483 addItem(new KPrefsItemFont(*mCurrentGroup,key,reference,defaultValue));
441} 484}
442 485
486void KPrefs::addItemSize(const QString &key,QSize *reference,const QSize &defaultValue)
487{
488 addItem(new KPrefsItemSize(*mCurrentGroup,key,reference,defaultValue));
489}
490
443void KPrefs::addItemString(const QString &key,QString *reference,const QString &defaultValue) 491void KPrefs::addItemString(const QString &key,QString *reference,const QString &defaultValue)
444{ 492{
445 addItem(new KPrefsItemString(*mCurrentGroup,key,reference,defaultValue,false)); 493 addItem(new KPrefsItemString(*mCurrentGroup,key,reference,defaultValue,false));
446} 494}
447 495
448void KPrefs::addItemPassword(const QString &key,QString *reference,const QString &defaultValue) 496void KPrefs::addItemPassword(const QString &key,QString *reference,const QString &defaultValue)
449{ 497{
450 addItem(new KPrefsItemString(*mCurrentGroup,key,reference,defaultValue,true)); 498 addItem(new KPrefsItemString(*mCurrentGroup,key,reference,defaultValue,true));
451} 499}
452 500
453void KPrefs::addItemStringList(const QString &key,QStringList *reference, 501void KPrefs::addItemStringList(const QString &key,QStringList *reference,
454 const QStringList &defaultValue) 502 const QStringList &defaultValue)
455{ 503{
456 addItem(new KPrefsItemStringList(*mCurrentGroup,key,reference,defaultValue)); 504 addItem(new KPrefsItemStringList(*mCurrentGroup,key,reference,defaultValue));
457} 505}
458 506
459void KPrefs::addItemIntList(const QString &key,QValueList<int> *reference, 507void KPrefs::addItemIntList(const QString &key,QValueList<int> *reference,
460 const QValueList<int> &defaultValue) 508 const QValueList<int> &defaultValue)
461{ 509{
462 addItem(new KPrefsItemIntList(*mCurrentGroup,key,reference,defaultValue)); 510 addItem(new KPrefsItemIntList(*mCurrentGroup,key,reference,defaultValue));
463} 511}
diff --git a/microkde/kdecore/kprefs.h b/microkde/kdecore/kprefs.h
index 7014bb8..95d2724 100644
--- a/microkde/kdecore/kprefs.h
+++ b/microkde/kdecore/kprefs.h
@@ -1,301 +1,316 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20#ifndef _KPREFS_H 20#ifndef _KPREFS_H
21#define _KPREFS_H 21#define _KPREFS_H
22// $Id$ 22// $Id$
23 23
24#include <qptrlist.h> 24#include <qptrlist.h>
25#include <qcolor.h> 25#include <qcolor.h>
26#include <qfont.h> 26#include <qfont.h>
27#include <qsize.h>
27#include <qstringlist.h> 28#include <qstringlist.h>
28 29
29class KConfig; 30class KConfig;
30 31
31/** 32/**
32 @short Class for storing a preferences setting 33 @short Class for storing a preferences setting
33 @author Cornelius Schumacher 34 @author Cornelius Schumacher
34 @see KPref 35 @see KPref
35 36
36 This class represents one preferences setting as used by @ref KPrefs. 37 This class represents one preferences setting as used by @ref KPrefs.
37 Subclasses of KPrefsItem implement storage functions for a certain type of 38 Subclasses of KPrefsItem implement storage functions for a certain type of
38 setting. Normally you don't have to use this class directly. Use the special 39 setting. Normally you don't have to use this class directly. Use the special
39 addItem() functions of KPrefs instead. If you subclass this class you will 40 addItem() functions of KPrefs instead. If you subclass this class you will
40 have to register instances with the function KPrefs::addItem(). 41 have to register instances with the function KPrefs::addItem().
41*/ 42*/
42class KPrefsItem { 43class KPrefsItem {
43 public: 44 public:
44 /** 45 /**
45 Constructor. 46 Constructor.
46 47
47 @param group Config file group. 48 @param group Config file group.
48 @param name Config file key. 49 @param name Config file key.
49 */ 50 */
50 KPrefsItem(const QString &group,const QString &name) : 51 KPrefsItem(const QString &group,const QString &name) :
51 mGroup(group),mName(name) {} 52 mGroup(group),mName(name) {}
52 /** 53 /**
53 Destructor. 54 Destructor.
54 */ 55 */
55 virtual ~KPrefsItem() {} 56 virtual ~KPrefsItem() {}
56 57
57 /** 58 /**
58 This function is called by @ref KPrefs to set this setting to its default 59 This function is called by @ref KPrefs to set this setting to its default
59 value. 60 value.
60 */ 61 */
61 virtual void setDefault() = 0; 62 virtual void setDefault() = 0;
62 /** 63 /**
63 This function is called by @ref KPrefs to read the value for this setting 64 This function is called by @ref KPrefs to read the value for this setting
64 from a config file. 65 from a config file.
65 value. 66 value.
66 */ 67 */
67 virtual void readConfig(KConfig *) = 0; 68 virtual void readConfig(KConfig *) = 0;
68 /** 69 /**
69 This function is called by @ref KPrefs to write the value of this setting 70 This function is called by @ref KPrefs to write the value of this setting
70 to a config file. 71 to a config file.
71 */ 72 */
72 virtual void writeConfig(KConfig *) = 0; 73 virtual void writeConfig(KConfig *) = 0;
73 74
74 protected: 75 protected:
75 QString mGroup; 76 QString mGroup;
76 QString mName; 77 QString mName;
77}; 78};
78 79
79/** 80/**
80 @short Class for handling preferences settings for an application. 81 @short Class for handling preferences settings for an application.
81 @author Cornelius Schumacher 82 @author Cornelius Schumacher
82 @see KPrefsItem 83 @see KPrefsItem
83 84
84 This class provides an interface to preferences settings. Preferences items 85 This class provides an interface to preferences settings. Preferences items
85 can be registered by the addItem() function corresponding to the data type of 86 can be registered by the addItem() function corresponding to the data type of
86 the seetting. KPrefs then handles reading and writing of config files and 87 the seetting. KPrefs then handles reading and writing of config files and
87 setting of default values. 88 setting of default values.
88 89
89 Normally you will subclass KPrefs, add data members for the preferences 90 Normally you will subclass KPrefs, add data members for the preferences
90 settings and register the members in the constructor of the subclass. 91 settings and register the members in the constructor of the subclass.
91 92
92 Example: 93 Example:
93 <pre> 94 <pre>
94 class MyPrefs : public KPrefs { 95 class MyPrefs : public KPrefs {
95 public: 96 public:
96 MyPrefs() 97 MyPrefs()
97 { 98 {
98 setCurrentGroup("MyGroup"); 99 setCurrentGroup("MyGroup");
99 addItemBool("MySetting1",&mMyBool,false); 100 addItemBool("MySetting1",&mMyBool,false);
100 addItemColor("MySetting2",&mMyColor,QColor(1,2,3)); 101 addItemColor("MySetting2",&mMyColor,QColor(1,2,3));
101 102
102 setCurrentGroup("MyOtherGroup"); 103 setCurrentGroup("MyOtherGroup");
103 addItemFont("MySetting3",&mMyFont,QFont("helvetica",12)); 104 addItemFont("MySetting3",&mMyFont,QFont("helvetica",12));
104 } 105 }
105 106
106 bool mMyBool; 107 bool mMyBool;
107 QColor mMyColor; 108 QColor mMyColor;
108 QFont mMyFont; 109 QFont mMyFont;
109 } 110 }
110 </pre> 111 </pre>
111 112
112 It might be convenient in many cases to make this subclass of KPrefs a 113 It might be convenient in many cases to make this subclass of KPrefs a
113 singleton for global access from all over the application without passing 114 singleton for global access from all over the application without passing
114 references to the KPrefs object around. 115 references to the KPrefs object around.
115 116
116 You can set all values to default values by calling @ref setDefaults(), write 117 You can set all values to default values by calling @ref setDefaults(), write
117 the data to the configuration file by calling @ref writeConfig() and read the 118 the data to the configuration file by calling @ref writeConfig() and read the
118 data from the configuration file by calling @ref readConfig(). 119 data from the configuration file by calling @ref readConfig().
119 120
120 If you have items, which are not covered by the existing addItem() functions 121 If you have items, which are not covered by the existing addItem() functions
121 you can add customized code for reading, writing and default setting by 122 you can add customized code for reading, writing and default setting by
122 implementing the functions @ref usrSetDefaults(), @ref usrReadConfig() and 123 implementing the functions @ref usrSetDefaults(), @ref usrReadConfig() and
123 @ref usrWriteConfig(). 124 @ref usrWriteConfig().
124 125
125 Internally preferences settings are stored in instances of subclasses of 126 Internally preferences settings are stored in instances of subclasses of
126 @ref KPrefsItem. You can also add KPrefsItem subclasses for your own types 127 @ref KPrefsItem. You can also add KPrefsItem subclasses for your own types
127 and call the generic @ref addItem() to register them. 128 and call the generic @ref addItem() to register them.
128*/ 129*/
129 130
130class KPrefs { 131class KPrefs {
131 public: 132 public:
132 /** 133 /**
133 Constructor. 134 Constructor.
134 135
135 @param configname name of config file. If no name is given, the default 136 @param configname name of config file. If no name is given, the default
136 config file as returned by kapp()->config() is used. 137 config file as returned by kapp()->config() is used.
137 */ 138 */
138 KPrefs(const QString &configname=QString::null); 139 KPrefs(const QString &configname=QString::null);
139 /** 140 /**
140 Destructor 141 Destructor
141 */ 142 */
142 virtual ~KPrefs(); 143 virtual ~KPrefs();
143 144
144 /** 145 /**
145 Set preferences to default values. All registered items are set to their 146 Set preferences to default values. All registered items are set to their
146 default values. 147 default values.
147 */ 148 */
148 void setDefaults(); 149 void setDefaults();
149 150
150 /** 151 /**
151 Read preferences from config file. All registered items are set to the 152 Read preferences from config file. All registered items are set to the
152 values read from disk. 153 values read from disk.
153 */ 154 */
154 void readConfig(); 155 void readConfig();
155 156
156 /** 157 /**
157 Write preferences to config file. The values of all registered items are 158 Write preferences to config file. The values of all registered items are
158 written to disk. 159 written to disk.
159 */ 160 */
160 void writeConfig(); 161 void writeConfig();
161 162
162 /** 163 /**
163 Set the config file group for subsequent addItem() calls. It is valid 164 Set the config file group for subsequent addItem() calls. It is valid
164 until setCurrentGroup() is called with a new argument. Call this before 165 until setCurrentGroup() is called with a new argument. Call this before
165 you add any items. The default value is "No Group". 166 you add any items. The default value is "No Group".
166 */ 167 */
167 static void setCurrentGroup(const QString &group); 168 static void setCurrentGroup(const QString &group);
168 169
169 /** 170 /**
170 Register a custom @ref KPrefsItem. 171 Register a custom @ref KPrefsItem.
171 */ 172 */
172 void addItem(KPrefsItem *); 173 void addItem(KPrefsItem *);
173 174
174 /** 175 /**
175 Register an item of type bool. 176 Register an item of type bool.
176 177
177 @param key Key used in config file. 178 @param key Key used in config file.
178 @param reference Pointer to the variable, which is set by readConfig() 179 @param reference Pointer to the variable, which is set by readConfig()
179 and setDefaults() calls and read by writeConfig() calls. 180 and setDefaults() calls and read by writeConfig() calls.
180 @param defaultValue Default value, which is used by setDefaults() and 181 @param defaultValue Default value, which is used by setDefaults() and
181 when the config file does not yet contain the key of 182 when the config file does not yet contain the key of
182 this item. 183 this item.
183 */ 184 */
184 void addItemBool(const QString &key,bool *reference, 185 void addItemBool(const QString &key,bool *reference,
185 bool defaultValue=false); 186 bool defaultValue=false);
186 /** 187 /**
187 Register an item of type int. 188 Register an item of type int.
188 189
189 @param key Key used in config file. 190 @param key Key used in config file.
190 @param reference Pointer to the variable, which is set by readConfig() 191 @param reference Pointer to the variable, which is set by readConfig()
191 and setDefaults() calls and read by writeConfig() calls. 192 and setDefaults() calls and read by writeConfig() calls.
192 @param defaultValue Default value, which is used by setDefaults() and 193 @param defaultValue Default value, which is used by setDefaults() and
193 when the config file does not yet contain the key of 194 when the config file does not yet contain the key of
194 this item. 195 this item.
195 */ 196 */
196 void addItemInt(const QString &key,int *reference, 197 void addItemInt(const QString &key,int *reference,
197 int defaultValue=0); 198 int defaultValue=0);
198 /** 199 /**
199 Register an item of type QColor. 200 Register an item of type QColor.
200 201
201 @param key Key used in config file. 202 @param key Key used in config file.
202 @param reference Pointer to the variable, which is set by readConfig() 203 @param reference Pointer to the variable, which is set by readConfig()
203 and setDefaults() calls and read by writeConfig() calls. 204 and setDefaults() calls and read by writeConfig() calls.
204 @param defaultValue Default value, which is used by setDefaults() and 205 @param defaultValue Default value, which is used by setDefaults() and
205 when the config file does not yet contain the key of 206 when the config file does not yet contain the key of
206 this item. 207 this item.
207 */ 208 */
208 void addItemColor(const QString &key,QColor *reference, 209 void addItemColor(const QString &key,QColor *reference,
209 const QColor &defaultValue=QColor(128,128,128)); 210 const QColor &defaultValue=QColor(128,128,128));
211
212 /**
213 Register an item of type QSize.
214
215 @param key Key used in config file.
216 @param reference Pointer to the variable, which is set by readConfig()
217 and setDefaults() calls and read by writeConfig() calls.
218 @param defaultValue Default value, which is used by setDefaults() and
219 when the config file does not yet contain the key of
220 this item.
221 */
222 void addItemSize(const QString &key,QSize *reference,
223 const QSize &defaultValue=QSize());
224
210 /** 225 /**
211 Register an item of type QFont. 226 Register an item of type QFont.
212 227
213 @param key Key used in config file. 228 @param key Key used in config file.
214 @param reference Pointer to the variable, which is set by readConfig() 229 @param reference Pointer to the variable, which is set by readConfig()
215 and setDefaults() calls and read by writeConfig() calls. 230 and setDefaults() calls and read by writeConfig() calls.
216 @param defaultValue Default value, which is used by setDefaults() and 231 @param defaultValue Default value, which is used by setDefaults() and
217 when the config file does not yet contain the key of 232 when the config file does not yet contain the key of
218 this item. 233 this item.
219 */ 234 */
220 void addItemFont(const QString &key,QFont *reference, 235 void addItemFont(const QString &key,QFont *reference,
221 const QFont &defaultValue=QFont("helvetica",12)); 236 const QFont &defaultValue=QFont("helvetica",12));
222 /** 237 /**
223 Register an item of type QString. 238 Register an item of type QString.
224 239
225 @param key Key used in config file. 240 @param key Key used in config file.
226 @param reference Pointer to the variable, which is set by readConfig() 241 @param reference Pointer to the variable, which is set by readConfig()
227 and setDefaults() calls and read by writeConfig() calls. 242 and setDefaults() calls and read by writeConfig() calls.
228 @param defaultValue Default value, which is used by setDefaults() and 243 @param defaultValue Default value, which is used by setDefaults() and
229 when the config file does not yet contain the key of 244 when the config file does not yet contain the key of
230 this item. 245 this item.
231 */ 246 */
232 void addItemString(const QString &key,QString *reference, 247 void addItemString(const QString &key,QString *reference,
233 const QString &defaultValue=""); 248 const QString &defaultValue="");
234 /** 249 /**
235 Register a password item of type QString. The string value is written 250 Register a password item of type QString. The string value is written
236 encrypted to the config file. Note that the current encryption scheme 251 encrypted to the config file. Note that the current encryption scheme
237 is very weak. 252 is very weak.
238 253
239 @param key Key used in config file. 254 @param key Key used in config file.
240 @param reference Pointer to the variable, which is set by readConfig() 255 @param reference Pointer to the variable, which is set by readConfig()
241 and setDefaults() calls and read by writeConfig() calls. 256 and setDefaults() calls and read by writeConfig() calls.
242 @param defaultValue Default value, which is used by setDefaults() and 257 @param defaultValue Default value, which is used by setDefaults() and
243 when the config file does not yet contain the key of 258 when the config file does not yet contain the key of
244 this item. 259 this item.
245 */ 260 */
246 void addItemPassword(const QString &key,QString *reference, 261 void addItemPassword(const QString &key,QString *reference,
247 const QString &defaultValue=""); 262 const QString &defaultValue="");
248 /** 263 /**
249 Register an item of type QStringList. 264 Register an item of type QStringList.
250 265
251 @param key Key used in config file. 266 @param key Key used in config file.
252 @param reference Pointer to the variable, which is set by readConfig() 267 @param reference Pointer to the variable, which is set by readConfig()
253 and setDefaults() calls and read by writeConfig() calls. 268 and setDefaults() calls and read by writeConfig() calls.
254 @param defaultValue Default value, which is used by setDefaults() and 269 @param defaultValue Default value, which is used by setDefaults() and
255 when the config file does not yet contain the key of 270 when the config file does not yet contain the key of
256 this item. 271 this item.
257 */ 272 */
258 void addItemStringList(const QString &key,QStringList *reference, 273 void addItemStringList(const QString &key,QStringList *reference,
259 const QStringList &defaultValue=QStringList()); 274 const QStringList &defaultValue=QStringList());
260 275
261 /** 276 /**
262 Register an item of type QValueList<int>. 277 Register an item of type QValueList<int>.
263 278
264 @param key Key used in config file. 279 @param key Key used in config file.
265 @param reference Pointer to the variable, which is set by readConfig() 280 @param reference Pointer to the variable, which is set by readConfig()
266 and setDefaults() calls and read by writeConfig() calls. 281 and setDefaults() calls and read by writeConfig() calls.
267 @param defaultValue Default value, which is used by setDefaults() and 282 @param defaultValue Default value, which is used by setDefaults() and
268 when the config file does not yet contain the key of 283 when the config file does not yet contain the key of
269 this item. 284 this item.
270 */ 285 */
271 void addItemIntList(const QString &key,QValueList<int> *reference, 286 void addItemIntList(const QString &key,QValueList<int> *reference,
272 const QValueList<int> &defaultValue=QValueList<int>()); 287 const QValueList<int> &defaultValue=QValueList<int>());
273 288
274 protected: 289 protected:
275 /** 290 /**
276 Implemented by subclasses that use special defaults. 291 Implemented by subclasses that use special defaults.
277 */ 292 */
278 virtual void usrSetDefaults() {}; 293 virtual void usrSetDefaults() {};
279 /** 294 /**
280 Implemented by subclasses that read special config values. 295 Implemented by subclasses that read special config values.
281 */ 296 */
282 virtual void usrReadConfig() {}; 297 virtual void usrReadConfig() {};
283 /** 298 /**
284 Implemented by subclasses that write special config values. 299 Implemented by subclasses that write special config values.
285 */ 300 */
286 virtual void usrWriteConfig() {}; 301 virtual void usrWriteConfig() {};
287 302
288 /** 303 /**
289 Return the @ref KConfig object used for reading and writing the settings. 304 Return the @ref KConfig object used for reading and writing the settings.
290 */ 305 */
291 KConfig *config() const; 306 KConfig *config() const;
292 307
293 private: 308 private:
294 static QString *mCurrentGroup; 309 static QString *mCurrentGroup;
295 310
296 KConfig *mConfig; // pointer to KConfig object 311 KConfig *mConfig; // pointer to KConfig object
297 312
298 QPtrList<KPrefsItem> mItems; 313 QPtrList<KPrefsItem> mItems;
299}; 314};
300 315
301#endif 316#endif
diff --git a/microkde/kutils/kcmultidialog.cpp b/microkde/kutils/kcmultidialog.cpp
index e7aa9d1..c4ccede 100644
--- a/microkde/kutils/kcmultidialog.cpp
+++ b/microkde/kutils/kcmultidialog.cpp
@@ -1,209 +1,227 @@
1/* 1/*
2 Copyright (c) 2000 Matthias Elter <elter@kde.org> 2 Copyright (c) 2000 Matthias Elter <elter@kde.org>
3 Copyright (c) 2003 Daniel Molkentin <molkentin@kde.org> 3 Copyright (c) 2003 Daniel Molkentin <molkentin@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19 19
20*/ 20*/
21 21
22#include <qhbox.h> 22#include <qhbox.h>
23#include <qvbox.h> 23#include <qvbox.h>
24#include <qcursor.h> 24#include <qcursor.h>
25#include <qlayout.h> 25#include <qlayout.h>
26 26
27#include <klocale.h> 27#include <klocale.h>
28#include <kglobal.h> 28#include <kglobal.h>
29#include <kdebug.h> 29#include <kdebug.h>
30#include <kiconloader.h> 30#include <kiconloader.h>
31#include <kmessagebox.h> 31#include <kmessagebox.h>
32//US #include <klibloader.h> 32//US #include <klibloader.h>
33#include <krun.h> 33#include <krun.h>
34#include <kprocess.h> 34#include <kprocess.h>
35 35
36#include "kcmultidialog.h" 36#include "kcmultidialog.h"
37//US #include "kcmultidialog.moc" 37//US #include "kcmultidialog.moc"
38//US #include "kcmoduleloader.h" 38//US #include "kcmoduleloader.h"
39 39
40KCMultiDialog::KCMultiDialog(const QString& baseGroup, QWidget *parent, const char *name, bool modal) 40KCMultiDialog::KCMultiDialog(const QString& baseGroup, QWidget *parent, const char *name, bool modal)
41 : KDialogBase(IconList, i18n("Configure"), Default |Cancel | Apply | Ok, Ok, 41 : KDialogBase(IconList, i18n("Configure"), Default |Cancel | Apply | Ok, Ok,
42 parent, name, modal, true), d(0L) 42 parent, name, modal, true), d(0L)
43{ 43{
44 enableButton(Apply, false); 44 enableButton(Apply, false);
45 //connect(this, SIGNAL(aboutToShowPage(QWidget *)), this, SLOT(slotAboutToShow(QWidget *))); 45 //connect(this, SIGNAL(aboutToShowPage(QWidget *)), this, SLOT(slotAboutToShow(QWidget *)));
46 46
47 connect( this, SIGNAL( defaultClicked() ), SLOT( slotDefault() ) ); 47 connect( this, SIGNAL( defaultClicked() ), SLOT( slotDefault() ) );
48 48
49 _baseGroup = baseGroup; 49 _baseGroup = baseGroup;
50 mMainWidget = new KJanusWidget( this, "JanusWidget", KJanusWidget::Tabbed ); 50 mMainWidget = new KJanusWidget( this, "JanusWidget", KJanusWidget::Tabbed );
51 setMainWidget(mMainWidget ); 51 setMainWidget(mMainWidget );
52#ifdef DESKTOP_VERSION 52#ifdef DESKTOP_VERSION
53 resize(640,480); 53 resize(640,480);
54#else 54#else
55 resize(640,480); 55 resize(640,480);
56 setMaximumSize( KMIN(KGlobal::getDesktopWidth()-5, 640), KMIN(KGlobal::getDesktopHeight()-20, 480)); 56 setMaximumSize( KMIN(KGlobal::getDesktopWidth()-5, 640), KMIN(KGlobal::getDesktopHeight()-20, 480));
57 //showMaximized(); 57 //showMaximized();
58#endif 58#endif
59 59
60} 60}
61 61
62KCMultiDialog::~KCMultiDialog() 62KCMultiDialog::~KCMultiDialog()
63{ 63{
64//US moduleDict.setAutoDelete(true); 64//US moduleDict.setAutoDelete(true);
65} 65}
66 66
67void KCMultiDialog::slotDefault() 67void KCMultiDialog::slotDefault()
68{ 68{
69 69
70 int curPageIndex = mMainWidget->activePageIndex(); 70 int curPageIndex = activePageIndex();
71 71
72 QPtrListIterator<KCModule> it(modules); 72 QPtrListIterator<KCModule> it(modules);
73 for (; it.current(); ++it) 73 for (; it.current(); ++it)
74 { 74 {
75 if (pageIndex((QWidget *)(*it)->parent()) == curPageIndex) 75 if (pageIndex((QWidget *)(*it)->parent()) == curPageIndex)
76 { 76 {
77 (*it)->defaults(); 77 (*it)->defaults();
78 clientChanged(true); 78 clientChanged(true);
79 return; 79 return;
80 } 80 }
81 } 81 }
82 82
83} 83}
84void KCMultiDialog::accept() 84void KCMultiDialog::accept()
85{ 85{
86 slotOk(); 86 slotOk();
87} 87}
88void KCMultiDialog::slotApply() 88void KCMultiDialog::slotApply()
89{ 89{
90qDebug("KCMultiDialog::slotApply clicked"); 90qDebug("KCMultiDialog::slotApply clicked");
91 91
92 QPtrListIterator<KCModule> it(modules); 92 QPtrListIterator<KCModule> it(modules);
93 for (; it.current(); ++it) 93 for (; it.current(); ++it)
94 (*it)->save(); 94 (*it)->save();
95 clientChanged(false); 95 clientChanged(false);
96 96
97 emit applyClicked(); 97 emit applyClicked();
98 98
99} 99}
100 100
101 101
102void KCMultiDialog::slotOk() 102void KCMultiDialog::slotOk()
103{ 103{
104qDebug("KCMultiDialog::slotOk clicked"); 104qDebug("KCMultiDialog::slotOk clicked");
105 105
106 QPtrListIterator<KCModule> it(modules); 106 QPtrListIterator<KCModule> it(modules);
107 for (; it.current(); ++it) 107 for (; it.current(); ++it)
108 (*it)->save(); 108 (*it)->save();
109 QDialog::accept(); 109 QDialog::accept();
110 110
111 emit okClicked(); 111 emit okClicked();
112} 112}
113 113
114void KCMultiDialog::slotHelp() 114void KCMultiDialog::slotHelp()
115{ 115{
116/*US 116/*US
117 KURL url( KURL("help:/"), _docPath ); 117 KURL url( KURL("help:/"), _docPath );
118 118
119 if (url.protocol() == "help" || url.protocol() == "man" || url.protocol() == "info") { 119 if (url.protocol() == "help" || url.protocol() == "man" || url.protocol() == "info") {
120 KProcess process; 120 KProcess process;
121 process << "khelpcenter" 121 process << "khelpcenter"
122 << url.url(); 122 << url.url();
123 process.start(KProcess::DontCare); 123 process.start(KProcess::DontCare);
124 process.detach(); 124 process.detach();
125 } else { 125 } else {
126 new KRun(url); 126 new KRun(url);
127 } 127 }
128*/ 128*/
129} 129}
130 130
131void KCMultiDialog::clientChanged(bool state) 131void KCMultiDialog::clientChanged(bool state)
132{ 132{
133 enableButton(Apply, state); 133 enableButton(Apply, state);
134} 134}
135 135
136/*US 136/*US
137void KCMultiDialog::addModule(const QString& path, bool withfallback) 137void KCMultiDialog::addModule(const QString& path, bool withfallback)
138{ 138{
139 kdDebug(1208) << "KCMultiDialog::addModule " << path << endl; 139 kdDebug(1208) << "KCMultiDialog::addModule " << path << endl;
140 140
141 KCModuleInfo info(path, _baseGroup); 141 KCModuleInfo info(path, _baseGroup);
142 142
143 QHBox* page = addHBoxPage(info.moduleName(), info.comment(), 143 QHBox* page = addHBoxPage(info.moduleName(), info.comment(),
144 KGlobal::iconLoader()->loadIcon(info.icon(), KIcon::Desktop, KIcon::SizeMedium)); 144 KGlobal::iconLoader()->loadIcon(info.icon(), KIcon::Desktop, KIcon::SizeMedium));
145 if(!page) { 145 if(!page) {
146 KCModuleLoader::unloadModule(info); 146 KCModuleLoader::unloadModule(info);
147 return; 147 return;
148 } 148 }
149 moduleDict.insert(page, new LoadInfo(path, withfallback)); 149 moduleDict.insert(page, new LoadInfo(path, withfallback));
150 if (modules.isEmpty()) 150 if (modules.isEmpty())
151 slotAboutToShow(page); 151 slotAboutToShow(page);
152} 152}
153*/ 153*/
154QVBox * KCMultiDialog::getNewVBoxPage( const QString & modulename ) 154QVBox * KCMultiDialog::getNewVBoxPage( const QString & modulename )
155{ 155{
156 QVBox *page = mMainWidget->addVBoxPage(modulename , QString::null,QPixmap() ); 156 QVBox *page = mMainWidget->addVBoxPage(modulename , QString::null,QPixmap() );
157 return page; 157 return page;
158 158
159} 159}
160//US special method for microkde. We dop noty want to load everything dynamically. 160//US special method for microkde. We dop noty want to load everything dynamically.
161void KCMultiDialog::addModule(KCModule* module ) //, const QString& modulename, const QString& iconname) 161void KCMultiDialog::addModule(KCModule* module ) //, const QString& modulename, const QString& iconname)
162{ 162{
163 163
164 modules.append(module); 164 modules.append(module);
165 connect(module, SIGNAL(changed(bool)), this, SLOT(clientChanged(bool))); 165 connect(module, SIGNAL(changed(bool)), this, SLOT(clientChanged(bool)));
166//US 166//US
167 module->load(); 167 module->load();
168 168
169 169
170} 170}
171 171
172void KCMultiDialog::slotAboutToShow(QWidget *page) 172void KCMultiDialog::slotAboutToShow(QWidget *page)
173{ 173{
174/*US 174/*US
175 LoadInfo *loadInfo = moduleDict[page]; 175 LoadInfo *loadInfo = moduleDict[page];
176 if (!loadInfo) 176 if (!loadInfo)
177 return; 177 return;
178 178
179 QApplication::setOverrideCursor(Qt::WaitCursor); 179 QApplication::setOverrideCursor(Qt::WaitCursor);
180 180
181 moduleDict.remove(page); 181 moduleDict.remove(page);
182 182
183 KCModuleInfo info(loadInfo->path, _baseGroup); 183 KCModuleInfo info(loadInfo->path, _baseGroup);
184 184
185 KCModule *module = KCModuleLoader::loadModule(info, loadInfo->withfallback); 185 KCModule *module = KCModuleLoader::loadModule(info, loadInfo->withfallback);
186 186
187 if (!module) 187 if (!module)
188 { 188 {
189 QApplication::restoreOverrideCursor(); 189 QApplication::restoreOverrideCursor();
190 KCModuleLoader::showLastLoaderError(this); 190 KCModuleLoader::showLastLoaderError(this);
191 delete loadInfo; 191 delete loadInfo;
192 return; 192 return;
193 } 193 }
194 194
195 module->reparent(page,0,QPoint(0,0),true); 195 module->reparent(page,0,QPoint(0,0),true);
196 connect(module, SIGNAL(changed(bool)), this, SLOT(clientChanged(bool))); 196 connect(module, SIGNAL(changed(bool)), this, SLOT(clientChanged(bool)));
197 //setHelp( docpath, QString::null ); 197 //setHelp( docpath, QString::null );
198 _docPath = info.docPath(); 198 _docPath = info.docPath();
199 modules.append(module); 199 modules.append(module);
200 200
201 //KCGlobal::repairAccels( topLevelWidget() ); 201 //KCGlobal::repairAccels( topLevelWidget() );
202 202
203 delete loadInfo; 203 delete loadInfo;
204 204
205 QApplication::restoreOverrideCursor(); 205 QApplication::restoreOverrideCursor();
206*/ 206*/
207 207
208qDebug("KCMultiDialog::slotAboutToShow not implemented"); 208qDebug("KCMultiDialog::slotAboutToShow not implemented");
209} 209}
210
211
212bool KCMultiDialog::showPage( int index )
213{
214 return(mMainWidget->showPage(index) );
215}
216
217
218int KCMultiDialog::activePageIndex() const
219{
220 return( mMainWidget->activePageIndex() );
221}
222
223
224int KCMultiDialog::pageIndex( QWidget *widget ) const
225{
226 return( mMainWidget->pageIndex( widget) );
227}
diff --git a/microkde/kutils/kcmultidialog.h b/microkde/kutils/kcmultidialog.h
index 768faea..66412ac 100644
--- a/microkde/kutils/kcmultidialog.h
+++ b/microkde/kutils/kcmultidialog.h
@@ -1,148 +1,151 @@
1/* 1/*
2 Copyright (c) 2000 Matthias Elter <elter@kde.org> 2 Copyright (c) 2000 Matthias Elter <elter@kde.org>
3 Copyright (c) 2003 Daniel Molkentin <molkentin@kde.org> 3 Copyright (c) 2003 Daniel Molkentin <molkentin@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19 19
20*/ 20*/
21 21
22#ifndef KCMULTIDIALOG_H 22#ifndef KCMULTIDIALOG_H
23#define KCMULTIDIALOG_H 23#define KCMULTIDIALOG_H
24 24
25#include <qptrlist.h> 25#include <qptrlist.h>
26#include <qptrdict.h> 26#include <qptrdict.h>
27 27
28#include <kdialogbase.h> 28#include <kdialogbase.h>
29#include <kjanuswidget.h> 29#include <kjanuswidget.h>
30#include <kcmodule.h> 30#include <kcmodule.h>
31 31
32/** 32/**
33 * A class that offers a @ref KDialogBase containing arbitrary KControl Modules 33 * A class that offers a @ref KDialogBase containing arbitrary KControl Modules
34 * 34 *
35 * @short A method that offers a @ref KDialogBase containing arbitrary 35 * @short A method that offers a @ref KDialogBase containing arbitrary
36 * KControl Modules. 36 * KControl Modules.
37 * 37 *
38 * @author Matthias Elter <elter@kde.org>, Daniel Molkentin <molkentin@kde.org> 38 * @author Matthias Elter <elter@kde.org>, Daniel Molkentin <molkentin@kde.org>
39 * @since 3.2 39 * @since 3.2
40 */ 40 */
41class KCMultiDialog : public KDialogBase 41class KCMultiDialog : public KDialogBase
42{ 42{
43 Q_OBJECT 43 Q_OBJECT
44 44
45public: 45public:
46 /** 46 /**
47 * Constructs a new KCMultiDialog 47 * Constructs a new KCMultiDialog
48 * 48 *
49 * @param parent The parent Widget 49 * @param parent The parent Widget
50 * @param name The widget name 50 * @param name The widget name
51 * @param baseGroup The baseGroup, if you want to call a module out of 51 * @param baseGroup The baseGroup, if you want to call a module out of
52 * kcontrol, just keep "settings" 52 * kcontrol, just keep "settings"
53 * @param modal If you pass true here, the dialog will be modal 53 * @param modal If you pass true here, the dialog will be modal
54 **/ 54 **/
55 KCMultiDialog(const QString& baseGroup = QString::fromLatin1("settings"), 55 KCMultiDialog(const QString& baseGroup = QString::fromLatin1("settings"),
56 QWidget *parent=0, const char *name=0, 56 QWidget *parent=0, const char *name=0,
57 bool modal=false); 57 bool modal=false);
58 58
59 /** 59 /**
60 * Destructor 60 * Destructor
61 **/ 61 **/
62 virtual ~KCMultiDialog(); 62 virtual ~KCMultiDialog();
63 63
64 /** 64 /**
65 * Add a module. 65 * Add a module.
66 * 66 *
67 * @param module Specify the name of the module that is to be added 67 * @param module Specify the name of the module that is to be added
68 * to the list of modules the dialog will show. 68 * to the list of modules the dialog will show.
69 * 69 *
70 * @param withfallback Try harder to load the module. Might result 70 * @param withfallback Try harder to load the module. Might result
71 * in the module appearing outside the dialog. 71 * in the module appearing outside the dialog.
72 **/ 72 **/
73//US void addModule(const QString& module, bool withfallback=true); 73//US void addModule(const QString& module, bool withfallback=true);
74 74
75 75
76//US special method for microkde. We dop noty want to load everything dynamically. 76//US special method for microkde. We do not want to load everything dynamically.
77 void addModule(KCModule* module );//, const QString& modulename, const QString& iconname); 77 void addModule(KCModule* module );//, const QString& modulename, const QString& iconname);
78 QVBox* getNewVBoxPage(const QString & modulename) ; 78 QVBox* getNewVBoxPage(const QString & modulename) ;
79 79
80 80
81 bool showPage( int index );
82 int activePageIndex() const;
83 int pageIndex( QWidget *widget ) const;
81 84
82protected slots: 85protected slots:
83 /** 86 /**
84 * This slot is called when the user presses the "Default" Button 87 * This slot is called when the user presses the "Default" Button
85 * You can reimplement it if needed. 88 * You can reimplement it if needed.
86 * 89 *
87 * @note Make sure you call the original implementation! 90 * @note Make sure you call the original implementation!
88 **/ 91 **/
89 virtual void slotDefault(); 92 virtual void slotDefault();
90 93
91 /** 94 /**
92 * This slot is called when the user presses the "Apply" Button 95 * This slot is called when the user presses the "Apply" Button
93 * You can reimplement it if needed 96 * You can reimplement it if needed
94 * 97 *
95 * @note Make sure you call the original implementation! 98 * @note Make sure you call the original implementation!
96 **/ 99 **/
97 virtual void slotApply(); 100 virtual void slotApply();
98 101
99 /** 102 /**
100 * This slot is called when the user presses the "OK" Button 103 * This slot is called when the user presses the "OK" Button
101 * You can reimplement it if needed 104 * You can reimplement it if needed
102 * 105 *
103 * @note Make sure you call the original implementation! 106 * @note Make sure you call the original implementation!
104 **/ 107 **/
105 virtual void slotOk(); 108 virtual void slotOk();
106 109
107 /** 110 /**
108 * This slot is called when the user presses the "Help" Button 111 * This slot is called when the user presses the "Help" Button
109 * You can reimplement it if needed 112 * You can reimplement it if needed
110 * 113 *
111 * @note Make sure you call the original implementation! 114 * @note Make sure you call the original implementation!
112 **/ 115 **/
113 virtual void slotHelp(); 116 virtual void slotHelp();
114 117
115 void accept(); 118 void accept();
116 119
117private slots: 120private slots:
118 121
119 void slotAboutToShow(QWidget *); 122 void slotAboutToShow(QWidget *);
120 123
121 void clientChanged(bool state); 124 void clientChanged(bool state);
122 125
123private: 126private:
124/*US 127/*US
125 struct LoadInfo { 128 struct LoadInfo {
126 LoadInfo(const QString &_path, bool _withfallback) 129 LoadInfo(const QString &_path, bool _withfallback)
127 : path(_path), withfallback(_withfallback) 130 : path(_path), withfallback(_withfallback)
128 { } 131 { }
129 QString path; 132 QString path;
130 bool withfallback; 133 bool withfallback;
131 }; 134 };
132*/ 135*/
133 QPtrList<KCModule> modules; 136 QPtrList<KCModule> modules;
134/* 137/*
135 QPtrDict<LoadInfo> moduleDict; 138 QPtrDict<LoadInfo> moduleDict;
136 QString _docPath; 139 QString _docPath;
137*/ 140*/
138 QString _baseGroup; 141 QString _baseGroup;
139 142
140//US 143//US
141 KJanusWidget* mMainWidget; 144 KJanusWidget* mMainWidget;
142 145
143 // For future use 146 // For future use
144 class KCMultiDialogPrivate; 147 class KCMultiDialogPrivate;
145 KCMultiDialogPrivate *d; 148 KCMultiDialogPrivate *d;
146}; 149};
147 150
148#endif //KCMULTIDIALOG_H 151#endif //KCMULTIDIALOG_H