Diffstat (limited to 'noncore/apps/tinykate/libkate/microkde/kconfig.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/tinykate/libkate/microkde/kconfig.cpp | 181 |
1 files changed, 181 insertions, 0 deletions
diff --git a/noncore/apps/tinykate/libkate/microkde/kconfig.cpp b/noncore/apps/tinykate/libkate/microkde/kconfig.cpp new file mode 100644 index 0000000..d88bda0 --- a/dev/null +++ b/noncore/apps/tinykate/libkate/microkde/kconfig.cpp | |||
@@ -0,0 +1,181 @@ | |||
1 | #include <qfile.h> | ||
2 | #include <qtextstream.h> | ||
3 | |||
4 | #include "kdebug.h" | ||
5 | |||
6 | #include "kconfig.h" | ||
7 | |||
8 | QString KConfig::mGroup = ""; | ||
9 | //QString KConfig::mGroup = "General"; | ||
10 | |||
11 | KConfig::KConfig( const QString &fileName ) | ||
12 | : mFileName( fileName ), mDirty( false ) | ||
13 | { | ||
14 | kdDebug() << "KConfig::KConfig(): '" << fileName << "'" << endl; | ||
15 | |||
16 | load(); | ||
17 | } | ||
18 | |||
19 | |||
20 | KConfig::~KConfig() | ||
21 | { | ||
22 | sync(); | ||
23 | } | ||
24 | |||
25 | void KConfig::setGroup( const QString &group ) | ||
26 | { | ||
27 | return; | ||
28 | |||
29 | // kdDebug() << "KConfig::setGroup(): '" << group << "'" << endl; | ||
30 | |||
31 | mGroup = group; | ||
32 | |||
33 | if ( mGroup.right( 1 ) != "/" ) mGroup += "/"; | ||
34 | } | ||
35 | |||
36 | |||
37 | QValueList<int> KConfig::readIntListEntry( const QString & ) | ||
38 | { | ||
39 | QValueList<int> l; | ||
40 | return l; | ||
41 | } | ||
42 | |||
43 | int KConfig::readNumEntry( const QString &, int def ) | ||
44 | { | ||
45 | return def; | ||
46 | } | ||
47 | |||
48 | QString KConfig::readEntry( const QString &key, const QString &def ) | ||
49 | { | ||
50 | QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key ); | ||
51 | |||
52 | if ( it == mStringMap.end() ) { | ||
53 | return def; | ||
54 | } | ||
55 | |||
56 | return *it; | ||
57 | } | ||
58 | |||
59 | QStringList KConfig::readListEntry( const QString & ) | ||
60 | { | ||
61 | return QStringList(); | ||
62 | } | ||
63 | |||
64 | bool KConfig::readBoolEntry( const QString &key, bool def ) | ||
65 | { | ||
66 | QMap<QString,bool>::ConstIterator it = mBoolMap.find( mGroup + key ); | ||
67 | |||
68 | if ( it == mBoolMap.end() ) { | ||
69 | return def; | ||
70 | } | ||
71 | |||
72 | return *it; | ||
73 | } | ||
74 | |||
75 | QColor KConfig::readColorEntry( const QString &, QColor *def ) | ||
76 | { | ||
77 | if ( def ) return *def; | ||
78 | return QColor(); | ||
79 | } | ||
80 | |||
81 | QFont KConfig::readFontEntry( const QString &, QFont *def ) | ||
82 | { | ||
83 | if ( def ) return *def; | ||
84 | return QFont(); | ||
85 | } | ||
86 | |||
87 | |||
88 | void KConfig::writeEntry( const QString &, QValueList<int> ) | ||
89 | { | ||
90 | } | ||
91 | |||
92 | void KConfig::writeEntry( const QString &, int ) | ||
93 | { | ||
94 | } | ||
95 | |||
96 | void KConfig::writeEntry( const QString &key, const QString &value ) | ||
97 | { | ||
98 | mStringMap.insert( mGroup + key, value ); | ||
99 | |||
100 | mDirty = true; | ||
101 | } | ||
102 | |||
103 | void KConfig::writeEntry( const QString &, const QStringList & ) | ||
104 | { | ||
105 | } | ||
106 | |||
107 | void KConfig::writeEntry( const QString &key, bool value) | ||
108 | { | ||
109 | mBoolMap.insert( mGroup + key, value ); | ||
110 | |||
111 | mDirty = true; | ||
112 | } | ||
113 | |||
114 | void KConfig::writeEntry( const QString &, const QColor & ) | ||
115 | { | ||
116 | } | ||
117 | |||
118 | void KConfig::writeEntry( const QString &, const QFont & ) | ||
119 | { | ||
120 | } | ||
121 | |||
122 | void KConfig::load() | ||
123 | { | ||
124 | mBoolMap.clear(); | ||
125 | mStringMap.clear(); | ||
126 | |||
127 | QFile f( mFileName ); | ||
128 | if ( !f.open( IO_ReadOnly ) ) { | ||
129 | kdDebug() << "KConfig::load(): Can't open file '" << mFileName << "'" | ||
130 | << endl; | ||
131 | return; | ||
132 | } | ||
133 | |||
134 | |||
135 | QTextStream t( &f ); | ||
136 | |||
137 | QString line = t.readLine(); | ||
138 | |||
139 | while ( !line.isNull() ) { | ||
140 | QStringList tokens = QStringList::split( ",", line ); | ||
141 | if ( tokens[0] == "bool" ) { | ||
142 | bool value = false; | ||
143 | if ( tokens[2] == "1" ) value = true; | ||
144 | |||
145 | mBoolMap.insert( tokens[1], value ); | ||
146 | } else if ( tokens[0] == "QString" ) { | ||
147 | QString value = tokens[2]; | ||
148 | mStringMap.insert( tokens[1], value ); | ||
149 | } | ||
150 | |||
151 | line = t.readLine(); | ||
152 | } | ||
153 | } | ||
154 | |||
155 | void KConfig::sync() | ||
156 | { | ||
157 | if ( !mDirty ) return; | ||
158 | |||
159 | QFile f( mFileName ); | ||
160 | if ( !f.open( IO_WriteOnly ) ) { | ||
161 | kdDebug() << "KConfig::sync(): Can't open file '" << mFileName << "'" | ||
162 | << endl; | ||
163 | return; | ||
164 | } | ||
165 | |||
166 | QTextStream t( &f ); | ||
167 | |||
168 | QMap<QString,bool>::ConstIterator itBool; | ||
169 | for( itBool = mBoolMap.begin(); itBool != mBoolMap.end(); ++itBool ) { | ||
170 | t << "bool," << itBool.key() << "," << (*itBool ) << endl; | ||
171 | } | ||
172 | |||
173 | QMap<QString,QString>::ConstIterator itString; | ||
174 | for( itString = mStringMap.begin(); itString != mStringMap.end(); ++itString ) { | ||
175 | t << "QString," << itString.key() << "," << (*itString ) << endl; | ||
176 | } | ||
177 | |||
178 | f.close(); | ||
179 | |||
180 | mDirty = false; | ||
181 | } | ||