Diffstat (limited to 'noncore/apps/tinykate/libkate/kateconfig.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/tinykate/libkate/kateconfig.cpp | 219 |
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 | |||
@@ -20,2 +20,10 @@ | |||
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> |
@@ -27,2 +35,3 @@ | |||
27 | 35 | ||
36 | /* STD */ | ||
28 | #include <sys/stat.h> | 37 | #include <sys/stat.h> |
@@ -33,6 +42,2 @@ | |||
33 | 42 | ||
34 | #define QTOPIA_INTERNAL_LANGLIST | ||
35 | #include "kateconfig.h" | ||
36 | #include <qpe/global.h> | ||
37 | |||
38 | 43 | ||
@@ -44,10 +49,10 @@ QString KateConfig::configFilename(const QString& name, Domain d) | |||
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 | } |
@@ -95,3 +100,3 @@ KateConfig::KateConfig( const QString &name, Domain domain ) | |||
95 | { | 100 | { |
96 | qWarning("KateConfig constructor\n"); | 101 | owarn << "KateConfig constructor\n" << oendl; |
97 | git = groups.end(); | 102 | git = groups.end(); |
@@ -106,3 +111,3 @@ KateConfig::KateConfig( const QString &name, Domain domain ) | |||
106 | KateConfig::KateConfig ( const QString &name, bool what ) | 111 | KateConfig::KateConfig ( const QString &name, bool what ) |
107 | : filename( configFilename(name,what ? User : File) ) | 112 | : filename( configFilename(name,what ? User : File) ) |
108 | { | 113 | { |
@@ -120,5 +125,5 @@ KateConfig::~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 | } |
@@ -131,3 +136,3 @@ bool KateConfig::hasKey( const QString &key ) const | |||
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 ); |
@@ -149,5 +154,5 @@ void KateConfig::setGroup( const QString &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 | } |
@@ -174,8 +179,8 @@ void KateConfig::writeEntry( const QString &key, const QString &value ) | |||
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 | } |
@@ -198,8 +203,8 @@ static QString encipher(const QString& plain) | |||
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 | } |
@@ -213,7 +218,7 @@ static QString decipher(const QString& cipher) | |||
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 | } |
@@ -234,4 +239,4 @@ void KateConfig::writeEntryCrypt( const QString &key, const QString &value ) | |||
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 | } |
@@ -239,4 +244,4 @@ void KateConfig::writeEntryCrypt( const QString &key, const QString &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 | } |
@@ -289,3 +294,3 @@ void KateConfig::writeEntry( const QString &key, const QStringList &lst, const Q | |||
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 ); |
@@ -299,3 +304,3 @@ void KateConfig::writeEntry( const QString &key, const QColor &val ) | |||
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(',') ); |
@@ -311,3 +316,3 @@ void KateConfig::writeEntry( const QString &key, const QFont &val ) | |||
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(',') ); |
@@ -323,4 +328,4 @@ void KateConfig::removeEntry( const QString &key ) | |||
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 | } |
@@ -356,7 +361,7 @@ QString KateConfig::readEntry( const QString &key, const QString &deflt ) | |||
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 | } |
@@ -379,7 +384,7 @@ QString KateConfig::readEntryCrypt( const QString &key, const QString &deflt ) | |||
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); |
@@ -399,4 +404,4 @@ QString KateConfig::readEntryDirect( const QString &key, const QString &deflt ) | |||
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 | } |
@@ -404,5 +409,5 @@ QString KateConfig::readEntryDirect( const QString &key, const QString &deflt ) | |||
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 | } |
@@ -422,5 +427,5 @@ int KateConfig::readNumEntry( const QString &key, int deflt ) | |||
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 | } |
@@ -440,5 +445,5 @@ bool KateConfig::readBoolEntry( const QString &key, bool deflt ) | |||
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 | } |
@@ -458,5 +463,5 @@ QStringList KateConfig::readListEntry( const QString &key, const QChar &sep ) | |||
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 | } |
@@ -486,3 +491,3 @@ QValueList<int> KateConfig::readIntListEntry( const QString &key ) const | |||
486 | if ( s.isEmpty() ) | 491 | if ( s.isEmpty() ) |
487 | return il; | 492 | return il; |
488 | 493 | ||
@@ -502,8 +507,8 @@ void KateConfig::clearGroup() | |||
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 | } |
@@ -518,3 +523,3 @@ void KateConfig::write( const QString &fn ) | |||
518 | if ( !fn.isEmpty() ) | 523 | if ( !fn.isEmpty() ) |
519 | filename = fn; | 524 | filename = fn; |
520 | strNewFile = filename + ".new"; | 525 | strNewFile = filename + ".new"; |
@@ -523,9 +528,9 @@ void KateConfig::write( const QString &fn ) | |||
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(); |
@@ -533,9 +538,9 @@ void KateConfig::write( const QString &fn ) | |||
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; |
@@ -543,9 +548,9 @@ void KateConfig::write( const QString &fn ) | |||
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(); |
@@ -553,6 +558,6 @@ void KateConfig::write( const QString &fn ) | |||
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 | } |
@@ -575,4 +580,4 @@ void KateConfig::read() | |||
575 | if ( !QFileInfo( filename ).exists() ) { | 580 | if ( !QFileInfo( filename ).exists() ) { |
576 | git = groups.end(); | 581 | git = groups.end(); |
577 | return; | 582 | return; |
578 | } | 583 | } |
@@ -581,4 +586,4 @@ void KateConfig::read() | |||
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 | } |
@@ -610,21 +615,21 @@ bool KateConfig::parse( const QString &l ) | |||
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 | } |