diff --git a/mythtv/libs/libmythui/mythmainwindow.cpp b/mythtv/libs/libmythui/mythmainwindow.cpp
index c4794a0..d1b8a0c 100644
a
|
b
|
using namespace std; |
88 | 88 | |
89 | 89 | #define LOC QString("MythMainWindow: ") |
90 | 90 | |
| 91 | struct KeyInfo |
| 92 | { |
| 93 | KeyInfo() {} |
| 94 | KeyInfo(const QString &kl, const QString &d) : keyList(kl), description(d) {} |
| 95 | QString keyList; |
| 96 | QString description; |
| 97 | }; |
| 98 | |
91 | 99 | class KeyContext |
92 | 100 | { |
93 | 101 | public: |
… |
… |
class MythMainWindowPrivate |
231 | 239 | bool m_useDB; ///< To allow or prevent database access |
232 | 240 | |
233 | 241 | QHash<QString, KeyContext *> keyContexts; |
| 242 | QMap<QString, QMap<QString, KeyInfo> > backendKeyCache; |
| 243 | |
234 | 244 | QMap<int, JumpData*> jumpMap; |
235 | 245 | QMap<QString, JumpData> destinationMap; |
236 | 246 | QMap<QString, MPData> mediaPluginMap; |
… |
… |
MythMainWindow::MythMainWindow(const bool useDB) |
505 | 515 | |
506 | 516 | d->m_udpListener = new MythUDPListener(); |
507 | 517 | |
| 518 | CacheBackendKeys(); |
508 | 519 | InitKeys(); |
509 | 520 | |
510 | 521 | d->gestureTimer = new QTimer(this); |
… |
… |
void MythMainWindow::RegisterKey(const QString &context, const QString &action, |
1705 | 1716 | { |
1706 | 1717 | QString keybind = key; |
1707 | 1718 | |
1708 | | MSqlQuery query(MSqlQuery::InitCon()); |
1709 | | |
1710 | | if (d->m_useDB && query.isConnected()) |
| 1719 | QMap<QString, QMap<QString, KeyInfo> >::iterator contextResult = d->backendKeyCache.find(context); |
| 1720 | if( contextResult != d->backendKeyCache.end() ) |
1711 | 1721 | { |
1712 | | query.prepare("SELECT keylist, description FROM keybindings WHERE " |
1713 | | "context = :CONTEXT AND action = :ACTION AND " |
1714 | | "hostname = :HOSTNAME ;"); |
1715 | | query.bindValue(":CONTEXT", context); |
1716 | | query.bindValue(":ACTION", action); |
1717 | | query.bindValue(":HOSTNAME", GetMythDB()->GetHostName()); |
1718 | | |
1719 | | if (query.exec() && query.next()) |
| 1722 | QMap<QString, KeyInfo>::iterator actionResult = contextResult.value().find(action); |
| 1723 | if( actionResult != contextResult.value().end() ) |
1720 | 1724 | { |
1721 | | keybind = query.value(0).toString(); |
1722 | | QString db_description = query.value(1).toString(); |
| 1725 | keybind = actionResult.value().keyList; |
| 1726 | const QString &db_description = actionResult.value().description; |
1723 | 1727 | |
1724 | 1728 | // Update keybinding description if changed |
1725 | 1729 | if (db_description != description) |
1726 | 1730 | { |
1727 | | LOG(VB_GENERAL, LOG_NOTICE, |
1728 | | "Updating keybinding description..."); |
1729 | | query.prepare( |
1730 | | "UPDATE keybindings " |
1731 | | "SET description = :DESCRIPTION " |
1732 | | "WHERE context = :CONTEXT AND " |
1733 | | " action = :ACTION AND " |
1734 | | " hostname = :HOSTNAME"); |
1735 | | |
1736 | | query.bindValue(":DESCRIPTION", description); |
1737 | | query.bindValue(":CONTEXT", context); |
1738 | | query.bindValue(":ACTION", action); |
1739 | | query.bindValue(":HOSTNAME", GetMythDB()->GetHostName()); |
| 1731 | MSqlQuery query(MSqlQuery::InitCon()); |
1740 | 1732 | |
1741 | | if (!query.exec() && !(GetMythDB()->SuppressDBMessages())) |
| 1733 | if (d->m_useDB && query.isConnected()) |
1742 | 1734 | { |
1743 | | MythDB::DBError("Update Keybinding", query); |
| 1735 | LOG(VB_GENERAL, LOG_NOTICE, |
| 1736 | "Updating keybinding description..."); |
| 1737 | query.prepare( |
| 1738 | "UPDATE keybindings " |
| 1739 | "SET description = :DESCRIPTION " |
| 1740 | "WHERE context = :CONTEXT AND " |
| 1741 | " action = :ACTION AND " |
| 1742 | " hostname = :HOSTNAME"); |
| 1743 | |
| 1744 | query.bindValue(":DESCRIPTION", description); |
| 1745 | query.bindValue(":CONTEXT", context); |
| 1746 | query.bindValue(":ACTION", action); |
| 1747 | query.bindValue(":HOSTNAME", GetMythDB()->GetHostName()); |
| 1748 | |
| 1749 | if (!query.exec() && !(GetMythDB()->SuppressDBMessages())) |
| 1750 | { |
| 1751 | MythDB::DBError("Update Keybinding", query); |
| 1752 | } |
1744 | 1753 | } |
1745 | 1754 | } |
1746 | 1755 | } |
1747 | 1756 | else |
1748 | 1757 | { |
1749 | | QString inskey = keybind; |
| 1758 | LOG(VB_GENERAL, LOG_NOTICE, |
| 1759 | "Insert missing keybinding description..."); |
1750 | 1760 | |
1751 | | query.prepare("INSERT INTO keybindings (context, action, " |
1752 | | "description, keylist, hostname) VALUES " |
1753 | | "( :CONTEXT, :ACTION, :DESCRIPTION, :KEYLIST, " |
1754 | | ":HOSTNAME );"); |
1755 | | query.bindValue(":CONTEXT", context); |
1756 | | query.bindValue(":ACTION", action); |
1757 | | query.bindValue(":DESCRIPTION", description); |
1758 | | query.bindValue(":KEYLIST", inskey); |
1759 | | query.bindValue(":HOSTNAME", GetMythDB()->GetHostName()); |
| 1761 | MSqlQuery query(MSqlQuery::InitCon()); |
1760 | 1762 | |
1761 | | if (!query.exec() && !(GetMythDB()->SuppressDBMessages())) |
| 1763 | if (d->m_useDB && query.isConnected()) |
1762 | 1764 | { |
1763 | | MythDB::DBError("Insert Keybinding", query); |
| 1765 | QString &inskey = keybind; |
| 1766 | query.prepare("INSERT INTO keybindings (context, action, " |
| 1767 | "description, keylist, hostname) VALUES " |
| 1768 | "( :CONTEXT, :ACTION, :DESCRIPTION, :KEYLIST, " |
| 1769 | ":HOSTNAME );"); |
| 1770 | query.bindValue(":CONTEXT", context); |
| 1771 | query.bindValue(":ACTION", action); |
| 1772 | query.bindValue(":DESCRIPTION", description); |
| 1773 | query.bindValue(":KEYLIST", inskey); |
| 1774 | query.bindValue(":HOSTNAME", GetMythDB()->GetHostName()); |
| 1775 | |
| 1776 | if (!query.exec() && !(GetMythDB()->SuppressDBMessages())) |
| 1777 | { |
| 1778 | MythDB::DBError("Insert Keybinding", query); |
| 1779 | } |
1764 | 1780 | } |
1765 | 1781 | } |
1766 | 1782 | } |
… |
… |
void MythMainWindow::RegisterKey(const QString &context, const QString &action, |
1769 | 1785 | d->actionText[context][action] = description; |
1770 | 1786 | } |
1771 | 1787 | |
| 1788 | void MythMainWindow::CacheBackendKeys() |
| 1789 | { |
| 1790 | MSqlQuery query(MSqlQuery::InitCon()); |
| 1791 | |
| 1792 | if (d->m_useDB && query.isConnected()) |
| 1793 | { |
| 1794 | query.prepare("SELECT context, action, keylist, description FROM keybindings WHERE " |
| 1795 | "hostname = :HOSTNAME ;"); |
| 1796 | query.bindValue(":HOSTNAME", GetMythDB()->GetHostName()); |
| 1797 | |
| 1798 | if (query.exec()) |
| 1799 | while (query.next()) |
| 1800 | { |
| 1801 | QString context = query.value(0).toString(); |
| 1802 | QString action = query.value(1).toString(); |
| 1803 | QString keybind = query.value(2).toString(); |
| 1804 | QString description = query.value(3).toString(); |
| 1805 | d->backendKeyCache[context][action] = KeyInfo(keybind, description); |
| 1806 | } |
| 1807 | } |
| 1808 | } |
| 1809 | |
1772 | 1810 | QString MythMainWindow::GetKey(const QString &context, |
1773 | 1811 | const QString &action) const |
1774 | 1812 | { |
1775 | | MSqlQuery query(MSqlQuery::InitCon()); |
1776 | | if (!query.isConnected()) |
1777 | | return "?"; |
1778 | | |
1779 | | query.prepare("SELECT keylist " |
1780 | | "FROM keybindings " |
1781 | | "WHERE context = :CONTEXT AND " |
1782 | | " action = :ACTION AND " |
1783 | | " hostname = :HOSTNAME"); |
1784 | | query.bindValue(":CONTEXT", context); |
1785 | | query.bindValue(":ACTION", action); |
1786 | | query.bindValue(":HOSTNAME", GetMythDB()->GetHostName()); |
1787 | | |
1788 | | if (!query.exec() || !query.isActive() || !query.next()) |
1789 | | return "?"; |
1790 | | |
1791 | | return query.value(0).toString(); |
| 1813 | QMap<QString, QMap<QString, KeyInfo> >::iterator contextResult = d->backendKeyCache.find(context); |
| 1814 | if( contextResult != d->backendKeyCache.end() ) |
| 1815 | { |
| 1816 | QMap<QString, KeyInfo>::iterator actionResult = contextResult.value().find(action); |
| 1817 | if( actionResult != contextResult.value().end() ) |
| 1818 | { |
| 1819 | return actionResult.value().keyList; |
| 1820 | } |
| 1821 | } |
| 1822 | return "?"; |
1792 | 1823 | } |
1793 | 1824 | |
1794 | 1825 | QString MythMainWindow::GetActionText(const QString &context, |
diff --git a/mythtv/libs/libmythui/mythmainwindow.h b/mythtv/libs/libmythui/mythmainwindow.h
index bca3bb9..2e47e8a 100644
a
|
b
|
class MUI_PUBLIC MythMainWindow : public QWidget |
62 | 62 | const QString &key); |
63 | 63 | void RegisterKey(const QString &context, const QString &action, |
64 | 64 | const QString &description, const QString &key); |
| 65 | void CacheBackendKeys(); |
65 | 66 | QString GetKey(const QString &context, const QString &action) const; |
66 | 67 | QString GetActionText(const QString &context, const QString &action) const; |
67 | 68 | |