00001 #ifndef CFGFILE_H
00002 #define CFGFILE_H
00003
00004 #include <qlist.h>
00005 #include "zkbxml.h"
00006
00007 class CfgEntry {
00008 public:
00009 CfgEntry();
00010 CfgEntry(const QString& file, const QString& label);
00011
00012 const QString& getFile() const;
00013 void setFile(const QString& f);
00014 const QString& getLabel() const;
00015 void setLabel(const QString& l);
00016
00017 protected:
00018 QString file;
00019 QString label;
00020 };
00021
00022 class CfgFile {
00023 public:
00024 CfgFile();
00025 ~CfgFile();
00026
00027 QList<CfgEntry>& getEntries();
00028 bool replaceEntry(const QString& file, const QString& label,
00029 int index = -1);
00030 bool deleteEntry(const QString& file);
00031
00032 int getAutorepeatDelay() const;
00033 void setAutorepeatDelay(int);
00034 int getAutorepeatPeriod() const;
00035 void setAutorepeatPeriod(int);
00036
00037 protected:
00038 QList<CfgEntry> entries;
00039 int ardelay;
00040 int arperiod;
00041 };
00042
00043 class CfgParser : public QXmlErrorHandler {
00044 public:
00045 CfgParser();
00046 virtual ~CfgParser();
00047
00048 bool load(QString file, CfgFile& cfg);
00049 bool save(QString file, CfgFile& cfg);
00050
00051 void addLabel(const QString& name, const QString& state);
00052 void addFile(const QString& file, const QString& prefix);
00053
00054 int getAutorepeatDelay() const;
00055 void setAutorepeatDelay(int);
00056 int getAutorepeatPeriod() const;
00057 void setAutorepeatPeriod(int);
00058
00059 virtual bool warning(const QXmlParseException& e);
00060 virtual bool error(const QXmlParseException& e);
00061 virtual bool fatalError(const QXmlParseException& e);
00062 virtual QString errorString();
00063
00064 QString getError();
00065
00066 protected:
00067 QString err;
00068 QMap<QString, QString> labels;
00069 QMap<QString, QString> includes;
00070 QList<QString> labelList;
00071 QList<QString> includeList;
00072 int ardelay;
00073 int arperiod;
00074 };
00075
00076 class CfgHandler : public ZkbXmlHandler {
00077 public:
00078 CfgHandler(CfgParser &);
00079 virtual ~CfgHandler();
00080
00081 protected:
00082 CfgParser& cfg;
00083
00084 virtual bool startKeymapElement(int ardelay, int arperiod,
00085 const QString& author);
00086 virtual bool startIncludeElement(const QString& file,
00087 const QString& prfix);
00088 virtual bool startLabelElement(const QString& label,
00089 const QString& state);
00090 virtual bool startStateElement(const QString& name,
00091 const QString& parent, bool dflt);
00092 virtual bool startMapElement(int key, bool pressed);
00093 virtual bool startEventElement(int keycode, int unicode, int modifiers,
00094 bool pressed, bool autorepeat);
00095 virtual bool startNextStateElement(const QString& state);
00096
00097 virtual bool endKeymapElement();
00098 virtual bool endIncludeElement();
00099 virtual bool endLabelElement();
00100 virtual bool endStateElement();
00101 virtual bool endMapElement();
00102 virtual bool endEventElement();
00103 virtual bool endNextStateElement();
00104 };
00105
00106 #endif