Ticket #4184: 23-4184-mythtv-setup-mythui.patch

File 23-4184-mythtv-setup-mythui.patch, 14.6 KB (added by Matthew Wire <devel@…>, 15 years ago)
  • mythtv/programs/mythtv-setup/setupdialog.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 "libmythtv/channeleditor.h"
     16#include "libmythui/mythprogressdialog.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 "remoteutil.h"
     27#include "storagegroup.h"
     28#include "tv.h"
     29#include "uitypes.h"
     30
     31#include "backendsettings.h"
     32#include "setupdialog.h"
     33#include "checksetup.h"
     34
     35void SetupMenuCallback ( void* data, QString& selection )
     36{
     37    (void)data;
     38
     39    QString sel = selection.toLower();
     40
     41    if ( sel == "general" )
     42    {
     43        BackendSettings be;
     44        be.exec();
     45    }
     46    else if ( sel == "capture cards" )
     47    {
     48        CaptureCardEditor cce;
     49        cce.exec();
     50    }
     51    else if ( sel == "video sources" )
     52    {
     53        VideoSourceEditor vse;
     54        vse.exec();
     55    }
     56    else if ( sel == "card inputs" )
     57    {
     58        CardInputEditor cie;
     59        cie.exec();
     60    }
     61    else if ( sel == "channel editor" )
     62    {
     63        ChannelEditor ce;
     64        ce.exec();
     65    }
     66    else if ( sel == "storage groups" )
     67    {
     68        StorageGroupListEditor sge;
     69        sge.exec();
     70    }
     71}
     72
     73
     74SetupDialog::SetupDialog(MythScreenStack *parent, const char *name)
     75              :MythScreenType(parent, name)
     76{
     77    gContext->addListener(this);
     78
     79    m_menuPopup = NULL;
     80    m_restartBackend = false;
     81    m_haveProblems = false;
     82    m_terminate = false;
     83}
     84
     85void SetupDialog::Start(void)
     86{
     87            // Offer to stop the backend if sensible
     88        if (gContext->BackendIsRunning() && gContext->IsMasterHost())
     89        {
     90            ShowBackendMenu();
     91        }
     92        else
     93        {
     94            ShowSetupMenu();
     95        }
     96
     97}
     98
     99void SetupDialog::ShowSetupMenu(void)
     100{
     101    QString theme = gContext->GetSetting("Theme", "blue");
     102
     103    MythMainWindow *win = GetMythMainWindow();
     104       
     105    MythThemedMenu* menu = new MythThemedMenu(GetMythUI()->FindThemeDir(theme),
     106                                              "setup.xml", win->GetMainStack(),
     107                                              "mainmenu", false);
     108
     109    menu->setCallback(SetupMenuCallback, gContext);
     110    menu->setKillable();
     111
     112    if ( menu->foundTheme() )
     113    {
     114        win->GetMainStack()->AddScreen(menu);
     115    }
     116    else
     117    {
     118        VERBOSE(VB_IMPORTANT, QString("Couldn't find theme '%1'").arg(theme));
     119    }
     120}
     121
     122
     123void SetupDialog::CloseDialog()
     124{
     125    // If the backend was stopped restart it here
     126    if (m_restartBackend)
     127    {
     128        QString commandString = gContext->GetSetting("MythbackendStartCommand");
     129        if (!commandString.isEmpty())
     130        {
     131            VERBOSE(VB_IMPORTANT, "backendrestart"+commandString);
     132            myth_system(commandString);
     133        }
     134    }
     135    else
     136    {
     137        // No need to run this if the backend has just restarted
     138        if (gContext->BackendIsRunning())
     139        {
     140            RemoteSendMessage("CLEAR_SETTINGS_CACHE");
     141        }
     142    }
     143   
     144    m_terminate = true;
     145    qApp->exit(GENERIC_EXIT_OK);
     146}
     147
     148void SetupDialog::StopBackend()
     149{
     150    VERBOSE(VB_IMPORTANT, "Trying to stop backend");
     151
     152    QString commandString = gContext->GetSetting("MythbackendStopCommand");
     153    if (!commandString.isEmpty())
     154    {
     155        myth_system(commandString);
     156    }
     157    m_restartBackend = true;
     158
     159    //todo check mythbackend was stopped
     160    ShowSetupMenu();
     161}
     162
     163void SetupDialog::ContinueWithBackendRunning()
     164{
     165    VERBOSE(VB_IMPORTANT, "Continuing with backend running");
     166    ShowSetupMenu();
     167}
     168
     169
     170SetupDialog::~SetupDialog()
     171{
     172    gContext->removeListener(this);
     173}
     174
     175void SetupDialog::ShowBackendMenu(void)
     176{
     177    MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
     178
     179    bool backendIsRecording = false;
     180    // Get recording status
     181    if (!gContext->IsConnectedToMaster())
     182    {
     183        gContext->ConnectToMasterServer(false);
     184        backendIsRecording = RemoteGetRecordingStatus(NULL, false);
     185    }
     186   
     187    QString warning = tr("WARNING: The backend is currently running.")+"\n\n"+
     188                      tr("Changing existing card inputs, deleting anything, "
     189                     "or scanning for channels may not work.")+"\n\n";
     190    if (backendIsRecording)
     191    {
     192        warning += tr("Recording Status: RECORDING.")+"\n"+
     193                   tr("If you stop the backend now these recordings will be stopped!");
     194    }
     195    else
     196    {
     197        warning += tr("Recording Status: None.");
     198    }
     199
     200    m_menuPopup = new MythDialogBox(warning, popupStack, "actionmenu");
     201
     202    if (m_menuPopup->Create())
     203        popupStack->AddScreen(m_menuPopup);
     204
     205    m_menuPopup->SetReturnEvent(this, "action");
     206
     207    QString commandString = gContext->GetSetting("MythbackendStopCommand");
     208    if (!commandString.isEmpty())
     209    {
     210        // Only show option to stop backend if command is defined.
     211        m_menuPopup->AddButton(tr("Stop Backend and Continue"), SLOT(StopBackend()));
     212    }
     213    m_menuPopup->AddButton(tr("Continue"), SLOT(ContinueWithBackendRunning()));
     214    m_menuPopup->AddButton(tr("Exit"), SLOT(CloseDialog()));
     215}
     216
     217
     218void SetupDialog::ShowExitMenu(void)
     219{
     220    // Look for common problems
     221    QString *problems = new QString("");
     222    bool haveProblems = CheckSetup(problems);
     223
     224    if (haveProblems)
     225    {
     226        if (problems->count("\n") > 1)
     227        {
     228            *problems += "\n"+QObject::tr("Do you want to fix these problems?");
     229        }
     230        else
     231        {
     232            *problems += "\n"+QObject::tr("Do you want to fix this problem?");
     233        }
     234   
     235        MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
     236
     237        m_menuPopup = new MythDialogBox(*problems, popupStack, "actionmenu");
     238
     239        if (m_menuPopup->Create())
     240            popupStack->AddScreen(m_menuPopup);
     241
     242        m_menuPopup->SetReturnEvent(this, "action");
     243
     244        m_menuPopup->AddButton(tr("Yes (Return to Setup Menu)"), SLOT(ContinueWithBackendRunning()));
     245        m_menuPopup->AddButton(tr("No (Exit)"), SLOT(CloseDialog()));
     246       
     247        delete problems;
     248    }
     249    else
     250    {
     251        CloseDialog();
     252    }
     253}
     254
     255bool SetupDialog::Terminate(void)
     256{
     257    return m_terminate;   
     258}
     259
     260// Converted to mythui.  Not really sure that this dialog is helpful so
     261//   commented out for now.
     262/*
     263    if (gContext->IsMasterHost())
     264    {
     265        MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
     266
     267        QString prompt = QObject::tr("If this is the master backend server, "
     268                                     "please run 'mythfilldatabase' "
     269                                     "to populate the database "
     270                                     "with channel information."));
     271
     272        m_menuPopup = new MythDialogBox(prompt, popupStack, "actionmenu");
     273
     274        if (m_menuPopup->Create())
     275            popupStack->AddScreen(m_menuPopup);
     276
     277        m_menuPopup->SetReturnEvent(this, "action");
     278
     279        m_menuPopup->AddButton(tr("OK"), SLOT(CloseDialog()));
     280    }
     281*/
  • mythtv/programs/mythtv-setup/main.cpp

     
    1 
    2 #include <unistd.h>
    3 #include <cstdio>
    4 #include <fcntl.h>
    5 #include <cstdlib>
    6 #include <sys/types.h>
    7 
    81#include <iostream>
    92
    103#include <QApplication>
    114#include <QString>
    125#include <QDir>
    13 #include <QFile>
    14 #include <QStringList>
    15 #include <QRegExp>
    166#include <QMap>
    177
    18 #include "mythconfig.h"
     8#include "libmythtv/dbcheck.h"
     9#include "exitcodes.h"
     10#include "langsettings.h"
    1911#include "mythcontext.h"
    2012#include "mythdbcon.h"
    21 #include "mythverbose.h"
    22 #include "mythversion.h"
    23 #include "langsettings.h"
    24 #include "dialogbox.h"
    25 #include "exitcodes.h"
    26 #include "util.h"
    27 #include "storagegroup.h"
    28 #include "myththemedmenu.h"
     13#include "mythdirs.h"
    2914#include "myththemebase.h"
    3015#include "mythuihelper.h"
    31 #include "mythdirs.h"
     16#include "mythverbose.h"
     17#include "mythversion.h"
    3218
    33 #include "libmythtv/dbcheck.h"
    34 #include "libmythtv/videosource.h"
    35 #include "libmythtv/channeleditor.h"
    36 #include "libmythtv/remoteutil.h"
    37 #include "backendsettings.h"
    38 #include "checksetup.h"
     19#include "setupdialog.h"
    3920
    4021using namespace std;
    4122
    42 void SetupMenuCallback ( void* data, QString& selection )
    43 {
    44     (void)data;
    45 
    46     QString sel = selection.toLower();
    47 
    48     if ( sel == "general" )
    49     {
    50         BackendSettings be;
    51         be.exec();
    52     }
    53     else if ( sel == "capture cards" )
    54     {
    55         CaptureCardEditor cce;
    56         cce.exec();
    57     }
    58     else if ( sel == "video sources" )
    59     {
    60         VideoSourceEditor vse;
    61         vse.exec();
    62     }
    63     else if ( sel == "card inputs" )
    64     {
    65         CardInputEditor cie;
    66         cie.exec();
    67     }
    68     else if ( sel == "channel editor" )
    69     {
    70         ChannelEditor ce;
    71         ce.exec();
    72     }
    73     else if ( sel == "storage groups" )
    74     {
    75         StorageGroupListEditor sge;
    76         sge.exec();
    77     }
    78 }
    79 
    80 void SetupMenu(MythMainWindow *win)
    81 {
    82     QString theme = gContext->GetSetting("Theme", "blue");
    83 
    84     MythThemedMenu* menu = new MythThemedMenu(GetMythUI()->FindThemeDir(theme),
    85                                               "setup.xml", win->GetMainStack(),
    86                                               "mainmenu", false);
    87 
    88     menu->setCallback(SetupMenuCallback, gContext);
    89     menu->setKillable();
    90 
    91     if ( menu->foundTheme() )
    92     {
    93         win->GetMainStack()->AddScreen(menu);
    94         qApp->exec();
    95     }
    96     else
    97     {
    98         VERBOSE(VB_IMPORTANT, QString("Couldn't find theme '%1'").arg(theme));
    99     }
    100 }
    101 
    10223int main(int argc, char *argv[])
    10324{
    10425    QString geometry = QString::null;
     
    310231    LanguageSettings::prompt();
    311232    LanguageSettings::load("mythfrontend");
    312233
    313     QString warn =
    314         QObject::tr("WARNING") + ": " +
    315         QObject::tr("MythTV has detected that the backend is running.")+"\n\n"+
    316         QObject::tr("Changing existing card inputs, deleting anything, "
    317                     "or scanning for channels may not work.");
    318 
    319     bool backendIsRunning = gContext->BackendIsRunning();
    320 
    321     if (backendIsRunning)
    322     {
    323         DialogCode val = MythPopupBox::Show2ButtonPopup(
    324             mainWindow, QObject::tr("WARNING"), warn,
    325             QObject::tr("Continue"),
    326             QObject::tr("Exit"), kDialogCodeButton0);
    327 
    328         if (kDialogCodeButton1 == val)
    329         {
    330             delete gContext;
    331             return GENERIC_EXIT_OK;
    332         }
    333     }
    334 
    335234    REG_KEY("qt", "DELETE", "Delete", "D");
    336235    REG_KEY("qt", "EDIT", "Edit", "E");
    337236
    338     DialogBox *dia = NULL;
    339     bool haveProblems = false;
    340     do
    341     {
    342         // Let the user select buttons, type values, scan for channels, etc.
    343         SetupMenu(mainWindow);
     237    MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
    344238
    345         // Look for common problems
    346         QString *problems = new QString("");
    347         haveProblems = CheckSetup(problems);
     239    SetupDialog *setup = new SetupDialog(mainStack, "mythtv-setup");
    348240
    349         if (haveProblems)
    350         {
    351             QString prompt;
    352 
    353             if (problems->count("\n") > 1)
    354                 prompt = QObject::tr("Do you want to fix these problems?");
    355             else
    356                 prompt = QObject::tr("Do you want to fix this problem?");
    357 
    358             dia = new DialogBox(mainWindow, problems->append("\n" + prompt));
    359             dia->AddButton(QObject::tr("Yes please"));
    360             dia->AddButton(QObject::tr("No, I know what I am doing"));
    361 
    362             if (kDialogCodeButton1 == dia->exec())
    363                 haveProblems = false;
    364             dia->deleteLater();
    365         }
    366 
    367         delete problems;
    368 
    369     // Execute UI again until there are no more problems:
    370     }
    371     while (haveProblems);
    372 
    373     if (gContext->IsMasterHost())
     241    setup->Start();
     242   
     243    do
    374244    {
    375         dia = new DialogBox(mainWindow,
    376                             QObject::tr("If this is the master backend server, "
    377                                         "please run 'mythfilldatabase' "
    378                                         "to populate the database "
    379                                         "with channel information."));
    380         dia->AddButton(QObject::tr("OK"));
    381         dia->exec();
    382         dia->deleteLater();
    383     }
     245        qApp->exec();
     246        setup->ShowExitMenu();
     247    } while (!setup->Terminate());
    384248
    385     if (backendIsRunning)
    386         RemoteSendMessage("CLEAR_SETTINGS_CACHE");
    387 
    388249    delete gContext;
    389250
    390251    return GENERIC_EXIT_OK;
  • mythtv/programs/mythtv-setup/setupdialog.h

     
     1#ifndef SETUPDIALOG_H_
     2#define SETUPDIALOG_H_
     3
     4// qt
     5
     6// myth
     7#include "mythscreentype.h"
     8#include "mythdialogbox.h"
     9
     10class SetupDialog : public MythScreenType
     11{
     12
     13  Q_OBJECT
     14
     15  public:
     16
     17    SetupDialog(MythScreenStack *parent, const char *name);
     18    ~SetupDialog();
     19
     20    void Start(void);
     21    void ShowExitMenu(void);
     22    bool Terminate(void);
     23
     24  protected slots:
     25    void CloseDialog(void);
     26    void StopBackend(void);
     27    void ContinueWithBackendRunning(void);
     28
     29  private:
     30
     31    MythDialogBox *m_menuPopup;
     32    bool m_restartBackend; // true if the backend should be restarted on exit
     33    bool m_haveProblems; // true if problems were encountered in checksetup
     34    bool m_terminate; // true if mythtv-setup has finished and should terminate
     35
     36    void ShowSetupMenu(void);
     37    void ShowBackendMenu(void);
     38
     39
     40
     41};
     42
     43#endif
  • mythtv/programs/mythtv-setup/mythtv-setup.pro

     
    1919QMAKE_CLEAN += $(TARGET)
    2020
    2121# Input
    22 HEADERS += backendsettings.h
    23 SOURCES += backendsettings.cpp checksetup.cpp main.cpp
     22HEADERS += backendsettings.h setupdialog.h
     23SOURCES += backendsettings.cpp checksetup.cpp main.cpp setupdialog.cpp
    2424
    2525macx {
    2626    mac_bundle {