Ticket #2078: ui_and_logic.2.diff

File ui_and_logic.2.diff, 99.6 KB (added by mfgalizi@…, 18 years ago)

UI and Logic (with formatting)

  • mythcontrols/actionset.h

     
    2626
    2727#include <qdict.h>
    2828
    29 /**
    30  * @brief The statically assigned context for jump point actions.
    31  */
     29/** The statically assigned context for jump point actions. */
    3230#define JUMP_CONTEXT "JumpPoints"
    3331
    34 /**
    35  * @brief The name of global actions.
    36  */
     32/** The name of global actions. */
    3733#define GLOBAL_CONTEXT "Global"
    3834
    39 
     35/** Context is a grouping of actions */
    4036typedef QDict<Action> Context;
    41 typedef QValueList<ActionID> ActionList;
    4237
    43 
    4438/**
    45  * @class ActionSet
    46  * @brief Maintains consistancy between actions and keybindings.
     39 * Action list is list of ActionIDs
    4740 *
    48  * This class handles adding a removing bindings to keys.
     41 * @todo Make a class out of this type and ensure that the list is
     42 * sorted appropriatly.
    4943 */
     44typedef QValueList<ActionID> ActionList;
     45
     46
     47/** Maintains consistancy between actions, contexts and keys. */
    5048class ActionSet
    5149{
    5250
    5351public:
    5452
    55     /**
    56      * @brief Create a new, empty set of action bindings.
    57      */
     53    /** Create a new, empty set of action bindings. */
    5854    inline ActionSet() {};
    5955
    6056    /**
    61      * @brief Add an action.
     57     * Add an action.
     58     *
    6259     * @param id The action identifier.
    6360     * @param description The action description.
    6461     * @param keys The keys for this action.
     
    6764     * If the action has already been added, it will not be added
    6865     * again.  There are no duplicate actions in the action set.
    6966     */
    70     bool addAction(const ActionID &id, const QString & description,
     67    bool AddAction(const ActionID &id, const QString & description,
    7168                   const QString &keys);
    7269
    7370    /**
    74      * @brief Add a binding.
     71     * Add a binding.
     72     *
    7573     * @param id The action identifier.
    7674     * @param key The symbolic name of the key.
    7775     * @return true if the key was added otherwise, false.
    7876     */
    79     bool add(const ActionID &id, const QString &key);
     77    bool Add(const ActionID &id, const QString &key);
    8078
    8179    /**
    82      * @brief Remove a key from an action identifier.
     80     * Remove a key from an action identifier.
     81     *
    8382     * @param id The action identifier to remove from.
    8483     * @param key The key to remove.
    8584     */
    86     bool remove(const ActionID &id, const QString &key);
     85    bool Remove(const ActionID &id, const QString &key);
    8786
    8887    /**
    89      * @brief Replace a specific key in a specific action.
     88     * Replace a specific key in a specific action.
     89     *
    9090     * @param id The action identifier.
    9191     * @param newkey The new key.
    9292     * @param oldkey The key to be replaced.
    9393     */
    94     bool replace(const ActionID &id, const QString &newkey,
     94    bool Replace(const ActionID &id, const QString &newkey,
    9595                 const QString &oldkey);
    9696
    9797    /**
    98      * @brief Get a list of all contexts in the action set.
     98     * Get a list of all contexts in the action set.
     99     *
    99100     * @return A list of all contexts.
    100101     */
    101     QStringList * contextStrings(void) const;
     102    QStringList * ContextStrings(void) const;
    102103
    103104    /**
    104      * @brief Get a list of all action in the action set.
     105     * Get a list of all action in the action set.
     106     *
    105107     * @return A list of all actions in the action set.
    106108     */
    107     QStringList * actionStrings(const QString & context_name) const;
     109    QStringList * ActionStrings(const QString & context_name) const;
    108110
    109111    /**
    110      * @brief Get a string containing all the keys in bound to an
    111      * action.
     112     * Get a string containing all the keys in bound to an action.
     113     *
    112114     * @param id The action's identifier.
    113115     * @return null if there is no such action, otherwise, the keys.
    114116     */
    115     QString keyString(const ActionID &id) const;
     117    QString KeyString(const ActionID &id) const;
    116118
    117119    /**
    118      * @brief Get the keys bound to an action by it's identifier.
     120     * Get the keys bound to an action by it's identifier.
     121     *
    119122     * @param id The action identifier.
    120123     * @return The keys used by the action.
    121124     */
    122     QStringList getKeys(const ActionID &id) const;
     125    QStringList GetKeys(const ActionID &id) const;
    123126
    124127    /**
    125      * @brief Get the description of an action.
     128     * Get all keys that are in use.
     129     *
     130     * @return A string list containing all of the keys.
     131     */
     132    QStringList * GetAllKeys(void) const;
     133
     134    /**
     135     * Get the contexts, in which a key is bound.
     136     *
     137     * @return A string list containing the context names.
     138     */
     139    QStringList * GetKeyContexts(const QString &key) const;
     140
     141    /**
     142     * Get all of the actions that are in use.
     143     *
     144     * @return A string list containing all of the actions.
     145     */
     146    QStringList *GetAllActions(void) const;
     147
     148    /**
     149     * Get the description of an action.
     150     *
    126151     * @param id The action identifier.
    127152     * @return The action description.
    128153     */
    129     const QString & getDescription(const ActionID &id) const;
     154    const QString & GetDescription(const ActionID &id) const;
    130155
    131156    /**
    132      * @brief Get the actions bound to the specified key.
     157     * Get the actions bound to the specified key.
     158     *
    133159     * @param key The key.
    134160     * @return The list of actions, which are bound to the key.
    135161     */
    136     const ActionList & getActions(const QString &key) const;
     162    inline const ActionList & GetActions(const QString &key) const
     163    {
     164        return m_KeyMap[key];
     165    }
    137166
     167
    138168    /**
    139      * @brief Get the appropriate container of modified actions based on
     169     * Get the appropriate container of modified actions based on
    140170     * context.
     171     *
    141172     * @return The appropriate container of modified actions.
    142173     */
    143     inline const ActionList & getModified(void) const { return _modified; }
     174    inline const ActionList & GetModified(void) const
     175    {
     176        return m_Modified;
     177    }
    144178
    145179    /**
    146      * @brief Determine if the action set has been modified.
     180     * Determine if the action set has been modified.
     181     *
    147182     * @return True if changes have been made, otherwise, false.
    148183     */
    149     inline bool hasModified(void) const { return !(_modified.isEmpty()); }
     184    inline bool HasModified(void) const
     185    {
     186        return !(m_Modified.isEmpty());
     187    }
    150188
    151189    /**
    152      * @brief Mark an action as unmodified.
     190     * Mark an action as unmodified.
     191     *
    153192     * @return true if the action was modified, and is set to unmodified.
    154193     */
    155     inline bool unmodify(const ActionID & id)
     194    inline bool Unmodify(const ActionID & id)
    156195    {
    157         return (_modified.remove(id) > 0);
     196        return (m_Modified.remove(id) > 0);
    158197    }
    159198
    160199    /**
    161      * @brief Determine if an action has been modified.
     200     * Determine if an action has been modified.
     201     *
    162202     * @param id The action identifier.
    163203     * @return true if the action is modified, otherwise, false.
    164204     */
    165     inline bool isModified(const ActionID &id)const { return !unmodified(id); }
     205    inline bool IsModified(const ActionID &id) const
     206    {
     207        return !Unmodified(id);
     208    }
    166209
    167210    /**
    168      * @brief Determine if an action is still unmodified.
     211     * Determine if an action is still unmodified.
     212     *
    169213     * @param id The action identifier.
    170214     * @return true if the action has not been modified, otherwise, false.
    171215     */
    172     inline bool unmodified(const ActionID &id) const
     216    inline bool Unmodified(const ActionID &id) const
    173217    {
    174         return (getModified().contains(id) == 0);
     218        return (GetModified().contains(id) == 0);
    175219    }
    176220
    177221protected:
    178222
    179223    /**
    180      * @brief Mark an action as modified.
     224     * Mark an action as modified.
     225     *
    181226     * @param id The actio identifier.
    182227     */
    183     inline void modify(const ActionID &id)
     228    inline void Modify(const ActionID &id)
    184229    {
    185         if (unmodified(id)) _modified.push_back(id);
     230        if (Unmodified(id)) m_Modified.push_back(id);
    186231    }
    187232
    188233    /**
    189      * @brief Get an action by its identifier.
     234     * Get an action by its identifier.
     235     *
    190236     * @return A pointer to the action.
    191237     */
    192     inline Action * action(const ActionID &id) const
     238    inline Action * GetAction(const ActionID &id) const
    193239    {
    194         return context(id.context()) ?
    195             (*context(id.context()))[id.action()] : NULL;
     240        return GetContext(id.context()) ?
     241            (*GetContext(id.context()))[id.action()] : NULL;
    196242    }
    197243
    198244    /**
    199      * @brief Get a context by its identifier.
     245     * Get a context by its identifier.
     246     *
    200247     * @return A pointer to the context.
    201248     */
    202     inline Context * context(const QString & name) const
     249    inline Context * GetContext(const QString & name) const
    203250    {
    204         return this->_contexts[name];
     251        return this->m_Contexts[name];
    205252    }
    206253
    207254private:
    208255
    209     QMap<QString, ActionList> _keymap;
    210     QDict<Context> _contexts;
    211     ActionList _modified;
     256    /** Maps keys to the actions the are bound */
     257    QMap<QString, ActionList> m_KeyMap;
     258
     259    /** Dictionary of contexts (which contain actions) */
     260    QDict<Context> m_Contexts;
     261
     262    /** Modified actions */
     263    ActionList m_Modified;
     264
     265    /** map from action to the contexts it belongs to */
     266    QMap<QString, QStringList> m_Actions;
     267
    212268};
    213269
    214270#endif /* ACTIONSET_H */
  • mythcontrols/action.h

     
    4141public:
    4242
    4343    /**
    44      * @brief Create a new empty action.
     44     * Create a new empty action.
     45     *
    4546     * @param description The actions description.
    4647     */
    47     inline Action(const QString & description) : _description(description) {}
     48    inline Action(const QString & description) : m_Description(description) {}
    4849
    4950    /**
    50      * @brief Create a new action.
     51     * Create a new action.
     52     *
    5153     * @param description The description of the action.
    5254     * @param keys The key sequence (strings) that trigger the action.
    5355     *
     
    5860    Action(const QString & description, const QString & keys);
    5961
    6062    /**
    61      * @brief Get the action description.
     63     * Get the action description.
     64     *
    6265     * @return The action description.
    6366     */
    64     inline const QString & getDescription() const { return this->_description; }
     67    inline const QString & GetDescription() const
     68    {
     69        return this->m_Description;
     70    }
    6571
    6672    /**
    67      * @brief Get the key sequence(s) that trigger this action.
     73     * Get the key sequence(s) that trigger this action.
     74     *
    6875     * @return The key sequence(s) that trigger this action.
    6976     */
    70     inline const QStringList & getKeys() const { return this->_keys; }
     77    inline const QStringList & GetKeys() const
     78    {
     79        return this->m_Keys;
     80    }
    7181
    7282    /**
    73      * @brief Get the keys as a string.
     83     * Get the keys as a string.
     84     *
    7485     * @return QString::null or a comma delimited string of keys.
    7586     */
    76     inline QString keyString() const { return _keys.join(","); }
     87    inline QString KeyString() const
     88    {
     89        return m_Keys.join(",");
     90    }
    7791
    7892    /**
    79      * @brief Add a key sequence to this action.
     93     * Add a key sequence to this action.
     94     *
    8095     * @param key The key to add to the action.
    8196     * @return true if the key was added otherwise, false.
    8297     */
    83     bool addKey(const QString & key);
     98    bool AddKey(const QString & key);
    8499
    85100    /**
    86      * @brief Remove a key from this action.
     101     * Remove a key from this action.
     102     *
    87103     * @param key The key to remove.
    88104     * @return true if the key is removed, otherwise, false.
    89105     */
    90     inline bool removeKey(const QString & key) { return (keys().remove(key)>0); }
     106    inline bool RemoveKey(const QString & key)
     107    {
     108        return (m_Keys.remove(key)>0);
     109    }
    91110
    92111    /**
    93      * @brief Replace a key.
     112     * Replace a key.
     113     *
    94114     * @param newkey The new key.
    95115     * @param oldkey The old key, which is being replaced.
    96116     */
    97     bool replaceKey(const QString & newkey, const QString & oldkey);
     117    bool ReplaceKey(const QString & newkey, const QString & oldkey);
    98118
    99119    /**
    100      * @brief Determine if the action already has a key.
     120     * Determine if the action already has a key.
     121     *
    101122     * @param key The key to check for.
    102123     * @return true if the key is already bound in this action,
    103124     * otherwise, false is returned.
    104125     */
    105     bool hasKey(const QString & key) const;
     126    bool HasKey(const QString & key) const;
    106127
    107128    /**
    108      * @brief Get the index of a key.
    109      * @param key The string containing the key.
    110      * @return The index of the key, which will be less than zero if the
    111      * key does not exist.
    112      */
    113 
    114     /**
    115      * @brief Determine if the action has any keys at all.
     129     * Determine if the action has any keys at all.
     130     *
    116131     * @return true if the action has keys, otherwise, false.
    117132     */
    118     inline bool empty(void) const { return (_keys.size() > 0); }
     133    inline bool IsEmpty(void) const
     134    {
     135        return (m_Keys.size() > 0);
     136    }
    119137
    120     /** @brief The maximum number of keys that can be bound to an action. */
     138    /** The maximum number of keys that can be bound to an action. */
    121139    static const unsigned short MAX_KEYS = 4;
    122140
    123 protected:
     141private:
    124142
    125     /**
    126      * @brief Get a reference to the action description.
    127      * @return A reference to the action description.
    128      */
    129     inline QString & description() { return this->_description; }
     143    /** The actions description. */
     144    QString m_Description;
    130145
    131     /**
    132      * @brief Get a reference to actions the key sequences.
    133      * @return A reference to actions the key sequences.
    134      */
    135     inline QStringList & keys() { return this->_keys; }
    136 
    137 private:
    138 
    139     QString _description;
    140     QStringList _keys;
     146    /** The keys bound to the action. */
     147    QStringList m_Keys;
    141148};
    142149
    143150#endif /* ACTION_H */
  • mythcontrols/mythcontrols.cpp

     
    2929#ifndef MYTHCONTROLS_CPP
    3030#define MYTHCONTROLS_CPP
    3131
    32 /* QT includes */
    3332#include <qnamespace.h>
    3433#include <qstringlist.h>
    3534#include <qapplication.h>
    3635#include <qbuttongroup.h>
    37 
    38 /* MythTV includes */
    3936#include <mythtv/mythcontext.h>
    4037#include <mythtv/mythdialogs.h>
    4138
     
    5451        return key;
    5552}
    5653
    57 static const QString DisplayToKey(const QString key)
    58 {
    59     if (key.left(1) == "[" && key != "[")
    60         return "remote" + key.mid(1,key.length()-2);
    61     else
    62         return key;
    63 }
    6454
    6555/* comments in header */
    6656MythControls::MythControls (MythMainWindow *parent, bool& ui_ok)
    6757    :MythThemedDialog(parent, "controls", "controls-", "controls")
    6858{
    6959    /* Nullify keybindings so the deconstructor knows not to delete it */
    70     this->key_bindings = NULL;
     60    this->m_KeyBindings = NULL;
    7161
    72     /* delete the contents when we're done */
    73     m_contexts.setAutoDelete(true);
    74    
     62    this->m_View = ActionsByContext;
     63
    7564    /* load up the ui components */
    76     if ((ui_ok = loadUI()))
     65    if ((ui_ok = LoadUI()))
    7766    {
    78         leftType = kContextList;
    79         rightType = kActionList;
    80 
    8167        /* for starters, load this host */
    82         loadHost(gContext->GetHostName());
     68        m_KeyBindings = new KeyBindings(gContext->GetHostName());
    8369
    8470        /* update the information */
    85         refreshKeyInformation();
     71        SetView(ActionsByContext, true);
     72        RefreshInformation();
    8673
    8774        /* capture the signals we want */
    88         connect(LeftList, SIGNAL(itemSelected(UIListBtnTypeItem*)),
    89                 this, SLOT(leftSelected(UIListBtnTypeItem*)));
    90         connect(RightList, SIGNAL(itemSelected(UIListBtnTypeItem*)),
    91                 this, SLOT(rightSelected(UIListBtnTypeItem*)));
    92 
     75        connect(m_LeftList, SIGNAL(itemSelected(UIListBtnTypeItem*)),
     76                this, SLOT(LeftSelected(UIListBtnTypeItem*)));
     77        connect(m_RightList, SIGNAL(itemSelected(UIListBtnTypeItem*)),
     78                this, SLOT(RightSelected(UIListBtnTypeItem*)));
    9379    }
    9480}
    9581
    9682
    9783
    9884/* comments in header */
    99 MythControls::~MythControls() { delete this->key_bindings; }
     85MythControls::~MythControls()
     86{
     87    delete this->m_KeyBindings;
     88}
    10089
    10190
    10291
    10392/* comments in header */
    104 bool MythControls::loadUI()
     93bool MythControls::LoadUI()
    10594{
    10695    /* the return value of the method */
    10796    bool retval = true;
    10897
    10998    /* Get the UI widgets that we need to work with */
    110     if ((description = getUITextType("description")) == NULL)
     99    if ((m_Description = getUITextType("description")) == NULL)
    111100    {
    112101        VERBOSE(VB_IMPORTANT, "MythControls: Unable to load action_description");
    113102        retval = false;
    114103    }
    115104
    116     if ((container = getContainer("controls")) == NULL) {
     105    if ((m_Container = getContainer("controls")) == NULL)
     106    {
    117107        VERBOSE(VB_IMPORTANT, "MythControls:  No controls container in theme");
    118108        retval = false;
    119109    }
    120     else if ((LeftList = getUIListBtnType("leftlist")) == NULL) {
     110    else if ((m_LeftList = getUIListBtnType("leftlist")) == NULL)
     111    {
    121112        VERBOSE(VB_IMPORTANT, "MythControls:  No leftlist in theme");
    122113        retval = false;
    123114    }
    124     else if ((RightList = getUIListBtnType("rightlist")) == NULL) {
     115    else if ((m_RightList = getUIListBtnType("rightlist")) == NULL)
     116    {
    125117        VERBOSE(VB_IMPORTANT, "MythControls:  No rightList in theme");
    126118        retval = false;
    127119    }
    128     else {
    129         LeftDesc = getUITextType("leftdesc");
    130         RightDesc = getUITextType("rightdesc");
    131         /* focus the context list by default */
    132         focused = LeftList;
    133         LeftList->calculateScreenArea();
    134         LeftList->SetActive(true);
    135         RightList->calculateScreenArea();
    136         RightList->SetActive(false);
     120    else
     121    {
     122        m_LeftDesc = getUITextType("leftdesc");
     123        m_RightDesc = getUITextType("rightdesc");
     124        m_Focused = m_LeftList;
     125        m_LeftList->calculateScreenArea();
     126        m_LeftList->SetActive(true);
     127        m_RightList->calculateScreenArea();
     128        m_RightList->SetActive(false);
    137129    }
    138130
    139131    /* Check that all the buttons are there */
    140     if ((ActionButtons[0] = getUITextButtonType("action_one")) == NULL)
     132    if ((m_ActionButtons[0] = getUITextButtonType("action_one")) == NULL)
    141133    {
    142         VERBOSE(VB_IMPORTANT, "MythControls: Unable to load first action button");
     134        VERBOSE(VB_IMPORTANT,
     135                "MythControls: Unable to load first action button");
    143136        retval = false;
    144137    }
    145     else if ((ActionButtons[1] = getUITextButtonType("action_two")) == NULL)
     138    else if ((m_ActionButtons[1] = getUITextButtonType("action_two")) == NULL)
    146139    {
    147         VERBOSE(VB_IMPORTANT, "MythControls: Unable to load second action button");
     140        VERBOSE(VB_IMPORTANT,
     141                "MythControls: Unable to load second action button");
    148142        retval = false;
    149143    }
    150     else if ((ActionButtons[2] = getUITextButtonType("action_three")) == NULL)
     144    else if ((m_ActionButtons[2] = getUITextButtonType("action_three")) == NULL)
    151145    {
    152         VERBOSE(VB_IMPORTANT, "MythControls: Unable to load thrid action button");
     146        VERBOSE(VB_IMPORTANT,
     147                "MythControls: Unable to load thrid action button");
    153148        retval = false;
    154149    }
    155     else if ((ActionButtons[3] = getUITextButtonType("action_four")) == NULL)
     150    else if ((m_ActionButtons[3] = getUITextButtonType("action_four")) == NULL)
    156151    {
    157         VERBOSE(VB_IMPORTANT, "MythControls: Unable to load fourth action button");
     152        VERBOSE(VB_IMPORTANT,
     153                "MythControls: Unable to load fourth action button");
    158154        retval = false;
    159155    }
    160156
     
    162158}
    163159
    164160
     161void MythControls::ShowButtons(bool shown) const
     162{
     163    for (size_t i = 0; i < Action::MAX_KEYS; i++)
     164        shown ? m_ActionButtons[i]->show() : m_ActionButtons[i]->hide();
     165}
    165166
    166 /* comments in header */
    167 size_t MythControls::focusedButton(void) const
     167
     168/* method description in mythcontrols.h */
     169void MythControls::BlankButtons(void) const
    168170{
    169171    for (size_t i = 0; i < Action::MAX_KEYS; i++)
    170         if (focused == ActionButtons[i]) return i;
     172        m_ActionButtons[i]->setText("");
     173}
    171174
     175/* method description in mythcontrols.h */
     176void MythControls::FillButtons(const QStringList & strings)
     177{
     178    size_t i = 0, maxstr = Action::MAX_KEYS;
     179
     180    if (strings.count() < Action::MAX_KEYS)
     181        maxstr = strings.count();
     182   
     183    /* fill existing keys */
     184    for (; i < maxstr; i++)
     185        m_ActionButtons[i]->setText(KeyToDisplay(strings[i]));
     186
     187    /* blank the other ones */
     188    for (; i < Action::MAX_KEYS; i++)
     189        m_ActionButtons[i]->setText("");
     190}
     191
     192/* comments in header */
     193size_t MythControls::FocusedButton(void) const
     194{
     195    for (size_t i = 0; i < Action::MAX_KEYS; i++)
     196    {
     197        if (m_Focused == m_ActionButtons[i])
     198            return i;
     199    }
    172200    return Action::MAX_KEYS;
    173201}
    174202
    175 
    176 void MythControls::focusButton(int direction)
     203void MythControls::FocusButton(int direction)
    177204{
    178     if (leftType != kContextList || rightType != kActionList)
    179         return;
    180205    if (direction == 0)
    181206    {
    182         focused = ActionButtons[0];
    183         ActionButtons[0]->takeFocus();
    184         RightList->looseFocus();
    185         RightList->SetActive(false);
     207        m_Focused = m_ActionButtons[0];
     208        m_ActionButtons[0]->takeFocus();
     209        m_RightList->looseFocus();
     210        m_RightList->SetActive(false);
    186211    }
    187212    else
    188213    {
    189214
    190215        /* change focus by at most one in either direction */
    191         if (direction > 0) direction = 1;
    192         else direction = -1;
     216        if (direction > 0)
     217            direction = 1;
     218        else
     219            direction = -1;
    193220
    194221        /* figure out which button is focused */
    195222        int current = 0;
    196         if (focused == ActionButtons[1]) current=1;
    197         else if (focused == ActionButtons[2]) current = 2;
    198         else if (focused == ActionButtons[3]) current = 3;
     223        if (m_Focused == m_ActionButtons[1])
     224            current=1;
     225        else if (m_Focused == m_ActionButtons[2])
     226            current = 2;
     227        else if (m_Focused == m_ActionButtons[3])
     228            current = 3;
    199229
    200230        /* determine the new focused button index */
    201231        int newb = current + direction;
     
    203233        /* focus an existing button */
    204234        if ((newb >= 0) && (newb < Action::MAX_KEYS))
    205235        {
    206             focused->looseFocus();
    207             focused = ActionButtons[newb];
    208             focused->takeFocus();
     236            m_Focused->looseFocus();
     237            m_Focused = m_ActionButtons[newb];
     238            m_Focused->takeFocus();
    209239        }
    210240    }
    211241}
    212242
    213243
    214244
    215 void MythControls::switchListFocus(UIListBtnType *focus, UIListBtnType *unfocus)
     245void MythControls::SwitchListFocus(UIListBtnType *focus, UIListBtnType *unfocus)
    216246{
    217247    /* unfocus a list (setactive(false)) or a button (focused->looseFocus) */
    218248    if (unfocus)
    219249        unfocus->SetActive(false);
    220250
    221     focused->looseFocus();
    222     focused = focus;
     251    m_Focused->looseFocus();
     252    m_Focused = focus;
    223253    focus->SetActive(true);
    224254    focus->takeFocus();
    225     refreshKeyInformation();
     255    RefreshInformation();
    226256}
    227257
     258/* method description in mythcontrols.h */
     259void MythControls::SetView(ViewMode newview, bool force)
     260{
     261    QStringList *lstrings = NULL, *rstrings = NULL;
     262
     263    /* Dont set the view to what is already is */
     264    if ((newview == m_View) && (force == false))
     265      return;
     266
     267    m_Focused->looseFocus();
     268    m_Focused = m_LeftList;
     269    m_LeftList->takeFocus();
     270   
     271    m_View = newview;
     272
     273    switch (newview)
     274    {
     275    case ActionsByContext:
     276        this->ShowButtons(true);
     277        m_LeftDesc->SetText(tr("Contexts"));
     278        m_RightDesc->SetText(tr("Actions"));
     279        lstrings = m_KeyBindings->GetContexts();
     280        rstrings = m_KeyBindings->GetActions((*lstrings)[0]);
     281        break;
     282    case ActionsByKey:
     283        this->ShowButtons(false);
     284        m_LeftDesc->SetText(tr("Keys"));
     285        m_RightDesc->SetText(tr("Actions"));
     286        lstrings = m_KeyBindings->GetAllKeys();
     287        rstrings = m_KeyBindings->GetKeyActions((*lstrings)[0]);
     288        break;
     289    case ContextsByKey:
     290        this->ShowButtons(false);
     291        m_LeftDesc->SetText(tr("Keys"));
     292        m_RightDesc->SetText(tr("Contexts"));
     293        lstrings = m_KeyBindings->GetAllKeys();
     294        rstrings = m_KeyBindings->GetContexts((*lstrings)[0]);
     295        break;
     296    }
     297
     298    /* refresh the keys on the left */
     299    if (lstrings != NULL)
     300    {
     301        RefreshLeft(lstrings);
     302        delete lstrings;
     303    }
     304
     305    /* refresh the keys on the right */
     306    if (rstrings != NULL)
     307    {
     308        RefreshRight(rstrings);
     309        delete rstrings;
     310    }
     311}
     312
    228313void MythControls::keyPressEvent(QKeyEvent *e)
    229314{
    230315    bool handled = false;
     
    239324
    240325        if (action == "MENU" || action == "INFO")
    241326        {
    242             focused->looseFocus();
     327            m_Focused->looseFocus();
    243328            OptionsMenu popup(gContext->GetMainWindow());
    244329            int a = (int)popup.getOption();
    245             switch (a) {
     330            switch (a)
     331            {
    246332                case (int)OptionsMenu::SAVE:
    247                     save();
     333                    Save();
    248334                    break;
    249335            }
    250             focused->takeFocus();
    251 //            if (popup.getOption() == OptionsMenu::SAVE) save();
     336            m_Focused->takeFocus();
    252337        }
    253338        else if (action == "SELECT")
    254339        {
    255             if (focused == LeftList)
    256                 switchListFocus(RightList, LeftList);
    257             else if (focused == RightList)
    258                 focusButton(0);
    259             else {
    260                 QString key = getCurrentKey();
    261                 if (!key.isEmpty())
     340            if (m_Focused == m_LeftList)
     341                SwitchListFocus(m_RightList, m_LeftList);
     342            else if (m_View == ActionsByContext)
     343            {
     344                if (m_Focused == m_RightList)
     345                    FocusButton(0);
     346                else
    262347                {
    263                     ActionMenu popup(gContext->GetMainWindow());
    264                     int result = popup.getOption();
    265                     if (result == ActionMenu::SET) addKeyToAction();
    266                     else if (result == ActionMenu::REMOVE) deleteKey();
    267                 } else // for blank keys, no reason to ask what to do
    268                     addKeyToAction();
     348                    QString key = GetCurrentKey();
     349                    if (!key.isEmpty())
     350                    {
     351                        ActionMenu popup(gContext->GetMainWindow());
     352                        int result = popup.getOption();
     353                        if (result == ActionMenu::SET)
     354                            AddKeyToAction();
     355                        else if (result == ActionMenu::REMOVE)
     356                            DeleteKey();
     357                    }
     358                    else // for blank keys, no reason to ask what to do
     359                        AddKeyToAction();
     360                }
    269361            }
    270362        }
    271363        else if (action == "ESCAPE")
    272364        {
    273365            escape = true;
    274             if (focused == LeftList)
     366            if (m_Focused == m_LeftList)
    275367            {
    276368                handled = false;
    277                 if (key_bindings->hasChanges())
     369                if (m_KeyBindings->HasChanges())
    278370                {
    279371                    /* prompt user to save changes */
    280372                    UnsavedMenu popup(gContext->GetMainWindow());
    281373                    if (popup.getOption() == UnsavedMenu::SAVE)
    282374                    {
    283                         save();
     375                        Save();
    284376                    }
    285377                }
    286378            }
    287             else if (focused == RightList)
    288                 switchListFocus(LeftList, RightList);
     379            else if (m_Focused == m_RightList)
     380                SwitchListFocus(m_LeftList, m_RightList);
    289381            else
    290                 switchListFocus(RightList, NULL);
     382                SwitchListFocus(m_RightList, NULL);
    291383        }
    292384        else if (action == "UP")
    293385        {
    294             if (focused == LeftList)
    295                 LeftList->MoveUp();
    296             else if (focused == RightList)
    297                 RightList->MoveUp();
     386            if (m_Focused == m_LeftList)
     387                m_LeftList->MoveUp();
     388            else if (m_Focused == m_RightList)
     389                m_RightList->MoveUp();
    298390        }
    299391        else if (action == "DOWN")
    300392        {
    301             if (focused == LeftList)
    302                 LeftList->MoveDown();
    303             else if (focused == RightList)
    304                 RightList->MoveDown();
     393            if (m_Focused == m_LeftList)
     394                m_LeftList->MoveDown();
     395            else if (m_Focused == m_RightList)
     396                m_RightList->MoveDown();
    305397        }
    306398        else if (action == "LEFT")
    307399        {
    308             if (focused==RightList)
    309                 switchListFocus(LeftList, RightList);
    310             else if (focused != LeftList)
    311                 focusButton(-1);
     400            if (m_Focused==m_RightList)
     401                SwitchListFocus(m_LeftList, m_RightList);
     402            else if (m_Focused != m_LeftList)
     403                FocusButton(-1);
    312404        }
    313405        else if (action == "RIGHT")
    314406        {
    315             if (focused == LeftList)
    316                 switchListFocus(RightList, LeftList);
    317             else if (focused != RightList)
    318                 focusButton(1);
     407            if (m_Focused == m_LeftList)
     408                SwitchListFocus(m_RightList, m_LeftList);
     409            else if (m_Focused != m_RightList)
     410                FocusButton(1);
    319411        }
    320412        else if (action == "PAGEUP")
    321413        {
    322             if (focused == LeftList)
    323                 LeftList->MoveUp(UIListBtnType::MovePage);
    324             else if (focused == RightList)
    325                 RightList->MoveUp(UIListBtnType::MovePage);
     414            if (m_Focused == m_LeftList)
     415                m_LeftList->MoveUp(UIListBtnType::MovePage);
     416            else if (m_Focused == m_RightList)
     417                m_RightList->MoveUp(UIListBtnType::MovePage);
    326418        }
    327419        else if (action == "PAGEDOWN")
    328420        {
    329             if (focused == LeftList)
    330                 LeftList->MoveDown(UIListBtnType::MovePage);
    331             else if (focused == RightList)
    332                 RightList->MoveDown(UIListBtnType::MovePage);
     421            if (m_Focused == m_LeftList)
     422                m_LeftList->MoveDown(UIListBtnType::MovePage);
     423            else if (m_Focused == m_RightList)
     424                m_RightList->MoveDown(UIListBtnType::MovePage);
    333425        }
    334426        else if (action == "1")
    335         {
    336             if (leftType != kContextList || rightType != kActionList)
    337             {
    338                 leftType = kContextList;
    339                 rightType = kActionList;
    340                 updateLists();
    341                 if (focused != LeftList)
    342                     switchListFocus(LeftList,
    343                                     (focused == RightList) ? RightList : NULL);
    344             } else handled = false;
    345         }
     427            SetView(ActionsByContext);
    346428        else if (action == "2")
    347         {
    348             if (leftType != kContextList || rightType != kKeyList)
    349             {
    350                 leftType = kContextList;
    351                 rightType = kKeyList;
    352                 updateLists();
    353                 if (focused != LeftList)
    354                     switchListFocus(LeftList,
    355                                     (focused == RightList) ? RightList : NULL);
    356             } else handled = false;
    357         }
     429            SetView(ActionsByKey);
    358430        else if (action == "3")
    359         {
    360             if (leftType != kKeyList || rightType != kContextList)
    361             {
    362                 leftType = kKeyList;
    363                 rightType = kContextList;
    364                 updateLists();
    365                 if (focused != LeftList)
    366                     switchListFocus(LeftList,
    367                                     (focused == RightList) ? RightList : NULL);
    368             } else handled = false;
    369         }
    370         else handled = false;
     431            SetView(ContextsByKey);
     432        else
     433            handled = false;
    371434    }
    372435
    373     if (handled) return;
     436    if (handled)
     437        return;
    374438
    375     if (!escape && JumpTo(e)) handled = true;
     439    if (!escape && JumpTo(e))
     440        handled = true;
    376441
    377442    if (!handled)
    378443        MythThemedDialog::keyPressEvent(e);
     
    380445
    381446bool MythControls::JumpTo(QKeyEvent *e)
    382447{
    383     UIListBtnType *list = NULL;
    384     if (focused == LeftList && leftType == kKeyList) list = LeftList;
    385     if (focused == RightList && rightType == kKeyList) list = RightList;
    386     if (!list) return false;
     448    UIListBtnType *flist = NULL;
    387449
     450    if (m_View != ActionsByContext)
     451    {
     452        if (m_Focused == m_LeftList)
     453            flist = m_LeftList;
     454        else
     455            flist = m_RightList;
     456    }
     457
     458    if (!flist)
     459        return false;
     460
    388461    QString key = e->text();
    389     if (key.left(6) == "remote") {
     462    if (key.left(6) == "remote")
    390463        key = KeyToDisplay(key);
    391     } else {
     464    else
     465    {
    392466        key = QString(QKeySequence(e->key()));
    393467        if (key.isEmpty()) return false;
    394468        QString modifiers = "";
     
    401475
    402476    UIListBtnTypeItem *b;
    403477    uint len = 1024; // infinity
    404     if (list == RightList)
     478    if (flist == m_RightList)
    405479    {
    406480        key = key + " ";
    407481        len = key.length();
    408482    }
    409483
    410     for (b = list->GetItemFirst(); b; b = list->GetItemNext(b))
    411         if (b->text().left(len) == key) break;
    412     if (!b) return false;
     484    for (b = flist->GetItemFirst(); b; b = flist->GetItemNext(b))
     485    {
     486        if (b->text().left(len) == key)
     487            break;
     488    }
     489    if (!b)
     490        return false;
    413491
    414     int curpos = list->GetItemPos(list->GetItemCurrent());
    415     int newpos = list->GetItemPos(b);
     492    int curpos = flist->GetItemPos(flist->GetItemCurrent());
     493    int newpos = flist->GetItemPos(b);
    416494
    417495    if (newpos > curpos)
    418         list->MoveDown(newpos - curpos);
     496        flist->MoveDown(newpos - curpos);
    419497    else if (newpos < curpos)
    420         list->MoveUp(curpos - newpos);
     498        flist->MoveUp(curpos - newpos);
    421499    return true;
    422500}
    423501
    424502
    425 void MythControls::leftSelected(UIListBtnTypeItem*)
     503void MythControls::LeftSelected(UIListBtnTypeItem*)
    426504{
    427     LeftList->refresh();
    428     RightList->blockSignals(true);
    429     refreshRightList();
    430     RightList->blockSignals(false);
    431     RightList->refresh();
     505    m_LeftList->refresh();
     506    m_RightList->blockSignals(true);
     507    RefreshRightList();
     508    m_RightList->blockSignals(false);
     509    m_RightList->refresh();
     510    m_Description->SetText("");
    432511}
    433512
    434 void MythControls::rightSelected(UIListBtnTypeItem*)
     513void MythControls::RightSelected(UIListBtnTypeItem*)
    435514{
    436     RightList->refresh();
    437     refreshKeyInformation();
     515    m_RightList->refresh();
     516    RefreshInformation();
    438517}
    439518
     519void MythControls::RefreshRight(QStringList * strings)
     520{
     521    m_RightList->blockSignals(true);
     522    m_RightList->Reset();
    440523
     524    strings->sort();
    441525
     526    for (size_t i = 0; i < strings->size(); i++)
     527    {
     528        UIListBtnTypeItem *item = new UIListBtnTypeItem(m_RightList,(*strings)[i]);
     529        item->setDrawArrow(false);
     530    }
     531
     532    m_RightList->blockSignals(false);
     533    m_RightList->refresh();
     534}
     535
    442536/* method description in header */
    443 void MythControls::refreshRightList()
     537void MythControls::RefreshLeft(QStringList * strings)
    444538{
    445     RightList->Reset();
     539    m_LeftList->blockSignals(true);
     540    m_LeftList->Reset();
    446541
    447     if (LeftList->GetItemCurrent() == NULL)
    448         return;
     542    /* sort the strings */
     543    strings->sort();
    449544
    450     if (leftType == kContextList)
     545    for (size_t i = 0; i < strings->size(); i++)
    451546    {
    452         if (rightType == kActionList)
    453         {
    454             /* add all of the actions to the context list */
    455             QString context = LeftList->GetItemCurrent()->text();
    456             QStringList *actions = m_contexts[context];
    457             if (actions == NULL)
    458             {
    459                 VERBOSE(VB_IMPORTANT, QString("MythControls: Unable to find actions for context %1").arg(context));
    460                 return;
    461             }
    462             UIListBtnTypeItem *item;
    463             for (size_t i = 0; i < actions->size(); i++)
    464                 item = new UIListBtnTypeItem(RightList, (*actions)[i]);
    465         }
    466         else if (rightType == kKeyList)
    467         {
    468             /* add all of the actions to the context list */
    469             QString context = LeftList->GetItemCurrent()->text();
    470             BindingList *list = contextKeys[context];
    471             if (list == NULL)
    472             {
    473                 VERBOSE(VB_IMPORTANT, QString("MythControls: Unable to find keys for context %1").arg(context));
    474                 return;
    475             }
    476             UIListBtnTypeItem *item;
    477             for (BindingList::iterator it = list->begin(); it != list->end(); ++it)
    478             {
    479                 binding_t *b = *it;
    480                 item = new UIListBtnTypeItem(RightList, KeyToDisplay(b->key) + " => " + b->action);
    481             }
    482         }
    483     } else if (leftType == kKeyList && rightType == kContextList)
    484     {
    485         QString key = DisplayToKey(LeftList->GetItemCurrent()->text());
    486         BindingList *list = keyActions[key];
    487         if (list == NULL)
    488         {
    489             VERBOSE(VB_IMPORTANT, QString("MythControls: Unable to find actions for key %1").arg(key));
    490             return;
    491         }
    492         UIListBtnTypeItem *item;
    493         BindingList::iterator it = list->begin();
    494         binding_t *b = *it;
    495         for (size_t i = 0; i < contexts.size(); i++)
    496         {
    497             QString context = contexts[i];
    498             QString action = "<none>";
    499             if (b && b->context == context)
    500             {
    501                 action = b->action;
    502                 ++it;
    503                 if (it != list->end()) b = *it;
    504                 else b = NULL;
    505             }
    506             item = new UIListBtnTypeItem(RightList, context + " => " + action);
    507         }
     547        UIListBtnTypeItem *item = new UIListBtnTypeItem(m_LeftList, (*strings)[i]);
     548        item->setDrawArrow(true);
    508549    }
     550
     551    m_LeftList->blockSignals(false);
     552    m_LeftList->refresh();
    509553}
    510554
    511555
    512 /* comments in header */
    513 void MythControls::refreshKeyInformation()
     556/* method description in mythcontrols.h */
     557void MythControls::RefreshRightList()
    514558{
    515     /* get the description of the current action */
    516     QString desc;
     559    QStringList *rstrings = NULL;
     560    QString lstring = m_LeftList->GetItemCurrent()->text();
    517561
    518     if (focused == LeftList)
     562    /* right list, based on values from the left */
     563    switch (m_View)
    519564    {
    520         /* blank all keys on the context */
    521         for (size_t i = 0; i < Action::MAX_KEYS; i++)
    522             ActionButtons[i]->setText("");
     565    case ActionsByContext:
     566        this->ShowButtons(true);
     567        rstrings = m_KeyBindings->GetActions(lstring);
     568        break;
     569    case ActionsByKey:
     570        this->ShowButtons(false);
     571        rstrings = m_KeyBindings->GetKeyActions(lstring);
     572        break;
     573    case ContextsByKey:
     574        this->ShowButtons(false);
     575        rstrings = m_KeyBindings->GetContexts(lstring);
     576        break;
    523577    }
    524     else if (leftType == kKeyList || rightType == kKeyList)
    525     { // Should show appropriate description
    526         QString action = getCurrentAction();
    527         QString context = getCurrentContext();
    528         /* blank all keys on the context */
    529         for (size_t i = 0; i < Action::MAX_KEYS; i++)
    530             ActionButtons[i]->setText("");
    531         if (!action.isEmpty())
    532             {
    533    
    534             desc = key_bindings->getActionDescription(context, action);
    535    
    536             BindingList *list = NULL;
    537             if (leftType == kKeyList && rightType == kContextList)
    538             {
    539                 QString key = getCurrentKey();
    540                 list = keyActions[DisplayToKey(key)];
    541             }
    542             else if (leftType == kContextList && rightType == kKeyList)
    543                 list = contextKeys[context];
    544             if (list)
    545             {
    546                 QString searchKey;
    547                 if (rightType == kContextList)
    548                     searchKey = context;
    549                 else if (rightType == kActionList)
    550                     searchKey = action;
    551                 else if (rightType == kKeyList)
    552                     searchKey = DisplayToKey(getCurrentKey());
    553                 binding_t *binding = NULL;
    554                 for (BindingList::iterator it = list->begin(); it != list->end(); ++it)
    555                 {
    556                     binding_t *b = *it;
    557                     switch (rightType)
    558                     {
    559                         case kContextList:
    560                             if (b->context == searchKey) binding = b;
    561                             break;
    562                         case kActionList:
    563                             if (b->action == searchKey) binding = b;
    564                             break;
    565                         case kKeyList:
    566                             if (b->key == searchKey) binding = b;
    567                             break;
    568                     }
    569                     if (binding) break;
    570                 }
    571    
    572                 if (binding)
    573                 {
    574                     if (desc.isEmpty() && context != binding->contextFrom)
    575                         desc = key_bindings->getActionDescription(binding->contextFrom, action);
    576                     desc += "\n" + tr("Binding comes from %1 context")
    577                             .arg(binding->contextFrom);
    578                 }
    579             }
    580         }
    581     } else {
    582         QString context = getCurrentContext();
    583         QString action = getCurrentAction();
    584         /* set the description */
    585         desc = key_bindings->getActionDescription(getCurrentContext(),
    586                                                   getCurrentAction());
    587578
    588         /* get the bindings of the current action */
    589         QStringList keys = key_bindings->getActionKeys(getCurrentContext(),
    590                                                        getCurrentAction());
     579    RefreshRight(rstrings);
     580    delete rstrings;
     581}
    591582
    592         size_t i;
    593583
    594         /* fill existing keys */
    595         for (i = 0; i < keys.count(); i++)
    596             ActionButtons[i]->setText(KeyToDisplay(keys[i]));
     584void MythControls::RefreshBindingInformation()
     585{
     586    QString context = m_LeftList->GetItemCurrent()->text();
     587    QString action = m_RightList->GetItemCurrent()->text();
     588    QString desc = m_KeyBindings->GetActionDescription(GetCurrentContext(),
     589                                                       GetCurrentAction());
    597590
    598         /* blank the other ones */
    599         for (; i < Action::MAX_KEYS; i++)
    600             ActionButtons[i]->setText("");
    601     }
     591    /* get the bindings of the current action */
     592    QStringList keys = m_KeyBindings->GetActionKeys(GetCurrentContext(),
     593                                                    GetCurrentAction());
    602594
    603     /* set the information */
    604     description->SetText(desc);
     595    FillButtons(keys);
     596
     597    m_Description->SetText(desc);
    605598}
    606599
    607600
    608 
    609 /* comments in header */
    610 QString MythControls::getCurrentContext(void) const
     601/* method description in mythcontrols.h */
     602void MythControls::RefreshInformation()
    611603{
    612     if (leftType == kContextList)
    613         return LeftList->GetItemCurrent()->text();
    614     if (focused == LeftList) return "";
    615 
    616     QString desc = RightList->GetItemCurrent()->text();
    617     int loc = desc.find(" => ");
    618     if (loc == -1) return ""; // Should not happen
    619     if (rightType == kContextList) return desc.left(loc);
    620     else return desc.mid(loc+4);
     604    switch (m_View)
     605    {
     606    case ActionsByContext:
     607        if (m_Focused == m_LeftList)
     608        {
     609            BlankButtons();
     610            m_Description->SetText("");
     611        }
     612        else
     613            RefreshBindingInformation();
     614        break;
     615    case ActionsByKey:
     616        if (m_Focused == m_LeftList)
     617            m_Description->SetText("");
     618        else
     619        {
     620            QString key = m_LeftList->GetItemCurrent()->text();
     621            QString action = m_RightList->GetItemCurrent()->text();
     622            int pos = m_RightList->GetItemPos(m_RightList->GetItemCurrent());
     623            QString context = m_KeyBindings->GetContext(key, action, pos);
     624            QString desc = m_KeyBindings->GetActionDescription(context, action);
     625            desc += "\n" + tr("Binding comes from %1 context").arg(context);
     626            m_Description->SetText(desc);
     627        }
     628        break;
     629    case ContextsByKey:
     630        if (m_Focused == m_LeftList)
     631            m_Description->SetText("");
     632        else
     633        {
     634            QString key = m_LeftList->GetItemCurrent()->text();
     635            QString context = m_RightList->GetItemCurrent()->text();
     636            QString action = m_KeyBindings->GetAction(key, context);
     637            QString desc = action + ": " +
     638                m_KeyBindings->GetActionDescription(context, action);
     639            m_Description->SetText(desc);
     640        }
     641        break;
     642    }
    621643}
    622644
    623645/* comments in header */
    624 QString MythControls::getCurrentAction(void) const
     646QString MythControls::GetCurrentContext(void) const
    625647{
    626     if (leftType == kActionList)
    627         return LeftList->GetItemCurrent()->text();
    628     if (focused == LeftList) return "";
    629 
    630     QString desc = RightList->GetItemCurrent()->text();
    631     if (leftType == kContextList && rightType == kActionList)
    632         return desc;
    633     int loc = desc.find(" => ");
    634     if (loc == -1) return ""; // Should not happen
    635     if (rightType == kActionList) return desc.left(loc);
     648    if (m_View == ActionsByContext)
     649        return m_LeftList->GetItemCurrent()->text();
     650    else if ((m_View == ContextsByKey) && (m_Focused == m_RightList))
     651        return m_RightList->GetItemCurrent()->text();
    636652    else
    637     {
    638         QString rv = desc.mid(loc+4);
    639         if (rv == "<none>") return "";
    640         else return rv;
    641     }
     653        return "";
    642654}
    643655
    644656/* comments in header */
    645 QString MythControls::getCurrentKey(void) const
     657QString MythControls::GetCurrentAction(void) const
    646658{
    647     if (leftType == kKeyList)
    648         return LeftList->GetItemCurrent()->text();
    649     if (focused == LeftList) return "";
    650659
    651     if (leftType == kContextList && rightType == kActionList)
    652     {
    653         QString context = getCurrentContext();
    654         QString action = getCurrentAction();
    655         size_t b = focusedButton();
    656         QStringList keys = key_bindings->getActionKeys(context, action);
    657         if (b < keys.count()) return keys[b];
    658         else return "";
    659     }
    660 
    661     QString desc = RightList->GetItemCurrent()->text();
    662     int loc = desc.find(" => ");
    663     if (loc == -1) return ""; // Should not happen
    664     if (rightType == kKeyList) return desc.left(loc);
    665     else return desc.mid(loc+4);
     660    if (((m_View == ActionsByContext) && (m_Focused != m_LeftList)) ||
     661        ((m_View == ActionsByKey) && (m_Focused == m_RightList)))
     662        return m_RightList->GetItemCurrent()->text();
     663    else
     664        return "";
    666665}
    667666
    668 
    669667/* comments in header */
    670 void MythControls::loadHost(const QString & hostname) {
    671 
    672     /* create the key bindings and the tree */
    673     key_bindings = new KeyBindings(hostname);
    674     contexts = *key_bindings->getContexts();
    675 
    676     keys.clear();
    677 
    678     /* Alphabetic order, but jump and global at the top  */
    679     contexts.sort();
    680     contexts.remove(JUMP_CONTEXT);
    681     contexts.remove(GLOBAL_CONTEXT);
    682     contexts.insert(contexts.begin(), 1, GLOBAL_CONTEXT);
    683     contexts.insert(contexts.begin(), 1, JUMP_CONTEXT);
    684 
    685     QStringList *actions;
    686     for (size_t i = 0; i < contexts.size(); i++)
     668QString MythControls::GetCurrentKey(void) const
     669{
     670    if (m_View == ActionsByContext)
    687671    {
    688         actions = key_bindings->getActions(contexts[i]);
    689         actions->sort();
    690         m_contexts.insert(contexts[i], actions);
     672        QString context = GetCurrentContext();
     673        QString action = GetCurrentAction();
     674        size_t b = FocusedButton();
     675        QStringList keys = m_KeyBindings->GetActionKeys(context, action);
     676        if (b < keys.count())
     677            return keys[b];
     678        else
     679            return "";
    691680    }
    692 
    693     refreshKeyBindings();
    694     updateLists();
     681    else
     682        return m_LeftList->GetItemCurrent()->text();
    695683}
    696684
    697 
    698 
    699685/* comments in header */
    700 void MythControls::deleteKey()
     686void MythControls::DeleteKey()
    701687{
    702688    // This code needs work to support deleteKey in any mode exc. Context/Action
    703     QString context = getCurrentContext();
    704     QString key = getCurrentKey();
    705     QString action = getCurrentAction();
     689    QString context = GetCurrentContext();
     690    QString key = GetCurrentKey();
     691    QString action = GetCurrentAction();
     692
    706693    if (context.isEmpty() || key.isEmpty() || action.isEmpty())
    707694    {
    708695        InvalidBindingPopup popup(gContext->GetMainWindow());
     
    710697        return;
    711698    }
    712699
    713     BindingList *list = keyActions[key];
    714     binding_t *binding = NULL;
    715     for (BindingList::iterator it = list->begin(); it != list->end(); ++it)
     700    if (m_View == ActionsByContext)
    716701    {
    717         binding_t *b = *it;
    718         if (b->context == context) binding = b;
     702        QString trtext =
     703            tr("Delete this key binding from context %1?").arg(context);
     704        ConfirmMenu popup(gContext->GetMainWindow(), trtext);
     705        if (popup.getOption() != ConfirmMenu::CONFIRM)
     706            return;
     707        else
     708        {
     709            m_KeyBindings->RemoveActionKey(context, action, key);
     710        }
    719711    }
    720     if (!binding)
    721     {
    722         InvalidBindingPopup popup(gContext->GetMainWindow());
    723         popup.getOption();
    724         return;
    725     }
    726712
    727     if (binding->contextFrom != context)
    728     {
    729         ConfirmMenu popup(gContext->GetMainWindow(), tr("Delete this key binding from context %1?").arg(binding->contextFrom));
    730         if (popup.getOption() != ConfirmMenu::CONFIRM) return;
    731     } else {
    732         ConfirmMenu popup(gContext->GetMainWindow(), tr("Delete this binding?"));
    733         if (popup.getOption() != ConfirmMenu::CONFIRM) return;
    734     }
    735 
    736     if (!key_bindings->removeActionKey(binding->contextFrom, action, key))
    737     {
    738         InvalidBindingPopup popup(gContext->GetMainWindow());
    739         popup.getOption();
    740         return;
    741     }
    742 
    743     // refreshing everything is overkill.  I tried incrementally updating, but the
    744     // code was ugly.  Since this is quick in my experience, overkill away!
    745     refreshKeyBindings();
    746     refreshKeyInformation();
     713    RefreshInformation();
    747714}
    748715
    749716/* method description in header */
    750 bool MythControls::resolveConflict(ActionID *conflict, int level)
     717bool MythControls::ResolveConflict(ActionID *conflict, int level)
    751718{
    752719    MythMainWindow *window = gContext->GetMainWindow();
    753720
    754721    /* prevent a fatal binding */
    755722    if (level == KeyBindings::Error)
    756723    {
    757         InvalidBindingPopup popup(gContext->GetMainWindow(),
    758                                   conflict->action(),
     724        InvalidBindingPopup popup(gContext->GetMainWindow(), conflict->action(),
    759725                                  conflict->context());
    760726        popup.getOption();
    761727        return false;
     
    778744
    779745
    780746/* method description in header */
    781 void MythControls::addKeyToAction(void)
     747void MythControls::AddKeyToAction(void)
    782748{
    783     // This code needs work to support deleteKey in any mode exc. Context/Action
    784749    /* grab a key from the user */
    785750    KeyGrabPopupBox *kg = new KeyGrabPopupBox(gContext->GetMainWindow());
    786751    int result = kg->ExecPopup(kg,SLOT(cancel()));
     
    788753    delete kg;
    789754
    790755    /* go no further if canceled */
    791     if (result == 0) return;
     756    if (result == 0)
     757        return;
    792758
    793759    /* get the keys for the selected action */
    794     size_t b = focusedButton();
    795     QString action = getCurrentAction(), context = getCurrentContext();
    796     QStringList keys = key_bindings->getActionKeys(context, action);
     760    size_t b = FocusedButton();
     761    QString action = GetCurrentAction(), context = GetCurrentContext();
     762    QStringList keys = m_KeyBindings->GetActionKeys(context, action);
    797763
    798764    /* dont bother rebinding the same key */
    799     if (keys[b] == key) return;
     765    if (keys[b] == key)
     766        return;
    800767
    801768    bool bind = true;
    802769    int level;
    803770
    804771    /* get the potential conflict */
    805772    ActionID *conflict = NULL;
    806     if ((conflict = key_bindings->conflicts(context, key, level)))
    807         bind = resolveConflict(conflict, level);
     773    if ((conflict = m_KeyBindings->Conflicts(context, key, level)))
     774        bind = ResolveConflict(conflict, level);
    808775
    809776    delete conflict;
    810777
    811778    /* dont bind if we shouldn't bind */
    812     if (!bind) return;
     779    if (!bind)
     780        return;
    813781
    814782    /* finally bind or rebind a key to the action */
    815783    if (b < keys.count())
    816         key_bindings->replaceActionKey(context,action, key, keys[b]);
     784        m_KeyBindings->ReplaceActionKey(context,action, key, keys[b]);
    817785    else
    818         key_bindings->addActionKey(context, action, key);
     786        m_KeyBindings->AddActionKey(context, action, key);
    819787
    820     refreshKeyBindings();
    821     refreshKeyInformation();
     788    RefreshInformation();
    822789}
    823790
    824 
    825 
    826 void MythControls::addBindings(QDict<binding_t> &bindings,
    827                                const QString &context,
    828                                const QString &contextParent, int bindlevel)
    829 {
    830     QStringList *actions = key_bindings->getActions(context);
    831 
    832     for (size_t i = 0; i < actions->size(); i++)
    833     {
    834         QString action = (*actions)[i];
    835         QStringList keys = key_bindings->getActionKeys(context, action);
    836 
    837         for (size_t j = 0; j < keys.size(); j++)
    838         {
    839             QString key = keys[j];
    840 
    841             binding_t *b = bindings.find(key);
    842             if (!b)
    843             {
    844                 b = new(binding_t);
    845                 b->key = key;
    846                 b->action = action;
    847                 b->context = contextParent;
    848                 b->contextFrom = context;
    849                 b->bindlevel = bindlevel;
    850                 bindings.insert(key, b);
    851             }
    852             else if (b->bindlevel == bindlevel)
    853             {
    854                 b->action += ", " + action;
    855             }
    856         }
    857     }
    858 }
    859 
    860 BindingList *MythControls::getKeyBindings(const QString &context)
    861 {
    862     QStringList keys;
    863     QDict<binding_t> bindings;
    864     bindings.clear();
    865 
    866     for (size_t i = 0; i < contexts.size(); i++)
    867         addBindings(bindings, contexts[i], context, i);
    868 
    869 
    870     for (QDictIterator<binding_t> it(bindings); it.current(); ++it)
    871     {
    872         QString key = it.currentKey();
    873         keys.append(key);
    874     }
    875 
    876     sortKeyList(keys);
    877 
    878     BindingList *retval = new BindingList;
    879     retval->clear();
    880 
    881     for (QStringList::Iterator kit = keys.begin(); kit != keys.end(); ++kit)
    882     {
    883         QString key = *kit;
    884         retval->append(bindings[key]);
    885     }
    886     retval->setAutoDelete(true);
    887     return retval;
    888 }
    889 
    890 void MythControls::refreshKeyBindings()
    891 {
    892     contextKeys.clear();
    893     keyActions.clear();
    894     for (size_t i = 0; i < contexts.size(); i++)
    895     {
    896         QString context = contexts[i];
    897         BindingList *list = getKeyBindings(context);
    898         contextKeys.insert(context, list);
    899         for (BindingList::iterator it = list->begin(); it != list->end(); ++it)
    900         {
    901             binding_t *b = *it;
    902             BindingList *list = keyActions.find(b->key);
    903             if (!list)
    904             {
    905                 list = new BindingList;
    906                 list->clear();
    907                 keyActions.insert(b->key, list);
    908             }
    909             keys.append(b->key);
    910             list->append(b);
    911         }
    912     }
    913     contextKeys.setAutoDelete(true);
    914     keyActions.setAutoDelete(true);
    915 
    916     sortKeyList(keys);
    917 }
    918 
    919 void MythControls::sortKeyList(QStringList &keys)
    920 {
    921     QStringList t;
    922     t.clear();
    923 
    924     for ( QStringList::Iterator it = keys.begin(); it != keys.end(); ++it )
    925     {
    926         QString key = *it;
    927 
    928         QString keydesc = "3 ";
    929         if (key.left(6) == "remote")
    930         {
    931             keydesc = "0 ";
    932         }
    933         else if (key.length() == 1)
    934         {
    935             switch (key[0].category())
    936             {
    937                 case QChar::Letter_Uppercase:
    938                     keydesc = "2 ";
    939                     break;
    940                 case QChar::Number_DecimalDigit:
    941                     keydesc = "1 ";
    942                     break;
    943                 default:
    944                     keydesc = "5 ";
    945                     break;
    946             }
    947         }
    948         else if (key.find("+", 1) != -1)
    949             keydesc = "4 ";
    950 
    951         t.push_back(keydesc + key);
    952     }
    953     t.sort();
    954 
    955     QString prev = "";
    956 
    957     keys.clear();
    958     for (QStringList::Iterator kit = t.begin(); kit != t.end(); ++kit)
    959     {
    960         QString cur = (*kit).mid(2);
    961         if (cur != prev)
    962         {
    963             keys.append(cur);
    964             prev = cur;
    965         }
    966     }
    967 }
    968 
    969 QString MythControls::getTypeDesc(ListType type)
    970 {
    971     switch (type)
    972     {
    973         case kContextList:
    974             return tr("Contexts");
    975             break;
    976         case kKeyList:
    977             return tr("Keys");
    978             break;
    979         case kActionList:
    980             return tr("Actions");
    981             break;
    982         default:
    983             return "";
    984     }
    985 }
    986 
    987 void MythControls::updateLists()
    988 {
    989     RightList->blockSignals(true);
    990     LeftList->blockSignals(true);
    991     LeftList->Reset();
    992     if (leftType == kContextList)
    993     {
    994         UIListBtnTypeItem *item;
    995         for (size_t i = 0; i < contexts.size(); i++)
    996         {
    997             item = new UIListBtnTypeItem(LeftList, contexts[i]);
    998             item->setDrawArrow(true);
    999         }
    1000     } else if (leftType == kKeyList)
    1001     {
    1002         UIListBtnTypeItem *item;
    1003         for (size_t i = 0; i < keys.size(); i++)
    1004         {
    1005             QString key = KeyToDisplay(keys[i]);
    1006             item = new UIListBtnTypeItem(LeftList, key);
    1007             item->setDrawArrow(true);
    1008         }
    1009     }
    1010     refreshRightList();
    1011     RightList->blockSignals(false);
    1012     LeftList->blockSignals(false);
    1013     LeftList->refresh();
    1014     RightList->refresh();
    1015 
    1016     if (LeftDesc != NULL)
    1017         LeftDesc->SetText(getTypeDesc(leftType));
    1018     if (RightDesc != NULL)
    1019         RightDesc->SetText(getTypeDesc(rightType));
    1020 }
    1021 
    1022 
    1023791#endif /* MYTHCONTROLS_CPP */
    1024792
    1025793/* vim: set expandtab tabstop=4 shiftwidth=4: */
  • mythcontrols/keybindings.cpp

     
    2626 * and the UI.
    2727 */
    2828
    29 /* QT */
    3029#include <qstring.h>
    31 
    32 /* MythTV */
    3330#include <mythtv/mythcontext.h>
    3431#include <mythtv/mythdialogs.h>
    3532
     
    3835#include "keybindings.h"
    3936
    4037
    41 
    4238KeyBindings::KeyBindings(const QString & hostname)
    4339{
    44     this->hostname() = hostname;
    45     loadManditoryBindings();
     40    m_HostName = hostname;
     41    LoadMandatoryBindings();
    4642
    47     retrieveContexts();
    48     retrieveJumppoints();
     43    RetrieveContexts();
     44    RetrieveJumppoints();
    4945}
    5046
     47QStringList * KeyBindings::GetKeyActions(const QString &key) const
     48{
     49    QStringList *strings;
     50    const ActionList & al = m_ActionSet.GetActions(key);
    5151
     52    if (al.size() > 0)
     53        strings = new QStringList();
     54    else
     55        return NULL;
    5256
    53 ActionID * KeyBindings::conflicts(const QString & context_name,
     57    for (size_t i = 0; i < al.size(); i++)
     58        strings->push_back(al[i].action());
     59
     60    return strings;
     61}
     62
     63
     64QString KeyBindings::GetContext(const QString & key, const QString & action,
     65                                size_t anum) const
     66{
     67    /* The cases where unknown is returned should never happen.  If
     68     * you see an unknown context, do not approach it.  Call the
     69     * police immediatly. */
     70    const ActionList &al = m_ActionSet.GetActions(key);
     71    int offset = al.size() - anum;
     72
     73    if (offset < 0)
     74        return "UNKNOWN";
     75    else if (al[anum].action() != action)
     76        return "UNKNOWN";
     77    if (anum < al.size())
     78        return al[anum].context();
     79    else
     80        return "UNKNOWN";
     81}
     82
     83QString KeyBindings::GetAction(const QString & key,
     84                               const QString & context) const
     85{
     86    const ActionList &al = m_ActionSet.GetActions(key);
     87
     88    for (size_t i = 0; i < al.size(); i++)
     89    {
     90        if (al[i].context() == context)
     91            return al[i].action();
     92    }
     93    return "UNKNOWN";
     94}
     95
     96
     97ActionID * KeyBindings::Conflicts(const QString & context_name,
    5498                                  const QString & key, int &level) const
    5599{
    56     const ActionList &ids = actionset.getActions(key);
     100    const ActionList &ids = m_ActionSet.GetActions(key);
    57101
    58102    /* trying to bind a jumppoint to an already bound key */
    59103    if ((context_name == JUMP_CONTEXT) && (ids.count() > 0))
     
    84128
    85129
    86130/* method description in header */
    87 bool KeyBindings::removeActionKey(const QString & context_name,
     131bool KeyBindings::RemoveActionKey(const QString & context_name,
    88132                                  const QString & action_name,
    89133                                  const QString & key)
    90134{
    91135
    92136    ActionID id(context_name, action_name);
    93137
    94     /* dont remove the last manditory binding */
    95     if (getManditoryBindings().contains(id)&&(actionset.getKeys(id).count()<2))
     138    /* dont remove the last mandatory binding */
     139    if (getMandatoryBindings().contains(id) &&
     140        (m_ActionSet.GetKeys(id).count()<2))
    96141        return false;
    97142    else
    98         return this->actionset.remove(id,key);
     143        return this->m_ActionSet.Remove(id,key);
    99144}
    100145
    101146
    102147
    103148/* method description in header */
    104 void KeyBindings::commitAction(const ActionID & id)
     149void KeyBindings::CommitAction(const ActionID & id)
    105150{
    106151
    107152    MSqlQuery query(MSqlQuery::InitCon());
     
    112157
    113158    if (query.isConnected())
    114159    {
    115         QString keys = actionset.keyString(id);
    116         query.bindValue(":HOSTNAME", this->getHostname());
     160        QString keys = m_ActionSet.KeyString(id);
     161        query.bindValue(":HOSTNAME", m_HostName);
    117162        query.bindValue(":CONTEXT", id.context());
    118163        query.bindValue(":ACTION", id.action());
    119164        query.bindValue(":KEYLIST", keys);
     
    131176
    132177
    133178
    134 void KeyBindings::commitJumppoint(const ActionID &id)
     179void KeyBindings::CommitJumppoint(const ActionID &id)
    135180{
    136181
    137182    MSqlQuery query(MSqlQuery::InitCon());
     
    142187
    143188    if (query.isConnected())
    144189    {
    145         QString keys = actionset.keyString(id);
    146         query.bindValue(":HOSTNAME", this->getHostname());
     190        QString keys = m_ActionSet.KeyString(id);
     191        query.bindValue(":HOSTNAME", this->m_HostName);
    147192        query.bindValue(":DESTINATION", id.action());
    148193        query.bindValue(":KEYLIST", keys);
    149194
     
    161206
    162207
    163208
    164 void KeyBindings::commitChanges(void)
     209void KeyBindings::CommitChanges(void)
    165210{
    166     ActionList modified = actionset.getModified();
     211    ActionList modified = m_ActionSet.GetModified();
    167212
    168213    while (modified.size() > 0)
    169214    {
    170215        ActionID id = modified.front();
    171216
    172217        /* commit either a jumppoint or an action */
    173         if (id.context() == JUMP_CONTEXT) commitJumppoint(id);
    174         else commitAction(id);
     218        if (id.context() == JUMP_CONTEXT)
     219            CommitJumppoint(id);
     220        else
     221            CommitAction(id);
    175222
    176223        /* tell the action set that the action is no longer modified */
    177         actionset.unmodify(id);
     224        m_ActionSet.Unmodify(id);
    178225
    179226        modified.pop_front();
    180227    }
     
    182229
    183230
    184231
    185 void KeyBindings::retrieveJumppoints()
     232void KeyBindings::RetrieveJumppoints()
    186233{
    187234    MSqlQuery query(MSqlQuery::InitCon());
    188235
     
    192239                      "FROM jumppoints "
    193240                      "WHERE hostname = :HOSTNAME "
    194241                      "ORDER BY destination ;");
    195         query.bindValue(":HOSTNAME", this->getHostname());
     242        query.bindValue(":HOSTNAME", m_HostName);
    196243    }
    197244
    198245    query.exec();
     
    202249        ActionID id(JUMP_CONTEXT, query.value(0).toString());
    203250
    204251        if (query.value(1).toString().isEmpty())
    205         {
    206             actionset.addAction(id, query.value(0).toString(),
    207                                 query.value(2).toString());
    208         }
    209         else actionset.addAction(id,query.value(1).toString(),
    210                                  query.value(2).toString());
     252            m_ActionSet.AddAction(id, query.value(0).toString(),
     253                                  query.value(2).toString());
     254        else
     255            m_ActionSet.AddAction(id,query.value(1).toString(),
     256                                  query.value(2).toString());
    211257    }
    212258}
    213259
    214260
    215261
    216 void KeyBindings::retrieveContexts()
     262void KeyBindings::RetrieveContexts()
    217263{
    218264
    219265    MSqlQuery query(MSqlQuery::InitCon());
     
    225271                      "WHERE hostname = :HOSTNAME "
    226272                      "ORDER BY context,action ;");
    227273
    228         query.bindValue(":HOSTNAME", this->getHostname());
     274        query.bindValue(":HOSTNAME", this->m_HostName);
    229275    }
    230276
    231277    query.exec();
     
    233279    for (query.next(); query.isValid(); query.next())
    234280    {
    235281        ActionID id(query.value(0).toString(), query.value(1).toString());
    236         this->actionset.addAction(id, query.value(2).toString(),
    237                                   query.value(3).toString());
     282        this->m_ActionSet.AddAction(id, query.value(2).toString(),
     283                                    query.value(3).toString());
    238284    }
    239285}
    240286
    241287
    242288
    243 void KeyBindings::loadManditoryBindings(void)
     289void KeyBindings::LoadMandatoryBindings(void)
    244290{
    245     if (getManditoryBindings().empty())
     291    if (m_MandatoryBindings.empty())
    246292    {
    247         manditoryBindings().append(ActionID(GLOBAL_CONTEXT, "DOWN"));
    248         defaultKeys().append("Down");
     293        m_MandatoryBindings.append(ActionID(GLOBAL_CONTEXT, "DOWN"));
     294        m_DefaultKeys.append("Down");
    249295
    250         manditoryBindings().append(ActionID(GLOBAL_CONTEXT, "UP"));
    251         defaultKeys().append("Up");
     296        m_MandatoryBindings.append(ActionID(GLOBAL_CONTEXT, "UP"));
     297        m_DefaultKeys.append("Up");
    252298
    253         manditoryBindings().append(ActionID(GLOBAL_CONTEXT, "LEFT"));
    254         defaultKeys().append("Left");
     299        m_MandatoryBindings.append(ActionID(GLOBAL_CONTEXT, "LEFT"));
     300        m_DefaultKeys.append("Left");
    255301
    256         manditoryBindings().append(ActionID(GLOBAL_CONTEXT, "RIGHT"));
    257         defaultKeys().append("Right");
     302        m_MandatoryBindings.append(ActionID(GLOBAL_CONTEXT, "RIGHT"));
     303        m_DefaultKeys.append("Right");
    258304
    259         manditoryBindings().append(ActionID(GLOBAL_CONTEXT, "ESCAPE"));
    260         defaultKeys().append("Esc");
     305        m_MandatoryBindings.append(ActionID(GLOBAL_CONTEXT, "ESCAPE"));
     306        m_DefaultKeys.append("Esc");
    261307
    262         manditoryBindings().append(ActionID(GLOBAL_CONTEXT, "SELECT"));
    263         defaultKeys().append("Return,Enter,Space");
     308        m_MandatoryBindings.append(ActionID(GLOBAL_CONTEXT, "SELECT"));
     309        m_DefaultKeys.append("Return,Enter,Space");
    264310    }
    265311}
    266312
    267313
    268314
    269 bool KeyBindings::hasManditoryBindings(void) const
     315bool KeyBindings::HasMandatoryBindings(void) const
    270316{
    271     ActionList manlist = getManditoryBindings();
     317    ActionList manlist = getMandatoryBindings();
    272318    for (size_t i = 0; i < manlist.count(); i++)
    273319    {
    274         if (actionset.getKeys(manlist[i]).isEmpty())
     320        if (m_ActionSet.GetKeys(manlist[i]).isEmpty())
    275321            return false;
    276322    }
    277323
  • mythcontrols/actionset.cpp

     
    3636
    3737
    3838/* method description in header */
    39 bool ActionSet::add(const ActionID &id, const QString &key)
     39bool ActionSet::Add(const ActionID &id, const QString &key)
    4040{
    4141    Action *a;
    4242
    4343    /* get the action; make sure it exists before doing anything */
    44     if ((a = this->action(id)))
     44    if ((a = this->GetAction(id)))
    4545    {
    4646
    4747        /* if the key was added, mark this action as modified, and
    4848           update the key map */
    49         if (a->addKey(key))
     49        if (a->AddKey(key))
    5050        {
    51             ActionList &ids = _keymap[key];
     51            ActionList &ids = m_KeyMap[key];
    5252            ids.push_back(id);
    53             this->modify(id);   
     53            this->Modify(id);   
    5454            return true;
    5555        }
    5656    }
     
    6161
    6262
    6363/* method description in header */
    64 bool ActionSet::remove(const ActionID &id, const QString & key)
     64bool ActionSet::Remove(const ActionID &id, const QString & key)
    6565{
    6666
    6767    Action *a;
    6868
    6969    /* make sure an action exists before removing */
    70     if ((a = this->action(id)))
     70    if ((a = this->GetAction(id)))
    7171    {
    7272        /* if the key was removed from the action, then remove it from
    7373         * the key list, and mark the action id as modified */
    74         if (a->removeKey(key))
     74        if (a->RemoveKey(key))
    7575        {
    7676            /* remove the action from the key map */
    77             this->_keymap[key].remove(id);
     77            this->m_KeyMap[key].remove(id);
    7878
    7979            /* mark the action as modified */
    80             this->modify(id);
     80            this->Modify(id);
    8181
    8282            return true;           
    8383        }
     
    9090
    9191
    9292/* method description in header */
    93 bool ActionSet::replace(const ActionID &id, const QString &newkey,
     93bool ActionSet::Replace(const ActionID &id, const QString &newkey,
    9494                        const QString &oldkey)
    9595{
    9696    Action *a;
    9797
    9898    /* make sure an action exists before replacing */
    99     if ((a = this->action(id)))
     99    if ((a = this->GetAction(id)))
    100100    {
    101101
    102102        /* make sure the key was actually replaced before modifying */
    103         if (a->replaceKey(newkey, oldkey))
     103        if (a->ReplaceKey(newkey, oldkey))
    104104        {
    105105            /* remove the action from the old key */
    106             this->_keymap[oldkey].remove(id);
     106            this->m_KeyMap[oldkey].remove(id);
    107107
    108108            /* add the action to the new key */
    109             this->_keymap[newkey].push_back(id);
     109            this->m_KeyMap[newkey].push_back(id);
    110110
    111111            /* mark the action as modified */
    112             this->modify(id);
     112            this->Modify(id);
    113113
    114114            /* the job is done, return true */
    115115            return true;           
     
    123123
    124124
    125125/* method description in header */
    126 QStringList * ActionSet::contextStrings(void) const
     126QStringList * ActionSet::ContextStrings(void) const
    127127{
    128128    QStringList *context_strings = new QStringList();
    129     QDictIterator<Context> it(_contexts);
     129    QDictIterator<Context> it(m_Contexts);
    130130
    131131    for (; it.current(); ++it)
    132132        context_strings->append(it.currentKey());
     
    137137
    138138
    139139/* method description in header */
    140 QStringList * ActionSet::actionStrings(const QString &context_name) const
     140QStringList * ActionSet::ActionStrings(const QString &context_name) const
    141141{
    142     Context *c = _contexts[context_name];
     142    Context *c = m_Contexts[context_name];
    143143
    144     if (c == NULL) return NULL;
     144    if (c == NULL)
     145        return NULL;
    145146    else
    146147    {
    147148        QStringList *action_strings = new QStringList();
    148         QDictIterator<Action> it(*(_contexts[context_name]));
     149        QDictIterator<Action> it(*(m_Contexts[context_name]));
    149150
    150151        for (; it.current(); ++it)
    151152            action_strings->append(it.currentKey());
     
    154155    }
    155156}
    156157
     158QStringList * ActionSet::GetAllKeys(void) const
     159{
     160    return new QStringList(this->m_KeyMap.keys());
     161}
    157162
    158163
     164QStringList * ActionSet::GetAllActions(void) const
     165{
     166    return new QStringList(this->m_Actions.keys());
     167}
     168
     169
     170QStringList * ActionSet::GetKeyContexts(const QString &key) const
     171{
     172    QStringList *strings = NULL;
     173    const ActionList &ids = m_KeyMap[key];
     174
     175    if (ids.size() == 0)
     176        return NULL;
     177
     178    strings = new QStringList();
     179
     180    for (size_t i = 0; i < ids.size(); i++)
     181    {
     182        if (!strings->contains(ids[i].context()))
     183            strings->push_back(ids[i].context());
     184    }
     185
     186    return strings;
     187}
     188
     189
    159190/* method description in header */
    160 bool ActionSet::addAction(const ActionID &id, const QString &description,
     191bool ActionSet::AddAction(const ActionID &id, const QString &description,
    161192                          const QString &keys)
    162193{
    163     if (!_contexts[id.context()]) _contexts.insert(id.context(),
    164                                                   new Context());
     194    if (!m_Contexts[id.context()])
     195        m_Contexts.insert(id.context(), new Context());
    165196
    166197    /* return false if the action already exists */
    167     if ((*_contexts[id.context()])[id.action()]) return false;
     198    if ((*m_Contexts[id.context()])[id.action()])
     199        return false;
    168200    else
    169201    {
    170202        /* create the action */
    171203        Action *a = new Action(description, keys);
    172204
    173205        /* add the action into the dict */
    174         _contexts[id.context()]->insert(id.action(), a);
     206        m_Contexts[id.context()]->insert(id.action(), a);
    175207
     208        /* if the action doesn't already exist, then add it */
     209        QStringList &contexts = m_Actions[id.action()];
     210        if (!contexts.contains(id.context()))
     211            contexts.push_back(id.context());
     212
    176213        /* get the actions keys */
    177         const QStringList &keys = a->getKeys();
     214        const QStringList &keys = a->GetKeys();
    178215        for (size_t i = 0; i < keys.count(); i++)
    179216        {
    180217            /* get the action list (of actions bound to keys[i])
    181218               if there is no key, keys[i], in the map, it will be added now */
    182             ActionList &ids = _keymap[keys[i]];
     219            ActionList &ids = m_KeyMap[keys[i]];
    183220
    184221            /* add this action id to the list of actions bound to this key */
    185             ids.push_back(id);
     222            if (ids.size() == 0)
     223                ids.push_back(id);
     224            else
     225            {
     226                bool added = false;
     227                ActionList::iterator it;
     228
     229                /* keep list sorted by action, then by context.  You
     230                 * must sort this stuff because multiple actions from
     231                 * different contexts can be added. Otherwise, we get
     232                 * into trouble in keybindings.cpp and
     233                 * mythcontrols.cpp when trying to delete based on
     234                 * action (displayed by key) */
     235                for (it = ids.begin(); (it != ids.end()) && (added == false);
     236                     ++it)
     237                {
     238                    if ((QString::compare(id.action(), (*it).action()) < 0) ||
     239                        ((QString::compare(id.action(), (*it).action()) == 0) &&
     240                         (QString::compare(id.context(), (*it).context()) < 0)))
     241                    {
     242                        ids.insert(it, id);
     243                        added = true;
     244                        break;
     245                    }
     246                }
     247                if (added == false) ids.push_back(id);
     248            }
    186249        }
    187 
    188250        return true;
    189251    }
    190 
    191252    return false;
    192253}
    193254
    194255
    195256
    196 QString ActionSet::keyString(const ActionID &id) const
     257QString ActionSet::KeyString(const ActionID &id) const
    197258{
    198259    Context *c;
    199     if ((c = _contexts[id.context()]))
     260    if ((c = m_Contexts[id.context()]))
    200261    {
    201262        Action *a;
    202263        if ((a = (*c)[id.action()]))
    203264        {
    204             return a->keyString();
     265            return a->KeyString();
    205266        }
    206267    }
    207268    return QString::null;
     
    209270
    210271
    211272
    212 QStringList ActionSet::getKeys(const ActionID &id) const
     273QStringList ActionSet::GetKeys(const ActionID &id) const
    213274{
    214275    Context *c;
    215     if ((c = _contexts[id.context()]))
     276    if ((c = m_Contexts[id.context()]))
    216277    {
    217278        Action *a;
    218279        if ((a = (*c)[id.action()]))
    219         {
    220             return a->getKeys();
    221         }
     280            return a->GetKeys();
    222281    }
    223282
    224283    return QStringList();
    225284}
    226285
    227286
    228 
    229 const QString & ActionSet::getDescription(const ActionID &id) const
     287const QString & ActionSet::GetDescription(const ActionID &id) const
    230288{
    231289    Context *c;
    232     if ((c = _contexts[id.context()]))
     290    if ((c = m_Contexts[id.context()]))
    233291    {
    234292        Action *a;
    235293        if ((a = (*c)[id.action()]))
    236         {
    237             return a->getDescription();
    238         }
     294            return a->GetDescription();
    239295    }
    240296
    241297    return QString::null;
    242298}
    243299
    244 
    245 
    246 const ActionList & ActionSet::getActions(const QString &key) const
    247 {
    248     return _keymap[key];
    249 }
    250 
    251 
    252300#endif /* ACTIONSET_CPP */
  • mythcontrols/mythcontrols.h

     
    2929
    3030#include "keybindings.h"
    3131
    32 typedef struct
    33 {
    34     QString key;
    35     QString context;
    36     QString contextFrom;
    37     QString action;
    38     int bindlevel;
    39 } binding_t;
    40 
    41 typedef QPtrList<binding_t> BindingList;
    42 
    4332/**
    4433 * @class MythControls
    4534 * @brief The myth controls configuration class.
     
    5140
    5241public:
    5342    /**
    54      * @brief Create a new myth controls wizard.
     43     * Create a new myth controls wizard.
     44     *
    5545     * @param parent The main myth window.
    5646     * @param name The name of this window?  I dunno, none of the docs
    5747     * say.
     
    6050     */
    6151    MythControls(MythMainWindow *parent, bool& ui_ok);
    6252
    63     /**
    64      * @brief Delete the myth controls object.
    65      */
     53    /** Delete the myth controls object. */
    6654    ~MythControls();
    6755
    6856    /**
    69      * @brief Get the currently selected context string.
     57     * Get the currently selected context string. If no context is
     58     * selected, an empty string is returned.
     59     *
    7060     * @return The currently selected context string.
    71      *
    72      * If no context is selected, an empty string is returned.
    7361     */
    74     QString getCurrentContext(void) const;
     62    QString GetCurrentContext(void) const;
    7563
    7664    /**
    77      * @brief Get the currently selected action string.
     65     * Get the currently selected action string. If no action is
     66     * selected, an empty string is returned.
     67     *
    7868     * @return The currently selected action string.
    79      *
    80      * If no action is selected, an empty string is returned.
    8169     */
    82     QString getCurrentAction(void) const;
     70    QString GetCurrentAction(void) const;
    8371
    8472    /**
    85      * @brief Get the currently selected key string
     73     * Get the currently selected key string.  If no context is
     74     * selected, an empty string is returned.
     75     *
    8676     * @return The currently selected key string
    87      *
    88      * If no context is selected, an empty string is returned.
    8977     */
    90     QString getCurrentKey(void) const;
     78    QString GetCurrentKey(void) const;
    9179
    92    
    93    
    9480protected:
    9581
     82
     83    /** The view mode */
     84    typedef enum { ActionsByContext, ActionsByKey, ContextsByKey } ViewMode;
     85
    9686    /**
    97      * @brief Load up UI.
    98      * @return true if all UI elements were loaded successfully,
    99      * otherwise false it returned.
     87     * Load up UI.
    10088     *
    101      * This method grabs all of the UI "thingies" that are needed by
    102      * mythcontrols.  If this method returns false, the plugin should
    103      * exit since it will probably just core dump.
     89     * @return true if all UI elements were loaded successfully
    10490     */
    105     bool loadUI();
     91    bool LoadUI();
    10692
    10793    /**
     94     * Show or hide the buttons at the bottom.
     95     *
     96     * @param shown Should the buttons be shown?
     97     */
     98    void ShowButtons(bool shown) const;
     99
     100    /**
     101     * Blank the text in the bottom buttons.
     102     */
     103    void BlankButtons(void) const;
     104
     105    /**
     106     * Fill the buttons with the strings in a string list.
     107     * @param strings The string list.
     108     */
     109    void FillButtons(const QStringList & strings);
     110
     111    /**
     112     * Set the viewing mode of the plugin.
     113     *
     114     * @param view The view mode.
     115     * @param force Force the view to be set (or reset)
     116     */
     117    void SetView(ViewMode newview, bool force=false);
     118
     119    /**
    108120     * @brief The key press handler.
    109121     * @param e The key event.
    110122     */
    111123    void keyPressEvent(QKeyEvent *e);
    112124
    113125    /**
    114      * @brief Redraw the key information
     126     * Refresh the action description and key binding buttons.
     127     */
     128    void RefreshBindingInformation();
     129
     130    /**
     131     * @brief Redraw the information at the bottom.
     132     */
     133    void RefreshInformation();
     134
     135    /**
     136     * Refresh the right list.
    115137     *
    116      * Updates the list of keys that are shown and the description of
    117      * the action.
     138     * @param strings The strings to place in the right list.
    118139     */
    119     void refreshKeyInformation();
     140    void RefreshRight(QStringList * strings);
    120141
    121142    /**
    122      * @brief Load the appropriate actions into the action list.
    123      * @param context The context, from which actions will be
    124      * displayed.
     143     * Refresh the left list.
     144     *
     145     * @param string The strings to place in the left list.
    125146     */
    126     void refreshRightList(void);
     147    void RefreshLeft(QStringList * strings);
    127148
    128149    /**
    129      * @brief Redisplay both the left and right lists and fix focus
     150     * Load the appropriate information into the right list.
     151     *
     152     * @param strings The strings to load into the right list.
    130153     */
    131     void updateLists(void);
     154    void RefreshRightList();
    132155
     156    /** Redisplay both the left and right lists and fix focus */
     157    void UpdateLists(void);
     158
    133159    /**
    134      * @brief Load the settings for a particular host.
     160     * Load the settings for a particular host.
     161     *
    135162     * @param hostname The host to load settings for.
    136163     */
    137     void loadHost(const QString & hostname);
     164    void LoadHost(const QString & hostname);
    138165
    139166    /**
    140      * @brief Focus a button in a particular direction.
     167     * Focus a button in a particular direction.
     168     *
    141169     * @param direction Positave values focus to the right, negatives
    142170     * to the left.  A value of zero focuses the first button.
    143171     */
    144     void focusButton(int direction);
     172    void FocusButton(int direction);
    145173
    146174    /**
    147      * @brief Determine which button is focused.
     175     * Determine which button is focused.
     176     *
    148177     * @return Action::MAX_KEYS is no button is focused, otherwise, the
    149178     * index of the button is returned.
    150      *
    151      * @sa Action::MAX_KEYS
    152179     */
    153     size_t focusedButton(void) const;
     180    size_t FocusedButton(void) const;
    154181
    155182    /**
    156      * @brief Resolve a potential conflict.
     183     * Resolve a potential conflict.
     184     *
    157185     * @return true if the conflict should be bound, otherwise, false
    158186     * is returned.
    159187     */
    160     bool resolveConflict(ActionID *conflict, int level);
     188    bool ResolveConflict(ActionID *conflict, int level);
    161189
    162190    /**
    163      * @brief Focus a new list and take focus away from the old.
     191     * Focus a new list and take focus away from the old.
     192     *
    164193     * @param focus The list to gain focus
    165194     * @param unfocus The list to loose focus
    166195     */
    167     void switchListFocus(UIListBtnType *focus, UIListBtnType *unfocus);
     196    void SwitchListFocus(UIListBtnType *focus, UIListBtnType *unfocus);
    168197
    169     /**
    170      * @brief Add bindings to QDict<binding_t> for specified context
    171      * @param bindings the QDict to which to add the bindings
    172      * @param context the context to grab keybindings from
    173      * @param contextParent the context whose keybindings are being calculated
    174      * @param bindlevel the bind level associated with this context
    175      */
    176     void addBindings(QDict<binding_t> &bindings, const QString &context, const QString &contextParent, int bindlevel);
    177 
    178     /**
    179      * @brief Create a BindingList for the specified context
    180      * @param context the context for which a BindingList should be created
    181      */
    182     BindingList *getKeyBindings(const QString &context);
    183 
    184198private slots:
    185199
    186 /**
    187  * @brief Add a key to the currently selected action.
    188  */
    189 void addKeyToAction(void);
     200        /** Add a key to the currently selected action. */
     201        void AddKeyToAction(void);
    190202
    191     /**
    192      * @brief Delete the currently active key.
    193      */
    194     void deleteKey();
     203    /** Delete the currently active key. */
     204    void DeleteKey();
    195205
    196     /**
    197      * @brief Save the settings.
    198      */
    199     inline void save(void) { key_bindings->commitChanges(); }
     206    /** Save the settings. */
     207    inline void Save(void)
     208    {
     209       m_KeyBindings->CommitChanges();
     210    }
    200211
    201212    /**
    202      * @brief Recieves a signal when an item in the left list is
    203      * selected.
     213     * Recieves a signal when an item in the left list is selected.
     214     *
    204215     * @param item The selected item.
    205216     */
    206     void leftSelected(UIListBtnTypeItem *item);
     217    void LeftSelected(UIListBtnTypeItem *item);
    207218
    208219    /**
    209      * @brief Recieves a signal when an item in the right list is
    210      * selected.
     220     * Recieves a signal when an item in the right list is selected.
     221     *
    211222     * @param item The selected item.
    212223     */
    213     void rightSelected(UIListBtnTypeItem *item);
     224    void RightSelected(UIListBtnTypeItem *item);
    214225
    215     /**
    216      * @brief Sort a list of keys, removing duplicates
    217      * @param keys the list of keys to sort
    218      */
    219     void sortKeyList(QStringList &keys);
     226    /** Refresh binding information */
     227    void RefreshKeyBindings();
    220228
    221229    /**
    222      * @brief Refresh binding information
    223      */
    224     void refreshKeyBindings();
    225 
    226     /**
    227      * @brief Jump to a particular key binding
     230     * Jump to a particular key binding
     231     *
    228232     * @param e key event to use as jump
    229233     */
    230234    bool JumpTo(QKeyEvent *e);
    231235
    232236private:
    233237
    234     UIType *focused;
    235     UIListBtnType *LeftList;
    236     UIListBtnType *RightList;
    237     UITextType *description, *LeftDesc, *RightDesc;
    238     UITextButtonType * ActionButtons[Action::MAX_KEYS];
    239     KeyBindings *key_bindings;
    240     LayerSet *container;
     238    /** Currently focused UI type */
     239    UIType *m_Focused;
    241240
    242     QStringList contexts; ///< sorted list of contexts
    243     QStringList keys; ///< sorted list of keys
     241    /** The left list */
     242    UIListBtnType *m_LeftList;
    244243
    245     QDict<QStringList> m_contexts; ///< actions for a given context
    246     QDict<BindingList> contextKeys; ///< key bindings for a given context
    247     QDict<BindingList> keyActions; ///< actions in each context for a given key
     244    /** The right list */
     245    UIListBtnType *m_RightList;
    248246
    249     typedef enum { kContextList, kKeyList, kActionList } ListType;
    250     ListType leftType, rightType;
     247    /** Text areas */
     248    UITextType *m_Description, *m_LeftDesc, *m_RightDesc;
    251249
    252     QString getTypeDesc(ListType type);
     250    /** Buttons */
     251    UITextButtonType * m_ActionButtons[Action::MAX_KEYS];
    253252
     253    /** The current keybindings */
     254    KeyBindings *m_KeyBindings;
     255
     256    /** A layer contianer */
     257    LayerSet *m_Container;
     258
     259    /** The view mode */
     260    ViewMode m_View;
    254261};
    255262
    256263
  • mythcontrols/keybindings.h

     
    3030#include "actionid.h"
    3131#include "actionset.h"
    3232
     33
    3334/**
    3435 * @class KeyBindings.
    3536 * @brief Information about the current keybindings.
    3637 *
    3738 * This class can retrieve, set, and modify the keybindings used by
    3839 * mythtv.  It is a layer between the user interface, and the
    39  * keybindings themeslfs.
     40 * keybindings themeslfs.  All of the logic behind conflicts, etc is
     41 * kept here, as well as the database routines.
    4042 */
    4143class KeyBindings {
    4244
    4345public:
    4446
    45     /**
    46      * @brief Levels of conflict
    47      * @li None: Does not conflict
    48      * @li Potential: May conflict.
    49      * @li Fatal: Frontend will become inoperable.
    50      */
     47    /** Levels of conflict */
    5148    enum ConflictLevels { Warning, Error};
    5249
    5350    /**
    54      * @brief Create a new KeyBindings instance.
     51     * Create a new KeyBindings instance.
     52     *
    5553     * @param hostname The host for which to create the key bindings.
    5654     */
    5755    KeyBindings(const QString & hostname);
    5856
    5957    /**
    60      * @brief Get the hostname these keybindings are from.
    61      * @return The hostname these keybindings are from.
     58     * Determine the context belonging to the key and action
     59     *
     60     * @param action The action.
     61     * @param anum The action number (in the list of all of a keys actions).
     62     *
     63     * @warning This method falls apart if the actionset class doesn't
     64     * sort it the actions lists in the _kemap variable.
    6265     */
    63     inline const QString & getHostname() const { return this->_hostname; }
     66    QString GetContext(const QString & key, const QString & action,
     67                       size_t anum) const;
    6468
    6569    /**
    66      * @brief Get a list of the context names.
     70     * Get a list of the context names.
     71     *
    6772     * @return A list of the context names.
    68      * @note The returned list is a copy and can be modified without
    69      * side-effects.
    7073     */
    71     inline QStringList * getContexts() const
     74    inline QStringList * GetContexts() const
    7275    {
    73         return actionset.contextStrings();
     76        return m_ActionSet.ContextStrings();
    7477    }
    7578
    7679    /**
    77      * @brief Get a list of the actions in a context.
     80     * Get the contexts in which a key is bound.
     81     *
     82     * @param key The key.
     83     * @return A string list containing the context names.
     84     */
     85    inline QStringList * GetContexts(const QString & key) const
     86    {
     87        return m_ActionSet.GetKeyContexts(key);
     88    }
     89
     90    /**
     91     * Get a list of the actions in a context.
     92     *
    7893     * @param context The name of the context.
    7994     * @return A list of action (names) for the target context.
    80      * @note Store this instead of calling repeatedly.  Every time you
    81      * do, ActionSet has to iterate over all contexts and actions.
    8295     */
    83     inline QStringList * getActions(const QString & context) const
     96    inline QStringList * GetActions(const QString & context) const
    8497    {
    85         return actionset.actionStrings(context);
     98        return m_ActionSet.ActionStrings(context);
    8699    }
    87100
    88101    /**
    89      * @brief Get a list of the actions in a context.
     102     * Get the action bound to a key in a particular context.
     103     *
     104     * @param key The key.
     105     * @param context The context.
     106     * @return The action.
     107     */
     108    QString GetAction(const QString & key, const QString & context) const;
     109
     110    /**
     111     * Get all bound keys.
     112     *
     113     * @return A string list of the bound keys.
     114     */
     115    inline QStringList * GetAllKeys() const
     116    {
     117        return m_ActionSet.GetAllKeys();
     118    }
     119
     120    /**
     121     * Get a list of the actions in a context.
     122     *
    90123     * @param context The name of the context.
    91124     * @return A list of action (names) for the target context.
    92125     * @note Store this instead of calling repeatedly.  Every time you
    93126     * do, ActionSet has to iterate over all contexts and actions.
    94127     */
    95     inline void getKeyActions(const QString &key, ActionList &list) const
    96     {
    97         list = actionset.getActions(key);
    98     }
     128    QStringList * GetKeyActions(const QString &key) const;
    99129
    100130    /**
    101      * @brief Get an action's keys.
     131     * Get an action's keys.
     132     *
    102133     * @param context_name The name of the context.
    103134     * @param action_name The name of the action.
    104135     * @return The keys bound to the specified context's action
    105136     */
    106     inline QStringList getActionKeys(const QString & context_name,
     137    inline QStringList GetActionKeys(const QString & context_name,
    107138                                     const QString & action_name) const
    108139    {
    109         return actionset.getKeys(ActionID(context_name, action_name));
     140        return m_ActionSet.GetKeys(ActionID(context_name, action_name));
    110141    }
    111142
    112143    /**
    113      * @brief Get an action's description.
     144     * Get an action's description.
     145     *
    114146     * @param context_name The name of the context.
    115147     * @param action_name The name of the action.
    116148     * @return The description of the specified context's action
    117149     */
    118     inline QString getActionDescription(const QString & context_name,
     150    inline QString GetActionDescription(const QString & context_name,
    119151                                        const QString & action_name) const
    120152    {
    121         return actionset.getDescription(ActionID(context_name, action_name));
     153        return m_ActionSet.GetDescription(ActionID(context_name, action_name));
    122154    }
    123155
    124156    /**
    125      * @brief Add a key to an action.
     157     * Add a key to an action.
     158     *
    126159     * @param context_name The name of the context.
    127160     * @param action_name The name of the action.
    128161     * @param key The key to add.
     
    131164     * This does not take effect until the commitChanges function is
    132165     * called.
    133166     */
    134     inline void addActionKey(const QString & context_name,
     167    inline void AddActionKey(const QString & context_name,
    135168                             const QString & action_name,
    136169                             const QString & key)
    137170    {
    138         this->actionset.add(ActionID(context_name, action_name), key);
     171        this->m_ActionSet.Add(ActionID(context_name, action_name), key);
    139172    }
    140173
    141174    /**
    142      * @brief Determine if adding a key would cause a conflict.
     175     * Determine if adding a key would cause a conflict.
     176     *
    143177     * @param context_name The name of the context.
    144178     * @param key The key to add.
    145179     * @param level The level of conflict.  Check this if the return
     
    157191     * errors should be prevented no matter what.  If they dont like it,
    158192     * they can learn SQL.
    159193     */
    160     ActionID * conflicts(const QString & context_name,
     194    ActionID * Conflicts(const QString & context_name,
    161195                         const QString & key, int &level) const;
    162196
    163197    /**
    164      * @brief Replace a key in an action.
     198     * Replace a key in an action.
     199     *
    165200     * @param context_name The name of the context.
    166201     * @param action_name The name of the action.
    167202     * @param newkey The key to add.
     
    171206     * This does not take effect until the commitChanges function is
    172207     * called.
    173208     */
    174     inline void replaceActionKey(const QString & context_name,
     209    inline void ReplaceActionKey(const QString & context_name,
    175210                                 const QString & action_name,
    176211                                 const QString & newkey,
    177212                                 const QString & oldkey)
    178213    {
    179         this->actionset.replace(ActionID(context_name, action_name),
     214        this->m_ActionSet.Replace(ActionID(context_name, action_name),
    180215                                newkey, oldkey);
    181216    }
    182217
    183218    /**
    184      * @brief Unbind a key from an action.
     219     * Unbind a key from an action.
     220     *
    185221     * @param context_name The name of the context.
    186222     * @param action_name The name of the action.
    187223     * @param key The key to remove.
    188224     * @return true if the key was removed, or false if it was not.
    189225     *
    190      * Unless the action is manditory there is only one key in the
     226     * Unless the action is mandatory and there is only one key in the
    191227     * action, this method should return true.
    192228     */
    193     bool removeActionKey(const QString & context_name,
     229    bool RemoveActionKey(const QString & context_name,
    194230                         const QString & action_name,
    195231                         const QString & key);
    196232
    197     /**
    198      * @brief Set the manditory bindings to their defaults.
    199      */
    200     void defaultManditoryBindings(void);
     233    /** Set the mandatory bindings to their defaults. */
     234    void DefaultMandatoryBindings(void);
    201235
    202236    /**
    203      * @brief Determine if there are changes to the keybindings.
     237     * Determine if there are changes to the keybindings.
     238     *
    204239     * @return True if keys have been changed, otherwise, false.
    205240     */
    206     inline bool hasChanges(void) const { return actionset.hasModified(); }
     241    inline bool HasChanges(void) const
     242    {
     243        return m_ActionSet.HasModified();
     244    }
    207245
    208246    /**
    209      * @brief Commit all changes made to the keybindings.
    210      *
    211      * This method will write the changes to the database, unbind myth's
    212      * current bindings for those actions that changed, and setup the
    213      * new bindings.
     247     * Commit the changes made to the keybindings into the database.
    214248     */
    215     void commitChanges(void);
     249    void CommitChanges(void);
    216250
    217251    /**
    218      * @brief Get a list of the manditory key bindings.
    219      * @return A list of the manditory bindings.
     252     * Get a list of the mandatory key bindings.
     253     *
     254     * @return A list of the mandatory bindings.
    220255     */
    221     inline const ActionList& getManditoryBindings(void) const
     256    inline const ActionList& getMandatoryBindings(void) const
    222257    {
    223         return this->_manditory_bindings;
     258        return this->m_MandatoryBindings;
    224259    }
    225260
    226261    /**
    227      * @brief Determine if all manditory bindings are satisfied.
    228      * @return true if all manditory bindings are satisfied, otherwise, false.
     262     * Determine if all mandatory bindings are satisfied.
     263     *
     264     * @return true if all mandatory bindings are satisfied,
     265     * otherwise, false.
    229266     */
    230     bool hasManditoryBindings(void) const;
     267    bool HasMandatoryBindings(void) const;
    231268
    232269protected:
    233270
    234     /**
    235      * @brief Get a reference to the hostname.
    236      * @return A reference to the hostname.
    237      */
    238     inline QString & hostname() { return this->_hostname; }
     271    /** Commit a jumppoint to the database. */
     272    void CommitJumppoint(const ActionID &id);
    239273
    240     /**
    241      * @brief Commit a jumppoint to the database.
    242      *
    243      * This (currently) does not reload the jumppoint.
    244      */
    245     void commitJumppoint(const ActionID &id);
     274    /** Commit an action to the database, and reload its keybindings. */
     275    void CommitAction(const ActionID & id);
    246276
    247     /**
    248      * @brief Commit an action to the database, and reload its keybindings.
    249      */
    250     void commitAction(const ActionID & id);
     277    /** Load the jumppoints from the database. */
     278    void RetrieveJumppoints(void);
    251279
    252     /**
    253      * @brief Load the jumppoints from the database.
    254      *
    255      * This method will load the keybindings for jump points.
    256      */
    257     void retrieveJumppoints(void);
     280    /** Load the keybindings from the database. */
     281    void RetrieveContexts(void);
    258282
    259     /**
    260      * @brief Load the keybindings from the database.
    261      *
    262      * This will load the keybindings which apply to the hostname
    263      * specified to the constructor.
    264      */
    265     void retrieveContexts(void);
     283    /** Load the mandatory bindings. */
     284    void LoadMandatoryBindings(void);
    266285
    267     /**
    268      * @brief Load the manditory bindings.
    269      */
    270     void loadManditoryBindings(void);
     286private:
    271287
    272     /**
    273      * @brief Get a reference to the list of the manditory key bindings.
    274      * @return A reference to the list of the manditory bindings.
    275      */
    276     inline ActionList & manditoryBindings(void) { return _manditory_bindings; }
     288    /** The hostname */
     289    QString m_HostName;
    277290
    278     /**
    279      * @brief Get the default keys.
    280      * @return A list of the default keys.
    281      */
    282     inline QStringList & defaultKeys() { return _default_keys; }
     291    /** List of mandatory bindings */
     292    ActionList m_MandatoryBindings;
    283293
    284 private:
     294    /** List of the default key bindings */
     295    QStringList m_DefaultKeys;
    285296
    286     QString _hostname;
    287     ActionList _manditory_bindings;
    288     QStringList _default_keys;
    289     ActionSet actionset;
     297    /** The action set */
     298    ActionSet m_ActionSet;
    290299};
    291300
    292301#endif /* KEYBINDINGS_H */
  • mythcontrols/action.cpp

     
    3434
    3535Action::Action(const QString & description, const QString & keys)
    3636{
    37     this->description() = description;
    38     this->keys() = QStringList::split(", ", QString(QKeySequence(keys)));
     37    m_Description = description;
     38    m_Keys = QStringList::split(", ", QString(QKeySequence(keys)));
    3939}
    4040
    4141
    4242
    43 bool Action::hasKey(const QString & key) const
     43bool Action::HasKey(const QString & key) const
    4444{
    4545    /* check the keys */
    46     for (size_t i = 0; i < getKeys().count(); i++)
     46    for (size_t i = 0; i < GetKeys().count(); i++)
    4747    {
    48         if (getKeys()[i] == key) return true;
     48        if (GetKeys()[i] == key)
     49            return true;
    4950    }
    5051
    5152    /* the key was not found, so return false */
     
    5455
    5556
    5657
    57 bool Action::addKey(const QString & key)
     58bool Action::AddKey(const QString & key)
    5859{
    5960
    6061    /* dont add empty keys and dont add too many, or duplicates  */
    6162    if ((key.length() == 0) ||
    62         (getKeys().size() >= MAX_KEYS) ||
    63         (getKeys().contains(key)))
     63        (GetKeys().size() >= MAX_KEYS) ||
     64        (GetKeys().contains(key)))
    6465        return false;
    6566
    6667    /* add the key */
    67     this->keys().push_back(key);
     68    m_Keys.push_back(key);
    6869    return true;
    6970}
    7071
    7172
    7273
    7374/* comments in header */
    74 bool Action::replaceKey(const QString & newkey, const QString &oldkey)
     75bool Action::ReplaceKey(const QString & newkey, const QString &oldkey)
    7576{
    7677    /* make sure that the key list doesn't already have the new key */
    77     if (getKeys().contains(newkey) == 0)
     78    if (GetKeys().contains(newkey) == 0)
    7879    {
    79         for (size_t i = 0; i < getKeys().size(); i++)
     80        for (size_t i = 0; i < GetKeys().size(); i++)
    8081        {
    81             if (getKeys()[i] == oldkey)
     82            if (GetKeys()[i] == oldkey)
    8283            {
    83                 keys()[i] = newkey;
     84                m_Keys[i] = newkey;
    8485                return true;
    8586            }
    8687        }