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
@@ -19,4 +19,12 @@
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>
@@ -26,4 +34,5 @@
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>
@@ -32,8 +41,4 @@
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/*!
@@ -43,12 +48,12 @@ QString 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;
@@ -94,5 +99,5 @@ KateConfig::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();
@@ -105,5 +110,5 @@ KateConfig::KateConfig( const QString &name, Domain domain )
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();
@@ -119,7 +124,7 @@ KateConfig::KateConfig ( const QString &name, bool what )
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
@@ -130,5 +135,5 @@ bool 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();
@@ -148,7 +153,7 @@ void KateConfig::setGroup( const QString &gname )
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;
@@ -173,10 +178,10 @@ void 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}
@@ -197,10 +202,10 @@ static QString encipher(const QString& plain)
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;
@@ -212,9 +217,9 @@ static QString decipher(const QString& cipher)
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;
@@ -233,11 +238,11 @@ void 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}
@@ -288,5 +293,5 @@ void KateConfig::writeEntry( const QString &key, const QStringList &lst, const Q
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}
@@ -298,5 +303,5 @@ void KateConfig::writeEntry( const QString &key, const QColor &val )
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}
@@ -310,5 +315,5 @@ void KateConfig::writeEntry( const QString &key, const QFont &val )
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}
@@ -322,6 +327,6 @@ void 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 );
@@ -355,9 +360,9 @@ QString KateConfig::readEntry( const QString &key, const QString &deflt )
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 );
@@ -378,9 +383,9 @@ QString KateConfig::readEntryCrypt( const QString &key, const QString &deflt )
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}
@@ -398,12 +403,12 @@ QString 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
@@ -421,7 +426,7 @@ int KateConfig::readNumEntry( const QString &key, int deflt )
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
@@ -439,7 +444,7 @@ bool KateConfig::readBoolEntry( const QString &key, bool deflt )
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
@@ -457,7 +462,7 @@ QStringList KateConfig::readListEntry( const QString &key, const QChar &sep )
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
@@ -485,5 +490,5 @@ QValueList<int> KateConfig::readIntListEntry( const QString &key ) const
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 );
@@ -501,10 +506,10 @@ void 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}
@@ -517,43 +522,43 @@ void KateConfig::write( const QString &fn )
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
@@ -574,12 +579,12 @@ void KateConfig::read()
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
@@ -609,23 +614,23 @@ bool 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;