summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/keyz-cfg/cfgfile.cpp365
1 files changed, 185 insertions, 180 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
@@ -14,3 +14,3 @@ CfgEntry::CfgEntry() {
CfgEntry::CfgEntry(const QString& f, const QString& l):
- file(f), label(l) {
+ file(f), label(l) {
}
@@ -18,3 +18,3 @@ CfgEntry::CfgEntry(const QString& f, const QString& l):
const QString& CfgEntry::getFile() const {
- return file;
+ return file;
}
@@ -22,3 +22,3 @@ const QString& CfgEntry::getFile() const {
void CfgEntry::setFile(const QString& f) {
- file = f;
+ file = f;
}
@@ -26,3 +26,3 @@ void CfgEntry::setFile(const QString& f) {
const QString& CfgEntry::getLabel() const {
- return label;
+ return label;
}
@@ -30,3 +30,3 @@ const QString& CfgEntry::getLabel() const {
void CfgEntry::setLabel(const QString& f) {
- label = f;
+ label = f;
}
@@ -41,3 +41,3 @@ CfgFile::~CfgFile() {
QList<CfgEntry>& CfgFile::getEntries() {
- return entries;
+ return entries;
}
@@ -45,12 +45,12 @@ QList<CfgEntry>& CfgFile::getEntries() {
bool CfgFile::replaceEntry(const QString& file, const QString& label, int index) {
- deleteEntry(file);
+ deleteEntry(file);
- CfgEntry* entry = new CfgEntry(file, label);
- if (index >= 0) {
- entries.insert(index, entry);
- } else {
- entries.append(entry);
- }
+ CfgEntry* entry = new CfgEntry(file, label);
+ if (index >= 0) {
+ entries.insert(index, entry);
+ } else {
+ entries.append(entry);
+ }
- return true;
+ return true;
}
@@ -58,10 +58,10 @@ bool CfgFile::replaceEntry(const QString& file, const QString& label, int index)
bool CfgFile::deleteEntry(const QString& file) {
- for(int i = 0; i < (int) entries.count(); i++) {
- CfgEntry* entry = entries.at(i);
- if (entry->getFile() == file) {
- entries.remove(i);
- return true;
- }
- }
- return false;
+ for(int i = 0; i < (int) entries.count(); i++) {
+ CfgEntry* entry = entries.at(i);
+ if (entry->getFile() == file) {
+ entries.remove(i);
+ return true;
+ }
+ }
+ return false;
}
@@ -69,3 +69,3 @@ bool CfgFile::deleteEntry(const QString& file) {
int CfgFile::getAutorepeatDelay() const {
- return ardelay;
+ return ardelay;
}
@@ -73,3 +73,3 @@ int CfgFile::getAutorepeatDelay() const {
void CfgFile::setAutorepeatDelay(int n) {
- ardelay = n;
+ ardelay = n;
}
@@ -77,3 +77,3 @@ void CfgFile::setAutorepeatDelay(int n) {
int CfgFile::getAutorepeatPeriod() const {
- return arperiod;
+ return arperiod;
}
@@ -81,3 +81,3 @@ int CfgFile::getAutorepeatPeriod() const {
void CfgFile::setAutorepeatPeriod(int n) {
- arperiod = n;
+ arperiod = n;
}
@@ -89,45 +89,45 @@ CfgParser::CfgParser() {
bool CfgParser::load(QString file, CfgFile& cfg) {
- QFile f(file);
- QXmlInputSource is(f);
- QXmlSimpleReader reader;
- CfgHandler p(*this);
-
- reader.setErrorHandler(this);
- reader.setContentHandler(&p);
-
- err = "";
- ardelay = -1;
- arperiod = -1;
- reader.parse(is);
-
- if (!err.isEmpty()) {
- odebug << err << oendl;
- 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;
+ QFile f(file);
+ QXmlInputSource is(f);
+ QXmlSimpleReader reader;
+ CfgHandler p(*this);
+
+ reader.setErrorHandler(this);
+ reader.setContentHandler(&p);
+
+ err = "";
+ ardelay = -1;
+ arperiod = -1;
+ reader.parse(is);
+
+ if (!err.isEmpty()) {
+ odebug << err << oendl;
+ 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;
}
@@ -135,51 +135,56 @@ bool CfgParser::load(QString file, CfgFile& cfg) {
bool CfgParser::save(QString file, CfgFile& cfg) {
- FILE* f = fopen((const char*) file.local8Bit(), "w");
-
- 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()) {
- 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;
+ 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()) {
+ 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;
}
@@ -190,3 +195,3 @@ CfgParser::~CfgParser() {
int CfgParser::getAutorepeatDelay() const {
- return ardelay;
+ return ardelay;
}
@@ -194,3 +199,3 @@ int CfgParser::getAutorepeatDelay() const {
void CfgParser::setAutorepeatDelay(int n) {
- ardelay = n;
+ ardelay = n;
}
@@ -198,3 +203,3 @@ void CfgParser::setAutorepeatDelay(int n) {
int CfgParser::getAutorepeatPeriod() const {
- return arperiod;
+ return arperiod;
}
@@ -202,3 +207,3 @@ int CfgParser::getAutorepeatPeriod() const {
void CfgParser::setAutorepeatPeriod(int n) {
- arperiod = n;
+ arperiod = n;
}
@@ -206,4 +211,4 @@ void CfgParser::setAutorepeatPeriod(int n) {
void CfgParser::addLabel(const QString& name, const QString& state) {
- labels.insert(state, name);
- labelList.append(&labels.find(state).data());
+ labels.insert(state, name);
+ labelList.append(&labels.find(state).data());
}
@@ -211,4 +216,4 @@ void CfgParser::addLabel(const QString& name, const QString& state) {
void CfgParser::addFile(const QString& file, const QString& prefix) {
- includes.insert(file, prefix);
- includeList.append(&includes.find(file).key());
+ includes.insert(file, prefix);
+ includeList.append(&includes.find(file).key());
}
@@ -216,3 +221,3 @@ void CfgParser::addFile(const QString& file, const QString& prefix) {
QString CfgParser::errorString() {
- return err;
+ return err;
}
@@ -220,10 +225,10 @@ QString CfgParser::errorString() {
bool CfgParser::warning(const QXmlParseException& e) {
- QString tmp;
+ QString tmp;
- tmp.sprintf("%d: warning: %s\n", e.lineNumber(),
- (const char*) e.message().utf8());
+ tmp.sprintf("%d: warning: %s\n", e.lineNumber(),
+ (const char*) e.message().utf8());
- err += tmp;
+ err += tmp;
- return true;
+ return true;
}
@@ -231,10 +236,10 @@ bool CfgParser::warning(const QXmlParseException& e) {
bool CfgParser::error(const QXmlParseException& e) {
- QString tmp;
+ QString tmp;
- tmp.sprintf("%d: error: %s\n", e.lineNumber(),
- (const char*) e.message().utf8());
+ tmp.sprintf("%d: error: %s\n", e.lineNumber(),
+ (const char*) e.message().utf8());
- err += tmp;
+ err += tmp;
- return true;
+ return true;
}
@@ -242,10 +247,10 @@ bool CfgParser::error(const QXmlParseException& e) {
bool CfgParser::fatalError(const QXmlParseException& e) {
- QString tmp;
+ QString tmp;
- tmp.sprintf("%d: fatal error: %s\n", e.lineNumber(),
- (const char*) e.message().utf8());
+ tmp.sprintf("%d: fatal error: %s\n", e.lineNumber(),
+ (const char*) e.message().utf8());
- err += tmp;
+ err += tmp;
- return false;
+ return false;
}
@@ -260,39 +265,39 @@ CfgHandler::~CfgHandler() {
bool CfgHandler::startKeymapElement(int ard, int arp, const QString& author) {
- if (author != "keyzcfg") {
- bool ret;
- ret = QMessageBox::warning(0, "keyz configurator",
- "Your zkb.xml doesn't seem created by keyz configurator.\n"
- "By using keyz configurator you may loose your current "
- "configuration\n Do you want to continue\n\n",
- "Yes", "No", 0, 0, 1);
+ if (author != "keyzcfg") {
+ bool ret;
+ ret = QMessageBox::warning(0, "keyz configurator",
+ "Your zkb.xml doesn't seem created by keyz configurator.\n"
+ "By using keyz configurator you may loose your current "
+ "configuration\n Do you want to continue\n\n",
+ "Yes", "No", 0, 0, 1);
- if (ret != 0) {
- err = "cancelled by user";
- return false;
- }
- }
+ if (ret != 0) {
+ err = "cancelled by user";
+ return false;
+ }
+ }
- if (ard != -1) {
- cfg.setAutorepeatDelay(ard);
- }
+ if (ard != -1) {
+ cfg.setAutorepeatDelay(ard);
+ }
- if (arp != -1) {
- cfg.setAutorepeatPeriod(arp);
- }
+ if (arp != -1) {
+ cfg.setAutorepeatPeriod(arp);
+ }
- return true;
+ return true;
}
-bool CfgHandler::startIncludeElement(const QString& file,
- const QString& pref) {
+bool CfgHandler::startIncludeElement(const QString& file,
+ const QString& pref) {
- cfg.addFile(file, pref);
- return true;
+ cfg.addFile(file, pref);
+ return true;
}
-bool CfgHandler::startLabelElement(const QString& label,
- const QString& state) {
+bool CfgHandler::startLabelElement(const QString& label,
+ const QString& state) {
- cfg.addLabel(label, state);
- return true;
+ cfg.addLabel(label, state);
+ return true;
}
@@ -301,3 +306,3 @@ bool CfgHandler::startStateElement(const QString&, const QString&, bool) {
- return true;
+ return true;
}
@@ -305,3 +310,3 @@ bool CfgHandler::startStateElement(const QString&, const QString&, bool) {
bool CfgHandler::startMapElement(int, bool) {
- return true;
+ return true;
}
@@ -309,3 +314,3 @@ bool CfgHandler::startMapElement(int, bool) {
bool CfgHandler::startEventElement(int, int, int, bool, bool) {
- return true;
+ return true;
}
@@ -313,3 +318,3 @@ bool CfgHandler::startEventElement(int, int, int, bool, bool) {
bool CfgHandler::startNextStateElement(const QString&) {
- return true;
+ return true;
}
@@ -318,3 +323,3 @@ bool CfgHandler::startNextStateElement(const QString&) {
bool CfgHandler::endKeymapElement() {
- return true;
+ return true;
}
@@ -322,3 +327,3 @@ bool CfgHandler::endKeymapElement() {
bool CfgHandler::endIncludeElement() {
- return true;
+ return true;
}
@@ -326,3 +331,3 @@ bool CfgHandler::endIncludeElement() {
bool CfgHandler::endLabelElement() {
- return true;
+ return true;
}
@@ -330,3 +335,3 @@ bool CfgHandler::endLabelElement() {
bool CfgHandler::endStateElement() {
- return true;
+ return true;
}
@@ -334,3 +339,3 @@ bool CfgHandler::endStateElement() {
bool CfgHandler::endMapElement() {
- return true;
+ return true;
}
@@ -338,3 +343,3 @@ bool CfgHandler::endMapElement() {
bool CfgHandler::endEventElement() {
- return true;
+ return true;
}
@@ -342,3 +347,3 @@ bool CfgHandler::endEventElement() {
bool CfgHandler::endNextStateElement() {
- return true;
+ return true;
}