Ticket #3446: 3446-mfe-quit-reboot-menu-combined.diff

File 3446-mfe-quit-reboot-menu-combined.diff, 7.4 KB (added by Nick Morrott <<knowledgejunkie [at] gmail [dot] com>>, 19 years ago)

Provides configurable shutdow/reboot exit menu options for SVN trunk

  • mythtv/programs/mythfrontend/globalsettings.cpp

     
    14461446    return gc;
    14471447}
    14481448
     1449static HostComboBox *OverrideExitMenu()
     1450{
     1451    HostComboBox *gc = new HostComboBox("OverrideExitMenu");
     1452    gc->setLabel(QObject::tr("Customise exit menu options"));
     1453    gc->addSelection(QObject::tr("Autodetect"), "0");
     1454    gc->addSelection(QObject::tr("Show quit"), "1");
     1455    gc->addSelection(QObject::tr("Show quit and shutdown"), "2");
     1456    gc->addSelection(QObject::tr("Show quit, reboot and shutdown"), "3");
     1457    gc->addSelection(QObject::tr("Show shutdown"), "4");
     1458    gc->addSelection(QObject::tr("Show reboot"), "5");
     1459    gc->addSelection(QObject::tr("Show reboot and shutdown"), "6");
     1460    gc->setHelpText(QObject::tr("By default, only remote frontends are shown "
     1461                    "the shutdown option on the exit menu. Here you can force "
     1462                    "specific shutdown and reboot options to be displayed."));
     1463    return gc;
     1464}
     1465
    14491466static HostCheckBox *NoPromptOnExit()
    14501467{
    14511468    HostCheckBox *gc = new HostCheckBox("NoPromptOnExit");
     
    14571474    return gc;
    14581475}
    14591476
     1477static HostLineEdit *RebootCommand()
     1478{
     1479    HostLineEdit *ge = new HostLineEdit("RebootCommand");
     1480    ge->setLabel(QObject::tr("Reboot command"));
     1481    ge->setValue("reboot");
     1482    ge->setHelpText(QObject::tr("Command or script to run if you select "
     1483                    "the reboot option from the exit menu, if the option "
     1484                    "is displayed. You must configure an exit key to "
     1485                    "display the exit menu."));
     1486    return ge;
     1487}
     1488
    14601489static HostLineEdit *HaltCommand()
    14611490{
    14621491    HostLineEdit *ge = new HostLineEdit("HaltCommand");
    14631492    ge->setLabel(QObject::tr("Halt command"));
    14641493    ge->setValue("halt");
    1465     ge->setHelpText(QObject::tr("If you have configured an exit key using the "
    1466                     "System Shutdown option, you will be given the opportunity "
    1467                     "to exit MythTV or halt the system completely. "
    1468                     "Another possibility for this field is \"poweroff\""));
     1494    ge->setHelpText(QObject::tr("Command or script to run if you select "
     1495                    "the shutdown option from the exit menu, if the option "
     1496                    "is displayed. You must configure an exit key to "
     1497                    "display the exit menu."));
    14691498    return ge;
    14701499}
    14711500
     
    35693598    pin->addChild(SetupPinCode());
    35703599    misc->addChild(pin);
    35713600    VerticalConfigurationGroup* shutdownSettings = new VerticalConfigurationGroup(true);
    3572     shutdownSettings->setLabel(QObject::tr("Shutdown Settings"));
     3601    shutdownSettings->setLabel(QObject::tr("Shutdown/Reboot Settings"));
     3602    shutdownSettings->addChild(OverrideExitMenu());
    35733603    shutdownSettings->addChild(HaltCommand());
     3604    shutdownSettings->addChild(RebootCommand());
    35743605    misc->addChild(shutdownSettings);
    35753606    addChild(misc);
    35763607
  • mythtv/programs/mythfrontend/main.cpp

     
    5454#define NO_EXIT  0
    5555#define QUIT     1
    5656#define HALT     2
     57#define REBOOT   3
    5758
    5859static MythThemedMenu *menu;
    5960static MythThemeBase *themeBase;
     
    437438    // first of all find out, if this is a frontend only host...
    438439    bool frontendOnly = gContext->IsFrontendOnly();
    439440
     441    // how do you want to quit today?
     442    int  exitMenuStyle = gContext->GetNumSetting("OverrideExitMenu", 0);
     443
    440444    QString title = QObject::tr("Do you really want to exit MythTV?");
    441445
     446    // 'simplify' exit menu construction
    442447    DialogBox diag(gContext->GetMainWindow(), title);
    443     diag.AddButton(QObject::tr("No"));
    444     diag.AddButton(QObject::tr("Yes, Exit now"));
    445     if (frontendOnly)
    446         diag.AddButton(QObject::tr("Yes, Exit and Shutdown"));
    447448
    448     int result = diag.exec();
    449     switch (result)
     449            diag.AddButton(QObject::tr("No"));
     450            int result;
     451
     452    switch (exitMenuStyle)
    450453    {
    451         case 1: return NO_EXIT;
    452         case 2: return QUIT;
    453         case 3: return HALT;
    454         default: return NO_EXIT;
     454        case 0:
     455            diag.AddButton(QObject::tr("Yes, Exit now"));
     456            if (frontendOnly)
     457                diag.AddButton(QObject::tr("Yes, Exit and Shutdown"));
     458            result = diag.exec();
     459            switch (result)
     460            {
     461                case 1: return NO_EXIT;
     462                case 2: return QUIT;
     463                case 3: return HALT;
     464                default: return NO_EXIT;
     465            }
     466        case 1:
     467            diag.AddButton(QObject::tr("Yes, Exit now"));
     468            result = diag.exec();
     469            switch (result)
     470            {
     471                case 1: return NO_EXIT;
     472                case 2: return QUIT;
     473                default: return NO_EXIT;
     474            }
     475        case 2:
     476            diag.AddButton(QObject::tr("Yes, Exit now"));
     477            diag.AddButton(QObject::tr("Yes, Exit and Shutdown"));
     478            result = diag.exec();
     479            switch (result)
     480            {
     481                case 1: return NO_EXIT;
     482                case 2: return QUIT;
     483                case 3: return HALT;
     484                default: return NO_EXIT;
     485            }
     486        case 3:
     487            diag.AddButton(QObject::tr("Yes, Exit now"));
     488            diag.AddButton(QObject::tr("Yes, Exit and Reboot"));
     489            diag.AddButton(QObject::tr("Yes, Exit and Shutdown"));
     490            result = diag.exec();
     491            switch (result)
     492            {
     493                case 1: return NO_EXIT;
     494                case 2: return QUIT;
     495                case 3: return REBOOT;
     496                case 4: return HALT;
     497                default: return NO_EXIT;
     498            }
     499        case 4:
     500            diag.AddButton(QObject::tr("Yes, Exit and Shutdown"));
     501            result = diag.exec();
     502            switch (result)
     503            {
     504                case 1: return NO_EXIT;
     505                case 2: return HALT;
     506                default: return NO_EXIT;
     507            }
     508        case 5:
     509            diag.AddButton(QObject::tr("Yes, Exit and Reboot"));
     510            result = diag.exec();
     511            switch (result)
     512            {
     513                case 1: return NO_EXIT;
     514                case 2: return REBOOT;
     515                default: return NO_EXIT;
     516            }
     517        case 6:
     518            diag.AddButton(QObject::tr("Yes, Exit and Reboot"));
     519            diag.AddButton(QObject::tr("Yes, Exit and Shutdown"));
     520            result = diag.exec();
     521            switch (result)
     522            {
     523                case 1: return NO_EXIT;
     524                case 2: return REBOOT;
     525                case 3: return HALT;
     526                default: return NO_EXIT;
     527            }
    455528    }
    456529}
    457530
     
    463536        system(halt_cmd.ascii());
    464537}
    465538
     539void rebootnow()
     540{
     541    QString reboot_cmd = gContext->GetSetting("RebootCommand",
     542                                            "sudo /sbin/reboot");
     543    if (!reboot_cmd.isEmpty())
     544        system(reboot_cmd.ascii());
     545}
     546
    466547bool RunMenu(QString themedir)
    467548{
    468549    menu = new MythThemedMenu(themedir.ascii(), "mainmenu.xml",
     
    12501331    if (exitstatus == HALT)
    12511332        haltnow();
    12521333
     1334    if (exitstatus == REBOOT)
     1335        rebootnow();
     1336
    12531337    pmanager->DestroyAllPlugins();
    12541338
    12551339#ifndef _WIN32