00001
00002 #include <QCoreApplication>
00003
00004
00005 #include "exitcodes.h"
00006 #include "mythcorecontext.h"
00007 #include "mythdialogbox.h"
00008 #include "mythmainwindow.h"
00009 #include "mythscreenstack.h"
00010 #include "mythsystem.h"
00011 #include "tvremoteutil.h"
00012
00013 #include "startprompt.h"
00014
00015 struct StartPrompterPrivate
00016 {
00017 StartPrompterPrivate()
00018 {
00019 stk = GetMythMainWindow()->GetStack("popup stack");
00020 }
00021
00022 MythScreenStack *stk;
00023 };
00024
00025 StartPrompter::StartPrompter()
00026 {
00027 m_d = new StartPrompterPrivate;
00028 }
00029
00030 StartPrompter::~StartPrompter()
00031 {
00032 delete m_d;
00033 }
00034
00035 void StartPrompter::handleStart()
00036 {
00037
00038 if (gCoreContext->BackendIsRunning() && gCoreContext->IsMasterHost())
00039 {
00040 backendRunningPrompt();
00041 }
00042 }
00043
00044 void StartPrompter::leaveBackendRunning()
00045 {
00046 LOG(VB_GENERAL, LOG_INFO, "Continuing with backend running");
00047 gCoreContext->OverrideSettingForSession("AutoRestartBackend", "0");
00048 }
00049
00050 void StartPrompter::stopBackend()
00051 {
00052 LOG(VB_GENERAL, LOG_INFO, "Trying to stop backend");
00053
00054 QString commandString = gCoreContext->GetSetting("BackendStopCommand");
00055 if (!commandString.isEmpty())
00056 {
00057 myth_system(commandString);
00058 }
00059 gCoreContext->OverrideSettingForSession("AutoRestartBackend", "1");
00060 }
00061
00062 void StartPrompter::backendRunningPrompt(void)
00063 {
00064 bool backendIsRecording = false;
00065
00066 if (!gCoreContext->IsConnectedToMaster() &&
00067 gCoreContext->ConnectToMasterServer(false))
00068 {
00069 backendIsRecording = RemoteGetRecordingStatus(NULL, false);
00070 }
00071
00072 QString warning = tr("WARNING: The backend is currently running.")+"\n\n"+
00073 tr("Changing existing card inputs, deleting anything, "
00074 "or scanning for channels may not work.")+"\n\n";
00075 if (backendIsRecording)
00076 {
00077 warning += tr("Recording Status: RECORDING.")+"\n"+
00078 tr("If you stop the backend now these recordings will be stopped!");
00079 }
00080 else
00081 {
00082 warning += tr("Recording Status: None.");
00083 }
00084
00085 MythDialogBox *dia = new MythDialogBox(warning, m_d->stk, "actionmenu");
00086
00087 if (!dia->Create())
00088 {
00089 LOG(VB_GENERAL, LOG_ERR, "Can't create Prompt dialog?");
00090 delete dia;
00091 quit();
00092 }
00093
00094
00095 dia->SetReturnEvent(this, QString());
00096
00097 m_d->stk->AddScreen(dia);
00098
00099 QString commandString = gCoreContext->GetSetting("BackendStopCommand");
00100 if (!commandString.isEmpty())
00101 {
00102
00103 dia->AddButton(tr("Stop Backend and Continue"), SLOT(stopBackend()));
00104 }
00105 dia->AddButton(tr("Continue"), SLOT(leaveBackendRunning()));
00106 dia->AddButton(tr("Exit"), SLOT(quit()));
00107 }
00108
00109 void StartPrompter::quit()
00110 {
00111 qApp->exit(GENERIC_EXIT_OK);
00112 }