/** \fn KeyBindings::CommitAction(const ActionID&) * \brief Commit an action to the database, and reload its keybindings. */ void KeyBindings::CommitAction(const ActionID &id) { MSqlQuery query(MSqlQuery::InitCon()); query.prepare( "UPDATE keybindings " "SET keylist = :KEYLIST " "WHERE hostname = :HOSTNAME AND " " action = :ACTION AND " " context = :CONTEXT"); QString keys = m_actionSet.GetKeyString(id); query.bindValue(":KEYLIST", keys); query.bindValue(":HOSTNAME", m_hostname); query.bindValue(":CONTEXT", id.GetContext()); query.bindValue(":ACTION", id.GetAction()); if (!query.exec() || !query.isActive()) { MythDB::DBError("KeyBindings::CommitAction", query); return; } GetMythMainWindow()->ClearKey(id.GetContext(), id.GetAction()); GetMythMainWindow()->BindKey(id.GetContext(), id.GetAction(), keys); }
/** \fn ActionSet::AddAction(const ActionID&, const QString&, const QString&) * \brief Add an action. * * If the action has already been added, it will not be added * again. There are no duplicate actions in the action set. * * \param id The action identifier. * \param description The action description. * \param keys The keys for this action. * \return true if the action on success, false otherwise. */ bool ActionSet::AddAction(const ActionID &id, const QString &description, const QString &keys) { ContextMap::iterator cit = m_contexts.find(id.GetContext()); if (cit == m_contexts.end()) cit = m_contexts.insert(id.GetContext(), Context()); else if ((*cit).find(id.GetAction()) != (*cit).end()) return false; Action *a = new Action(description, keys); (*cit).insert(id.GetAction(), a); const QStringList keylist = a->GetKeys(); QStringList::const_iterator it = keylist.begin(); for (; it != keylist.end(); ++it) m_keyToActionMap[*it].push_back(id); return true; }
/** \fn ActionSet::GetDescription(const ActionID&) const * \brief Returns the description of an action by its identifier. */ QString ActionSet::GetDescription(const ActionID &id) const { ContextMap::const_iterator cit = m_contexts.find(id.GetContext()); if (cit == m_contexts.end()) return QString(); Context::const_iterator it = (*cit).find(id.GetAction()); if (it != (*cit).end()) return (*it)->GetDescription(); return QString(); }
/** \fn ActionSet::GetKeys(const ActionID&) const * \brief Get the keys bound to an action by its identifier. */ QStringList ActionSet::GetKeys(const ActionID &id) const { QStringList keys; ContextMap::const_iterator cit = m_contexts.find(id.GetContext()); if (cit == m_contexts.end()) return keys; Context::const_iterator it = (*cit).find(id.GetAction()); if (it != (*cit).end()) keys = (*it)->GetKeys(); keys.detach(); return keys; }
/** \fn KeyBindings::CommitChanges(void) * \brief Commit all changes made to the keybindings. * * This method will write the changes to the database, unbind %MythTV's * current bindings for those actions that changed, and setup the * new bindings. */ void KeyBindings::CommitChanges(void) { ActionList modified = m_actionSet.GetModified(); while (modified.size() > 0) { ActionID id = modified.front(); // commit either a jumppoint or an action if (id.GetContext() == ActionSet::kJumpContext) CommitJumppoint(id); else CommitAction(id); // tell the action set that the action is no longer modified m_actionSet.SetModifiedFlag(id, false); modified.pop_front(); } }