blob: 3693dff32a972934c084b9db8dce061d4bd02b74 (
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
106
107
108
109
110
111
112
|
#include "ConfigEx.h"
ConfigEx::ConfigEx(const QString& name, Domain domain)
: Config(name, domain)
{
m_charset = "utf8";
decode();
m_lastRead = QDateTime::currentDateTime();
}
#if 0
void ConfigEx::removeComment()
{
for(QMap<QString,ConfigGroup>::Iterator it=groups.begin();
it!=groups.end(); ++it){
QStringList removeList;
for(ConfigGroup::Iterator it2=(*it).begin();
it2!=(*it).end(); ++it2){
if(it2.key()[0] == '#'){
QString key = it2.key();
removeList.append(it2.key());
}
}
for(QStringList::Iterator it3=removeList.begin();
it3!=removeList.end(); ++it3){
(*it).remove(*it3);
}
}
}
#endif
void ConfigEx::decode()
{
QString group = getGroup();
setGroup("Global");
QString charset = readEntry("CharSet", "utf8");
qWarning("ConfigEx::decode()[%s][%s]", charset.latin1(), m_charset.latin1());
setGroup(group);
if(charset != m_charset){
m_charset = charset;
read();
}
//removeComment();
}
void ConfigEx::read()
{
qWarning("ConfigEx::read()");
groups.clear();
changed = FALSE;
if ( !QFileInfo( filename ).exists() ) {
git = groups.end();
return;
}
QFile f( filename );
if ( !f.open( IO_ReadOnly ) ) {
git = groups.end();
return;
}
QTextStream s( &f );
#ifdef CONFIG_MULTICODEC
QTextCodec* codec = QTextCodec::codecForName(m_charset);
if(codec == NULL){
codec = QTextCodec::codecForName("utf8");
qWarning("Config CharSet[utf8]");
} else {
qWarning("Config CharSet[%s]", m_charset.latin1());
}
s.setCodec(codec);
#else /* CONFIG_MULTICODEC */
#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
// The below should work, but doesn't in Qt 2.3.0
s.setCodec( QTextCodec::codecForMib( 106 ) );
#else
s.setEncoding( QTextStream::UnicodeUTF8 );
#endif
#endif /* CONFIG_MULTICODEC */
QStringList list = QStringList::split('\n', s.read() );
f.close();
for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
if ( !parse( *it ) ) {
git = groups.end();
return;
}
}
}
QStringList ConfigEx::getKeys()
{
QStringList keys;
if(groups.end() != git){
for(ConfigGroup::ConstIterator it=(*git).begin();
it!=(*git).end(); ++it){
if(it.key()[0] != '#'){
keys.append(it.key());
}
}
}
return(keys);
}
QDateTime ConfigEx::lastModified()
{
QFileInfo info(filename);
return(info.lastModified());
}
|