summaryrefslogtreecommitdiff
path: root/noncore/apps/zsafe/extra
authorllornkcor <llornkcor>2004-07-13 10:35:23 (UTC)
committer llornkcor <llornkcor>2004-07-13 10:35:23 (UTC)
commit37e0e077b51841971c3d4c25b287f4d39e750e2d (patch) (unidiff)
treec1b499dd6e544207c6ff7047acd8170d6ea63f94 /noncore/apps/zsafe/extra
parent5d2ec2e9b1dce49e914c260fe16a82ddccbaa92d (diff)
downloadopie-37e0e077b51841971c3d4c25b287f4d39e750e2d.zip
opie-37e0e077b51841971c3d4c25b287f4d39e750e2d.tar.gz
opie-37e0e077b51841971c3d4c25b287f4d39e750e2d.tar.bz2
fix ups, and move qsettings files away
Diffstat (limited to 'noncore/apps/zsafe/extra') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/zsafe/extra/qsettings.cpp156
-rw-r--r--noncore/apps/zsafe/extra/qsettings.h56
2 files changed, 212 insertions, 0 deletions
diff --git a/noncore/apps/zsafe/extra/qsettings.cpp b/noncore/apps/zsafe/extra/qsettings.cpp
new file mode 100644
index 0000000..def2e2d
--- a/dev/null
+++ b/noncore/apps/zsafe/extra/qsettings.cpp
@@ -0,0 +1,156 @@
1/*
2** $Id$
3*/
4
5#include "qsettings.h"
6#include <stdio.h>
7#include <qfile.h>
8#include <qtextstream.h>
9
10
11QSettings::QSettings(const QString &_fn)
12{
13 qWarning("Settings "+_fn);
14 // read the prefs from the file
15 fn = _fn;
16
17 QFile f(_fn);
18 if ( f.open(IO_ReadOnly) ) { // file opened successfully
19 QTextStream t( &f ); // use a text stream
20 QString s;
21 while ( !t.eof() ) { // until end of file...
22 s = t.readLine(); // line of text excluding '\n'
23 char buf[256];
24 sprintf (buf, "%s", (const char *) s);
25 int pos = s.find (" = ");
26 QString key = s.left (pos);
27 QString val = s.right (s.length() - pos - 3);
28 writeEntry (key, val);
29
30 sprintf (buf, "%s|%s", (const char *)key, (const char *)val);
31 }
32 f.close();
33 }
34
35
36}
37
38QSettings::~QSettings()
39{
40 // write out the prefs to the file
41 QAsciiDictIterator <QString> it( prefs ); // iterator for dict
42 QFile f(fn);
43 f.open(IO_WriteOnly);
44 QTextStream ts( &f );
45
46 while ( it.current() )
47 {
48 QString *key = new QString(it.currentKey());
49 char buf[256];
50 sprintf (buf, "%s", (const char *) *( it.current()));
51 QString *val = new QString(buf);
52 sprintf (buf, "%s %s", (const char *)*key, (const char *)*val);
53 ts << *key << " = " << *val << endl;
54 ++it;
55 }
56
57 f.close();
58 prefs.clear();
59}
60
61void QSettings::insertSearchPath (System sys, const QString &str)
62{
63 fn = str;
64}
65
66QString QSettings::readEntry (const QString &key, const QString &def)
67{
68
69 QString *s = prefs.find((const char *)key);
70 if (!s)
71 return def;
72 else
73 return *s;
74
75}
76
77int QSettings::readNumEntry (const QString &key, int def)
78{
79 QString *s = prefs[key];
80 if (!s) return def;
81 return s->toInt();
82}
83
84bool QSettings::readBoolEntry (const QString &key, bool def)
85{
86 QString *s = prefs[key];
87 if (!s) return def;
88 if (*s == "1")
89 return true;
90 else
91 return false;
92}
93
94bool QSettings::writeEntry (const QString &key, int val)
95{
96 char buf[64];
97 sprintf (buf, "%d", val);
98 QString *v = new QString(buf);
99 prefs.replace ((const char *)key, v);
100 return true;
101}
102
103bool QSettings::writeEntry (const QString &key, bool val)
104{
105 QString *v;
106 if (val)
107 v = new QString("1");
108 else
109 v = new QString("0");
110 prefs.replace ((const char *)key, v);
111 return true;
112}
113
114bool QSettings::writeEntry (const QString &key, const QString &val)
115{
116 QString *v = new QString (val);
117 prefs.replace ((const char *)key, v);
118 return true;
119}
120
121bool QSettings::writeEntry (const QString &key, const char *val)
122{
123 QString *v = new QString (val);
124 prefs.replace ((const char *)key, v);
125 return true;
126}
127
128bool QSettings::removeEntry (const QString &key)
129{
130 prefs.remove (key);
131 return true;
132}
133
134QStringList QSettings::entryList (const QString &key) const
135{
136 qDebug("entryList: "+key);
137 QStringList list;
138 if(!prefs.isEmpty()) {
139 QAsciiDictIterator <QString> it( prefs ); // iterator for dict
140 qDebug("ready");
141 while ( it.current() )
142 {
143 char buf[512];
144 sprintf(buf, "%s", (const char *) *( it.current()));
145 QString *val = new QString(buf);
146 sprintf(buf, "%s -> %s\n", it.currentKey(), (const char *)*val );
147 QString *cat = new QString(it.currentKey());
148 if (cat->contains("-field", FALSE))
149 list.append (it.currentKey());
150 ++it;
151 }
152 }
153 qWarning("Return here");
154 return list;
155}
156
diff --git a/noncore/apps/zsafe/extra/qsettings.h b/noncore/apps/zsafe/extra/qsettings.h
new file mode 100644
index 0000000..95e87b5
--- a/dev/null
+++ b/noncore/apps/zsafe/extra/qsettings.h
@@ -0,0 +1,56 @@
1/*
2** $Id$
3*/
4
5#ifndef _QSETTINGS_H_
6#define _QSETTINGS_H_
7
8#include <qstring.h>
9#include <qstringlist.h>
10#include <qasciidict.h>
11
12// class to hold one category item
13
14class QSettings
15{
16public:
17 enum Format {
18 Native = 0,
19 Ini
20 };
21 enum System {
22 Unix = 0,
23 Windows,
24 Mac
25 };
26 enum Scope {
27 User,
28 Global
29 };
30
31 QSettings(const QString &file=0);
32 ~QSettings();
33
34 void insertSearchPath (System, const QString &);
35
36 QString readEntry (const QString &, const QString &def = QString::null);
37 int readNumEntry (const QString &, int def = 0);
38 bool readBoolEntry (const QString &, bool def = 0);
39
40 bool writeEntry (const QString &, int);
41 bool writeEntry (const QString &, bool);
42 bool writeEntry (const QString &, const QString &);
43 bool writeEntry (const QString &, const char *);
44
45 bool removeEntry (const QString &);
46
47 QStringList entryList (const QString &) const;
48
49protected:
50
51private:
52 QAsciiDict <QString> prefs; // key, value dictonary
53 QString fn; // preference filename
54
55};
56#endif // _QSETTINGS_H_