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