MythTV master
guistartup.cpp
Go to the documentation of this file.
1
2// Copyright (c) 2017 MythTV Developers <mythtv-dev@mythtv.org>
3//
4// This is part of MythTV (https://www.mythtv.org)
5//
6// This program is free software; you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation; either version 2 of the License, or
9// (at your option) any later version.
10//
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with this program; if not, write to the Free Software
18// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19//
20// You should have received a copy of the GNU General Public License
21// along with this program. If not, see <http://www.gnu.org/licenses/>.
22//
24
25
26#include "langsettings.h"
27
28// C++
29#include <chrono>
30
31// qt
32#include <QEventLoop>
33#include <QDir>
34#include <QFileInfo>
35
36// libmythbase
37#include "libmythbase/iso3166.h"
38#include "libmythbase/iso639.h"
45
46// libmythui
54
55#include "guistartup.h"
56
57GUIStartup::GUIStartup(MythScreenStack *parent, QEventLoop *eventLoop)
58 :MythScreenType(parent, "GUIStartup"),
59 m_loop(eventLoop),
60 m_dlgLoop(this)
61{
62}
63
65{
66 delete m_progressTimer;
67}
68
70{
71 if (!LoadWindowFromXML("config-ui.xml", "guistartup", this))
72 return false;
73
74 bool err = false;
75 UIUtilE::Assign(this, m_dummyButton, "dummy", &err);
76 if (!err)
77 UIUtilE::Assign(this, m_retryButton, "retry", &err);
78 if (!err)
79 UIUtilE::Assign(this, m_searchButton, "search", &err);
80 if (!err)
81 UIUtilE::Assign(this, m_setupButton, "setup", &err);
82 if (!err)
83 UIUtilE::Assign(this, m_exitButton, "exit", &err);
84 if (!err)
85 UIUtilE::Assign(this, m_statusState, "statusstate", &err);
86 if (!err)
87 UIUtilE::Assign(this, m_progressBar, "progress", &err);
88 if (!err)
89 UIUtilE::Assign(this, m_messageState, "messagestate", &err);
90
91 if (err)
92 {
93 LOG(VB_GENERAL, LOG_ALERT,
94 "Cannot load screen 'guistartup'");
95 return false;
96 }
97
102 connect(&m_timer, &QTimer::timeout, this, qOverload<>(&GUIStartup::updateProgress));
103
105
106 return true;
107}
108
109bool GUIStartup::setStatusState(const QString &name)
110{
111 bool ret = m_statusState->DisplayState(name);
112 m_Exit = false;
113 m_Setup = false;
114 m_Search = false;
115 m_Retry = false;
116 return ret;
117}
118
119bool GUIStartup::setMessageState(const QString &name)
120{
121 bool ret = m_messageState->DisplayState(name);
122 m_Exit = false;
123 m_Setup = false;
124 m_Search = false;
125 m_Retry = false;
126 return ret;
127}
128
129
130void GUIStartup::setTotal(std::chrono::seconds total)
131{
132 delete m_progressTimer;
134 m_timer.start(500ms);
135 m_total = total;
138
139 m_Exit = false;
140 m_Setup = false;
141 m_Search = false;
142 m_Retry = false;
143}
144
145// return = true if time is up
146bool GUIStartup::updateProgress(bool finished)
147{
148 if (m_progressTimer)
149 {
150 std::chrono::milliseconds elapsed { 0ms };
151 if (finished)
152 elapsed = m_total;
153 else
154 elapsed = m_progressTimer->elapsed();
155 m_progressBar->SetUsed(elapsed.count());
156 if (elapsed >= m_total)
157 {
158 m_timer.stop();
159 emit cancelPortCheck();
160 delete m_progressTimer;
161 m_progressTimer = nullptr;
162 }
163 return elapsed >= m_total;
164 }
165 m_timer.stop();
166 return false;
167}
168
170{
171 updateProgress(false);
172}
173
175{
176 std::chrono::milliseconds elapsed { 0ms };
177 if (m_progressTimer)
178 {
179 elapsed = m_progressTimer->elapsed();
181 m_timer.stop();
182 }
183 QString message = tr("Do you really want to exit MythTV?");
184 MythScreenStack *popupStack
185 = GetMythMainWindow()->GetStack("popup stack");
186 auto *confirmdialog = new MythConfirmationDialog(popupStack, message);
187
188 if (confirmdialog->Create())
189 popupStack->AddScreen(confirmdialog);
190
191 connect(confirmdialog, &MythConfirmationDialog::haveResult,
193
194 m_dlgLoop.exec();
195
196 if (m_progressTimer && !m_Exit)
197 {
199 m_progressTimer->addMSecs(elapsed);
200 m_timer.start();
201 }
202}
203
205{
206 if (m_dlgLoop.isRunning())
207 m_dlgLoop.exit();
208
209 if (submit)
210 {
211 if (m_loop->isRunning())
212 m_loop->exit();
213 m_Exit = true;
214 emit cancelPortCheck();
216 }
217}
218
220{
221 m_Retry = true;
222 emit cancelPortCheck();
223 if (m_loop->isRunning())
224 m_loop->exit();
225}
226
228{
229 m_Search = true;
230 emit cancelPortCheck();
231 if (m_loop->isRunning())
232 m_loop->exit();
233}
234
236{
237 m_Setup = true;
238 emit cancelPortCheck();
239 if (m_loop->isRunning())
240 m_loop->exit();
241}
242
MythTimer * m_progressTimer
Definition: guistartup.h:92
QEventLoop * m_loop
Definition: guistartup.h:93
bool setMessageState(const QString &name)
Definition: guistartup.cpp:119
MythUIStateType * m_statusState
Definition: guistartup.h:89
bool m_Retry
Definition: guistartup.h:59
void updateProgress(void)
Definition: guistartup.cpp:169
MythUIButton * m_dummyButton
Definition: guistartup.h:84
std::chrono::milliseconds m_total
Definition: guistartup.h:95
void Retry(void)
Definition: guistartup.cpp:219
bool setStatusState(const QString &name)
Definition: guistartup.cpp:109
QEventLoop m_dlgLoop
Definition: guistartup.h:94
MythUIStateType * m_messageState
Definition: guistartup.h:90
void Search(void)
Definition: guistartup.cpp:227
void cancelPortCheck(void)
MythUIButton * m_setupButton
Definition: guistartup.h:87
bool m_Search
Definition: guistartup.h:60
MythUIButton * m_retryButton
Definition: guistartup.h:85
void setTotal(std::chrono::seconds total)
Definition: guistartup.cpp:130
~GUIStartup(void) override
Definition: guistartup.cpp:64
bool Create(void) override
Definition: guistartup.cpp:69
MythUIButton * m_exitButton
Definition: guistartup.h:88
GUIStartup(MythScreenStack *parent, QEventLoop *eventLoop)
Definition: guistartup.cpp:57
bool m_Exit
Definition: guistartup.h:57
MythUIButton * m_searchButton
Definition: guistartup.h:86
void Close(void) override
Definition: guistartup.cpp:174
bool m_Setup
Definition: guistartup.h:58
QTimer m_timer
Definition: guistartup.h:96
MythUIProgressBar * m_progressBar
Definition: guistartup.h:91
void Setup(void)
Definition: guistartup.cpp:235
void OnClosePromptReturn(bool submit)
Definition: guistartup.cpp:204
Dialog asking for user confirmation.
MythScreenStack * GetStack(const QString &Stackname)
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Screen in which all other widgets are contained and rendered.
void BuildFocusList(void)
bool SetFocusWidget(MythUIType *widget=nullptr)
virtual void Close()
A QElapsedTimer based timer to replace use of QTime as a timer.
Definition: mythtimer.h:14
void addMSecs(std::chrono::milliseconds ms)
Adds an offset to the last call to start() or restart().
Definition: mythtimer.cpp:146
std::chrono::milliseconds elapsed(void)
Returns milliseconds elapsed since last start() or restart()
Definition: mythtimer.cpp:91
void stop(void)
Stops timer, next call to isRunning() will return false and any calls to elapsed() or restart() will ...
Definition: mythtimer.cpp:78
@ kStartRunning
Definition: mythtimer.h:17
void start(void)
starts measuring elapsed time.
Definition: mythtimer.cpp:47
void Clicked()
void SetUsed(int value)
void SetTotal(int value)
bool DisplayState(const QString &name)
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
ISO 3166-1 support functions.
ISO 639-1 and ISO 639-2 support functions.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythMainWindow * GetMythMainWindow(void)
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition: mythuiutils.h:27