author | zecke <zecke> | 2004-12-24 23:05:54 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-12-24 23:05:54 (UTC) |
commit | eb16a7b3d17b0659a7d83900843cef8efb510ceb (patch) (unidiff) | |
tree | 7e493f8b38e9e1a3553d4e87fb36a962acd82c5c | |
parent | d36845f5f7e7d6bd49529524cdc9f39ce1164491 (diff) | |
download | opie-eb16a7b3d17b0659a7d83900843cef8efb510ceb.zip opie-eb16a7b3d17b0659a7d83900843cef8efb510ceb.tar.gz opie-eb16a7b3d17b0659a7d83900843cef8efb510ceb.tar.bz2 |
Config:
Merged:
void writeEntry( const QString &key, const QStringList &lst)
QStringList readListEntry( const QString &key ) const
void removeGroup()
void removeGroup(const QString&)
QStringList allGroups() const
Uninlined:
const versions of read*Entry
bool hasGroup ( const QString &gname )const
QStringList groupList ( )const
Marked these methods as NOT_IN_QPE, NOT_IN_SHARP, QTOPIA_MERGED_METHOD(version)
to make them weak by default and to know which functions needs to be defined
for possible SHARP.ROM versions
-rw-r--r-- | library/config.cpp | 164 | ||||
-rw-r--r-- | library/config.h | 33 | ||||
-rw-r--r-- | library/qpeglobal.h | 3 |
3 files changed, 182 insertions, 18 deletions
diff --git a/library/config.cpp b/library/config.cpp index 664ca34..61ff089 100644 --- a/library/config.cpp +++ b/library/config.cpp | |||
@@ -1,258 +1,258 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000,2004 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
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 | #include <qdir.h> | 21 | #include <qdir.h> |
22 | #include <qmessagebox.h> | 22 | #include <qmessagebox.h> |
23 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) | 23 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) |
24 | #include <qtextcodec.h> | 24 | #include <qtextcodec.h> |
25 | #endif | 25 | #endif |
26 | #include <qtextstream.h> | 26 | #include <qtextstream.h> |
27 | 27 | ||
28 | #include <sys/stat.h> | 28 | #include <sys/stat.h> |
29 | #include <sys/types.h> | 29 | #include <sys/types.h> |
30 | #include <fcntl.h> | 30 | #include <fcntl.h> |
31 | #include <stdlib.h> | 31 | #include <stdlib.h> |
32 | #include <unistd.h> | 32 | #include <unistd.h> |
33 | 33 | ||
34 | #define QTOPIA_INTERNAL_LANGLIST | 34 | #define QTOPIA_INTERNAL_LANGLIST |
35 | #include "config.h" | 35 | #include "config.h" |
36 | #include "global.h" | 36 | #include "global.h" |
37 | 37 | ||
38 | 38 | ||
39 | /*! | 39 | /*! |
40 | \internal | 40 | \internal |
41 | */ | 41 | */ |
42 | QString Config::configFilename(const QString& name, Domain d) | 42 | QString Config::configFilename(const QString& name, Domain d) |
43 | { | 43 | { |
44 | switch (d) { | 44 | switch (d) { |
45 | case File: | 45 | case File: |
46 | return name; | 46 | return name; |
47 | case User: { | 47 | case User: { |
48 | QDir dir = (QString(getenv("HOME")) + "/Settings"); | 48 | QDir dir = (QString(getenv("HOME")) + "/Settings"); |
49 | if ( !dir.exists() ) | 49 | if ( !dir.exists() ) |
50 | mkdir(dir.path().local8Bit(),0700); | 50 | mkdir(dir.path().local8Bit(),0700); |
51 | return dir.path() + "/" + name + ".conf"; | 51 | return dir.path() + "/" + name + ".conf"; |
52 | } | 52 | } |
53 | } | 53 | } |
54 | return name; | 54 | return name; |
55 | } | 55 | } |
56 | 56 | ||
57 | /*! | 57 | /*! |
58 | \class Config config.h | 58 | \class Config config.h |
59 | \brief The Config class provides for saving application cofniguration state. | 59 | \brief The Config class provides for saving application cofniguration state. |
60 | 60 | ||
61 | You should keep a Config in existence only while you do not want others | 61 | You should keep a Config in existence only while you do not want others |
62 | to be able to change the state. There is no locking currently, but there | 62 | to be able to change the state. There is no locking currently, but there |
63 | may be in the future. | 63 | may be in the future. |
64 | */ | 64 | */ |
65 | 65 | ||
66 | /*! | 66 | /*! |
67 | \enum Config::ConfigGroup | 67 | \enum Config::ConfigGroup |
68 | \internal | 68 | \internal |
69 | */ | 69 | */ |
70 | 70 | ||
71 | /*! | 71 | /*! |
72 | \enum Config::Domain | 72 | \enum Config::Domain |
73 | 73 | ||
74 | \value File | 74 | \value File |
75 | \value User | 75 | \value User |
76 | 76 | ||
77 | See Config for details. | 77 | See Config for details. |
78 | */ | 78 | */ |
79 | 79 | ||
80 | /*! | 80 | /*! |
81 | Constructs a config that will load or create a configuration with the | 81 | Constructs a config that will load or create a configuration with the |
82 | given \a name in the given \a domain. | 82 | given \a name in the given \a domain. |
83 | 83 | ||
84 | You must call setGroup() before doing much else with the Config. | 84 | You must call setGroup() before doing much else with the Config. |
85 | 85 | ||
86 | In the default Domain, \e User, | 86 | In the default Domain, \e User, |
87 | the configuration is user-specific. \a name should not contain "/" in | 87 | 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 | 88 | this case, and in general should be the name of the C++ class that is |
89 | primarily responsible for maintaining the configuration. | 89 | primarily responsible for maintaining the configuration. |
90 | 90 | ||
91 | In the File Domain, \a name is an absolute filename. | 91 | In the File Domain, \a name is an absolute filename. |
92 | */ | 92 | */ |
93 | Config::Config( const QString &name, Domain domain ) | 93 | Config::Config( const QString &name, Domain domain ) |
94 | : filename( configFilename(name,domain) ) | 94 | : filename( configFilename(name,domain) ) |
95 | { | 95 | { |
96 | git = groups.end(); | 96 | git = groups.end(); |
97 | read(); | 97 | read(); |
98 | QStringList l = Global::languageList(); | 98 | QStringList l = Global::languageList(); |
99 | lang = l[0]; | 99 | lang = l[0]; |
100 | glang = l[1]; | 100 | glang = l[1]; |
101 | } | 101 | } |
102 | 102 | ||
103 | 103 | ||
104 | // Sharp ROM compatibility | 104 | // Sharp ROM compatibility |
105 | Config::Config ( const QString &name, bool what ) | 105 | Config::Config ( const QString &name, bool what ) |
106 | : filename( configFilename(name,what ? User : File) ) | 106 | : filename( configFilename(name,what ? User : File) ) |
107 | { | 107 | { |
108 | git = groups.end(); | 108 | git = groups.end(); |
109 | read(); | 109 | read(); |
110 | QStringList l = Global::languageList(); | 110 | QStringList l = Global::languageList(); |
111 | lang = l[0]; | 111 | lang = l[0]; |
112 | glang = l[1]; | 112 | glang = l[1]; |
113 | } | 113 | } |
114 | 114 | ||
115 | /*! | 115 | /*! |
116 | Writes any changes to disk and destroys the in-memory object. | 116 | Writes any changes to disk and destroys the in-memory object. |
117 | */ | 117 | */ |
118 | Config::~Config() | 118 | Config::~Config() |
119 | { | 119 | { |
120 | if ( changed ) | 120 | if ( changed ) |
121 | write(); | 121 | write(); |
122 | } | 122 | } |
123 | 123 | ||
124 | /*! | 124 | /*! |
125 | Returns whether the current group has an entry called \a key. | 125 | Returns whether the current group has an entry called \a key. |
126 | */ | 126 | */ |
127 | bool Config::hasKey( const QString &key ) const | 127 | bool Config::hasKey( const QString &key ) const |
128 | { | 128 | { |
129 | if ( groups.end() == git ) | 129 | if ( groups.end() == git ) |
130 | return FALSE; | 130 | return FALSE; |
131 | ConfigGroup::ConstIterator it = ( *git ).find( key ); | 131 | ConfigGroup::ConstIterator it = ( *git ).find( key ); |
132 | return it != ( *git ).end(); | 132 | return it != ( *git ).end(); |
133 | } | 133 | } |
134 | 134 | ||
135 | /*! | 135 | /*! |
136 | Sets the current group for subsequent reading and writing of | 136 | Sets the current group for subsequent reading and writing of |
137 | entries to \a gname. Grouping allows the application to partition the namespace. | 137 | entries to \a gname. Grouping allows the application to partition the namespace. |
138 | 138 | ||
139 | This function must be called prior to any reading or writing | 139 | This function must be called prior to any reading or writing |
140 | of entries. | 140 | of entries. |
141 | 141 | ||
142 | The \a gname must not be empty. | 142 | The \a gname must not be empty. |
143 | */ | 143 | */ |
144 | void Config::setGroup( const QString &gname ) | 144 | void Config::setGroup( const QString &gname ) |
145 | { | 145 | { |
146 | QMap< QString, ConfigGroup>::Iterator it = groups.find( gname ); | 146 | QMap< QString, ConfigGroup>::Iterator it = groups.find( gname ); |
147 | if ( it == groups.end() ) { | 147 | if ( it == groups.end() ) { |
148 | git = groups.insert( gname, ConfigGroup() ); | 148 | git = groups.insert( gname, ConfigGroup() ); |
149 | changed = TRUE; | 149 | changed = TRUE; |
150 | return; | 150 | return; |
151 | } | 151 | } |
152 | git = it; | 152 | git = it; |
153 | } | 153 | } |
154 | 154 | ||
155 | /*! | 155 | /*! |
156 | Writes a (\a key, \a value) entry to the current group. | 156 | Writes a (\a key, \a value) entry to the current group. |
157 | 157 | ||
158 | \sa readEntry() | 158 | \sa readEntry() |
159 | */ | 159 | */ |
160 | void Config::writeEntry( const QString &key, const char* value ) | 160 | void Config::writeEntry( const QString &key, const char* value ) |
161 | { | 161 | { |
162 | writeEntry(key,QString(value)); | 162 | writeEntry(key,QString(value)); |
163 | } | 163 | } |
164 | 164 | ||
165 | /*! | 165 | /*! |
166 | Writes a (\a key, \a value) entry to the current group. | 166 | Writes a (\a key, \a value) entry to the current group. |
167 | 167 | ||
168 | \sa readEntry() | 168 | \sa readEntry() |
169 | */ | 169 | */ |
170 | void Config::writeEntry( const QString &key, const QString &value ) | 170 | void Config::writeEntry( const QString &key, const QString &value ) |
171 | { | 171 | { |
172 | if ( git == groups.end() ) { | 172 | if ( git == groups.end() ) { |
173 | qWarning( "no group set" ); | 173 | qWarning( "no group set" ); |
174 | return; | 174 | return; |
175 | } | 175 | } |
176 | if ( (*git)[key] != value ) { | 176 | if ( (*git)[key] != value ) { |
177 | ( *git ).insert( key, value ); | 177 | ( *git ).insert( key, value ); |
178 | changed = TRUE; | 178 | changed = TRUE; |
179 | } | 179 | } |
180 | } | 180 | } |
181 | 181 | ||
182 | /* | 182 | /* |
183 | Note that the degree of protection offered by the encryption here is | 183 | Note that the degree of protection offered by the encryption here is |
184 | only sufficient to avoid the most casual observation of the configuration | 184 | only sufficient to avoid the most casual observation of the configuration |
185 | files. People with access to the files can write down the contents and | 185 | files. People with access to the files can write down the contents and |
186 | decrypt it using this source code. | 186 | decrypt it using this source code. |
187 | 187 | ||
188 | Conceivably, and at some burden to the user, this encryption could | 188 | Conceivably, and at some burden to the user, this encryption could |
189 | be improved. | 189 | be improved. |
190 | */ | 190 | */ |
191 | static QString encipher(const QString& plain) | 191 | static QString encipher(const QString& plain) |
192 | { | 192 | { |
193 | // mainly, we make it long | 193 | // mainly, we make it long |
194 | QString cipher; | 194 | QString cipher; |
195 | int mix=28730492; | 195 | int mix=28730492; |
196 | for (int i=0; i<(int)plain.length(); i++) { | 196 | for (int i=0; i<(int)plain.length(); i++) { |
197 | int u = plain[i].unicode(); | 197 | int u = plain[i].unicode(); |
198 | int c = u ^ mix; | 198 | int c = u ^ mix; |
199 | QString x = QString::number(c,36); | 199 | QString x = QString::number(c,36); |
200 | cipher.append(QChar('a'+x.length())); | 200 | cipher.append(QChar('a'+x.length())); |
201 | cipher.append(x); | 201 | cipher.append(x); |
202 | mix *= u; | 202 | mix *= u; |
203 | } | 203 | } |
204 | return cipher; | 204 | return cipher; |
205 | } | 205 | } |
206 | 206 | ||
207 | static QString decipher(const QString& cipher) | 207 | static QString decipher(const QString& cipher) |
208 | { | 208 | { |
209 | QString plain; | 209 | QString plain; |
210 | int mix=28730492; | 210 | int mix=28730492; |
211 | for (int i=0; i<(int)cipher.length();) { | 211 | for (int i=0; i<(int)cipher.length();) { |
212 | int l = cipher[i].unicode()-'a'; | 212 | int l = cipher[i].unicode()-'a'; |
213 | QString x = cipher.mid(i+1,l); i+=l+1; | 213 | QString x = cipher.mid(i+1,l); i+=l+1; |
214 | int u = x.toInt(0,36) ^ mix; | 214 | int u = x.toInt(0,36) ^ mix; |
215 | plain.append(QChar(u)); | 215 | plain.append(QChar(u)); |
216 | mix *= u; | 216 | mix *= u; |
217 | } | 217 | } |
218 | return plain; | 218 | return plain; |
219 | } | 219 | } |
220 | 220 | ||
221 | /*! | 221 | /*! |
222 | Writes an encrypted (\a key, \a value) entry to the current group. | 222 | Writes an encrypted (\a key, \a value) entry to the current group. |
223 | 223 | ||
224 | Note that the degree of protection offered by the encryption is | 224 | Note that the degree of protection offered by the encryption is |
225 | only sufficient to avoid the most casual observation of the configuration | 225 | only sufficient to avoid the most casual observation of the configuration |
226 | files. | 226 | files. |
227 | 227 | ||
228 | \sa readEntry() | 228 | \sa readEntry() |
229 | */ | 229 | */ |
230 | void Config::writeEntryCrypt( const QString &key, const QString &value ) | 230 | void Config::writeEntryCrypt( const QString &key, const QString &value ) |
231 | { | 231 | { |
232 | if ( git == groups.end() ) { | 232 | if ( git == groups.end() ) { |
233 | qWarning( "no group set" ); | 233 | qWarning( "no group set" ); |
234 | return; | 234 | return; |
235 | } | 235 | } |
236 | QString evalue = encipher(value); | 236 | QString evalue = encipher(value); |
237 | if ( (*git)[key] != evalue ) { | 237 | if ( (*git)[key] != evalue ) { |
238 | ( *git ).insert( key, evalue ); | 238 | ( *git ).insert( key, evalue ); |
239 | changed = TRUE; | 239 | changed = TRUE; |
240 | } | 240 | } |
241 | } | 241 | } |
242 | 242 | ||
243 | /*! | 243 | /*! |
244 | Writes a (\a key, \a num) entry to the current group. | 244 | Writes a (\a key, \a num) entry to the current group. |
245 | 245 | ||
246 | \sa readNumEntry() | 246 | \sa readNumEntry() |
247 | */ | 247 | */ |
248 | void Config::writeEntry( const QString &key, int num ) | 248 | void Config::writeEntry( const QString &key, int num ) |
249 | { | 249 | { |
250 | QString s; | 250 | QString s; |
251 | s.setNum( num ); | 251 | s.setNum( num ); |
252 | writeEntry( key, s ); | 252 | writeEntry( key, s ); |
253 | } | 253 | } |
254 | 254 | ||
255 | #ifdef Q_HAS_BOOL_TYPE | 255 | #ifdef Q_HAS_BOOL_TYPE |
256 | /*! | 256 | /*! |
257 | Writes a (\a key, \a b) entry to the current group. This is equivalent | 257 | Writes a (\a key, \a b) entry to the current group. This is equivalent |
258 | to writing a 0 or 1 as an integer entry. | 258 | to writing a 0 or 1 as an integer entry. |
@@ -325,256 +325,418 @@ QString Config::readEntry( const QString &key, const QString &deflt ) | |||
325 | if ( !res.isNull() ) | 325 | if ( !res.isNull() ) |
326 | return res; | 326 | return res; |
327 | if ( !glang.isEmpty() ) { | 327 | if ( !glang.isEmpty() ) { |
328 | res = readEntryDirect( key+"["+glang+"]" ); | 328 | res = readEntryDirect( key+"["+glang+"]" ); |
329 | if ( !res.isNull() ) | 329 | if ( !res.isNull() ) |
330 | return res; | 330 | return res; |
331 | } | 331 | } |
332 | return readEntryDirect( key, deflt ); | 332 | return readEntryDirect( key, deflt ); |
333 | } | 333 | } |
334 | 334 | ||
335 | /*! | 335 | /*! |
336 | \fn QString Config::readEntryCrypt( const QString &key, const QString &deflt ) const | 336 | \fn QString Config::readEntryCrypt( const QString &key, const QString &deflt ) const |
337 | 337 | ||
338 | Reads an encrypted string entry stored with \a key, defaulting to \a deflt if there is no entry. | 338 | Reads an encrypted string entry stored with \a key, defaulting to \a deflt if there is no entry. |
339 | */ | 339 | */ |
340 | 340 | ||
341 | /*! | 341 | /*! |
342 | \internal | 342 | \internal |
343 | For compatibility, non-const version. | 343 | For compatibility, non-const version. |
344 | */ | 344 | */ |
345 | QString Config::readEntryCrypt( const QString &key, const QString &deflt ) | 345 | QString Config::readEntryCrypt( const QString &key, const QString &deflt ) |
346 | { | 346 | { |
347 | QString res = readEntryDirect( key+"["+lang+"]" ); | 347 | QString res = readEntryDirect( key+"["+lang+"]" ); |
348 | if ( res.isNull() && glang.isEmpty() ) | 348 | if ( res.isNull() && glang.isEmpty() ) |
349 | res = readEntryDirect( key+"["+glang+"]" ); | 349 | res = readEntryDirect( key+"["+glang+"]" ); |
350 | if ( res.isNull() ) | 350 | if ( res.isNull() ) |
351 | res = readEntryDirect( key, QString::null ); | 351 | res = readEntryDirect( key, QString::null ); |
352 | if ( res.isNull() ) | 352 | if ( res.isNull() ) |
353 | return deflt; | 353 | return deflt; |
354 | return decipher(res); | 354 | return decipher(res); |
355 | } | 355 | } |
356 | 356 | ||
357 | /*! | 357 | /*! |
358 | \fn QString Config::readEntryDirect( const QString &key, const QString &deflt ) const | 358 | \fn QString Config::readEntryDirect( const QString &key, const QString &deflt ) const |
359 | \internal | 359 | \internal |
360 | */ | 360 | */ |
361 | 361 | ||
362 | /*! | 362 | /*! |
363 | \internal | 363 | \internal |
364 | For compatibility, non-const version. | 364 | For compatibility, non-const version. |
365 | */ | 365 | */ |
366 | QString Config::readEntryDirect( const QString &key, const QString &deflt ) | 366 | QString Config::readEntryDirect( const QString &key, const QString &deflt ) |
367 | { | 367 | { |
368 | if ( git == groups.end() ) { | 368 | if ( git == groups.end() ) { |
369 | //qWarning( "no group set" ); | 369 | //qWarning( "no group set" ); |
370 | return deflt; | 370 | return deflt; |
371 | } | 371 | } |
372 | ConfigGroup::ConstIterator it = ( *git ).find( key ); | 372 | ConfigGroup::ConstIterator it = ( *git ).find( key ); |
373 | if ( it != ( *git ).end() ) | 373 | if ( it != ( *git ).end() ) |
374 | return *it; | 374 | return *it; |
375 | else | 375 | else |
376 | return deflt; | 376 | return deflt; |
377 | } | 377 | } |
378 | 378 | ||
379 | /*! | 379 | /*! |
380 | \fn int Config::readNumEntry( const QString &key, int deflt ) const | 380 | \fn int Config::readNumEntry( const QString &key, int deflt ) const |
381 | Reads a numeric entry stored with \a key, defaulting to \a deflt if there is no entry. | 381 | Reads a numeric entry stored with \a key, defaulting to \a deflt if there is no entry. |
382 | */ | 382 | */ |
383 | 383 | ||
384 | /*! | 384 | /*! |
385 | \internal | 385 | \internal |
386 | For compatibility, non-const version. | 386 | For compatibility, non-const version. |
387 | */ | 387 | */ |
388 | int Config::readNumEntry( const QString &key, int deflt ) | 388 | int Config::readNumEntry( const QString &key, int deflt ) |
389 | { | 389 | { |
390 | QString s = readEntry( key ); | 390 | QString s = readEntry( key ); |
391 | if ( s.isEmpty() ) | 391 | if ( s.isEmpty() ) |
392 | return deflt; | 392 | return deflt; |
393 | else | 393 | else |
394 | return s.toInt(); | 394 | return s.toInt(); |
395 | } | 395 | } |
396 | 396 | ||
397 | /*! | 397 | /*! |
398 | \fn bool Config::readBoolEntry( const QString &key, bool deflt ) const | 398 | \fn bool Config::readBoolEntry( const QString &key, bool deflt ) const |
399 | Reads a bool entry stored with \a key, defaulting to \a deflt if there is no entry. | 399 | Reads a bool entry stored with \a key, defaulting to \a deflt if there is no entry. |
400 | */ | 400 | */ |
401 | 401 | ||
402 | /*! | 402 | /*! |
403 | \internal | 403 | \internal |
404 | For compatibility, non-const version. | 404 | For compatibility, non-const version. |
405 | */ | 405 | */ |
406 | bool Config::readBoolEntry( const QString &key, bool deflt ) | 406 | bool Config::readBoolEntry( const QString &key, bool deflt ) |
407 | { | 407 | { |
408 | QString s = readEntry( key ); | 408 | QString s = readEntry( key ); |
409 | if ( s.isEmpty() ) | 409 | if ( s.isEmpty() ) |
410 | return deflt; | 410 | return deflt; |
411 | else | 411 | else |
412 | return (bool)s.toInt(); | 412 | return (bool)s.toInt(); |
413 | } | 413 | } |
414 | 414 | ||
415 | /*! | 415 | /*! |
416 | \fn QStringList Config::readListEntry( const QString &key, const QChar &sep ) const | 416 | \fn QStringList Config::readListEntry( const QString &key, const QChar &sep ) const |
417 | Reads a string list entry stored with \a key, and with \a sep as the separator. | 417 | Reads a string list entry stored with \a key, and with \a sep as the separator. |
418 | */ | 418 | */ |
419 | 419 | ||
420 | /*! | 420 | /*! |
421 | \internal | 421 | \internal |
422 | For compatibility, non-const version. | 422 | For compatibility, non-const version. |
423 | */ | 423 | */ |
424 | QStringList Config::readListEntry( const QString &key, const QChar &sep ) | 424 | QStringList Config::readListEntry( const QString &key, const QChar &sep ) |
425 | { | 425 | { |
426 | QString s = readEntry( key ); | 426 | QString s = readEntry( key ); |
427 | if ( s.isEmpty() ) | 427 | if ( s.isEmpty() ) |
428 | return QStringList(); | 428 | return QStringList(); |
429 | else | 429 | else |
430 | return QStringList::split( sep, s ); | 430 | return QStringList::split( sep, s ); |
431 | } | 431 | } |
432 | 432 | ||
433 | /*! | 433 | /*! |
434 | Removes all entries from the current group. | 434 | Removes all entries from the current group. |
435 | */ | 435 | */ |
436 | void Config::clearGroup() | 436 | void Config::clearGroup() |
437 | { | 437 | { |
438 | if ( git == groups.end() ) { | 438 | if ( git == groups.end() ) { |
439 | qWarning( "no group set" ); | 439 | qWarning( "no group set" ); |
440 | return; | 440 | return; |
441 | } | 441 | } |
442 | if ( !(*git).isEmpty() ) { | 442 | if ( !(*git).isEmpty() ) { |
443 | ( *git ).clear(); | 443 | ( *git ).clear(); |
444 | changed = TRUE; | 444 | changed = TRUE; |
445 | } | 445 | } |
446 | } | 446 | } |
447 | 447 | ||
448 | /*! | 448 | /*! |
449 | \internal | 449 | \internal |
450 | */ | 450 | */ |
451 | void Config::write( const QString &fn ) | 451 | void Config::write( const QString &fn ) |
452 | { | 452 | { |
453 | QString strNewFile; | 453 | QString strNewFile; |
454 | if ( !fn.isEmpty() ) | 454 | if ( !fn.isEmpty() ) |
455 | filename = fn; | 455 | filename = fn; |
456 | strNewFile = filename + ".new"; | 456 | strNewFile = filename + ".new"; |
457 | 457 | ||
458 | QFile f( strNewFile ); | 458 | QFile f( strNewFile ); |
459 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) { | 459 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) { |
460 | qWarning( "could not open for writing `%s'", strNewFile.latin1() ); | 460 | qWarning( "could not open for writing `%s'", strNewFile.latin1() ); |
461 | git = groups.end(); | 461 | git = groups.end(); |
462 | return; | 462 | return; |
463 | } | 463 | } |
464 | 464 | ||
465 | QString str; | 465 | QString str; |
466 | QCString cstr; | 466 | QCString cstr; |
467 | QMap< QString, ConfigGroup >::Iterator g_it = groups.begin(); | 467 | QMap< QString, ConfigGroup >::Iterator g_it = groups.begin(); |
468 | 468 | ||
469 | for ( ; g_it != groups.end(); ++g_it ) { | 469 | for ( ; g_it != groups.end(); ++g_it ) { |
470 | str += "[" + g_it.key() + "]\n"; | 470 | str += "[" + g_it.key() + "]\n"; |
471 | ConfigGroup::Iterator e_it = ( *g_it ).begin(); | 471 | ConfigGroup::Iterator e_it = ( *g_it ).begin(); |
472 | for ( ; e_it != ( *g_it ).end(); ++e_it ) | 472 | for ( ; e_it != ( *g_it ).end(); ++e_it ) |
473 | str += e_it.key() + " = " + *e_it + "\n"; | 473 | str += e_it.key() + " = " + *e_it + "\n"; |
474 | } | 474 | } |
475 | cstr = str.utf8(); | 475 | cstr = str.utf8(); |
476 | 476 | ||
477 | int total_length; | 477 | int total_length; |
478 | total_length = f.writeBlock( cstr.data(), cstr.length() ); | 478 | total_length = f.writeBlock( cstr.data(), cstr.length() ); |
479 | if ( total_length != int(cstr.length()) ) { | 479 | if ( total_length != int(cstr.length()) ) { |
480 | QMessageBox::critical( 0, QObject::tr("Out of Space"), | 480 | QMessageBox::critical( 0, QObject::tr("Out of Space"), |
481 | QObject::tr("There was a problem creating\nConfiguration Information \nfor this program.\n\nPlease free up some space and\ntry again.") ); | 481 | QObject::tr("There was a problem creating\nConfiguration Information \nfor this program.\n\nPlease free up some space and\ntry again.") ); |
482 | f.close(); | 482 | f.close(); |
483 | QFile::remove( strNewFile ); | 483 | QFile::remove( strNewFile ); |
484 | return; | 484 | return; |
485 | } | 485 | } |
486 | 486 | ||
487 | f.close(); | 487 | f.close(); |
488 | // now rename the file... | 488 | // now rename the file... |
489 | if ( rename( strNewFile, filename ) < 0 ) { | 489 | if ( rename( strNewFile, filename ) < 0 ) { |
490 | qWarning( "problem renaming the file %s to %s", strNewFile.latin1(), | 490 | qWarning( "problem renaming the file %s to %s", strNewFile.latin1(), |
491 | filename.latin1() ); | 491 | filename.latin1() ); |
492 | QFile::remove( strNewFile ); | 492 | QFile::remove( strNewFile ); |
493 | } | 493 | } |
494 | } | 494 | } |
495 | 495 | ||
496 | /*! | 496 | /*! |
497 | Returns whether the Config is in a valid state. | 497 | Returns whether the Config is in a valid state. |
498 | */ | 498 | */ |
499 | bool Config::isValid() const | 499 | bool Config::isValid() const |
500 | { | 500 | { |
501 | return groups.end() != git; | 501 | return groups.end() != git; |
502 | } | 502 | } |
503 | 503 | ||
504 | /*! | 504 | /*! |
505 | \internal | 505 | \internal |
506 | */ | 506 | */ |
507 | void Config::read() | 507 | void Config::read() |
508 | { | 508 | { |
509 | changed = FALSE; | 509 | changed = FALSE; |
510 | 510 | ||
511 | if ( !QFileInfo( filename ).exists() ) { | 511 | if ( !QFileInfo( filename ).exists() ) { |
512 | git = groups.end(); | 512 | git = groups.end(); |
513 | return; | 513 | return; |
514 | } | 514 | } |
515 | 515 | ||
516 | QFile f( filename ); | 516 | QFile f( filename ); |
517 | if ( !f.open( IO_ReadOnly ) ) { | 517 | if ( !f.open( IO_ReadOnly ) ) { |
518 | git = groups.end(); | 518 | git = groups.end(); |
519 | return; | 519 | return; |
520 | } | 520 | } |
521 | 521 | ||
522 | 522 | ||
523 | // hack to avoid problems if big files are passed to test | 523 | // hack to avoid problems if big files are passed to test |
524 | // if they are valid configs ( like passing a mp3 ... ) | 524 | // if they are valid configs ( like passing a mp3 ... ) |
525 | // I just hope that there are no conf files > 100000 byte | 525 | // I just hope that there are no conf files > 100000 byte |
526 | // not the best solution, find something else later | 526 | // not the best solution, find something else later |
527 | if ( f.getch()!='[' ||f.size() > 100000 ) { | 527 | if ( f.getch()!='[' ||f.size() > 100000 ) { |
528 | git = groups.end(); | 528 | git = groups.end(); |
529 | return; | 529 | return; |
530 | } | 530 | } |
531 | f.ungetch('['); | 531 | f.ungetch('['); |
532 | 532 | ||
533 | 533 | ||
534 | QTextStream s( &f ); | 534 | QTextStream s( &f ); |
535 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) | 535 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) |
536 | // The below should work, but doesn't in Qt 2.3.0 | 536 | // The below should work, but doesn't in Qt 2.3.0 |
537 | s.setCodec( QTextCodec::codecForMib( 106 ) ); | 537 | s.setCodec( QTextCodec::codecForMib( 106 ) ); |
538 | #else | 538 | #else |
539 | s.setEncoding( QTextStream::UnicodeUTF8 ); | 539 | s.setEncoding( QTextStream::UnicodeUTF8 ); |
540 | #endif | 540 | #endif |
541 | 541 | ||
542 | QStringList list = QStringList::split('\n', s.read() ); | 542 | QStringList list = QStringList::split('\n', s.read() ); |
543 | f.close(); | 543 | f.close(); |
544 | 544 | ||
545 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | 545 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { |
546 | if ( !parse( *it ) ) { | 546 | if ( !parse( *it ) ) { |
547 | git = groups.end(); | 547 | git = groups.end(); |
548 | return; | 548 | return; |
549 | } | 549 | } |
550 | } | 550 | } |
551 | } | 551 | } |
552 | 552 | ||
553 | /*! | 553 | /*! |
554 | \internal | 554 | \internal |
555 | */ | 555 | */ |
556 | bool Config::parse( const QString &l ) | 556 | bool Config::parse( const QString &l ) |
557 | { | 557 | { |
558 | QString line = l.stripWhiteSpace(); | 558 | QString line = l.stripWhiteSpace(); |
559 | 559 | ||
560 | if ( line [0] == QChar ( '#' )) | 560 | if ( line [0] == QChar ( '#' )) |
561 | return true; // ignore comments | 561 | return true; // ignore comments |
562 | 562 | ||
563 | if ( line[ 0 ] == QChar( '[' ) ) { | 563 | if ( line[ 0 ] == QChar( '[' ) ) { |
564 | QString gname = line; | 564 | QString gname = line; |
565 | gname = gname.remove( 0, 1 ); | 565 | gname = gname.remove( 0, 1 ); |
566 | if ( gname[ (int)gname.length() - 1 ] == QChar( ']' ) ) | 566 | if ( gname[ (int)gname.length() - 1 ] == QChar( ']' ) ) |
567 | gname = gname.remove( gname.length() - 1, 1 ); | 567 | gname = gname.remove( gname.length() - 1, 1 ); |
568 | git = groups.insert( gname, ConfigGroup() ); | 568 | git = groups.insert( gname, ConfigGroup() ); |
569 | } else if ( !line.isEmpty() ) { | 569 | } else if ( !line.isEmpty() ) { |
570 | if ( git == groups.end() ) | 570 | if ( git == groups.end() ) |
571 | return FALSE; | 571 | return FALSE; |
572 | int eq = line.find( '=' ); | 572 | int eq = line.find( '=' ); |
573 | if ( eq == -1 ) | 573 | if ( eq == -1 ) |
574 | return FALSE; | 574 | return FALSE; |
575 | QString key = line.left(eq).stripWhiteSpace(); | 575 | QString key = line.left(eq).stripWhiteSpace(); |
576 | QString value = line.mid(eq+1).stripWhiteSpace(); | 576 | QString value = line.mid(eq+1).stripWhiteSpace(); |
577 | ( *git ).insert( key, value ); | 577 | ( *git ).insert( key, value ); |
578 | } | 578 | } |
579 | return TRUE; | 579 | return TRUE; |
580 | } | 580 | } |
581 | |||
582 | |||
583 | |||
584 | bool Config::hasGroup( const QString& name )const { | ||
585 | return ( groups. find ( name ) != groups. end ( )); | ||
586 | }; | ||
587 | |||
588 | QStringList Config::groupList()const { | ||
589 | QStringList sl; | ||
590 | for ( ConfigGroupMap::ConstIterator it = groups. begin ( ); it != groups. end ( ); ++it ) | ||
591 | sl << it.key(); | ||
592 | |||
593 | return sl; | ||
594 | }; | ||
595 | |||
596 | ///////////// | ||
597 | // Qtopia 2.1 Functions | ||
598 | // | ||
599 | //////////// | ||
600 | |||
601 | QStringList Config::allGroups()const { | ||
602 | return groupList(); | ||
603 | } | ||
604 | |||
605 | /*! | ||
606 | Returns the time stamp for the config identified by \a name. The | ||
607 | time stamp represents the time the config was last committed to storage. | ||
608 | Returns 0 if there is no time stamp available for the config. | ||
609 | |||
610 | A \a domain can optionally be specified and defaults to User. | ||
611 | See \l{Config()} for details. | ||
612 | |||
613 | First availability: Qtopia 2.0 | ||
614 | */ | ||
615 | long Config::timeStamp(const QString& name, Domain domain) | ||
616 | { | ||
617 | #ifdef Q_WS_WIN | ||
618 | // Too slow (many conversions too and from time_t and QDataTime) | ||
619 | QDateTime epoch; | ||
620 | epoch.setTime_t(0); | ||
621 | return epoch.secsTo(QFileInfo(Config::configFilename(name,domain)).lastModified()); | ||
622 | #else | ||
623 | QString fn = Config::configFilename(name,domain); | ||
624 | struct stat b; | ||
625 | if (lstat( QFile::encodeName(fn).data(), &b ) == 0) | ||
626 | return b.st_mtime; | ||
627 | else | ||
628 | return 0; | ||
629 | #endif | ||
630 | } | ||
631 | |||
632 | |||
633 | /*! | ||
634 | Removes the current group (and all its entries). | ||
635 | |||
636 | The current group becomes unset. | ||
637 | |||
638 | First availability: Qtopia 2.0 | ||
639 | */ | ||
640 | void Config::removeGroup() | ||
641 | { | ||
642 | if ( git == groups.end() ) { | ||
643 | qWarning( "no group set" ); | ||
644 | return; | ||
645 | } | ||
646 | |||
647 | groups.remove(git.key()); | ||
648 | git = groups.end(); | ||
649 | changed = TRUE; | ||
650 | } | ||
651 | |||
652 | /*! | ||
653 | Removes the current group (and all its entries). | ||
654 | |||
655 | The current group becomes unset. | ||
656 | |||
657 | First availability: Qtopia 2.0 | ||
658 | */ | ||
659 | void Config::removeGroup(const QString& g) | ||
660 | { | ||
661 | groups.remove(g); | ||
662 | git = groups.end(); | ||
663 | } | ||
664 | |||
665 | |||
666 | |||
667 | /*! | ||
668 | Writes a (\a key, \a lst) entry to the current group. | ||
669 | |||
670 | The list is | ||
671 | separated by the two characters "^e", and "^" withing the strings | ||
672 | is replaced by "^^", such that the strings may contain any character, | ||
673 | including "^". | ||
674 | |||
675 | Null strings are also allowed, and are recorded as "^0" in the string. | ||
676 | |||
677 | First availability: Qtopia 2.0 | ||
678 | |||
679 | \sa readListEntry() | ||
680 | */ | ||
681 | void Config::writeEntry( const QString &key, const QStringList &lst ) | ||
682 | { | ||
683 | QString s; | ||
684 | for (QStringList::ConstIterator it=lst.begin(); it!=lst.end(); ++it) { | ||
685 | QString el = *it; | ||
686 | if ( el.isNull() ) { | ||
687 | el = "^0"; | ||
688 | } else { | ||
689 | el.replace(QRegExp("\\^"), "^^"); | ||
690 | } | ||
691 | s+=el; | ||
692 | s+="^e"; // end of element | ||
693 | } | ||
694 | writeEntry(key, s); | ||
695 | } | ||
696 | |||
697 | /*! | ||
698 | Returns the string list entry stored using \a key and with | ||
699 | the escaped seperator convention described in writeListEntry(). | ||
700 | |||
701 | First availability: Qtopia 2.0 | ||
702 | */ | ||
703 | QStringList Config::readListEntry( const QString &key ) const | ||
704 | { | ||
705 | QString value = readEntry( key, QString::null ); | ||
706 | QStringList l; | ||
707 | QString s; | ||
708 | bool esc=FALSE; | ||
709 | for (int i=0; i<(int)value.length(); i++) { | ||
710 | if ( esc ) { | ||
711 | if ( value[i] == 'e' ) { // end-of-string | ||
712 | l.append(s); | ||
713 | s=""; | ||
714 | } else if ( value[i] == '0' ) { // null string | ||
715 | s=QString::null; | ||
716 | } else { | ||
717 | s.append(value[i]); | ||
718 | } | ||
719 | esc = FALSE; | ||
720 | } else if ( value[i] == '^' ) { | ||
721 | esc = TRUE; | ||
722 | } else { | ||
723 | s.append(value[i]); | ||
724 | if ( i == (int)value.length()-1 ) | ||
725 | l.append(s); | ||
726 | } | ||
727 | } | ||
728 | return l; | ||
729 | } | ||
730 | |||
731 | QString Config::readEntry( const QString &key, const QString &deflt ) const | ||
732 | { return ((Config*)this)->readEntry(key,deflt); } | ||
733 | QString Config::readEntryCrypt( const QString &key, const QString &deflt ) const | ||
734 | { return ((Config*)this)->readEntryCrypt(key,deflt); } | ||
735 | QString Config::readEntryDirect( const QString &key, const QString &deflt ) const | ||
736 | { return ((Config*)this)->readEntryDirect(key,deflt); } | ||
737 | int Config::readNumEntry( const QString &key, int deflt ) const | ||
738 | { return ((Config*)this)->readNumEntry(key,deflt); } | ||
739 | bool Config::readBoolEntry( const QString &key, bool deflt ) const | ||
740 | { return ((Config*)this)->readBoolEntry(key,deflt); } | ||
741 | QStringList Config::readListEntry( const QString &key, const QChar &sep ) const | ||
742 | { return ((Config*)this)->readListEntry(key,sep); } | ||
diff --git a/library/config.h b/library/config.h index a2f9b2d..29ba0d6 100644 --- a/library/config.h +++ b/library/config.h | |||
@@ -1,109 +1,108 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000, 2004 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
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 | #ifndef CONFIG_H | 21 | #ifndef CONFIG_H |
22 | #define CONFIG_H | 22 | #define CONFIG_H |
23 | 23 | ||
24 | // ##### could use QSettings with Qt 3.0 | 24 | // ##### could use QSettings with Qt 3.0 |
25 | 25 | ||
26 | #include <qpe/qpeglobal.h> | ||
27 | |||
26 | #include <qmap.h> | 28 | #include <qmap.h> |
27 | #include <qstringlist.h> | 29 | #include <qstringlist.h> |
28 | 30 | ||
31 | typedef QMap< QString, QString > ConfigGroup; | ||
32 | typedef QMap< QString, ConfigGroup> ConfigGroupMap; | ||
33 | |||
29 | class ConfigPrivate; | 34 | class ConfigPrivate; |
30 | class Config | 35 | class Config |
31 | { | 36 | { |
32 | public: | 37 | public: |
33 | typedef QMap< QString, QString > ConfigGroup; | ||
34 | 38 | ||
35 | enum Domain { File, User }; | 39 | enum Domain { File, User }; |
36 | Config( const QString &name, Domain domain=User ); | 40 | Config( const QString &name, Domain domain=User ); |
37 | ~Config(); | 41 | ~Config(); |
38 | 42 | ||
43 | QTOPIA_MERGED_METHOD(static long timeStamp( const QString &name, Domain domain=User ), "2.1"); | ||
44 | |||
39 | bool operator == ( const Config & other ) const { return (filename == other.filename); } | 45 | bool operator == ( const Config & other ) const { return (filename == other.filename); } |
40 | bool operator != ( const Config & other ) const { return (filename != other.filename); } | 46 | bool operator != ( const Config & other ) const { return (filename != other.filename); } |
41 | 47 | ||
42 | bool isValid() const; | 48 | bool isValid() const; |
43 | bool hasKey( const QString &key ) const; | 49 | bool hasKey( const QString &key ) const; |
44 | 50 | ||
45 | // inline for better SharpROM BC | 51 | // inline for better SharpROM BC |
46 | inline bool hasGroup ( const QString &gname ) const { return ( groups. find ( gname ) != groups. end ( )); }; | 52 | NOT_IN_QPE(bool hasGroup ( const QString &gname ) const); |
47 | inline QStringList groupList ( ) const { QStringList sl; for ( QMap< QString, ConfigGroup >::ConstIterator it = groups. begin ( ); it != groups. end ( ); ++it ) { sl << it.key(); } return sl; }; | 53 | NOT_IN_QPE(QStringList groupList ( ) const); |
48 | 54 | ||
49 | void setGroup( const QString &gname ); | 55 | void setGroup( const QString &gname ); |
50 | void writeEntry( const QString &key, const char* value ); | 56 | void writeEntry( const QString &key, const char* value ); |
51 | void writeEntry( const QString &key, const QString &value ); | 57 | void writeEntry( const QString &key, const QString &value ); |
52 | void writeEntryCrypt( const QString &key, const QString &value ); | 58 | void writeEntryCrypt( const QString &key, const QString &value ); |
53 | void writeEntry( const QString &key, int num ); | 59 | void writeEntry( const QString &key, int num ); |
54 | #ifdef Q_HAS_BOOL_TYPE | 60 | #ifdef Q_HAS_BOOL_TYPE |
55 | void writeEntry( const QString &key, bool b ); | 61 | void writeEntry( const QString &key, bool b ); |
56 | #endif | 62 | #endif |
57 | void writeEntry( const QString &key, const QStringList &lst, const QChar &sep ); | 63 | void writeEntry( const QString &key, const QStringList &lst, const QChar &sep ); |
64 | QTOPIA_MERGED_METHOD(void writeEntry( const QString &key, const QStringList &lst ), "2.1.0"); | ||
65 | |||
58 | void removeEntry( const QString &key ); | 66 | void removeEntry( const QString &key ); |
59 | 67 | ||
60 | QString readEntry( const QString &key, const QString &deflt = QString::null ) const; | 68 | QString readEntry( const QString &key, const QString &deflt = QString::null ) const; |
61 | QString readEntryCrypt( const QString &key, const QString &deflt = QString::null ) const; | 69 | QString readEntryCrypt( const QString &key, const QString &deflt = QString::null ) const; |
62 | QString readEntryDirect( const QString &key, const QString &deflt = QString::null ) const; | 70 | QString readEntryDirect( const QString &key, const QString &deflt = QString::null ) const; |
63 | int readNumEntry( const QString &key, int deflt = -1 ) const; | 71 | int readNumEntry( const QString &key, int deflt = -1 ) const; |
64 | bool readBoolEntry( const QString &key, bool deflt = FALSE ) const; | 72 | bool readBoolEntry( const QString &key, bool deflt = FALSE ) const; |
65 | QStringList readListEntry( const QString &key, const QChar &sep ) const; | 73 | QStringList readListEntry( const QString &key, const QChar &sep ) const; |
74 | QTOPIA_MERGED_METHOD(QStringList readListEntry( const QString &key ) const, "2.1.0"); | ||
66 | 75 | ||
67 | // For compatibility, non-const versions. | 76 | // For compatibility, non-const versions. |
68 | QString readEntry( const QString &key, const QString &deflt ); | 77 | QString readEntry( const QString &key, const QString &deflt ); |
69 | QString readEntryCrypt( const QString &key, const QString &deflt ); | 78 | QString readEntryCrypt( const QString &key, const QString &deflt ); |
70 | QString readEntryDirect( const QString &key, const QString &deflt ); | 79 | QString readEntryDirect( const QString &key, const QString &deflt ); |
71 | int readNumEntry( const QString &key, int deflt ); | 80 | int readNumEntry( const QString &key, int deflt ); |
72 | bool readBoolEntry( const QString &key, bool deflt ); | 81 | bool readBoolEntry( const QString &key, bool deflt ); |
73 | QStringList readListEntry( const QString &key, const QChar &sep ); | 82 | QStringList readListEntry( const QString &key, const QChar &sep ); |
74 | 83 | ||
75 | void clearGroup(); | 84 | void clearGroup(); |
85 | QTOPIA_MERGED_METHOD(void removeGroup(), "2.1.0"); | ||
86 | QTOPIA_MERGED_METHOD(void removeGroup(const QString&), "2.1.0"); | ||
87 | QTOPIA_MERGED_METHOD(QStringList allGroups() const, "2.1.0"); | ||
76 | 88 | ||
77 | void write( const QString &fn = QString::null ); | 89 | void write( const QString &fn = QString::null ); |
78 | 90 | ||
79 | protected: | 91 | protected: |
80 | void read(); | 92 | void read(); |
81 | bool parse( const QString &line ); | 93 | bool parse( const QString &line ); |
82 | 94 | ||
83 | QMap< QString, ConfigGroup > groups; | 95 | QMap< QString, ConfigGroup > groups; |
84 | QMap< QString, ConfigGroup >::Iterator git; | 96 | QMap< QString, ConfigGroup >::Iterator git; |
85 | QString filename; | 97 | QString filename; |
86 | QString lang; | 98 | QString lang; |
87 | QString glang; | 99 | QString glang; |
88 | bool changed; | 100 | bool changed; |
89 | ConfigPrivate *d; | 101 | ConfigPrivate *d; |
90 | static QString configFilename(const QString& name, Domain); | 102 | static QString configFilename(const QString& name, Domain); |
91 | 103 | ||
92 | private: // Sharp ROM compatibility | 104 | private: // Sharp ROM compatibility |
93 | Config( const QString &name, bool what ); | 105 | Config( const QString &name, bool what ); |
94 | }; | 106 | }; |
95 | 107 | ||
96 | inline QString Config::readEntry( const QString &key, const QString &deflt ) const | ||
97 | { return ((Config*)this)->readEntry(key,deflt); } | ||
98 | inline QString Config::readEntryCrypt( const QString &key, const QString &deflt ) const | ||
99 | { return ((Config*)this)->readEntryCrypt(key,deflt); } | ||
100 | inline QString Config::readEntryDirect( const QString &key, const QString &deflt ) const | ||
101 | { return ((Config*)this)->readEntryDirect(key,deflt); } | ||
102 | inline int Config::readNumEntry( const QString &key, int deflt ) const | ||
103 | { return ((Config*)this)->readNumEntry(key,deflt); } | ||
104 | inline bool Config::readBoolEntry( const QString &key, bool deflt ) const | ||
105 | { return ((Config*)this)->readBoolEntry(key,deflt); } | ||
106 | inline QStringList Config::readListEntry( const QString &key, const QChar &sep ) const | ||
107 | { return ((Config*)this)->readListEntry(key,sep); } | ||
108 | |||
109 | #endif | 108 | #endif |
diff --git a/library/qpeglobal.h b/library/qpeglobal.h index a84e435..f64ccfd 100644 --- a/library/qpeglobal.h +++ b/library/qpeglobal.h | |||
@@ -1,88 +1,91 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the OPIE Project | 2 | This file is part of the OPIE Project |
3 | Copyright (c) 2002,2003,2004 Holger Hans Peter Freyther <freyther@handhelds.org> | 3 | Copyright (c) 2002,2003,2004 Holger Hans Peter Freyther <freyther@handhelds.org> |
4 | Copyright (c) 2002,2003,2004 Stefan Eilers <eilers@handhelds.org> | 4 | Copyright (c) 2002,2003,2004 Stefan Eilers <eilers@handhelds.org> |
5 | 5 | ||
6 | =. | 6 | =. |
7 | .=l. | 7 | .=l. |
8 | .>+-= | 8 | .>+-= |
9 | _;:, .> :=|. This library is free software; you can | 9 | _;:, .> :=|. This library is free software; you can |
10 | .> <`_, > . <= redistribute it and/or modify it under | 10 | .> <`_, > . <= redistribute it and/or modify it under |
11 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 11 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
12 | .="- .-=="i, .._ License as published by the Free Software | 12 | .="- .-=="i, .._ License as published by the Free Software |
13 | - . .-<_> .<> Foundation; either version 2 of the License, | 13 | - . .-<_> .<> Foundation; either version 2 of the License, |
14 | ._= =} : or (at your option) any later version. | 14 | ._= =} : or (at your option) any later version. |
15 | .%`+i> _;_. | 15 | .%`+i> _;_. |
16 | .i_,=:_. -<s. This library is distributed in the hope that | 16 | .i_,=:_. -<s. This library is distributed in the hope that |
17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
18 | : .. .:, . . . without even the implied warranty of | 18 | : .. .:, . . . without even the implied warranty of |
19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
20 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 20 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
21 | ..}^=.= = ; Library General Public License for more | 21 | ..}^=.= = ; Library General Public License for more |
22 | ++= -. .` .: details. | 22 | ++= -. .` .: details. |
23 | : = ...= . :.=- | 23 | : = ...= . :.=- |
24 | -. .:....=;==+<; You should have received a copy of the GNU | 24 | -. .:....=;==+<; You should have received a copy of the GNU |
25 | -_. . . )=. = Library General Public License along with | 25 | -_. . . )=. = Library General Public License along with |
26 | -- :-=` this library; see the file COPYING.LIB. | 26 | -- :-=` this library; see the file COPYING.LIB. |
27 | If not, write to the Free Software Foundation, | 27 | If not, write to the Free Software Foundation, |
28 | Inc., 59 Temple Place - Suite 330, | 28 | Inc., 59 Temple Place - Suite 330, |
29 | Boston, MA 02111-1307, USA. | 29 | Boston, MA 02111-1307, USA. |
30 | 30 | ||
31 | */ | 31 | */ |
32 | 32 | ||
33 | #ifndef QPE_GLOBAL_DEFINES_H | 33 | #ifndef QPE_GLOBAL_DEFINES_H |
34 | #define QPE_GLOBAL_DEFINES_H | 34 | #define QPE_GLOBAL_DEFINES_H |
35 | 35 | ||
36 | /** | 36 | /** |
37 | * Defines for used compiler attributes | 37 | * Defines for used compiler attributes |
38 | * | 38 | * |
39 | */ | 39 | */ |
40 | 40 | ||
41 | /* | 41 | /* |
42 | * commons | 42 | * commons |
43 | */ | 43 | */ |
44 | #define QPE_DEPRECATED | 44 | #define QPE_DEPRECATED |
45 | 45 | ||
46 | 46 | ||
47 | #if defined(Q_OS_MACX) | 47 | #if defined(Q_OS_MACX) |
48 | #define QPE_WEAK_SYMBOL __attribute__((weak_import)) | 48 | #define QPE_WEAK_SYMBOL __attribute__((weak_import)) |
49 | #define QPE_SYMBOL_USED | 49 | #define QPE_SYMBOL_USED |
50 | #define QPE_SYMBOL_UNUSED | 50 | #define QPE_SYMBOL_UNUSED |
51 | #define QPE_EXPORT_SYMBOL | 51 | #define QPE_EXPORT_SYMBOL |
52 | 52 | ||
53 | #elif defined(_OS_UNIX_) | 53 | #elif defined(_OS_UNIX_) |
54 | #define QPE_WEAK_SYMBOL __attribute__((weak)) | 54 | #define QPE_WEAK_SYMBOL __attribute__((weak)) |
55 | #define QPE_SYMBOL_USED __attribute__((used)) | 55 | #define QPE_SYMBOL_USED __attribute__((used)) |
56 | #define QPE_SYMBOL_UNUSED __attribute__((unused)) | 56 | #define QPE_SYMBOL_UNUSED __attribute__((unused)) |
57 | #define QPE_EXPORT_SYMBOL | 57 | #define QPE_EXPORT_SYMBOL |
58 | 58 | ||
59 | 59 | ||
60 | /* | 60 | /* |
61 | * mark method as deprecated | 61 | * mark method as deprecated |
62 | */ | 62 | */ |
63 | #if __GNUC__ - 0 > 3 || (__GNUC__ - 0 == 3 && __GNUC_MINOR__ - 0 >= 2) | 63 | #if __GNUC__ - 0 > 3 || (__GNUC__ - 0 == 3 && __GNUC_MINOR__ - 0 >= 2) |
64 | /* gcc >= 3.2 */ | 64 | /* gcc >= 3.2 */ |
65 | #undef QPE_DEPRECATED | 65 | #undef QPE_DEPRECATED |
66 | #define QPE_DEPRECATED __attribute__((deprecated)) | 66 | #define QPE_DEPRECATED __attribute__((deprecated)) |
67 | #endif | 67 | #endif |
68 | 68 | ||
69 | /* | 69 | /* |
70 | * Defined if Compiler supports attributes | 70 | * Defined if Compiler supports attributes |
71 | */ | 71 | */ |
72 | #ifdef GCC_SUPPORTS_VISIBILITY | 72 | #ifdef GCC_SUPPORTS_VISIBILITY |
73 | #undef QPE_EXPORT_SYMBOL | 73 | #undef QPE_EXPORT_SYMBOL |
74 | #define QPE_EXPORT_SYMBOL __attribute__((visibility("default"))) | 74 | #define QPE_EXPORT_SYMBOL __attribute__((visibility("default"))) |
75 | #endif | 75 | #endif |
76 | 76 | ||
77 | 77 | ||
78 | 78 | ||
79 | #else // defined(Q_OS_WIN32) | 79 | #else // defined(Q_OS_WIN32) |
80 | #define QPE_WEAK_SYMBOL | 80 | #define QPE_WEAK_SYMBOL |
81 | #define QPE_SYMBOL_USED | 81 | #define QPE_SYMBOL_USED |
82 | #define QPE_SYMBOL_UNUSED | 82 | #define QPE_SYMBOL_UNUSED |
83 | #define QPE_EXPORT_SYMBOL | 83 | #define QPE_EXPORT_SYMBOL |
84 | #endif | 84 | #endif |
85 | 85 | ||
86 | 86 | ||
87 | #define QTOPIA_MERGED_METHOD(method, version) method QPE_WEAK_SYMBOL; | ||
88 | #define NOT_IN_SHARP(method) method QPE_WEAK_SYMBOL; | ||
89 | #define NOT_IN_QPE(method) method QPE_WEAK_SYMBOL; | ||
87 | 90 | ||
88 | #endif | 91 | #endif |