Skip to content

Commit

Permalink
MythFrontend: Add confirmation dialog when shutting down and mythbackend
Browse files Browse the repository at this point in the history
is running on the same system
  • Loading branch information
mark-kendall committed Nov 27, 2019
1 parent 9dc72f3 commit 406fc21
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 8 deletions.
57 changes: 51 additions & 6 deletions mythtv/programs/mythfrontend/exitprompt.cpp
Expand Up @@ -69,12 +69,21 @@ static bool DBusHalt(void)
int_reply = hal.call("Shutdown");

return void_reply.isValid() || int_reply.isValid();
#endif
#else
return false;
#endif
}

void ExitPrompter::confirmHalt()
{
confirm(HALT);
}

void ExitPrompter::halt()
void ExitPrompter::halt(bool Confirmed)
{
if (!Confirmed)
return;

QString halt_cmd = gCoreContext->GetSetting("HaltCommand","");
int ret = -1;

Expand Down Expand Up @@ -130,12 +139,21 @@ static bool DBusReboot(void)
int_reply = hal.call("Reboot");

return void_reply.isValid() || int_reply.isValid();
#endif
#else
return false;
#endif
}

void ExitPrompter::confirmReboot()
{
confirm(REBOOT);
}

void ExitPrompter::reboot()
void ExitPrompter::reboot(bool Confirmed)
{
if (!Confirmed)
return;

QString reboot_cmd = gCoreContext->GetSetting("RebootCommand","");
int ret = -1;

Expand Down Expand Up @@ -227,9 +245,15 @@ void ExitPrompter::handleExit()
if (allowExit)
dlg->AddButton(tr("Yes, Exit now"), SLOT(quit()));
if (allowReboot)
dlg->AddButton(tr("Yes, Exit and Reboot"), SLOT(reboot()));
{
dlg->AddButton(tr("Yes, Exit and Reboot"),
frontendOnly ? SLOT(reboot()) : SLOT(confirmReboot()));
}
if (allowShutdown)
dlg->AddButton(tr("Yes, Exit and Shutdown"), SLOT(halt()));
{
dlg->AddButton(tr("Yes, Exit and Shutdown"),
frontendOnly ? SLOT(halt()) : SLOT(confirmHalt()));
}
if (allowStandby)
dlg->AddButton(tr("Yes, Enter Standby Mode"), SLOT(standby()));

Expand All @@ -238,3 +262,24 @@ void ExitPrompter::handleExit()

ss->AddScreen(dlg);
}

void ExitPrompter::confirm(int Action)
{
MythScreenStack *ss = GetMythMainWindow()->GetStack("popup stack");
MythConfirmationDialog *dlg = new MythConfirmationDialog(ss,
tr("Mythbackend is running on this system. Are you sure you want to continue?"));

if (!dlg->Create())
{
delete dlg;
quit();
return;
}

if (Action == HALT)
connect(dlg, SIGNAL(haveResult(bool)), SLOT(halt(bool)));
else if (Action == REBOOT)
connect(dlg, SIGNAL(haveResult(bool)), SLOT(reboot(bool)));

ss->AddScreen(dlg);
}
7 changes: 5 additions & 2 deletions mythtv/programs/mythfrontend/exitprompt.h
Expand Up @@ -15,8 +15,11 @@ class ExitPrompter : public QObject

public slots:
static void quit(void);
static void halt(void);
static void reboot(void);
static void halt(bool Confirmed = true);
static void reboot(bool Confirmed = true);
static void standby(void);
void handleExit(void);
void confirmHalt(void);
void confirmReboot(void);
void confirm(int Action);
};

0 comments on commit 406fc21

Please sign in to comment.