Skip to content
Permalink
Browse files

Remove the "Confirm exit" setting.

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 6e203ecfd76b7f798987e8df43ce43ca9ed58ea3
@@ -114,7 +114,7 @@ package MythTV;
# 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
# 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
# the number of items in a ProgramInfo QStringList group used by
@@ -5,7 +5,7 @@
"""

OWN_VERSION = (0,25,-1,2)
SCHEMA_VERSION = 1279
SCHEMA_VERSION = 1280
NVSCHEMA_VERSION = 1007
MUSICSCHEMA_VERSION = 1018
PROTO_VERSION = '69'
@@ -22,7 +22,7 @@ using namespace std;
mythtv/bindings/perl/MythTV.pm
*/
/// 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 performActualUpdate(
@@ -5786,6 +5786,69 @@ NULL
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;
}

@@ -1170,7 +1170,9 @@ void MythMainWindow::InitKeys()
"Go forward to previous page"), "F");

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()
@@ -217,13 +217,16 @@ bool MythThemedMenu::keyPressEvent(QKeyEvent *event)
MythUIButtonListItem *item = m_buttonList->GetItemCurrent();
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 lastScreen = (GetMythMainWindow()->GetMainStack()
->TotalScreens() == 1);
QString menuaction = "UPMENU";
QString selExit = "EXITING_APP";
QString selExit = "EXITING_APP_PROMPT";
if (action == "EXIT")
selExit = "EXITING_APP";

if (!m_allocedstate)
handleAction(menuaction);
@@ -243,8 +246,9 @@ bool MythThemedMenu::keyPressEvent(QKeyEvent *event)
QCoreApplication::exit();
}
}
else if ((action == "EXIT" || (action == "ESCAPE" &&
(QCoreApplication::applicationName() ==
else if ((action == "EXIT" || action == "EXITPROMPT" ||
(action == "ESCAPE" &&
(QCoreApplication::applicationName() ==
MYTH_APPNAME_MYTHTV_SETUP))) && lastScreen)
{
if (callbacks)
@@ -1670,17 +1670,6 @@ static HostComboBox *OverrideExitMenu()
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()
{
HostLineEdit *ge = new HostLineEdit("RebootCommand");
@@ -3314,21 +3303,13 @@ MainGeneralSettings::MainGeneralSettings()
media->addChild(mediaMon);
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 =
new VerticalConfigurationGroup(true, true, false, false);
shutdownSettings->setLabel(QObject::tr("Shutdown/Reboot Settings"));
shutdownSettings->addChild(OverrideExitMenu());
shutdownSettings->addChild(HaltCommand());
shutdownSettings->addChild(RebootCommand());
exit->addChild(ehor0);
exit->addChild(shutdownSettings);
addChild(exit);
addChild(shutdownSettings);

VerticalConfigurationGroup *remotecontrol =
new VerticalConfigurationGroup(false, true, false, false);
@@ -92,7 +92,7 @@ static QString logfile;
static MediaRenderer *g_pUPnp = NULL;
static MythPluginManager *pmanager = NULL;

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

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

@@ -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)
qApp->quit();
else
if (prompt)
{
if (!exitPopup)
exitPopup = new ExitPrompter();

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

static bool RunMenu(QString themedir, QString themename)
@@ -101,7 +101,7 @@ static void SetupMenuCallback(void* data, QString& selection)
else
delete msee;
}
else if (sel == "exiting_app")
else if (sel.startsWith("exiting_app"))
{
if (!exitPrompt)
exitPrompt = new ExitPrompter();

0 comments on commit 6e203ec

Please sign in to comment.
You can’t perform that action at this time.