Permalink
Browse files

Allow users to reset all keys to defaults.

This patch adds a menu item in MythControls (Utilities/Setup|Edit Keys)
to "Reset All Keys to Defaults".  The patch also adds a jump point,
"Reset All Keys," which does the same.

Note that the bindings for plugins will not be reset until the next time
mythfrontend is started, but they will continue to work as they were
previously mapped.  They will also not show in MythControls (nor the
database) until a frontend restart--when the plugins are re-init'ed.  I
didn't think this warranted a change to the plugin API nor unloading and
reloading all plugins just for the once-in-a-blue-moon "Reset All Keys".

The jump point was primarily to allow access to all the static functions
used in mythfrontend's main.cpp for key bindings initialization and jump
point callbacks from the MythControls code, but could actually be quite
useful if someone breaks "critical" key bindings like those which allow
navigating the menu to get to MythControls.  I did not define a default
mapping for the jump point, but with MythWeb's key bindings/jump point
mapping editor, users should be able to recover even if they didn't
assign a key before breaking bindings.

While I was in there, I renamed the ResetKeys() functions I had added in
anticipation of this patch to ReloadKeys() to better describe their
purpose.
  • Loading branch information...
1 parent 4e7fd7f commit 28a42f28efaeda8e044db03672698dd6197ffc10 @sphery sphery committed Jul 26, 2011
View
2 mythtv/libs/libmythtv/tv_play.cpp
@@ -763,7 +763,7 @@ void TV::InitKeys(void)
*/
}
-void TV::ResetKeys(void)
+void TV::ReloadKeys(void)
{
MythMainWindow *mainWindow = GetMythMainWindow();
mainWindow->ClearKeyContext("TV Frontend");
View
2 mythtv/libs/libmythtv/tv_play.h
@@ -244,7 +244,7 @@ class MTV_PUBLIC TV : public QObject
// static functions
static void InitKeys(void);
- static void ResetKeys(void);
+ static void ReloadKeys(void);
static bool StartTV(ProgramInfo *tvrec = NULL,
uint flags = kStartTVNoFlags);
static void SetFuncPtr(const char *, void *);
View
2 mythtv/libs/libmythui/mythmainwindow.cpp
@@ -1175,7 +1175,7 @@ void MythMainWindow::InitKeys()
"Display System Exit Prompt"), "Esc");
}
-void MythMainWindow::ResetKeys()
+void MythMainWindow::ReloadKeys()
{
ClearKeyContext("Global");
ClearKeyContext("Browser");
View
2 mythtv/libs/libmythui/mythmainwindow.h
@@ -52,7 +52,7 @@ class MUI_PUBLIC MythMainWindow : public QWidget
QStringList &actions, bool allowJumps = true)
MUNUSED_RESULT;
- void ResetKeys(void);
+ void ReloadKeys(void);
void ClearKey(const QString &context, const QString &action);
void ClearKeyContext(const QString &context);
void BindKey(const QString &context, const QString &action,
View
102 mythtv/programs/mythfrontend/main.cpp
@@ -93,6 +93,7 @@ static MediaRenderer *g_pUPnp = NULL;
static MythPluginManager *pmanager = NULL;
static void handleExit(bool prompt);
+static void resetAllKeys(void);
namespace
{
@@ -1266,7 +1267,8 @@ static void InitJumpPoints(void)
"", "", startGuide, "GUIDE");
REG_JUMPLOC(QT_TRANSLATE_NOOP("MythControls", "Program Finder"),
"", "", startFinder, "FINDER");
- //REG_JUMP("Search Listings", "", "", startSearch);
+ //REG_JUMP(QT_TRANSLATE_NOOP("MythControls", "Search Listings"),
+ // "", "", startSearch);
REG_JUMPLOC(QT_TRANSLATE_NOOP("MythControls", "Manage Recordings / "
"Fix Conflicts"), "", "", startManaged, "VIEWSCHEDULED");
REG_JUMP(QT_TRANSLATE_NOOP("MythControls", "Program Recording "
@@ -1303,6 +1305,46 @@ static void InitJumpPoints(void)
REG_JUMP("Play Disc", QT_TRANSLATE_NOOP("MythControls",
"Play an Optical Disc"), "", playDisc);
+ REG_JUMPEX(QT_TRANSLATE_NOOP("MythControls", "Toggle Show Widget Borders"),
+ "", "", setDebugShowBorders, false);
+ REG_JUMPEX(QT_TRANSLATE_NOOP("MythControls", "Toggle Show Widget Names"),
+ "", "", setDebugShowNames, false);
+ REG_JUMPEX(QT_TRANSLATE_NOOP("MythControls", "Reset All Keys"),
+ QT_TRANSLATE_NOOP("MythControls", "Reset all keys to defaults"),
+ "", resetAllKeys, false);
+}
+
+static void ReloadJumpPoints(void)
+{
+ MythMainWindow *mainWindow = GetMythMainWindow();
+ mainWindow->ClearJump("Reload Theme");
+ mainWindow->ClearJump("Main Menu");
+ mainWindow->ClearJump("Program Guide");
+ mainWindow->ClearJump("Program Finder");
+ //mainWindow->ClearJump("Search Listings");
+ mainWindow->ClearJump("Manage Recordings / Fix Conflicts");
+ mainWindow->ClearJump("Program Recording Priorities");
+ mainWindow->ClearJump("Manage Recording Rules");
+ mainWindow->ClearJump("Channel Recording Priorities");
+ mainWindow->ClearJump("TV Recording Playback");
+ mainWindow->ClearJump("TV Recording Deletion");
+ mainWindow->ClearJump("Live TV");
+ mainWindow->ClearJump("Live TV In Guide");
+ mainWindow->ClearJump("Status Screen");
+ mainWindow->ClearJump("Previously Recorded");
+ mainWindow->ClearJump("Video Default");
+ mainWindow->ClearJump("Video Manager");
+ mainWindow->ClearJump("Video Browser");
+ mainWindow->ClearJump("Video Listings");
+ mainWindow->ClearJump("Video Gallery");
+ mainWindow->ClearJump("Play Disc");
+ mainWindow->ClearJump("Toggle Show Widget Borders");
+ mainWindow->ClearJump("Toggle Show Widget Names");
+ InitJumpPoints();
+}
+
+static void InitKeys(void)
+{
REG_KEY("Video","PLAYALT", QT_TRANSLATE_NOOP("MythControls",
"Play selected item in alternate player"), "ALT+P");
REG_KEY("Video","FILTER", QT_TRANSLATE_NOOP("MythControls",
@@ -1323,24 +1365,58 @@ static void InitJumpPoints(void)
"Go to the first video"), "Home");
REG_KEY("Video","END", QT_TRANSLATE_NOOP("MythControls",
"Go to the last video"), "End");
- REG_MEDIA_HANDLER(QT_TRANSLATE_NOOP("MythControls",
- "MythDVD DVD Media Handler"), "", "", handleDVDMedia,
- MEDIATYPE_DVD, QString::null);
+}
- REG_JUMPEX(QT_TRANSLATE_NOOP("MythControls", "Toggle Show Widget Borders"),
- "", "", setDebugShowBorders, false);
- REG_JUMPEX(QT_TRANSLATE_NOOP("MythControls", "Toggle Show Widget Names"),
- "", "", setDebugShowNames, false);
+static void ReloadKeys(void)
+{
+ GetMythMainWindow()->ClearKeyContext("Video");
+ InitKeys();
- TV::InitKeys();
+ TV::ReloadKeys();
+}
+static void SetFuncPtrs(void)
+{
TV::SetFuncPtr("playbackbox", (void *)PlaybackBox::RunPlaybackBox);
TV::SetFuncPtr("viewscheduled", (void *)ViewScheduled::RunViewScheduled);
TV::SetFuncPtr("programguide", (void *)GuideGrid::RunProgramGuide);
TV::SetFuncPtr("programfinder", (void *)RunProgramFinder);
TV::SetFuncPtr("scheduleeditor", (void *)ScheduleEditor::RunScheduleEditor);
}
+/**
+ * \brief Deletes all key bindings and jump points for this host
+ */
+static void clearAllKeys(void)
+{
+ MSqlQuery query(MSqlQuery::InitCon());
+
+ query.prepare("DELETE FROM keybindings "
+ "WHERE hostname = :HOSTNAME;");
+ query.bindValue(":HOSTNAME", gCoreContext->GetHostName());
+ if (!query.exec())
+ MythDB::DBError("Deleting keybindings", query);
+ query.prepare("DELETE FROM jumppoints "
+ "WHERE hostname = :HOSTNAME;");
+ query.bindValue(":HOSTNAME", gCoreContext->GetHostName());
+ if (!query.exec())
+ MythDB::DBError("Deleting jumppoints", query);
+}
+
+/**
+ * \brief Reset this host's key bindings and jump points to default values
+ */
+static void resetAllKeys(void)
+{
+ clearAllKeys();
+ // Reload MythMainWindow bindings
+ GetMythMainWindow()->ReloadKeys();
+ // Reload Jump Points
+ ReloadJumpPoints();
+ // Reload mythfrontend and TV bindings
+ ReloadKeys();
+}
+
static void signal_USR1_handler(int){
LOG(VB_GENERAL, LOG_NOTICE, "SIGUSR1 received, reloading theme");
@@ -1361,6 +1437,9 @@ static int internal_media_init()
{
REG_MEDIAPLAYER("Internal", QT_TRANSLATE_NOOP("MythControls",
"MythTV's native media player."), internal_play_media);
+ REG_MEDIA_HANDLER(QT_TRANSLATE_NOOP("MythControls",
+ "MythDVD DVD Media Handler"), "", "", handleDVDMedia,
+ MEDIATYPE_DVD, QString::null);
return 0;
}
@@ -1544,9 +1623,12 @@ int main(int argc, char **argv)
// Refresh Global/Main Menu keys after DB update in case there was no DB
// when they were written originally
- mainWindow->ResetKeys();
+ mainWindow->ReloadKeys();
InitJumpPoints();
+ InitKeys();
+ TV::InitKeys();
+ SetFuncPtrs();
internal_media_init();
View
3 mythtv/programs/mythfrontend/mythcontrols.cpp
@@ -257,6 +257,7 @@ void MythControls::ShowMenu()
m_menuPopup->AddButton(tr("Save"));
m_menuPopup->AddButton(tr("Change View"));
+ m_menuPopup->AddButton(tr("Reset All Keys to Defaults"));
m_menuPopup->AddButton(tr("Cancel"));
}
@@ -718,6 +719,8 @@ void MythControls::customEvent(QEvent *event)
Save();
else if (buttonnum == 1)
ChangeView();
+ else if (buttonnum == 2)
+ GetMythMainWindow()->JumpTo("Reset All Keys");
}
else if (resultid == "exit")
{
View
2 mythtv/programs/mythtv-setup/main.cpp
@@ -482,7 +482,7 @@ int main(int argc, char *argv[])
// Refresh Global/Main Menu keys after DB update in case there was no DB
// when they were written originally
- mainWindow->ResetKeys();
+ mainWindow->ReloadKeys();
if (!startPrompt)
startPrompt = new StartPrompter();

0 comments on commit 28a42f2

Please sign in to comment.