summaryrefslogtreecommitdiff
path: root/noncore/apps/tinykate/libkate/microkde
authorkergoth <kergoth>2003-01-28 03:23:14 (UTC)
committer kergoth <kergoth>2003-01-28 03:23:14 (UTC)
commitde1321a53998bc1d078f9492395c2a26392875ed (patch) (unidiff)
treeb36d59612da5bbafeaddd28cb88a222b699d2645 /noncore/apps/tinykate/libkate/microkde
parent728a7a4966c342be32c80c045cbae500160fc17b (diff)
downloadopie-de1321a53998bc1d078f9492395c2a26392875ed.zip
opie-de1321a53998bc1d078f9492395c2a26392875ed.tar.gz
opie-de1321a53998bc1d078f9492395c2a26392875ed.tar.bz2
Added a Config derivative.
Diffstat (limited to 'noncore/apps/tinykate/libkate/microkde') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/tinykate/libkate/microkde/kconfig.cpp181
-rw-r--r--noncore/apps/tinykate/libkate/microkde/kconfig.h51
-rw-r--r--noncore/apps/tinykate/libkate/microkde/kglobal.cpp6
-rw-r--r--noncore/apps/tinykate/libkate/microkde/kglobal.h6
4 files changed, 6 insertions, 238 deletions
diff --git a/noncore/apps/tinykate/libkate/microkde/kconfig.cpp b/noncore/apps/tinykate/libkate/microkde/kconfig.cpp
deleted file mode 100644
index d88bda0..0000000
--- a/noncore/apps/tinykate/libkate/microkde/kconfig.cpp
+++ b/dev/null
@@ -1,181 +0,0 @@
1#include <qfile.h>
2#include <qtextstream.h>
3
4#include "kdebug.h"
5
6#include "kconfig.h"
7
8QString KConfig::mGroup = "";
9//QString KConfig::mGroup = "General";
10
11KConfig::KConfig( const QString &fileName )
12 : mFileName( fileName ), mDirty( false )
13{
14 kdDebug() << "KConfig::KConfig(): '" << fileName << "'" << endl;
15
16 load();
17}
18
19
20KConfig::~KConfig()
21{
22 sync();
23}
24
25void 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
37QValueList<int> KConfig::readIntListEntry( const QString & )
38{
39 QValueList<int> l;
40 return l;
41}
42
43int KConfig::readNumEntry( const QString &, int def )
44{
45 return def;
46}
47
48QString 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
59QStringList KConfig::readListEntry( const QString & )
60{
61 return QStringList();
62}
63
64bool 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
75QColor KConfig::readColorEntry( const QString &, QColor *def )
76{
77 if ( def ) return *def;
78 return QColor();
79}
80
81QFont KConfig::readFontEntry( const QString &, QFont *def )
82{
83 if ( def ) return *def;
84 return QFont();
85}
86
87
88void KConfig::writeEntry( const QString &, QValueList<int> )
89{
90}
91
92void KConfig::writeEntry( const QString &, int )
93{
94}
95
96void KConfig::writeEntry( const QString &key, const QString &value )
97{
98 mStringMap.insert( mGroup + key, value );
99
100 mDirty = true;
101}
102
103void KConfig::writeEntry( const QString &, const QStringList & )
104{
105}
106
107void KConfig::writeEntry( const QString &key, bool value)
108{
109 mBoolMap.insert( mGroup + key, value );
110
111 mDirty = true;
112}
113
114void KConfig::writeEntry( const QString &, const QColor & )
115{
116}
117
118void KConfig::writeEntry( const QString &, const QFont & )
119{
120}
121
122void 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
155void 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}
diff --git a/noncore/apps/tinykate/libkate/microkde/kconfig.h b/noncore/apps/tinykate/libkate/microkde/kconfig.h
deleted file mode 100644
index 8bd768a..0000000
--- a/noncore/apps/tinykate/libkate/microkde/kconfig.h
+++ b/dev/null
@@ -1,51 +0,0 @@
1#ifndef MINIKDE_KCONFIG_H
2#define MINIKDE_KCONFIG_H
3
4#include <qstring.h>
5#include <qstringlist.h>
6#include <qvaluelist.h>
7#include <qcolor.h>
8#include <qfont.h>
9#include <qmap.h>
10
11class KConfig
12{
13 public:
14 KConfig( const QString & );
15 ~KConfig();
16
17 void setGroup( const QString & );
18
19 bool hasGroup( const QString &) {return false;}
20
21 QValueList<int> readIntListEntry( const QString & );
22 int readNumEntry( const QString &, int def=0 );
23 QString readEntry( const QString &, const QString &def=QString::null );
24 QStringList readListEntry( const QString & );
25 bool readBoolEntry( const QString &, bool def=false );
26 QColor readColorEntry( const QString &, QColor * );
27 QFont readFontEntry( const QString &, QFont * );
28
29 void writeEntry( const QString &, QValueList<int> );
30 void writeEntry( const QString &, int );
31 void writeEntry( const QString &, const QString & );
32 void writeEntry( const QString &, const QStringList & );
33 void writeEntry( const QString &, bool );
34 void writeEntry( const QString &, const QColor & );
35 void writeEntry( const QString &, const QFont & );
36
37 void load();
38 void sync();
39
40 private:
41 static QString mGroup;
42
43 QString mFileName;
44
45 QMap<QString,bool> mBoolMap;
46 QMap<QString,QString> mStringMap;
47
48 bool mDirty;
49};
50
51#endif
diff --git a/noncore/apps/tinykate/libkate/microkde/kglobal.cpp b/noncore/apps/tinykate/libkate/microkde/kglobal.cpp
index 572768d..9b5c4d3 100644
--- a/noncore/apps/tinykate/libkate/microkde/kglobal.cpp
+++ b/noncore/apps/tinykate/libkate/microkde/kglobal.cpp
@@ -1,7 +1,7 @@
1#include "kglobal.h" 1#include "kglobal.h"
2 2
3KLocale *KGlobal::mLocale = 0; 3KLocale *KGlobal::mLocale = 0;
4KConfig *KGlobal::mConfig = 0; 4KateConfig *KGlobal::mConfig = 0;
5KIconLoader *KGlobal::mIconLoader = 0; 5KIconLoader *KGlobal::mIconLoader = 0;
6KStandardDirs *KGlobal::mDirs = 0; 6KStandardDirs *KGlobal::mDirs = 0;
7 7
@@ -16,10 +16,10 @@ KLocale *KGlobal::locale()
16 return mLocale; 16 return mLocale;
17} 17}
18 18
19KConfig *KGlobal::config() 19KateConfig *KGlobal::config()
20{ 20{
21 if ( !mConfig ) { 21 if ( !mConfig ) {
22 mConfig = new KConfig( KStandardDirs::appDir() + mAppName + "rc" ); 22 mConfig = new KateConfig( mAppName );
23 } 23 }
24 24
25 return mConfig; 25 return mConfig;
diff --git a/noncore/apps/tinykate/libkate/microkde/kglobal.h b/noncore/apps/tinykate/libkate/microkde/kglobal.h
index 8985bd4..e4e2c79 100644
--- a/noncore/apps/tinykate/libkate/microkde/kglobal.h
+++ b/noncore/apps/tinykate/libkate/microkde/kglobal.h
@@ -4,12 +4,12 @@
4#include "klocale.h" 4#include "klocale.h"
5#include "kiconloader.h" 5#include "kiconloader.h"
6#include "kstandarddirs.h" 6#include "kstandarddirs.h"
7#include "kconfig.h" 7#include <kateconfig.h>
8 8
9class KGlobal { 9class KGlobal {
10 public: 10 public:
11 static KLocale *locale(); 11 static KLocale *locale();
12 static KConfig *config(); 12 static KateConfig *config();
13 static KIconLoader *iconLoader(); 13 static KIconLoader *iconLoader();
14 static KStandardDirs *dirs(); 14 static KStandardDirs *dirs();
15 15
@@ -17,7 +17,7 @@ class KGlobal {
17 17
18 private: 18 private:
19 static KLocale *mLocale; 19 static KLocale *mLocale;
20 static KConfig *mConfig; 20 static KateConfig *mConfig;
21 static KIconLoader *mIconLoader; 21 static KIconLoader *mIconLoader;
22 static KStandardDirs *mDirs; 22 static KStandardDirs *mDirs;
23 23