-
Notifications
You must be signed in to change notification settings - Fork 0
/
options_reader.cc
120 lines (88 loc) · 2.02 KB
/
options_reader.cc
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <settings.h>
#include <options_reader.h>
QStringList options_reader::keys;
/*
** -- options_reader() --
*/
options_reader::options_reader(void)
{
contents.setAutoDelete(true);
initializeKeys();
}
/*
** -- ~options_reader() --
*/
options_reader::~options_reader()
{
contents.clear();
}
/*
** -- initializeKeys() --
*/
void options_reader::initializeKeys(void)
{
if(!keys.contains("auto_save"))
keys.append("auto_save");
if(!keys.contains("save_geometry"))
keys.append("save_geometry");
if(!keys.contains("time_option"))
keys.append("time_option");
if(!keys.contains("width"))
keys.append("width");
if(!keys.contains("height"))
keys.append("height");
if(!keys.contains("x-coord"))
keys.append("x-coord");
if(!keys.contains("y-coord"))
keys.append("y-coord");
if(!keys.contains("fw-x-coord"))
keys.append("fw-x-coord");
if(!keys.contains("fw-y-coord"))
keys.append("fw-y-coord");
if(!keys.contains("tw-x-coord"))
keys.append("tw-x-coord");
if(!keys.contains("tw-y-coord"))
keys.append("tw-y-coord");
if(!keys.contains("nqc_location"))
keys.append("nqc_location");
if(!keys.contains("delete_prompt_disabled"))
keys.append("delete_prompt_disabled");
}
/*
** -- read() --
*/
int options_reader::read(void)
{
QFile qf;
QString key = "";
QString str = "";
QString *item = NULL;
QString value = "";
QTextStream qts;
qf.setName(settings::getConfigurationFile());
if(!qf.open(IO_ReadOnly))
return 1;
contents.clear();
qts.setDevice(&qf);
while(!qts.eof())
{
str = qts.readLine().stripWhiteSpace();
if(str.startsWith("#"))
continue;
if(!str.contains("="))
continue;
key = str.left(str.find("=")).stripWhiteSpace();
value = str.right(str.length() - str.find("=") - 1).stripWhiteSpace();
if((item = new QString(value)) != NULL)
contents.insert(key, item);
}
qf.close();
return 0;
}
/*
** -- getContents() --
*/
QDict<QString> options_reader::getContents(void)
{
return contents;
}