Skip to content

Commit

Permalink
Remove the "Confirm exit" setting.
Browse files Browse the repository at this point in the history
The "Confirm exit" setting is another setting that changes the behavior
of an action based on a setting, and, therefore, should actually be
handled through binding the exit key to the appropriate action.

This patch adds a new action Main Menu/EXITPROMPT which displays a
prompt before exiting and uses the existing Main Menu/EXIT action to
exit without prompting the user.  This allows users to choose whether
mythfrontend should prompt them before exit and even allows a user to
bind different keys to each action so they can exit with a prompt in
some cases (such as when using Escape key, often bound to the Stop
button on remotes) and exit without a prompt in other cases (such as
when using the key bound to the Power button on their remote or a
keyboard shortcut that's not mapped on their remote).

Key bindings are updated automatically based on the currently-specified
"Confirm exit" setting such that the key mapped to EXIT is re-mapped to
EXITPROMPT is "Confirm exit" is enabled.  The default behavior for new
MythTV systems is unchanged--EXITPROMPT will be mapped to the Escape key
since the "Confirm Exit" setting defaulted to enabled.

Thanks to [R] on IRC for the idea, and to skd5aner and stuartm on IRC
for the final push to finish and the inspiration to figure out that last
10% of the patch.
  • Loading branch information
sphery committed Jul 22, 2011
1 parent e90f024 commit 6e203ec
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 35 deletions.
2 changes: 1 addition & 1 deletion mythtv/bindings/perl/MythTV.pm
Expand Up @@ -114,7 +114,7 @@ package MythTV;
# schema version supported in the main code. We need to check that the schema # schema version supported in the main code. We need to check that the schema
# version in the database is as expected by the bindings, which are expected # version in the database is as expected by the bindings, which are expected
# to be kept in sync with the main code. # to be kept in sync with the main code.
our $SCHEMA_VERSION = "1279"; our $SCHEMA_VERSION = "1280";


# NUMPROGRAMLINES is defined in mythtv/libs/libmythtv/programinfo.h and is # NUMPROGRAMLINES is defined in mythtv/libs/libmythtv/programinfo.h and is
# the number of items in a ProgramInfo QStringList group used by # the number of items in a ProgramInfo QStringList group used by
Expand Down
2 changes: 1 addition & 1 deletion mythtv/bindings/python/MythTV/static.py
Expand Up @@ -5,7 +5,7 @@
""" """


OWN_VERSION = (0,25,-1,2) OWN_VERSION = (0,25,-1,2)
SCHEMA_VERSION = 1279 SCHEMA_VERSION = 1280
NVSCHEMA_VERSION = 1007 NVSCHEMA_VERSION = 1007
MUSICSCHEMA_VERSION = 1018 MUSICSCHEMA_VERSION = 1018
PROTO_VERSION = '69' PROTO_VERSION = '69'
Expand Down
65 changes: 64 additions & 1 deletion mythtv/libs/libmythtv/dbcheck.cpp
Expand Up @@ -22,7 +22,7 @@ using namespace std;
mythtv/bindings/perl/MythTV.pm mythtv/bindings/perl/MythTV.pm
*/ */
/// This is the DB schema version expected by the running MythTV instance. /// This is the DB schema version expected by the running MythTV instance.
const QString currentDatabaseVersion = "1279"; const QString currentDatabaseVersion = "1280";


static bool UpdateDBVersionNumber(const QString &newnumber, QString &dbver); static bool UpdateDBVersionNumber(const QString &newnumber, QString &dbver);
static bool performActualUpdate( static bool performActualUpdate(
Expand Down Expand Up @@ -5786,6 +5786,69 @@ NULL
return false; return false;
} }


if (dbver == "1279")
{
LOG(VB_GENERAL, LOG_NOTICE, "Upgrading to MythTV schema version 1280");

MSqlQuery select(MSqlQuery::InitCon());
// New DBs/hosts will not have a NoPromptOnExit, so they'll get defaults
select.prepare("SELECT hostname, data FROM settings "
" WHERE value = 'NoPromptOnExit'");
if (!select.exec())
{
MythDB::DBError("Unable to retrieve confirm exit values.", select);
}
else
{
MSqlQuery update(MSqlQuery::InitCon());
while (select.next())
{
QString hostname = select.value(0).toString();
// Yes, enabled NoPromptOnExit meant to prompt on exit
QString prompt_on_exit = select.value(1).toString();
// Default EXITPROMPT is wrong for all upgrades
update.prepare("DELETE FROM keybindings "
" WHERE action = 'EXITPROMPT' "
" AND context = 'Main Menu' "
" AND hostname = :HOSTNAME ;");
update.bindValue(":HOSTNAME", hostname);
if (!update.exec())
MythDB::DBError("Unable to delete EXITPROMPT binding",
update);

if ("0" == prompt_on_exit)
{
// EXIT is already mapped appropriately, so just create a
// no-keylist mapping for EXITPROMPT to prevent conflict
update.prepare("INSERT INTO keybindings (context, action, "
" description, keylist, hostname) "
"VALUES ('Main Menu', 'EXITPROMPT', '', "
" '', :HOSTNAME );");
update.bindValue(":HOSTNAME", hostname);
if (!update.exec())
MythDB::DBError("Unable to create EXITPROMPT binding",
update);
}
else
{
// EXIT must be changed to EXITPROMPT
update.prepare("UPDATE keybindings "
" SET action = 'EXITPROMPT' "
" WHERE action = 'EXIT' "
" AND context = 'Main Menu' "
" AND hostname = :HOSTNAME ;");
update.bindValue(":HOSTNAME", hostname);
if (!update.exec())
MythDB::DBError("Unable to update EXITPROMPT binding",
update);
}
}
}

if (!UpdateDBVersionNumber("1280", dbver))
return false;
}

return true; return true;
} }


