Ticket #98: sorting_and_warnings2.diff

File sorting_and_warnings2.diff, 9.8 KB (added by mfgalizi@…, 19 years ago)

OOPS (use this one instead)

  • mythcontrols/mythcontrols/mythcontrols.cpp

     
    5050
    5151/**
    5252 * @class ConflictResolver
    53  * @brief A MythDialog that notifies the user of conflicts. 
     53 * @brief A MythDialog that notifies the user of conflicts.
    5454 */
    5555class ConflictResolver : public MythPopupBox
    5656{
     
    392392    context_tree = new GenericTree(hostname, 0, false);
    393393    QStringList context_names = key_bindings->getContexts();
    394394
     395    /* Alphabetic order, except... */
     396    context_names.sort();
     397
     398    /* jump points go first*/
     399    if (context_names.contains(JUMP_CONTEXT))
     400    {
     401        context_names.remove(JUMP_CONTEXT);
     402        context_names.insert(context_names.begin(), 1, JUMP_CONTEXT);
     403    }
     404
     405    /* followed by global */
     406    if (context_names.contains(GLOBAL_CONTEXT))
     407    {
     408        context_names.remove(GLOBAL_CONTEXT);
     409        context_names.insert(++(context_names.begin()), 1, GLOBAL_CONTEXT);
     410    }
     411
    395412    for (size_t i = 0; i < context_names.size(); i++) {
    396413
    397414        GenericTree *context_node = new GenericTree(context_names[i], i, true);
     
    400417        context_tree->addNode(context_node);
    401418
    402419        QStringList action_names = key_bindings->getActions(context_names[i]);
     420        action_names.sort();
    403421
    404422        /* add all actions to the context */
    405423        for (size_t j = 0; j < action_names.size(); j++)
     
    412430
    413431
    414432
     433/* comments in header */
    415434void MythControls::killPopup()
    416435{
    417436    if (this->popup == NULL) return;
     
    461480    QStringList keys = key_bindings->getActionKeys(context, action);
    462481    if (b < keys.count())
    463482    {
     483        cerr << "DELETING" << endl;
    464484        if (!key_bindings->removeActionKey(context, action, keys[b]))
    465485        {
    466             this->popup = new ConflictResolver(gContext->GetMainWindow());
    467             this->popup->ExecPopup(this, SLOT(killPopup()));
     486          /* create the popup */
     487          popup = new MythPopupBox(gContext->GetMainWindow(),
     488                                   "conflictresolver");
     489
     490          QString warning = "This action is manditory and needs at least one "
     491            "key bound to it.  Instead, try rebinding with another key.";
     492           
     493          popup->addLabel("Manditory Action", MythPopupBox::Large, false);
     494          popup->addLabel(warning, MythPopupBox::Small, true);
     495
     496          /*this->popup = new ConflictResolver(gContext->GetMainWindow());*/
     497          this->popup->ExecPopup(this, SLOT(killPopup()));
    468498        }
    469499        else refreshKeyInformation();
    470500    }
     
    472502
    473503
    474504
     505/* method description in header */
     506bool MythControls::resolveConflict(ActionID *conflict, int level)
     507{
     508    MythMainWindow *window = gContext->GetMainWindow();
     509
     510    /* prevent a fatal binding */
     511    if (level == KeyBindings::Error)
     512    {
     513        this->popup = new MythPopupBox(window, "conflictresolver");
     514        QString warning;
     515        warning = "This action is manditory and needs at least one key "
     516            "bound to it.  Instead, try rebinding with another key.";
     517           
     518        popup->addLabel("Manditory Action", MythPopupBox::Large, false);
     519        popup->addLabel(warning, MythPopupBox::Small, true);
     520
     521        this->popup->ExecPopup();
     522        return false;
     523    }
     524    else
     525    {
     526        /* warn the user that this could conflict */
     527        QString message = "This kebinding may conflict with ";
     528        message += conflict->action() + " in the " + conflict->context();
     529        message += " context.  Do you want to bind it anyways?";
     530
     531        if (MythPopupBox::show2ButtonPopup(window, "Conflict Warning",
     532                                           message,"Bind Key","Cancel",0))
     533            return false;
     534    }
     535
     536    return true;
     537}
     538
     539
     540
     541/* method description in header */
    475542void MythControls::addKeyToAction(void)
    476543{
    477544    size_t b = focusedButton();
     
    483550    /* having got the key, kill the key grabber */
    484551    killPopup();
    485552
     553    /* dont bother if its the same key */
     554    if (keys[b] == newkey) return;
     555
     556    bool bind = true;
     557    int level;
     558
     559    /* get the potential conflict */
     560    if ((conflict = key_bindings->conflicts(context, newkey, level)))
     561        bind = resolveConflict(conflict, level);
     562
     563    delete conflict;
     564
     565    /* dont bind */
     566    if (!bind) return;
     567
     568    /* */
    486569    if (b < keys.count())
    487     {
    488         /* dont replace with the same key */
    489         if (keys[b] != newkey) {
    490             if ((conflict = key_bindings->conflicts(context, newkey)))
    491             {
    492                 this->popup = new ConflictResolver(gContext->GetMainWindow(),
    493                                                    conflict);
    494                 this->popup->ExecPopup(this, SLOT(killPopup()));
    495             }
    496             else key_bindings->replaceActionKey(context,action,newkey,keys[b]);
    497         }
    498     }
    499     else {
    500         if ((conflict = key_bindings->conflicts(context, newkey)))
    501         {
    502             this->popup = new ConflictResolver(gContext->GetMainWindow(),
    503                                                conflict);
    504             this->popup->ExecPopup(this, SLOT(killPopup()));
    505         }
    506         else key_bindings->addActionKey(context, action, newkey);
    507     }
     570        key_bindings->replaceActionKey(context,action,newkey,keys[b]);
     571    else
     572        key_bindings->addActionKey(context, action, newkey);
    508573
    509     /* delete the conflict and hide the popup*/
    510     if (conflict) {
    511         delete conflict;
    512         killPopup();
    513     }
    514 
    515574    refreshKeyInformation();
    516575}
    517576
  • mythcontrols/mythcontrols/keybindings.cpp

     
    4949
    5050
    5151ActionID * KeyBindings::conflicts(const QString & context_name,
    52                                   const QString & key) const
     52                                  const QString & key, int &level) const
    5353{
    5454    const ActionList &ids = actionset.getActions(key);
    5555
     
    6060    /* check the contexts of the other bindings */
    6161    for (size_t i = 0; i < ids.count(); i++)
    6262    {
    63         if (ids[i].context() == JUMP_CONTEXT) return new ActionID(ids[i]);
    64         else if (ids[i].context() == context_name) return new ActionID(ids[i]);
     63        /* jump points, then global, then the same context */
     64        if (ids[i].context() == JUMP_CONTEXT) {
     65            level = KeyBindings::Error;
     66            return new ActionID(ids[i]);
     67        }
     68        else if (ids[i].context() == context_name) {
     69            level = KeyBindings::Error;
     70            return new ActionID(ids[i]);
     71        }
     72        else if (ids[i].context()==GLOBAL_CONTEXT) {
     73            level = KeyBindings::Warning;
     74            return new ActionID(ids[i]);
     75        }
    6576    }
    6677
    6778    /* no conflicts */
     
    7081
    7182
    7283
     84/* method description in header */
     85bool KeyBindings::removeActionKey(const QString & context_name,
     86                     const QString & action_name,
     87                     const QString & key) {
     88
     89    ActionID id(context_name, action_name);
     90
     91    /* dont remove the last manditory binding */
     92    if (getManditoryBindings().contains(id)&&(actionset.getKeys(id).count()<2))
     93        return false;
     94    else
     95        return this->actionset.remove(id,key);
     96}
     97
     98
     99
     100/* method description in header */
    73101void KeyBindings::commitAction(const ActionID & id)
    74102{
    75103
  • mythcontrols/mythcontrols/mythcontrols.h

     
    125125     */
    126126    size_t focusedButton(void) const;
    127127
     128    /**
     129     * @brief Resolve a potential conflict.
     130     * @return true if the conflict should be bound, otherwise, false
     131     * is returned.
     132     */
     133    bool resolveConflict(ActionID *conflict, int level);
     134
    128135 private slots:
    129136
    130137     /**
  • mythcontrols/mythcontrols/keybindings.h

     
    2929#include "actionid.h"
    3030#include "actionset.h"
    3131
    32 
    3332/**
    3433 * @class KeyBindings.
    3534 * @brief Information about the current keybindings.
     
    4342 public:
    4443
    4544  /**
     45   * @brief Levels of conflict
     46   * @li None: Does not conflict
     47   * @li Potential: May conflict.
     48   * @li Fatal: Frontend will become inoperable.
     49   */
     50  enum ConflictLevels { Warning, Error};
     51
     52  /**
    4653   * @brief Create a new KeyBindings instance.
    4754   * @param hostname The host for which to create the key bindings.
    4855   */
     
    111118   * @brief Determine if adding a key would cause a conflict.
    112119   * @param context_name The name of the context.
    113120   * @param key The key to add.
     121   * @param level The level of conflict.  Check this if the return
     122   * value is not NULL
    114123   * @return true if adding the key would cause a conflict.
    115124   *
    116125   * Conflicts occur if:
    117126   * @li the key is a jump point, but is bound elsewhere
    118127   * @li the key is already bound to a jumppoint.
     128   * @li the key is bound to something in the global context.
    119129   * @li the key is bound to something else in the specified context
     130   *
     131   * If the method does not return NULL, check the value given to
     132   * level.  Warnings can be ignored (at the users disgression), but
     133   * errors should be prevented no matter what.  If they dont like it,
     134   * they can learn SQL.
    120135   */
    121136  ActionID * conflicts(const QString & context_name,
    122                        const QString & key) const;
     137                       const QString & key, int &level) const;
    123138
    124139  /**
    125140   * @brief Replace a key in an action.
     
    152167   */
    153168  bool removeActionKey(const QString & context_name,
    154169                       const QString & action_name,
    155                        const QString & key) {
    156       return this->actionset.remove(ActionID(context_name, action_name),key);
    157   }
     170                       const QString & key);
    158171
    159172  /**
    160173   * @brief Set the manditory bindings to their defaults.
  • mythcontrols/mythcontrols/mythcontrols.pro

     
    11include ( ../../settings.pro )
    22
    33TEMPLATE = lib
    4 CONFIG += plugin thread warn_on debug
     4CONFIG += plugin thread
    55TARGET = mythcontrols
    66target.path = $${PREFIX}/lib/mythtv/plugins
    77INSTALLS += target