MythTV  master
action.h
Go to the documentation of this file.
1 /* -*- myth -*- */
23 #ifndef ACTION_H
24 #define ACTION_H
25 
26 // Qt headers
27 #include <QStringList>
28 #include <QHash>
29 
38 class Action
39 {
40  public:
42  explicit Action(const QString &description) : m_description(description) {}
43  Action(QString description, const QString &keys);
44 
45  // Commands
46  bool AddKey(const QString &key);
47  bool ReplaceKey(const QString &newkey, const QString &oldkey);
50  bool RemoveKey(const QString &key)
51  {
52  return m_keys.removeAll(key);
53  }
54 
55  // Gets
57  QString GetDescription(void) const { return m_description; }
60  QStringList GetKeys(void) const { return m_keys; }
62  QString GetKeyString(void) const { return m_keys.join(","); }
64  bool IsEmpty(void) const { return m_keys.empty(); }
65  bool HasKey(const QString &key) const;
66 
67  public:
69  static const unsigned int kMaximumNumberOfBindings = 4;
70 
71  private:
72  QString m_description;
73  QStringList m_keys;
74 };
75 using Context = QHash<QString, Action*>;
76 
82 class ActionID
83 {
84  public:
86  ActionID(void);
87 
92  ActionID(const QString &context, const QString &action)
93  : m_context(context), m_action(action) {}
94  ActionID(const ActionID &other)
95  : m_context(other.m_context), m_action(other.m_action) {}
96 
98  {
99  m_context = rhs.m_context;
100  m_action = rhs.m_action;
101  return *this;
102  }
103 
105  QString GetContext(void) const { return m_context; }
106 
108  QString GetAction(void) const { return m_action; }
109 
110  bool operator==(const ActionID &other) const
111  {
112  return ((m_action == other.m_action) &&
113  (m_context == other.m_context));
114  }
115 
116  private:
117  QString m_context;
118  QString m_action;
119 };
120 using ActionList = QList<ActionID>;
121 
122 #endif /* ACTION_H */
QStringList m_keys
The keys bound to the action.
Definition: action.h:73
QString GetKeyString(void) const
Returns comma delimited string of key bindings.
Definition: action.h:62
QHash< QString, Action * > Context
Definition: action.h:75
ActionID & operator=(const ActionID &rhs)
Definition: action.h:97
bool AddKey(const QString &key)
Add a key sequence to this action.
Definition: action.cpp:68
bool IsEmpty(void) const
Returns true iff the action has no keys.
Definition: action.h:64
bool ReplaceKey(const QString &newkey, const QString &oldkey)
Replace a key.
Definition: action.cpp:85
QString m_description
The actions description.
Definition: action.h:72
QString m_action
Definition: action.h:118
A class that uniquely identifies an action.
Definition: action.h:82
An action (for this plugin) consists of a description, and a set of key sequences.
Definition: action.h:38
bool RemoveKey(const QString &key)
Remove a key from this action.
Definition: action.h:50
ActionID(const ActionID &other)
Definition: action.h:94
QString GetDescription(void) const
Returns the action description. (note: not threadsafe)
Definition: action.h:57
QStringList GetKeys(void) const
Returns the key sequence(s) that trigger this action.
Definition: action.h:60
ActionID(void)
Create an empty action.
Action(const QString &description)
Create a new empty action.
Definition: action.h:42
ActionID(const QString &context, const QString &action)
Create a new action identifier.
Definition: action.h:92
QString GetAction(void) const
Returns the action name.
Definition: action.h:108
bool HasKey(const QString &key) const
Determine if the action already has a key.
Definition: action.cpp:52
bool operator==(const ActionID &other) const
Definition: action.h:110
QList< ActionID > ActionList
Definition: action.h:120
QString GetContext(void) const
Returns the context name.
Definition: action.h:105
QString m_context
Definition: action.h:117
static const unsigned int kMaximumNumberOfBindings
The maximum number of keys that can be bound to an action.
Definition: action.h:69