Index: mythcontrols/actionset.h
===================================================================
--- mythcontrols/actionset.h	(revision 10604)
+++ mythcontrols/actionset.h	(working copy)
@@ -26,39 +26,36 @@
 
 #include <qdict.h>
 
-/**
- * @brief The statically assigned context for jump point actions.
- */
+/** The statically assigned context for jump point actions. */
 #define JUMP_CONTEXT "JumpPoints"
 
-/**
- * @brief The name of global actions.
- */
+/** The name of global actions. */
 #define GLOBAL_CONTEXT "Global"
 
-
+/** Context is a grouping of actions */
 typedef QDict<Action> Context;
-typedef QValueList<ActionID> ActionList;
 
-
 /**
- * @class ActionSet
- * @brief Maintains consistancy between actions and keybindings.
+ * Action list is list of ActionIDs
  *
- * This class handles adding a removing bindings to keys.
+ * @todo Make a class out of this type and ensure that the list is
+ * sorted appropriatly.
  */
+typedef QValueList<ActionID> ActionList;
+
+
+/** Maintains consistancy between actions, contexts and keys. */
 class ActionSet
 {
 
 public:
 
-    /**
-     * @brief Create a new, empty set of action bindings.
-     */
+    /** Create a new, empty set of action bindings. */
     inline ActionSet() {};
 
     /**
-     * @brief Add an action.
+     * Add an action.
+     *
      * @param id The action identifier.
      * @param description The action description.
      * @param keys The keys for this action.
@@ -67,148 +64,207 @@
      * If the action has already been added, it will not be added
      * again.  There are no duplicate actions in the action set.
      */
-    bool addAction(const ActionID &id, const QString & description,
+    bool AddAction(const ActionID &id, const QString & description,
                    const QString &keys);
 
     /**
-     * @brief Add a binding.
+     * Add a binding.
+     *
      * @param id The action identifier.
      * @param key The symbolic name of the key.
      * @return true if the key was added otherwise, false.
      */
-    bool add(const ActionID &id, const QString &key);
+    bool Add(const ActionID &id, const QString &key);
 
     /**
-     * @brief Remove a key from an action identifier.
+     * Remove a key from an action identifier.
+     *
      * @param id The action identifier to remove from.
      * @param key The key to remove.
      */
-    bool remove(const ActionID &id, const QString &key);
+    bool Remove(const ActionID &id, const QString &key);
 
     /**
-     * @brief Replace a specific key in a specific action.
+     * Replace a specific key in a specific action.
+     *
      * @param id The action identifier.
      * @param newkey The new key.
      * @param oldkey The key to be replaced.
      */
-    bool replace(const ActionID &id, const QString &newkey,
+    bool Replace(const ActionID &id, const QString &newkey,
                  const QString &oldkey);
 
     /**
-     * @brief Get a list of all contexts in the action set.
+     * Get a list of all contexts in the action set.
+     *
      * @return A list of all contexts.
      */
-    QStringList * contextStrings(void) const;
+    QStringList * ContextStrings(void) const;
 
     /**
-     * @brief Get a list of all action in the action set.
+     * Get a list of all action in the action set.
+     *
      * @return A list of all actions in the action set.
      */
-    QStringList * actionStrings(const QString & context_name) const;
+    QStringList * ActionStrings(const QString & context_name) const;
 
     /**
-     * @brief Get a string containing all the keys in bound to an
-     * action.
+     * Get a string containing all the keys in bound to an action.
+     *
      * @param id The action's identifier.
      * @return null if there is no such action, otherwise, the keys.
      */
-    QString keyString(const ActionID &id) const;
+    QString KeyString(const ActionID &id) const;
 
     /**
-     * @brief Get the keys bound to an action by it's identifier.
+     * Get the keys bound to an action by it's identifier.
+     *
      * @param id The action identifier.
      * @return The keys used by the action.
      */
-    QStringList getKeys(const ActionID &id) const;
+    QStringList GetKeys(const ActionID &id) const;
 
     /**
-     * @brief Get the description of an action.
+     * Get all keys that are in use.
+     *
+     * @return A string list containing all of the keys.
+     */
+    QStringList * GetAllKeys(void) const;
+
+    /**
+     * Get the contexts, in which a key is bound.
+     *
+     * @return A string list containing the context names.
+     */
+    QStringList * GetKeyContexts(const QString &key) const;
+
+    /**
+     * Get all of the actions that are in use.
+     *
+     * @return A string list containing all of the actions.
+     */
+    QStringList *GetAllActions(void) const;
+
+    /**
+     * Get the description of an action.
+     *
      * @param id The action identifier.
      * @return The action description.
      */
-    const QString & getDescription(const ActionID &id) const;
+    const QString & GetDescription(const ActionID &id) const;
 
     /**
-     * @brief Get the actions bound to the specified key.
+     * Get the actions bound to the specified key.
+     *
      * @param key The key.
      * @return The list of actions, which are bound to the key.
      */
-    const ActionList & getActions(const QString &key) const;
+    inline const ActionList & GetActions(const QString &key) const
+    {
+        return m_KeyMap[key];
+    }
 
+
     /**
-     * @brief Get the appropriate container of modified actions based on
+     * Get the appropriate container of modified actions based on
      * context.
+     *
      * @return The appropriate container of modified actions.
      */
-    inline const ActionList & getModified(void) const { return _modified; }
+    inline const ActionList & GetModified(void) const
+    {
+        return m_Modified;
+    }
 
     /**
-     * @brief Determine if the action set has been modified.
+     * Determine if the action set has been modified.
+     *
      * @return True if changes have been made, otherwise, false.
      */
-    inline bool hasModified(void) const { return !(_modified.isEmpty()); }
+    inline bool HasModified(void) const
+    {
+        return !(m_Modified.isEmpty());
+    }
 
     /**
-     * @brief Mark an action as unmodified.
+     * Mark an action as unmodified.
+     *
      * @return true if the action was modified, and is set to unmodified.
      */
-    inline bool unmodify(const ActionID & id)
+    inline bool Unmodify(const ActionID & id)
     {
-        return (_modified.remove(id) > 0);
+        return (m_Modified.remove(id) > 0);
     }
 
     /**
-     * @brief Determine if an action has been modified.
+     * Determine if an action has been modified.
+     *
      * @param id The action identifier.
      * @return true if the action is modified, otherwise, false.
      */
-    inline bool isModified(const ActionID &id)const { return !unmodified(id); }
+    inline bool IsModified(const ActionID &id) const
+    {
+        return !Unmodified(id);
+    }
 
     /**
-     * @brief Determine if an action is still unmodified.
+     * Determine if an action is still unmodified.
+     *
      * @param id The action identifier.
      * @return true if the action has not been modified, otherwise, false.
      */
-    inline bool unmodified(const ActionID &id) const
+    inline bool Unmodified(const ActionID &id) const
     {
-        return (getModified().contains(id) == 0);
+        return (GetModified().contains(id) == 0);
     }
 
 protected:
 
     /**
-     * @brief Mark an action as modified.
+     * Mark an action as modified.
+     *
      * @param id The actio identifier.
      */
-    inline void modify(const ActionID &id)
+    inline void Modify(const ActionID &id)
     {
-        if (unmodified(id)) _modified.push_back(id);
+        if (Unmodified(id)) m_Modified.push_back(id);
     }
 
     /**
-     * @brief Get an action by its identifier.
+     * Get an action by its identifier.
+     *
      * @return A pointer to the action.
      */
-    inline Action * action(const ActionID &id) const
+    inline Action * GetAction(const ActionID &id) const
     {
-        return context(id.context()) ?
-            (*context(id.context()))[id.action()] : NULL;
+        return GetContext(id.context()) ?
+            (*GetContext(id.context()))[id.action()] : NULL;
     }
 
     /**
-     * @brief Get a context by its identifier.
+     * Get a context by its identifier.
+     *
      * @return A pointer to the context.
      */
-    inline Context * context(const QString & name) const
+    inline Context * GetContext(const QString & name) const
     {
-        return this->_contexts[name];
+        return this->m_Contexts[name];
     }
 
 private:
 
-    QMap<QString, ActionList> _keymap;
-    QDict<Context> _contexts;
-    ActionList _modified;
+    /** Maps keys to the actions the are bound */
+    QMap<QString, ActionList> m_KeyMap;
+
+    /** Dictionary of contexts (which contain actions) */
+    QDict<Context> m_Contexts;
+
+    /** Modified actions */
+    ActionList m_Modified;
+
+    /** map from action to the contexts it belongs to */
+    QMap<QString, QStringList> m_Actions;
+
 };
 
 #endif /* ACTIONSET_H */
Index: mythcontrols/action.h
===================================================================
--- mythcontrols/action.h	(revision 10604)
+++ mythcontrols/action.h	(working copy)
@@ -41,13 +41,15 @@
 public:
 
     /**
-     * @brief Create a new empty action.
+     * Create a new empty action.
+     *
      * @param description The actions description.
      */
-    inline Action(const QString & description) : _description(description) {}
+    inline Action(const QString & description) : m_Description(description) {}
 
     /**
-     * @brief Create a new action.
+     * Create a new action.
+     *
      * @param description The description of the action.
      * @param keys The key sequence (strings) that trigger the action.
      *
@@ -58,86 +60,91 @@
     Action(const QString & description, const QString & keys);
 
     /**
-     * @brief Get the action description.
+     * Get the action description.
+     *
      * @return The action description.
      */
-    inline const QString & getDescription() const { return this->_description; }
+    inline const QString & GetDescription() const
+    {
+        return this->m_Description;
+    }
 
     /**
-     * @brief Get the key sequence(s) that trigger this action.
+     * Get the key sequence(s) that trigger this action.
+     *
      * @return The key sequence(s) that trigger this action.
      */
-    inline const QStringList & getKeys() const { return this->_keys; }
+    inline const QStringList & GetKeys() const
+    {
+        return this->m_Keys;
+    }
 
     /**
-     * @brief Get the keys as a string.
+     * Get the keys as a string.
+     *
      * @return QString::null or a comma delimited string of keys.
      */
-    inline QString keyString() const { return _keys.join(","); }
+    inline QString KeyString() const
+    {
+        return m_Keys.join(",");
+    }
 
     /**
-     * @brief Add a key sequence to this action.
+     * Add a key sequence to this action.
+     *
      * @param key The key to add to the action.
      * @return true if the key was added otherwise, false.
      */
-    bool addKey(const QString & key);
+    bool AddKey(const QString & key);
 
     /**
-     * @brief Remove a key from this action.
+     * Remove a key from this action.
+     *
      * @param key The key to remove.
      * @return true if the key is removed, otherwise, false.
      */
-    inline bool removeKey(const QString & key) { return (keys().remove(key)>0); }
+    inline bool RemoveKey(const QString & key)
+    {
+        return (m_Keys.remove(key)>0);
+    }
 
     /**
-     * @brief Replace a key.
+     * Replace a key.
+     *
      * @param newkey The new key.
      * @param oldkey The old key, which is being replaced.
      */
-    bool replaceKey(const QString & newkey, const QString & oldkey);
+    bool ReplaceKey(const QString & newkey, const QString & oldkey);
 
     /**
-     * @brief Determine if the action already has a key.
+     * Determine if the action already has a key.
+     *
      * @param key The key to check for.
      * @return true if the key is already bound in this action,
      * otherwise, false is returned.
      */
-    bool hasKey(const QString & key) const;
+    bool HasKey(const QString & key) const;
 
     /**
-     * @brief Get the index of a key.
-     * @param key The string containing the key.
-     * @return The index of the key, which will be less than zero if the
-     * key does not exist.
-     */
-
-    /**
-     * @brief Determine if the action has any keys at all.
+     * Determine if the action has any keys at all.
+     *
      * @return true if the action has keys, otherwise, false.
      */
-    inline bool empty(void) const { return (_keys.size() > 0); }
+    inline bool IsEmpty(void) const
+    {
+        return (m_Keys.size() > 0);
+    }
 
-    /** @brief The maximum number of keys that can be bound to an action. */
+    /** The maximum number of keys that can be bound to an action. */
     static const unsigned short MAX_KEYS = 4;
 
-protected:
+private:
 
-    /**
-     * @brief Get a reference to the action description.
-     * @return A reference to the action description.
-     */
-    inline QString & description() { return this->_description; }
+    /** The actions description. */
+    QString m_Description;
 
-    /**
-     * @brief Get a reference to actions the key sequences.
-     * @return A reference to actions the key sequences.
-     */
-    inline QStringList & keys() { return this->_keys; }
-
-private:
-
-    QString _description;
-    QStringList _keys;
+    /** The keys bound to the action. */
+    QStringList m_Keys;
 };
 
 #endif /* ACTION_H */
Index: mythcontrols/mythcontrols.cpp
===================================================================
--- mythcontrols/mythcontrols.cpp	(revision 10604)
+++ mythcontrols/mythcontrols.cpp	(working copy)
@@ -29,13 +29,10 @@
 #ifndef MYTHCONTROLS_CPP
 #define MYTHCONTROLS_CPP
 
-/* QT includes */
 #include <qnamespace.h>
 #include <qstringlist.h>
 #include <qapplication.h>
 #include <qbuttongroup.h>
-
-/* MythTV includes */
 #include <mythtv/mythcontext.h>
 #include <mythtv/mythdialogs.h>
 
@@ -54,107 +51,106 @@
         return key;
 }
 
