Ticket #9740: mythtv-0.24-p2.patch

File mythtv-0.24-p2.patch, 12.8 KB (added by jorcas33@…, 8 years ago)

changes in mythwelcome: welcomedialog.cpp, welcomedialog.h and welcomesettings.cpp

  • mythtv/programs/mythwelcome/welcomedialog.cpp

    diff --git a/mythtv/programs/mythwelcome/welcomedialog.cpp b/mythtv/programs/mythwelcome/welcomedialog.cpp
    index 743519e..bb107ae 100644
    a b  
    11// ANSI C
    22#include <cstdlib>
     3#include <fstream>
    34
    45// POSIX
    56#include <unistd.h>
     
    2324#include "welcomedialog.h"
    2425#include "welcomesettings.h"
    2526
    26 #define UPDATE_STATUS_INTERVAL   30000
    27 #define UPDATE_SCREEN_INTERVAL   15000
     27#define UPDATE_STATUS_INTERVAL          30000
     28#define UPDATE_SCREEN_INTERVAL          15000
    2829
     30#define ACTION_CLOSE                    1
     31#define ACTION_SHOW_WELCOME_SETTINGS    2
     32#define ACTION_SHOW_SHUTDOWN_SETTINGS   3
     33           
    2934
    3035WelcomeDialog::WelcomeDialog(MythScreenStack *parent, const char *name)
    3136              :MythScreenType(parent, name),
    WelcomeDialog::WelcomeDialog(MythScreenStack *parent, const char *name) 
    4954    m_timeFormat = gCoreContext->GetSetting("TimeFormat", "h:mm AP");
    5055    m_dateFormat = gCoreContext->GetSetting("MythWelcomeDateFormat", "dddd\\ndd MMM yyyy");
    5156    m_dateFormat.replace("\\n", "\n");
     57    m_closePasswordSetting = "MythWelcomeExitPIN";
    5258
    5359    // if idleTimeoutSecs is 0, the user disabled the auto-shutdown feature
    5460    m_bWillShutdown = (gCoreContext->GetNumSetting("idleTimeoutSecs", 0) != 0);
    void WelcomeDialog::customEvent(QEvent *e) 
    212218    }
    213219}
    214220
     221void WelcomeDialog::showWelcomeSettings(void)
     222{
     223    MythWelcomeSettings settings;
     224    if (kDialogCodeAccepted == settings.exec())
     225    {
     226        RemoteSendMessage("CLEAR_SETTINGS_CACHE");
     227        updateStatus();
     228        updateScreen();
     229
     230        m_dateFormat = gCoreContext->GetSetting("MythWelcomeDateFormat", "dddd\\ndd MMM yyyy");
     231        m_dateFormat.replace("\\n", "\n");
     232    }
     233}
     234
     235void WelcomeDialog::showShutdownSettings(void)
     236{
     237    MythShutdownSettings settings;
     238    if (kDialogCodeAccepted == settings.exec())
     239        RemoteSendMessage("CLEAR_SETTINGS_CACHE");
     240}
     241
    215242bool WelcomeDialog::keyPressEvent(QKeyEvent *event)
    216243{
    217244    if (GetFocusWidget()->keyPressEvent(event))
    bool WelcomeDialog::keyPressEvent(QKeyEvent *event) 
    238265        {
    239266            Close();
    240267        }
    241         else if (action == "INFO")
     268        else if ( (action == "INFO") && checkPinCode("MythWelcome settings", ACTION_SHOW_WELCOME_SETTINGS) )
    242269        {
    243             MythWelcomeSettings settings;
    244             if (kDialogCodeAccepted == settings.exec())
    245             {
    246                 RemoteSendMessage("CLEAR_SETTINGS_CACHE");
    247                 updateStatus();
    248                 updateScreen();
    249 
    250                 m_dateFormat = gCoreContext->GetSetting("MythWelcomeDateFormat", "dddd\\ndd MMM yyyy");
    251                 m_dateFormat.replace("\\n", "\n");
    252             }
     270            showWelcomeSettings();
    253271        }
    254         else if (action == "SHOWSETTINGS")
     272        else if ( (action == "SHOWSETTINGS") && checkPinCode("MythShutdown settings", ACTION_SHOW_SHUTDOWN_SETTINGS) )
    255273        {
    256             MythShutdownSettings settings;
    257             if (kDialogCodeAccepted == settings.exec())
    258                 RemoteSendMessage("CLEAR_SETTINGS_CACHE");
     274            showShutdownSettings();
    259275        }
    260276        else if (action == "0")
    261277        {
    bool WelcomeDialog::keyPressEvent(QKeyEvent *event) 
    307323
    308324void WelcomeDialog::closeDialog()
    309325{
     326    if ( !checkPinCode("Exit PIN", ACTION_CLOSE) )
     327    {
     328        // password dialog is created, checking will be done in closePasswordCheck function
     329        // return without closing now
     330        updateStatusMessage();
     331        updateScreen();
     332        return;
     333    }
     334
    310335    Close();
    311336}
    312337
    void WelcomeDialog::showMenu(void) 
    614639
    615640    m_menuPopup->AddButton(tr("Run mythfilldatabase"), SLOT(runEPGGrabber()));
    616641    m_menuPopup->AddButton(tr("Shutdown Now"), SLOT(shutdownNow()));
     642    m_menuPopup->AddButton(tr("Reboot Now"), SLOT(rebootNow()));
    617643    m_menuPopup->AddButton(tr("Exit"), SLOT(closeDialog()));
    618644    m_menuPopup->AddButton(tr("Cancel"));
    619645}
    void WelcomeDialog::runEPGGrabber(void) 
    642668    updateScreen();
    643669}
    644670
    645 void WelcomeDialog::shutdownNow(void)
     671void WelcomeDialog::shutdownNow(bool is_poweroff)
    646672{
     673    // is_poweroff is true by default, so calling from shutdown menu it perform a real shutdown
     674    // rebootNow function will call this function with false as parameter
     675    QString poweroff_cmd = gCoreContext->GetSetting(is_poweroff ? "MythShutdownPowerOff" : "MythShutdownReboot", "");
     676    if ( poweroff_cmd.isEmpty() ) return;
     677   
    647678    // if this is a frontend only machine just shut down now
    648679    if (gCoreContext->IsFrontendOnly())
    649680    {
    650         VERBOSE(VB_GENERAL, "MythWelcome is shutting this computer down now");
    651         QString poweroff_cmd = gCoreContext->GetSetting("MythShutdownPowerOff", "");
    652         if (!poweroff_cmd.isEmpty())
    653             myth_system(poweroff_cmd);
     681        VERBOSE(VB_GENERAL, QString("MythWelcome is %1 this computer %2now")
     682                .arg(is_poweroff ? "shutting" : "rebooting")
     683                .arg(is_poweroff ? "down" : ""));
     684        myth_system(poweroff_cmd);
    654685        return;
    655686    }
    656687
    657688    // don't shutdown if we are recording
    658689    if (m_isRecording)
    659690    {
    660         MythPopupBox::showOkPopup(GetMythMainWindow(), "Cannot shutdown",
    661                 tr("Cannot shutdown because MythTV is currently recording"));
     691        MythPopupBox::showOkPopup(GetMythMainWindow(), QString("Cannot %1").arg(is_poweroff ? "shutdown" : "reboot"),
     692                QString("Cannot %1 because MythTV is currently recording").arg(is_poweroff ? "shutdown" : "reboot"));
    662693        return;
    663694    }
    664695
    665696    QDateTime curtime = QDateTime::currentDateTime();
    666697
    667     // don't shutdown if we are about to start recording
     698    // don't shutdown/reboot if we are about to start recording
    668699    if (!m_nextRecordingStart.isNull() &&
    669700        curtime.secsTo(m_nextRecordingStart) - m_preRollSeconds <
    670701        (m_idleWaitForRecordingTime * 60) + m_idleTimeoutSecs)
    671702    {
    672         MythPopupBox::showOkPopup(GetMythMainWindow(), "Cannot shutdown",
    673                 tr("Cannot shutdown because MythTV is about to start recording"));
     703        MythPopupBox::showOkPopup(GetMythMainWindow(), QString("Cannot %1").arg(is_poweroff ? "shutdown" : "reboot"),
     704                QString("Cannot %1 because MythTV is about to start recording").arg(is_poweroff ? "shutdown" : "reboot"));
    674705        return;
    675706    }
    676707
    677     // don't shutdown if we are about to start a wakeup/shutdown period
     708    // don't shutdown/reboot if we are about to start a wakeup/shutdown period
    678709    QString mythshutdown_exe_status =
    679710        m_installDir + "/bin/mythshutdown --status 0";
    680711    int statusCode = system(mythshutdown_exe_status.toLocal8Bit().constData());
    void WelcomeDialog::shutdownNow(void) 
    683714
    684715    if (statusCode & 128)
    685716    {
    686         MythPopupBox::showOkPopup(GetMythMainWindow(), "Cannot shutdown",
    687                 tr("Cannot shutdown because MythTV is about to start "
    688                 "a wakeup/shutdown period."));
     717        MythPopupBox::showOkPopup(GetMythMainWindow(), QString("Cannot %1").arg(is_poweroff ? "shutdown" : "reboot"),
     718                QString("Cannot %1 because MythTV is about to start a wakeup/shutdown period.").arg(is_poweroff ? "shutdown" : "reboot"));
    689719        return;
    690720    }
    691721
    void WelcomeDialog::shutdownNow(void) 
    721751        }
    722752    }
    723753
    724     // run command to set wakeuptime in bios and shutdown the system
    725     QString mythshutdown_exe =
    726         "sudo " + m_installDir + "/bin/mythshutdown --shutdown";
    727     myth_system(mythshutdown_exe);
     754    // run command to set wakeuptime in bios and shutdown/reboot the system
     755    myth_system(poweroff_cmd);
     756}
     757
     758void WelcomeDialog::rebootNow(void)
     759{
     760    // run shutdown function with parameter false, so a reboot will be performed
     761    shutdownNow(false);
     762}
     763
     764bool WelcomeDialog::checkPinCode(const QString &title, uint action)
     765{
     766    if ( gCoreContext->GetNumSetting(m_closePasswordSetting, 0) )
     767    {
     768        QString password = gCoreContext->GetSetting(m_closePasswordSetting);
     769
     770        if (!password.isEmpty())
     771        {
     772            // exit password is set, delay action until valid password is entered
     773            VERBOSE(VB_GENERAL, QString("Using Password: %1").arg(m_closePasswordSetting));
     774
     775            MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
     776            MythTextInputDialog *pwd =
     777                    new MythTextInputDialog(mainStack, title, FilterNone, true);
     778            switch(action)
     779            {
     780                default:
     781                case ACTION_CLOSE:
     782                    connect(pwd, SIGNAL(haveResult(QString)),SLOT(closePasswordCheck(QString)));
     783                    break;
     784                case ACTION_SHOW_WELCOME_SETTINGS:
     785                    connect(pwd, SIGNAL(haveResult(QString)),SLOT(showWelcomeSettingsPasswordCheck(QString)));
     786                    break;
     787                case ACTION_SHOW_SHUTDOWN_SETTINGS:
     788                    connect(pwd, SIGNAL(haveResult(QString)),SLOT(showShutdownSettingsPasswordCheck(QString)));
     789                    break;
     790            }
     791            if (pwd->Create())
     792            {
     793                mainStack->AddScreen(pwd, false);
     794            }
     795            // password dialog is created, checking will be done in specified action function
     796            updateStatusMessage();
     797            updateScreen();
     798            // return false, so no action will be done
     799            return false;
     800        }
     801    }
     802    return true;
     803}
     804
     805void WelcomeDialog::closePasswordCheck(const QString &password)
     806{
     807    QString exit_password = gCoreContext->GetSetting(m_closePasswordSetting);
     808    VERBOSE(VB_GENERAL, QString("closePasswordCheck"));
     809
     810    if (exit_password == password) Close();
     811}
     812
     813void WelcomeDialog::showWelcomeSettingsPasswordCheck(const QString &password)
     814{
     815    QString exit_password = gCoreContext->GetSetting(m_closePasswordSetting);
     816    VERBOSE(VB_GENERAL, QString("showWelcomeSettingsPasswordCheck"));
     817
     818    if (exit_password == password) showWelcomeSettings();
    728819}
    729820
     821void WelcomeDialog::showShutdownSettingsPasswordCheck(const QString &password)
     822{
     823    QString exit_password = gCoreContext->GetSetting(m_closePasswordSetting);
     824    VERBOSE(VB_GENERAL, QString("showShutdownSettingsPasswordCheck"));
     825
     826    if (exit_password == password) showShutdownSettings();
     827}
  • mythtv/programs/mythwelcome/welcomedialog.h

    diff --git a/mythtv/programs/mythwelcome/welcomedialog.h b/mythtv/programs/mythwelcome/welcomedialog.h
    index 1f16c59..c6a6b7a 100644
    a b class WelcomeDialog : public MythScreenType 
    3434    void updateScreen(void);
    3535    void closeDialog(void);
    3636    void showMenu(void);
    37     void shutdownNow(void);
     37    void shutdownNow(bool is_poweroff=true);
     38    void rebootNow(void);
    3839    void runEPGGrabber(void);
    3940    void lockShutdown(void);
    4041    void unlockShutdown(void);
    4142    bool updateRecordingList(void);
    4243    bool updateScheduledList(void);
    43 
     44    void showWelcomeSettings(void);
     45    void showShutdownSettings(void);
     46    bool checkPinCode(const QString &title, uint action);
     47    void closePasswordCheck(const QString &password);
     48    void showWelcomeSettingsPasswordCheck(const QString &password);
     49    void showShutdownSettingsPasswordCheck(const QString &password);
     50   
    4451  private:
    4552    void updateStatusMessage(void);
    4653    bool checkConnectionToServer(void);
    class WelcomeDialog : public MythScreenType 
    7885    uint           m_statusListNo;
    7986    QStringList    m_statusList;
    8087    bool           m_frontendIsRunning;
     88    QString        m_closePasswordSetting;
    8189
    8290    vector<TunerStatus> m_tunerList;
    8391    ProgramDetailList   m_scheduledList;
  • mythtv/programs/mythwelcome/welcomesettings.cpp

    diff --git a/mythtv/programs/mythwelcome/welcomesettings.cpp b/mythtv/programs/mythwelcome/welcomesettings.cpp
    index 39c85d2..7970018 100644
    a b static HostLineEdit *MythWelcomeDateFormat() 
    8585    return gc;
    8686};
    8787
     88
    8889MythWelcomeSettings::MythWelcomeSettings()
    8990{
    9091    HorizontalConfigurationGroup* hcg1 =
    static HostLineEdit *MythShutdownXTermCmd() 
    196197    return gc;
    197198};
    198199
     200static HostLineEdit *MythWelcomeExitPIN()
     201{
     202    HostLineEdit *gc = new HostLineEdit("MythWelcomeExitPIN");
     203    gc->setLabel(QObject::tr("Exit PIN"));
     204    gc->setValue("");
     205    gc->setHelpText(QObject::tr("Enter a PIN to protect MythWelcome from exit. "
     206                                "It also protect from accessing to setting screen. "
     207                                "Leave it blank to disable it. "));
     208    return gc;
     209};
     210
    199211
    200212MythShutdownSettings::MythShutdownSettings()
    201213{
    MythShutdownSettings::MythShutdownSettings() 
    210222    vcg->addChild(MythShutdownPowerOff());
    211223    vcg->addChild(MythShutdownXTermCmd());
    212224    vcg->addChild(MythShutdownStartFECmd());
     225    vcg->addChild(MythWelcomeExitPIN());
    213226
    214227    addChild(vcg);
    215228}