summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/preferences.cpp
blob: 67960ed7ebddaeb645e514b0bb357ac7b8a75d51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105

#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