Ticket #2078: ui_and_logic.2.diff
File ui_and_logic.2.diff, 99.6 KB (added by , 18 years ago) |
---|
-
mythcontrols/actionset.h
26 26 27 27 #include <qdict.h> 28 28 29 /** 30 * @brief The statically assigned context for jump point actions. 31 */ 29 /** The statically assigned context for jump point actions. */ 32 30 #define JUMP_CONTEXT "JumpPoints" 33 31 34 /** 35 * @brief The name of global actions. 36 */ 32 /** The name of global actions. */ 37 33 #define GLOBAL_CONTEXT "Global" 38 34 39 35 /** Context is a grouping of actions */ 40 36 typedef QDict<Action> Context; 41 typedef QValueList<ActionID> ActionList;42 37 43 44 38 /** 45 * @class ActionSet 46 * @brief Maintains consistancy between actions and keybindings. 39 * Action list is list of ActionIDs 47 40 * 48 * This class handles adding a removing bindings to keys. 41 * @todo Make a class out of this type and ensure that the list is 42 * sorted appropriatly. 49 43 */ 44 typedef QValueList<ActionID> ActionList; 45 46 47 /** Maintains consistancy between actions, contexts and keys. */ 50 48 class ActionSet 51 49 { 52 50 53 51 public: 54 52 55 /** 56 * @brief Create a new, empty set of action bindings. 57 */ 53 /** Create a new, empty set of action bindings. */ 58 54 inline ActionSet() {}; 59 55 60 56 /** 61 * @brief Add an action. 57 * Add an action. 58 * 62 59 * @param id The action identifier. 63 60 * @param description The action description. 64 61 * @param keys The keys for this action. … … 67 64 * If the action has already been added, it will not be added 68 65 * again. There are no duplicate actions in the action set. 69 66 */ 70 bool addAction(const ActionID &id, const QString & description,67 bool AddAction(const ActionID &id, const QString & description, 71 68 const QString &keys); 72 69 73 70 /** 74 * @brief Add a binding. 71 * Add a binding. 72 * 75 73 * @param id The action identifier. 76 74 * @param key The symbolic name of the key. 77 75 * @return true if the key was added otherwise, false. 78 76 */ 79 bool add(const ActionID &id, const QString &key);77 bool Add(const ActionID &id, const QString &key); 80 78 81 79 /** 82 * @brief Remove a key from an action identifier. 80 * Remove a key from an action identifier. 81 * 83 82 * @param id The action identifier to remove from. 84 83 * @param key The key to remove. 85 84 */ 86 bool remove(const ActionID &id, const QString &key);85 bool Remove(const ActionID &id, const QString &key); 87 86 88 87 /** 89 * @brief Replace a specific key in a specific action. 88 * Replace a specific key in a specific action. 89 * 90 90 * @param id The action identifier. 91 91 * @param newkey The new key. 92 92 * @param oldkey The key to be replaced. 93 93 */ 94 bool replace(const ActionID &id, const QString &newkey,94 bool Replace(const ActionID &id, const QString &newkey, 95 95 const QString &oldkey); 96 96 97 97 /** 98 * @brief Get a list of all contexts in the action set. 98 * Get a list of all contexts in the action set. 99 * 99 100 * @return A list of all contexts. 100 101 */ 101 QStringList * contextStrings(void) const;102 QStringList * ContextStrings(void) const; 102 103 103 104 /** 104 * @brief Get a list of all action in the action set. 105 * Get a list of all action in the action set. 106 * 105 107 * @return A list of all actions in the action set. 106 108 */ 107 QStringList * actionStrings(const QString & context_name) const;109 QStringList * ActionStrings(const QString & context_name) const; 108 110 109 111 /** 110 * @brief Get a string containing all the keys in bound to an111 * action.112 * Get a string containing all the keys in bound to an action. 113 * 112 114 * @param id The action's identifier. 113 115 * @return null if there is no such action, otherwise, the keys. 114 116 */ 115 QString keyString(const ActionID &id) const;117 QString KeyString(const ActionID &id) const; 116 118 117 119 /** 118 * @brief Get the keys bound to an action by it's identifier. 120 * Get the keys bound to an action by it's identifier. 121 * 119 122 * @param id The action identifier. 120 123 * @return The keys used by the action. 121 124 */ 122 QStringList getKeys(const ActionID &id) const;125 QStringList GetKeys(const ActionID &id) const; 123 126 124 127 /** 125 * @brief Get the description of an action. 128 * Get all keys that are in use. 129 * 130 * @return A string list containing all of the keys. 131 */ 132 QStringList * GetAllKeys(void) const; 133 134 /** 135 * Get the contexts, in which a key is bound. 136 * 137 * @return A string list containing the context names. 138 */ 139 QStringList * GetKeyContexts(const QString &key) const; 140 141 /** 142 * Get all of the actions that are in use. 143 * 144 * @return A string list containing all of the actions. 145 */ 146 QStringList *GetAllActions(void) const; 147 148 /** 149 * Get the description of an action. 150 * 126 151 * @param id The action identifier. 127 152 * @return The action description. 128 153 */ 129 const QString & getDescription(const ActionID &id) const;154 const QString & GetDescription(const ActionID &id) const; 130 155 131 156 /** 132 * @brief Get the actions bound to the specified key. 157 * Get the actions bound to the specified key. 158 * 133 159 * @param key The key. 134 160 * @return The list of actions, which are bound to the key. 135 161 */ 136 const ActionList & getActions(const QString &key) const; 162 inline const ActionList & GetActions(const QString &key) const 163 { 164 return m_KeyMap[key]; 165 } 137 166 167 138 168 /** 139 * @briefGet the appropriate container of modified actions based on169 * Get the appropriate container of modified actions based on 140 170 * context. 171 * 141 172 * @return The appropriate container of modified actions. 142 173 */ 143 inline const ActionList & getModified(void) const { return _modified; } 174 inline const ActionList & GetModified(void) const 175 { 176 return m_Modified; 177 } 144 178 145 179 /** 146 * @brief Determine if the action set has been modified. 180 * Determine if the action set has been modified. 181 * 147 182 * @return True if changes have been made, otherwise, false. 148 183 */ 149 inline bool hasModified(void) const { return !(_modified.isEmpty()); } 184 inline bool HasModified(void) const 185 { 186 return !(m_Modified.isEmpty()); 187 } 150 188 151 189 /** 152 * @brief Mark an action as unmodified. 190 * Mark an action as unmodified. 191 * 153 192 * @return true if the action was modified, and is set to unmodified. 154 193 */ 155 inline bool unmodify(const ActionID & id)194 inline bool Unmodify(const ActionID & id) 156 195 { 157 return ( _modified.remove(id) > 0);196 return (m_Modified.remove(id) > 0); 158 197 } 159 198 160 199 /** 161 * @brief Determine if an action has been modified. 200 * Determine if an action has been modified. 201 * 162 202 * @param id The action identifier. 163 203 * @return true if the action is modified, otherwise, false. 164 204 */ 165 inline bool isModified(const ActionID &id)const { return !unmodified(id); } 205 inline bool IsModified(const ActionID &id) const 206 { 207 return !Unmodified(id); 208 } 166 209 167 210 /** 168 * @brief Determine if an action is still unmodified. 211 * Determine if an action is still unmodified. 212 * 169 213 * @param id The action identifier. 170 214 * @return true if the action has not been modified, otherwise, false. 171 215 */ 172 inline bool unmodified(const ActionID &id) const216 inline bool Unmodified(const ActionID &id) const 173 217 { 174 return ( getModified().contains(id) == 0);218 return (GetModified().contains(id) == 0); 175 219 } 176 220 177 221 protected: 178 222 179 223 /** 180 * @brief Mark an action as modified. 224 * Mark an action as modified. 225 * 181 226 * @param id The actio identifier. 182 227 */ 183 inline void modify(const ActionID &id)228 inline void Modify(const ActionID &id) 184 229 { 185 if ( unmodified(id)) _modified.push_back(id);230 if (Unmodified(id)) m_Modified.push_back(id); 186 231 } 187 232 188 233 /** 189 * @brief Get an action by its identifier. 234 * Get an action by its identifier. 235 * 190 236 * @return A pointer to the action. 191 237 */ 192 inline Action * action(const ActionID &id) const238 inline Action * GetAction(const ActionID &id) const 193 239 { 194 return context(id.context()) ?195 (* context(id.context()))[id.action()] : NULL;240 return GetContext(id.context()) ? 241 (*GetContext(id.context()))[id.action()] : NULL; 196 242 } 197 243 198 244 /** 199 * @brief Get a context by its identifier. 245 * Get a context by its identifier. 246 * 200 247 * @return A pointer to the context. 201 248 */ 202 inline Context * context(const QString & name) const249 inline Context * GetContext(const QString & name) const 203 250 { 204 return this-> _contexts[name];251 return this->m_Contexts[name]; 205 252 } 206 253 207 254 private: 208 255 209 QMap<QString, ActionList> _keymap; 210 QDict<Context> _contexts; 211 ActionList _modified; 256 /** Maps keys to the actions the are bound */ 257 QMap<QString, ActionList> m_KeyMap; 258 259 /** Dictionary of contexts (which contain actions) */ 260 QDict<Context> m_Contexts; 261 262 /** Modified actions */ 263 ActionList m_Modified; 264 265 /** map from action to the contexts it belongs to */ 266 QMap<QString, QStringList> m_Actions; 267 212 268 }; 213 269 214 270 #endif /* ACTIONSET_H */ -
mythcontrols/action.h
41 41 public: 42 42 43 43 /** 44 * @brief Create a new empty action. 44 * Create a new empty action. 45 * 45 46 * @param description The actions description. 46 47 */ 47 inline Action(const QString & description) : _description(description) {}48 inline Action(const QString & description) : m_Description(description) {} 48 49 49 50 /** 50 * @brief Create a new action. 51 * Create a new action. 52 * 51 53 * @param description The description of the action. 52 54 * @param keys The key sequence (strings) that trigger the action. 53 55 * … … 58 60 Action(const QString & description, const QString & keys); 59 61 60 62 /** 61 * @brief Get the action description. 63 * Get the action description. 64 * 62 65 * @return The action description. 63 66 */ 64 inline const QString & getDescription() const { return this->_description; } 67 inline const QString & GetDescription() const 68 { 69 return this->m_Description; 70 } 65 71 66 72 /** 67 * @brief Get the key sequence(s) that trigger this action. 73 * Get the key sequence(s) that trigger this action. 74 * 68 75 * @return The key sequence(s) that trigger this action. 69 76 */ 70 inline const QStringList & getKeys() const { return this->_keys; } 77 inline const QStringList & GetKeys() const 78 { 79 return this->m_Keys; 80 } 71 81 72 82 /** 73 * @brief Get the keys as a string. 83 * Get the keys as a string. 84 * 74 85 * @return QString::null or a comma delimited string of keys. 75 86 */ 76 inline QString keyString() const { return _keys.join(","); } 87 inline QString KeyString() const 88 { 89 return m_Keys.join(","); 90 } 77 91 78 92 /** 79 * @brief Add a key sequence to this action. 93 * Add a key sequence to this action. 94 * 80 95 * @param key The key to add to the action. 81 96 * @return true if the key was added otherwise, false. 82 97 */ 83 bool addKey(const QString & key);98 bool AddKey(const QString & key); 84 99 85 100 /** 86 * @brief Remove a key from this action. 101 * Remove a key from this action. 102 * 87 103 * @param key The key to remove. 88 104 * @return true if the key is removed, otherwise, false. 89 105 */ 90 inline bool removeKey(const QString & key) { return (keys().remove(key)>0); } 106 inline bool RemoveKey(const QString & key) 107 { 108 return (m_Keys.remove(key)>0); 109 } 91 110 92 111 /** 93 * @brief Replace a key. 112 * Replace a key. 113 * 94 114 * @param newkey The new key. 95 115 * @param oldkey The old key, which is being replaced. 96 116 */ 97 bool replaceKey(const QString & newkey, const QString & oldkey);117 bool ReplaceKey(const QString & newkey, const QString & oldkey); 98 118 99 119 /** 100 * @brief Determine if the action already has a key. 120 * Determine if the action already has a key. 121 * 101 122 * @param key The key to check for. 102 123 * @return true if the key is already bound in this action, 103 124 * otherwise, false is returned. 104 125 */ 105 bool hasKey(const QString & key) const;126 bool HasKey(const QString & key) const; 106 127 107 128 /** 108 * @brief Get the index of a key. 109 * @param key The string containing the key. 110 * @return The index of the key, which will be less than zero if the 111 * key does not exist. 112 */ 113 114 /** 115 * @brief Determine if the action has any keys at all. 129 * Determine if the action has any keys at all. 130 * 116 131 * @return true if the action has keys, otherwise, false. 117 132 */ 118 inline bool empty(void) const { return (_keys.size() > 0); } 133 inline bool IsEmpty(void) const 134 { 135 return (m_Keys.size() > 0); 136 } 119 137 120 /** @briefThe maximum number of keys that can be bound to an action. */138 /** The maximum number of keys that can be bound to an action. */ 121 139 static const unsigned short MAX_KEYS = 4; 122 140 123 pr otected:141 private: 124 142 125 /** 126 * @brief Get a reference to the action description. 127 * @return A reference to the action description. 128 */ 129 inline QString & description() { return this->_description; } 143 /** The actions description. */ 144 QString m_Description; 130 145 131 /** 132 * @brief Get a reference to actions the key sequences. 133 * @return A reference to actions the key sequences. 134 */ 135 inline QStringList & keys() { return this->_keys; } 136 137 private: 138 139 QString _description; 140 QStringList _keys; 146 /** The keys bound to the action. */ 147 QStringList m_Keys; 141 148 }; 142 149 143 150 #endif /* ACTION_H */ -
mythcontrols/mythcontrols.cpp
29 29 #ifndef MYTHCONTROLS_CPP 30 30 #define MYTHCONTROLS_CPP 31 31 32 /* QT includes */33 32 #include <qnamespace.h> 34 33 #include <qstringlist.h> 35 34 #include <qapplication.h> 36 35 #include <qbuttongroup.h> 37 38 /* MythTV includes */39 36 #include <mythtv/mythcontext.h> 40 37 #include <mythtv/mythdialogs.h> 41 38 … … 54 51 return key; 55 52 } 56 53 57 static const QString DisplayToKey(const QString key)58 {59 if (key.left(1) == "[" && key != "[")60 return "remote" + key.mid(1,key.length()-2);61 else62 return key;63 }64 54 65 55 /* comments in header */ 66 56 MythControls::MythControls (MythMainWindow *parent, bool& ui_ok) 67 57 :MythThemedDialog(parent, "controls", "controls-", "controls") 68 58 { 69 59 /* Nullify keybindings so the deconstructor knows not to delete it */ 70 this-> key_bindings = NULL;60 this->m_KeyBindings = NULL; 71 61 72 /* delete the contents when we're done */ 73 m_contexts.setAutoDelete(true); 74 62 this->m_View = ActionsByContext; 63 75 64 /* load up the ui components */ 76 if ((ui_ok = loadUI()))65 if ((ui_ok = LoadUI())) 77 66 { 78 leftType = kContextList;79 rightType = kActionList;80 81 67 /* for starters, load this host */ 82 loadHost(gContext->GetHostName());68 m_KeyBindings = new KeyBindings(gContext->GetHostName()); 83 69 84 70 /* update the information */ 85 refreshKeyInformation(); 71 SetView(ActionsByContext, true); 72 RefreshInformation(); 86 73 87 74 /* capture the signals we want */ 88 connect(LeftList, SIGNAL(itemSelected(UIListBtnTypeItem*)), 89 this, SLOT(leftSelected(UIListBtnTypeItem*))); 90 connect(RightList, SIGNAL(itemSelected(UIListBtnTypeItem*)), 91 this, SLOT(rightSelected(UIListBtnTypeItem*))); 92 75 connect(m_LeftList, SIGNAL(itemSelected(UIListBtnTypeItem*)), 76 this, SLOT(LeftSelected(UIListBtnTypeItem*))); 77 connect(m_RightList, SIGNAL(itemSelected(UIListBtnTypeItem*)), 78 this, SLOT(RightSelected(UIListBtnTypeItem*))); 93 79 } 94 80 } 95 81 96 82 97 83 98 84 /* comments in header */ 99 MythControls::~MythControls() { delete this->key_bindings; } 85 MythControls::~MythControls() 86 { 87 delete this->m_KeyBindings; 88 } 100 89 101 90 102 91 103 92 /* comments in header */ 104 bool MythControls:: loadUI()93 bool MythControls::LoadUI() 105 94 { 106 95 /* the return value of the method */ 107 96 bool retval = true; 108 97 109 98 /* Get the UI widgets that we need to work with */ 110 if (( description = getUITextType("description")) == NULL)99 if ((m_Description = getUITextType("description")) == NULL) 111 100 { 112 101 VERBOSE(VB_IMPORTANT, "MythControls: Unable to load action_description"); 113 102 retval = false; 114 103 } 115 104 116 if ((container = getContainer("controls")) == NULL) { 105 if ((m_Container = getContainer("controls")) == NULL) 106 { 117 107 VERBOSE(VB_IMPORTANT, "MythControls: No controls container in theme"); 118 108 retval = false; 119 109 } 120 else if ((LeftList = getUIListBtnType("leftlist")) == NULL) { 110 else if ((m_LeftList = getUIListBtnType("leftlist")) == NULL) 111 { 121 112 VERBOSE(VB_IMPORTANT, "MythControls: No leftlist in theme"); 122 113 retval = false; 123 114 } 124 else if ((RightList = getUIListBtnType("rightlist")) == NULL) { 115 else if ((m_RightList = getUIListBtnType("rightlist")) == NULL) 116 { 125 117 VERBOSE(VB_IMPORTANT, "MythControls: No rightList in theme"); 126 118 retval = false; 127 119 } 128 else {129 LeftDesc = getUITextType("leftdesc");130 RightDesc = getUITextType("rightdesc");131 /* focus the context list by default */132 focused =LeftList;133 LeftList->calculateScreenArea();134 LeftList->SetActive(true);135 RightList->calculateScreenArea();136 RightList->SetActive(false);120 else 121 { 122 m_LeftDesc = getUITextType("leftdesc"); 123 m_RightDesc = getUITextType("rightdesc"); 124 m_Focused = m_LeftList; 125 m_LeftList->calculateScreenArea(); 126 m_LeftList->SetActive(true); 127 m_RightList->calculateScreenArea(); 128 m_RightList->SetActive(false); 137 129 } 138 130 139 131 /* Check that all the buttons are there */ 140 if (( ActionButtons[0] = getUITextButtonType("action_one")) == NULL)132 if ((m_ActionButtons[0] = getUITextButtonType("action_one")) == NULL) 141 133 { 142 VERBOSE(VB_IMPORTANT, "MythControls: Unable to load first action button"); 134 VERBOSE(VB_IMPORTANT, 135 "MythControls: Unable to load first action button"); 143 136 retval = false; 144 137 } 145 else if (( ActionButtons[1] = getUITextButtonType("action_two")) == NULL)138 else if ((m_ActionButtons[1] = getUITextButtonType("action_two")) == NULL) 146 139 { 147 VERBOSE(VB_IMPORTANT, "MythControls: Unable to load second action button"); 140 VERBOSE(VB_IMPORTANT, 141 "MythControls: Unable to load second action button"); 148 142 retval = false; 149 143 } 150 else if (( ActionButtons[2] = getUITextButtonType("action_three")) == NULL)144 else if ((m_ActionButtons[2] = getUITextButtonType("action_three")) == NULL) 151 145 { 152 VERBOSE(VB_IMPORTANT, "MythControls: Unable to load thrid action button"); 146 VERBOSE(VB_IMPORTANT, 147 "MythControls: Unable to load thrid action button"); 153 148 retval = false; 154 149 } 155 else if (( ActionButtons[3] = getUITextButtonType("action_four")) == NULL)150 else if ((m_ActionButtons[3] = getUITextButtonType("action_four")) == NULL) 156 151 { 157 VERBOSE(VB_IMPORTANT, "MythControls: Unable to load fourth action button"); 152 VERBOSE(VB_IMPORTANT, 153 "MythControls: Unable to load fourth action button"); 158 154 retval = false; 159 155 } 160 156 … … 162 158 } 163 159 164 160 161 void MythControls::ShowButtons(bool shown) const 162 { 163 for (size_t i = 0; i < Action::MAX_KEYS; i++) 164 shown ? m_ActionButtons[i]->show() : m_ActionButtons[i]->hide(); 165 } 165 166 166 /* comments in header */ 167 size_t MythControls::focusedButton(void) const 167 168 /* method description in mythcontrols.h */ 169 void MythControls::BlankButtons(void) const 168 170 { 169 171 for (size_t i = 0; i < Action::MAX_KEYS; i++) 170 if (focused == ActionButtons[i]) return i; 172 m_ActionButtons[i]->setText(""); 173 } 171 174 175 /* method description in mythcontrols.h */ 176 void MythControls::FillButtons(const QStringList & strings) 177 { 178 size_t i = 0, maxstr = Action::MAX_KEYS; 179 180 if (strings.count() < Action::MAX_KEYS) 181 maxstr = strings.count(); 182 183 /* fill existing keys */ 184 for (; i < maxstr; i++) 185 m_ActionButtons[i]->setText(KeyToDisplay(strings[i])); 186 187 /* blank the other ones */ 188 for (; i < Action::MAX_KEYS; i++) 189 m_ActionButtons[i]->setText(""); 190 } 191 192 /* comments in header */ 193 size_t MythControls::FocusedButton(void) const 194 { 195 for (size_t i = 0; i < Action::MAX_KEYS; i++) 196 { 197 if (m_Focused == m_ActionButtons[i]) 198 return i; 199 } 172 200 return Action::MAX_KEYS; 173 201 } 174 202 175 176 void MythControls::focusButton(int direction) 203 void MythControls::FocusButton(int direction) 177 204 { 178 if (leftType != kContextList || rightType != kActionList)179 return;180 205 if (direction == 0) 181 206 { 182 focused =ActionButtons[0];183 ActionButtons[0]->takeFocus();184 RightList->looseFocus();185 RightList->SetActive(false);207 m_Focused = m_ActionButtons[0]; 208 m_ActionButtons[0]->takeFocus(); 209 m_RightList->looseFocus(); 210 m_RightList->SetActive(false); 186 211 } 187 212 else 188 213 { 189 214 190 215 /* change focus by at most one in either direction */ 191 if (direction > 0) direction = 1; 192 else direction = -1; 216 if (direction > 0) 217 direction = 1; 218 else 219 direction = -1; 193 220 194 221 /* figure out which button is focused */ 195 222 int current = 0; 196 if (focused == ActionButtons[1]) current=1; 197 else if (focused == ActionButtons[2]) current = 2; 198 else if (focused == ActionButtons[3]) current = 3; 223 if (m_Focused == m_ActionButtons[1]) 224 current=1; 225 else if (m_Focused == m_ActionButtons[2]) 226 current = 2; 227 else if (m_Focused == m_ActionButtons[3]) 228 current = 3; 199 229 200 230 /* determine the new focused button index */ 201 231 int newb = current + direction; … … 203 233 /* focus an existing button */ 204 234 if ((newb >= 0) && (newb < Action::MAX_KEYS)) 205 235 { 206 focused->looseFocus();207 focused =ActionButtons[newb];208 focused->takeFocus();236 m_Focused->looseFocus(); 237 m_Focused = m_ActionButtons[newb]; 238 m_Focused->takeFocus(); 209 239 } 210 240 } 211 241 } 212 242 213 243 214 244 215 void MythControls:: switchListFocus(UIListBtnType *focus, UIListBtnType *unfocus)245 void MythControls::SwitchListFocus(UIListBtnType *focus, UIListBtnType *unfocus) 216 246 { 217 247 /* unfocus a list (setactive(false)) or a button (focused->looseFocus) */ 218 248 if (unfocus) 219 249 unfocus->SetActive(false); 220 250 221 focused->looseFocus();222 focused = focus;251 m_Focused->looseFocus(); 252 m_Focused = focus; 223 253 focus->SetActive(true); 224 254 focus->takeFocus(); 225 refreshKeyInformation();255 RefreshInformation(); 226 256 } 227 257 258 /* method description in mythcontrols.h */ 259 void MythControls::SetView(ViewMode newview, bool force) 260 { 261 QStringList *lstrings = NULL, *rstrings = NULL; 262 263 /* Dont set the view to what is already is */ 264 if ((newview == m_View) && (force == false)) 265 return; 266 267 m_Focused->looseFocus(); 268 m_Focused = m_LeftList; 269 m_LeftList->takeFocus(); 270 271 m_View = newview; 272 273 switch (newview) 274 { 275 case ActionsByContext: 276 this->ShowButtons(true); 277 m_LeftDesc->SetText(tr("Contexts")); 278 m_RightDesc->SetText(tr("Actions")); 279 lstrings = m_KeyBindings->GetContexts(); 280 rstrings = m_KeyBindings->GetActions((*lstrings)[0]); 281 break; 282 case ActionsByKey: 283 this->ShowButtons(false); 284 m_LeftDesc->SetText(tr("Keys")); 285 m_RightDesc->SetText(tr("Actions")); 286 lstrings = m_KeyBindings->GetAllKeys(); 287 rstrings = m_KeyBindings->GetKeyActions((*lstrings)[0]); 288 break; 289 case ContextsByKey: 290 this->ShowButtons(false); 291 m_LeftDesc->SetText(tr("Keys")); 292 m_RightDesc->SetText(tr("Contexts")); 293 lstrings = m_KeyBindings->GetAllKeys(); 294 rstrings = m_KeyBindings->GetContexts((*lstrings)[0]); 295 break; 296 } 297 298 /* refresh the keys on the left */ 299 if (lstrings != NULL) 300 { 301 RefreshLeft(lstrings); 302 delete lstrings; 303 } 304 305 /* refresh the keys on the right */ 306 if (rstrings != NULL) 307 { 308 RefreshRight(rstrings); 309 delete rstrings; 310 } 311 } 312 228 313 void MythControls::keyPressEvent(QKeyEvent *e) 229 314 { 230 315 bool handled = false; … … 239 324 240 325 if (action == "MENU" || action == "INFO") 241 326 { 242 focused->looseFocus();327 m_Focused->looseFocus(); 243 328 OptionsMenu popup(gContext->GetMainWindow()); 244 329 int a = (int)popup.getOption(); 245 switch (a) { 330 switch (a) 331 { 246 332 case (int)OptionsMenu::SAVE: 247 save();333 Save(); 248 334 break; 249 335 } 250 focused->takeFocus(); 251 // if (popup.getOption() == OptionsMenu::SAVE) save(); 336 m_Focused->takeFocus(); 252 337 } 253 338 else if (action == "SELECT") 254 339 { 255 if ( focused ==LeftList)256 switchListFocus(RightList,LeftList);257 else if ( focused == RightList)258 focusButton(0);259 else {260 QString key = getCurrentKey();261 if (!key.isEmpty())340 if (m_Focused == m_LeftList) 341 SwitchListFocus(m_RightList, m_LeftList); 342 else if (m_View == ActionsByContext) 343 { 344 if (m_Focused == m_RightList) 345 FocusButton(0); 346 else 262 347 { 263 ActionMenu popup(gContext->GetMainWindow()); 264 int result = popup.getOption(); 265 if (result == ActionMenu::SET) addKeyToAction(); 266 else if (result == ActionMenu::REMOVE) deleteKey(); 267 } else // for blank keys, no reason to ask what to do 268 addKeyToAction(); 348 QString key = GetCurrentKey(); 349 if (!key.isEmpty()) 350 { 351 ActionMenu popup(gContext->GetMainWindow()); 352 int result = popup.getOption(); 353 if (result == ActionMenu::SET) 354 AddKeyToAction(); 355 else if (result == ActionMenu::REMOVE) 356 DeleteKey(); 357 } 358 else // for blank keys, no reason to ask what to do 359 AddKeyToAction(); 360 } 269 361 } 270 362 } 271 363 else if (action == "ESCAPE") 272 364 { 273 365 escape = true; 274 if ( focused ==LeftList)366 if (m_Focused == m_LeftList) 275 367 { 276 368 handled = false; 277 if ( key_bindings->hasChanges())369 if (m_KeyBindings->HasChanges()) 278 370 { 279 371 /* prompt user to save changes */ 280 372 UnsavedMenu popup(gContext->GetMainWindow()); 281 373 if (popup.getOption() == UnsavedMenu::SAVE) 282 374 { 283 save();375 Save(); 284 376 } 285 377 } 286 378 } 287 else if ( focused ==RightList)288 switchListFocus(LeftList,RightList);379 else if (m_Focused == m_RightList) 380 SwitchListFocus(m_LeftList, m_RightList); 289 381 else 290 switchListFocus(RightList, NULL);382 SwitchListFocus(m_RightList, NULL); 291 383 } 292 384 else if (action == "UP") 293 385 { 294 if ( focused ==LeftList)295 LeftList->MoveUp();296 else if ( focused ==RightList)297 RightList->MoveUp();386 if (m_Focused == m_LeftList) 387 m_LeftList->MoveUp(); 388 else if (m_Focused == m_RightList) 389 m_RightList->MoveUp(); 298 390 } 299 391 else if (action == "DOWN") 300 392 { 301 if ( focused ==LeftList)302 LeftList->MoveDown();303 else if ( focused ==RightList)304 RightList->MoveDown();393 if (m_Focused == m_LeftList) 394 m_LeftList->MoveDown(); 395 else if (m_Focused == m_RightList) 396 m_RightList->MoveDown(); 305 397 } 306 398 else if (action == "LEFT") 307 399 { 308 if ( focused==RightList)309 switchListFocus(LeftList,RightList);310 else if ( focused !=LeftList)311 focusButton(-1);400 if (m_Focused==m_RightList) 401 SwitchListFocus(m_LeftList, m_RightList); 402 else if (m_Focused != m_LeftList) 403 FocusButton(-1); 312 404 } 313 405 else if (action == "RIGHT") 314 406 { 315 if ( focused ==LeftList)316 switchListFocus(RightList,LeftList);317 else if ( focused !=RightList)318 focusButton(1);407 if (m_Focused == m_LeftList) 408 SwitchListFocus(m_RightList, m_LeftList); 409 else if (m_Focused != m_RightList) 410 FocusButton(1); 319 411 } 320 412 else if (action == "PAGEUP") 321 413 { 322 if ( focused ==LeftList)323 LeftList->MoveUp(UIListBtnType::MovePage);324 else if ( focused ==RightList)325 RightList->MoveUp(UIListBtnType::MovePage);414 if (m_Focused == m_LeftList) 415 m_LeftList->MoveUp(UIListBtnType::MovePage); 416 else if (m_Focused == m_RightList) 417 m_RightList->MoveUp(UIListBtnType::MovePage); 326 418 } 327 419 else if (action == "PAGEDOWN") 328 420 { 329 if ( focused ==LeftList)330 LeftList->MoveDown(UIListBtnType::MovePage);331 else if ( focused ==RightList)332 RightList->MoveDown(UIListBtnType::MovePage);421 if (m_Focused == m_LeftList) 422 m_LeftList->MoveDown(UIListBtnType::MovePage); 423 else if (m_Focused == m_RightList) 424 m_RightList->MoveDown(UIListBtnType::MovePage); 333 425 } 334 426 else if (action == "1") 335 { 336 if (leftType != kContextList || rightType != kActionList) 337 { 338 leftType = kContextList; 339 rightType = kActionList; 340 updateLists(); 341 if (focused != LeftList) 342 switchListFocus(LeftList, 343 (focused == RightList) ? RightList : NULL); 344 } else handled = false; 345 } 427 SetView(ActionsByContext); 346 428 else if (action == "2") 347 { 348 if (leftType != kContextList || rightType != kKeyList) 349 { 350 leftType = kContextList; 351 rightType = kKeyList; 352 updateLists(); 353 if (focused != LeftList) 354 switchListFocus(LeftList, 355 (focused == RightList) ? RightList : NULL); 356 } else handled = false; 357 } 429 SetView(ActionsByKey); 358 430 else if (action == "3") 359 { 360 if (leftType != kKeyList || rightType != kContextList) 361 { 362 leftType = kKeyList; 363 rightType = kContextList; 364 updateLists(); 365 if (focused != LeftList) 366 switchListFocus(LeftList, 367 (focused == RightList) ? RightList : NULL); 368 } else handled = false; 369 } 370 else handled = false; 431 SetView(ContextsByKey); 432 else 433 handled = false; 371 434 } 372 435 373 if (handled) return; 436 if (handled) 437 return; 374 438 375 if (!escape && JumpTo(e)) handled = true; 439 if (!escape && JumpTo(e)) 440 handled = true; 376 441 377 442 if (!handled) 378 443 MythThemedDialog::keyPressEvent(e); … … 380 445 381 446 bool MythControls::JumpTo(QKeyEvent *e) 382 447 { 383 UIListBtnType *list = NULL; 384 if (focused == LeftList && leftType == kKeyList) list = LeftList; 385 if (focused == RightList && rightType == kKeyList) list = RightList; 386 if (!list) return false; 448 UIListBtnType *flist = NULL; 387 449 450 if (m_View != ActionsByContext) 451 { 452 if (m_Focused == m_LeftList) 453 flist = m_LeftList; 454 else 455 flist = m_RightList; 456 } 457 458 if (!flist) 459 return false; 460 388 461 QString key = e->text(); 389 if (key.left(6) == "remote") {462 if (key.left(6) == "remote") 390 463 key = KeyToDisplay(key); 391 } else { 464 else 465 { 392 466 key = QString(QKeySequence(e->key())); 393 467 if (key.isEmpty()) return false; 394 468 QString modifiers = ""; … … 401 475 402 476 UIListBtnTypeItem *b; 403 477 uint len = 1024; // infinity 404 if ( list ==RightList)478 if (flist == m_RightList) 405 479 { 406 480 key = key + " "; 407 481 len = key.length(); 408 482 } 409 483 410 for (b = list->GetItemFirst(); b; b = list->GetItemNext(b)) 411 if (b->text().left(len) == key) break; 412 if (!b) return false; 484 for (b = flist->GetItemFirst(); b; b = flist->GetItemNext(b)) 485 { 486 if (b->text().left(len) == key) 487 break; 488 } 489 if (!b) 490 return false; 413 491 414 int curpos = list->GetItemPos(list->GetItemCurrent());415 int newpos = list->GetItemPos(b);492 int curpos = flist->GetItemPos(flist->GetItemCurrent()); 493 int newpos = flist->GetItemPos(b); 416 494 417 495 if (newpos > curpos) 418 list->MoveDown(newpos - curpos);496 flist->MoveDown(newpos - curpos); 419 497 else if (newpos < curpos) 420 list->MoveUp(curpos - newpos);498 flist->MoveUp(curpos - newpos); 421 499 return true; 422 500 } 423 501 424 502 425 void MythControls:: leftSelected(UIListBtnTypeItem*)503 void MythControls::LeftSelected(UIListBtnTypeItem*) 426 504 { 427 LeftList->refresh(); 428 RightList->blockSignals(true); 429 refreshRightList(); 430 RightList->blockSignals(false); 431 RightList->refresh(); 505 m_LeftList->refresh(); 506 m_RightList->blockSignals(true); 507 RefreshRightList(); 508 m_RightList->blockSignals(false); 509 m_RightList->refresh(); 510 m_Description->SetText(""); 432 511 } 433 512 434 void MythControls:: rightSelected(UIListBtnTypeItem*)513 void MythControls::RightSelected(UIListBtnTypeItem*) 435 514 { 436 RightList->refresh();437 refreshKeyInformation();515 m_RightList->refresh(); 516 RefreshInformation(); 438 517 } 439 518 519 void MythControls::RefreshRight(QStringList * strings) 520 { 521 m_RightList->blockSignals(true); 522 m_RightList->Reset(); 440 523 524 strings->sort(); 441 525 526 for (size_t i = 0; i < strings->size(); i++) 527 { 528 UIListBtnTypeItem *item = new UIListBtnTypeItem(m_RightList,(*strings)[i]); 529 item->setDrawArrow(false); 530 } 531 532 m_RightList->blockSignals(false); 533 m_RightList->refresh(); 534 } 535 442 536 /* method description in header */ 443 void MythControls:: refreshRightList()537 void MythControls::RefreshLeft(QStringList * strings) 444 538 { 445 RightList->Reset(); 539 m_LeftList->blockSignals(true); 540 m_LeftList->Reset(); 446 541 447 if (LeftList->GetItemCurrent() == NULL)448 return;542 /* sort the strings */ 543 strings->sort(); 449 544 450 if (leftType == kContextList)545 for (size_t i = 0; i < strings->size(); i++) 451 546 { 452 if (rightType == kActionList) 453 { 454 /* add all of the actions to the context list */ 455 QString context = LeftList->GetItemCurrent()->text(); 456 QStringList *actions = m_contexts[context]; 457 if (actions == NULL) 458 { 459 VERBOSE(VB_IMPORTANT, QString("MythControls: Unable to find actions for context %1").arg(context)); 460 return; 461 } 462 UIListBtnTypeItem *item; 463 for (size_t i = 0; i < actions->size(); i++) 464 item = new UIListBtnTypeItem(RightList, (*actions)[i]); 465 } 466 else if (rightType == kKeyList) 467 { 468 /* add all of the actions to the context list */ 469 QString context = LeftList->GetItemCurrent()->text(); 470 BindingList *list = contextKeys[context]; 471 if (list == NULL) 472 { 473 VERBOSE(VB_IMPORTANT, QString("MythControls: Unable to find keys for context %1").arg(context)); 474 return; 475 } 476 UIListBtnTypeItem *item; 477 for (BindingList::iterator it = list->begin(); it != list->end(); ++it) 478 { 479 binding_t *b = *it; 480 item = new UIListBtnTypeItem(RightList, KeyToDisplay(b->key) + " => " + b->action); 481 } 482 } 483 } else if (leftType == kKeyList && rightType == kContextList) 484 { 485 QString key = DisplayToKey(LeftList->GetItemCurrent()->text()); 486 BindingList *list = keyActions[key]; 487 if (list == NULL) 488 { 489 VERBOSE(VB_IMPORTANT, QString("MythControls: Unable to find actions for key %1").arg(key)); 490 return; 491 } 492 UIListBtnTypeItem *item; 493 BindingList::iterator it = list->begin(); 494 binding_t *b = *it; 495 for (size_t i = 0; i < contexts.size(); i++) 496 { 497 QString context = contexts[i]; 498 QString action = "<none>"; 499 if (b && b->context == context) 500 { 501 action = b->action; 502 ++it; 503 if (it != list->end()) b = *it; 504 else b = NULL; 505 } 506 item = new UIListBtnTypeItem(RightList, context + " => " + action); 507 } 547 UIListBtnTypeItem *item = new UIListBtnTypeItem(m_LeftList, (*strings)[i]); 548 item->setDrawArrow(true); 508 549 } 550 551 m_LeftList->blockSignals(false); 552 m_LeftList->refresh(); 509 553 } 510 554 511 555 512 /* comments in header*/513 void MythControls:: refreshKeyInformation()556 /* method description in mythcontrols.h */ 557 void MythControls::RefreshRightList() 514 558 { 515 /* get the description of the current action */516 QString desc;559 QStringList *rstrings = NULL; 560 QString lstring = m_LeftList->GetItemCurrent()->text(); 517 561 518 if (focused == LeftList) 562 /* right list, based on values from the left */ 563 switch (m_View) 519 564 { 520 /* blank all keys on the context */ 521 for (size_t i = 0; i < Action::MAX_KEYS; i++) 522 ActionButtons[i]->setText(""); 565 case ActionsByContext: 566 this->ShowButtons(true); 567 rstrings = m_KeyBindings->GetActions(lstring); 568 break; 569 case ActionsByKey: 570 this->ShowButtons(false); 571 rstrings = m_KeyBindings->GetKeyActions(lstring); 572 break; 573 case ContextsByKey: 574 this->ShowButtons(false); 575 rstrings = m_KeyBindings->GetContexts(lstring); 576 break; 523 577 } 524 else if (leftType == kKeyList || rightType == kKeyList)525 { // Should show appropriate description526 QString action = getCurrentAction();527 QString context = getCurrentContext();528 /* blank all keys on the context */529 for (size_t i = 0; i < Action::MAX_KEYS; i++)530 ActionButtons[i]->setText("");531 if (!action.isEmpty())532 {533 534 desc = key_bindings->getActionDescription(context, action);535 536 BindingList *list = NULL;537 if (leftType == kKeyList && rightType == kContextList)538 {539 QString key = getCurrentKey();540 list = keyActions[DisplayToKey(key)];541 }542 else if (leftType == kContextList && rightType == kKeyList)543 list = contextKeys[context];544 if (list)545 {546 QString searchKey;547 if (rightType == kContextList)548 searchKey = context;549 else if (rightType == kActionList)550 searchKey = action;551 else if (rightType == kKeyList)552 searchKey = DisplayToKey(getCurrentKey());553 binding_t *binding = NULL;554 for (BindingList::iterator it = list->begin(); it != list->end(); ++it)555 {556 binding_t *b = *it;557 switch (rightType)558 {559 case kContextList:560 if (b->context == searchKey) binding = b;561 break;562 case kActionList:563 if (b->action == searchKey) binding = b;564 break;565 case kKeyList:566 if (b->key == searchKey) binding = b;567 break;568 }569 if (binding) break;570 }571 572 if (binding)573 {574 if (desc.isEmpty() && context != binding->contextFrom)575 desc = key_bindings->getActionDescription(binding->contextFrom, action);576 desc += "\n" + tr("Binding comes from %1 context")577 .arg(binding->contextFrom);578 }579 }580 }581 } else {582 QString context = getCurrentContext();583 QString action = getCurrentAction();584 /* set the description */585 desc = key_bindings->getActionDescription(getCurrentContext(),586 getCurrentAction());587 578 588 /* get the bindings of the current action */589 QStringList keys = key_bindings->getActionKeys(getCurrentContext(),590 getCurrentAction()); 579 RefreshRight(rstrings); 580 delete rstrings; 581 } 591 582 592 size_t i;593 583 594 /* fill existing keys */ 595 for (i = 0; i < keys.count(); i++) 596 ActionButtons[i]->setText(KeyToDisplay(keys[i])); 584 void MythControls::RefreshBindingInformation() 585 { 586 QString context = m_LeftList->GetItemCurrent()->text(); 587 QString action = m_RightList->GetItemCurrent()->text(); 588 QString desc = m_KeyBindings->GetActionDescription(GetCurrentContext(), 589 GetCurrentAction()); 597 590 598 /* blank the other ones */ 599 for (; i < Action::MAX_KEYS; i++) 600 ActionButtons[i]->setText(""); 601 } 591 /* get the bindings of the current action */ 592 QStringList keys = m_KeyBindings->GetActionKeys(GetCurrentContext(), 593 GetCurrentAction()); 602 594 603 /* set the information */ 604 description->SetText(desc); 595 FillButtons(keys); 596 597 m_Description->SetText(desc); 605 598 } 606 599 607 600 608 609 /* comments in header */ 610 QString MythControls::getCurrentContext(void) const 601 /* method description in mythcontrols.h */ 602 void MythControls::RefreshInformation() 611 603 { 612 if (leftType == kContextList) 613 return LeftList->GetItemCurrent()->text(); 614 if (focused == LeftList) return ""; 615 616 QString desc = RightList->GetItemCurrent()->text(); 617 int loc = desc.find(" => "); 618 if (loc == -1) return ""; // Should not happen 619 if (rightType == kContextList) return desc.left(loc); 620 else return desc.mid(loc+4); 604 switch (m_View) 605 { 606 case ActionsByContext: 607 if (m_Focused == m_LeftList) 608 { 609 BlankButtons(); 610 m_Description->SetText(""); 611 } 612 else 613 RefreshBindingInformation(); 614 break; 615 case ActionsByKey: 616 if (m_Focused == m_LeftList) 617 m_Description->SetText(""); 618 else 619 { 620 QString key = m_LeftList->GetItemCurrent()->text(); 621 QString action = m_RightList->GetItemCurrent()->text(); 622 int pos = m_RightList->GetItemPos(m_RightList->GetItemCurrent()); 623 QString context = m_KeyBindings->GetContext(key, action, pos); 624 QString desc = m_KeyBindings->GetActionDescription(context, action); 625 desc += "\n" + tr("Binding comes from %1 context").arg(context); 626 m_Description->SetText(desc); 627 } 628 break; 629 case ContextsByKey: 630 if (m_Focused == m_LeftList) 631 m_Description->SetText(""); 632 else 633 { 634 QString key = m_LeftList->GetItemCurrent()->text(); 635 QString context = m_RightList->GetItemCurrent()->text(); 636 QString action = m_KeyBindings->GetAction(key, context); 637 QString desc = action + ": " + 638 m_KeyBindings->GetActionDescription(context, action); 639 m_Description->SetText(desc); 640 } 641 break; 642 } 621 643 } 622 644 623 645 /* comments in header */ 624 QString MythControls:: getCurrentAction(void) const646 QString MythControls::GetCurrentContext(void) const 625 647 { 626 if (leftType == kActionList) 627 return LeftList->GetItemCurrent()->text(); 628 if (focused == LeftList) return ""; 629 630 QString desc = RightList->GetItemCurrent()->text(); 631 if (leftType == kContextList && rightType == kActionList) 632 return desc; 633 int loc = desc.find(" => "); 634 if (loc == -1) return ""; // Should not happen 635 if (rightType == kActionList) return desc.left(loc); 648 if (m_View == ActionsByContext) 649 return m_LeftList->GetItemCurrent()->text(); 650 else if ((m_View == ContextsByKey) && (m_Focused == m_RightList)) 651 return m_RightList->GetItemCurrent()->text(); 636 652 else 637 { 638 QString rv = desc.mid(loc+4); 639 if (rv == "<none>") return ""; 640 else return rv; 641 } 653 return ""; 642 654 } 643 655 644 656 /* comments in header */ 645 QString MythControls:: getCurrentKey(void) const657 QString MythControls::GetCurrentAction(void) const 646 658 { 647 if (leftType == kKeyList)648 return LeftList->GetItemCurrent()->text();649 if (focused == LeftList) return "";650 659 651 if (leftType == kContextList && rightType == kActionList) 652 { 653 QString context = getCurrentContext(); 654 QString action = getCurrentAction(); 655 size_t b = focusedButton(); 656 QStringList keys = key_bindings->getActionKeys(context, action); 657 if (b < keys.count()) return keys[b]; 658 else return ""; 659 } 660 661 QString desc = RightList->GetItemCurrent()->text(); 662 int loc = desc.find(" => "); 663 if (loc == -1) return ""; // Should not happen 664 if (rightType == kKeyList) return desc.left(loc); 665 else return desc.mid(loc+4); 660 if (((m_View == ActionsByContext) && (m_Focused != m_LeftList)) || 661 ((m_View == ActionsByKey) && (m_Focused == m_RightList))) 662 return m_RightList->GetItemCurrent()->text(); 663 else 664 return ""; 666 665 } 667 666 668 669 667 /* comments in header */ 670 void MythControls::loadHost(const QString & hostname) { 671 672 /* create the key bindings and the tree */ 673 key_bindings = new KeyBindings(hostname); 674 contexts = *key_bindings->getContexts(); 675 676 keys.clear(); 677 678 /* Alphabetic order, but jump and global at the top */ 679 contexts.sort(); 680 contexts.remove(JUMP_CONTEXT); 681 contexts.remove(GLOBAL_CONTEXT); 682 contexts.insert(contexts.begin(), 1, GLOBAL_CONTEXT); 683 contexts.insert(contexts.begin(), 1, JUMP_CONTEXT); 684 685 QStringList *actions; 686 for (size_t i = 0; i < contexts.size(); i++) 668 QString MythControls::GetCurrentKey(void) const 669 { 670 if (m_View == ActionsByContext) 687 671 { 688 actions = key_bindings->getActions(contexts[i]); 689 actions->sort(); 690 m_contexts.insert(contexts[i], actions); 672 QString context = GetCurrentContext(); 673 QString action = GetCurrentAction(); 674 size_t b = FocusedButton(); 675 QStringList keys = m_KeyBindings->GetActionKeys(context, action); 676 if (b < keys.count()) 677 return keys[b]; 678 else 679 return ""; 691 680 } 692 693 refreshKeyBindings(); 694 updateLists(); 681 else 682 return m_LeftList->GetItemCurrent()->text(); 695 683 } 696 684 697 698 699 685 /* comments in header */ 700 void MythControls:: deleteKey()686 void MythControls::DeleteKey() 701 687 { 702 688 // This code needs work to support deleteKey in any mode exc. Context/Action 703 QString context = getCurrentContext(); 704 QString key = getCurrentKey(); 705 QString action = getCurrentAction(); 689 QString context = GetCurrentContext(); 690 QString key = GetCurrentKey(); 691 QString action = GetCurrentAction(); 692 706 693 if (context.isEmpty() || key.isEmpty() || action.isEmpty()) 707 694 { 708 695 InvalidBindingPopup popup(gContext->GetMainWindow()); … … 710 697 return; 711 698 } 712 699 713 BindingList *list = keyActions[key]; 714 binding_t *binding = NULL; 715 for (BindingList::iterator it = list->begin(); it != list->end(); ++it) 700 if (m_View == ActionsByContext) 716 701 { 717 binding_t *b = *it; 718 if (b->context == context) binding = b; 702 QString trtext = 703 tr("Delete this key binding from context %1?").arg(context); 704 ConfirmMenu popup(gContext->GetMainWindow(), trtext); 705 if (popup.getOption() != ConfirmMenu::CONFIRM) 706 return; 707 else 708 { 709 m_KeyBindings->RemoveActionKey(context, action, key); 710 } 719 711 } 720 if (!binding)721 {722 InvalidBindingPopup popup(gContext->GetMainWindow());723 popup.getOption();724 return;725 }726 712 727 if (binding->contextFrom != context) 728 { 729 ConfirmMenu popup(gContext->GetMainWindow(), tr("Delete this key binding from context %1?").arg(binding->contextFrom)); 730 if (popup.getOption() != ConfirmMenu::CONFIRM) return; 731 } else { 732 ConfirmMenu popup(gContext->GetMainWindow(), tr("Delete this binding?")); 733 if (popup.getOption() != ConfirmMenu::CONFIRM) return; 734 } 735 736 if (!key_bindings->removeActionKey(binding->contextFrom, action, key)) 737 { 738 InvalidBindingPopup popup(gContext->GetMainWindow()); 739 popup.getOption(); 740 return; 741 } 742 743 // refreshing everything is overkill. I tried incrementally updating, but the 744 // code was ugly. Since this is quick in my experience, overkill away! 745 refreshKeyBindings(); 746 refreshKeyInformation(); 713 RefreshInformation(); 747 714 } 748 715 749 716 /* method description in header */ 750 bool MythControls:: resolveConflict(ActionID *conflict, int level)717 bool MythControls::ResolveConflict(ActionID *conflict, int level) 751 718 { 752 719 MythMainWindow *window = gContext->GetMainWindow(); 753 720 754 721 /* prevent a fatal binding */ 755 722 if (level == KeyBindings::Error) 756 723 { 757 InvalidBindingPopup popup(gContext->GetMainWindow(), 758 conflict->action(), 724 InvalidBindingPopup popup(gContext->GetMainWindow(), conflict->action(), 759 725 conflict->context()); 760 726 popup.getOption(); 761 727 return false; … … 778 744 779 745 780 746 /* method description in header */ 781 void MythControls:: addKeyToAction(void)747 void MythControls::AddKeyToAction(void) 782 748 { 783 // This code needs work to support deleteKey in any mode exc. Context/Action784 749 /* grab a key from the user */ 785 750 KeyGrabPopupBox *kg = new KeyGrabPopupBox(gContext->GetMainWindow()); 786 751 int result = kg->ExecPopup(kg,SLOT(cancel())); … … 788 753 delete kg; 789 754 790 755 /* go no further if canceled */ 791 if (result == 0) return; 756 if (result == 0) 757 return; 792 758 793 759 /* get the keys for the selected action */ 794 size_t b = focusedButton();795 QString action = getCurrentAction(), context = getCurrentContext();796 QStringList keys = key_bindings->getActionKeys(context, action);760 size_t b = FocusedButton(); 761 QString action = GetCurrentAction(), context = GetCurrentContext(); 762 QStringList keys = m_KeyBindings->GetActionKeys(context, action); 797 763 798 764 /* dont bother rebinding the same key */ 799 if (keys[b] == key) return; 765 if (keys[b] == key) 766 return; 800 767 801 768 bool bind = true; 802 769 int level; 803 770 804 771 /* get the potential conflict */ 805 772 ActionID *conflict = NULL; 806 if ((conflict = key_bindings->conflicts(context, key, level)))807 bind = resolveConflict(conflict, level);773 if ((conflict = m_KeyBindings->Conflicts(context, key, level))) 774 bind = ResolveConflict(conflict, level); 808 775 809 776 delete conflict; 810 777 811 778 /* dont bind if we shouldn't bind */ 812 if (!bind) return; 779 if (!bind) 780 return; 813 781 814 782 /* finally bind or rebind a key to the action */ 815 783 if (b < keys.count()) 816 key_bindings->replaceActionKey(context,action, key, keys[b]);784 m_KeyBindings->ReplaceActionKey(context,action, key, keys[b]); 817 785 else 818 key_bindings->addActionKey(context, action, key);786 m_KeyBindings->AddActionKey(context, action, key); 819 787 820 refreshKeyBindings(); 821 refreshKeyInformation(); 788 RefreshInformation(); 822 789 } 823 790 824 825 826 void MythControls::addBindings(QDict<binding_t> &bindings,827 const QString &context,828 const QString &contextParent, int bindlevel)829 {830 QStringList *actions = key_bindings->getActions(context);831 832 for (size_t i = 0; i < actions->size(); i++)833 {834 QString action = (*actions)[i];835 QStringList keys = key_bindings->getActionKeys(context, action);836 837 for (size_t j = 0; j < keys.size(); j++)838 {839 QString key = keys[j];840 841 binding_t *b = bindings.find(key);842 if (!b)843 {844 b = new(binding_t);845 b->key = key;846 b->action = action;847 b->context = contextParent;848 b->contextFrom = context;849 b->bindlevel = bindlevel;850 bindings.insert(key, b);851 }852 else if (b->bindlevel == bindlevel)853 {854 b->action += ", " + action;855 }856 }857 }858 }859 860 BindingList *MythControls::getKeyBindings(const QString &context)861 {862 QStringList keys;863 QDict<binding_t> bindings;864 bindings.clear();865 866 for (size_t i = 0; i < contexts.size(); i++)867 addBindings(bindings, contexts[i], context, i);868 869 870 for (QDictIterator<binding_t> it(bindings); it.current(); ++it)871 {872 QString key = it.currentKey();873 keys.append(key);874 }875 876 sortKeyList(keys);877 878 BindingList *retval = new BindingList;879 retval->clear();880 881 for (QStringList::Iterator kit = keys.begin(); kit != keys.end(); ++kit)882 {883 QString key = *kit;884 retval->append(bindings[key]);885 }886 retval->setAutoDelete(true);887 return retval;888 }889 890 void MythControls::refreshKeyBindings()891 {892 contextKeys.clear();893 keyActions.clear();894 for (size_t i = 0; i < contexts.size(); i++)895 {896 QString context = contexts[i];897 BindingList *list = getKeyBindings(context);898 contextKeys.insert(context, list);899 for (BindingList::iterator it = list->begin(); it != list->end(); ++it)900 {901 binding_t *b = *it;902 BindingList *list = keyActions.find(b->key);903 if (!list)904 {905 list = new BindingList;906 list->clear();907 keyActions.insert(b->key, list);908 }909 keys.append(b->key);910 list->append(b);911 }912 }913 contextKeys.setAutoDelete(true);914 keyActions.setAutoDelete(true);915 916 sortKeyList(keys);917 }918 919 void MythControls::sortKeyList(QStringList &keys)920 {921 QStringList t;922 t.clear();923 924 for ( QStringList::Iterator it = keys.begin(); it != keys.end(); ++it )925 {926 QString key = *it;927 928 QString keydesc = "3 ";929 if (key.left(6) == "remote")930 {931 keydesc = "0 ";932 }933 else if (key.length() == 1)934 {935 switch (key[0].category())936 {937 case QChar::Letter_Uppercase:938 keydesc = "2 ";939 break;940 case QChar::Number_DecimalDigit:941 keydesc = "1 ";942 break;943 default:944 keydesc = "5 ";945 break;946 }947 }948 else if (key.find("+", 1) != -1)949 keydesc = "4 ";950 951 t.push_back(keydesc + key);952 }953 t.sort();954 955 QString prev = "";956 957 keys.clear();958 for (QStringList::Iterator kit = t.begin(); kit != t.end(); ++kit)959 {960 QString cur = (*kit).mid(2);961 if (cur != prev)962 {963 keys.append(cur);964 prev = cur;965 }966 }967 }968 969 QString MythControls::getTypeDesc(ListType type)970 {971 switch (type)972 {973 case kContextList:974 return tr("Contexts");975 break;976 case kKeyList:977 return tr("Keys");978 break;979 case kActionList:980 return tr("Actions");981 break;982 default:983 return "";984 }985 }986 987 void MythControls::updateLists()988 {989 RightList->blockSignals(true);990 LeftList->blockSignals(true);991 LeftList->Reset();992 if (leftType == kContextList)993 {994 UIListBtnTypeItem *item;995 for (size_t i = 0; i < contexts.size(); i++)996 {997 item = new UIListBtnTypeItem(LeftList, contexts[i]);998 item->setDrawArrow(true);999 }1000 } else if (leftType == kKeyList)1001 {1002 UIListBtnTypeItem *item;1003 for (size_t i = 0; i < keys.size(); i++)1004 {1005 QString key = KeyToDisplay(keys[i]);1006 item = new UIListBtnTypeItem(LeftList, key);1007 item->setDrawArrow(true);1008 }1009 }1010 refreshRightList();1011 RightList->blockSignals(false);1012 LeftList->blockSignals(false);1013 LeftList->refresh();1014 RightList->refresh();1015 1016 if (LeftDesc != NULL)1017 LeftDesc->SetText(getTypeDesc(leftType));1018 if (RightDesc != NULL)1019 RightDesc->SetText(getTypeDesc(rightType));1020 }1021 1022 1023 791 #endif /* MYTHCONTROLS_CPP */ 1024 792 1025 793 /* vim: set expandtab tabstop=4 shiftwidth=4: */ -
mythcontrols/keybindings.cpp
26 26 * and the UI. 27 27 */ 28 28 29 /* QT */30 29 #include <qstring.h> 31 32 /* MythTV */33 30 #include <mythtv/mythcontext.h> 34 31 #include <mythtv/mythdialogs.h> 35 32 … … 38 35 #include "keybindings.h" 39 36 40 37 41 42 38 KeyBindings::KeyBindings(const QString & hostname) 43 39 { 44 this->hostname()= hostname;45 loadManditoryBindings();40 m_HostName = hostname; 41 LoadMandatoryBindings(); 46 42 47 retrieveContexts();48 retrieveJumppoints();43 RetrieveContexts(); 44 RetrieveJumppoints(); 49 45 } 50 46 47 QStringList * KeyBindings::GetKeyActions(const QString &key) const 48 { 49 QStringList *strings; 50 const ActionList & al = m_ActionSet.GetActions(key); 51 51 52 if (al.size() > 0) 53 strings = new QStringList(); 54 else 55 return NULL; 52 56 53 ActionID * KeyBindings::conflicts(const QString & context_name, 57 for (size_t i = 0; i < al.size(); i++) 58 strings->push_back(al[i].action()); 59 60 return strings; 61 } 62 63 64 QString KeyBindings::GetContext(const QString & key, const QString & action, 65 size_t anum) const 66 { 67 /* The cases where unknown is returned should never happen. If 68 * you see an unknown context, do not approach it. Call the 69 * police immediatly. */ 70 const ActionList &al = m_ActionSet.GetActions(key); 71 int offset = al.size() - anum; 72 73 if (offset < 0) 74 return "UNKNOWN"; 75 else if (al[anum].action() != action) 76 return "UNKNOWN"; 77 if (anum < al.size()) 78 return al[anum].context(); 79 else 80 return "UNKNOWN"; 81 } 82 83 QString KeyBindings::GetAction(const QString & key, 84 const QString & context) const 85 { 86 const ActionList &al = m_ActionSet.GetActions(key); 87 88 for (size_t i = 0; i < al.size(); i++) 89 { 90 if (al[i].context() == context) 91 return al[i].action(); 92 } 93 return "UNKNOWN"; 94 } 95 96 97 ActionID * KeyBindings::Conflicts(const QString & context_name, 54 98 const QString & key, int &level) const 55 99 { 56 const ActionList &ids = actionset.getActions(key);100 const ActionList &ids = m_ActionSet.GetActions(key); 57 101 58 102 /* trying to bind a jumppoint to an already bound key */ 59 103 if ((context_name == JUMP_CONTEXT) && (ids.count() > 0)) … … 84 128 85 129 86 130 /* method description in header */ 87 bool KeyBindings:: removeActionKey(const QString & context_name,131 bool KeyBindings::RemoveActionKey(const QString & context_name, 88 132 const QString & action_name, 89 133 const QString & key) 90 134 { 91 135 92 136 ActionID id(context_name, action_name); 93 137 94 /* dont remove the last manditory binding */ 95 if (getManditoryBindings().contains(id)&&(actionset.getKeys(id).count()<2)) 138 /* dont remove the last mandatory binding */ 139 if (getMandatoryBindings().contains(id) && 140 (m_ActionSet.GetKeys(id).count()<2)) 96 141 return false; 97 142 else 98 return this-> actionset.remove(id,key);143 return this->m_ActionSet.Remove(id,key); 99 144 } 100 145 101 146 102 147 103 148 /* method description in header */ 104 void KeyBindings:: commitAction(const ActionID & id)149 void KeyBindings::CommitAction(const ActionID & id) 105 150 { 106 151 107 152 MSqlQuery query(MSqlQuery::InitCon()); … … 112 157 113 158 if (query.isConnected()) 114 159 { 115 QString keys = actionset.keyString(id);116 query.bindValue(":HOSTNAME", this->getHostname());160 QString keys = m_ActionSet.KeyString(id); 161 query.bindValue(":HOSTNAME", m_HostName); 117 162 query.bindValue(":CONTEXT", id.context()); 118 163 query.bindValue(":ACTION", id.action()); 119 164 query.bindValue(":KEYLIST", keys); … … 131 176 132 177 133 178 134 void KeyBindings:: commitJumppoint(const ActionID &id)179 void KeyBindings::CommitJumppoint(const ActionID &id) 135 180 { 136 181 137 182 MSqlQuery query(MSqlQuery::InitCon()); … … 142 187 143 188 if (query.isConnected()) 144 189 { 145 QString keys = actionset.keyString(id);146 query.bindValue(":HOSTNAME", this-> getHostname());190 QString keys = m_ActionSet.KeyString(id); 191 query.bindValue(":HOSTNAME", this->m_HostName); 147 192 query.bindValue(":DESTINATION", id.action()); 148 193 query.bindValue(":KEYLIST", keys); 149 194 … … 161 206 162 207 163 208 164 void KeyBindings:: commitChanges(void)209 void KeyBindings::CommitChanges(void) 165 210 { 166 ActionList modified = actionset.getModified();211 ActionList modified = m_ActionSet.GetModified(); 167 212 168 213 while (modified.size() > 0) 169 214 { 170 215 ActionID id = modified.front(); 171 216 172 217 /* commit either a jumppoint or an action */ 173 if (id.context() == JUMP_CONTEXT) commitJumppoint(id); 174 else commitAction(id); 218 if (id.context() == JUMP_CONTEXT) 219 CommitJumppoint(id); 220 else 221 CommitAction(id); 175 222 176 223 /* tell the action set that the action is no longer modified */ 177 actionset.unmodify(id);224 m_ActionSet.Unmodify(id); 178 225 179 226 modified.pop_front(); 180 227 } … … 182 229 183 230 184 231 185 void KeyBindings:: retrieveJumppoints()232 void KeyBindings::RetrieveJumppoints() 186 233 { 187 234 MSqlQuery query(MSqlQuery::InitCon()); 188 235 … … 192 239 "FROM jumppoints " 193 240 "WHERE hostname = :HOSTNAME " 194 241 "ORDER BY destination ;"); 195 query.bindValue(":HOSTNAME", this->getHostname());242 query.bindValue(":HOSTNAME", m_HostName); 196 243 } 197 244 198 245 query.exec(); … … 202 249 ActionID id(JUMP_CONTEXT, query.value(0).toString()); 203 250 204 251 if (query.value(1).toString().isEmpty()) 205 { 206 actionset.addAction(id, query.value(0).toString(), 207 query.value(2).toString()); 208 } 209 else actionset.addAction(id,query.value(1).toString(), 210 query.value(2).toString()); 252 m_ActionSet.AddAction(id, query.value(0).toString(), 253 query.value(2).toString()); 254 else 255 m_ActionSet.AddAction(id,query.value(1).toString(), 256 query.value(2).toString()); 211 257 } 212 258 } 213 259 214 260 215 261 216 void KeyBindings:: retrieveContexts()262 void KeyBindings::RetrieveContexts() 217 263 { 218 264 219 265 MSqlQuery query(MSqlQuery::InitCon()); … … 225 271 "WHERE hostname = :HOSTNAME " 226 272 "ORDER BY context,action ;"); 227 273 228 query.bindValue(":HOSTNAME", this-> getHostname());274 query.bindValue(":HOSTNAME", this->m_HostName); 229 275 } 230 276 231 277 query.exec(); … … 233 279 for (query.next(); query.isValid(); query.next()) 234 280 { 235 281 ActionID id(query.value(0).toString(), query.value(1).toString()); 236 this-> actionset.addAction(id, query.value(2).toString(),237 query.value(3).toString());282 this->m_ActionSet.AddAction(id, query.value(2).toString(), 283 query.value(3).toString()); 238 284 } 239 285 } 240 286 241 287 242 288 243 void KeyBindings:: loadManditoryBindings(void)289 void KeyBindings::LoadMandatoryBindings(void) 244 290 { 245 if ( getManditoryBindings().empty())291 if (m_MandatoryBindings.empty()) 246 292 { 247 m anditoryBindings().append(ActionID(GLOBAL_CONTEXT, "DOWN"));248 defaultKeys().append("Down");293 m_MandatoryBindings.append(ActionID(GLOBAL_CONTEXT, "DOWN")); 294 m_DefaultKeys.append("Down"); 249 295 250 m anditoryBindings().append(ActionID(GLOBAL_CONTEXT, "UP"));251 defaultKeys().append("Up");296 m_MandatoryBindings.append(ActionID(GLOBAL_CONTEXT, "UP")); 297 m_DefaultKeys.append("Up"); 252 298 253 m anditoryBindings().append(ActionID(GLOBAL_CONTEXT, "LEFT"));254 defaultKeys().append("Left");299 m_MandatoryBindings.append(ActionID(GLOBAL_CONTEXT, "LEFT")); 300 m_DefaultKeys.append("Left"); 255 301 256 m anditoryBindings().append(ActionID(GLOBAL_CONTEXT, "RIGHT"));257 defaultKeys().append("Right");302 m_MandatoryBindings.append(ActionID(GLOBAL_CONTEXT, "RIGHT")); 303 m_DefaultKeys.append("Right"); 258 304 259 m anditoryBindings().append(ActionID(GLOBAL_CONTEXT, "ESCAPE"));260 defaultKeys().append("Esc");305 m_MandatoryBindings.append(ActionID(GLOBAL_CONTEXT, "ESCAPE")); 306 m_DefaultKeys.append("Esc"); 261 307 262 m anditoryBindings().append(ActionID(GLOBAL_CONTEXT, "SELECT"));263 defaultKeys().append("Return,Enter,Space");308 m_MandatoryBindings.append(ActionID(GLOBAL_CONTEXT, "SELECT")); 309 m_DefaultKeys.append("Return,Enter,Space"); 264 310 } 265 311 } 266 312 267 313 268 314 269 bool KeyBindings:: hasManditoryBindings(void) const315 bool KeyBindings::HasMandatoryBindings(void) const 270 316 { 271 ActionList manlist = getMand itoryBindings();317 ActionList manlist = getMandatoryBindings(); 272 318 for (size_t i = 0; i < manlist.count(); i++) 273 319 { 274 if ( actionset.getKeys(manlist[i]).isEmpty())320 if (m_ActionSet.GetKeys(manlist[i]).isEmpty()) 275 321 return false; 276 322 } 277 323 -
mythcontrols/actionset.cpp
36 36 37 37 38 38 /* method description in header */ 39 bool ActionSet:: add(const ActionID &id, const QString &key)39 bool ActionSet::Add(const ActionID &id, const QString &key) 40 40 { 41 41 Action *a; 42 42 43 43 /* get the action; make sure it exists before doing anything */ 44 if ((a = this-> action(id)))44 if ((a = this->GetAction(id))) 45 45 { 46 46 47 47 /* if the key was added, mark this action as modified, and 48 48 update the key map */ 49 if (a-> addKey(key))49 if (a->AddKey(key)) 50 50 { 51 ActionList &ids = _keymap[key];51 ActionList &ids = m_KeyMap[key]; 52 52 ids.push_back(id); 53 this-> modify(id);53 this->Modify(id); 54 54 return true; 55 55 } 56 56 } … … 61 61 62 62 63 63 /* method description in header */ 64 bool ActionSet:: remove(const ActionID &id, const QString & key)64 bool ActionSet::Remove(const ActionID &id, const QString & key) 65 65 { 66 66 67 67 Action *a; 68 68 69 69 /* make sure an action exists before removing */ 70 if ((a = this-> action(id)))70 if ((a = this->GetAction(id))) 71 71 { 72 72 /* if the key was removed from the action, then remove it from 73 73 * the key list, and mark the action id as modified */ 74 if (a-> removeKey(key))74 if (a->RemoveKey(key)) 75 75 { 76 76 /* remove the action from the key map */ 77 this-> _keymap[key].remove(id);77 this->m_KeyMap[key].remove(id); 78 78 79 79 /* mark the action as modified */ 80 this-> modify(id);80 this->Modify(id); 81 81 82 82 return true; 83 83 } … … 90 90 91 91 92 92 /* method description in header */ 93 bool ActionSet:: replace(const ActionID &id, const QString &newkey,93 bool ActionSet::Replace(const ActionID &id, const QString &newkey, 94 94 const QString &oldkey) 95 95 { 96 96 Action *a; 97 97 98 98 /* make sure an action exists before replacing */ 99 if ((a = this-> action(id)))99 if ((a = this->GetAction(id))) 100 100 { 101 101 102 102 /* make sure the key was actually replaced before modifying */ 103 if (a-> replaceKey(newkey, oldkey))103 if (a->ReplaceKey(newkey, oldkey)) 104 104 { 105 105 /* remove the action from the old key */ 106 this-> _keymap[oldkey].remove(id);106 this->m_KeyMap[oldkey].remove(id); 107 107 108 108 /* add the action to the new key */ 109 this-> _keymap[newkey].push_back(id);109 this->m_KeyMap[newkey].push_back(id); 110 110 111 111 /* mark the action as modified */ 112 this-> modify(id);112 this->Modify(id); 113 113 114 114 /* the job is done, return true */ 115 115 return true; … … 123 123 124 124 125 125 /* method description in header */ 126 QStringList * ActionSet:: contextStrings(void) const126 QStringList * ActionSet::ContextStrings(void) const 127 127 { 128 128 QStringList *context_strings = new QStringList(); 129 QDictIterator<Context> it( _contexts);129 QDictIterator<Context> it(m_Contexts); 130 130 131 131 for (; it.current(); ++it) 132 132 context_strings->append(it.currentKey()); … … 137 137 138 138 139 139 /* method description in header */ 140 QStringList * ActionSet:: actionStrings(const QString &context_name) const140 QStringList * ActionSet::ActionStrings(const QString &context_name) const 141 141 { 142 Context *c = _contexts[context_name];142 Context *c = m_Contexts[context_name]; 143 143 144 if (c == NULL) return NULL; 144 if (c == NULL) 145 return NULL; 145 146 else 146 147 { 147 148 QStringList *action_strings = new QStringList(); 148 QDictIterator<Action> it(*( _contexts[context_name]));149 QDictIterator<Action> it(*(m_Contexts[context_name])); 149 150 150 151 for (; it.current(); ++it) 151 152 action_strings->append(it.currentKey()); … … 154 155 } 155 156 } 156 157 158 QStringList * ActionSet::GetAllKeys(void) const 159 { 160 return new QStringList(this->m_KeyMap.keys()); 161 } 157 162 158 163 164 QStringList * ActionSet::GetAllActions(void) const 165 { 166 return new QStringList(this->m_Actions.keys()); 167 } 168 169 170 QStringList * ActionSet::GetKeyContexts(const QString &key) const 171 { 172 QStringList *strings = NULL; 173 const ActionList &ids = m_KeyMap[key]; 174 175 if (ids.size() == 0) 176 return NULL; 177 178 strings = new QStringList(); 179 180 for (size_t i = 0; i < ids.size(); i++) 181 { 182 if (!strings->contains(ids[i].context())) 183 strings->push_back(ids[i].context()); 184 } 185 186 return strings; 187 } 188 189 159 190 /* method description in header */ 160 bool ActionSet:: addAction(const ActionID &id, const QString &description,191 bool ActionSet::AddAction(const ActionID &id, const QString &description, 161 192 const QString &keys) 162 193 { 163 if (! _contexts[id.context()]) _contexts.insert(id.context(),164 194 if (!m_Contexts[id.context()]) 195 m_Contexts.insert(id.context(), new Context()); 165 196 166 197 /* return false if the action already exists */ 167 if ((*_contexts[id.context()])[id.action()]) return false; 198 if ((*m_Contexts[id.context()])[id.action()]) 199 return false; 168 200 else 169 201 { 170 202 /* create the action */ 171 203 Action *a = new Action(description, keys); 172 204 173 205 /* add the action into the dict */ 174 _contexts[id.context()]->insert(id.action(), a);206 m_Contexts[id.context()]->insert(id.action(), a); 175 207 208 /* if the action doesn't already exist, then add it */ 209 QStringList &contexts = m_Actions[id.action()]; 210 if (!contexts.contains(id.context())) 211 contexts.push_back(id.context()); 212 176 213 /* get the actions keys */ 177 const QStringList &keys = a-> getKeys();214 const QStringList &keys = a->GetKeys(); 178 215 for (size_t i = 0; i < keys.count(); i++) 179 216 { 180 217 /* get the action list (of actions bound to keys[i]) 181 218 if there is no key, keys[i], in the map, it will be added now */ 182 ActionList &ids = _keymap[keys[i]];219 ActionList &ids = m_KeyMap[keys[i]]; 183 220 184 221 /* add this action id to the list of actions bound to this key */ 185 ids.push_back(id); 222 if (ids.size() == 0) 223 ids.push_back(id); 224 else 225 { 226 bool added = false; 227 ActionList::iterator it; 228 229 /* keep list sorted by action, then by context. You 230 * must sort this stuff because multiple actions from 231 * different contexts can be added. Otherwise, we get 232 * into trouble in keybindings.cpp and 233 * mythcontrols.cpp when trying to delete based on 234 * action (displayed by key) */ 235 for (it = ids.begin(); (it != ids.end()) && (added == false); 236 ++it) 237 { 238 if ((QString::compare(id.action(), (*it).action()) < 0) || 239 ((QString::compare(id.action(), (*it).action()) == 0) && 240 (QString::compare(id.context(), (*it).context()) < 0))) 241 { 242 ids.insert(it, id); 243 added = true; 244 break; 245 } 246 } 247 if (added == false) ids.push_back(id); 248 } 186 249 } 187 188 250 return true; 189 251 } 190 191 252 return false; 192 253 } 193 254 194 255 195 256 196 QString ActionSet:: keyString(const ActionID &id) const257 QString ActionSet::KeyString(const ActionID &id) const 197 258 { 198 259 Context *c; 199 if ((c = _contexts[id.context()]))260 if ((c = m_Contexts[id.context()])) 200 261 { 201 262 Action *a; 202 263 if ((a = (*c)[id.action()])) 203 264 { 204 return a-> keyString();265 return a->KeyString(); 205 266 } 206 267 } 207 268 return QString::null; … … 209 270 210 271 211 272 212 QStringList ActionSet:: getKeys(const ActionID &id) const273 QStringList ActionSet::GetKeys(const ActionID &id) const 213 274 { 214 275 Context *c; 215 if ((c = _contexts[id.context()]))276 if ((c = m_Contexts[id.context()])) 216 277 { 217 278 Action *a; 218 279 if ((a = (*c)[id.action()])) 219 { 220 return a->getKeys(); 221 } 280 return a->GetKeys(); 222 281 } 223 282 224 283 return QStringList(); 225 284 } 226 285 227 286 228 229 const QString & ActionSet::getDescription(const ActionID &id) const 287 const QString & ActionSet::GetDescription(const ActionID &id) const 230 288 { 231 289 Context *c; 232 if ((c = _contexts[id.context()]))290 if ((c = m_Contexts[id.context()])) 233 291 { 234 292 Action *a; 235 293 if ((a = (*c)[id.action()])) 236 { 237 return a->getDescription(); 238 } 294 return a->GetDescription(); 239 295 } 240 296 241 297 return QString::null; 242 298 } 243 299 244 245 246 const ActionList & ActionSet::getActions(const QString &key) const247 {248 return _keymap[key];249 }250 251 252 300 #endif /* ACTIONSET_CPP */ -
mythcontrols/mythcontrols.h
29 29 30 30 #include "keybindings.h" 31 31 32 typedef struct33 {34 QString key;35 QString context;36 QString contextFrom;37 QString action;38 int bindlevel;39 } binding_t;40 41 typedef QPtrList<binding_t> BindingList;42 43 32 /** 44 33 * @class MythControls 45 34 * @brief The myth controls configuration class. … … 51 40 52 41 public: 53 42 /** 54 * @brief Create a new myth controls wizard. 43 * Create a new myth controls wizard. 44 * 55 45 * @param parent The main myth window. 56 46 * @param name The name of this window? I dunno, none of the docs 57 47 * say. … … 60 50 */ 61 51 MythControls(MythMainWindow *parent, bool& ui_ok); 62 52 63 /** 64 * @brief Delete the myth controls object. 65 */ 53 /** Delete the myth controls object. */ 66 54 ~MythControls(); 67 55 68 56 /** 69 * @brief Get the currently selected context string. 57 * Get the currently selected context string. If no context is 58 * selected, an empty string is returned. 59 * 70 60 * @return The currently selected context string. 71 *72 * If no context is selected, an empty string is returned.73 61 */ 74 QString getCurrentContext(void) const;62 QString GetCurrentContext(void) const; 75 63 76 64 /** 77 * @brief Get the currently selected action string. 65 * Get the currently selected action string. If no action is 66 * selected, an empty string is returned. 67 * 78 68 * @return The currently selected action string. 79 *80 * If no action is selected, an empty string is returned.81 69 */ 82 QString getCurrentAction(void) const;70 QString GetCurrentAction(void) const; 83 71 84 72 /** 85 * @brief Get the currently selected key string 73 * Get the currently selected key string. If no context is 74 * selected, an empty string is returned. 75 * 86 76 * @return The currently selected key string 87 *88 * If no context is selected, an empty string is returned.89 77 */ 90 QString getCurrentKey(void) const;78 QString GetCurrentKey(void) const; 91 79 92 93 94 80 protected: 95 81 82 83 /** The view mode */ 84 typedef enum { ActionsByContext, ActionsByKey, ContextsByKey } ViewMode; 85 96 86 /** 97 * @brief Load up UI. 98 * @return true if all UI elements were loaded successfully, 99 * otherwise false it returned. 87 * Load up UI. 100 88 * 101 * This method grabs all of the UI "thingies" that are needed by 102 * mythcontrols. If this method returns false, the plugin should 103 * exit since it will probably just core dump. 89 * @return true if all UI elements were loaded successfully 104 90 */ 105 bool loadUI();91 bool LoadUI(); 106 92 107 93 /** 94 * Show or hide the buttons at the bottom. 95 * 96 * @param shown Should the buttons be shown? 97 */ 98 void ShowButtons(bool shown) const; 99 100 /** 101 * Blank the text in the bottom buttons. 102 */ 103 void BlankButtons(void) const; 104 105 /** 106 * Fill the buttons with the strings in a string list. 107 * @param strings The string list. 108 */ 109 void FillButtons(const QStringList & strings); 110 111 /** 112 * Set the viewing mode of the plugin. 113 * 114 * @param view The view mode. 115 * @param force Force the view to be set (or reset) 116 */ 117 void SetView(ViewMode newview, bool force=false); 118 119 /** 108 120 * @brief The key press handler. 109 121 * @param e The key event. 110 122 */ 111 123 void keyPressEvent(QKeyEvent *e); 112 124 113 125 /** 114 * @brief Redraw the key information 126 * Refresh the action description and key binding buttons. 127 */ 128 void RefreshBindingInformation(); 129 130 /** 131 * @brief Redraw the information at the bottom. 132 */ 133 void RefreshInformation(); 134 135 /** 136 * Refresh the right list. 115 137 * 116 * Updates the list of keys that are shown and the description of 117 * the action. 138 * @param strings The strings to place in the right list. 118 139 */ 119 void refreshKeyInformation();140 void RefreshRight(QStringList * strings); 120 141 121 142 /** 122 * @brief Load the appropriate actions into the actionlist.123 * @param context The context, from which actions will be124 * displayed.143 * Refresh the left list. 144 * 145 * @param string The strings to place in the left list. 125 146 */ 126 void refreshRightList(void);147 void RefreshLeft(QStringList * strings); 127 148 128 149 /** 129 * @brief Redisplay both the left and right lists and fix focus 150 * Load the appropriate information into the right list. 151 * 152 * @param strings The strings to load into the right list. 130 153 */ 131 void updateLists(void);154 void RefreshRightList(); 132 155 156 /** Redisplay both the left and right lists and fix focus */ 157 void UpdateLists(void); 158 133 159 /** 134 * @brief Load the settings for a particular host. 160 * Load the settings for a particular host. 161 * 135 162 * @param hostname The host to load settings for. 136 163 */ 137 void loadHost(const QString & hostname);164 void LoadHost(const QString & hostname); 138 165 139 166 /** 140 * @brief Focus a button in a particular direction. 167 * Focus a button in a particular direction. 168 * 141 169 * @param direction Positave values focus to the right, negatives 142 170 * to the left. A value of zero focuses the first button. 143 171 */ 144 void focusButton(int direction);172 void FocusButton(int direction); 145 173 146 174 /** 147 * @brief Determine which button is focused. 175 * Determine which button is focused. 176 * 148 177 * @return Action::MAX_KEYS is no button is focused, otherwise, the 149 178 * index of the button is returned. 150 *151 * @sa Action::MAX_KEYS152 179 */ 153 size_t focusedButton(void) const;180 size_t FocusedButton(void) const; 154 181 155 182 /** 156 * @brief Resolve a potential conflict. 183 * Resolve a potential conflict. 184 * 157 185 * @return true if the conflict should be bound, otherwise, false 158 186 * is returned. 159 187 */ 160 bool resolveConflict(ActionID *conflict, int level);188 bool ResolveConflict(ActionID *conflict, int level); 161 189 162 190 /** 163 * @brief Focus a new list and take focus away from the old. 191 * Focus a new list and take focus away from the old. 192 * 164 193 * @param focus The list to gain focus 165 194 * @param unfocus The list to loose focus 166 195 */ 167 void switchListFocus(UIListBtnType *focus, UIListBtnType *unfocus);196 void SwitchListFocus(UIListBtnType *focus, UIListBtnType *unfocus); 168 197 169 /**170 * @brief Add bindings to QDict<binding_t> for specified context171 * @param bindings the QDict to which to add the bindings172 * @param context the context to grab keybindings from173 * @param contextParent the context whose keybindings are being calculated174 * @param bindlevel the bind level associated with this context175 */176 void addBindings(QDict<binding_t> &bindings, const QString &context, const QString &contextParent, int bindlevel);177 178 /**179 * @brief Create a BindingList for the specified context180 * @param context the context for which a BindingList should be created181 */182 BindingList *getKeyBindings(const QString &context);183 184 198 private slots: 185 199 186 /** 187 * @brief Add a key to the currently selected action. 188 */ 189 void addKeyToAction(void); 200 /** Add a key to the currently selected action. */ 201 void AddKeyToAction(void); 190 202 191 /** 192 * @brief Delete the currently active key. 193 */ 194 void deleteKey(); 203 /** Delete the currently active key. */ 204 void DeleteKey(); 195 205 196 /** 197 * @brief Save the settings. 198 */ 199 inline void save(void) { key_bindings->commitChanges(); } 206 /** Save the settings. */ 207 inline void Save(void) 208 { 209 m_KeyBindings->CommitChanges(); 210 } 200 211 201 212 /** 202 * @brief Recieves a signal when an item in the left list is203 * selected.213 * Recieves a signal when an item in the left list is selected. 214 * 204 215 * @param item The selected item. 205 216 */ 206 void leftSelected(UIListBtnTypeItem *item);217 void LeftSelected(UIListBtnTypeItem *item); 207 218 208 219 /** 209 * @brief Recieves a signal when an item in the right list is210 * selected.220 * Recieves a signal when an item in the right list is selected. 221 * 211 222 * @param item The selected item. 212 223 */ 213 void rightSelected(UIListBtnTypeItem *item);224 void RightSelected(UIListBtnTypeItem *item); 214 225 215 /** 216 * @brief Sort a list of keys, removing duplicates 217 * @param keys the list of keys to sort 218 */ 219 void sortKeyList(QStringList &keys); 226 /** Refresh binding information */ 227 void RefreshKeyBindings(); 220 228 221 229 /** 222 * @brief Refresh binding information 223 */ 224 void refreshKeyBindings(); 225 226 /** 227 * @brief Jump to a particular key binding 230 * Jump to a particular key binding 231 * 228 232 * @param e key event to use as jump 229 233 */ 230 234 bool JumpTo(QKeyEvent *e); 231 235 232 236 private: 233 237 234 UIType *focused; 235 UIListBtnType *LeftList; 236 UIListBtnType *RightList; 237 UITextType *description, *LeftDesc, *RightDesc; 238 UITextButtonType * ActionButtons[Action::MAX_KEYS]; 239 KeyBindings *key_bindings; 240 LayerSet *container; 238 /** Currently focused UI type */ 239 UIType *m_Focused; 241 240 242 QStringList contexts; ///< sorted list of contexts243 QStringList keys; ///< sorted list of keys241 /** The left list */ 242 UIListBtnType *m_LeftList; 244 243 245 QDict<QStringList> m_contexts; ///< actions for a given context 246 QDict<BindingList> contextKeys; ///< key bindings for a given context 247 QDict<BindingList> keyActions; ///< actions in each context for a given key 244 /** The right list */ 245 UIListBtnType *m_RightList; 248 246 249 typedef enum { kContextList, kKeyList, kActionList } ListType;250 ListType leftType, rightType;247 /** Text areas */ 248 UITextType *m_Description, *m_LeftDesc, *m_RightDesc; 251 249 252 QString getTypeDesc(ListType type); 250 /** Buttons */ 251 UITextButtonType * m_ActionButtons[Action::MAX_KEYS]; 253 252 253 /** The current keybindings */ 254 KeyBindings *m_KeyBindings; 255 256 /** A layer contianer */ 257 LayerSet *m_Container; 258 259 /** The view mode */ 260 ViewMode m_View; 254 261 }; 255 262 256 263 -
mythcontrols/keybindings.h
30 30 #include "actionid.h" 31 31 #include "actionset.h" 32 32 33 33 34 /** 34 35 * @class KeyBindings. 35 36 * @brief Information about the current keybindings. 36 37 * 37 38 * This class can retrieve, set, and modify the keybindings used by 38 39 * mythtv. It is a layer between the user interface, and the 39 * keybindings themeslfs. 40 * keybindings themeslfs. All of the logic behind conflicts, etc is 41 * kept here, as well as the database routines. 40 42 */ 41 43 class KeyBindings { 42 44 43 45 public: 44 46 45 /** 46 * @brief Levels of conflict 47 * @li None: Does not conflict 48 * @li Potential: May conflict. 49 * @li Fatal: Frontend will become inoperable. 50 */ 47 /** Levels of conflict */ 51 48 enum ConflictLevels { Warning, Error}; 52 49 53 50 /** 54 * @brief Create a new KeyBindings instance. 51 * Create a new KeyBindings instance. 52 * 55 53 * @param hostname The host for which to create the key bindings. 56 54 */ 57 55 KeyBindings(const QString & hostname); 58 56 59 57 /** 60 * @brief Get the hostname these keybindings are from. 61 * @return The hostname these keybindings are from. 58 * Determine the context belonging to the key and action 59 * 60 * @param action The action. 61 * @param anum The action number (in the list of all of a keys actions). 62 * 63 * @warning This method falls apart if the actionset class doesn't 64 * sort it the actions lists in the _kemap variable. 62 65 */ 63 inline const QString & getHostname() const { return this->_hostname; } 66 QString GetContext(const QString & key, const QString & action, 67 size_t anum) const; 64 68 65 69 /** 66 * @brief Get a list of the context names. 70 * Get a list of the context names. 71 * 67 72 * @return A list of the context names. 68 * @note The returned list is a copy and can be modified without69 * side-effects.70 73 */ 71 inline QStringList * getContexts() const74 inline QStringList * GetContexts() const 72 75 { 73 return actionset.contextStrings();76 return m_ActionSet.ContextStrings(); 74 77 } 75 78 76 79 /** 77 * @brief Get a list of the actions in a context. 80 * Get the contexts in which a key is bound. 81 * 82 * @param key The key. 83 * @return A string list containing the context names. 84 */ 85 inline QStringList * GetContexts(const QString & key) const 86 { 87 return m_ActionSet.GetKeyContexts(key); 88 } 89 90 /** 91 * Get a list of the actions in a context. 92 * 78 93 * @param context The name of the context. 79 94 * @return A list of action (names) for the target context. 80 * @note Store this instead of calling repeatedly. Every time you81 * do, ActionSet has to iterate over all contexts and actions.82 95 */ 83 inline QStringList * getActions(const QString & context) const96 inline QStringList * GetActions(const QString & context) const 84 97 { 85 return actionset.actionStrings(context);98 return m_ActionSet.ActionStrings(context); 86 99 } 87 100 88 101 /** 89 * @brief Get a list of the actions in a context. 102 * Get the action bound to a key in a particular context. 103 * 104 * @param key The key. 105 * @param context The context. 106 * @return The action. 107 */ 108 QString GetAction(const QString & key, const QString & context) const; 109 110 /** 111 * Get all bound keys. 112 * 113 * @return A string list of the bound keys. 114 */ 115 inline QStringList * GetAllKeys() const 116 { 117 return m_ActionSet.GetAllKeys(); 118 } 119 120 /** 121 * Get a list of the actions in a context. 122 * 90 123 * @param context The name of the context. 91 124 * @return A list of action (names) for the target context. 92 125 * @note Store this instead of calling repeatedly. Every time you 93 126 * do, ActionSet has to iterate over all contexts and actions. 94 127 */ 95 inline void getKeyActions(const QString &key, ActionList &list) const 96 { 97 list = actionset.getActions(key); 98 } 128 QStringList * GetKeyActions(const QString &key) const; 99 129 100 130 /** 101 * @brief Get an action's keys. 131 * Get an action's keys. 132 * 102 133 * @param context_name The name of the context. 103 134 * @param action_name The name of the action. 104 135 * @return The keys bound to the specified context's action 105 136 */ 106 inline QStringList getActionKeys(const QString & context_name,137 inline QStringList GetActionKeys(const QString & context_name, 107 138 const QString & action_name) const 108 139 { 109 return actionset.getKeys(ActionID(context_name, action_name));140 return m_ActionSet.GetKeys(ActionID(context_name, action_name)); 110 141 } 111 142 112 143 /** 113 * @brief Get an action's description. 144 * Get an action's description. 145 * 114 146 * @param context_name The name of the context. 115 147 * @param action_name The name of the action. 116 148 * @return The description of the specified context's action 117 149 */ 118 inline QString getActionDescription(const QString & context_name,150 inline QString GetActionDescription(const QString & context_name, 119 151 const QString & action_name) const 120 152 { 121 return actionset.getDescription(ActionID(context_name, action_name));153 return m_ActionSet.GetDescription(ActionID(context_name, action_name)); 122 154 } 123 155 124 156 /** 125 * @brief Add a key to an action. 157 * Add a key to an action. 158 * 126 159 * @param context_name The name of the context. 127 160 * @param action_name The name of the action. 128 161 * @param key The key to add. … … 131 164 * This does not take effect until the commitChanges function is 132 165 * called. 133 166 */ 134 inline void addActionKey(const QString & context_name,167 inline void AddActionKey(const QString & context_name, 135 168 const QString & action_name, 136 169 const QString & key) 137 170 { 138 this-> actionset.add(ActionID(context_name, action_name), key);171 this->m_ActionSet.Add(ActionID(context_name, action_name), key); 139 172 } 140 173 141 174 /** 142 * @brief Determine if adding a key would cause a conflict. 175 * Determine if adding a key would cause a conflict. 176 * 143 177 * @param context_name The name of the context. 144 178 * @param key The key to add. 145 179 * @param level The level of conflict. Check this if the return … … 157 191 * errors should be prevented no matter what. If they dont like it, 158 192 * they can learn SQL. 159 193 */ 160 ActionID * conflicts(const QString & context_name,194 ActionID * Conflicts(const QString & context_name, 161 195 const QString & key, int &level) const; 162 196 163 197 /** 164 * @brief Replace a key in an action. 198 * Replace a key in an action. 199 * 165 200 * @param context_name The name of the context. 166 201 * @param action_name The name of the action. 167 202 * @param newkey The key to add. … … 171 206 * This does not take effect until the commitChanges function is 172 207 * called. 173 208 */ 174 inline void replaceActionKey(const QString & context_name,209 inline void ReplaceActionKey(const QString & context_name, 175 210 const QString & action_name, 176 211 const QString & newkey, 177 212 const QString & oldkey) 178 213 { 179 this-> actionset.replace(ActionID(context_name, action_name),214 this->m_ActionSet.Replace(ActionID(context_name, action_name), 180 215 newkey, oldkey); 181 216 } 182 217 183 218 /** 184 * @brief Unbind a key from an action. 219 * Unbind a key from an action. 220 * 185 221 * @param context_name The name of the context. 186 222 * @param action_name The name of the action. 187 223 * @param key The key to remove. 188 224 * @return true if the key was removed, or false if it was not. 189 225 * 190 * Unless the action is mand itorythere is only one key in the226 * Unless the action is mandatory and there is only one key in the 191 227 * action, this method should return true. 192 228 */ 193 bool removeActionKey(const QString & context_name,229 bool RemoveActionKey(const QString & context_name, 194 230 const QString & action_name, 195 231 const QString & key); 196 232 197 /** 198 * @brief Set the manditory bindings to their defaults. 199 */ 200 void defaultManditoryBindings(void); 233 /** Set the mandatory bindings to their defaults. */ 234 void DefaultMandatoryBindings(void); 201 235 202 236 /** 203 * @brief Determine if there are changes to the keybindings. 237 * Determine if there are changes to the keybindings. 238 * 204 239 * @return True if keys have been changed, otherwise, false. 205 240 */ 206 inline bool hasChanges(void) const { return actionset.hasModified(); } 241 inline bool HasChanges(void) const 242 { 243 return m_ActionSet.HasModified(); 244 } 207 245 208 246 /** 209 * @brief Commit all changes made to the keybindings. 210 * 211 * This method will write the changes to the database, unbind myth's 212 * current bindings for those actions that changed, and setup the 213 * new bindings. 247 * Commit the changes made to the keybindings into the database. 214 248 */ 215 void commitChanges(void);249 void CommitChanges(void); 216 250 217 251 /** 218 * @brief Get a list of the manditory key bindings. 219 * @return A list of the manditory bindings. 252 * Get a list of the mandatory key bindings. 253 * 254 * @return A list of the mandatory bindings. 220 255 */ 221 inline const ActionList& getMand itoryBindings(void) const256 inline const ActionList& getMandatoryBindings(void) const 222 257 { 223 return this-> _manditory_bindings;258 return this->m_MandatoryBindings; 224 259 } 225 260 226 261 /** 227 * @brief Determine if all manditory bindings are satisfied. 228 * @return true if all manditory bindings are satisfied, otherwise, false. 262 * Determine if all mandatory bindings are satisfied. 263 * 264 * @return true if all mandatory bindings are satisfied, 265 * otherwise, false. 229 266 */ 230 bool hasManditoryBindings(void) const;267 bool HasMandatoryBindings(void) const; 231 268 232 269 protected: 233 270 234 /** 235 * @brief Get a reference to the hostname. 236 * @return A reference to the hostname. 237 */ 238 inline QString & hostname() { return this->_hostname; } 271 /** Commit a jumppoint to the database. */ 272 void CommitJumppoint(const ActionID &id); 239 273 240 /** 241 * @brief Commit a jumppoint to the database. 242 * 243 * This (currently) does not reload the jumppoint. 244 */ 245 void commitJumppoint(const ActionID &id); 274 /** Commit an action to the database, and reload its keybindings. */ 275 void CommitAction(const ActionID & id); 246 276 247 /** 248 * @brief Commit an action to the database, and reload its keybindings. 249 */ 250 void commitAction(const ActionID & id); 277 /** Load the jumppoints from the database. */ 278 void RetrieveJumppoints(void); 251 279 252 /** 253 * @brief Load the jumppoints from the database. 254 * 255 * This method will load the keybindings for jump points. 256 */ 257 void retrieveJumppoints(void); 280 /** Load the keybindings from the database. */ 281 void RetrieveContexts(void); 258 282 259 /** 260 * @brief Load the keybindings from the database. 261 * 262 * This will load the keybindings which apply to the hostname 263 * specified to the constructor. 264 */ 265 void retrieveContexts(void); 283 /** Load the mandatory bindings. */ 284 void LoadMandatoryBindings(void); 266 285 267 /** 268 * @brief Load the manditory bindings. 269 */ 270 void loadManditoryBindings(void); 286 private: 271 287 272 /** 273 * @brief Get a reference to the list of the manditory key bindings. 274 * @return A reference to the list of the manditory bindings. 275 */ 276 inline ActionList & manditoryBindings(void) { return _manditory_bindings; } 288 /** The hostname */ 289 QString m_HostName; 277 290 278 /** 279 * @brief Get the default keys. 280 * @return A list of the default keys. 281 */ 282 inline QStringList & defaultKeys() { return _default_keys; } 291 /** List of mandatory bindings */ 292 ActionList m_MandatoryBindings; 283 293 284 private: 294 /** List of the default key bindings */ 295 QStringList m_DefaultKeys; 285 296 286 QString _hostname; 287 ActionList _manditory_bindings; 288 QStringList _default_keys; 289 ActionSet actionset; 297 /** The action set */ 298 ActionSet m_ActionSet; 290 299 }; 291 300 292 301 #endif /* KEYBINDINGS_H */ -
mythcontrols/action.cpp
34 34 35 35 Action::Action(const QString & description, const QString & keys) 36 36 { 37 this->description()= description;38 this->keys()= QStringList::split(", ", QString(QKeySequence(keys)));37 m_Description = description; 38 m_Keys = QStringList::split(", ", QString(QKeySequence(keys))); 39 39 } 40 40 41 41 42 42 43 bool Action:: hasKey(const QString & key) const43 bool Action::HasKey(const QString & key) const 44 44 { 45 45 /* check the keys */ 46 for (size_t i = 0; i < getKeys().count(); i++)46 for (size_t i = 0; i < GetKeys().count(); i++) 47 47 { 48 if (getKeys()[i] == key) return true; 48 if (GetKeys()[i] == key) 49 return true; 49 50 } 50 51 51 52 /* the key was not found, so return false */ … … 54 55 55 56 56 57 57 bool Action:: addKey(const QString & key)58 bool Action::AddKey(const QString & key) 58 59 { 59 60 60 61 /* dont add empty keys and dont add too many, or duplicates */ 61 62 if ((key.length() == 0) || 62 ( getKeys().size() >= MAX_KEYS) ||63 ( getKeys().contains(key)))63 (GetKeys().size() >= MAX_KEYS) || 64 (GetKeys().contains(key))) 64 65 return false; 65 66 66 67 /* add the key */ 67 this->keys().push_back(key);68 m_Keys.push_back(key); 68 69 return true; 69 70 } 70 71 71 72 72 73 73 74 /* comments in header */ 74 bool Action:: replaceKey(const QString & newkey, const QString &oldkey)75 bool Action::ReplaceKey(const QString & newkey, const QString &oldkey) 75 76 { 76 77 /* make sure that the key list doesn't already have the new key */ 77 if ( getKeys().contains(newkey) == 0)78 if (GetKeys().contains(newkey) == 0) 78 79 { 79 for (size_t i = 0; i < getKeys().size(); i++)80 for (size_t i = 0; i < GetKeys().size(); i++) 80 81 { 81 if ( getKeys()[i] == oldkey)82 if (GetKeys()[i] == oldkey) 82 83 { 83 keys()[i] = newkey;84 m_Keys[i] = newkey; 84 85 return true; 85 86 } 86 87 }