![]() |
Mixxx
|
00001 /*************************************************************************** 00002 configobject.h - description 00003 ------------------- 00004 begin : Thu Jun 6 2002 00005 copyright : (C) 2002 by Tue & Ken Haste Andersen 00006 email : haste@diku.dk 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #ifndef CONFIGOBJECT_H 00019 #define CONFIGOBJECT_H 00020 00021 #include <qstring.h> 00022 #include <qfile.h> 00023 #include <qkeysequence.h> 00024 #include <qdom.h> 00025 #include <qmap.h> 00026 #include <QHash> 00027 00028 /* 00029 typedef enum { 00030 MIDI_EMPTY = 0, 00031 MIDI_KEY = 1, 00032 MIDI_CTRL = 2, 00033 MIDI_PITCH = 3 00034 } MidiType; 00035 */ 00036 00037 typedef QMap<char,char> MidiValueMap; 00038 00039 /* 00040 Class for the key for a specific configuration element. A key consists of a 00041 group and an item. 00042 */ 00043 class ConfigKey 00044 { 00045 public: 00046 ConfigKey(); 00047 ConfigKey(QString g, QString i); 00048 static ConfigKey parseCommaSeparated(QString key); 00049 QString group, item; 00050 }; 00051 00052 /* comparison function for ConfigKeys. Used by a QHash in ControlObject */ 00053 inline bool operator==(const ConfigKey &c1, const ConfigKey &c2) { 00054 return c1.group == c2.group && c1.item == c2.item; 00055 } 00056 00057 /* QHash hash function for ConfigKey objects. */ 00058 inline uint qHash(const ConfigKey &key) { 00059 return qHash(key.group) ^ qHash(key.item); 00060 } 00061 00062 /* 00063 The value corresponding to a key. The basic value is a string, but can be 00064 subclassed to more specific needs. 00065 */ 00066 class ConfigValue 00067 { 00068 public: 00069 ConfigValue(); 00070 ConfigValue(QString _value); 00071 ConfigValue(int _value); 00072 inline ConfigValue(QDomNode /* node */) { qFatal("ConfigValue from QDomNode not implemented here"); } 00073 void valCopy(const ConfigValue _value); 00074 00075 QString value; 00076 friend bool operator==(const ConfigValue & s1, const ConfigValue & s2); 00077 }; 00078 00079 00080 class ConfigValueKbd : public ConfigValue 00081 { 00082 public: 00083 ConfigValueKbd(); 00084 ConfigValueKbd(QString _value); 00085 ConfigValueKbd(QKeySequence key); 00086 inline ConfigValueKbd(QDomNode /* node */) { qFatal("ConfigValueKbd from QDomNode not implemented here"); } 00087 void valCopy(const ConfigValueKbd v); 00088 friend bool operator==(const ConfigValueKbd & s1, const ConfigValueKbd & s2); 00089 00090 QKeySequence m_qKey; 00091 }; 00092 00093 template <class ValueType> class ConfigOption 00094 { 00095 public: 00096 ConfigOption() { val = NULL; key = NULL;}; 00097 ConfigOption(ConfigKey *_key, ValueType *_val) { key = _key ; val = _val; }; 00098 virtual ~ConfigOption() { 00099 delete key; 00100 delete val; 00101 } 00102 ValueType *val; 00103 ConfigKey *key; 00104 }; 00105 00106 template <class ValueType> class ConfigObject { 00107 public: 00108 ConfigKey key; 00109 ValueType value; 00110 ConfigOption<ValueType> option; 00111 00112 ConfigObject(QString file); 00113 ConfigObject(QDomNode node); 00114 ~ConfigObject(); 00115 ConfigOption<ValueType> *set(ConfigKey, ValueType); 00116 ConfigOption<ValueType> *get(ConfigKey key); 00117 ConfigKey *get(ValueType v); 00118 QString getValueString(ConfigKey k); 00119 00120 void clear(); 00121 void reopen(QString file); 00122 void Save(); 00123 QString getConfigPath(); 00124 00125 protected: 00126 QList< ConfigOption<ValueType>* > list; 00127 QString filename; 00128 00131 bool Parse(); 00132 }; 00133 00134 #endif 00135 00136