summaryrefslogtreecommitdiffabout
path: root/microkde/kconfig.cpp
Unidiff
Diffstat (limited to 'microkde/kconfig.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kconfig.cpp30
1 files changed, 16 insertions, 14 deletions
diff --git a/microkde/kconfig.cpp b/microkde/kconfig.cpp
index 940196e..12063ca 100644
--- a/microkde/kconfig.cpp
+++ b/microkde/kconfig.cpp
@@ -1,15 +1,17 @@
1#include <qfile.h> 1#include <qfile.h>
2#include <qtextstream.h> 2#include <q3textstream.h>
3#include <qwidget.h> 3#include <qwidget.h>
4//Added by qt3to4:
5#include <Q3ValueList>
4 6
5#include "kdebug.h" 7#include "kdebug.h"
6 8
7#include "kurl.h" 9#include "kurl.h"
8#include "kstandarddirs.h" 10#include "kstandarddirs.h"
9#include "kconfig.h" 11#include "kconfig.h"
10 12
11QString KConfig::mGroup = ""; 13QString KConfig::mGroup = "";
12//QString KConfig::mGroup = "General"; 14//QString KConfig::mGroup = "General";
13 15
14KConfig::KConfig( const QString &fileName ) 16KConfig::KConfig( const QString &fileName )
15 : mFileName( fileName ), mDirty( false ) 17 : mFileName( fileName ), mDirty( false )
@@ -44,29 +46,29 @@ void KConfig::setGroup( const QString &group )
44 46
45 mGroup = group; 47 mGroup = group;
46 48
47 if ( mGroup.right( 1 ) != "/" ) mGroup += "/"; 49 if ( mGroup.right( 1 ) != "/" ) mGroup += "/";
48} 50}
49 51
50//US 52//US
51QString KConfig::group() const { 53QString KConfig::group() const {
52 return mGroup; 54 return mGroup;
53} 55}
54 56
55//US added method 57//US added method
56QValueList<int> KConfig::readIntListEntry( const QString & key) 58Q3ValueList<int> KConfig::readIntListEntry( const QString & key)
57{ 59{
58// qDebug("KConfig::readIntListEntry key=%s:", key.latin1()); 60// qDebug("KConfig::readIntListEntry key=%s:", key.latin1());
59 61
60 QValueList<int> result; 62 Q3ValueList<int> result;
61 63
62 QMap<QString,QString>::ConstIterator mit = mStringMap.find( mGroup + key ); 64 QMap<QString,QString>::ConstIterator mit = mStringMap.find( mGroup + key );
63 65
64 if ( mit == mStringMap.end() ) { 66 if ( mit == mStringMap.end() ) {
65 return result; 67 return result;
66 } 68 }
67 69
68 QStringList valuesAsStrings = QStringList::split(":", *mit ); 70 QStringList valuesAsStrings = QStringList::split(":", *mit );
69 bool ok = false; 71 bool ok = false;
70 bool ok2 = true; 72 bool ok2 = true;
71 int val; 73 int val;
72 74
@@ -102,25 +104,25 @@ QString KConfig::readEntry( const QString &key, const QString &def )
102{ 104{
103 QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key ); 105 QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key );
104 106
105 if ( it == mStringMap.end() ) { 107 if ( it == mStringMap.end() ) {
106 return def; 108 return def;
107 } 109 }
108 110
109 return QString::fromUtf8((*it).latin1()); 111 return QString::fromUtf8((*it).latin1());
110} 112}
111 113
112QSize KConfig::readSizeEntry( const QString &key, QSize* def ) 114QSize KConfig::readSizeEntry( const QString &key, QSize* def )
113{ 115{
114 QValueList<int> intlist = readIntListEntry(key); 116 Q3ValueList<int> intlist = readIntListEntry(key);
115 117
116 if (intlist.count() < 2) 118 if (intlist.count() < 2)
117 { 119 {
118 if (def) 120 if (def)
119 return *def; 121 return *def;
120 else 122 else
121 return QSize(); 123 return QSize();
122 } 124 }
123 125
124 QSize ret; 126 QSize ret;
125 ret.setWidth(intlist[0]); 127 ret.setWidth(intlist[0]);
126 ret.setHeight(intlist[1]); 128 ret.setHeight(intlist[1]);
@@ -185,29 +187,29 @@ QDateTime KConfig::readDateTimeEntry( const QString &key, const QDateTime *def )
185{ 187{
186 QMap<QString,QDateTime>::ConstIterator it = mDateTimeMap.find( mGroup + key ); 188 QMap<QString,QDateTime>::ConstIterator it = mDateTimeMap.find( mGroup + key );
187 189
188 if ( it == mDateTimeMap.end() ) { 190 if ( it == mDateTimeMap.end() ) {
189 if ( def ) return *def; 191 if ( def ) return *def;
190 else return QDateTime(); 192 else return QDateTime();
191 } 193 }
192 194
193 return *it; 195 return *it;
194} 196}
195 197
196//US added method 198//US added method
197void KConfig::writeEntry( const QString &key, const QValueList<int> &value) 199void KConfig::writeEntry( const QString &key, const Q3ValueList<int> &value)
198{ 200{
199 QStringList valuesAsStrings; 201 QStringList valuesAsStrings;
200 202
201 QValueList<int>::ConstIterator it; 203 Q3ValueList<int>::ConstIterator it;
202 204
203 for( it = value.begin(); it != value.end(); ++it ) 205 for( it = value.begin(); it != value.end(); ++it )
204 { 206 {
205 valuesAsStrings << QString::number(*it); 207 valuesAsStrings << QString::number(*it);
206 } 208 }
207 209
208 mStringMap.insert( mGroup + key, valuesAsStrings.join(":") ); 210 mStringMap.insert( mGroup + key, valuesAsStrings.join(":") );
209 mDirty = true; 211 mDirty = true;
210} 212}
211 213
212void KConfig::writeEntry( const QString & key , int num ) 214void KConfig::writeEntry( const QString & key , int num )
213{ 215{
@@ -237,63 +239,63 @@ void KConfig::writeEntry( const QString &key, bool value)
237 239
238void KConfig::writeEntry( const QString & e, const QColor & c ) 240void KConfig::writeEntry( const QString & e, const QColor & c )
239{ 241{
240 QStringList l; 242 QStringList l;
241 l.append( QString::number ( c.red() ) ); 243 l.append( QString::number ( c.red() ) );
242 l.append( QString::number ( c.green() ) ); 244 l.append( QString::number ( c.green() ) );
243 l.append( QString::number ( c.blue() ) ); 245 l.append( QString::number ( c.blue() ) );
244 writeEntry( e.utf8(), l ); 246 writeEntry( e.utf8(), l );
245} 247}
246 248
247void KConfig::writeEntry( const QString & e, const QSize & s ) 249void KConfig::writeEntry( const QString & e, const QSize & s )
248{ 250{
249 QValueList<int> intlist; 251 Q3ValueList<int> intlist;
250 intlist << s.width() << s.height(); 252 intlist << s.width() << s.height();
251 writeEntry( e, intlist ); 253 writeEntry( e, intlist );
252} 254}
253 255
254void KConfig::writeEntry( const QString & e , const QFont & f ) 256void KConfig::writeEntry( const QString & e , const QFont & f )
255{ 257{
256 QStringList font; 258 QStringList font;
257 font.append( f.family()); 259 font.append( f.family());
258 font.append( (!f.bold ()?"nonbold":"bold") ); 260 font.append( (!f.bold ()?"nonbold":"bold") );
259 font.append( QString::number ( f.pointSize () ) ); 261 font.append( QString::number ( f.pointSize () ) );
260 font.append( !f.italic ()?"nonitalic":"italic" ); 262 font.append( !f.italic ()?"nonitalic":"italic" );
261 writeEntry( e, font ); 263 writeEntry( e, font );
262} 264}
263 265
264void KConfig::writeEntry( const QString &key, const QDateTime &dt ) 266void KConfig::writeEntry( const QString &key, const QDateTime &dt )
265{ 267{
266 mDateTimeMap.insert( mGroup + key, dt ); 268 mDateTimeMap.insert( mGroup + key, dt );
267} 269}
268 270
269void KConfig::load() 271void KConfig::load()
270{ 272{
271 273
272 274
273 QFile f( mFileName ); 275 QFile f( mFileName );
274 if ( !f.open( IO_ReadOnly ) ) { 276 if ( !f.open( QIODevice::ReadOnly ) ) {
275 //qDebug("KConfig: could not open file %s ",mFileName.latin1() ); 277 //qDebug("KConfig: could not open file %s ",mFileName.latin1() );
276 return; 278 return;
277 } 279 }
278 280
279 mBoolMap.clear(); 281 mBoolMap.clear();
280 mStringMap.clear(); 282 mStringMap.clear();
281 283
282 QTextStream t( &f ); 284 Q3TextStream t( &f );
283 t.setEncoding( QTextStream::Latin1 ); 285 t.setEncoding( Q3TextStream::Latin1 );
284 QString line = t.readLine(); 286 QString line = t.readLine();
285 287
286 while ( !line.isNull() ) { 288 while ( !line.isNull() ) {
287 QStringList tokens = QStringList::split( ",", line ); 289 QStringList tokens = line.split(',');
288 if ( tokens[0] == "bool" ) { 290 if ( tokens[0] == "bool" ) {
289 bool value = false; 291 bool value = false;
290 if ( tokens[2] == "1" ) value = true; 292 if ( tokens[2] == "1" ) value = true;
291 mBoolMap.insert( tokens[1], value ); 293 mBoolMap.insert( tokens[1], value );
292 } else if ( tokens[0] == "QString" ) { 294 } else if ( tokens[0] == "QString" ) {
293 QString value = tokens[2]; 295 QString value = tokens[2];
294 mStringMap.insert( tokens[1], value ); 296 mStringMap.insert( tokens[1], value );
295 } else if ( tokens[0] == "QDateTime" ) { 297 } else if ( tokens[0] == "QDateTime" ) {
296#if 0 298#if 0
297 int year = tokens[2].toInt(); 299 int year = tokens[2].toInt();
298 QDateTime dt( QDate( year, 300 QDateTime dt( QDate( year,
299 tokens[3].toInt(), 301 tokens[3].toInt(),
@@ -314,33 +316,33 @@ void KConfig::sync()
314 if ( !mDirty ) return; 316 if ( !mDirty ) return;
315 //qDebug("KConfig::sync() %s ",mFileName.latin1() ); 317 //qDebug("KConfig::sync() %s ",mFileName.latin1() );
316 //kdDebug() << "KConfig::sync(): " << mFileName << endl; 318 //kdDebug() << "KConfig::sync(): " << mFileName << endl;
317 319
318//US I took the following code from a newer version of KDE 320//US I took the following code from a newer version of KDE
319 // Create the containing dir if needed 321 // Create the containing dir if needed
320 KURL path; 322 KURL path;
321 path.setPath(mFileName); 323 path.setPath(mFileName);
322 QString dir=path.directory(); 324 QString dir=path.directory();
323 KStandardDirs::makeDir(dir); 325 KStandardDirs::makeDir(dir);
324 326
325 QFile f( mFileName ); 327 QFile f( mFileName );
326 if ( !f.open( IO_WriteOnly ) ) { 328 if ( !f.open( QIODevice::WriteOnly ) ) {
327 329
328 qDebug("KConfig::sync() Can't open file %s ",mFileName.latin1() ); 330 qDebug("KConfig::sync() Can't open file %s ",mFileName.latin1() );
329 331
330 return; 332 return;
331 } 333 }
332 334
333 QTextStream t( &f ); 335 Q3TextStream t( &f );
334 t.setEncoding( QTextStream::Latin1 ); 336 t.setEncoding( Q3TextStream::Latin1 );
335 QMap<QString,bool>::ConstIterator itBool; 337 QMap<QString,bool>::ConstIterator itBool;
336 for( itBool = mBoolMap.begin(); itBool != mBoolMap.end(); ++itBool ) { 338 for( itBool = mBoolMap.begin(); itBool != mBoolMap.end(); ++itBool ) {
337 t << "bool," << itBool.key() << "," << ( *itBool ? "1" : "0" ) << endl; 339 t << "bool," << itBool.key() << "," << ( *itBool ? "1" : "0" ) << endl;
338 } 340 }
339 341
340 QMap<QString,QString>::ConstIterator itString; 342 QMap<QString,QString>::ConstIterator itString;
341 for( itString = mStringMap.begin(); itString != mStringMap.end(); ++itString ) { 343 for( itString = mStringMap.begin(); itString != mStringMap.end(); ++itString ) {
342 t << "QString," << itString.key() << "," << (*itString ) << endl; 344 t << "QString," << itString.key() << "," << (*itString ) << endl;
343 } 345 }
344 346
345 QMap<QString,QDateTime>::ConstIterator itDateTime; 347 QMap<QString,QDateTime>::ConstIterator itDateTime;
346 for( itDateTime = mDateTimeMap.begin(); itDateTime != mDateTimeMap.end(); ++itDateTime ) { 348 for( itDateTime = mDateTimeMap.begin(); itDateTime != mDateTimeMap.end(); ++itDateTime ) {