-static const QString DisplayToKey(const QString key)
-{
-    if (key.left(1) == "[" && key != "[")
-        return "remote" + key.mid(1,key.length()-2);
-    else
-        return key;
-}
 
 /* comments in header */
 MythControls::MythControls (MythMainWindow *parent, bool& ui_ok)
     :MythThemedDialog(parent, "controls", "controls-", "controls")
 {
     /* Nullify keybindings so the deconstructor knows not to delete it */
-    this->key_bindings = NULL;
+    this->m_KeyBindings = NULL;
 
-    /* delete the contents when we're done */
-    m_contexts.setAutoDelete(true);
-    
+    this->m_View = ActionsByContext;
+
     /* load up the ui components */
-    if ((ui_ok = loadUI()))
+    if ((ui_ok = LoadUI()))
     {
-        leftType = kContextList;
-        rightType = kActionList;
-
         /* for starters, load this host */
-        loadHost(gContext->GetHostName());
+        m_KeyBindings = new KeyBindings(gContext->GetHostName());
 
         /* update the information */
-        refreshKeyInformation();
+        SetView(ActionsByContext, true);
+        RefreshInformation();
 
         /* capture the signals we want */
-        connect(LeftList, SIGNAL(itemSelected(UIListBtnTypeItem*)),
-                this, SLOT(leftSelected(UIListBtnTypeItem*)));
-        connect(RightList, SIGNAL(itemSelected(UIListBtnTypeItem*)),
-                this, SLOT(rightSelected(UIListBtnTypeItem*)));
-
+        connect(m_LeftList, SIGNAL(itemSelected(UIListBtnTypeItem*)),
+                this, SLOT(LeftSelected(UIListBtnTypeItem*)));
+        connect(m_RightList, SIGNAL(itemSelected(UIListBtnTypeItem*)),
+                this, SLOT(RightSelected(UIListBtnTypeItem*)));
     }
 }
 
 
 
 /* comments in header */
-MythControls::~MythControls() { delete this->key_bindings; }
+MythControls::~MythControls()
+{
+    delete this->m_KeyBindings;
+}
 
 
 
 /* comments in header */
