author | zecke <zecke> | 2004-12-20 22:17:40 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-12-20 22:17:40 (UTC) |
commit | b15930cd03acafd9770bca26f3388817f1a4dcbf (patch) (side-by-side diff) | |
tree | 7f86e31793c1bacb0882e7abb88a3847333f5c4a | |
parent | a50334dddaa542fd63726a639e852c30036f53a0 (diff) | |
download | opie-b15930cd03acafd9770bca26f3388817f1a4dcbf.zip opie-b15930cd03acafd9770bca26f3388817f1a4dcbf.tar.gz opie-b15930cd03acafd9770bca26f3388817f1a4dcbf.tar.bz2 |
-Fix for 1483
"ZKB should keep user settings in $HOME/Settings instead of $OPIEDIR/share/zkb"
Now by default it loads and saves to $HOME/Applications/zkb but falls
back to $OPIEDIR/share/zkb to find the included files
-rw-r--r-- | noncore/applets/zkbapplet/applet/zkbwidget.cpp | 18 | ||||
-rw-r--r-- | noncore/applets/zkbapplet/applet/zkbwidget.h | 2 | ||||
-rw-r--r-- | noncore/applets/zkbapplet/keyzcfg/cfgdlg.cpp | 2 | ||||
-rw-r--r-- | noncore/applets/zkbapplet/keyzcfg/main.cpp | 4 | ||||
-rw-r--r-- | noncore/applets/zkbapplet/keyzcfg/zkbcfg.cpp | 67 |
5 files changed, 47 insertions, 46 deletions
diff --git a/noncore/applets/zkbapplet/applet/zkbwidget.cpp b/noncore/applets/zkbapplet/applet/zkbwidget.cpp index 13729ea..55c08b3 100644 --- a/noncore/applets/zkbapplet/applet/zkbwidget.cpp +++ b/noncore/applets/zkbapplet/applet/zkbwidget.cpp @@ -1,168 +1,160 @@ #include <opie2/otaskbarapplet.h> #include <opie2/okeyfilter.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/applnk.h> #include <qpe/qpeapplication.h> #include <qpe/resource.h> #include <stdio.h> #include <unistd.h> #include "zkbwidget.h" #include "zkbcfg.h" using namespace Opie::Ui; ZkbWidget::ZkbWidget(QWidget* parent) :QLabel(parent),keymap(0),disabled(Resource::loadPixmap("zkb-disabled")) { labels = new QPopupMenu(); connect(labels, SIGNAL(activated(int)), this, SLOT(labelChanged(int))); loadKeymap(); channel = new QCopChannel("QPE/zkb", this); connect(channel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(signalReceived(const QCString&,const QByteArray&))); setFixedWidth ( AppLnk::smallIconSize() ); setFixedHeight ( AppLnk::smallIconSize() ); } ZkbWidget::~ZkbWidget() { - if (keymap != 0) { - delete keymap; - keymap = 0; - } + delete keymap; + keymap = 0; } int ZkbWidget::position() { return 8; } bool ZkbWidget::loadKeymap() { - ZkbConfig c(QPEApplication::qpeDir()+"share/zkb"); + ZkbConfig c(Global::applicationFileName("zkb", QString::null) ); QFontMetrics fm(font()); - if (keymap != 0) { - delete keymap; - keymap = 0; - } + delete keymap; + keymap = 0; Keymap* km = new Keymap(); if (!c.load("zkb.xml", *km, "")) { delete km; setPixmap(disabled); return false; } connect(km, SIGNAL(stateChanged(const QString&)), this, SLOT(stateChanged(const QString&))); Opie::Core::OKeyFilter::inst()->addHandler(km); Keymap* oldkm = keymap; keymap = km; if (oldkm != 0) { delete oldkm; } QString ltext = keymap->getCurrentLabel(); if (ltext.length()==0) ltext = "??"; setText(ltext); labels->clear(); QStringList l = keymap->listLabels(); labels->insertItem(disabled, 0, 0); int n = 1; w = 0; for(QStringList::Iterator it = l.begin(); it != l.end(); ++it, n++) { // printf("label: %s\n", (const char*) (*it).utf8()); labels->insertItem(*it, n, n); int lw = fm.width(*it); if (lw > w) { w = lw; } } if (w == 0) { hide(); } else { show(); } return true; } -QSize ZkbWidget::sizeHint() const { - return QSize(AppLnk::smallIconSize(),AppLnk::smallIconSize()); -} - void ZkbWidget::stateChanged(const QString& s) { // odebug << "stateChanged: " << s.utf8() << "\n" << oendl; setText(s); } void ZkbWidget::labelChanged(int id) { if (id == 0) { keymap->disable(); setPixmap(disabled); return; } keymap->enable(); QStringList l = keymap->listLabels(); QString lbl = l[id-1]; // printf("labelChanged: %s\n", (const char*) lbl.utf8()); State* state = keymap->getStateByLabel(lbl); if (state != 0) { keymap->setCurrentState(state); setText(lbl); } } void ZkbWidget::mouseReleaseEvent(QMouseEvent*) { QSize sh = labels->sizeHint(); QPoint p = mapToGlobal(QPoint((width()-sh.width())/2,-sh.height())); labels->exec(p); } void ZkbWidget::signalReceived(const QCString& msg, const QByteArray& data) { QDataStream stream(data, IO_ReadOnly); if (msg == "enable()") { keymap->enable(); } else if (msg == "disable()") { keymap->disable(); } else if (msg == "reload()") { QCopEnvelope("QPE/System", "busy()"); QTimer::singleShot(0, this, SLOT(reload())); } else if (msg == "switch(QString)") { QString lbl; stream >> lbl; if (keymap != 0) { State* state = keymap->getStateByLabel(lbl); if (state != 0) { keymap->setCurrentState(state); setText(lbl); } } } else if (msg == "debug(QString)") { QString flag; stream >> flag; } } void ZkbWidget::reload() { loadKeymap(); QCopEnvelope("QPE/System", "notBusy()"); } EXPORT_OPIE_APPLET_v1( ZkbWidget ) diff --git a/noncore/applets/zkbapplet/applet/zkbwidget.h b/noncore/applets/zkbapplet/applet/zkbwidget.h index 9bce85a..13906c0 100644 --- a/noncore/applets/zkbapplet/applet/zkbwidget.h +++ b/noncore/applets/zkbapplet/applet/zkbwidget.h @@ -1,39 +1,37 @@ #ifndef ZKBWIDGET_H #define ZKBWIDGET_H #include <qwidget.h> #include <qlabel.h> #include <qpopupmenu.h> #include <qpixmap.h> #include <qcopchannel_qws.h> #include "zkb.h" class ZkbWidget : public QLabel { Q_OBJECT public: ZkbWidget(QWidget* parent); ~ZkbWidget(); static int position(); - QSize sizeHint() const; - protected: QLabel* label; Keymap* keymap; QPopupMenu* labels; QCopChannel* channel; int w, h; QPixmap disabled; bool loadKeymap(); void mouseReleaseEvent(QMouseEvent*); protected slots: void stateChanged(const QString&); void labelChanged(int id); void signalReceived(const QCString& msg, const QByteArray& data); void reload(); }; #endif diff --git a/noncore/applets/zkbapplet/keyzcfg/cfgdlg.cpp b/noncore/applets/zkbapplet/keyzcfg/cfgdlg.cpp index 4190a9e..6f24ea0 100644 --- a/noncore/applets/zkbapplet/keyzcfg/cfgdlg.cpp +++ b/noncore/applets/zkbapplet/keyzcfg/cfgdlg.cpp @@ -1,132 +1,132 @@ #include <qdir.h> #include <qpe/qpeapplication.h> #include <qpe/qcopenvelope_qws.h> #include <unistd.h> #include "cfgdlg.h" CfgDlg::CfgDlg(QWidget* parent, CfgFile* cf, QApplication* app, bool mod): QDialog(parent, "CfgDlg", mod), cfile(cf), application(app) { setCaption(tr("keyz configurator")); QGridLayout* gl = new QGridLayout(this, 7, 5, 5, 5); QLabel* flabel = new QLabel("Available Keymaps", this); files = new QListBox(this); QPushButton* addButton = new QPushButton(">>", this); //add->setText("Add"); connect(addButton, SIGNAL(clicked()), this, SLOT(add())); QLabel* klabel = new QLabel("Selected Keymaps", this); keymaps = new QListBox(this); connect(keymaps, SIGNAL(highlighted(const QString&)), this, SLOT(keymapHighlighted(const QString&))); QPushButton* delButton = new QPushButton("<<", this); //del->setText("Delete"); connect(delButton, SIGNAL(clicked()), this, SLOT(del())); QPushButton* slabelButton = new QPushButton("Set Label", this); //apply->setText("Apply"); connect(slabelButton, SIGNAL(clicked()), this, SLOT(setLabel())); QLabel* l = new QLabel("Label", this); label = new QLineEdit(this); QLabel* adlabel = new QLabel("Auto Repeat Delay (ms)", this); QLabel* aplabel = new QLabel("Auto Repeat Period (ms)", this); ad = new QSpinBox(50, 5000, 5, this); ap = new QSpinBox(0, 5000, 5, this); // QLabel* adms = new QLabel("ms", this); // QLabel* apms = new QLabel("ms", this); // QCheckBox* enable = new QCheckBox("Enable", t); gl->setColStretch(0, 1); gl->setColStretch(1, 1); gl->setColStretch(3, 1); gl->setColStretch(4, 1); gl->setRowStretch(3, 1); gl->addMultiCellWidget(flabel, 0, 0, 0, 1); gl->addMultiCellWidget(klabel, 0, 0, 3, 4); gl->addMultiCellWidget(files, 1, 3, 0, 1); gl->addMultiCellWidget(keymaps, 1, 3, 3, 4); gl->addWidget(addButton, 1, 2); gl->addWidget(delButton, 2, 2); gl->addWidget(l, 4, 0); gl->addWidget(label, 4, 1); gl->addMultiCellWidget(slabelButton, 4, 4, 3, 4); gl->addMultiCellWidget(adlabel, 5, 5, 0, 2); gl->addMultiCellWidget(ad, 5, 5, 3, 4); // gl->addWidget(adms, 5, 3); gl->addMultiCellWidget(aplabel, 6, 6, 0, 2); gl->addMultiCellWidget(ap, 6, 6, 3, 4); // gl->addWidget(apms, 6, 3); QList<CfgEntry>& e = cfile->getEntries(); for(uint i = 0; i < e.count(); i++) { CfgEntry* entry = e.at(i); keymaps->insertItem(entry->getFile()); m.insert(entry->getFile(), entry->getLabel()); } QDir dir(QPEApplication::qpeDir()+"share/zkb", "*.xml"); QStringList flist = dir.entryList(); QStringList::Iterator sit; for(sit = flist.begin(); sit != flist.end(); ++sit) { if (*sit != "common.xml" && *sit != "zkb.xml" && m.find(*sit) == m.end()) { files->insertItem(*sit); } } ad->setValue(cfile->getAutorepeatDelay()); ap->setValue(cfile->getAutorepeatPeriod()); // gl->addMultiCellWidget(enable, 7, 7, 0, 4); } CfgDlg::~CfgDlg() { } void CfgDlg::add() { if (!files->currentText().isEmpty()) { QString t = files->currentText(); files->removeItem(files->currentItem()); keymaps->insertItem(t); cfile->replaceEntry(t, ""); m.replace(t, ""); } } void CfgDlg::del() { if (!keymaps->currentText().isEmpty()) { QString t = keymaps->currentText(); keymaps->removeItem(keymaps->currentItem()); cfile->deleteEntry(t); files->insertItem(t); m.remove(files->currentText()); } } void CfgDlg::setLabel() { if (!keymaps->currentText().isEmpty()) { cfile->replaceEntry(keymaps->currentText(), label->text()); m.replace(keymaps->currentText(), label->text()); } } void CfgDlg::keymapHighlighted(const QString&text) { label->setText(*m.find(text)); } void CfgDlg::accept() { cfile->setAutorepeatDelay(ad->value()); cfile->setAutorepeatPeriod(ap->value()); CfgParser p; - p.save(QPEApplication::qpeDir()+"share/zkb/zkb.xml", *cfile); + p.save(Global::applicationFileName("zkb", "zkb.xml" ), *cfile); QCopEnvelope("QPE/zkb", "reload()"); QDialog::accept(); } diff --git a/noncore/applets/zkbapplet/keyzcfg/main.cpp b/noncore/applets/zkbapplet/keyzcfg/main.cpp index afd0f6a..d7926f0 100644 --- a/noncore/applets/zkbapplet/keyzcfg/main.cpp +++ b/noncore/applets/zkbapplet/keyzcfg/main.cpp @@ -1,22 +1,24 @@ #include <stdio.h> #include <qpe/qpeapplication.h> +#include <qpe/global.h> + #include <qlayout.h> #include <qmainwindow.h> #include "cfgdlg.h" int main( int argc, char **argv ) { QPEApplication app(argc, argv); CfgFile cfile; CfgParser cp; - cp.load(QPEApplication::qpeDir()+"share/zkb/zkb.xml", cfile); + cp.load(Global::applicationFileName("zkb", "zkb.xml"), cfile); CfgDlg c(0, &cfile, &app, true); app.showMainWidget(&c); int ret = QPEApplication::execDialog(&c); return ret; } diff --git a/noncore/applets/zkbapplet/keyzcfg/zkbcfg.cpp b/noncore/applets/zkbapplet/keyzcfg/zkbcfg.cpp index 24bd897..6f3b9bf 100644 --- a/noncore/applets/zkbapplet/keyzcfg/zkbcfg.cpp +++ b/noncore/applets/zkbapplet/keyzcfg/zkbcfg.cpp @@ -1,231 +1,240 @@ #include "zkbcfg.h" /* OPIE */ #include <opie2/odebug.h> +#include <opie2/oapplication.h> using namespace Opie::Core; /* QT */ #include <qfileinfo.h> // Implementation of XkbConfig class ZkbConfig::ZkbConfig(const QString& dir):path(dir) { } ZkbConfig::~ZkbConfig() { } bool ZkbConfig::load(const QString& file, Keymap& keymap, const QString& prefix) { - bool ret; - QFile f(path+"/"+file); - QFileInfo fi(f); + bool ret; + QFile *f = new QFile(path+"/"+file); + QFileInfo fi(*f); - odebug << "start loading file=" << file.utf8() << "\n" << oendl; - if (includedFiles.find(fi.absFilePath()) != includedFiles.end()) { - return false; - } + /* Try */ + if ( !fi.exists() && !path.contains( QPEApplication::qpeDir()) ) { + delete f; + f = new QFile( QPEApplication::qpeDir() + "share/zkb/" + file ); + fi = QFileInfo( *f ); + } - includedFiles.insert(fi.absFilePath(), 1); - QXmlInputSource is(f); - QXmlSimpleReader reader; - ZkbHandler h(*this, keymap, prefix); + odebug << "start loading file=" << file << "\n" << oendl; + if (includedFiles.find(fi.absFilePath()) != includedFiles.end()) { + return false; + } - reader.setContentHandler(&h); - reader.setErrorHandler(this); - ret = reader.parse(is); - includedFiles.remove(fi.absFilePath()); + includedFiles.insert(fi.absFilePath(), 1); + QXmlInputSource is(*f); + QXmlSimpleReader reader; + ZkbHandler h(*this, keymap, prefix); - odebug << "end loading file=" << file.utf8() << ": status=" << err.utf8() << oendl; - return ret; + reader.setContentHandler(&h); + reader.setErrorHandler(this); + ret = reader.parse(is); + includedFiles.remove(fi.absFilePath()); + + odebug << "end loading file=" << file << ": status=" << err << oendl; + delete f; + return ret; } bool ZkbConfig::warning(const QXmlParseException& e) { QString tmp; - tmp.sprintf("%d: warning: %s\n", e.lineNumber(), + tmp.sprintf("%d: warning: %s\n", e.lineNumber(), (const char*) e.message().utf8()); err += tmp; return true; } bool ZkbConfig::error(const QXmlParseException& e) { QString tmp; - tmp.sprintf("%d: error: %s\n", e.lineNumber(), + tmp.sprintf("%d: error: %s\n", e.lineNumber(), (const char*) e.message().utf8()); err += tmp; return true; } bool ZkbConfig::fatalError(const QXmlParseException& e) { QString tmp; - tmp.sprintf("%d: fatal error: %s\n", e.lineNumber(), + tmp.sprintf("%d: fatal error: %s\n", e.lineNumber(), (const char*) e.message().utf8()); err += tmp; return false; } QString ZkbConfig::errorString() { return err; } // Implementation of ZkbHandler -ZkbHandler::ZkbHandler(ZkbConfig& z, Keymap& k, const QString& p):zkc(z), keymap(k), +ZkbHandler::ZkbHandler(ZkbConfig& z, Keymap& k, const QString& p):zkc(z), keymap(k), prefix(p), ardelay(-1), arperiod(-1), currentState(0), currentAction(0) { } ZkbHandler::~ZkbHandler() { } bool ZkbHandler::startKeymapElement(int ard, int arp, const QString&) { ardelay = ard; arperiod = arp; return true; } -bool ZkbHandler::startIncludeElement(const QString& file, +bool ZkbHandler::startIncludeElement(const QString& file, const QString& pref) { QString p = prefix; if (!pref.isNull()) { p += pref + ":"; } - + bool ret = zkc.load(file, keymap, p); if (!ret) { setError("Error including file: " + file); } return ret; } -bool ZkbHandler::startLabelElement(const QString& label, +bool ZkbHandler::startLabelElement(const QString& label, const QString& state) { if (!keymap.addLabel(label, prefix + state)) { err = "label " + label + " already defined"; return false; } return true; } -bool ZkbHandler::startStateElement(const QString& name, +bool ZkbHandler::startStateElement(const QString& name, const QString& parentName, bool dflt) { currentStateName = prefix + name; currentState = keymap.getStateByName(currentStateName); -// odebug << "state name=" << currentStateName.utf8() << "\n" << oendl; +// odebug << "state name=" << currentStateName.utf8() << "\n" << oendl; State* parent = 0; if (!parentName.isEmpty()) { QString pn = prefix + parentName; parent = keymap.getStateByName(pn); if (parent == 0) { - err = currentStateName + + err = currentStateName + ": undefined parent state: " + pn; return false; } } if (currentState == 0) { currentState = new State(parent); keymap.addState(currentStateName, currentState); } else { if (parent!=0) { currentState->setParent(parent); } } if (dflt) { keymap.setCurrentState(currentState); } return true; } bool ZkbHandler::startMapElement(int keycode, bool pressed) { currentAction = currentState->get(keycode, pressed); if (currentAction == 0) { setError("keycode " + QString::number(keycode) + " not supported"); return false; } currentAction->setEvent(false); currentAction->setState(0); return true; } -bool ZkbHandler::startEventElement(int keycode, int unicode, int modifiers, +bool ZkbHandler::startEventElement(int keycode, int unicode, int modifiers, bool pressed, bool autorepeat) { currentAction->setEvent(true); currentAction->setKeycode(keycode); currentAction->setUnicode(unicode); currentAction->setModifiers(modifiers); currentAction->setPressed(pressed); currentAction->setAutorepeat(autorepeat); return true; } bool ZkbHandler::startNextStateElement(const QString& state) { State* s = keymap.getStateByName(prefix + state); if (s == 0) { setError("undefine state: " + prefix + state); return false; } currentAction->setState(s); return true; } bool ZkbHandler::endKeymapElement() { if (ardelay > 0) { keymap.setAutorepeatDelay(ardelay); } if (arperiod > 0) { keymap.setAutorepeatPeriod(arperiod); } - + return true; } bool ZkbHandler::endIncludeElement() { return true; } bool ZkbHandler::endLabelElement() { return true; } bool ZkbHandler::endStateElement() { currentState = 0; return true; } bool ZkbHandler::endMapElement() { currentAction = 0; return true; } bool ZkbHandler::endEventElement() { return true; } bool ZkbHandler::endNextStateElement() { return true; } |