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// C++
26#include <chrono>
27
28// qt
29#include <QEventLoop>
30#include <QDir>
31#include <QFileInfo>
32
33// libmythbase
34#include "libmythbase/iso3166.h"
35#include "libmythbase/iso639.h"
42
43// libmythui
52
53#include "guistartup.h"
54
55GUIStartup::GUIStartup(MythScreenStack *parent, QEventLoop *eventLoop)
56 :MythScreenType(parent, "GUIStartup"),
57 m_loop(eventLoop),
58 m_dlgLoop(this)
59{
60}
61
63{
64 delete m_progressTimer;
65}
66
68{
69 if (!LoadWindowFromXML("config-ui.xml", "guistartup", this))
70 return false;
71
72 bool err = false;
73 UIUtilE::Assign(this, m_dummyButton, "dummy", &err);
74 if (!err)
75 UIUtilE::Assign(this, m_retryButton, "retry", &err);
76 if (!err)
77 UIUtilE::Assign(this, m_searchButton, "search", &err);
78 if (!err)
79 UIUtilE::Assign(this, m_setupButton, "setup", &err);
80 if (!err)
81 UIUtilE::Assign(this, m_exitButton, "exit", &err);
82 if (!err)
83 UIUtilE::Assign(this, m_statusState, "statusstate", &err);
84 if (!err)
85 UIUtilE::Assign(this, m_progressBar, "progress", &err);
86 if (!err)
87 UIUtilE::Assign(this, m_messageState, "messagestate", &err);
88
89 if (err)
90 {
91 LOG(VB_GENERAL, LOG_ALERT,
92 "Cannot load screen 'guistartup'");
93 return false;
94 }
95
100 connect(&m_timer, &QTimer::timeout, this, qOverload<>(&GUIStartup::updateProgress));
101
103
104 return true;
105}
106
107bool GUIStartup::setStatusState(const QString &name)
108{
109 bool ret = m_statusState->DisplayState(name);
110 m_Exit = false;
111 m_Setup = false;
112 m_Search = false;
113 m_Retry = false;
114 return ret;
115}
116
117bool GUIStartup::setMessageState(const QString &name)
118{
119 bool ret = m_messageState->DisplayState(name);
120 m_Exit = false;
121 m_Setup = false;
122 m_Search = false;
123 m_Retry = false;
124 return ret;
125}
126
127
128void GUIStartup::setTotal(std::chrono::seconds total)
129{
130 delete m_progressTimer;
132 m_timer.start(500ms);
133 m_total = total;
136
137 m_Exit = false;
138 m_Setup = false;
139 m_Search = false;
140 m_Retry = false;
141}
142
143// return = true if time is up
144bool GUIStartup::updateProgress(bool finished)
145{
146 if (m_progressTimer)
147 {
148 std::chrono::milliseconds elapsed { 0ms };
149 if (finished)
150 elapsed = m_total;
151 else
152 elapsed = m_progressTimer->elapsed();
153 m_progressBar->SetUsed(elapsed.count());
154 if (elapsed >= m_total)
155 {
156 m_timer.stop();
157 emit cancelPortCheck();
158 delete m_progressTimer;
159 m_progressTimer = nullptr;
160 }
161 return elapsed >= m_total;
162 }
163 m_timer.stop();
164 return false;
165}
166
168{
169 updateProgress(false);
170}
171
173{
174 std::chrono::milliseconds elapsed { 0ms };
175 if (m_progressTimer)
176 {
177 elapsed = m_progressTimer->elapsed();
179 m_timer.stop();
180 }
181 QString message = tr("Do you really want to exit MythTV?");
182 MythScreenStack *popupStack
183 = GetMythMainWindow()->GetStack("popup stack");
184 auto *confirmdialog = new MythConfirmationDialog(popupStack, message);
185
186 if (confirmdialog->Create())
187 popupStack->AddScreen(confirmdialog);
188
189 connect(confirmdialog, &MythConfirmationDialog::haveResult,
191
192 m_dlgLoop.exec();
193
194 if (m_progressTimer && !m_Exit)
195 {
197 m_progressTimer->addMSecs(elapsed);
198 m_timer.start();
199 }
200}
201
203{
204 if (m_dlgLoop.isRunning())
205 m_dlgLoop.exit();
206
207 if (submit)
208 {
209 if (m_loop->isRunning())
210 m_loop->exit();
211 m_Exit = true;
212 emit cancelPortCheck();
214 }
215}
216
218{
219 m_Retry = true;
220 emit cancelPortCheck();
221 if (m_loop->isRunning())
222 m_loop->exit();
223}
224
226{
227 m_Search = true;
228 emit cancelPortCheck();
229 if (m_loop->isRunning())
230 m_loop->exit();
231}
232
234{
235 m_Setup = true;
236 emit cancelPortCheck();
237 if (m_loop->isRunning())
238 m_loop->exit();
239}
240
MythTimer * m_progressTimer
Definition: guistartup.h:89
QEventLoop * m_loop
Definition: guistartup.h:90
bool setMessageState(const QString &name)
Definition: guistartup.cpp:117
MythUIStateType * m_statusState
Definition: guistartup.h:86
bool m_Retry
Definition: guistartup.h:56
void updateProgress(void)
Definition: guistartup.cpp:167
MythUIButton * m_dummyButton
Definition: guistartup.h:81
std::chrono::milliseconds m_total
Definition: guistartup.h:92
void Retry(void)
Definition: guistartup.cpp:217
bool setStatusState(const QString &name)
Definition: guistartup.cpp:107
QEventLoop m_dlgLoop
Definition: guistartup.h:91
MythUIStateType * m_messageState
Definition: guistartup.h:87
void Search(void)
Definition: guistartup.cpp:225
void cancelPortCheck(void)
MythUIButton * m_setupButton
Definition: guistartup.h:84
bool m_Search
Definition: guistartup.h:57
MythUIButton * m_retryButton
Definition: guistartup.h:82
void setTotal(std::chrono::seconds total)
Definition: guistartup.cpp:128
~GUIStartup(void) override
Definition: guistartup.cpp:62
bool Create(void) override
Definition: guistartup.cpp:67
MythUIButton * m_exitButton
Definition: guistartup.h:85
GUIStartup(MythScreenStack *parent, QEventLoop *eventLoop)
Definition: guistartup.cpp:55
bool m_Exit
Definition: guistartup.h:54
MythUIButton * m_searchButton
Definition: guistartup.h:83
void Close(void) override
Definition: guistartup.cpp:172
bool m_Setup
Definition: guistartup.h:55
QTimer m_timer
Definition: guistartup.h:93
MythUIProgressBar * m_progressBar
Definition: guistartup.h:88
void Setup(void)
Definition: guistartup.cpp:233
void OnClosePromptReturn(bool submit)
Definition: guistartup.cpp:202
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