Ticket #98: sorting_and_warnings.diff
File sorting_and_warnings.diff, 9.8 KB (added by , 16 years ago) |
---|
-
mythcontrols/mythcontrols/mythcontrols.cpp
50 50 51 51 /** 52 52 * @class ConflictResolver 53 * @brief A MythDialog that notifies the user of conflicts. 53 * @brief A MythDialog that notifies the user of conflicts. 54 54 */ 55 55 class ConflictResolver : public MythPopupBox 56 56 { … … 392 392 context_tree = new GenericTree(hostname, 0, false); 393 393 QStringList context_names = key_bindings->getContexts(); 394 394 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 395 412 for (size_t i = 0; i < context_names.size(); i++) { 396 413 397 414 GenericTree *context_node = new GenericTree(context_names[i], i, true); … … 400 417 context_tree->addNode(context_node); 401 418 402 419 QStringList action_names = key_bindings->getActions(context_names[i]); 420 action_names.sort(); 403 421 404 422 /* add all actions to the context */ 405 423 for (size_t j = 0; j < action_names.size(); j++) … … 412 430 413 431 414 432 433 /* comments in header */ 415 434 void MythControls::killPopup() 416 435 { 417 436 if (this->popup == NULL) return; … … 461 480 QStringList keys = key_bindings->getActionKeys(context, action); 462 481 if (b < keys.count()) 463 482 { 483 cerr << "DELETING" << endl; 464 484 if (!key_bindings->removeActionKey(context, action, keys[b])) 465 485 { 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())); 468 498 } 469 499 else refreshKeyInformation(); 470 500 } … … 472 502 473 503 474 504 505 /* method description in header */ 506 bool 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 */ 475 542 void MythControls::addKeyToAction(void) 476 543 { 477 544 size_t b = focusedButton(); … … 483 550 /* having got the key, kill the key grabber */ 484 551 killPopup(); 485 552 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 /* */ 486 569 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); 508 573 509 /* delete the conflict and hide the popup*/510 if (conflict) {511 delete conflict;512 killPopup();513 }514 515 574 refreshKeyInformation(); 516 575 } 517 576 -
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