MythTV  master
mythtv-setup/exitprompt.cpp
Go to the documentation of this file.
1 // Qt
2 #include <QCoreApplication>
3 
4 // MythTV stuff
12 
13 // MythTV Setup
14 #include "checksetup.h"
15 #include "exitprompt.h"
16 
18 {
20  {
21  m_stk = GetMythMainWindow()->GetStack("popup stack");
22  }
23 
25 };
26 
28 {
30 }
31 
33 {
34  delete m_d;
35 }
36 
38 {
40  {
41  QString label = tr("If you've added or altered channels,"
42  " please run 'mythfilldatabase' on the"
43  " master backend to populate the"
44  " database with guide information.");
45 
46  auto *dia = new MythConfirmationDialog(m_d->m_stk, label, 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->m_stk->AddScreen(dia);
57  }
58  }
59  else
60  quit();
61 }
62 
64 {
65  QStringList allproblems;
66 
67  // Look for common problems
68  if (CheckSetup(allproblems))
69  {
70  // Only report the first 4 problems
71  QStringList problems;
72 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
73  int limit = std::min(4, allproblems.size());
74 #else
75  int limit = std::min(4LL, allproblems.size());
76 #endif
77  for (int i = 0; i < limit; ++i)
78  {
79  problems.push_back(allproblems[i]);
80  }
81  if (problems.size() < allproblems.size())
82  {
83  problems.push_back(tr("...and more..."));
84  }
85  else
86  {
87  problems.push_back(QString());
88  }
89 
90  problems.push_back(tr("Do you want to go back and fix this(these) "
91  "problem(s)?", nullptr, problems.size()));
92 
93  auto *dia = new MythDialogBox(tr("Configuration Problems"), problems.join("\n"),
94  m_d->m_stk, "exit prompt", true);
95  if (!dia->Create())
96  {
97  LOG(VB_GENERAL, LOG_ERR, "Can't create Exit Prompt dialog?");
98  delete dia;
99  quit();
100  return;
101  }
102 
103  dia->SetReturnEvent(this, "problemprompt");
104 
105  dia->AddButton(tr("Yes please"));
106  dia->AddButton(tr("No, I know what I am doing"),
108 
109  m_d->m_stk->AddScreen(dia);
110  }
111  else
113 }
114 
115 void ExitPrompter::customEvent(QEvent *event)
116 {
117  if (event->type() == DialogCompletionEvent::kEventType)
118  {
119  auto *dce = (DialogCompletionEvent*)(event);
120 
121  QString resultid= dce->GetId();
122  int buttonnum = dce->GetResult();
123 
124  if (resultid == "mythfillprompt")
125  {
126  quit();
127  }
128  else if (resultid == "problemprompt")
129  {
130  switch (buttonnum)
131  {
132  case 0 :
133  break;
134  case 1 :
136  break;
137  }
138  }
139  }
140 }
141 
143 {
144  // If the backend was stopped restart it here
145  if (gCoreContext->GetSetting("AutoRestartBackend") == "1")
146  {
147  QString commandString = gCoreContext->GetSetting("BackendStartCommand");
148  if (!commandString.isEmpty())
149  {
150  LOG(VB_GENERAL, LOG_ERR, "backendrestart"+commandString);
151  myth_system(commandString);
152  }
153  }
154  else
155  {
156  // No need to run this if the backend has just restarted
158  {
159  gCoreContext->SendMessage("CLEAR_SETTINGS_CACHE");
160  }
161  }
162 
163  qApp->exit(GENERIC_EXIT_OK);
164 }
MythCoreContext::SendMessage
void SendMessage(const QString &message)
Definition: mythcorecontext.cpp:1517
ExitPrompter::m_d
struct ExitPrompterPrivate * m_d
Definition: mythtv-setup/exitprompt.h:29
mythscreenstack.h
mythdialogbox.h
MythScreenStack
Definition: mythscreenstack.h:16
checksetup.h
needsMFDBReminder
bool needsMFDBReminder()
Definition: checksetup.cpp:293
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
ExitPrompter::~ExitPrompter
~ExitPrompter() override
Definition: mythfrontend/exitprompt.cpp:27
myth_system
uint myth_system(const QString &command, uint flags, std::chrono::seconds timeout)
Definition: mythsystemlegacy.cpp:506
GENERIC_EXIT_OK
@ GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:11
remoteutil.h
mythsystemlegacy.h
ExitPrompter::customEvent
void customEvent(QEvent *event) override
Definition: mythtv-setup/exitprompt.cpp:115
CheckSetup
bool CheckSetup(QStringList &problems)
Build up a string of common problems that the user should correct in the MythTV-Setup program.
Definition: checksetup.cpp:285
MythCoreContext::BackendIsRunning
static bool BackendIsRunning(void)
a backend process is running on this host
Definition: mythcorecontext.cpp:700
MythDialogBox
Basic menu dialog, message and a list of options.
Definition: mythdialogbox.h:166
ExitPrompterPrivate
Definition: mythtv-setup/exitprompt.cpp:17
ExitPrompter::handleExit
void handleExit(void)
Definition: mythtv-setup/exitprompt.cpp:63
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:55
ExitPrompterPrivate::ExitPrompterPrivate
ExitPrompterPrivate()
Definition: mythtv-setup/exitprompt.cpp:19
MythConfirmationDialog
Dialog asking for user confirmation. Ok and optional Cancel button.
Definition: mythdialogbox.h:272
mythcorecontext.h
DialogCompletionEvent
Event dispatched from MythUI modal dialogs to a listening class containing a result of some form.
Definition: mythdialogbox.h:41
DialogCompletionEvent::kEventType
static const Type kEventType
Definition: mythdialogbox.h:57
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:104
ExitPrompter::masterPromptExit
void masterPromptExit(void)
Definition: mythtv-setup/exitprompt.cpp:37
MythMainWindow::GetStack
MythScreenStack * GetStack(const QString &Stackname)
Definition: mythmainwindow.cpp:323
ExitPrompterPrivate::m_stk
MythScreenStack * m_stk
Definition: mythtv-setup/exitprompt.cpp:24
MythCoreContext::IsMasterHost
bool IsMasterHost(void)
is this the same host as the master
Definition: mythcorecontext.cpp:659
exitcodes.h
mythmainwindow.h
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:52
ExitPrompter::ExitPrompter
ExitPrompter()
Definition: mythfrontend/exitprompt.cpp:16
exitprompt.h
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:898
ExitPrompter::quit
static void quit(void)
Definition: mythtv-setup/exitprompt.cpp:142