Diffstat (limited to 'noncore/apps/opie-reader/preferences.cpp') (more/less context) (ignore whitespace changes)
-rwxr-xr-x | noncore/apps/opie-reader/preferences.cpp | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/noncore/apps/opie-reader/preferences.cpp b/noncore/apps/opie-reader/preferences.cpp new file mode 100755 index 0000000..b9397cf --- a/dev/null +++ b/noncore/apps/opie-reader/preferences.cpp | |||
@@ -0,0 +1,105 @@ | |||
1 | #include "useqpe.h" | ||
2 | #ifndef USEQPE | ||
3 | |||
4 | #include "preferences.h" | ||
5 | |||
6 | #include <qfile.h> | ||
7 | #include <qtextstream.h> | ||
8 | |||
9 | Config::Config(const QString& _fn) : fname(_fn) | ||
10 | { | ||
11 | // qDebug("Config::Config:%s", (const char*)fname); | ||
12 | QFile fl(fname); | ||
13 | if (fl.open(IO_ReadOnly)) | ||
14 | { | ||
15 | QTextStream t(&fl); | ||
16 | QString key, value; | ||
17 | while (!t.eof()) | ||
18 | { | ||
19 | QString data = t.readLine(); | ||
20 | int colon = data.find(':'); | ||
21 | if (colon > 0) | ||
22 | { | ||
23 | QString key = data.left(colon); | ||
24 | QString value = data.right(data.length()-colon-1); | ||
25 | values[key] = value; | ||
26 | } | ||
27 | } | ||
28 | fl.close(); | ||
29 | } | ||
30 | // read entries into values | ||
31 | } | ||
32 | Config::~Config() | ||
33 | { | ||
34 | // qDebug("Config::~Config:%s", (const char*)fname); | ||
35 | QFile fl(fname); | ||
36 | if (fl.open(IO_WriteOnly)) | ||
37 | { | ||
38 | QTextStream t(&fl); | ||
39 | for (QMap<QString,QString>::Iterator iter = values.begin(); | ||
40 | iter != values.end(); | ||
41 | iter++) | ||
42 | { | ||
43 | t << iter.key() << ':' << iter.data() << '\n'; | ||
44 | } | ||
45 | fl.close(); | ||
46 | } | ||
47 | } | ||
48 | QString Config::readEntry(const QString& key, const QString& deflt) | ||
49 | { | ||
50 | QMap<QString,QString>::Iterator iter = values.find(key); | ||
51 | if (iter != values.end()) | ||
52 | { | ||
53 | return iter.data(); | ||
54 | } | ||
55 | else | ||
56 | { | ||
57 | return deflt; | ||
58 | } | ||
59 | } | ||
60 | bool Config::readBoolEntry(const QString& key, const bool deflt) | ||
61 | { | ||
62 | bool ok; | ||
63 | QMap<QString,QString>::Iterator iter = values.find(key); | ||
64 | if (iter != values.end()) | ||
65 | { | ||
66 | int ret = iter.data().toInt(&ok); | ||
67 | return ((ok) ? !!ret : deflt); | ||
68 | } | ||
69 | else | ||
70 | { | ||
71 | return deflt; | ||
72 | } | ||
73 | } | ||
74 | int Config::readNumEntry(const QString& key, const int deflt) | ||
75 | { | ||
76 | bool ok; | ||
77 | QMap<QString,QString>::Iterator iter = values.find(key); | ||
78 | if (iter != values.end()) | ||
79 | { | ||
80 | int ret = iter.data().toInt(&ok); | ||
81 | return ((ok) ? ret : deflt); | ||
82 | } | ||
83 | else | ||
84 | { | ||
85 | return deflt; | ||
86 | } | ||
87 | } | ||
88 | void Config::writeEntry(const QString& key, const QString& value) | ||
89 | { | ||
90 | values[key] = value; | ||
91 | } | ||
92 | |||
93 | void Config::writeEntry(const QString& key, const bool value) | ||
94 | { | ||
95 | values[key] = (value) ? "1" : "0"; | ||
96 | } | ||
97 | |||
98 | void Config::writeEntry(const QString& key, const int value) | ||
99 | { | ||
100 | QString rhs; | ||
101 | rhs.setNum(value); | ||
102 | values[key] = rhs; | ||
103 | } | ||
104 | |||
105 | #endif | ||