summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/preferences.cpp
authorpohly <pohly>2004-08-24 20:52:45 (UTC)
committer pohly <pohly>2004-08-24 20:52:45 (UTC)
commit73253e93327cf4ef0932de1b4afb56af22a0f37e (patch) (side-by-side diff)
tree1c9a7a6dd3341e036a894d348a3372525d29acec /noncore/apps/opie-reader/preferences.cpp
parente90847c784c48bd21bf8768cb38edb853b832697 (diff)
downloadopie-73253e93327cf4ef0932de1b4afb56af22a0f37e.zip
opie-73253e93327cf4ef0932de1b4afb56af22a0f37e.tar.gz
opie-73253e93327cf4ef0932de1b4afb56af22a0f37e.tar.bz2
updated source to opie-reader 0.7g
Diffstat (limited to 'noncore/apps/opie-reader/preferences.cpp') (more/less context) (ignore whitespace changes)
-rwxr-xr-xnoncore/apps/opie-reader/preferences.cpp105
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 @@
+#include "useqpe.h"
+#ifndef USEQPE
+
+#include "preferences.h"
+
+#include <qfile.h>
+#include <qtextstream.h>
+
+Config::Config(const QString& _fn) : fname(_fn)
+{
+// qDebug("Config::Config:%s", (const char*)fname);
+ QFile fl(fname);
+ if (fl.open(IO_ReadOnly))
+ {
+ QTextStream t(&fl);
+ QString key, value;
+ while (!t.eof())
+ {
+ QString data = t.readLine();
+ int colon = data.find(':');
+ if (colon > 0)
+ {
+ QString key = data.left(colon);
+ QString value = data.right(data.length()-colon-1);
+ values[key] = value;
+ }
+ }
+ fl.close();
+ }
+// read entries into values
+}
+Config::~Config()
+{
+// qDebug("Config::~Config:%s", (const char*)fname);
+ QFile fl(fname);
+ if (fl.open(IO_WriteOnly))
+ {
+ QTextStream t(&fl);
+ for (QMap<QString,QString>::Iterator iter = values.begin();
+ iter != values.end();
+ iter++)
+ {
+ t << iter.key() << ':' << iter.data() << '\n';
+ }
+ fl.close();
+ }
+}
+QString Config::readEntry(const QString& key, const QString& deflt)
+{
+ QMap<QString,QString>::Iterator iter = values.find(key);
+ if (iter != values.end())
+ {
+ return iter.data();
+ }
+ else
+ {
+ return deflt;
+ }
+}
+bool Config::readBoolEntry(const QString& key, const bool deflt)
+{
+ bool ok;
+ QMap<QString,QString>::Iterator iter = values.find(key);
+ if (iter != values.end())
+ {
+ int ret = iter.data().toInt(&ok);
+ return ((ok) ? !!ret : deflt);
+ }
+ else
+ {
+ return deflt;
+ }
+}
+int Config::readNumEntry(const QString& key, const int deflt)
+{
+ bool ok;
+ QMap<QString,QString>::Iterator iter = values.find(key);
+ if (iter != values.end())
+ {
+ int ret = iter.data().toInt(&ok);
+ return ((ok) ? ret : deflt);
+ }
+ else
+ {
+ return deflt;
+ }
+}
+void Config::writeEntry(const QString& key, const QString& value)
+{
+ values[key] = value;
+}
+
+void Config::writeEntry(const QString& key, const bool value)
+{
+ values[key] = (value) ? "1" : "0";
+}
+
+void Config::writeEntry(const QString& key, const int value)
+{
+ QString rhs;
+ rhs.setNum(value);
+ values[key] = rhs;
+}
+
+#endif