Expand Down
4 changes: 3 additions & 1 deletion mythtv/libs/libmythui/mythmainwindow.cpp
Expand Up @@ -1170,7 +1170,9 @@ void MythMainWindow::InitKeys()
"Go forward to previous page"), "F"); "Go forward to previous page"), "F");


RegisterKey("Main Menu", "EXIT", QT_TRANSLATE_NOOP("MythControls", RegisterKey("Main Menu", "EXIT", QT_TRANSLATE_NOOP("MythControls",
"System Exit"), "Esc"); "System Exit"), "");
RegisterKey("Main Menu", "EXITPROMPT", QT_TRANSLATE_NOOP("MythControls",
"Display System Exit Prompt"), "Esc");
} }


void MythMainWindow::ResetKeys() void MythMainWindow::ResetKeys()
Expand Down
12 changes: 8 additions & 4 deletions mythtv/libs/libmythui/myththemedmenu.cpp
Expand Up @@ -217,13 +217,16 @@ bool MythThemedMenu::keyPressEvent(QKeyEvent *event)
MythUIButtonListItem *item = m_buttonList->GetItemCurrent(); MythUIButtonListItem *item = m_buttonList->GetItemCurrent();
buttonAction(item); buttonAction(item);
} }
else if (action == "LEFT" || action == "ESCAPE" || action == "EXIT" ) else if (action == "LEFT" || action == "ESCAPE" ||
action == "EXIT" || action == "EXITPROMPT" )
{ {
bool callbacks = m_state->m_callback; bool callbacks = m_state->m_callback;
bool lastScreen = (GetMythMainWindow()->GetMainStack() bool lastScreen = (GetMythMainWindow()->GetMainStack()
->TotalScreens() == 1); ->TotalScreens() == 1);
QString menuaction = "UPMENU"; QString menuaction = "UPMENU";
QString selExit = "EXITING_APP"; QString selExit = "EXITING_APP_PROMPT";
if (action == "EXIT")
selExit = "EXITING_APP";


if (!m_allocedstate) if (!m_allocedstate)
handleAction(menuaction); handleAction(menuaction);
Expand All @@ -243,8 +246,9 @@ bool MythThemedMenu::keyPressEvent(QKeyEvent *event)
QCoreApplication::exit(); QCoreApplication::exit();
} }
} }
else if ((action == "EXIT" || (action == "ESCAPE" && else if ((action == "EXIT" || action == "EXITPROMPT" ||
(QCoreApplication::applicationName() == (action == "ESCAPE" &&
(QCoreApplication::applicationName() ==
MYTH_APPNAME_MYTHTV_SETUP))) && lastScreen) MYTH_APPNAME_MYTHTV_SETUP))) && lastScreen)
{ {
if (callbacks) if (callbacks)
Expand Down
21 changes: 1 addition & 20 deletions mythtv/programs/mythfrontend/globalsettings.cpp
Expand Up @@ -1670,17 +1670,6 @@ static HostComboBox *OverrideExitMenu()
return gc; return gc;
} }


