author | alwin <alwin> | 2004-08-01 14:13:14 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-08-01 14:13:14 (UTC) |
commit | 67e2e98457418bc491efd2d4567f851e77a0441a (patch) (unidiff) | |
tree | 44a579f9ee06ec5a703825c1738d3e1a6155a282 | |
parent | 4fbd0218b71432444214cf124c45e3d03185324f (diff) | |
download | opie-67e2e98457418bc491efd2d4567f851e77a0441a.zip opie-67e2e98457418bc491efd2d4567f851e77a0441a.tar.gz opie-67e2e98457418bc491efd2d4567f851e77a0441a.tar.bz2 |
fixed a crasher when configfile isn't writeable
empty labels will replaced by filename
-rw-r--r-- | noncore/apps/keyz-cfg/cfgfile.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/noncore/apps/keyz-cfg/cfgfile.cpp b/noncore/apps/keyz-cfg/cfgfile.cpp index 81d1ee1..be7150e 100644 --- a/noncore/apps/keyz-cfg/cfgfile.cpp +++ b/noncore/apps/keyz-cfg/cfgfile.cpp | |||
@@ -113,64 +113,69 @@ bool CfgParser::load(QString file, CfgFile& cfg) { | |||
113 | QString label = ""; | 113 | QString label = ""; |
114 | 114 | ||
115 | odebug << "include: file=" + fit.key() + ", prefix=" + fit.data() << oendl; | 115 | odebug << "include: file=" + fit.key() + ", prefix=" + fit.data() << oendl; |
116 | lit = labels.find(prefix+":*"); | 116 | lit = labels.find(prefix+":*"); |
117 | if (lit != labels.end()) { | 117 | if (lit != labels.end()) { |
118 | label = lit.data(); | 118 | label = lit.data(); |
119 | } | 119 | } |
120 | 120 | ||
121 | cfg.replaceEntry(file, label); | 121 | cfg.replaceEntry(file, label); |
122 | } | 122 | } |
123 | 123 | ||
124 | if (ardelay != -1) { | 124 | if (ardelay != -1) { |
125 | cfg.setAutorepeatDelay(ardelay); | 125 | cfg.setAutorepeatDelay(ardelay); |
126 | } | 126 | } |
127 | 127 | ||
128 | if (arperiod != -1) { | 128 | if (arperiod != -1) { |
129 | cfg.setAutorepeatPeriod(arperiod); | 129 | cfg.setAutorepeatPeriod(arperiod); |
130 | } | 130 | } |
131 | 131 | ||
132 | return true; | 132 | return true; |
133 | } | 133 | } |
134 | 134 | ||
135 | bool CfgParser::save(QString file, CfgFile& cfg) { | 135 | bool CfgParser::save(QString file, CfgFile& cfg) { |
136 | FILE* f = fopen((const char*) file.local8Bit(), "w"); | 136 | FILE* f = fopen((const char*) file.local8Bit(), "w"); |
137 | if (!f) { | ||
138 | oerr << "Could not write config file!" << oendl; | ||
139 | return false; | ||
140 | } | ||
137 | 141 | ||
138 | fprintf(f, "<keymap autorepeat-delay=\"%d\" autorepeat-period=\"%d\" " | 142 | fprintf(f, "<keymap autorepeat-delay=\"%d\" autorepeat-period=\"%d\" " |
139 | "author=\"keyzcfg\">\n", cfg.getAutorepeatDelay(), | 143 | "author=\"keyzcfg\">\n", cfg.getAutorepeatDelay(), |
140 | cfg.getAutorepeatPeriod()); | 144 | cfg.getAutorepeatPeriod()); |
141 | 145 | ||
142 | QList<CfgEntry>& entries = cfg.getEntries(); | 146 | QList<CfgEntry>& entries = cfg.getEntries(); |
143 | int n; | 147 | int n; |
144 | 148 | ||
145 | for(n=0; n < (int) entries.count(); n++) { | 149 | for(n=0; n < (int) entries.count(); n++) { |
146 | CfgEntry* entry = entries.at(n); | 150 | CfgEntry* entry = entries.at(n); |
147 | QString l = entry->getLabel(); | 151 | QString l = entry->getLabel(); |
148 | if (!l.isEmpty()) { | 152 | if (l.isEmpty()) { |
153 | l = entry->getFile(); | ||
154 | } | ||
149 | fprintf(f, "\t<label name=\"%s\" state=\"km%d:*\"/>\n", | 155 | fprintf(f, "\t<label name=\"%s\" state=\"km%d:*\"/>\n", |
150 | (const char*) l.utf8(), n); | 156 | (const char*) l.utf8(), n); |
151 | } | 157 | } |
152 | } | ||
153 | 158 | ||
154 | for(n=0; n < (int) entries.count(); n++) { | 159 | for(n=0; n < (int) entries.count(); n++) { |
155 | CfgEntry* entry = entries.at(n); | 160 | CfgEntry* entry = entries.at(n); |
156 | fprintf(f, "\t<include file=\"%s\" prefix=\"km%d\"/>\n", | 161 | fprintf(f, "\t<include file=\"%s\" prefix=\"km%d\"/>\n", |
157 | (const char*) entry->getFile().utf8(), n); | 162 | (const char*) entry->getFile().utf8(), n); |
158 | } | 163 | } |
159 | 164 | ||
160 | int k = n-1; | 165 | int k = n-1; |
161 | char* states[] = { "LShift", "LShift-Caps", "LShift-Num", | 166 | char* states[] = { "LShift", "LShift-Caps", "LShift-Num", |
162 | "LShift-Num-Caps", 0}; | 167 | "LShift-Num-Caps", 0}; |
163 | 168 | ||
164 | for(n=0; n < (int) entries.count(); n++) { | 169 | for(n=0; n < (int) entries.count(); n++) { |
165 | QString nstate = "km" + QString::number(n+1); | 170 | QString nstate = "km" + QString::number(n+1); |
166 | if (n == k) { | 171 | if (n == k) { |
167 | nstate = "km" + QString::number(0); | 172 | nstate = "km" + QString::number(0); |
168 | } | 173 | } |
169 | 174 | ||
170 | for(int i = 0; states[i] != 0; i++) { | 175 | for(int i = 0; states[i] != 0; i++) { |
171 | fprintf(f, "\t<state name=\"km%d:%s\">\n", | 176 | fprintf(f, "\t<state name=\"km%d:%s\">\n", |
172 | n, states[i]); | 177 | n, states[i]); |
173 | fprintf(f, "\t\t<map keycode=\"Middle\" pressed=\"true\">\n"); | 178 | fprintf(f, "\t\t<map keycode=\"Middle\" pressed=\"true\">\n"); |
174 | fprintf(f, "\t\t\t<next-state name=\"%s:%s\"/>\n", | 179 | fprintf(f, "\t\t\t<next-state name=\"%s:%s\"/>\n", |
175 | (const char*) nstate.utf8(), states[i]); | 180 | (const char*) nstate.utf8(), states[i]); |
176 | fprintf(f, "\t\t</map>\n\t</state>\n\n"); | 181 | fprintf(f, "\t\t</map>\n\t</state>\n\n"); |