Diffstat (limited to 'noncore/apps/tinykate/libkate/kateconfig.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/tinykate/libkate/kateconfig.cpp | 29 |
1 files changed, 17 insertions, 12 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,41 +9,46 @@ | |||
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 | */ |
42 | QString KateConfig::configFilename(const QString& name, Domain d) | 47 | 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() ) |
@@ -84,50 +89,50 @@ 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 | */ |
93 | KateConfig::KateConfig( const QString &name, Domain domain ) | 98 | 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(); |
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 |
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 | { |
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 | */ |
119 | KateConfig::~KateConfig() | 124 | 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 | } |
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 | */ |
129 | bool KateConfig::hasKey( const QString &key ) const | 134 | 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 ); |
@@ -163,25 +168,25 @@ void 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 | */ |
172 | void KateConfig::writeEntry( const QString &key, const QString &value ) | 177 | 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 | } |
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 |
@@ -223,25 +228,25 @@ static QString decipher(const QString& cipher) | |||
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 | */ |
232 | void KateConfig::writeEntryCrypt( const QString &key, const QString &value ) | 237 | 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 | } |
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 | ||
@@ -312,25 +317,25 @@ void KateConfig::writeEntry( const QString &key, const QFont &val ) | |||
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 | ||
321 | void KateConfig::removeEntry( const QString &key ) | 326 | 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 ); |
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 | ||
@@ -388,25 +393,25 @@ QString KateConfig::readEntryCrypt( const QString &key, const QString &deflt ) | |||
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 | */ |
397 | QString KateConfig::readEntryDirect( const QString &key, const QString &deflt ) | 402 | 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 | ||
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. |
@@ -491,46 +496,46 @@ QValueList<int> KateConfig::readIntListEntry( const QString &key ) const | |||
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 | */ |
500 | void KateConfig::clearGroup() | 505 | 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 | } |
511 | 516 | ||
512 | /*! | 517 | /*! |
513 | \internal | 518 | \internal |
514 | */ | 519 | */ |
515 | void KateConfig::write( const QString &fn ) | 520 | 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 ) |