static HostCheckBox *NoPromptOnExit()
{
HostCheckBox *gc = new HostCheckBox("NoPromptOnExit");
gc->setLabel(QObject::tr("Confirm exit"));
gc->setValue(true);
gc->setHelpText(QObject::tr("If enabled, MythTV will prompt "
"for confirmation when you press the System Exit "
"key."));
return gc;
}

static HostLineEdit *RebootCommand() static HostLineEdit *RebootCommand()
{ {
HostLineEdit *ge = new HostLineEdit("RebootCommand"); HostLineEdit *ge = new HostLineEdit("RebootCommand");
Expand Down Expand Up @@ -3314,21 +3303,13 @@ MainGeneralSettings::MainGeneralSettings()
media->addChild(mediaMon); media->addChild(mediaMon);
addChild(media); addChild(media);


VerticalConfigurationGroup *exit =
new VerticalConfigurationGroup(false, true, false, false);
exit->setLabel(QObject::tr("Program Exit"));
HorizontalConfigurationGroup *ehor0 =
new HorizontalConfigurationGroup(false, false, true, true);
ehor0->addChild(NoPromptOnExit());
VerticalConfigurationGroup *shutdownSettings = VerticalConfigurationGroup *shutdownSettings =
new VerticalConfigurationGroup(true, true, false, false); new VerticalConfigurationGroup(true, true, false, false);
shutdownSettings->setLabel(QObject::tr("Shutdown/Reboot Settings")); shutdownSettings->setLabel(QObject::tr("Shutdown/Reboot Settings"));
shutdownSettings->addChild(OverrideExitMenu()); shutdownSettings->addChild(OverrideExitMenu());
shutdownSettings->addChild(HaltCommand()); shutdownSettings->addChild(HaltCommand());
shutdownSettings->addChild(RebootCommand()); shutdownSettings->addChild(RebootCommand());
exit->addChild(ehor0); addChild(shutdownSettings);
exit->addChild(shutdownSettings);
addChild(exit);


VerticalConfigurationGroup *remotecontrol = VerticalConfigurationGroup *remotecontrol =
new VerticalConfigurationGroup(false, true, false, false); new VerticalConfigurationGroup(false, true, false, false);
Expand Down
14 changes: 8 additions & 6 deletions mythtv/programs/mythfrontend/main.cpp
Expand Up @@ -92,7 +92,7 @@ static QString logfile;
static MediaRenderer *g_pUPnp = NULL; static MediaRenderer *g_pUPnp = NULL;
static MythPluginManager *pmanager = NULL; static MythPluginManager *pmanager = NULL;


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


namespace namespace
{ {
Expand Down Expand Up @@ -996,8 +996,10 @@ static void TVMenuCallback(void *data, QString &selection)
} }
else if (sel == "tv_status") else if (sel == "tv_status")
showStatus(); showStatus();
else if (sel == "exiting_app_prompt")
handleExit(true);
else if (sel == "exiting_app") else if (sel == "exiting_app")
handleExit(); handleExit(false);
else else
LOG(VB_GENERAL, LOG_ERR, "Unknown menu action: " + selection); LOG(VB_GENERAL, LOG_ERR, "Unknown menu action: " + selection);


Expand All @@ -1015,17 +1017,17 @@ static void TVMenuCallback(void *data, QString &selection)
} }
} }


static void handleExit(void) static void handleExit(bool prompt)
{ {
if (gCoreContext->GetNumSetting("NoPromptOnExit", 1) == 0) if (prompt)
qApp->quit();
else
{ {
if (!exitPopup) if (!exitPopup)
exitPopup = new ExitPrompter(); exitPopup = new ExitPrompter();


exitPopup->handleExit(); exitPopup->handleExit();
} }
else
qApp->quit();
} }


static bool RunMenu(QString themedir, QString themename) static bool RunMenu(QString themedir, QString themename)
Expand Down
2 changes: 1 addition & 1 deletion mythtv/programs/mythtv-setup/main.cpp
Expand Up @@ -101,7 +101,7 @@ static void SetupMenuCallback(void* data, QString& selection)
else else
delete msee; delete msee;
} }
else if (sel == "exiting_app") else if (sel.startsWith("exiting_app"))
{ {
if (!exitPrompt) if (!exitPrompt)
exitPrompt = new ExitPrompter(); exitPrompt = new ExitPrompter();
Expand Down

0 comments on commit 6e203ec

Please sign in to comment.