Ticket #6290: 90-6290-mythtv-setup.patch

File 90-6290-mythtv-setup.patch, 7.5 KB (added by Matthew Wire <devel@…>, 15 years ago)

Updated patch for 20683

  • mythtv/programs/mythtv-setup/startprompt.cpp

     
     1// ANSI C
     2#include <cstdlib>
     3
     4// POSIX
     5#include <unistd.h>
     6
     7// qt
     8#include <QApplication>
     9#include <QKeyEvent>
     10#include <QLabel>
     11#include <QEvent>
     12
     13// myth
     14#include "libmythtv/videosource.h"
     15#include "libmythui/mythprogressdialog.h"
     16#include "channeleditor.h"
     17#include "compat.h"
     18#include "exitcodes.h"
     19#include "lcddevice.h"
     20#include "mythcontext.h"
     21#include "mythdbcon.h"
     22#include "mythdirs.h"
     23#include "myththemedmenu.h"
     24#include "mythuihelper.h"
     25#include "programinfo.h"
     26#include "uitypes.h"
     27
     28#include "backendsettings.h"
     29#include "startprompt.h"
     30#include "libmythtv/videosource.h"
     31
     32#include <QApplication>
     33
     34// MythTV stuff
     35#include "exitcodes.h"
     36#include "mythcontext.h"
     37#include "mythdialogbox.h"
     38#include "mythmainwindow.h"
     39#include "mythscreenstack.h"
     40#include "remoteutil.h"
     41
     42#include "checksetup.h"
     43#include "exitprompt.h"
     44
     45struct StartPrompterPrivate
     46{
     47    StartPrompterPrivate()
     48    {
     49        stk = GetMythMainWindow()->GetStack("popup stack");
     50    }
     51
     52    MythScreenStack *stk;
     53};
     54
     55StartPrompter::StartPrompter()
     56{
     57    m_d = new StartPrompterPrivate;
     58}
     59
     60StartPrompter::~StartPrompter()
     61{
     62    delete m_d;
     63}
     64
     65void StartPrompter::handleStart()
     66{
     67    // Offer to stop the backend if sensible
     68    if (gContext->BackendIsRunning() && gContext->IsMasterHost())
     69    {
     70        backendRunningPrompt();
     71    }   
     72}
     73
     74void StartPrompter::leaveBackendRunning()
     75{
     76    VERBOSE(VB_GENERAL, "Continuing with backend running");
     77    gContext->SetSetting("AutoRestartBackend", "0");
     78}
     79
     80void StartPrompter::stopBackend()
     81{
     82    VERBOSE(VB_GENERAL, "Trying to stop backend");
     83
     84    QString commandString = gContext->GetSetting("BackendStopCommand");
     85    if (!commandString.isEmpty())
     86    {
     87        myth_system(commandString);
     88    }
     89    gContext->SetSetting("AutoRestartBackend", "1");
     90}
     91
     92void StartPrompter::backendRunningPrompt(void)
     93{
     94    bool backendIsRecording = false;
     95    // Get recording status
     96    if (!gContext->IsConnectedToMaster())
     97    {
     98        gContext->ConnectToMasterServer(false);
     99        backendIsRecording = RemoteGetRecordingStatus(NULL, false);
     100    }
     101   
     102    QString warning = tr("WARNING: The backend is currently running.")+"\n\n"+
     103                      tr("Changing existing card inputs, deleting anything, "
     104                     "or scanning for channels may not work.")+"\n\n";
     105    if (backendIsRecording)
     106    {
     107        warning += tr("Recording Status: RECORDING.")+"\n"+
     108                   tr("If you stop the backend now these recordings will be stopped!");
     109    }
     110    else
     111    {
     112        warning += tr("Recording Status: None.");
     113    }
     114
     115    MythDialogBox *dia = new MythDialogBox(warning, m_d->stk, "actionmenu");
     116
     117    if (!dia->Create())
     118    {
     119        VERBOSE(VB_IMPORTANT, "Can't create Prompt dialog?");
     120        delete dia;
     121        quit();
     122    }
     123
     124    // This is a hack so that the button clicks target the correct slot:
     125    dia->SetReturnEvent(this, QString());
     126
     127    m_d->stk->AddScreen(dia);
     128
     129    QString commandString = gContext->GetSetting("BackendStopCommand");
     130    if (!commandString.isEmpty())
     131    {
     132        // Only show option to stop backend if command is defined.
     133        dia->AddButton(tr("Stop Backend and Continue"), SLOT(stopBackend()));
     134    }
     135    dia->AddButton(tr("Continue"), SLOT(leaveBackendRunning()));
     136    dia->AddButton(tr("Exit"), SLOT(quit()));
     137}
     138
     139void StartPrompter::quit()
     140{
     141    qApp->exit(GENERIC_EXIT_OK);
     142}
  • mythtv/programs/mythtv-setup/startprompt.h

     
     1#ifndef SETUPDIALOG_H_
     2#define SETUPDIALOG_H_
     3
     4#include <QObject>
     5
     6class StartPrompter : public QObject
     7{
     8    Q_OBJECT
     9
     10  public:
     11    StartPrompter();
     12    ~StartPrompter();
     13
     14  public slots:
     15    void handleStart();
     16    void backendRunningPrompt();
     17    void leaveBackendRunning();
     18    void stopBackend();
     19    void quit();
     20
     21  private:
     22    StartPrompter(const StartPrompter &);
     23
     24  private:
     25    struct StartPrompterPrivate *m_d;
     26};
     27
     28#endif
     29 No newline at end of file
  • mythtv/programs/mythtv-setup/mythtv-setup.pro

     
    2222    DEFINES += USING_BACKEND
    2323}
    2424
     25HEADERS += startprompt.h
     26SOURCES += startprompt.cpp
    2527# Input
    2628HEADERS += backendsettings.h   checksetup.h   exitprompt.h importicons.h
    2729HEADERS += channeleditor.h
  • mythtv/programs/mythtv-setup/exitprompt.cpp

     
    88#include "mythmainwindow.h"
    99#include "mythscreenstack.h"
    1010#include "remoteutil.h"
     11#include "mythsystem.h"
    1112
    1213#include "checksetup.h"
    1314#include "exitprompt.h"
     
    9495
    9596void ExitPrompter::quit()
    9697{
    97     if (gContext->BackendIsRunning())
    98         RemoteSendMessage("CLEAR_SETTINGS_CACHE");
     98    // If the backend was stopped restart it here
     99    if (gContext->GetSetting("AutoRestartBackend") == "1")
     100    {
     101        QString commandString = gContext->GetSetting("BackendStartCommand");
     102        if (!commandString.isEmpty())
     103        {
     104            VERBOSE(VB_IMPORTANT, "backendrestart"+commandString);
     105            myth_system(commandString);
     106        }
     107    }
     108    else
     109    {
     110        // No need to run this if the backend has just restarted
     111        if (gContext->BackendIsRunning())
     112        {
     113            RemoteSendMessage("CLEAR_SETTINGS_CACHE");
     114        }
     115    }
    99116
    100117    qApp->exit(GENERIC_EXIT_OK);
    101118}
  • mythtv/programs/mythtv-setup/main.cpp

     
    3131#include "libmythtv/remoteutil.h"
    3232#include "backendsettings.h"
    3333#include "checksetup.h"
     34#include "startprompt.h"
    3435
    3536using namespace std;
    3637
    3738ExitPrompter   *exitPrompt = NULL;
     39StartPrompter   *startPrompt = NULL;
    3840
    3941void SetupMenuCallback(void* data, QString& selection)
    4042{
     
    508510        return GENERIC_EXIT_DB_OUTOFDATE;
    509511    }
    510512
    511     QString warn =
    512         QObject::tr("WARNING") + ": " +
    513         QObject::tr("MythTV has detected that the backend is running.")+"\n\n"+
    514         QObject::tr("Changing existing card inputs, deleting anything, "
    515                     "or scanning for channels may not work.");
     513    if (!startPrompt)
     514            startPrompt = new StartPrompter();
     515        startPrompt->handleStart();
    516516
    517     bool backendIsRunning = gContext->BackendIsRunning();
    518 
    519     if (backendIsRunning)
    520     {
    521         DialogCode val = MythPopupBox::Show2ButtonPopup(
    522             mainWindow, QObject::tr("WARNING"), warn,
    523             QObject::tr("Continue"),
    524             QObject::tr("Exit"), kDialogCodeButton0);
    525 
    526         if (kDialogCodeButton1 == val)
    527         {
    528             return GENERIC_EXIT_OK;
    529         }
    530     }
    531 
    532517    REG_KEY("qt", "DELETE", "Delete", "D");
    533518    REG_KEY("qt", "EDIT", "Edit", "E");
    534519