-bool MythControls::loadUI()
+bool MythControls::LoadUI()
 {
     /* the return value of the method */
     bool retval = true;
 
     /* Get the UI widgets that we need to work with */
-    if ((description = getUITextType("description")) == NULL)
+    if ((m_Description = getUITextType("description")) == NULL)
     {
         VERBOSE(VB_IMPORTANT, "MythControls: Unable to load action_description");
         retval = false;
     }
 
-    if ((container = getContainer("controls")) == NULL) {
+    if ((m_Container = getContainer("controls")) == NULL)
+    {
         VERBOSE(VB_IMPORTANT, "MythControls:  No controls container in theme");
         retval = false;
     }
-    else if ((LeftList = getUIListBtnType("leftlist")) == NULL) {
+    else if ((m_LeftList = getUIListBtnType("leftlist")) == NULL)
+    {
         VERBOSE(VB_IMPORTANT, "MythControls:  No leftlist in theme");
         retval = false;
     }
-    else if ((RightList = getUIListBtnType("rightlist")) == NULL) {
+    else if ((m_RightList = getUIListBtnType("rightlist")) == NULL)
+    {
         VERBOSE(VB_IMPORTANT, "MythControls:  No rightList in theme");
         retval = false;
     }
-    else {
-        LeftDesc = getUITextType("leftdesc");
-        RightDesc = getUITextType("rightdesc");
-        /* focus the context list by default */
-        focused = LeftList;
-        LeftList->calculateScreenArea();
-        LeftList->SetActive(true);
-        RightList->calculateScreenArea();
-        RightList->SetActive(false);
+    else
+    {
+        m_LeftDesc = getUITextType("leftdesc");
+        m_RightDesc = getUITextType("rightdesc");
+        m_Focused = m_LeftList;
+        m_LeftList->calculateScreenArea();
+        m_LeftList->SetActive(true);
+        m_RightList->calculateScreenArea();
+        m_RightList->SetActive(false);
     }
 
     /* Check that all the buttons are there */
-    if ((ActionButtons[0] = getUITextButtonType("action_one")) == NULL)
+    if ((m_ActionButtons[0] = getUITextButtonType("action_one")) == NULL)
     {
-        VERBOSE(VB_IMPORTANT, "MythControls: Unable to load first action button");
+        VERBOSE(VB_IMPORTANT,
+                "MythControls: Unable to load first action button");
         retval = false;
     }
-    else if ((ActionButtons[1] = getUITextButtonType("action_two")) == NULL)
+    else if ((m_ActionButtons[1] = getUITextButtonType("action_two")) == NULL)
     {
-        VERBOSE(VB_IMPORTANT, "MythControls: Unable to load second action button");
+        VERBOSE(VB_IMPORTANT,
+                "MythControls: Unable to load second action button");
         retval = false;
     }
-    else if ((ActionButtons[2] = getUITextButtonType("action_three")) == NULL)
+    else if ((m_ActionButtons[2] = getUITextButtonType("action_three")) == NULL)
     {
-        VERBOSE(VB_IMPORTANT, "MythControls: Unable to load thrid action button");
+        VERBOSE(VB_IMPORTANT,
+                "MythControls: Unable to load thrid action button");
         retval = false;
     }
-    else if ((ActionButtons[3] = getUITextButtonType("action_four")) == NULL)
+    else if ((m_ActionButtons[3] = getUITextButtonType("action_four")) == NULL)
     {
-        VERBOSE(VB_IMPORTANT, "MythControls: Unable to load fourth action button");
+        VERBOSE(VB_IMPORTANT,
+                "MythControls: Unable to load fourth action button");
         retval = false;
     }
 
@@ -162,40 +158,74 @@
 }
 
 
+void MythControls::ShowButtons(bool shown) const
+{
+    for (size_t i = 0; i < Action::MAX_KEYS; i++)
+        shown ? m_ActionButtons[i]->show() : m_ActionButtons[i]->hide();
+}
 
-/* comments in header */
-size_t MythControls::focusedButton(void) const
+
+/* method description in mythcontrols.h */
+void MythControls::BlankButtons(void) const
 {
     for (size_t i = 0; i < Action::MAX_KEYS; i++)
-        if (focused == ActionButtons[i]) return i;
+        m_ActionButtons[i]->setText("");
+}
 
+/* method description in mythcontrols.h */
+void MythControls::FillButtons(const QStringList & strings)
+{
+    size_t i = 0, maxstr = Action::MAX_KEYS;
+
+    if (strings.count() < Action::MAX_KEYS)
+        maxstr = strings.count();
+    
+    /* fill existing keys */
+    for (; i < maxstr; i++)
+        m_ActionButtons[i]->setText(KeyToDisplay(strings[i]));
+
+    /* blank the other ones */
+    for (; i < Action::MAX_KEYS; i++)
+        m_ActionButtons[i]->setText("");
+}
+
+/* comments in header */
+size_t MythControls::FocusedButton(void) const
+{
+    for (size_t i = 0; i < Action::MAX_KEYS; i++)
+    {
+        if (m_Focused == m_ActionButtons[i])
+            return i;
+    }
     return Action::MAX_KEYS;
 }
 
-
-void MythControls::focusButton(int direction)
+void MythControls::FocusButton(int direction)
 {
-    if (leftType != kContextList || rightType != kActionList)
-        return;
     if (direction == 0)
     {
-        focused = ActionButtons[0];
-        ActionButtons[0]->takeFocus();
-        RightList->looseFocus();
-        RightList->SetActive(false);
+        m_Focused = m_ActionButtons[0];
+        m_ActionButtons[0]->takeFocus();
+        m_RightList->looseFocus();
+        m_RightList->SetActive(false);
     }
     else
     {
 
         /* change focus by at most one in either direction */
-        if (direction > 0) direction = 1;
-        else direction = -1;
+        if (direction > 0)
+            direction = 1;
+        else
+            direction = -1;
 
         /* figure out which button is focused */
         int current = 0;
-        if (focused == ActionButtons[1]) current=1;
-        else if (focused == ActionButtons[2]) current = 2;
-        else if (focused == ActionButtons[3]) current = 3;
+        if (m_Focused == m_ActionButtons[1])
+            current=1;
+        else if (m_Focused == m_ActionButtons[2])
+            current = 2;
+        else if (m_Focused == m_ActionButtons[3])
+            current = 3;
 
         /* determine the new focused button index */
         int newb = current + direction;
@@ -203,28 +233,83 @@
         /* focus an existing button */
         if ((newb >= 0) && (newb < Action::MAX_KEYS))
         {
-            focused->looseFocus();
-            focused = ActionButtons[newb];
-            focused->takeFocus();
+            m_Focused->looseFocus();
+            m_Focused = m_ActionButtons[newb];
+            m_Focused->takeFocus();
         }
     }
 }
 
 
 
-void MythControls::switchListFocus(UIListBtnType *focus, UIListBtnType *unfocus)
+void MythControls::SwitchListFocus(UIListBtnType *focus, UIListBtnType *unfocus)
 {
     /* unfocus a list (setactive(false)) or a button (focused->looseFocus) */
     if (unfocus)
         unfocus->SetActive(false);
 
-    focused->looseFocus();
-    focused = focus;
+    m_Focused->looseFocus();
+    m_Focused = focus;
     focus->SetActive(true);
     focus->takeFocus();
-    refreshKeyInformation();
+    RefreshInformation();
 }
 
+/* method description in mythcontrols.h */
+void MythControls::SetView(ViewMode newview, bool force)
+{
+    QStringList *lstrings = NULL, *rstrings = NULL;
+
+    /* Dont set the view to what is already is */
+    if ((newview == m_View) && (force == false))
+      return;
+
+    m_Focused->looseFocus();
+    m_Focused = m_LeftList;
+    m_LeftList->takeFocus();
+    
+    m_View = newview;
+
+    switch (newview)
+    {
+    case ActionsByContext:
+        this->ShowButtons(true);
+        m_LeftDesc->SetText(tr("Contexts"));
+        m_RightDesc->SetText(tr("Actions"));
+        lstrings = m_KeyBindings->GetContexts();
+        rstrings = m_KeyBindings->GetActions((*lstrings)[0]);
+        break;
+    case ActionsByKey:
+        this->ShowButtons(false);
+        m_LeftDesc->SetText(tr("Keys"));
+        m_RightDesc->SetText(tr("Actions"));
+        lstrings = m_KeyBindings->GetAllKeys();
+        rstrings = m_KeyBindings->GetKeyActions((*lstrings)[0]);
+        break;
+    case ContextsByKey:
+        this->ShowButtons(false);
+        m_LeftDesc->SetText(tr("Keys"));
+        m_RightDesc->SetText(tr("Contexts"));
+        lstrings = m_KeyBindings->GetAllKeys();
+        rstrings = m_KeyBindings->GetContexts((*lstrings)[0]);
+        break;
+    }
+
+    /* refresh the keys on the left */
+    if (lstrings != NULL)
+    {
+        RefreshLeft(lstrings);
+        delete lstrings;
+    }
+
+    /* refresh the keys on the right */
+    if (rstrings != NULL)
+    {
+        RefreshRight(rstrings);
+        delete rstrings;
+    }
+}
+
 void MythControls::keyPressEvent(QKeyEvent *e)
 {
     bool handled = false;
@@ -239,140 +324,120 @@
 
         if (action == "MENU" || action == "INFO")
         {
-            focused->looseFocus();
+            m_Focused->looseFocus();
             OptionsMenu popup(gContext->GetMainWindow());
             int a = (int)popup.getOption();
-            switch (a) {
+            switch (a)
+            {
                 case (int)OptionsMenu::SAVE:
-                    save();
+                    Save();
                     break;
             }
-            focused->takeFocus();
-//            if (popup.getOption() == OptionsMenu::SAVE) save();
+            m_Focused->takeFocus();
         }
         else if (action == "SELECT")
         {
-            if (focused == LeftList)
-                switchListFocus(RightList, LeftList);
-            else if (focused == RightList)
-                focusButton(0);
-            else {
-                QString key = getCurrentKey();
-                if (!key.isEmpty())
+            if (m_Focused == m_LeftList)
+                SwitchListFocus(m_RightList, m_LeftList);
+            else if (m_View == ActionsByContext)
+            {
+                if (m_Focused == m_RightList)
+                    FocusButton(0);
+                else
                 {
-                    ActionMenu popup(gContext->GetMainWindow());
-                    int result = popup.getOption();
-                    if (result == ActionMenu::SET) addKeyToAction();
-                    else if (result == ActionMenu::REMOVE) deleteKey();
-                } else // for blank keys, no reason to ask what to do
-                    addKeyToAction();
+                    QString key = GetCurrentKey();
+                    if (!key.isEmpty())
+                    {
+                        ActionMenu popup(gContext->GetMainWindow());
+                        int result = popup.getOption();
+                        if (result == ActionMenu::SET)
+                            AddKeyToAction();
+                        else if (result == ActionMenu::REMOVE)
+                            DeleteKey();
+                    }
+                    else // for blank keys, no reason to ask what to do
+                        AddKeyToAction();
+                }
             }
         }
         else if (action == "ESCAPE")
         {
             escape = true;
-            if (focused == LeftList)
+            if (m_Focused == m_LeftList)
             {
                 handled = false;
-                if (key_bindings->hasChanges())
+                if (m_KeyBindings->HasChanges())
                 {
                     /* prompt user to save changes */
                     UnsavedMenu popup(gContext->GetMainWindow());
                     if (popup.getOption() == UnsavedMenu::SAVE)
                     {
-                        save();
+                        Save();
                     }
                 }
             }
-            else if (focused == RightList)
-                switchListFocus(LeftList, RightList);
+            else if (m_Focused == m_RightList)
+                SwitchListFocus(m_LeftList, m_RightList);
             else
-                switchListFocus(RightList, NULL);
+                SwitchListFocus(m_RightList, NULL);
         }
         else if (action == "UP")
         {
-            if (focused == LeftList)
-                LeftList->MoveUp();
-            else if (focused == RightList)
-                RightList->MoveUp();
+            if (m_Focused == m_LeftList)
+                m_LeftList->MoveUp();
+            else if (m_Focused == m_RightList)
+                m_RightList->MoveUp();
         }
         else if (action == "DOWN")
         {
-            if (focused == LeftList)
-                LeftList->MoveDown();
-            else if (focused == RightList)
-                RightList->MoveDown();
+            if (m_Focused == m_LeftList)
+                m_LeftList->MoveDown();
+            else if (m_Focused == m_RightList)
+                m_RightList->MoveDown();
         }
         else if (action == "LEFT")
         {
-            if (focused==RightList)
-                switchListFocus(LeftList, RightList);
-            else if (focused != LeftList)
-                focusButton(-1);
+            if (m_Focused==m_RightList)
+                SwitchListFocus(m_LeftList, m_RightList);
+            else if (m_Focused != m_LeftList)
+                FocusButton(-1);
         }
         else if (action == "RIGHT")
         {
-            if (focused == LeftList)
-                switchListFocus(RightList, LeftList);
-            else if (focused != RightList)
-                focusButton(1);
+            if (m_Focused == m_LeftList)
+                SwitchListFocus(m_RightList, m_LeftList);
+            else if (m_Focused != m_RightList)
+                FocusButton(1);
         }
         else if (action == "PAGEUP")
         {
-            if (focused == LeftList)
-                LeftList->MoveUp(UIListBtnType::MovePage);
-            else if (focused == RightList)
-                RightList->MoveUp(UIListBtnType::MovePage);
+            if (m_Focused == m_LeftList)
+                m_LeftList->MoveUp(UIListBtnType::MovePage);
+            else if (m_Focused == m_RightList)
+                m_RightList->MoveUp(UIListBtnType::MovePage);
         }
         else if (action == "PAGEDOWN")
         {
-            if (focused == LeftList)
-                LeftList->MoveDown(UIListBtnType::MovePage);
-            else if (focused == RightList)
-                RightList->MoveDown(UIListBtnType::MovePage);
+            if (m_Focused == m_LeftList)
+                m_LeftList->MoveDown(UIListBtnType::MovePage);
+            else if (m_Focused == m_RightList)
+                m_RightList->MoveDown(UIListBtnType::MovePage);
         }
         else if (action == "1")
-        {
-            if (leftType != kContextList || rightType != kActionList)
-            {
-                leftType = kContextList;
-                rightType = kActionList;
-                updateLists();
-                if (focused != LeftList)
-                    switchListFocus(LeftList,
-                                    (focused == RightList) ? RightList : NULL);
-            } else handled = false;
-        }
+            SetView(ActionsByContext);
         else if (action == "2")
-        {
-            if (leftType != kContextList || rightType != kKeyList)
-            {
-                leftType = kContextList;
-                rightType = kKeyList;
-                updateLists();
-                if (focused != LeftList)
-                    switchListFocus(LeftList,
-                                    (focused == RightList) ? RightList : NULL);
-            } else handled = false;
-        }
+            SetView(ActionsByKey);
         else if (action == "3")
-        {
-            if (leftType != kKeyList || rightType != kContextList)
-            {
-                leftType = kKeyList;
-                rightType = kContextList;
-                updateLists();
-                if (focused != LeftList)
-                    switchListFocus(LeftList,
-                                    (focused == RightList) ? RightList : NULL);
-            } else handled = false;
-        }
-        else handled = false;
+            SetView(ContextsByKey);
+        else
+            handled = false;
     }
 
-    if (handled) return;
+    if (handled)
+        return;
 
-    if (!escape && JumpTo(e)) handled = true;
+    if (!escape && JumpTo(e))
+        handled = true;
 
     if (!handled)
         MythThemedDialog::keyPressEvent(e);
@@ -380,15 +445,24 @@
 
 bool MythControls::JumpTo(QKeyEvent *e)
 {
-    UIListBtnType *list = NULL;
-    if (focused == LeftList && leftType == kKeyList) list = LeftList;
-    if (focused == RightList && rightType == kKeyList) list = RightList;
-    if (!list) return false;
+    UIListBtnType *flist = NULL;
 
+    if (m_View != ActionsByContext)
+    {
+        if (m_Focused == m_LeftList)
+            flist = m_LeftList;
+        else
+            flist = m_RightList;
+    }
+
+    if (!flist)
+        return false;
+
     QString key = e->text();
-    if (key.left(6) == "remote") {
+    if (key.left(6) == "remote")
         key = KeyToDisplay(key);
-    } else {
+    else
+    {
         key = QString(QKeySequence(e->key()));
         if (key.isEmpty()) return false;
         QString modifiers = "";
@@ -401,308 +475,221 @@
 
     UIListBtnTypeItem *b;
     uint len = 1024; // infinity
-    if (list == RightList)
+    if (flist == m_RightList)
     {
         key = key + " ";
         len = key.length();
     }
 
-    for (b = list->GetItemFirst(); b; b = list->GetItemNext(b))
-        if (b->text().left(len) == key) break;
-    if (!b) return false;
+    for (b = flist->GetItemFirst(); b; b = flist->GetItemNext(b))
+    {
+        if (b->text().left(len) == key)
+            break;
+    }
+    if (!b)
+        return false;
 
-    int curpos = list->GetItemPos(list->GetItemCurrent());
-    int newpos = list->GetItemPos(b);
+    int curpos = flist->GetItemPos(flist->GetItemCurrent());
+    int newpos = flist->GetItemPos(b);
 
     if (newpos > curpos)
-        list->MoveDown(newpos - curpos);
+        flist->MoveDown(newpos - curpos);
     else if (newpos < curpos)
-        list->MoveUp(curpos - newpos);
+        flist->MoveUp(curpos - newpos);
     return true;
 }
 
 
-void MythControls::leftSelected(UIListBtnTypeItem*)
+void MythControls::LeftSelected(UIListBtnTypeItem*)
 {
-    LeftList->refresh();
-    RightList->blockSignals(true);
-    refreshRightList();
-    RightList->blockSignals(false);
-    RightList->refresh();
+    m_LeftList->refresh();
+    m_RightList->blockSignals(true);
+    RefreshRightList();
+    m_RightList->blockSignals(false);
+    m_RightList->refresh();
+    m_Description->SetText("");
 }
 
-void MythControls::rightSelected(UIListBtnTypeItem*)
+void MythControls::RightSelected(UIListBtnTypeItem*)
 {
-    RightList->refresh();
-    refreshKeyInformation();
+    m_RightList->refresh();
+    RefreshInformation();
 }
 
+void MythControls::RefreshRight(QStringList * strings)
+{
+    m_RightList->blockSignals(true);
+    m_RightList->Reset();
 
+    strings->sort();
 
+    for (size_t i = 0; i < strings->size(); i++)
+    {
+        UIListBtnTypeItem *item = new UIListBtnTypeItem(m_RightList,(*strings)[i]);
+        item->setDrawArrow(false);
+    }
+
+    m_RightList->blockSignals(false);
+    m_RightList->refresh();
+}
+
 /* method description in header */
-void MythControls::refreshRightList()
+void MythControls::RefreshLeft(QStringList * strings)
 {
-    RightList->Reset();
+    m_LeftList->blockSignals(true);
+    m_LeftList->Reset();
 
-    if (LeftList->GetItemCurrent() == NULL)
-        return;
+    /* sort the strings */
+    strings->sort();
 
-    if (leftType == kContextList)
+    for (size_t i = 0; i < strings->size(); i++)
     {
-        if (rightType == kActionList)
-        {
-            /* add all of the actions to the context list */
-            QString context = LeftList->GetItemCurrent()->text();
-            QStringList *actions = m_contexts[context];
-            if (actions == NULL)
-            {
-                VERBOSE(VB_IMPORTANT, QString("MythControls: Unable to find actions for context %1").arg(context));
-                return;
-            }
-            UIListBtnTypeItem *item;
-            for (size_t i = 0; i < actions->size(); i++)
-                item = new UIListBtnTypeItem(RightList, (*actions)[i]);
-        }
-        else if (rightType == kKeyList)
-        {
-            /* add all of the actions to the context list */
-            QString context = LeftList->GetItemCurrent()->text();
-            BindingList *list = contextKeys[context];
-            if (list == NULL)
-            {
-                VERBOSE(VB_IMPORTANT, QString("MythControls: Unable to find keys for context %1").arg(context));
-                return;
-            }
-            UIListBtnTypeItem *item;
-            for (BindingList::iterator it = list->begin(); it != list->end(); ++it)
-            {
-                binding_t *b = *it;
-                item = new UIListBtnTypeItem(RightList, KeyToDisplay(b->key) + " => " + b->action);
-            }
-        }
-    } else if (leftType == kKeyList && rightType == kContextList)
-    {
-        QString key = DisplayToKey(LeftList->GetItemCurrent()->text());
-        BindingList *list = keyActions[key];
-        if (list == NULL)
-        {
-            VERBOSE(VB_IMPORTANT, QString("MythControls: Unable to find actions for key %1").arg(key));
-            return;
-        }
-        UIListBtnTypeItem *item;
-        BindingList::iterator it = list->begin();
-        binding_t *b = *it;
-        for (size_t i = 0; i < contexts.size(); i++)
-        {
-            QString context = contexts[i];
-            QString action = "<none>";
-            if (b && b->context == context)
-            {
-                action = b->action;
-                ++it;
-                if (it != list->end()) b = *it;
-                else b = NULL;
-            }
-            item = new UIListBtnTypeItem(RightList, context + " => " + action);
-        }
+        UIListBtnTypeItem *item = new UIListBtnTypeItem(m_LeftList, (*strings)[i]);
+        item->setDrawArrow(true);
     }
+
+    m_LeftList->blockSignals(false);
+    m_LeftList->refresh();
 }
 
 
-/* comments in header */
-void MythControls::refreshKeyInformation()
+/* method description in mythcontrols.h */
+void MythControls::RefreshRightList()
 {
-    /* get the description of the current action */
-    QString desc;
+    QStringList *rstrings = NULL;
+    QString lstring = m_LeftList->GetItemCurrent()->text();
 
-    if (focused == LeftList)
+    /* right list, based on values from the left */
+    switch (m_View)
     {
-        /* blank all keys on the context */
-        for (size_t i = 0; i < Action::MAX_KEYS; i++)
-            ActionButtons[i]->setText("");
+    case ActionsByContext:
+        this->ShowButtons(true);
+        rstrings = m_KeyBindings->GetActions(lstring);
+        break;
+    case ActionsByKey:
+        this->ShowButtons(false);
+        rstrings = m_KeyBindings->GetKeyActions(lstring);
+        break;
+    case ContextsByKey:
+        this->ShowButtons(false);
+        rstrings = m_KeyBindings->GetContexts(lstring);
+        break;
     }
-    else if (leftType == kKeyList || rightType == kKeyList)
-    { // Should show appropriate description 
-        QString action = getCurrentAction();
-        QString context = getCurrentContext();
-        /* blank all keys on the context */
-        for (size_t i = 0; i < Action::MAX_KEYS; i++)
-            ActionButtons[i]->setText("");
-        if (!action.isEmpty())
-            {
-    
-            desc = key_bindings->getActionDescription(context, action);
-    
-            BindingList *list = NULL;
-            if (leftType == kKeyList && rightType == kContextList)
-            {
-                QString key = getCurrentKey();
-                list = keyActions[DisplayToKey(key)];
-            }
-            else if (leftType == kContextList && rightType == kKeyList)
-                list = contextKeys[context];
-            if (list)
-            {
-                QString searchKey;
-                if (rightType == kContextList)
-                    searchKey = context;
-                else if (rightType == kActionList)
-                    searchKey = action;
-                else if (rightType == kKeyList)
-                    searchKey = DisplayToKey(getCurrentKey());
-                binding_t *binding = NULL;
-                for (BindingList::iterator it = list->begin(); it != list->end(); ++it)
-                {
-                    binding_t *b = *it;
-                    switch (rightType)
-                    {
-                        case kContextList:
-                            if (b->context == searchKey) binding = b;
-                            break;
-                        case kActionList:
-                            if (b->action == searchKey) binding = b;
-                            break;
-                        case kKeyList:
-                            if (b->key == searchKey) binding = b;
-                            break;
-                    }
-                    if (binding) break;
-                }
-    
-                if (binding)
-                {
-                    if (desc.isEmpty() && context != binding->contextFrom)
-                        desc = key_bindings->getActionDescription(binding->contextFrom, action);
-                    desc += "\n" + tr("Binding comes from %1 context")
-                            .arg(binding->contextFrom);
-                }
-            }
-        }
-    } else {
-        QString context = getCurrentContext();
-        QString action = getCurrentAction();
-        /* set the description */
-        desc = key_bindings->getActionDescription(getCurrentContext(),
-                                                  getCurrentAction());
 
-        /* get the bindings of the current action */
-        QStringList keys = key_bindings->getActionKeys(getCurrentContext(),
-                                                       getCurrentAction());
+    RefreshRight(rstrings);
+    delete rstrings;
+}
 
-        size_t i;
 
-        /* fill existing keys */
-        for (i = 0; i < keys.count(); i++)
-            ActionButtons[i]->setText(KeyToDisplay(keys[i]));
+void MythControls::RefreshBindingInformation()
+{
+    QString context = m_LeftList->GetItemCurrent()->text();
+    QString action = m_RightList->GetItemCurrent()->text();
+    QString desc = m_KeyBindings->GetActionDescription(GetCurrentContext(),
+                                                       GetCurrentAction());
 
-        /* blank the other ones */
-        for (; i < Action::MAX_KEYS; i++)
-            ActionButtons[i]->setText("");
-    }
+    /* get the bindings of the current action */
+    QStringList keys = m_KeyBindings->GetActionKeys(GetCurrentContext(),
+                                                    GetCurrentAction());
 
-    /* set the information */
-    description->SetText(desc);
+    FillButtons(keys);
+
+    m_Description->SetText(desc);
 }
 
 
-
-/* comments in header */
-QString MythControls::getCurrentContext(void) const
+/* method description in mythcontrols.h */
+void MythControls::RefreshInformation()
 {
-    if (leftType == kContextList)
-        return LeftList->GetItemCurrent()->text();
-    if (focused == LeftList) return "";
-
-    QString desc = RightList->GetItemCurrent()->text();
-    int loc = desc.find(" => ");
-    if (loc == -1) return ""; // Should not happen
-    if (rightType == kContextList) return desc.left(loc);
-    else return desc.mid(loc+4);
+    switch (m_View)
+    {
+    case ActionsByContext:
+        if (m_Focused == m_LeftList)
+        {
+            BlankButtons();
+            m_Description->SetText("");
+        }
+        else
+            RefreshBindingInformation();
+        break;
+    case ActionsByKey:
+        if (m_Focused == m_LeftList)
+            m_Description->SetText("");
+        else
+        {
+            QString key = m_LeftList->GetItemCurrent()->text();
+            QString action = m_RightList->GetItemCurrent()->text();
+            int pos = m_RightList->GetItemPos(m_RightList->GetItemCurrent());
+            QString context = m_KeyBindings->GetContext(key, action, pos);
+            QString desc = m_KeyBindings->GetActionDescription(context, action);
+            desc += "\n" + tr("Binding comes from %1 context").arg(context);
+            m_Description->SetText(desc);
+        }
+        break;
+    case ContextsByKey:
+        if (m_Focused == m_LeftList)
+            m_Description->SetText("");
+        else
+        {
+            QString key = m_LeftList->GetItemCurrent()->text();
+            QString context = m_RightList->GetItemCurrent()->text();
+            QString action = m_KeyBindings->GetAction(key, context);
+            QString desc = action + ": " +
+                m_KeyBindings->GetActionDescription(context, action);
+            m_Description->SetText(desc);
+        }
+        break;
+    }
 }
 
 /* comments in header */
-QString MythControls::getCurrentAction(void) const
+QString MythControls::GetCurrentContext(void) const
 {
-    if (leftType == kActionList)
-        return LeftList->GetItemCurrent()->text();
-    if (focused == LeftList) return "";
-
-    QString desc = RightList->GetItemCurrent()->text();
-    if (leftType == kContextList && rightType == kActionList)
-        return desc;
-    int loc = desc.find(" => ");
-    if (loc == -1) return ""; // Should not happen
-    if (rightType == kActionList) return desc.left(loc);
+    if (m_View == ActionsByContext)
+        return m_LeftList->GetItemCurrent()->text();
+    else if ((m_View == ContextsByKey) && (m_Focused == m_RightList))
+        return m_RightList->GetItemCurrent()->text();
     else
-    {
-        QString rv = desc.mid(loc+4);
-        if (rv == "<none>") return "";
-        else return rv;
-    }
+        return "";
 }
 
 /* comments in header */
-QString MythControls::getCurrentKey(void) const
+QString MythControls::GetCurrentAction(void) const
 {
-    if (leftType == kKeyList)
-        return LeftList->GetItemCurrent()->text();
-    if (focused == LeftList) return "";
 
-    if (leftType == kContextList && rightType == kActionList)
-    {
-        QString context = getCurrentContext();
-        QString action = getCurrentAction();
-        size_t b = focusedButton();
-        QStringList keys = key_bindings->getActionKeys(context, action);
-        if (b < keys.count()) return keys[b];
-        else return "";
-    }
-
-    QString desc = RightList->GetItemCurrent()->text();
-    int loc = desc.find(" => ");
-    if (loc == -1) return ""; // Should not happen
-    if (rightType == kKeyList) return desc.left(loc);
-    else return desc.mid(loc+4);
+    if (((m_View == ActionsByContext) && (m_Focused != m_LeftList)) ||
+        ((m_View == ActionsByKey) && (m_Focused == m_RightList)))
+        return m_RightList->GetItemCurrent()->text();
+    else
+        return "";
 }
 
-
 /* comments in header */
-void MythControls::loadHost(const QString & hostname) {
-
-    /* create the key bindings and the tree */
-    key_bindings = new KeyBindings(hostname);
-    contexts = *key_bindings->getContexts();
-
-    keys.clear();
-
-    /* Alphabetic order, but jump and global at the top  */
-    contexts.sort();
-    contexts.remove(JUMP_CONTEXT);
-    contexts.remove(GLOBAL_CONTEXT);
-    contexts.insert(contexts.begin(), 1, GLOBAL_CONTEXT);
-    contexts.insert(contexts.begin(), 1, JUMP_CONTEXT);
-
-    QStringList *actions;
-    for (size_t i = 0; i < contexts.size(); i++)
+QString MythControls::GetCurrentKey(void) const
+{
+    if (m_View == ActionsByContext)
     {
-        actions = key_bindings->getActions(contexts[i]);
-        actions->sort();
-        m_contexts.insert(contexts[i], actions);
+        QString context = GetCurrentContext();
+        QString action = GetCurrentAction();
+        size_t b = FocusedButton();
+        QStringList keys = m_KeyBindings->GetActionKeys(context, action);
+        if (b < keys.count())
+            return keys[b];
+        else
+            return "";
     }
-
-    refreshKeyBindings();
-    updateLists();
+    else
+        return m_LeftList->GetItemCurrent()->text();
 }
 
-
-
 /* comments in header */
-void MythControls::deleteKey()
+void MythControls::DeleteKey()
 {
     // This code needs work to support deleteKey in any mode exc. Context/Action
-    QString context = getCurrentContext();
-    QString key = getCurrentKey();
-    QString action = getCurrentAction();
+    QString context = GetCurrentContext();
+    QString key = GetCurrentKey();
+    QString action = GetCurrentAction();
+
     if (context.isEmpty() || key.isEmpty() || action.isEmpty())
     {
         InvalidBindingPopup popup(gContext->GetMainWindow());
@@ -710,52 +697,31 @@
         return;
     }
 
-    BindingList *list = keyActions[key];
-    binding_t *binding = NULL;
-    for (BindingList::iterator it = list->begin(); it != list->end(); ++it)
+    if (m_View == ActionsByContext)
     {
-        binding_t *b = *it;
-        if (b->context == context) binding = b;
+        QString trtext =
+            tr("Delete this key binding from context %1?").arg(context);
+        ConfirmMenu popup(gContext->GetMainWindow(), trtext);
+        if (popup.getOption() != ConfirmMenu::CONFIRM)
+            return;
+        else
+        {
+            m_KeyBindings->RemoveActionKey(context, action, key);
+        }
     }
-    if (!binding)
-    {
-        InvalidBindingPopup popup(gContext->GetMainWindow());
-        popup.getOption();
-        return;
-    }
 
-    if (binding->contextFrom != context)
-    {
-        ConfirmMenu popup(gContext->GetMainWindow(), tr("Delete this key binding from context %1?").arg(binding->contextFrom));
-        if (popup.getOption() != ConfirmMenu::CONFIRM) return;
-    } else {
-        ConfirmMenu popup(gContext->GetMainWindow(), tr("Delete this binding?"));
-        if (popup.getOption() != ConfirmMenu::CONFIRM) return;
-    }
-
-    if (!key_bindings->removeActionKey(binding->contextFrom, action, key))
-    {
-        InvalidBindingPopup popup(gContext->GetMainWindow());
-        popup.getOption();
-        return;
-    }
-
-    // refreshing everything is overkill.  I tried incrementally updating, but the
-    // code was ugly.  Since this is quick in my experience, overkill away!
-    refreshKeyBindings();
-    refreshKeyInformation();
+    RefreshInformation();
 }
 
 /* method description in header */
-bool MythControls::resolveConflict(ActionID *conflict, int level)
+bool MythControls::ResolveConflict(ActionID *conflict, int level)
 {
     MythMainWindow *window = gContext->GetMainWindow();
 
     /* prevent a fatal binding */
     if (level == KeyBindings::Error)
     {
-        InvalidBindingPopup popup(gContext->GetMainWindow(),
-                                  conflict->action(),
+        InvalidBindingPopup popup(gContext->GetMainWindow(), conflict->action(),
                                   conflict->context());
         popup.getOption();
         return false;
@@ -778,9 +744,8 @@
 
 
 /* method description in header */
-void MythControls::addKeyToAction(void)
+void MythControls::AddKeyToAction(void)
 {
-    // This code needs work to support deleteKey in any mode exc. Context/Action
     /* grab a key from the user */
     KeyGrabPopupBox *kg = new KeyGrabPopupBox(gContext->GetMainWindow());
     int result = kg->ExecPopup(kg,SLOT(cancel()));
@@ -788,238 +753,41 @@
     delete kg;
 
     /* go no further if canceled */
-    if (result == 0) return;
+    if (result == 0)
+        return;
 
     /* get the keys for the selected action */
-    size_t b = focusedButton();
-    QString action = getCurrentAction(), context = getCurrentContext();
-    QStringList keys = key_bindings->getActionKeys(context, action);
+    size_t b = FocusedButton();
+    QString action = GetCurrentAction(), context = GetCurrentContext();
+    QStringList keys = m_KeyBindings->GetActionKeys(context, action);
 
     /* dont bother rebinding the same key */
-    if (keys[b] == key) return;
+    if (keys[b] == key)
+        return;
 
     bool bind = true;
     int level;
 
     /* get the potential conflict */
     ActionID *conflict = NULL;
-    if ((conflict = key_bindings->conflicts(context, key, level)))
-        bind = resolveConflict(conflict, level);
+    if ((conflict = m_KeyBindings->Conflicts(context, key, level)))
+        bind = ResolveConflict(conflict, level);
 
     delete conflict;
 
     /* dont bind if we shouldn't bind */
-    if (!bind) return;
+    if (!bind)
+        return;
 
     /* finally bind or rebind a key to the action */
     if (b < keys.count())
-        key_bindings->replaceActionKey(context,action, key, keys[b]);
+        m_KeyBindings->ReplaceActionKey(context,action, key, keys[b]);
     else
-        key_bindings->addActionKey(context, action, key);
+        m_KeyBindings->AddActionKey(context, action, key);
 
-    refreshKeyBindings();
-    refreshKeyInformation();
+    RefreshInformation();
 }
 
-
-
-void MythControls::addBindings(QDict<binding_t> &bindings,
-                               const QString &context,
-                               const QString &contextParent, int bindlevel)
-{
-    QStringList *actions = key_bindings->getActions(context);
-
-    for (size_t i = 0; i < actions->size(); i++)
-    {
-        QString action = (*actions)[i];
-        QStringList keys = key_bindings->getActionKeys(context, action);
-
-        for (size_t j = 0; j < keys.size(); j++)
-        {
-            QString key = keys[j];
-
-            binding_t *b = bindings.find(key);
-            if (!b) 
-            {
-                b = new(binding_t);
-                b->key = key;
-                b->action = action;
-                b->context = contextParent;
-                b->contextFrom = context;
-                b->bindlevel = bindlevel;
-                bindings.insert(key, b);
-            }
-            else if (b->bindlevel == bindlevel)
-            {
-                b->action += ", " + action;
-            }
-        }
-    }
-}
-
-BindingList *MythControls::getKeyBindings(const QString &context)
-{
-    QStringList keys;
-    QDict<binding_t> bindings;
-    bindings.clear();
-
-    for (size_t i = 0; i < contexts.size(); i++)
-        addBindings(bindings, contexts[i], context, i);
-
-
-    for (QDictIterator<binding_t> it(bindings); it.current(); ++it)
-    {
-        QString key = it.currentKey();
-        keys.append(key);
-    }
-
-    sortKeyList(keys);
-
-    BindingList *retval = new BindingList;
-    retval->clear();
-
-    for (QStringList::Iterator kit = keys.begin(); kit != keys.end(); ++kit)
-    {
-        QString key = *kit;
-        retval->append(bindings[key]);
-    }
-    retval->setAutoDelete(true);
-    return retval;
-}
-
-void MythControls::refreshKeyBindings()
-{
-    contextKeys.clear();
-    keyActions.clear();
-    for (size_t i = 0; i < contexts.size(); i++)
-    {
-        QString context = contexts[i];
-        BindingList *list = getKeyBindings(context);
-        contextKeys.insert(context, list);
-        for (BindingList::iterator it = list->begin(); it != list->end(); ++it)
-        {
-            binding_t *b = *it;
-            BindingList *list = keyActions.find(b->key);
-            if (!list)
-            {
-                list = new BindingList;
-                list->clear();
-                keyActions.insert(b->key, list);
-            }
-            keys.append(b->key);
-            list->append(b);
-        }
-    }
-    contextKeys.setAutoDelete(true);
-    keyActions.setAutoDelete(true);
-
-    sortKeyList(keys);
-}
-
-void MythControls::sortKeyList(QStringList &keys)
-{
-    QStringList t;
-    t.clear();
-
-    for ( QStringList::Iterator it = keys.begin(); it != keys.end(); ++it )
-    {
-        QString key = *it;
-
-        QString keydesc = "3 ";
-        if (key.left(6) == "remote")
-        {
-            keydesc = "0 ";
-        }
-        else if (key.length() == 1)
-        {
-            switch (key[0].category())
-            {
-                case QChar::Letter_Uppercase:
-                    keydesc = "2 ";
-                    break;
-                case QChar::Number_DecimalDigit:
-                    keydesc = "1 ";
-                    break;
-                default:
-                    keydesc = "5 ";
-                    break;
-            }
-        }
-        else if (key.find("+", 1) != -1)
-            keydesc = "4 ";
-
-        t.push_back(keydesc + key);
-    }
-    t.sort();
-
-    QString prev = "";
-
-    keys.clear();
-    for (QStringList::Iterator kit = t.begin(); kit != t.end(); ++kit)
-    {
-        QString cur = (*kit).mid(2);
-        if (cur != prev) 
-        {
-            keys.append(cur);
-            prev = cur;
-        }
-    }
-}
-
-QString MythControls::getTypeDesc(ListType type)
-{
-    switch (type)
-    {
-        case kContextList:
-            return tr("Contexts");
-            break;
-        case kKeyList:
-            return tr("Keys");
-            break;
-        case kActionList:
-            return tr("Actions");
-            break;
-        default:
-            return "";
-    }
-}
-
-void MythControls::updateLists()
-{
-    RightList->blockSignals(true);
-    LeftList->blockSignals(true);
-    LeftList->Reset();
-    if (leftType == kContextList)
-    {
-        UIListBtnTypeItem *item;
-        for (size_t i = 0; i < contexts.size(); i++)
-        {
-            item = new UIListBtnTypeItem(LeftList, contexts[i]);
-            item->setDrawArrow(true);
-        }
-    } else if (leftType == kKeyList)
-    {
-        UIListBtnTypeItem *item;
-        for (size_t i = 0; i < keys.size(); i++)
-        {
-            QString key = KeyToDisplay(keys[i]);
-            item = new UIListBtnTypeItem(LeftList, key);
-            item->setDrawArrow(true);
-        }
-    }
-    refreshRightList();
-    RightList->blockSignals(false);
-    LeftList->blockSignals(false);
-    LeftList->refresh();
-    RightList->refresh();
-
-    if (LeftDesc != NULL)
-        LeftDesc->SetText(getTypeDesc(leftType));
-    if (RightDesc != NULL)
-        RightDesc->SetText(getTypeDesc(rightType));
-}
-
-
 #endif /* MYTHCONTROLS_CPP */
 
 /* vim: set expandtab tabstop=4 shiftwidth=4: */
Index: mythcontrols/keybindings.cpp
===================================================================
--- mythcontrols/keybindings.cpp	(revision 10604)
+++ mythcontrols/keybindings.cpp	(working copy)
@@ -26,10 +26,7 @@
  * and the UI.
  */
 
-/* QT */
 #include <qstring.h>
-
-/* MythTV */
 #include <mythtv/mythcontext.h>
 #include <mythtv/mythdialogs.h>
 
@@ -38,22 +35,69 @@
 #include "keybindings.h"
 
 
-
 KeyBindings::KeyBindings(const QString & hostname)
 {
-    this->hostname() = hostname;
-    loadManditoryBindings();
+    m_HostName = hostname;
+    LoadMandatoryBindings();
 
-    retrieveContexts();
-    retrieveJumppoints();
+    RetrieveContexts();
+    RetrieveJumppoints();
 }
 
+QStringList * KeyBindings::GetKeyActions(const QString &key) const
+{
+    QStringList *strings;
+    const ActionList & al = m_ActionSet.GetActions(key);
 
+    if (al.size() > 0)
+        strings = new QStringList();
+    else
+        return NULL;
 
-ActionID * KeyBindings::conflicts(const QString & context_name,
+    for (size_t i = 0; i < al.size(); i++)
+        strings->push_back(al[i].action());
+
+    return strings;
+}
+
+
+QString KeyBindings::GetContext(const QString & key, const QString & action,
+                                size_t anum) const
+{
+    /* The cases where unknown is returned should never happen.  If
+     * you see an unknown context, do not approach it.  Call the
+     * police immediatly. */
+    const ActionList &al = m_ActionSet.GetActions(key);
+    int offset = al.size() - anum;
+
+    if (offset < 0)
+        return "UNKNOWN";
+    else if (al[anum].action() != action)
+        return "UNKNOWN";
+    if (anum < al.size())
+        return al[anum].context();
+    else
+        return "UNKNOWN";
+}
+
+QString KeyBindings::GetAction(const QString & key,
+                               const QString & context) const
+{
+    const ActionList &al = m_ActionSet.GetActions(key);
+
+    for (size_t i = 0; i < al.size(); i++)
+    {
+        if (al[i].context() == context)
+            return al[i].action();
+    }
+    return "UNKNOWN";
+}
+
+
+ActionID * KeyBindings::Conflicts(const QString & context_name,
                                   const QString & key, int &level) const
 {
-    const ActionList &ids = actionset.getActions(key);
+    const ActionList &ids = m_ActionSet.GetActions(key);
 
     /* trying to bind a jumppoint to an already bound key */
     if ((context_name == JUMP_CONTEXT) && (ids.count() > 0))
@@ -84,24 +128,25 @@
 
 
 /* method description in header */
-bool KeyBindings::removeActionKey(const QString & context_name,
+bool KeyBindings::RemoveActionKey(const QString & context_name,
                                   const QString & action_name,
                                   const QString & key)
 {
 
     ActionID id(context_name, action_name);
 
-    /* dont remove the last manditory binding */
-    if (getManditoryBindings().contains(id)&&(actionset.getKeys(id).count()<2))
+    /* dont remove the last mandatory binding */
+    if (getMandatoryBindings().contains(id) &&
+        (m_ActionSet.GetKeys(id).count()<2))
         return false;
     else
-        return this->actionset.remove(id,key);
+        return this->m_ActionSet.Remove(id,key);
 }
 
 
 
 /* method description in header */
-void KeyBindings::commitAction(const ActionID & id)
+void KeyBindings::CommitAction(const ActionID & id)
 {
 
     MSqlQuery query(MSqlQuery::InitCon());
@@ -112,8 +157,8 @@
 
     if (query.isConnected())
     {
-        QString keys = actionset.keyString(id);
-        query.bindValue(":HOSTNAME", this->getHostname());
+        QString keys = m_ActionSet.KeyString(id);
+        query.bindValue(":HOSTNAME", m_HostName);
         query.bindValue(":CONTEXT", id.context());
         query.bindValue(":ACTION", id.action());
         query.bindValue(":KEYLIST", keys);
@@ -131,7 +176,7 @@
 
 
 
-void KeyBindings::commitJumppoint(const ActionID &id)
+void KeyBindings::CommitJumppoint(const ActionID &id)
 {
 
     MSqlQuery query(MSqlQuery::InitCon());
@@ -142,8 +187,8 @@
 
     if (query.isConnected())
     {
-        QString keys = actionset.keyString(id);
-        query.bindValue(":HOSTNAME", this->getHostname());
+        QString keys = m_ActionSet.KeyString(id);
+        query.bindValue(":HOSTNAME", this->m_HostName);
         query.bindValue(":DESTINATION", id.action());
         query.bindValue(":KEYLIST", keys);
 
@@ -161,20 +206,22 @@
 
 
 
-void KeyBindings::commitChanges(void)
+void KeyBindings::CommitChanges(void)
 {
-    ActionList modified = actionset.getModified();
+    ActionList modified = m_ActionSet.GetModified();
 
     while (modified.size() > 0)
     {
         ActionID id = modified.front();
 
         /* commit either a jumppoint or an action */
-        if (id.context() == JUMP_CONTEXT) commitJumppoint(id);
-        else commitAction(id);
+        if (id.context() == JUMP_CONTEXT)
+            CommitJumppoint(id);
+        else
+            CommitAction(id);
 
         /* tell the action set that the action is no longer modified */
-        actionset.unmodify(id);
+        m_ActionSet.Unmodify(id);
 
         modified.pop_front();
     }
@@ -182,7 +229,7 @@
 
 
 
-void KeyBindings::retrieveJumppoints()
+void KeyBindings::RetrieveJumppoints()
 {
     MSqlQuery query(MSqlQuery::InitCon());
 
@@ -192,7 +239,7 @@
                       "FROM jumppoints "
                       "WHERE hostname = :HOSTNAME "
                       "ORDER BY destination ;");
-        query.bindValue(":HOSTNAME", this->getHostname());
+        query.bindValue(":HOSTNAME", m_HostName);
     }
 
     query.exec();
@@ -202,18 +249,17 @@
         ActionID id(JUMP_CONTEXT, query.value(0).toString());
 
         if (query.value(1).toString().isEmpty())
-        {
-            actionset.addAction(id, query.value(0).toString(),
-                                query.value(2).toString());
-        }
-        else actionset.addAction(id,query.value(1).toString(),
-                                 query.value(2).toString());
+            m_ActionSet.AddAction(id, query.value(0).toString(),
+                                  query.value(2).toString());
+        else
+            m_ActionSet.AddAction(id,query.value(1).toString(),
+                                  query.value(2).toString());
     }
 }
 
 
 
-void KeyBindings::retrieveContexts()
+void KeyBindings::RetrieveContexts()
 {
 
     MSqlQuery query(MSqlQuery::InitCon());
@@ -225,7 +271,7 @@
                       "WHERE hostname = :HOSTNAME "
                       "ORDER BY context,action ;");
 
-        query.bindValue(":HOSTNAME", this->getHostname());
+        query.bindValue(":HOSTNAME", this->m_HostName);
     }
 
     query.exec();
@@ -233,45 +279,45 @@
     for (query.next(); query.isValid(); query.next())
     {
         ActionID id(query.value(0).toString(), query.value(1).toString());
-        this->actionset.addAction(id, query.value(2).toString(),
-                                  query.value(3).toString());
+        this->m_ActionSet.AddAction(id, query.value(2).toString(),
+                                    query.value(3).toString());
     }
 }
 
 
 
-void KeyBindings::loadManditoryBindings(void)
+void KeyBindings::LoadMandatoryBindings(void)
 {
-    if (getManditoryBindings().empty())
+    if (m_MandatoryBindings.empty())
     {
-        manditoryBindings().append(ActionID(GLOBAL_CONTEXT, "DOWN"));
-        defaultKeys().append("Down");
+        m_MandatoryBindings.append(ActionID(GLOBAL_CONTEXT, "DOWN"));
+        m_DefaultKeys.append("Down");
 
-        manditoryBindings().append(ActionID(GLOBAL_CONTEXT, "UP"));
-        defaultKeys().append("Up");
+        m_MandatoryBindings.append(ActionID(GLOBAL_CONTEXT, "UP"));
+        m_DefaultKeys.append("Up");
 
-        manditoryBindings().append(ActionID(GLOBAL_CONTEXT, "LEFT"));
-        defaultKeys().append("Left");
+        m_MandatoryBindings.append(ActionID(GLOBAL_CONTEXT, "LEFT"));
+        m_DefaultKeys.append("Left");
 
-        manditoryBindings().append(ActionID(GLOBAL_CONTEXT, "RIGHT"));
-        defaultKeys().append("Right");
+        m_MandatoryBindings.append(ActionID(GLOBAL_CONTEXT, "RIGHT"));
+        m_DefaultKeys.append("Right");
 
-        manditoryBindings().append(ActionID(GLOBAL_CONTEXT, "ESCAPE"));
-        defaultKeys().append("Esc");
+        m_MandatoryBindings.append(ActionID(GLOBAL_CONTEXT, "ESCAPE"));
+        m_DefaultKeys.append("Esc");
 
-        manditoryBindings().append(ActionID(GLOBAL_CONTEXT, "SELECT"));
-        defaultKeys().append("Return,Enter,Space");
+        m_MandatoryBindings.append(ActionID(GLOBAL_CONTEXT, "SELECT"));
+        m_DefaultKeys.append("Return,Enter,Space");
     }
 }
 
 
 
-bool KeyBindings::hasManditoryBindings(void) const
+bool KeyBindings::HasMandatoryBindings(void) const
 {
-    ActionList manlist = getManditoryBindings();
+    ActionList manlist = getMandatoryBindings();
     for (size_t i = 0; i < manlist.count(); i++)
     {
-        if (actionset.getKeys(manlist[i]).isEmpty())
+        if (m_ActionSet.GetKeys(manlist[i]).isEmpty())
             return false;
     }
 
Index: mythcontrols/actionset.cpp
===================================================================
--- mythcontrols/actionset.cpp	(revision 10604)
+++ mythcontrols/actionset.cpp	(working copy)
@@ -36,21 +36,21 @@
 
 
 /* method description in header */
-bool ActionSet::add(const ActionID &id, const QString &key)
+bool ActionSet::Add(const ActionID &id, const QString &key)
 {
     Action *a;
 
     /* get the action; make sure it exists before doing anything */
-    if ((a = this->action(id)))
+    if ((a = this->GetAction(id)))
     {
 
         /* if the key was added, mark this action as modified, and
            update the key map */
-        if (a->addKey(key))
+        if (a->AddKey(key))
         {
-            ActionList &ids = _keymap[key];
+            ActionList &ids = m_KeyMap[key];
             ids.push_back(id);
-            this->modify(id);	
+            this->Modify(id);	
             return true;
         }
     }
@@ -61,23 +61,23 @@
 
 
 /* method description in header */
-bool ActionSet::remove(const ActionID &id, const QString & key)
+bool ActionSet::Remove(const ActionID &id, const QString & key)
 {
 
     Action *a;
 
     /* make sure an action exists before removing */
-    if ((a = this->action(id)))
+    if ((a = this->GetAction(id)))
     {
         /* if the key was removed from the action, then remove it from
          * the key list, and mark the action id as modified */
-        if (a->removeKey(key))
+        if (a->RemoveKey(key))
         {
             /* remove the action from the key map */
-            this->_keymap[key].remove(id);
+            this->m_KeyMap[key].remove(id);
 
             /* mark the action as modified */
-            this->modify(id);
+            this->Modify(id);
 
             return true;	    
         }
@@ -90,26 +90,26 @@
 
 
 /* method description in header */
-bool ActionSet::replace(const ActionID &id, const QString &newkey,
+bool ActionSet::Replace(const ActionID &id, const QString &newkey,
                         const QString &oldkey)
 {
     Action *a;
 
     /* make sure an action exists before replacing */
-    if ((a = this->action(id)))
+    if ((a = this->GetAction(id)))
     {
 
         /* make sure the key was actually replaced before modifying */
-        if (a->replaceKey(newkey, oldkey))
+        if (a->ReplaceKey(newkey, oldkey))
         {
             /* remove the action from the old key */
-            this->_keymap[oldkey].remove(id);
+            this->m_KeyMap[oldkey].remove(id);
 
             /* add the action to the new key */
-            this->_keymap[newkey].push_back(id);
+            this->m_KeyMap[newkey].push_back(id);
 
             /* mark the action as modified */
-            this->modify(id);
+            this->Modify(id);
 
             /* the job is done, return true */
             return true;	    
@@ -123,10 +123,10 @@
 
 
 /* method description in header */
-QStringList * ActionSet::contextStrings(void) const
+QStringList * ActionSet::ContextStrings(void) const
 {
     QStringList *context_strings = new QStringList();
-    QDictIterator<Context> it(_contexts);
+    QDictIterator<Context> it(m_Contexts);
 
     for (; it.current(); ++it)
         context_strings->append(it.currentKey());
@@ -137,15 +137,16 @@
 
 
 /* method description in header */
-QStringList * ActionSet::actionStrings(const QString &context_name) const
+QStringList * ActionSet::ActionStrings(const QString &context_name) const
 {
-    Context *c = _contexts[context_name];
+    Context *c = m_Contexts[context_name];
 
-    if (c == NULL) return NULL;
+    if (c == NULL)
+        return NULL;
     else
     {
         QStringList *action_strings = new QStringList();
-        QDictIterator<Action> it(*(_contexts[context_name]));
+        QDictIterator<Action> it(*(m_Contexts[context_name]));
 
         for (; it.current(); ++it)
             action_strings->append(it.currentKey());
@@ -154,54 +155,114 @@
     }
 }
 
+QStringList * ActionSet::GetAllKeys(void) const
+{
+    return new QStringList(this->m_KeyMap.keys());
+}
 
 
+QStringList * ActionSet::GetAllActions(void) const
+{
+    return new QStringList(this->m_Actions.keys());
+}
+
+
+QStringList * ActionSet::GetKeyContexts(const QString &key) const
+{
+    QStringList *strings = NULL;
+    const ActionList &ids = m_KeyMap[key];
+
+    if (ids.size() == 0)
+        return NULL;
+
+    strings = new QStringList();
+
+    for (size_t i = 0; i < ids.size(); i++)
+    {
+        if (!strings->contains(ids[i].context()))
+            strings->push_back(ids[i].context());
+    }
+
+    return strings;
+}
+
+
 /* method description in header */
-bool ActionSet::addAction(const ActionID &id, const QString &description,
+bool ActionSet::AddAction(const ActionID &id, const QString &description,
                           const QString &keys)
 {
-    if (!_contexts[id.context()]) _contexts.insert(id.context(),
-                                                   new Context());
+    if (!m_Contexts[id.context()])
+        m_Contexts.insert(id.context(), new Context());
 
     /* return false if the action already exists */
-    if ((*_contexts[id.context()])[id.action()]) return false;
+    if ((*m_Contexts[id.context()])[id.action()])
+        return false;
     else
     {
         /* create the action */
         Action *a = new Action(description, keys);
 
         /* add the action into the dict */
-        _contexts[id.context()]->insert(id.action(), a);
+        m_Contexts[id.context()]->insert(id.action(), a);
 
+        /* if the action doesn't already exist, then add it */
+        QStringList &contexts = m_Actions[id.action()];
+        if (!contexts.contains(id.context()))
+            contexts.push_back(id.context());
+
         /* get the actions keys */
-        const QStringList &keys = a->getKeys();
+        const QStringList &keys = a->GetKeys();
         for (size_t i = 0; i < keys.count(); i++)
         {
             /* get the action list (of actions bound to keys[i])
                if there is no key, keys[i], in the map, it will be added now */
-            ActionList &ids = _keymap[keys[i]];
+            ActionList &ids = m_KeyMap[keys[i]];
 
             /* add this action id to the list of actions bound to this key */
-            ids.push_back(id);
+            if (ids.size() == 0)
+                ids.push_back(id);
+            else
+            {
+                bool added = false;
+                ActionList::iterator it;
+
+                /* keep list sorted by action, then by context.  You
+                 * must sort this stuff because multiple actions from
+                 * different contexts can be added. Otherwise, we get
+                 * into trouble in keybindings.cpp and
+                 * mythcontrols.cpp when trying to delete based on
+                 * action (displayed by key) */
+                for (it = ids.begin(); (it != ids.end()) && (added == false);
+                     ++it)
+                {
+                    if ((QString::compare(id.action(), (*it).action()) < 0) ||
+                        ((QString::compare(id.action(), (*it).action()) == 0) &&
+                         (QString::compare(id.context(), (*it).context()) < 0)))
+                    {
+                        ids.insert(it, id);
+                        added = true;
+                        break;
+                    }
+                }
+                if (added == false) ids.push_back(id);
+            }
         }
-
         return true;
     }
-
     return false;
 }
 
 
 
-QString ActionSet::keyString(const ActionID &id) const
+QString ActionSet::KeyString(const ActionID &id) const
 {
     Context *c;
-    if ((c = _contexts[id.context()]))
+    if ((c = m_Contexts[id.context()]))
     {
         Action *a;
         if ((a = (*c)[id.action()]))
         {
-            return a->keyString();
+            return a->KeyString();
         }
     }
     return QString::null;
@@ -209,44 +270,31 @@
 
 
 
-QStringList ActionSet::getKeys(const ActionID &id) const
+QStringList ActionSet::GetKeys(const ActionID &id) const
 {
     Context *c;
-    if ((c = _contexts[id.context()]))
+    if ((c = m_Contexts[id.context()]))
     {
         Action *a;
         if ((a = (*c)[id.action()]))
-        {
-            return a->getKeys();
-        }
+            return a->GetKeys();
     }
 
     return QStringList();
 }
 
 
-
-const QString & ActionSet::getDescription(const ActionID &id) const
+const QString & ActionSet::GetDescription(const ActionID &id) const
 {
     Context *c;
-    if ((c = _contexts[id.context()]))
+    if ((c = m_Contexts[id.context()]))
     {
         Action *a;
         if ((a = (*c)[id.action()]))
-        {
-            return a->getDescription();
-        }
+            return a->GetDescription();
     }
 
     return QString::null;
 }
 
-
-
-const ActionList & ActionSet::getActions(const QString &key) const
-{
-    return _keymap[key];
-}
-
-
 #endif /* ACTIONSET_CPP */
Index: mythcontrols/mythcontrols.h
===================================================================
--- mythcontrols/mythcontrols.h	(revision 10604)
+++ mythcontrols/mythcontrols.h	(working copy)
@@ -29,17 +29,6 @@
 
 #include "keybindings.h"
 
-typedef struct
-{
-    QString key;
-    QString context;
-    QString contextFrom;
-    QString action;
-    int bindlevel;
-} binding_t;
-
-typedef QPtrList<binding_t> BindingList;
-
 /**
  * @class MythControls
  * @brief The myth controls configuration class.
@@ -51,7 +40,8 @@
 
 public:
     /**
-     * @brief Create a new myth controls wizard.
+     * Create a new myth controls wizard.
+     *
      * @param parent The main myth window.
      * @param name The name of this window?  I dunno, none of the docs
      * say.
@@ -60,197 +50,214 @@
      */
     MythControls(MythMainWindow *parent, bool& ui_ok);
 
-    /**
-     * @brief Delete the myth controls object.
-     */
+    /** Delete the myth controls object. */
     ~MythControls();
 
     /**
-     * @brief Get the currently selected context string.
+     * Get the currently selected context string. If no context is
+     * selected, an empty string is returned.
+     *
      * @return The currently selected context string.
-     *
-     * If no context is selected, an empty string is returned.
      */
-    QString getCurrentContext(void) const;
+    QString GetCurrentContext(void) const;
 
     /**
-     * @brief Get the currently selected action string.
+     * Get the currently selected action string. If no action is
+     * selected, an empty string is returned.
+     *
      * @return The currently selected action string.
-     *
-     * If no action is selected, an empty string is returned.
      */
-    QString getCurrentAction(void) const;
+    QString GetCurrentAction(void) const;
 
     /**
-     * @brief Get the currently selected key string
+     * Get the currently selected key string.  If no context is
+     * selected, an empty string is returned.
+     *
      * @return The currently selected key string
-     *
-     * If no context is selected, an empty string is returned.
      */
-    QString getCurrentKey(void) const;
+    QString GetCurrentKey(void) const;
 
-    
-    
 protected:
 
+
+    /** The view mode */
+    typedef enum { ActionsByContext, ActionsByKey, ContextsByKey } ViewMode;
+
     /**
-     * @brief Load up UI.
-     * @return true if all UI elements were loaded successfully,
-     * otherwise false it returned.
+     * Load up UI.
      *
-     * This method grabs all of the UI "thingies" that are needed by
-     * mythcontrols.  If this method returns false, the plugin should
-     * exit since it will probably just core dump.
+     * @return true if all UI elements were loaded successfully
      */
-    bool loadUI();
+    bool LoadUI();
 
     /**
+     * Show or hide the buttons at the bottom.
+     *
+     * @param shown Should the buttons be shown?
+     */
+    void ShowButtons(bool shown) const;
+
+    /**
+     * Blank the text in the bottom buttons.
+     */
+    void BlankButtons(void) const;
+
+    /**
+     * Fill the buttons with the strings in a string list.
+     * @param strings The string list.
+     */
+    void FillButtons(const QStringList & strings);
+
+    /**
+     * Set the viewing mode of the plugin.
+     *
+     * @param view The view mode.
+     * @param force Force the view to be set (or reset)
+     */
+    void SetView(ViewMode newview, bool force=false);
+
+    /**
      * @brief The key press handler.
      * @param e The key event.
      */
     void keyPressEvent(QKeyEvent *e);
 
     /**
-     * @brief Redraw the key information
+     * Refresh the action description and key binding buttons.
+     */
+    void RefreshBindingInformation();
+
+    /**
+     * @brief Redraw the information at the bottom.
+     */
+    void RefreshInformation();
+
+    /**
+     * Refresh the right list.
      *
-     * Updates the list of keys that are shown and the description of
-     * the action.
+     * @param strings The strings to place in the right list.
      */
-    void refreshKeyInformation();
+    void RefreshRight(QStringList * strings);
 
     /**
-     * @brief Load the appropriate actions into the action list.
-     * @param context The context, from which actions will be
-     * displayed.
+     * Refresh the left list.
+     *
+     * @param string The strings to place in the left list.
      */
-    void refreshRightList(void);
+    void RefreshLeft(QStringList * strings);
 
     /**
-     * @brief Redisplay both the left and right lists and fix focus
+     * Load the appropriate information into the right list.
+     *
+     * @param strings The strings to load into the right list.
      */
-    void updateLists(void);
+    void RefreshRightList();
 
+    /** Redisplay both the left and right lists and fix focus */
+    void UpdateLists(void);
+
     /**
-     * @brief Load the settings for a particular host.
+     * Load the settings for a particular host.
+     *
      * @param hostname The host to load settings for.
      */
-    void loadHost(const QString & hostname);
+    void LoadHost(const QString & hostname);
 
     /**
-     * @brief Focus a button in a particular direction.
+     * Focus a button in a particular direction.
+     *
      * @param direction Positave values focus to the right, negatives
      * to the left.  A value of zero focuses the first button.
      */
-    void focusButton(int direction);
+    void FocusButton(int direction);
 
     /**
-     * @brief Determine which button is focused.
+     * Determine which button is focused.
+     *
      * @return Action::MAX_KEYS is no button is focused, otherwise, the
      * index of the button is returned.
-     *
-     * @sa Action::MAX_KEYS
      */
-    size_t focusedButton(void) const;
+    size_t FocusedButton(void) const;
 
     /**
-     * @brief Resolve a potential conflict.
+     * Resolve a potential conflict.
+     *
      * @return true if the conflict should be bound, otherwise, false
      * is returned.
      */
-    bool resolveConflict(ActionID *conflict, int level);
+    bool ResolveConflict(ActionID *conflict, int level);
 
     /**
-     * @brief Focus a new list and take focus away from the old.
+     * Focus a new list and take focus away from the old.
+     *
      * @param focus The list to gain focus
      * @param unfocus The list to loose focus
      */
-    void switchListFocus(UIListBtnType *focus, UIListBtnType *unfocus);
+    void SwitchListFocus(UIListBtnType *focus, UIListBtnType *unfocus);
 
-    /**
-     * @brief Add bindings to QDict<binding_t> for specified context
-     * @param bindings the QDict to which to add the bindings
-     * @param context the context to grab keybindings from
-     * @param contextParent the context whose keybindings are being calculated
-     * @param bindlevel the bind level associated with this context
-     */
-    void addBindings(QDict<binding_t> &bindings, const QString &context, const QString &contextParent, int bindlevel);
-
-    /**
-     * @brief Create a BindingList for the specified context
-     * @param context the context for which a BindingList should be created
-     */
-    BindingList *getKeyBindings(const QString &context);
-
 private slots:
 
-/**
- * @brief Add a key to the currently selected action.
- */
-void addKeyToAction(void);
+	/** Add a key to the currently selected action. */
+	void AddKeyToAction(void);
 
-    /**
-     * @brief Delete the currently active key.
-     */
-    void deleteKey();
+    /** Delete the currently active key. */
+    void DeleteKey();
 
-    /**
-     * @brief Save the settings.
-     */
-    inline void save(void) { key_bindings->commitChanges(); }
+    /** Save the settings. */
+    inline void Save(void)
+    {
+       m_KeyBindings->CommitChanges();
+    }
 
     /**
-     * @brief Recieves a signal when an item in the left list is
-     * selected.
+     * Recieves a signal when an item in the left list is selected.
+     *
      * @param item The selected item.
      */
-    void leftSelected(UIListBtnTypeItem *item);
+    void LeftSelected(UIListBtnTypeItem *item);
 
     /**
-     * @brief Recieves a signal when an item in the right list is
-     * selected.
+     * Recieves a signal when an item in the right list is selected.
+     *
      * @param item The selected item.
      */
-    void rightSelected(UIListBtnTypeItem *item);
+    void RightSelected(UIListBtnTypeItem *item);
 
-    /**
-     * @brief Sort a list of keys, removing duplicates
-     * @param keys the list of keys to sort
-     */
-    void sortKeyList(QStringList &keys);
+    /** Refresh binding information */
+    void RefreshKeyBindings();
 
     /**
-     * @brief Refresh binding information
-     */
-    void refreshKeyBindings();
-
-    /**
-     * @brief Jump to a particular key binding
+     * Jump to a particular key binding
+     *
      * @param e key event to use as jump
      */
     bool JumpTo(QKeyEvent *e);
 
 private:
 
-    UIType *focused;
-    UIListBtnType *LeftList;
-    UIListBtnType *RightList;
-    UITextType *description, *LeftDesc, *RightDesc;
-    UITextButtonType * ActionButtons[Action::MAX_KEYS];
-    KeyBindings *key_bindings;
-    LayerSet *container;
+    /** Currently focused UI type */
+    UIType *m_Focused;
 
-    QStringList contexts; ///< sorted list of contexts
-    QStringList keys; ///< sorted list of keys
+    /** The left list */
+    UIListBtnType *m_LeftList;
 
-    QDict<QStringList> m_contexts; ///< actions for a given context
-    QDict<BindingList> contextKeys; ///< key bindings for a given context
-    QDict<BindingList> keyActions; ///< actions in each context for a given key
+    /** The right list */
+    UIListBtnType *m_RightList;
 
-    typedef enum { kContextList, kKeyList, kActionList } ListType;
-    ListType leftType, rightType;
+    /** Text areas */
+    UITextType *m_Description, *m_LeftDesc, *m_RightDesc;
 
-    QString getTypeDesc(ListType type);
+    /** Buttons */
+    UITextButtonType * m_ActionButtons[Action::MAX_KEYS];
 
+    /** The current keybindings */
+    KeyBindings *m_KeyBindings;
+
+    /** A layer contianer */
+    LayerSet *m_Container;
+
+    /** The view mode */
+    ViewMode m_View;
 };
 
 
Index: mythcontrols/keybindings.h
===================================================================
--- mythcontrols/keybindings.h	(revision 10604)
+++ mythcontrols/keybindings.h	(working copy)
@@ -30,99 +30,132 @@
 #include "actionid.h"
 #include "actionset.h"
 
+
 /**
  * @class KeyBindings.
  * @brief Information about the current keybindings.
  *
  * This class can retrieve, set, and modify the keybindings used by
  * mythtv.  It is a layer between the user interface, and the
- * keybindings themeslfs.
+ * keybindings themeslfs.  All of the logic behind conflicts, etc is
+ * kept here, as well as the database routines.
  */
 class KeyBindings {
 
 public:
 
-    /**
-     * @brief Levels of conflict 
-     * @li None: Does not conflict
-     * @li Potential: May conflict.
-     * @li Fatal: Frontend will become inoperable.
-     */
+    /** Levels of conflict */
     enum ConflictLevels { Warning, Error};
 
     /**
-     * @brief Create a new KeyBindings instance.
+     * Create a new KeyBindings instance.
+     *
      * @param hostname The host for which to create the key bindings.
      */
     KeyBindings(const QString & hostname);
 
     /**
-     * @brief Get the hostname these keybindings are from.
-     * @return The hostname these keybindings are from.
+     * Determine the context belonging to the key and action
+     *
+     * @param action The action.
+     * @param anum The action number (in the list of all of a keys actions).
+     *
+     * @warning This method falls apart if the actionset class doesn't
+     * sort it the actions lists in the _kemap variable.
      */
-    inline const QString & getHostname() const { return this->_hostname; }
+    QString GetContext(const QString & key, const QString & action,
+                       size_t anum) const;
 
     /**
-     * @brief Get a list of the context names.
+     * Get a list of the context names.
+     *
      * @return A list of the context names.
-     * @note The returned list is a copy and can be modified without
-     * side-effects.
      */
-    inline QStringList * getContexts() const
+    inline QStringList * GetContexts() const
     {
-        return actionset.contextStrings();
+        return m_ActionSet.ContextStrings();
     }
 
     /**
-     * @brief Get a list of the actions in a context.
+     * Get the contexts in which a key is bound.
+     *
+     * @param key The key.
+     * @return A string list containing the context names.
+     */
+    inline QStringList * GetContexts(const QString & key) const
+    {
+        return m_ActionSet.GetKeyContexts(key);
+    }
+
+    /**
+     * Get a list of the actions in a context.
+     *
      * @param context The name of the context.
      * @return A list of action (names) for the target context.
-     * @note Store this instead of calling repeatedly.  Every time you
-     * do, ActionSet has to iterate over all contexts and actions.
      */
-    inline QStringList * getActions(const QString & context) const
+    inline QStringList * GetActions(const QString & context) const
     {
-        return actionset.actionStrings(context);
+        return m_ActionSet.ActionStrings(context);
     }
 
     /**
-     * @brief Get a list of the actions in a context.
+     * Get the action bound to a key in a particular context.
+     *
+     * @param key The key.
+     * @param context The context.
+     * @return The action.
+     */
+    QString GetAction(const QString & key, const QString & context) const;
+
+    /**
+     * Get all bound keys.
+     *
+     * @return A string list of the bound keys.
+     */
+    inline QStringList * GetAllKeys() const
+    {
+        return m_ActionSet.GetAllKeys();
+    }
+
+    /**
+     * Get a list of the actions in a context.
+     *
      * @param context The name of the context.
      * @return A list of action (names) for the target context.
      * @note Store this instead of calling repeatedly.  Every time you
      * do, ActionSet has to iterate over all contexts and actions.
      */
-    inline void getKeyActions(const QString &key, ActionList &list) const
-    {
-        list = actionset.getActions(key);
-    }
+    QStringList * GetKeyActions(const QString &key) const;
 
     /**
-     * @brief Get an action's keys.
+     * Get an action's keys.
+     *
      * @param context_name The name of the context.
      * @param action_name The name of the action.
      * @return The keys bound to the specified context's action
      */
-    inline QStringList getActionKeys(const QString & context_name,
+    inline QStringList GetActionKeys(const QString & context_name,
                                      const QString & action_name) const
     {
-        return actionset.getKeys(ActionID(context_name, action_name));
+        return m_ActionSet.GetKeys(ActionID(context_name, action_name));
     }
 
     /**
-     * @brief Get an action's description.
+     * Get an action's description.
+     *
      * @param context_name The name of the context.
      * @param action_name The name of the action.
      * @return The description of the specified context's action
      */
-    inline QString getActionDescription(const QString & context_name,
+    inline QString GetActionDescription(const QString & context_name,
                                         const QString & action_name) const
     {
-        return actionset.getDescription(ActionID(context_name, action_name));
+        return m_ActionSet.GetDescription(ActionID(context_name, action_name));
     }
 
     /**
-     * @brief Add a key to an action.
+     * Add a key to an action.
+     *
      * @param context_name The name of the context.
      * @param action_name The name of the action.
      * @param key The key to add.
@@ -131,15 +164,16 @@
      * This does not take effect until the commitChanges function is
      * called.
      */
-    inline void addActionKey(const QString & context_name,
+    inline void AddActionKey(const QString & context_name,
                              const QString & action_name,
                              const QString & key)
     {
-        this->actionset.add(ActionID(context_name, action_name), key);
+        this->m_ActionSet.Add(ActionID(context_name, action_name), key);
     }
 
     /**
-     * @brief Determine if adding a key would cause a conflict.
+     * Determine if adding a key would cause a conflict.
+     *
      * @param context_name The name of the context.
      * @param key The key to add.
      * @param level The level of conflict.  Check this if the return
@@ -157,11 +191,12 @@
      * errors should be prevented no matter what.  If they dont like it,
      * they can learn SQL.
      */
-    ActionID * conflicts(const QString & context_name,
+    ActionID * Conflicts(const QString & context_name,
                          const QString & key, int &level) const;
 
     /**
-     * @brief Replace a key in an action.
+     * Replace a key in an action.
+     *
      * @param context_name The name of the context.
      * @param action_name The name of the action.
      * @param newkey The key to add.
@@ -171,122 +206,96 @@
      * This does not take effect until the commitChanges function is
      * called.
      */
-    inline void replaceActionKey(const QString & context_name,
+    inline void ReplaceActionKey(const QString & context_name,
                                  const QString & action_name,
                                  const QString & newkey,
                                  const QString & oldkey)
     {
-        this->actionset.replace(ActionID(context_name, action_name),
+        this->m_ActionSet.Replace(ActionID(context_name, action_name),
                                 newkey, oldkey);
     }
 
     /**
-     * @brief Unbind a key from an action.
+     * Unbind a key from an action.
+     *
      * @param context_name The name of the context.
      * @param action_name The name of the action.
      * @param key The key to remove.
      * @return true if the key was removed, or false if it was not.
      *
-     * Unless the action is manditory there is only one key in the
+     * Unless the action is mandatory and there is only one key in the
      * action, this method should return true.
      */
-    bool removeActionKey(const QString & context_name,
+    bool RemoveActionKey(const QString & context_name,
                          const QString & action_name,
                          const QString & key);
 
-    /**
-     * @brief Set the manditory bindings to their defaults.
-     */
-    void defaultManditoryBindings(void);
+    /** Set the mandatory bindings to their defaults. */
+    void DefaultMandatoryBindings(void);
 
     /**
-     * @brief Determine if there are changes to the keybindings.
+     * Determine if there are changes to the keybindings.
+     *
      * @return True if keys have been changed, otherwise, false.
      */
-    inline bool hasChanges(void) const { return actionset.hasModified(); }
+    inline bool HasChanges(void) const
+    {
+        return m_ActionSet.HasModified();
+    }
 
     /**
-     * @brief Commit all changes made to the keybindings.
-     *
-     * This method will write the changes to the database, unbind myth's
-     * current bindings for those actions that changed, and setup the
-     * new bindings.
+     * Commit the changes made to the keybindings into the database.
      */
-    void commitChanges(void);
+    void CommitChanges(void);
 
     /**
-     * @brief Get a list of the manditory key bindings.
-     * @return A list of the manditory bindings.
+     * Get a list of the mandatory key bindings.
+     *
+     * @return A list of the mandatory bindings.
      */
-    inline const ActionList& getManditoryBindings(void) const
+    inline const ActionList& getMandatoryBindings(void) const
     {
-        return this->_manditory_bindings;
+        return this->m_MandatoryBindings;
     }
 
     /**
-     * @brief Determine if all manditory bindings are satisfied.
-     * @return true if all manditory bindings are satisfied, otherwise, false.
+     * Determine if all mandatory bindings are satisfied.
+     *
+     * @return true if all mandatory bindings are satisfied,
+     * otherwise, false.
      */
-    bool hasManditoryBindings(void) const;
+    bool HasMandatoryBindings(void) const;
 
 protected:
 
-    /**
-     * @brief Get a reference to the hostname.
-     * @return A reference to the hostname.
-     */
-    inline QString & hostname() { return this->_hostname; }
+    /** Commit a jumppoint to the database. */
+    void CommitJumppoint(const ActionID &id);
 
-    /**
-     * @brief Commit a jumppoint to the database.
-     *
-     * This (currently) does not reload the jumppoint.
-     */
-    void commitJumppoint(const ActionID &id);
+    /** Commit an action to the database, and reload its keybindings. */
+    void CommitAction(const ActionID & id);
 
-    /**
-     * @brief Commit an action to the database, and reload its keybindings.
-     */
-    void commitAction(const ActionID & id);
+    /** Load the jumppoints from the database. */
+    void RetrieveJumppoints(void);
 
-    /**
-     * @brief Load the jumppoints from the database.
-     *
-     * This method will load the keybindings for jump points.
-     */
-    void retrieveJumppoints(void);
+    /** Load the keybindings from the database. */
+    void RetrieveContexts(void);
 
-    /**
-     * @brief Load the keybindings from the database.
-     *
-     * This will load the keybindings which apply to the hostname
-     * specified to the constructor.
-     */
-    void retrieveContexts(void);
+    /** Load the mandatory bindings. */
+    void LoadMandatoryBindings(void);
 
-    /**
-     * @brief Load the manditory bindings.
-     */
-    void loadManditoryBindings(void);
+private:
 
-    /**
-     * @brief Get a reference to the list of the manditory key bindings.
-     * @return A reference to the list of the manditory bindings.
-     */
-    inline ActionList & manditoryBindings(void) { return _manditory_bindings; }
+    /** The hostname */
+    QString m_HostName;
 
-    /**
-     * @brief Get the default keys.
-     * @return A list of the default keys.
-     */
-    inline QStringList & defaultKeys() { return _default_keys; }
+    /** List of mandatory bindings */
+    ActionList m_MandatoryBindings;
 
-private:
+    /** List of the default key bindings */
+    QStringList m_DefaultKeys;
 
-    QString _hostname;
-    ActionList _manditory_bindings;
-    QStringList _default_keys;
-    ActionSet actionset;
+    /** The action set */
+    ActionSet m_ActionSet;
 };
 
 #endif /* KEYBINDINGS_H */
Index: mythcontrols/action.cpp
===================================================================
--- mythcontrols/action.cpp	(revision 10604)
+++ mythcontrols/action.cpp	(working copy)
@@ -34,18 +34,19 @@
 
 Action::Action(const QString & description, const QString & keys)
 {
-    this->description() = description;
-    this->keys() = QStringList::split(", ", QString(QKeySequence(keys)));
+    m_Description = description;
+    m_Keys = QStringList::split(", ", QString(QKeySequence(keys)));
 }
 
 
 
-bool Action::hasKey(const QString & key) const
+bool Action::HasKey(const QString & key) const
 {
     /* check the keys */
-    for (size_t i = 0; i < getKeys().count(); i++)
+    for (size_t i = 0; i < GetKeys().count(); i++)
     {
-        if (getKeys()[i] == key) return true;
+        if (GetKeys()[i] == key)
+            return true;
     }
 
     /* the key was not found, so return false */
@@ -54,33 +55,33 @@
 
 
 
-bool Action::addKey(const QString & key)
+bool Action::AddKey(const QString & key)
 {
 
     /* dont add empty keys and dont add too many, or duplicates  */
     if ((key.length() == 0) ||
-        (getKeys().size() >= MAX_KEYS) ||
-        (getKeys().contains(key)))
+        (GetKeys().size() >= MAX_KEYS) ||
+        (GetKeys().contains(key)))
         return false;
 
     /* add the key */
-    this->keys().push_back(key);
+    m_Keys.push_back(key);
     return true;
 }
 
 
 
 /* comments in header */
-bool Action::replaceKey(const QString & newkey, const QString &oldkey)
+bool Action::ReplaceKey(const QString & newkey, const QString &oldkey)
 {
     /* make sure that the key list doesn't already have the new key */
-    if (getKeys().contains(newkey) == 0)
+    if (GetKeys().contains(newkey) == 0)
     {
-        for (size_t i = 0; i < getKeys().size(); i++)
+        for (size_t i = 0; i < GetKeys().size(); i++)
         {
-            if (getKeys()[i] == oldkey)
+            if (GetKeys()[i] == oldkey)
             {
-                keys()[i] = newkey;
+                m_Keys[i] = newkey;
                 return true;
             }
         }
