summaryrefslogtreecommitdiff
path: root/noncore/apps/tinykate/libkate/kateconfig.cpp
Unidiff
Diffstat (limited to 'noncore/apps/tinykate/libkate/kateconfig.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/tinykate/libkate/kateconfig.cpp219
1 files changed, 112 insertions, 107 deletions
diff --git a/noncore/apps/tinykate/libkate/kateconfig.cpp b/noncore/apps/tinykate/libkate/kateconfig.cpp
index 96f91fb..782b629 100644
--- a/noncore/apps/tinykate/libkate/kateconfig.cpp
+++ b/noncore/apps/tinykate/libkate/kateconfig.cpp
@@ -9,56 +9,61 @@
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#define QTOPIA_INTERNAL_LANGLIST
22#include "kateconfig.h"
23
24/* OPIE */
25#include <opie2/odebug.h>
26#include <qpe/global.h>
27
28/* QT */
21#include <qdir.h> 29#include <qdir.h>
22#include <qmessagebox.h> 30#include <qmessagebox.h>
23#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 31#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
24#include <qtextcodec.h> 32#include <qtextcodec.h>
25#endif 33#endif
26#include <qtextstream.h> 34#include <qtextstream.h>
27 35
36/* STD */
28#include <sys/stat.h> 37#include <sys/stat.h>
29#include <sys/types.h> 38#include <sys/types.h>
30#include <fcntl.h> 39#include <fcntl.h>
31#include <stdlib.h> 40#include <stdlib.h>
32#include <unistd.h> 41#include <unistd.h>
33 42
34#define QTOPIA_INTERNAL_LANGLIST
35#include "kateconfig.h"
36#include <qpe/global.h>
37
38 43
39/*! 44/*!
40 \internal 45 \internal
41*/ 46*/
42QString KateConfig::configFilename(const QString& name, Domain d) 47QString KateConfig::configFilename(const QString& name, Domain d)
43{ 48{
44 switch (d) { 49 switch (d) {
45 case File: 50 case File:
46 return name; 51 return name;
47 case User: { 52 case User: {
48 QDir dir = (QString(getenv("HOME")) + "/Settings"); 53 QDir dir = (QString(getenv("HOME")) + "/Settings");
49 if ( !dir.exists() ) 54 if ( !dir.exists() )
50 mkdir(dir.path().local8Bit(),0700); 55 mkdir(dir.path().local8Bit(),0700);
51 return dir.path() + "/" + name + ".conf"; 56 return dir.path() + "/" + name + ".conf";
52 } 57 }
53 } 58 }
54 return name; 59 return name;
55} 60}
56 61
57/*! 62/*!
58 \class KateConfig config.h 63 \class KateConfig config.h
59 \brief The KateConfig class provides for saving application cofniguration state. 64 \brief The KateConfig class provides for saving application cofniguration state.
60 65
61 You should keep a KateConfig in existence only while you do not want others 66 You should keep a KateConfig in existence only while you do not want others
62 to be able to change the state. There is no locking currently, but there 67 to be able to change the state. There is no locking currently, but there
63 may be in the future. 68 may be in the future.
64*/ 69*/
@@ -84,170 +89,170 @@ QString KateConfig::configFilename(const QString& name, Domain d)
84 You must call setGroup() before doing much else with the KateConfig. 89 You must call setGroup() before doing much else with the KateConfig.
85 90
86 In the default Domain, \e User, 91 In the default Domain, \e User,
87 the configuration is user-specific. \a name should not contain "/" in 92 the configuration is user-specific. \a name should not contain "/" in
88 this case, and in general should be the name of the C++ class that is 93 this case, and in general should be the name of the C++ class that is
89 primarily responsible for maintaining the configuration. 94 primarily responsible for maintaining the configuration.
90 95
91 In the File Domain, \a name is an absolute filename. 96 In the File Domain, \a name is an absolute filename.
92*/ 97*/
93KateConfig::KateConfig( const QString &name, Domain domain ) 98KateConfig::KateConfig( const QString &name, Domain domain )
94 : filename( configFilename(name,domain) ) 99 : filename( configFilename(name,domain) )
95{ 100{
96 qWarning("KateConfig constructor\n"); 101 owarn << "KateConfig constructor\n" << oendl;
97 git = groups.end(); 102 git = groups.end();
98 read(); 103 read();
99 QStringList l = Global::languageList(); 104 QStringList l = Global::languageList();
100 lang = l[0]; 105 lang = l[0];
101 glang = l[1]; 106 glang = l[1];
102} 107}
103 108
104 109
105// Sharp ROM compatibility 110// Sharp ROM compatibility
106KateConfig::KateConfig ( const QString &name, bool what ) 111KateConfig::KateConfig ( const QString &name, bool what )
107 : filename( configFilename(name,what ? User : File) ) 112 : filename( configFilename(name,what ? User : File) )
108{ 113{
109 git = groups.end(); 114 git = groups.end();
110 read(); 115 read();
111 QStringList l = Global::languageList(); 116 QStringList l = Global::languageList();
112 lang = l[0]; 117 lang = l[0];
113 glang = l[1]; 118 glang = l[1];
114} 119}
115 120
116/*! 121/*!
117 Writes any changes to disk and destroys the in-memory object. 122 Writes any changes to disk and destroys the in-memory object.
118*/ 123*/
119KateConfig::~KateConfig() 124KateConfig::~KateConfig()
120{ 125{
121 qWarning("KateConfig destructor\n"); 126 owarn << "KateConfig destructor\n" << oendl;
122 if ( changed ) 127 if ( changed )
123 write(); 128 write();
124} 129}
125 130
126/*! 131/*!
127 Returns whether the current group has an entry called \a key. 132 Returns whether the current group has an entry called \a key.
128*/ 133*/
129bool KateConfig::hasKey( const QString &key ) const 134bool KateConfig::hasKey( const QString &key ) const
130{ 135{
131 if ( groups.end() == git ) 136 if ( groups.end() == git )
132 return FALSE; 137 return FALSE;
133 KateConfigGroup::ConstIterator it = ( *git ).find( key ); 138 KateConfigGroup::ConstIterator it = ( *git ).find( key );
134 return it != ( *git ).end(); 139 return it != ( *git ).end();
135} 140}
136 141
137/*! 142/*!
138 Sets the current group for subsequent reading and writing of 143 Sets the current group for subsequent reading and writing of
139 entries to \a gname. Grouping allows the application to partition the namespace. 144 entries to \a gname. Grouping allows the application to partition the namespace.
140 145
141 This function must be called prior to any reading or writing 146 This function must be called prior to any reading or writing
142 of entries. 147 of entries.
143 148
144 The \a gname must not be empty. 149 The \a gname must not be empty.
145*/ 150*/
146void KateConfig::setGroup( const QString &gname ) 151void KateConfig::setGroup( const QString &gname )
147{ 152{
148 QMap< QString, KateConfigGroup>::Iterator it = groups.find( gname ); 153 QMap< QString, KateConfigGroup>::Iterator it = groups.find( gname );
149 if ( it == groups.end() ) { 154 if ( it == groups.end() ) {
150 git = groups.insert( gname, KateConfigGroup() ); 155 git = groups.insert( gname, KateConfigGroup() );
151 changed = TRUE; 156 changed = TRUE;
152 return; 157 return;
153 } 158 }
154 git = it; 159 git = it;
155} 160}
156 161
157/*! 162/*!
158 Writes a (\a key, \a value) entry to the current group. 163 Writes a (\a key, \a value) entry to the current group.
159 164
160 \sa readEntry() 165 \sa readEntry()
161*/ 166*/
162void KateConfig::writeEntry( const QString &key, const char* value ) 167void KateConfig::writeEntry( const QString &key, const char* value )
163{ 168{
164 writeEntry(key,QString(value)); 169 writeEntry(key,QString(value));
165} 170}
166 171
167/*! 172/*!
168 Writes a (\a key, \a value) entry to the current group. 173 Writes a (\a key, \a value) entry to the current group.
169 174
170 \sa readEntry() 175 \sa readEntry()
171*/ 176*/
172void KateConfig::writeEntry( const QString &key, const QString &value ) 177void KateConfig::writeEntry( const QString &key, const QString &value )
173{ 178{
174 if ( git == groups.end() ) { 179 if ( git == groups.end() ) {
175 qWarning( "no group set" ); 180 owarn << "no group set" << oendl;
176 return; 181 return;
177 } 182 }
178 if ( (*git)[key] != value ) { 183 if ( (*git)[key] != value ) {
179 ( *git ).insert( key, value ); 184 ( *git ).insert( key, value );
180 changed = TRUE; 185 changed = TRUE;
181 } 186 }
182} 187}
183 188
184/* 189/*
185 Note that the degree of protection offered by the encryption here is 190 Note that the degree of protection offered by the encryption here is
186 only sufficient to avoid the most casual observation of the configuration 191 only sufficient to avoid the most casual observation of the configuration
187 files. People with access to the files can write down the contents and 192 files. People with access to the files can write down the contents and
188 decrypt it using this source code. 193 decrypt it using this source code.
189 194
190 Conceivably, and at some burden to the user, this encryption could 195 Conceivably, and at some burden to the user, this encryption could
191 be improved. 196 be improved.
192*/ 197*/
193static QString encipher(const QString& plain) 198static QString encipher(const QString& plain)
194{ 199{
195 // mainly, we make it long 200 // mainly, we make it long
196 QString cipher; 201 QString cipher;
197 int mix=28730492; 202 int mix=28730492;
198 for (int i=0; i<(int)plain.length(); i++) { 203 for (int i=0; i<(int)plain.length(); i++) {
199 int u = plain[i].unicode(); 204 int u = plain[i].unicode();
200 int c = u ^ mix; 205 int c = u ^ mix;
201 QString x = QString::number(c,36); 206 QString x = QString::number(c,36);
202 cipher.append(QChar('a'+x.length())); 207 cipher.append(QChar('a'+x.length()));
203 cipher.append(x); 208 cipher.append(x);
204 mix *= u; 209 mix *= u;
205 } 210 }
206 return cipher; 211 return cipher;
207} 212}
208 213
209static QString decipher(const QString& cipher) 214static QString decipher(const QString& cipher)
210{ 215{
211 QString plain; 216 QString plain;
212 int mix=28730492; 217 int mix=28730492;
213 for (int i=0; i<(int)cipher.length();) { 218 for (int i=0; i<(int)cipher.length();) {
214 int l = cipher[i].unicode()-'a'; 219 int l = cipher[i].unicode()-'a';
215 QString x = cipher.mid(i+1,l); i+=l+1; 220 QString x = cipher.mid(i+1,l); i+=l+1;
216 int u = x.toInt(0,36) ^ mix; 221 int u = x.toInt(0,36) ^ mix;
217 plain.append(QChar(u)); 222 plain.append(QChar(u));
218 mix *= u; 223 mix *= u;
219 } 224 }
220 return plain; 225 return plain;
221} 226}
222 227
223/*! 228/*!
224 Writes an encrypted (\a key, \a value) entry to the current group. 229 Writes an encrypted (\a key, \a value) entry to the current group.
225 230
226 Note that the degree of protection offered by the encryption is 231 Note that the degree of protection offered by the encryption is
227 only sufficient to avoid the most casual observation of the configuration 232 only sufficient to avoid the most casual observation of the configuration
228 files. 233 files.
229 234
230 \sa readEntry() 235 \sa readEntry()
231*/ 236*/
232void KateConfig::writeEntryCrypt( const QString &key, const QString &value ) 237void KateConfig::writeEntryCrypt( const QString &key, const QString &value )
233{ 238{
234 if ( git == groups.end() ) { 239 if ( git == groups.end() ) {
235 qWarning( "no group set" ); 240 owarn << "no group set" << oendl;
236 return; 241 return;
237 } 242 }
238 QString evalue = encipher(value); 243 QString evalue = encipher(value);
239 if ( (*git)[key] != evalue ) { 244 if ( (*git)[key] != evalue ) {
240 ( *git ).insert( key, evalue ); 245 ( *git ).insert( key, evalue );
241 changed = TRUE; 246 changed = TRUE;
242 } 247 }
243} 248}
244 249
245/*! 250/*!
246 Writes a (\a key, \a num) entry to the current group. 251 Writes a (\a key, \a num) entry to the current group.
247 252
248 \sa readNumEntry() 253 \sa readNumEntry()
249*/ 254*/
250void KateConfig::writeEntry( const QString &key, int num ) 255void KateConfig::writeEntry( const QString &key, int num )
251{ 256{
252 QString s; 257 QString s;
253 s.setNum( num ); 258 s.setNum( num );
@@ -278,60 +283,60 @@ void KateConfig::writeEntry( const QString &key, bool b )
278 283
279/*! 284/*!
280 Writes a (\a key, \a lst) entry to the current group. The list 285 Writes a (\a key, \a lst) entry to the current group. The list
281 is separated by \a sep, so the strings must not contain that character. 286 is separated by \a sep, so the strings must not contain that character.
282 287
283 \sa readListEntry() 288 \sa readListEntry()
284*/ 289*/
285void KateConfig::writeEntry( const QString &key, const QStringList &lst, const QChar &sep ) 290void KateConfig::writeEntry( const QString &key, const QStringList &lst, const QChar &sep )
286{ 291{
287 QString s; 292 QString s;
288 QStringList::ConstIterator it = lst.begin(); 293 QStringList::ConstIterator it = lst.begin();
289 for ( ; it != lst.end(); ++it ) 294 for ( ; it != lst.end(); ++it )
290 s += *it + sep; 295 s += *it + sep;
291 writeEntry( key, s ); 296 writeEntry( key, s );
292} 297}
293 298
294void KateConfig::writeEntry( const QString &key, const QColor &val ) 299void KateConfig::writeEntry( const QString &key, const QColor &val )
295{ 300{
296 QStringList l; 301 QStringList l;
297 l.append( QString().setNum(val.red()) ); 302 l.append( QString().setNum(val.red()) );
298 l.append( QString().setNum(val.green()) ); 303 l.append( QString().setNum(val.green()) );
299 l.append( QString().setNum(val.blue()) ); 304 l.append( QString().setNum(val.blue()) );
300 305
301 writeEntry( key, l, QChar(',') ); 306 writeEntry( key, l, QChar(',') );
302} 307}
303 308
304void KateConfig::writeEntry( const QString &key, const QFont &val ) 309void KateConfig::writeEntry( const QString &key, const QFont &val )
305{ 310{
306 QStringList l; 311 QStringList l;
307 l.append( val.family() ); 312 l.append( val.family() );
308 l.append( QString().setNum(val.pointSize()) ); 313 l.append( QString().setNum(val.pointSize()) );
309 l.append( QString().setNum(val.weight()) ); 314 l.append( QString().setNum(val.weight()) );
310 l.append( QString().setNum((int)val.italic()) ); 315 l.append( QString().setNum((int)val.italic()) );
311 l.append( QString().setNum((int)val.charSet()) ); 316 l.append( QString().setNum((int)val.charSet()) );
312 317
313 writeEntry( key, l, QChar(',') ); 318 writeEntry( key, l, QChar(',') );
314} 319}
315 320
316/*! 321/*!
317 Removes the \a key entry from the current group. Does nothing if 322 Removes the \a key entry from the current group. Does nothing if
318 there is no such entry. 323 there is no such entry.
319*/ 324*/
320 325
321void KateConfig::removeEntry( const QString &key ) 326void KateConfig::removeEntry( const QString &key )
322{ 327{
323 if ( git == groups.end() ) { 328 if ( git == groups.end() ) {
324 qWarning( "no group set" ); 329 owarn << "no group set" << oendl;
325 return; 330 return;
326 } 331 }
327 ( *git ).remove( key ); 332 ( *git ).remove( key );
328 changed = TRUE; 333 changed = TRUE;
329} 334}
330 335
331/*! 336/*!
332 \fn bool KateConfig::operator == ( const KateConfig & other ) const 337 \fn bool KateConfig::operator == ( const KateConfig & other ) const
333 338
334 Tests for equality with \a other. KateConfig objects are equal if they refer to the same filename. 339 Tests for equality with \a other. KateConfig objects are equal if they refer to the same filename.
335*/ 340*/
336 341
337/*! 342/*!
@@ -345,129 +350,129 @@ void KateConfig::removeEntry( const QString &key )
345 350
346 Reads a string entry stored with \a key, defaulting to \a deflt if there is no entry. 351 Reads a string entry stored with \a key, defaulting to \a deflt if there is no entry.
347*/ 352*/
348 353
349/*! 354/*!
350 \internal 355 \internal
351 For compatibility, non-const version. 356 For compatibility, non-const version.
352*/ 357*/
353QString KateConfig::readEntry( const QString &key, const QString &deflt ) 358QString KateConfig::readEntry( const QString &key, const QString &deflt )
354{ 359{
355 QString res = readEntryDirect( key+"["+lang+"]" ); 360 QString res = readEntryDirect( key+"["+lang+"]" );
356 if ( !res.isNull() ) 361 if ( !res.isNull() )
357 return res; 362 return res;
358 if ( !glang.isEmpty() ) { 363 if ( !glang.isEmpty() ) {
359 res = readEntryDirect( key+"["+glang+"]" ); 364 res = readEntryDirect( key+"["+glang+"]" );
360 if ( !res.isNull() ) 365 if ( !res.isNull() )
361 return res; 366 return res;
362 } 367 }
363 return readEntryDirect( key, deflt ); 368 return readEntryDirect( key, deflt );
364} 369}
365 370
366/*! 371/*!
367 \fn QString KateConfig::readEntryCrypt( const QString &key, const QString &deflt ) const 372 \fn QString KateConfig::readEntryCrypt( const QString &key, const QString &deflt ) const
368 373
369 Reads an encrypted string entry stored with \a key, defaulting to \a deflt if there is no entry. 374 Reads an encrypted string entry stored with \a key, defaulting to \a deflt if there is no entry.
370*/ 375*/
371 376
372/*! 377/*!
373 \internal 378 \internal
374 For compatibility, non-const version. 379 For compatibility, non-const version.
375*/ 380*/
376QString KateConfig::readEntryCrypt( const QString &key, const QString &deflt ) 381QString KateConfig::readEntryCrypt( const QString &key, const QString &deflt )
377{ 382{
378 QString res = readEntryDirect( key+"["+lang+"]" ); 383 QString res = readEntryDirect( key+"["+lang+"]" );
379 if ( res.isNull() && glang.isEmpty() ) 384 if ( res.isNull() && glang.isEmpty() )
380 res = readEntryDirect( key+"["+glang+"]" ); 385 res = readEntryDirect( key+"["+glang+"]" );
381 if ( res.isNull() ) 386 if ( res.isNull() )
382 res = readEntryDirect( key, QString::null ); 387 res = readEntryDirect( key, QString::null );
383 if ( res.isNull() ) 388 if ( res.isNull() )
384 return deflt; 389 return deflt;
385 return decipher(res); 390 return decipher(res);
386} 391}
387 392
388/*! 393/*!
389 \fn QString KateConfig::readEntryDirect( const QString &key, const QString &deflt ) const 394 \fn QString KateConfig::readEntryDirect( const QString &key, const QString &deflt ) const
390 \internal 395 \internal
391*/ 396*/
392 397
393/*! 398/*!
394 \internal 399 \internal
395 For compatibility, non-const version. 400 For compatibility, non-const version.
396*/ 401*/
397QString KateConfig::readEntryDirect( const QString &key, const QString &deflt ) 402QString KateConfig::readEntryDirect( const QString &key, const QString &deflt )
398{ 403{
399 if ( git == groups.end() ) { 404 if ( git == groups.end() ) {
400 //qWarning( "no group set" ); 405 //owarn << "no group set" << oendl;
401 return deflt; 406 return deflt;
402 } 407 }
403 KateConfigGroup::ConstIterator it = ( *git ).find( key ); 408 KateConfigGroup::ConstIterator it = ( *git ).find( key );
404 if ( it != ( *git ).end() ) 409 if ( it != ( *git ).end() )
405 return *it; 410 return *it;
406 else 411 else
407 return deflt; 412 return deflt;
408} 413}
409 414
410/*! 415/*!
411 \fn int KateConfig::readNumEntry( const QString &key, int deflt ) const 416 \fn int KateConfig::readNumEntry( const QString &key, int deflt ) const
412 Reads a numeric entry stored with \a key, defaulting to \a deflt if there is no entry. 417 Reads a numeric entry stored with \a key, defaulting to \a deflt if there is no entry.
413*/ 418*/
414 419
415/*! 420/*!
416 \internal 421 \internal
417 For compatibility, non-const version. 422 For compatibility, non-const version.
418*/ 423*/
419int KateConfig::readNumEntry( const QString &key, int deflt ) 424int KateConfig::readNumEntry( const QString &key, int deflt )
420{ 425{
421 QString s = readEntry( key ); 426 QString s = readEntry( key );
422 if ( s.isEmpty() ) 427 if ( s.isEmpty() )
423 return deflt; 428 return deflt;
424 else 429 else
425 return s.toInt(); 430 return s.toInt();
426} 431}
427 432
428/*! 433/*!
429 \fn bool KateConfig::readBoolEntry( const QString &key, bool deflt ) const 434 \fn bool KateConfig::readBoolEntry( const QString &key, bool deflt ) const
430 Reads a bool entry stored with \a key, defaulting to \a deflt if there is no entry. 435 Reads a bool entry stored with \a key, defaulting to \a deflt if there is no entry.
431*/ 436*/
432 437
433/*! 438/*!
434 \internal 439 \internal
435 For compatibility, non-const version. 440 For compatibility, non-const version.
436*/ 441*/
437bool KateConfig::readBoolEntry( const QString &key, bool deflt ) 442bool KateConfig::readBoolEntry( const QString &key, bool deflt )
438{ 443{
439 QString s = readEntry( key ); 444 QString s = readEntry( key );
440 if ( s.isEmpty() ) 445 if ( s.isEmpty() )
441 return deflt; 446 return deflt;
442 else 447 else
443 return (bool)s.toInt(); 448 return (bool)s.toInt();
444} 449}
445 450
446/*! 451/*!
447 \fn QStringList KateConfig::readListEntry( const QString &key, const QChar &sep ) const 452 \fn QStringList KateConfig::readListEntry( const QString &key, const QChar &sep ) const
448 Reads a string list entry stored with \a key, and with \a sep as the separator. 453 Reads a string list entry stored with \a key, and with \a sep as the separator.
449*/ 454*/
450 455
451/*! 456/*!
452 \internal 457 \internal
453 For compatibility, non-const version. 458 For compatibility, non-const version.
454*/ 459*/
455QStringList KateConfig::readListEntry( const QString &key, const QChar &sep ) 460QStringList KateConfig::readListEntry( const QString &key, const QChar &sep )
456{ 461{
457 QString s = readEntry( key ); 462 QString s = readEntry( key );
458 if ( s.isEmpty() ) 463 if ( s.isEmpty() )
459 return QStringList(); 464 return QStringList();
460 else 465 else
461 return QStringList::split( sep, s ); 466 return QStringList::split( sep, s );
462} 467}
463 468
464QColor KateConfig::readColorEntry( const QString &key, const QColor &def ) const 469QColor KateConfig::readColorEntry( const QString &key, const QColor &def ) const
465{ 470{
466 QStringList list = readListEntry(key, QChar(',')); 471 QStringList list = readListEntry(key, QChar(','));
467 if( list.count() != 3 ) 472 if( list.count() != 3 )
468 return def; 473 return def;
469 474
470 return QColor(list[0].toInt(), list[1].toInt(), list[2].toInt()); 475 return QColor(list[0].toInt(), list[1].toInt(), list[2].toInt());
471} 476}
472 477
473QFont KateConfig::readFontEntry( const QString &key, const QFont &def ) const 478QFont KateConfig::readFontEntry( const QString &key, const QFont &def ) const
@@ -475,121 +480,121 @@ QFont KateConfig::readFontEntry( const QString &key, const QFont &def ) const
475 QStringList list = readListEntry(key, QChar(',')); 480 QStringList list = readListEntry(key, QChar(','));
476 if( list.count() != 5 ) 481 if( list.count() != 5 )
477 return def; 482 return def;
478 483
479 return QFont(list[0], list[1].toInt(), list[2].toInt(), (bool)list[3].toInt(), (QFont::CharSet)list[4].toInt()); 484 return QFont(list[0], list[1].toInt(), list[2].toInt(), (bool)list[3].toInt(), (QFont::CharSet)list[4].toInt());
480} 485}
481 486
482QValueList<int> KateConfig::readIntListEntry( const QString &key ) const 487QValueList<int> KateConfig::readIntListEntry( const QString &key ) const
483{ 488{
484 QString s = readEntry( key ); 489 QString s = readEntry( key );
485 QValueList<int> il; 490 QValueList<int> il;
486 if ( s.isEmpty() ) 491 if ( s.isEmpty() )
487 return il; 492 return il;
488 493
489 QStringList l = QStringList::split( QChar(','), s ); 494 QStringList l = QStringList::split( QChar(','), s );
490 495
491 QStringList::Iterator l_it; 496 QStringList::Iterator l_it;
492 for( l_it = l.begin(); l_it != l.end(); ++l_it ) 497 for( l_it = l.begin(); l_it != l.end(); ++l_it )
493 il.append( (*l_it).toInt() ); 498 il.append( (*l_it).toInt() );
494 return il; 499 return il;
495} 500}
496 501
497/*! 502/*!
498 Removes all entries from the current group. 503 Removes all entries from the current group.
499*/ 504*/
500void KateConfig::clearGroup() 505void KateConfig::clearGroup()
501{ 506{
502 if ( git == groups.end() ) { 507 if ( git == groups.end() ) {
503 qWarning( "no group set" ); 508 owarn << "no group set" << oendl;
504 return; 509 return;
505 } 510 }
506 if ( !(*git).isEmpty() ) { 511 if ( !(*git).isEmpty() ) {
507 ( *git ).clear(); 512 ( *git ).clear();
508 changed = TRUE; 513 changed = TRUE;
509 } 514 }
510} 515}
511 516
512/*! 517/*!
513 \internal 518 \internal
514*/ 519*/
515void KateConfig::write( const QString &fn ) 520void KateConfig::write( const QString &fn )
516{ 521{
517 QString strNewFile; 522 QString strNewFile;
518 if ( !fn.isEmpty() ) 523 if ( !fn.isEmpty() )
519 filename = fn; 524 filename = fn;
520 strNewFile = filename + ".new"; 525 strNewFile = filename + ".new";
521 526
522 QFile f( strNewFile ); 527 QFile f( strNewFile );
523 if ( !f.open( IO_WriteOnly|IO_Raw ) ) { 528 if ( !f.open( IO_WriteOnly|IO_Raw ) ) {
524 qWarning( "could not open for writing `%s'", strNewFile.latin1() ); 529 owarn << "could not open for writing `" << strNewFile << "'" << oendl;
525 git = groups.end(); 530 git = groups.end();
526 return; 531 return;
527 } 532 }
528 533
529 QString str; 534 QString str;
530 QCString cstr; 535 QCString cstr;
531 QMap< QString, KateConfigGroup >::Iterator g_it = groups.begin(); 536 QMap< QString, KateConfigGroup >::Iterator g_it = groups.begin();
532 537
533 for ( ; g_it != groups.end(); ++g_it ) { 538 for ( ; g_it != groups.end(); ++g_it ) {
534 str += "[" + g_it.key() + "]\n"; 539 str += "[" + g_it.key() + "]\n";
535 KateConfigGroup::Iterator e_it = ( *g_it ).begin(); 540 KateConfigGroup::Iterator e_it = ( *g_it ).begin();
536 for ( ; e_it != ( *g_it ).end(); ++e_it ) 541 for ( ; e_it != ( *g_it ).end(); ++e_it )
537 str += e_it.key() + " = " + *e_it + "\n"; 542 str += e_it.key() + " = " + *e_it + "\n";
538 } 543 }
539 cstr = str.utf8(); 544 cstr = str.utf8();
540 545
541 int total_length; 546 int total_length;
542 total_length = f.writeBlock( cstr.data(), cstr.length() ); 547 total_length = f.writeBlock( cstr.data(), cstr.length() );
543 if ( total_length != int(cstr.length()) ) { 548 if ( total_length != int(cstr.length()) ) {
544 QMessageBox::critical( 0, QObject::tr("Out of Space"), 549 QMessageBox::critical( 0, QObject::tr("Out of Space"),
545 QObject::tr("There was a problem creating\nKateConfiguration Information \nfor this program.\n\nPlease free up some space and\ntry again.") ); 550 QObject::tr("There was a problem creating\nKateConfiguration Information \nfor this program.\n\nPlease free up some space and\ntry again.") );
546 f.close(); 551 f.close();
547 QFile::remove( strNewFile ); 552 QFile::remove( strNewFile );
548 return; 553 return;
549 } 554 }
550 555
551 f.close(); 556 f.close();
552 // now rename the file... 557 // now rename the file...
553 if ( rename( strNewFile, filename ) < 0 ) { 558 if ( rename( strNewFile, filename ) < 0 ) {
554 qWarning( "problem renaming the file %s to %s", strNewFile.latin1(), 559 qWarning( "problem renaming the file %s to %s", strNewFile.latin1(),
555 filename.latin1() ); 560 filename.latin1() );
556 QFile::remove( strNewFile ); 561 QFile::remove( strNewFile );
557 } 562 }
558} 563}
559 564
560/*! 565/*!
561 Returns whether the KateConfig is in a valid state. 566 Returns whether the KateConfig is in a valid state.
562*/ 567*/
563bool KateConfig::isValid() const 568bool KateConfig::isValid() const
564{ 569{
565 return groups.end() != git; 570 return groups.end() != git;
566} 571}
567 572
568/*! 573/*!
569 \internal 574 \internal
570*/ 575*/
571void KateConfig::read() 576void KateConfig::read()
572{ 577{
573 changed = FALSE; 578 changed = FALSE;
574 579
575 if ( !QFileInfo( filename ).exists() ) { 580 if ( !QFileInfo( filename ).exists() ) {
576 git = groups.end(); 581 git = groups.end();
577 return; 582 return;
578 } 583 }
579 584
580 QFile f( filename ); 585 QFile f( filename );
581 if ( !f.open( IO_ReadOnly ) ) { 586 if ( !f.open( IO_ReadOnly ) ) {
582 git = groups.end(); 587 git = groups.end();
583 return; 588 return;
584 } 589 }
585 590
586 QTextStream s( &f ); 591 QTextStream s( &f );
587#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 592#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
588 // The below should work, but doesn't in Qt 2.3.0 593 // The below should work, but doesn't in Qt 2.3.0
589 s.setCodec( QTextCodec::codecForMib( 106 ) ); 594 s.setCodec( QTextCodec::codecForMib( 106 ) );
590#else 595#else
591 s.setEncoding( QTextStream::UnicodeUTF8 ); 596 s.setEncoding( QTextStream::UnicodeUTF8 );
592#endif 597#endif
593 598
594 QStringList list = QStringList::split('\n', s.read() ); 599 QStringList list = QStringList::split('\n', s.read() );
595 f.close(); 600 f.close();
@@ -599,34 +604,34 @@ void KateConfig::read()
599 git = groups.end(); 604 git = groups.end();
600 return; 605 return;
601 } 606 }
602 } 607 }
603} 608}
604 609
605/*! 610/*!
606 \internal 611 \internal
607*/ 612*/
608bool KateConfig::parse( const QString &l ) 613bool KateConfig::parse( const QString &l )
609{ 614{
610 QString line = l.stripWhiteSpace(); 615 QString line = l.stripWhiteSpace();
611 616
612 if ( line [0] == QChar ( '#' )) 617 if ( line [0] == QChar ( '#' ))
613 return true; // ignore comments 618 return true; // ignore comments
614 619
615 if ( line[ 0 ] == QChar( '[' ) ) { 620 if ( line[ 0 ] == QChar( '[' ) ) {
616 QString gname = line; 621 QString gname = line;
617 gname = gname.remove( 0, 1 ); 622 gname = gname.remove( 0, 1 );
618 if ( gname[ (int)gname.length() - 1 ] == QChar( ']' ) ) 623 if ( gname[ (int)gname.length() - 1 ] == QChar( ']' ) )
619 gname = gname.remove( gname.length() - 1, 1 ); 624 gname = gname.remove( gname.length() - 1, 1 );
620 git = groups.insert( gname, KateConfigGroup() ); 625 git = groups.insert( gname, KateConfigGroup() );
621 } else if ( !line.isEmpty() ) { 626 } else if ( !line.isEmpty() ) {
622 if ( git == groups.end() ) 627 if ( git == groups.end() )
623 return FALSE; 628 return FALSE;
624 int eq = line.find( '=' ); 629 int eq = line.find( '=' );
625 if ( eq == -1 ) 630 if ( eq == -1 )
626 return FALSE; 631 return FALSE;
627 QString key = line.left(eq).stripWhiteSpace(); 632 QString key = line.left(eq).stripWhiteSpace();
628 QString value = line.mid(eq+1).stripWhiteSpace(); 633 QString value = line.mid(eq+1).stripWhiteSpace();
629 ( *git ).insert( key, value ); 634 ( *git ).insert( key, value );
630 } 635 }
631 return TRUE; 636 return TRUE;
632} 637}