bool CustomEdit::keyPressEvent(QKeyEvent *event) { if (GetFocusWidget()->keyPressEvent(event)) return true; QStringList actions; bool handled = GetMythMainWindow()->TranslateKeyPress("TV Frontend", event, actions); for (int i = 0; i < actions.size() && !handled; i++) { QString action = actions[i]; handled = true; if (action == "DELETE") { if (GetFocusWidget() == m_clauseList) deleteRule(); // else if (GetFocusWidget() == m_ruleList) // deleteRecordingRule(); } else if (action == "EDIT") { // toggle evaluated/unevaluated sample view m_evaluate = !m_evaluate; MythUIButtonListItem* item = m_clauseList->GetItemCurrent(); clauseChanged(item); } else handled = false; } if (!handled && MythScreenType::keyPressEvent(event)) handled = true; return handled; }
void CustomEdit::storeRule(bool is_search, bool is_new) { CustomRuleInfo rule; rule.recordid = '0'; rule.title = m_titleEdit->GetText(); rule.subtitle = m_subtitleEdit->GetText(); rule.description = m_descriptionEdit->GetText(); MSqlQuery query(MSqlQuery::InitCon()); query.prepare("REPLACE INTO customexample " "(rulename,fromclause,whereclause,search) " "VALUES(:RULE,:FROMC,:WHEREC,:SEARCH);"); query.bindValue(":RULE", rule.title); query.bindValue(":FROMC", rule.subtitle); query.bindValue(":WHEREC", rule.description); query.bindValue(":SEARCH", is_search); if (is_search) rule.title += m_seSuffix; else rule.title += m_exSuffix; if (!query.exec()) MythDB::DBError("Store custom example", query); else if (is_new) { new MythUIButtonListItem(m_clauseList, rule.title, qVariantFromValue(rule)); } else { /* Modify the existing entry. We know one exists from the database search but do not know its position in the clause list. It may or may not be the current item. */ for (int i = m_maxex; i < m_clauseList->GetCount(); i++) { MythUIButtonListItem* item = m_clauseList->GetItemAt(i); QString removedStr = item->GetText().remove(m_seSuffix) .remove(m_exSuffix); if (m_titleEdit->GetText() == removedStr) { item->SetData(qVariantFromValue(rule)); clauseChanged(item); break; } } } }