-rw-r--r-- | microkde/kconfig.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/microkde/kconfig.cpp b/microkde/kconfig.cpp index 862166d..b9cf2f1 100644 --- a/microkde/kconfig.cpp +++ b/microkde/kconfig.cpp | |||
@@ -61,277 +61,277 @@ QValueList<int> KConfig::readIntListEntry( const QString & key) | |||
61 | 61 | ||
62 | QMap<QString,QString>::ConstIterator mit = mStringMap.find( mGroup + key ); | 62 | QMap<QString,QString>::ConstIterator mit = mStringMap.find( mGroup + key ); |
63 | 63 | ||
64 | if ( mit == mStringMap.end() ) { | 64 | if ( mit == mStringMap.end() ) { |
65 | return result; | 65 | return result; |
66 | } | 66 | } |
67 | 67 | ||
68 | QStringList valuesAsStrings = QStringList::split(":", *mit ); | 68 | QStringList valuesAsStrings = QStringList::split(":", *mit ); |
69 | bool ok = false; | 69 | bool ok = false; |
70 | bool ok2 = true; | 70 | bool ok2 = true; |
71 | int val; | 71 | int val; |
72 | 72 | ||
73 | for ( QStringList::Iterator sit = valuesAsStrings.begin(); sit != valuesAsStrings.end(); ++sit ) { | 73 | for ( QStringList::Iterator sit = valuesAsStrings.begin(); sit != valuesAsStrings.end(); ++sit ) { |
74 | val = (*sit).toInt(&ok); | 74 | val = (*sit).toInt(&ok); |
75 | result << val; | 75 | result << val; |
76 | if (ok == false) { | 76 | if (ok == false) { |
77 | qDebug("KConfig::readIntListEntry str=%s , int=%n:", (*sit).latin1(), &val); | 77 | qDebug("KConfig::readIntListEntry str=%s , int=%n:", (*sit).latin1(), &val); |
78 | ok2 = false; | 78 | ok2 = false; |
79 | } | 79 | } |
80 | } | 80 | } |
81 | 81 | ||
82 | if (ok2 == false) | 82 | if (ok2 == false) |
83 | { | 83 | { |
84 | 84 | ||
85 | qDebug("KConfig::readIntListEntry: error while reading one of the intvalues."); | 85 | qDebug("KConfig::readIntListEntry: error while reading one of the intvalues."); |
86 | } | 86 | } |
87 | 87 | ||
88 | return result; | 88 | return result; |
89 | } | 89 | } |
90 | 90 | ||
91 | int KConfig::readNumEntry( const QString & key, int def ) | 91 | int KConfig::readNumEntry( const QString & key, int def ) |
92 | { | 92 | { |
93 | QString res = readEntry(key, QString::number(def ) ); | 93 | QString res = readEntry(key, QString::number(def ) ); |
94 | bool ok = false; | 94 | bool ok = false; |
95 | int result = res.toInt(&ok); | 95 | int result = res.toInt(&ok); |
96 | if ( ok ) | 96 | if ( ok ) |
97 | return result; | 97 | return result; |
98 | return def; | 98 | return def; |
99 | } | 99 | } |
100 | 100 | ||
101 | QString KConfig::readEntry( const QString &key, const QString &def ) | 101 | QString KConfig::readEntry( const QString &key, const QString &def ) |
102 | { | 102 | { |
103 | QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key ); | 103 | QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key ); |
104 | 104 | ||
105 | if ( it == mStringMap.end() ) { | 105 | if ( it == mStringMap.end() ) { |
106 | return def; | 106 | return def; |
107 | } | 107 | } |
108 | 108 | ||
109 | return QString::fromUtf8((*it).latin1()); | 109 | return QString::fromUtf8((*it).latin1()); |
110 | } | 110 | } |
111 | 111 | ||
112 | QSize KConfig::readSizeEntry( const QString &key, QSize* def ) | 112 | QSize KConfig::readSizeEntry( const QString &key, QSize* def ) |
113 | { | 113 | { |
114 | QValueList<int> intlist = readIntListEntry(key); | 114 | QValueList<int> intlist = readIntListEntry(key); |
115 | 115 | ||
116 | if (intlist.count() < 2) | 116 | if (intlist.count() < 2) |
117 | { | 117 | { |
118 | if (def) | 118 | if (def) |
119 | return *def; | 119 | return *def; |
120 | else | 120 | else |
121 | return QSize(); | 121 | return QSize(); |
122 | } | 122 | } |
123 | 123 | ||
124 | QSize ret; | 124 | QSize ret; |
125 | ret.setWidth(intlist[0]); | 125 | ret.setWidth(intlist[0]); |
126 | ret.setHeight(intlist[1]); | 126 | ret.setHeight(intlist[1]); |
127 | 127 | ||
128 | return ret; | 128 | return ret; |
129 | } | 129 | } |
130 | 130 | ||
131 | QStringList KConfig::readListEntry( const QString &key ) | 131 | QStringList KConfig::readListEntry( const QString &key ) |
132 | { | 132 | { |
133 | QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key ); | 133 | QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key ); |
134 | 134 | ||
135 | if ( it == mStringMap.end() ) { | 135 | if ( it == mStringMap.end() ) { |
136 | return QStringList(); | 136 | return QStringList(); |
137 | } | 137 | } |
138 | return QStringList::split(":", QString::fromUtf8((*it).latin1())); | 138 | return QStringList::split(":", QString::fromUtf8((*it).latin1())); |
139 | 139 | ||
140 | } | 140 | } |
141 | 141 | ||
142 | bool KConfig::readBoolEntry( const QString &key, bool def ) | 142 | bool KConfig::readBoolEntry( const QString &key, bool def ) |
143 | { | 143 | { |
144 | QMap<QString,bool>::ConstIterator it = mBoolMap.find( mGroup + key ); | 144 | QMap<QString,bool>::ConstIterator it = mBoolMap.find( mGroup + key ); |
145 | 145 | ||
146 | if ( it == mBoolMap.end() ) { | 146 | if ( it == mBoolMap.end() ) { |
147 | return def; | 147 | return def; |
148 | } | 148 | } |
149 | 149 | ||
150 | return *it; | 150 | return *it; |
151 | } | 151 | } |
152 | 152 | ||
153 | QColor KConfig::readColorEntry( const QString & e, QColor *def ) | 153 | QColor KConfig::readColorEntry( const QString & e, QColor *def ) |
154 | { | 154 | { |
155 | 155 | ||
156 | QStringList l; | 156 | QStringList l; |
157 | l = readListEntry( e ); | 157 | l = readListEntry( e.utf8() ); |
158 | if (l.count() != 3 ) { | 158 | if (l.count() != 3 ) { |
159 | if ( def ) | 159 | if ( def ) |
160 | return *def; | 160 | return *def; |
161 | else | 161 | else |
162 | return QColor(); | 162 | return QColor(); |
163 | } | 163 | } |
164 | QColor c ( l[0].toInt(), l[1].toInt(), l[2].toInt() ); | 164 | QColor c ( l[0].toInt(), l[1].toInt(), l[2].toInt() ); |
165 | return c; | 165 | return c; |
166 | } | 166 | } |
167 | 167 | ||
168 | QFont KConfig::readFontEntry( const QString & e, QFont *def ) | 168 | QFont KConfig::readFontEntry( const QString & e, QFont *def ) |
169 | { | 169 | { |
170 | QStringList font = readListEntry( e ); | 170 | QStringList font = readListEntry( e ); |
171 | if ( font.isEmpty() ) | 171 | if ( font.isEmpty() ) |
172 | return *def; | 172 | return *def; |
173 | QFont f; | 173 | QFont f; |
174 | f.setFamily( font[0]); | 174 | f.setFamily( font[0]); |
175 | f.setBold ( font[1] == "bold"); | 175 | f.setBold ( font[1] == "bold"); |
176 | f.setPointSize ( font[2].toInt()); | 176 | f.setPointSize ( font[2].toInt()); |
177 | f.setItalic( font[3] == "italic" ); | 177 | f.setItalic( font[3] == "italic" ); |
178 | return f; | 178 | return f; |
179 | } | 179 | } |
180 | 180 | ||
181 | QDateTime KConfig::readDateTimeEntry( const QString &key, const QDateTime *def ) | 181 | QDateTime KConfig::readDateTimeEntry( const QString &key, const QDateTime *def ) |
182 | { | 182 | { |
183 | QMap<QString,QDateTime>::ConstIterator it = mDateTimeMap.find( mGroup + key ); | 183 | QMap<QString,QDateTime>::ConstIterator it = mDateTimeMap.find( mGroup + key ); |
184 | 184 | ||
185 | if ( it == mDateTimeMap.end() ) { | 185 | if ( it == mDateTimeMap.end() ) { |
186 | if ( def ) return *def; | 186 | if ( def ) return *def; |
187 | else return QDateTime(); | 187 | else return QDateTime(); |
188 | } | 188 | } |
189 | 189 | ||
190 | return *it; | 190 | return *it; |
191 | } | 191 | } |
192 | 192 | ||
193 | //US added method | 193 | //US added method |
194 | void KConfig::writeEntry( const QString &key, const QValueList<int> &value) | 194 | void KConfig::writeEntry( const QString &key, const QValueList<int> &value) |
195 | { | 195 | { |
196 | QStringList valuesAsStrings; | 196 | QStringList valuesAsStrings; |
197 | 197 | ||
198 | QValueList<int>::ConstIterator it; | 198 | QValueList<int>::ConstIterator it; |
199 | 199 | ||
200 | for( it = value.begin(); it != value.end(); ++it ) | 200 | for( it = value.begin(); it != value.end(); ++it ) |
201 | { | 201 | { |
202 | valuesAsStrings << QString::number(*it); | 202 | valuesAsStrings << QString::number(*it); |
203 | } | 203 | } |
204 | 204 | ||
205 | mStringMap.insert( mGroup + key, valuesAsStrings.join(":") ); | 205 | mStringMap.insert( mGroup + key, valuesAsStrings.join(":") ); |
206 | mDirty = true; | 206 | mDirty = true; |
207 | } | 207 | } |
208 | 208 | ||
209 | void KConfig::writeEntry( const QString & key , int num ) | 209 | void KConfig::writeEntry( const QString & key , int num ) |
210 | { | 210 | { |
211 | writeEntry( key, QString::number ( num ) ); | 211 | writeEntry( key, QString::number ( num ) ); |
212 | } | 212 | } |
213 | 213 | ||
214 | void KConfig::writeEntry( const QString &key, const QString &value ) | 214 | void KConfig::writeEntry( const QString &key, const QString &value ) |
215 | { | 215 | { |
216 | mStringMap.insert( mGroup + key, value.utf8() ); | 216 | mStringMap.insert( mGroup + key, value.utf8() ); |
217 | 217 | ||
218 | mDirty = true; | 218 | mDirty = true; |
219 | } | 219 | } |
220 | 220 | ||
221 | void KConfig::writeEntry( const QString &key, const QStringList &value ) | 221 | void KConfig::writeEntry( const QString &key, const QStringList &value ) |
222 | { | 222 | { |
223 | mStringMap.insert( mGroup + key, value.join(":").utf8() ); | 223 | mStringMap.insert( mGroup + key, value.join(":").utf8() ); |
224 | 224 | ||
225 | mDirty = true; | 225 | mDirty = true; |
226 | } | 226 | } |
227 | 227 | ||
228 | void KConfig::writeEntry( const QString &key, bool value) | 228 | void KConfig::writeEntry( const QString &key, bool value) |
229 | { | 229 | { |
230 | mBoolMap.insert( mGroup + key, value ); | 230 | mBoolMap.insert( mGroup + key, value ); |
231 | 231 | ||
232 | mDirty = true; | 232 | mDirty = true; |
233 | } | 233 | } |
234 | 234 | ||
235 | void KConfig::writeEntry( const QString & e, const QColor & c ) | 235 | void KConfig::writeEntry( const QString & e, const QColor & c ) |
236 | { | 236 | { |
237 | QStringList l; | 237 | QStringList l; |
238 | l.append( QString::number ( c.red() ) ); | 238 | l.append( QString::number ( c.red() ) ); |
239 | l.append( QString::number ( c.green() ) ); | 239 | l.append( QString::number ( c.green() ) ); |
240 | l.append( QString::number ( c.blue() ) ); | 240 | l.append( QString::number ( c.blue() ) ); |
241 | writeEntry( e, l ); | 241 | writeEntry( e.utf8(), l ); |
242 | } | 242 | } |
243 | 243 | ||
244 | void KConfig::writeEntry( const QString & e, const QSize & s ) | 244 | void KConfig::writeEntry( const QString & e, const QSize & s ) |
245 | { | 245 | { |
246 | QValueList<int> intlist; | 246 | QValueList<int> intlist; |
247 | intlist << s.width() << s.height(); | 247 | intlist << s.width() << s.height(); |
248 | writeEntry( e, intlist ); | 248 | writeEntry( e, intlist ); |
249 | } | 249 | } |
250 | 250 | ||
251 | void KConfig::writeEntry( const QString & e , const QFont & f ) | 251 | void KConfig::writeEntry( const QString & e , const QFont & f ) |
252 | { | 252 | { |
253 | QStringList font; | 253 | QStringList font; |
254 | font.append( f.family()); | 254 | font.append( f.family()); |
255 | font.append( (!f.bold ()?"nonbold":"bold") ); | 255 | font.append( (!f.bold ()?"nonbold":"bold") ); |
256 | font.append( QString::number ( f.pointSize () ) ); | 256 | font.append( QString::number ( f.pointSize () ) ); |
257 | font.append( !f.italic ()?"nonitalic":"italic" ); | 257 | font.append( !f.italic ()?"nonitalic":"italic" ); |
258 | writeEntry( e, font ); | 258 | writeEntry( e, font ); |
259 | } | 259 | } |
260 | 260 | ||
261 | void KConfig::writeEntry( const QString &key, const QDateTime &dt ) | 261 | void KConfig::writeEntry( const QString &key, const QDateTime &dt ) |
262 | { | 262 | { |
263 | mDateTimeMap.insert( mGroup + key, dt ); | 263 | mDateTimeMap.insert( mGroup + key, dt ); |
264 | } | 264 | } |
265 | 265 | ||
266 | void KConfig::load() | 266 | void KConfig::load() |
267 | { | 267 | { |
268 | 268 | ||
269 | 269 | ||
270 | QFile f( mFileName ); | 270 | QFile f( mFileName ); |
271 | if ( !f.open( IO_ReadOnly ) ) { | 271 | if ( !f.open( IO_ReadOnly ) ) { |
272 | //qDebug("KConfig: could not open file %s ",mFileName.latin1() ); | 272 | //qDebug("KConfig: could not open file %s ",mFileName.latin1() ); |
273 | return; | 273 | return; |
274 | } | 274 | } |
275 | 275 | ||
276 | mBoolMap.clear(); | 276 | mBoolMap.clear(); |
277 | mStringMap.clear(); | 277 | mStringMap.clear(); |
278 | 278 | ||
279 | QTextStream t( &f ); | 279 | QTextStream t( &f ); |
280 | 280 | ||
281 | QString line = t.readLine(); | 281 | QString line = t.readLine(); |
282 | 282 | ||
283 | while ( !line.isNull() ) { | 283 | while ( !line.isNull() ) { |
284 | QStringList tokens = QStringList::split( ",", line ); | 284 | QStringList tokens = QStringList::split( ",", line ); |
285 | if ( tokens[0] == "bool" ) { | 285 | if ( tokens[0] == "bool" ) { |
286 | bool value = false; | 286 | bool value = false; |
287 | if ( tokens[2] == "1" ) value = true; | 287 | if ( tokens[2] == "1" ) value = true; |
288 | mBoolMap.insert( tokens[1], value ); | 288 | mBoolMap.insert( tokens[1], value ); |
289 | } else if ( tokens[0] == "QString" ) { | 289 | } else if ( tokens[0] == "QString" ) { |
290 | QString value = tokens[2]; | 290 | QString value = tokens[2]; |
291 | mStringMap.insert( tokens[1], value ); | 291 | mStringMap.insert( tokens[1], value ); |
292 | } else if ( tokens[0] == "QDateTime" ) { | 292 | } else if ( tokens[0] == "QDateTime" ) { |
293 | #if 0 | 293 | #if 0 |
294 | int year = tokens[2].toInt(); | 294 | int year = tokens[2].toInt(); |
295 | QDateTime dt( QDate( year, | 295 | QDateTime dt( QDate( year, |
296 | tokens[3].toInt(), | 296 | tokens[3].toInt(), |
297 | tokens[4].toInt() ), | 297 | tokens[4].toInt() ), |
298 | QTime( tokens[5].toInt(), tokens[6].toInt(), | 298 | QTime( tokens[5].toInt(), tokens[6].toInt(), |
299 | tokens[7].toInt() ) ); | 299 | tokens[7].toInt() ) ); |
300 | mDateTimeMap.insert( tokens[1], dt ); | 300 | mDateTimeMap.insert( tokens[1], dt ); |
301 | #endif | 301 | #endif |
302 | } | 302 | } |
303 | 303 | ||
304 | line = t.readLine(); | 304 | line = t.readLine(); |
305 | } | 305 | } |
306 | } | 306 | } |
307 | 307 | ||
308 | void KConfig::sync() | 308 | void KConfig::sync() |
309 | { | 309 | { |
310 | 310 | ||
311 | if ( !mDirty ) return; | 311 | if ( !mDirty ) return; |
312 | //qDebug("KConfig::sync() %s ",mFileName.latin1() ); | 312 | //qDebug("KConfig::sync() %s ",mFileName.latin1() ); |
313 | //kdDebug() << "KConfig::sync(): " << mFileName << endl; | 313 | //kdDebug() << "KConfig::sync(): " << mFileName << endl; |
314 | 314 | ||
315 | //US I took the following code from a newer version of KDE | 315 | //US I took the following code from a newer version of KDE |
316 | // Create the containing dir if needed | 316 | // Create the containing dir if needed |
317 | KURL path; | 317 | KURL path; |
318 | path.setPath(mFileName); | 318 | path.setPath(mFileName); |
319 | QString dir=path.directory(); | 319 | QString dir=path.directory(); |
320 | KStandardDirs::makeDir(dir); | 320 | KStandardDirs::makeDir(dir); |
321 | 321 | ||
322 | QFile f( mFileName ); | 322 | QFile f( mFileName ); |
323 | if ( !f.open( IO_WriteOnly ) ) { | 323 | if ( !f.open( IO_WriteOnly ) ) { |
324 | 324 | ||
325 | qDebug("KConfig::sync() Can't open file %s ",mFileName.latin1() ); | 325 | qDebug("KConfig::sync() Can't open file %s ",mFileName.latin1() ); |
326 | 326 | ||
327 | return; | 327 | return; |
328 | } | 328 | } |
329 | 329 | ||
330 | QTextStream t( &f ); | 330 | QTextStream t( &f ); |
331 | 331 | ||
332 | QMap<QString,bool>::ConstIterator itBool; | 332 | QMap<QString,bool>::ConstIterator itBool; |
333 | for( itBool = mBoolMap.begin(); itBool != mBoolMap.end(); ++itBool ) { | 333 | for( itBool = mBoolMap.begin(); itBool != mBoolMap.end(); ++itBool ) { |
334 | t << "bool," << itBool.key() << "," << ( *itBool ? "1" : "0" ) << endl; | 334 | t << "bool," << itBool.key() << "," << ( *itBool ? "1" : "0" ) << endl; |
335 | } | 335 | } |
336 | 336 | ||
337 | QMap<QString,QString>::ConstIterator itString; | 337 | QMap<QString,QString>::ConstIterator itString; |