00001 /* -*- myth -*- */ 00024 #ifndef ACTION_H 00025 #define ACTION_H 00026 00027 // Qt headers 00028 #include <QStringList> 00029 #include <QHash> 00030 00039 class Action 00040 { 00041 public: 00043 Action(const QString &description) : m_description(description) 00044 { 00045 m_description.detach(); 00046 } 00047 Action(const QString &description, const QString &keys); 00048 00049 // Commands 00050 bool AddKey(const QString &key); 00051 bool ReplaceKey(const QString &newkey, const QString &oldkey); 00054 bool RemoveKey(const QString &key) 00055 { 00056 return m_keys.removeAll(key); 00057 } 00058 00059 // Gets 00061 QString GetDescription(void) const 00062 { 00063 QString desc = m_description; 00064 desc.detach(); 00065 return desc; 00066 } 00069 QStringList GetKeys(void) const 00070 { 00071 QStringList keys = m_keys; 00072 keys.detach(); 00073 return keys; 00074 } 00076 QString GetKeyString(void) const { return m_keys.join(","); } 00078 bool IsEmpty(void) const { return m_keys.empty(); } 00079 bool HasKey(const QString &key) const; 00080 00081 public: 00083 static const unsigned int kMaximumNumberOfBindings = 4; 00084 00085 private: 00086 QString m_description; 00087 QStringList m_keys; 00088 }; 00089 typedef QHash<QString, Action*> Context; 00090 00096 class ActionID 00097 { 00098 public: 00100 ActionID(void); 00101 00106 ActionID(const QString &context, const QString &action) 00107 : m_context(context), m_action(action) 00108 { 00109 m_context.detach(); 00110 m_action.detach(); 00111 } 00112 00113 ActionID(const ActionID &other) 00114 : m_context(other.m_context), m_action(other.m_action) 00115 { 00116 m_context.detach(); 00117 m_action.detach(); 00118 } 00119 00121 QString GetContext(void) const 00122 { 00123 QString tmp = m_context; 00124 tmp.detach(); 00125 return tmp; 00126 } 00127 00129 QString GetAction(void) const 00130 { 00131 QString tmp = m_action; 00132 tmp.detach(); 00133 return tmp; 00134 } 00135 00136 bool operator==(const ActionID &other) const 00137 { 00138 return ((m_action == other.m_action) && 00139 (m_context == other.m_context)); 00140 } 00141 00142 private: 00143 QString m_context; 00144 QString m_action; 00145 }; 00146 typedef QList<ActionID> ActionList; 00147 00148 #endif /* ACTION_H */
1.6.3