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