-rw-r--r-- | microkde/kconfig.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/microkde/kconfig.cpp b/microkde/kconfig.cpp index 4cbec94..ba41f6c 100644 --- a/microkde/kconfig.cpp +++ b/microkde/kconfig.cpp | |||
@@ -64,96 +64,115 @@ QValueList<int> KConfig::readIntListEntry( const QString & key) | |||
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 *it; | 109 | return *it; |
110 | } | 110 | } |
111 | 111 | ||
112 | QSize KConfig::readSizeEntry( const QString &key, QSize* def ) | ||
113 | { | ||
114 | QValueList<int> intlist = readIntListEntry(key); | ||
115 | |||
116 | if (intlist.count() < 2) | ||
117 | { | ||
118 | if (def) | ||
119 | return *def; | ||
120 | else | ||
121 | return QSize(); | ||
122 | } | ||
123 | |||
124 | QSize ret; | ||
125 | ret.setWidth(intlist[0]); | ||
126 | ret.setHeight(intlist[1]); | ||
127 | |||
128 | return ret; | ||
129 | } | ||
130 | |||
112 | QStringList KConfig::readListEntry( const QString &key ) | 131 | QStringList KConfig::readListEntry( const QString &key ) |
113 | { | 132 | { |
114 | QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key ); | 133 | QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key ); |
115 | 134 | ||
116 | if ( it == mStringMap.end() ) { | 135 | if ( it == mStringMap.end() ) { |
117 | return QStringList(); | 136 | return QStringList(); |
118 | } | 137 | } |
119 | return QStringList::split(":", *it ); | 138 | return QStringList::split(":", *it ); |
120 | 139 | ||
121 | } | 140 | } |
122 | 141 | ||
123 | bool KConfig::readBoolEntry( const QString &key, bool def ) | 142 | bool KConfig::readBoolEntry( const QString &key, bool def ) |
124 | { | 143 | { |
125 | QMap<QString,bool>::ConstIterator it = mBoolMap.find( mGroup + key ); | 144 | QMap<QString,bool>::ConstIterator it = mBoolMap.find( mGroup + key ); |
126 | 145 | ||
127 | if ( it == mBoolMap.end() ) { | 146 | if ( it == mBoolMap.end() ) { |
128 | return def; | 147 | return def; |
129 | } | 148 | } |
130 | 149 | ||
131 | return *it; | 150 | return *it; |
132 | } | 151 | } |
133 | 152 | ||
134 | QColor KConfig::readColorEntry( const QString & e, QColor *def ) | 153 | QColor KConfig::readColorEntry( const QString & e, QColor *def ) |
135 | { | 154 | { |
136 | 155 | ||
137 | QStringList l; | 156 | QStringList l; |
138 | l = readListEntry( e ); | 157 | l = readListEntry( e ); |
139 | if (l.count() != 3 ) { | 158 | if (l.count() != 3 ) { |
140 | if ( def ) | 159 | if ( def ) |
141 | return *def; | 160 | return *def; |
142 | else | 161 | else |
143 | return QColor(); | 162 | return QColor(); |
144 | } | 163 | } |
145 | QColor c ( l[0].toInt(), l[1].toInt(), l[2].toInt() ); | 164 | QColor c ( l[0].toInt(), l[1].toInt(), l[2].toInt() ); |
146 | return c; | 165 | return c; |
147 | } | 166 | } |
148 | 167 | ||
149 | QFont KConfig::readFontEntry( const QString & e, QFont *def ) | 168 | QFont KConfig::readFontEntry( const QString & e, QFont *def ) |
150 | { | 169 | { |
151 | QStringList font = readListEntry( e ); | 170 | QStringList font = readListEntry( e ); |
152 | if ( font.isEmpty() ) | 171 | if ( font.isEmpty() ) |
153 | return *def; | 172 | return *def; |
154 | QFont f; | 173 | QFont f; |
155 | f.setFamily( font[0]); | 174 | f.setFamily( font[0]); |
156 | f.setBold ( font[1] == "bold"); | 175 | f.setBold ( font[1] == "bold"); |
157 | f.setPointSize ( font[2].toInt()); | 176 | f.setPointSize ( font[2].toInt()); |
158 | f.setItalic( font[3] == "italic" ); | 177 | f.setItalic( font[3] == "italic" ); |
159 | return f; | 178 | return f; |
@@ -177,96 +196,103 @@ void KConfig::writeEntry( const QString &key, const QValueList<int> &value) | |||
177 | QStringList valuesAsStrings; | 196 | QStringList valuesAsStrings; |
178 | 197 | ||
179 | QValueList<int>::ConstIterator it; | 198 | QValueList<int>::ConstIterator it; |
180 | 199 | ||
181 | for( it = value.begin(); it != value.end(); ++it ) | 200 | for( it = value.begin(); it != value.end(); ++it ) |
182 | { | 201 | { |
183 | valuesAsStrings << QString::number(*it); | 202 | valuesAsStrings << QString::number(*it); |
184 | } | 203 | } |
185 | 204 | ||
186 | mStringMap.insert( mGroup + key, valuesAsStrings.join(":") ); | 205 | mStringMap.insert( mGroup + key, valuesAsStrings.join(":") ); |
187 | mDirty = true; | 206 | mDirty = true; |
188 | } | 207 | } |
189 | 208 | ||
190 | void KConfig::writeEntry( const QString & key , int num ) | 209 | void KConfig::writeEntry( const QString & key , int num ) |
191 | { | 210 | { |
192 | writeEntry( key, QString::number ( num ) ); | 211 | writeEntry( key, QString::number ( num ) ); |
193 | } | 212 | } |
194 | 213 | ||
195 | void KConfig::writeEntry( const QString &key, const QString &value ) | 214 | void KConfig::writeEntry( const QString &key, const QString &value ) |
196 | { | 215 | { |
197 | mStringMap.insert( mGroup + key, value ); | 216 | mStringMap.insert( mGroup + key, value ); |
198 | 217 | ||
199 | mDirty = true; | 218 | mDirty = true; |
200 | } | 219 | } |
201 | 220 | ||
202 | void KConfig::writeEntry( const QString &key, const QStringList &value ) | 221 | void KConfig::writeEntry( const QString &key, const QStringList &value ) |
203 | { | 222 | { |
204 | mStringMap.insert( mGroup + key, value.join(":") ); | 223 | mStringMap.insert( mGroup + key, value.join(":") ); |
205 | 224 | ||
206 | mDirty = true; | 225 | mDirty = true; |
207 | } | 226 | } |
208 | 227 | ||
209 | void KConfig::writeEntry( const QString &key, bool value) | 228 | void KConfig::writeEntry( const QString &key, bool value) |
210 | { | 229 | { |
211 | mBoolMap.insert( mGroup + key, value ); | 230 | mBoolMap.insert( mGroup + key, value ); |
212 | 231 | ||
213 | mDirty = true; | 232 | mDirty = true; |
214 | } | 233 | } |
215 | 234 | ||
216 | void KConfig::writeEntry( const QString & e, const QColor & c ) | 235 | void KConfig::writeEntry( const QString & e, const QColor & c ) |
217 | { | 236 | { |
218 | QStringList l; | 237 | QStringList l; |
219 | l.append( QString::number ( c.red() ) ); | 238 | l.append( QString::number ( c.red() ) ); |
220 | l.append( QString::number ( c.green() ) ); | 239 | l.append( QString::number ( c.green() ) ); |
221 | l.append( QString::number ( c.blue() ) ); | 240 | l.append( QString::number ( c.blue() ) ); |
222 | writeEntry( e, l ); | 241 | writeEntry( e, l ); |
223 | } | 242 | } |
224 | 243 | ||
244 | void KConfig::writeEntry( const QString & e, const QSize & s ) | ||
245 | { | ||
246 | QValueList<int> intlist; | ||
247 | intlist << s.width() << s.height(); | ||
248 | writeEntry( e, intlist ); | ||
249 | } | ||
250 | |||
225 | void KConfig::writeEntry( const QString & e , const QFont & f ) | 251 | void KConfig::writeEntry( const QString & e , const QFont & f ) |
226 | { | 252 | { |
227 | QStringList font; | 253 | QStringList font; |
228 | font.append( f.family()); | 254 | font.append( f.family()); |
229 | font.append( (!f.bold ()?"nonbold":"bold") ); | 255 | font.append( (!f.bold ()?"nonbold":"bold") ); |
230 | font.append( QString::number ( f.pointSize () ) ); | 256 | font.append( QString::number ( f.pointSize () ) ); |
231 | font.append( !f.italic ()?"nonitalic":"italic" ); | 257 | font.append( !f.italic ()?"nonitalic":"italic" ); |
232 | writeEntry( e, font ); | 258 | writeEntry( e, font ); |
233 | } | 259 | } |
234 | 260 | ||
235 | void KConfig::writeEntry( const QString &key, const QDateTime &dt ) | 261 | void KConfig::writeEntry( const QString &key, const QDateTime &dt ) |
236 | { | 262 | { |
237 | mDateTimeMap.insert( mGroup + key, dt ); | 263 | mDateTimeMap.insert( mGroup + key, dt ); |
238 | } | 264 | } |
239 | 265 | ||
240 | void KConfig::load() | 266 | void KConfig::load() |
241 | { | 267 | { |
242 | 268 | ||
243 | 269 | ||
244 | QFile f( mFileName ); | 270 | QFile f( mFileName ); |
245 | if ( !f.open( IO_ReadOnly ) ) { | 271 | if ( !f.open( IO_ReadOnly ) ) { |
246 | qDebug("KConfig: could not open file %s ",mFileName.latin1() ); | 272 | qDebug("KConfig: could not open file %s ",mFileName.latin1() ); |
247 | return; | 273 | return; |
248 | } | 274 | } |
249 | 275 | ||
250 | mBoolMap.clear(); | 276 | mBoolMap.clear(); |
251 | mStringMap.clear(); | 277 | mStringMap.clear(); |
252 | 278 | ||
253 | QTextStream t( &f ); | 279 | QTextStream t( &f ); |
254 | 280 | ||
255 | QString line = t.readLine(); | 281 | QString line = t.readLine(); |
256 | 282 | ||
257 | while ( !line.isNull() ) { | 283 | while ( !line.isNull() ) { |
258 | QStringList tokens = QStringList::split( ",", line ); | 284 | QStringList tokens = QStringList::split( ",", line ); |
259 | if ( tokens[0] == "bool" ) { | 285 | if ( tokens[0] == "bool" ) { |
260 | bool value = false; | 286 | bool value = false; |
261 | if ( tokens[2] == "1" ) value = true; | 287 | if ( tokens[2] == "1" ) value = true; |
262 | mBoolMap.insert( tokens[1], value ); | 288 | mBoolMap.insert( tokens[1], value ); |
263 | } else if ( tokens[0] == "QString" ) { | 289 | } else if ( tokens[0] == "QString" ) { |
264 | QString value = tokens[2]; | 290 | QString value = tokens[2]; |
265 | mStringMap.insert( tokens[1], value ); | 291 | mStringMap.insert( tokens[1], value ); |
266 | } else if ( tokens[0] == "QDateTime" ) { | 292 | } else if ( tokens[0] == "QDateTime" ) { |
267 | #if 0 | 293 | #if 0 |
268 | int year = tokens[2].toInt(); | 294 | int year = tokens[2].toInt(); |
269 | QDateTime dt( QDate( year, | 295 | QDateTime dt( QDate( year, |
270 | tokens[3].toInt(), | 296 | tokens[3].toInt(), |
271 | tokens[4].toInt() ), | 297 | tokens[4].toInt() ), |
272 | QTime( tokens[5].toInt(), tokens[6].toInt(), | 298 | QTime( tokens[5].toInt(), tokens[6].toInt(), |