Skip to content

Commit

Permalink
Allow users to reset all keys to defaults.
Browse files Browse the repository at this point in the history
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
sphery committed Jul 26, 2011
1 parent 4e7fd7f commit 28a42f2
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 15 deletions.
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/tv_play.cpp
Expand Up @@ -763,7 +763,7 @@ void TV::InitKeys(void)
*/
}

void TV::ResetKeys(void)
void TV::ReloadKeys(void)
{
MythMainWindow *mainWindow = GetMythMainWindow();
mainWindow->ClearKeyContext("TV Frontend");
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/tv_play.h
Expand Up @@ -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 *);
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythui/mythmainwindow.cpp
Expand Up @@ -1175,7 +1175,7 @@ void MythMainWindow::InitKeys()
"Display System Exit Prompt"), "Esc");
}

void MythMainWindow::ResetKeys()
void MythMainWindow::ReloadKeys()
{
ClearKeyContext("Global");
ClearKeyContext("Browser");
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythui/mythmainwindow.h
Expand Up @@ -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,
Expand Down
102 changes: 92 additions & 10 deletions mythtv/programs/mythfrontend/main.cpp
Expand Up @@ -93,6 +93,7 @@ static MediaRenderer *g_pUPnp = NULL;
static MythPluginManager *pmanager = NULL;

static void handleExit(bool prompt);
static void resetAllKeys(void);

namespace
{
Expand Down Expand Up @@ -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 "
Expand Down Expand Up @@ -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",
Expand All @@ -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");
Expand All @@ -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;
}

Expand Down Expand Up @@ -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();

Expand Down
3 changes: 3 additions & 0 deletions mythtv/programs/mythfrontend/mythcontrols.cpp
Expand Up @@ -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"));
}

Expand Down Expand Up @@ -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")
{
Expand Down
2 changes: 1 addition & 1 deletion mythtv/programs/mythtv-setup/main.cpp
Expand Up @@ -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();
Expand Down

0 comments on commit 28a42f2

Please sign in to comment.