Diffstat (limited to 'noncore/apps/keyz-cfg/cfgfile.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/keyz-cfg/cfgfile.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/noncore/apps/keyz-cfg/cfgfile.cpp b/noncore/apps/keyz-cfg/cfgfile.cpp index b0dc968..81d1ee1 100644 --- a/noncore/apps/keyz-cfg/cfgfile.cpp +++ b/noncore/apps/keyz-cfg/cfgfile.cpp @@ -1,157 +1,163 @@ -#include <qmessagebox.h> #include "cfgfile.h" +/* OPIE */ +#include <opie2/odebug.h> +using namespace Opie::Core; + +/* QT */ +#include <qmessagebox.h> + // CfgEntry implementation CfgEntry::CfgEntry() { } CfgEntry::CfgEntry(const QString& f, const QString& l): file(f), label(l) { } const QString& CfgEntry::getFile() const { return file; } void CfgEntry::setFile(const QString& f) { file = f; } const QString& CfgEntry::getLabel() const { return label; } void CfgEntry::setLabel(const QString& f) { label = f; } // CfgFile implementation CfgFile::CfgFile():ardelay(400), arperiod(80) { } CfgFile::~CfgFile() { } QList<CfgEntry>& CfgFile::getEntries() { return entries; } bool CfgFile::replaceEntry(const QString& file, const QString& label, int index) { deleteEntry(file); CfgEntry* entry = new CfgEntry(file, label); if (index >= 0) { entries.insert(index, entry); } else { entries.append(entry); } return true; } 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; } int CfgFile::getAutorepeatDelay() const { return ardelay; } void CfgFile::setAutorepeatDelay(int n) { ardelay = n; } int CfgFile::getAutorepeatPeriod() const { return arperiod; } void CfgFile::setAutorepeatPeriod(int n) { arperiod = n; } // CfgParser implementation 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()) { - qDebug(err); + 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 = ""; - qDebug("include: file=" + fit.key() + ", prefix=" + fit.data()); + 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"); 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}; |