-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 @@ -105,80 +105,85 @@ bool CfgParser::load(QString file, CfgFile& cfg) { return false; } QMap<QString, QString>::Iterator fit, lit; for(uint i = 0; i < includeList.count(); i++) { QString file = *includeList.at(i); fit = includes.find(file); QString prefix = fit.data(); QString label = ""; odebug << "include: file=" + fit.key() + ", prefix=" + fit.data() << oendl; lit = labels.find(prefix+":*"); if (lit != labels.end()) { label = lit.data(); } cfg.replaceEntry(file, label); } if (ardelay != -1) { cfg.setAutorepeatDelay(ardelay); } if (arperiod != -1) { cfg.setAutorepeatPeriod(arperiod); } return true; } bool CfgParser::save(QString file, CfgFile& cfg) { FILE* f = fopen((const char*) file.local8Bit(), "w"); + if (!f) { + oerr << "Could not write config file!" << oendl; + return false; + } fprintf(f, "<keymap autorepeat-delay=\"%d\" autorepeat-period=\"%d\" " "author=\"keyzcfg\">\n", cfg.getAutorepeatDelay(), cfg.getAutorepeatPeriod()); QList<CfgEntry>& entries = cfg.getEntries(); int n; for(n=0; n < (int) entries.count(); n++) { CfgEntry* entry = entries.at(n); QString l = entry->getLabel(); - if (!l.isEmpty()) { + if (l.isEmpty()) { + l = entry->getFile(); + } fprintf(f, "\t<label name=\"%s\" state=\"km%d:*\"/>\n", (const char*) l.utf8(), n); } - } for(n=0; n < (int) entries.count(); n++) { CfgEntry* entry = entries.at(n); fprintf(f, "\t<include file=\"%s\" prefix=\"km%d\"/>\n", (const char*) entry->getFile().utf8(), n); } int k = n-1; char* states[] = { "LShift", "LShift-Caps", "LShift-Num", "LShift-Num-Caps", 0}; for(n=0; n < (int) entries.count(); n++) { QString nstate = "km" + QString::number(n+1); if (n == k) { nstate = "km" + QString::number(0); } for(int i = 0; states[i] != 0; i++) { fprintf(f, "\t<state name=\"km%d:%s\">\n", n, states[i]); fprintf(f, "\t\t<map keycode=\"Middle\" pressed=\"true\">\n"); fprintf(f, "\t\t\t<next-state name=\"%s:%s\"/>\n", (const char*) nstate.utf8(), states[i]); fprintf(f, "\t\t</map>\n\t</state>\n\n"); } } fprintf(f, "\t<state name=\"km0:Normal\" default=\"true\"/>\n"); fprintf(f, "</keymap>"); fclose(f); return true; |