Ticket #98: sorting_and_warnings3.diff
File sorting_and_warnings3.diff, 10.7 KB (added by , 20 years ago) |
---|
-
mythcontrols/mythcontrols/mythcontrols.cpp
48 48 #include "mythcontrols.h" 49 49 #include "keygrabber.h" 50 50 51 /**52 * @class ConflictResolver53 * @brief A MythDialog that notifies the user of conflicts.54 */55 class ConflictResolver : public MythPopupBox56 {57 51 58 public:59 ConflictResolver(MythMainWindow *window, ActionID *conflict)60 : MythPopupBox(window, "conflictresolver")61 {62 QString warning = "The key you have chosen is already bound to "63 + conflict->action() + " in the " + conflict->context()64 + " context; please rebind it before binding this key.";65 66 addLabel("Action Conflict", Large, false);67 addLabel(warning, Small, true);68 }69 52 70 71 ConflictResolver(MythMainWindow *window)72 : MythPopupBox(window,"conflictresolver")73 {74 75 QString warning;76 warning = "This action is manditory and needs at least one key bound ";77 warning += "to it. Instead, try rebinding with another key.";78 79 addLabel("Manditory Action", Large, false);80 addLabel(warning, Small, true);81 }82 };83 84 85 53 /* comments in header */ 86 54 MythControls::MythControls (MythMainWindow *parent, const char *name) 87 55 :MythThemedDialog(parent, "controls", "controls-", name) … … 392 360 context_tree = new GenericTree(hostname, 0, false); 393 361 QStringList context_names = key_bindings->getContexts(); 394 362 363 /* Alphabetic order, except... */ 364 context_names.sort(); 365 366 /* jump points go first*/ 367 if (context_names.contains(JUMP_CONTEXT)) 368 { 369 context_names.remove(JUMP_CONTEXT); 370 context_names.insert(context_names.begin(), 1, JUMP_CONTEXT); 371 } 372 373 /* followed by global */ 374 if (context_names.contains(GLOBAL_CONTEXT)) 375 { 376 context_names.remove(GLOBAL_CONTEXT); 377 context_names.insert(++(context_names.begin()), 1, GLOBAL_CONTEXT); 378 } 379 395 380 for (size_t i = 0; i < context_names.size(); i++) { 396 381 397 382 GenericTree *context_node = new GenericTree(context_names[i], i, true); … … 400 385 context_tree->addNode(context_node); 401 386 402 387 QStringList action_names = key_bindings->getActions(context_names[i]); 388 action_names.sort(); 403 389 404 390 /* add all actions to the context */ 405 391 for (size_t j = 0; j < action_names.size(); j++) … … 412 398 413 399 414 400 401 /* comments in header */ 415 402 void MythControls::killPopup() 416 403 { 417 404 if (this->popup == NULL) return; … … 461 448 QStringList keys = key_bindings->getActionKeys(context, action); 462 449 if (b < keys.count()) 463 450 { 451 cerr << "DELETING" << endl; 464 452 if (!key_bindings->removeActionKey(context, action, keys[b])) 465 453 { 466 this->popup = new ConflictResolver(gContext->GetMainWindow()); 467 this->popup->ExecPopup(this, SLOT(killPopup())); 454 /* create the popup */ 455 popup = new MythPopupBox(gContext->GetMainWindow(), 456 "conflictresolver"); 457 458 QString warning = "This action is manditory and needs at least one " 459 "key bound to it. Instead, try rebinding with another key."; 460 461 popup->addLabel("Manditory Action", MythPopupBox::Large, false); 462 popup->addLabel(warning, MythPopupBox::Small, true); 463 464 /*this->popup = new ConflictResolver(gContext->GetMainWindow());*/ 465 this->popup->ExecPopup(this, SLOT(killPopup())); 468 466 } 469 467 else refreshKeyInformation(); 470 468 } … … 472 470 473 471 474 472 473 /* method description in header */ 474 bool MythControls::resolveConflict(ActionID *conflict, int level) 475 { 476 MythMainWindow *window = gContext->GetMainWindow(); 477 478 /* prevent a fatal binding */ 479 if (level == KeyBindings::Error) 480 { 481 this->popup = new MythPopupBox(window, "conflictresolver"); 482 QString warning; 483 warning = "This action is manditory and needs at least one key " 484 "bound to it. Instead, try rebinding with another key."; 485 486 popup->addLabel("Manditory Action", MythPopupBox::Large, false); 487 popup->addLabel(warning, MythPopupBox::Small, true); 488 489 this->popup->ExecPopup(); 490 return false; 491 } 492 else 493 { 494 /* warn the user that this could conflict */ 495 QString message = "This kebinding may conflict with "; 496 message += conflict->action() + " in the " + conflict->context(); 497 message += " context. Do you want to bind it anyways?"; 498 499 if (MythPopupBox::show2ButtonPopup(window, "Conflict Warning", 500 message,"Bind Key","Cancel",0)) 501 return false; 502 } 503 504 return true; 505 } 506 507 508 509 /* method description in header */ 475 510 void MythControls::addKeyToAction(void) 476 511 { 477 512 size_t b = focusedButton(); … … 483 518 /* having got the key, kill the key grabber */ 484 519 killPopup(); 485 520 521 /* dont bother if its the same key */ 522 if (keys[b] == newkey) return; 523 524 bool bind = true; 525 int level; 526 527 /* get the potential conflict */ 528 if ((conflict = key_bindings->conflicts(context, newkey, level))) 529 bind = resolveConflict(conflict, level); 530 531 delete conflict; 532 533 /* dont bind */ 534 if (!bind) return; 535 536 /* */ 486 537 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 } 538 key_bindings->replaceActionKey(context,action,newkey,keys[b]); 539 else 540 key_bindings->addActionKey(context, action, newkey); 508 541 509 /* delete the conflict and hide the popup*/510 if (conflict) {511 delete conflict;512 killPopup();513 }514 515 542 refreshKeyInformation(); 516 543 } 517 544 -
mythcontrols/mythcontrols/keybindings.cpp
49 49 50 50 51 51 ActionID * KeyBindings::conflicts(const QString & context_name, 52 const QString & key ) const52 const QString & key, int &level) const 53 53 { 54 54 const ActionList &ids = actionset.getActions(key); 55 55 … … 60 60 /* check the contexts of the other bindings */ 61 61 for (size_t i = 0; i < ids.count(); i++) 62 62 { 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 } 65 76 } 66 77 67 78 /* no conflicts */ … … 70 81 71 82 72 83 84 /* method description in header */ 85 bool 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 */ 73 101 void KeyBindings::commitAction(const ActionID & id) 74 102 { 75 103 -
mythcontrols/mythcontrols/mythcontrols.h
125 125 */ 126 126 size_t focusedButton(void) const; 127 127 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 128 135 private slots: 129 136 130 137 /** -
mythcontrols/mythcontrols/keybindings.h
29 29 #include "actionid.h" 30 30 #include "actionset.h" 31 31 32 33 32 /** 34 33 * @class KeyBindings. 35 34 * @brief Information about the current keybindings. … … 43 42 public: 44 43 45 44 /** 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 /** 46 53 * @brief Create a new KeyBindings instance. 47 54 * @param hostname The host for which to create the key bindings. 48 55 */ … … 111 118 * @brief Determine if adding a key would cause a conflict. 112 119 * @param context_name The name of the context. 113 120 * @param key The key to add. 121 * @param level The level of conflict. Check this if the return 122 * value is not NULL 114 123 * @return true if adding the key would cause a conflict. 115 124 * 116 125 * Conflicts occur if: 117 126 * @li the key is a jump point, but is bound elsewhere 118 127 * @li the key is already bound to a jumppoint. 128 * @li the key is bound to something in the global context. 119 129 * @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. 120 135 */ 121 136 ActionID * conflicts(const QString & context_name, 122 const QString & key ) const;137 const QString & key, int &level) const; 123 138 124 139 /** 125 140 * @brief Replace a key in an action. … … 152 167 */ 153 168 bool removeActionKey(const QString & context_name, 154 169 const QString & action_name, 155 const QString & key) { 156 return this->actionset.remove(ActionID(context_name, action_name),key); 157 } 170 const QString & key); 158 171 159 172 /** 160 173 * @brief Set the manditory bindings to their defaults. -
mythcontrols/mythcontrols/mythcontrols.pro
1 1 include ( ../../settings.pro ) 2 2 3 3 TEMPLATE = lib 4 CONFIG += plugin thread warn_on debug4 CONFIG += plugin thread 5 5 TARGET = mythcontrols 6 6 target.path = $${PREFIX}/lib/mythtv/plugins 7 7 INSTALLS += target