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
@@ -18,6 +18,14 @@
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)
@@ -25,16 +33,13 @@
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
@@ -42,14 +47,14 @@
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}
@@ -93,7 +98,7 @@ QString KateConfig::configFilename(const QString& name, Domain d)
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();
@@ -104,7 +109,7 @@ KateConfig::KateConfig( const QString &name, Domain domain )
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();
@@ -118,9 +123,9 @@ KateConfig::KateConfig ( const QString &name, bool what )
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/*!
@@ -129,7 +134,7 @@ KateConfig::~KateConfig()
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}
@@ -147,9 +152,9 @@ void 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}
@@ -172,12 +177,12 @@ void KateConfig::writeEntry( const QString &key, const char* value )
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
@@ -196,12 +201,12 @@ static QString encipher(const QString& plain)
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}
@@ -211,11 +216,11 @@ static QString decipher(const QString& cipher)
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}
@@ -232,13 +237,13 @@ static QString decipher(const QString& cipher)
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
@@ -287,7 +292,7 @@ void KateConfig::writeEntry( const QString &key, const QStringList &lst, const Q
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
@@ -297,7 +302,7 @@ void KateConfig::writeEntry( const QString &key, const QColor &val )
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
@@ -309,7 +314,7 @@ void KateConfig::writeEntry( const QString &key, const QFont &val )
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
@@ -321,8 +326,8 @@ void KateConfig::writeEntry( const QString &key, const QFont &val )
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;
@@ -354,11 +359,11 @@ QString 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}
@@ -377,11 +382,11 @@ QString 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
@@ -397,14 +402,14 @@ QString KateConfig::readEntryCrypt( const QString &key, const QString &deflt )
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/*!
@@ -420,9 +425,9 @@ int 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/*!
@@ -438,9 +443,9 @@ bool 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/*!
@@ -456,9 +461,9 @@ QStringList 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
@@ -484,7 +489,7 @@ QValueList<int> KateConfig::readIntListEntry( const QString &key ) const
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
@@ -500,12 +505,12 @@ QValueList<int> KateConfig::readIntListEntry( const QString &key ) const
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
@@ -516,45 +521,45 @@ void 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/*!
@@ -573,14 +578,14 @@ void KateConfig::read()
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 );
@@ -608,25 +613,25 @@ void KateConfig::read()
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}