author | alwin <alwin> | 2005-02-28 09:40:30 (UTC) |
---|---|---|
committer | alwin <alwin> | 2005-02-28 09:40:30 (UTC) |
commit | 2b64a84d39eeed5681d0ee5068c7d11a01527750 (patch) (unidiff) | |
tree | c8693340dbc5ef5e2f9afa90b690829ddff2c4bd /noncore/applets/keyhelper/keyhelperapplet/misc/ConfigEx.cpp | |
parent | 61fa699140c5efbb6ba0bf2a62f7e8fbf62976be (diff) | |
download | opie-2b64a84d39eeed5681d0ee5068c7d11a01527750.zip opie-2b64a84d39eeed5681d0ee5068c7d11a01527750.tar.gz opie-2b64a84d39eeed5681d0ee5068c7d11a01527750.tar.bz2 |
other keymapping tool - not working this moment, I have to check it out
- the reason is that the config file is somewhat easier to understand than
from zkbapplet and has a nice config tool.
Please don't put it into any repositories this moment.
Diffstat (limited to 'noncore/applets/keyhelper/keyhelperapplet/misc/ConfigEx.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/applets/keyhelper/keyhelperapplet/misc/ConfigEx.cpp | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/noncore/applets/keyhelper/keyhelperapplet/misc/ConfigEx.cpp b/noncore/applets/keyhelper/keyhelperapplet/misc/ConfigEx.cpp new file mode 100644 index 0000000..3693dff --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/misc/ConfigEx.cpp | |||
@@ -0,0 +1,112 @@ | |||
1 | #include "ConfigEx.h" | ||
2 | |||
3 | ConfigEx::ConfigEx(const QString& name, Domain domain) | ||
4 | : Config(name, domain) | ||
5 | { | ||
6 | m_charset = "utf8"; | ||
7 | decode(); | ||
8 | m_lastRead = QDateTime::currentDateTime(); | ||
9 | } | ||
10 | |||
11 | #if 0 | ||
12 | void ConfigEx::removeComment() | ||
13 | { | ||
14 | for(QMap<QString,ConfigGroup>::Iterator it=groups.begin(); | ||
15 | it!=groups.end(); ++it){ | ||
16 | QStringList removeList; | ||
17 | for(ConfigGroup::Iterator it2=(*it).begin(); | ||
18 | it2!=(*it).end(); ++it2){ | ||
19 | if(it2.key()[0] == '#'){ | ||
20 | QString key = it2.key(); | ||
21 | removeList.append(it2.key()); | ||
22 | } | ||
23 | } | ||
24 | for(QStringList::Iterator it3=removeList.begin(); | ||
25 | it3!=removeList.end(); ++it3){ | ||
26 | (*it).remove(*it3); | ||
27 | } | ||
28 | } | ||
29 | } | ||
30 | #endif | ||
31 | |||
32 | void ConfigEx::decode() | ||
33 | { | ||
34 | QString group = getGroup(); | ||
35 | setGroup("Global"); | ||
36 | QString charset = readEntry("CharSet", "utf8"); | ||
37 | qWarning("ConfigEx::decode()[%s][%s]", charset.latin1(), m_charset.latin1()); | ||
38 | setGroup(group); | ||
39 | if(charset != m_charset){ | ||
40 | m_charset = charset; | ||
41 | read(); | ||
42 | } | ||
43 | //removeComment(); | ||
44 | } | ||
45 | |||
46 | void ConfigEx::read() | ||
47 | { | ||
48 | qWarning("ConfigEx::read()"); | ||
49 | groups.clear(); | ||
50 | changed = FALSE; | ||
51 | |||
52 | if ( !QFileInfo( filename ).exists() ) { | ||
53 | git = groups.end(); | ||
54 | return; | ||
55 | } | ||
56 | |||
57 | QFile f( filename ); | ||
58 | if ( !f.open( IO_ReadOnly ) ) { | ||
59 | git = groups.end(); | ||
60 | return; | ||
61 | } | ||
62 | |||
63 | QTextStream s( &f ); | ||
64 | #ifdef CONFIG_MULTICODEC | ||
65 | QTextCodec* codec = QTextCodec::codecForName(m_charset); | ||
66 | if(codec == NULL){ | ||
67 | codec = QTextCodec::codecForName("utf8"); | ||
68 | qWarning("Config CharSet[utf8]"); | ||
69 | } else { | ||
70 | qWarning("Config CharSet[%s]", m_charset.latin1()); | ||
71 | } | ||
72 | s.setCodec(codec); | ||
73 | #else /* CONFIG_MULTICODEC */ | ||
74 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) | ||
75 | // The below should work, but doesn't in Qt 2.3.0 | ||
76 | s.setCodec( QTextCodec::codecForMib( 106 ) ); | ||
77 | #else | ||
78 | s.setEncoding( QTextStream::UnicodeUTF8 ); | ||
79 | #endif | ||
80 | #endif /* CONFIG_MULTICODEC */ | ||
81 | |||
82 | QStringList list = QStringList::split('\n', s.read() ); | ||
83 | |||
84 | f.close(); | ||
85 | |||
86 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | ||
87 | if ( !parse( *it ) ) { | ||
88 | git = groups.end(); | ||
89 | return; | ||
90 | } | ||
91 | } | ||
92 | } | ||
93 | |||
94 | QStringList ConfigEx::getKeys() | ||
95 | { | ||
96 | QStringList keys; | ||
97 | if(groups.end() != git){ | ||
98 | for(ConfigGroup::ConstIterator it=(*git).begin(); | ||
99 | it!=(*git).end(); ++it){ | ||
100 | if(it.key()[0] != '#'){ | ||
101 | keys.append(it.key()); | ||
102 | } | ||
103 | } | ||
104 | } | ||
105 | return(keys); | ||
106 | } | ||
107 | |||
108 | QDateTime ConfigEx::lastModified() | ||
109 | { | ||
110 | QFileInfo info(filename); | ||
111 | return(info.lastModified()); | ||
112 | } | ||