MythTV master
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 : m_d(new ExitPrompterPrivate)
29{
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 {
61 quit();
62 }
63}
64
66{
67 QStringList allproblems;
68
69 // Look for common problems
70 if (CheckSetup(allproblems))
71 {
72 // Only report the first 4 problems
73 QStringList problems;
74#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
75 int limit = std::min(4, allproblems.size());
76#else
77 int limit = std::min(static_cast<qsizetype>(4), allproblems.size());
78#endif
79 for (int i = 0; i < limit; ++i)
80 {
81 problems.push_back(allproblems[i]);
82 }
83 if (problems.size() < allproblems.size())
84 {
85 problems.push_back(tr("...and more..."));
86 }
87 else
88 {
89 problems.push_back(QString());
90 }
91
92 problems.push_back(tr("Do you want to go back and fix this(these) "
93 "problem(s)?", nullptr, problems.size()));
94
95 auto *dia = new MythDialogBox(tr("Configuration Problems"), problems.join("\n"),
96 m_d->m_stk, "exit prompt", true);
97 if (!dia->Create())
98 {
99 LOG(VB_GENERAL, LOG_ERR, "Can't create Exit Prompt dialog?");
100 delete dia;
101 quit();
102 return;
103 }
104
105 dia->SetReturnEvent(this, "problemprompt");
106
107 dia->AddButton(tr("Yes please"));
108 dia->AddButton(tr("No, I know what I am doing"),
110
111 m_d->m_stk->AddScreen(dia);
112 }
113 else
114 {
116 }
117}
118
119void ExitPrompter::customEvent(QEvent *event)
120{
121 if (event->type() == DialogCompletionEvent::kEventType)
122 {
123 auto *dce = (DialogCompletionEvent*)(event);
124
125 QString resultid= dce->GetId();
126 int buttonnum = dce->GetResult();
127
128 if (resultid == "mythfillprompt")
129 {
130 quit();
131 }
132 else if (resultid == "problemprompt")
133 {
134 switch (buttonnum)
135 {
136 case 0 :
137 break;
138 case 1 :
140 break;
141 }
142 }
143 }
144}
145
147{
148 // If the backend was stopped restart it here
149 if (gCoreContext->GetSetting("AutoRestartBackend") == "1")
150 {
151 QString commandString = gCoreContext->GetSetting("BackendStartCommand");
152 if (!commandString.isEmpty())
153 {
154 LOG(VB_GENERAL, LOG_ERR, "backendrestart"+commandString);
155 myth_system(commandString);
156 }
157 }
158 else
159 {
160 // No need to run this if the backend has just restarted
162 {
163 gCoreContext->SendMessage("CLEAR_SETTINGS_CACHE");
164 }
165 }
166
167 qApp->exit(GENERIC_EXIT_OK);
168}
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:37
void handleExit(void)
Definition: exitprompt.cpp:65
~ExitPrompter() override
Definition: exitprompt.cpp:28
struct ExitPrompterPrivate * m_d
Definition: exitprompt.h:32
void customEvent(QEvent *event) override
Definition: exitprompt.cpp:119
static void quit(void)
Definition: exitprompt.cpp:146
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:24