MythTV  master
mythtv-setup/exitprompt.cpp
Go to the documentation of this file.
1 #include <QCoreApplication>
2 
3 // MythTV stuff
4 #include "exitcodes.h"
5 #include "mythcorecontext.h"
6 #include "mythdialogbox.h"
7 #include "mythmainwindow.h"
8 #include "mythscreenstack.h"
9 #include "remoteutil.h"
10 #include "mythsystemlegacy.h"
11 
12 #include "checksetup.h"
13 #include "exitprompt.h"
14 
16 {
18  {
19  stk = GetMythMainWindow()->GetStack("popup stack");
20  }
21 
23 };
24 
26 {
28 }
29 
31 {
32  delete m_d;
33 }
34 
36 {
38  {
39  QString label = tr("If you've added or altered channels,"
40  " please run 'mythfilldatabase' on the"
41  " master backend to populate the"
42  " database with guide information.");
43 
45  label,
46  false);
47  if (!dia->Create())
48  {
49  LOG(VB_GENERAL, LOG_ERR, "Can't create fill DB prompt?");
50  delete dia;
51  quit();
52  }
53  else
54  {
55  dia->SetReturnEvent(this, "mythfillprompt");
56  m_d->stk->AddScreen(dia);
57  }
58  }
59  else
60  quit();
61 }
62 
64 {
65  QStringList problems;
66 
67  // Look for common problems
68  if (CheckSetup(problems))
69  {
70  problems.push_back(QString());
71  problems.push_back(tr("Do you want to go back and fix this(these) "
72  "problem(s)?", nullptr, problems.size()));
73 
74  MythDialogBox *dia = new MythDialogBox(problems.join("\n"),
75  m_d->stk, "exit prompt");
76  if (!dia->Create())
77  {
78  LOG(VB_GENERAL, LOG_ERR, "Can't create Exit Prompt dialog?");
79  delete dia;
80  quit();
81  return;
82  }
83 
84  dia->SetReturnEvent(this, "problemprompt");
85 
86  dia->AddButton(tr("Yes please"));
87  dia->AddButton(tr("No, I know what I am doing"),
88  SLOT(masterPromptExit()));
89 
90  m_d->stk->AddScreen(dia);
91  }
92  else
94 }
95 
96 void ExitPrompter::customEvent(QEvent *event)
97 {
98  if (event->type() == DialogCompletionEvent::kEventType)
99  {
101 
102  QString resultid= dce->GetId();
103  int buttonnum = dce->GetResult();
104 
105  if (resultid == "mythfillprompt")
106  {
107  quit();
108  }
109  else if (resultid == "problemprompt")
110  {
111  switch (buttonnum)
112  {
113  case 0 :
114  break;
115  case 1 :
117  break;
118  }
119  }
120  }
121 }
122 
123 void ExitPrompter::quit()
124 {
125  // If the backend was stopped restart it here
126  if (gCoreContext->GetSetting("AutoRestartBackend") == "1")
127  {
128  QString commandString = gCoreContext->GetSetting("BackendStartCommand");
129  if (!commandString.isEmpty())
130  {
131  LOG(VB_GENERAL, LOG_ERR, "backendrestart"+commandString);
132  myth_system(commandString);
133  }
134  }
135  else
136  {
137  // No need to run this if the backend has just restarted
139  {
140  gCoreContext->SendMessage("CLEAR_SETTINGS_CACHE");
141  }
142  }
143 
144  qApp->exit(GENERIC_EXIT_OK);
145 }
bool CheckSetup(QStringList &problems)
Build up a string of common problems that the user should correct in the MythTV-Setup program.
Definition: checksetup.cpp:242
Dialog asking for user confirmation.
#define GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:10
Basic menu dialog, message and a list of options.
MythScreenStack * GetStack(const QString &stackname)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
static void quit(void)
static Type kEventType
Definition: mythdialogbox.h:50
void SendMessage(const QString &message)
void AddButton(const QString &title, QVariant data=0, bool newMenu=false, bool setCurrent=false)
bool needsMFDBReminder()
Definition: checksetup.cpp:249
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
QString GetSetting(const QString &key, const QString &defaultval="")
static bool BackendIsRunning(void)
a backend process is running on this host
void SetReturnEvent(QObject *retobject, const QString &resultid)
uint myth_system(const QString &command, uint flags, uint timeout)
bool IsMasterHost(void)
is this the same host as the master
MythMainWindow * GetMythMainWindow(void)
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
bool Create(void) override
void SetReturnEvent(QObject *retobject, const QString &resultid)
void customEvent(QEvent *event) override
Event dispatched from MythUI modal dialogs to a listening class containing a result of some form.
Definition: mythdialogbox.h:37
bool Create(void) override
struct ExitPrompterPrivate * m_d