00001 #include <QCoreApplication>
00002
00003
00004 #include "exitcodes.h"
00005 #include "mythcorecontext.h"
00006 #include "mythdialogbox.h"
00007 #include "mythmainwindow.h"
00008 #include "mythscreenstack.h"
00009 #include "remoteutil.h"
00010 #include "mythsystem.h"
00011
00012 #include "checksetup.h"
00013 #include "exitprompt.h"
00014
00015 struct ExitPrompterPrivate
00016 {
00017 ExitPrompterPrivate()
00018 {
00019 stk = GetMythMainWindow()->GetStack("popup stack");
00020 }
00021
00022 MythScreenStack *stk;
00023 };
00024
00025 ExitPrompter::ExitPrompter()
00026 {
00027 m_d = new ExitPrompterPrivate;
00028 }
00029
00030 ExitPrompter::~ExitPrompter()
00031 {
00032 delete m_d;
00033 }
00034
00035 void ExitPrompter::masterPromptExit()
00036 {
00037 if (gCoreContext->IsMasterHost() && needsMFDBReminder())
00038 {
00039 QString label = tr("If you've added or altered channels,"
00040 " please run 'mythfilldatabase' on the"
00041 " master backend to populate the"
00042 " database with guide information.");
00043
00044 MythConfirmationDialog *dia = new MythConfirmationDialog(m_d->stk,
00045 label,
00046 false);
00047 if (!dia->Create())
00048 {
00049 LOG(VB_GENERAL, LOG_ERR, "Can't create fill DB prompt?");
00050 delete dia;
00051 quit();
00052 }
00053 else
00054 {
00055 dia->SetReturnEvent(this, "mythfillprompt");
00056 m_d->stk->AddScreen(dia);
00057 }
00058 }
00059 else
00060 quit();
00061 }
00062
00063 void ExitPrompter::handleExit()
00064 {
00065 QStringList problems;
00066
00067
00068 if (CheckSetup(problems))
00069 {
00070 problems.push_back(QString());
00071 problems.push_back(tr("Do you want to go back and fix this(these) "
00072 "problem(s)?", 0, problems.size()));
00073
00074 MythDialogBox *dia = new MythDialogBox(problems.join("\n"),
00075 m_d->stk, "exit prompt");
00076 if (!dia->Create())
00077 {
00078 LOG(VB_GENERAL, LOG_ERR, "Can't create Exit Prompt dialog?");
00079 delete dia;
00080 quit();
00081 }
00082
00083 dia->SetReturnEvent(this, "problemprompt");
00084
00085 dia->AddButton(tr("Yes please"));
00086 dia->AddButton(tr("No, I know what I am doing"),
00087 SLOT(masterPromptExit()));
00088
00089 m_d->stk->AddScreen(dia);
00090 }
00091 else
00092 masterPromptExit();
00093 }
00094
00095 void ExitPrompter::customEvent(QEvent *event)
00096 {
00097 if (event->type() == DialogCompletionEvent::kEventType)
00098 {
00099 DialogCompletionEvent *dce = (DialogCompletionEvent*)(event);
00100
00101 QString resultid= dce->GetId();
00102 int buttonnum = dce->GetResult();
00103
00104 if (resultid == "mythfillprompt")
00105 {
00106 quit();
00107 }
00108 else if (resultid == "problemprompt")
00109 {
00110 switch (buttonnum)
00111 {
00112 case 0 :
00113 break;
00114 case 1 :
00115 masterPromptExit();
00116 break;
00117 }
00118 }
00119 }
00120 }
00121
00122 void ExitPrompter::quit()
00123 {
00124
00125 if (gCoreContext->GetSetting("AutoRestartBackend") == "1")
00126 {
00127 QString commandString = gCoreContext->GetSetting("BackendStartCommand");
00128 if (!commandString.isEmpty())
00129 {
00130 LOG(VB_GENERAL, LOG_ERR, "backendrestart"+commandString);
00131 myth_system(commandString);
00132 }
00133 }
00134 else
00135 {
00136
00137 if (gCoreContext->BackendIsRunning())
00138 {
00139 gCoreContext->SendMessage("CLEAR_SETTINGS_CACHE");
00140 }
00141 }
00142
00143 qApp->exit(GENERIC_EXIT_OK);
00144 }