MythTV  master
guistartup.cpp
Go to the documentation of this file.
1 // 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 "mythcorecontext.h"
38 #include "mythstorage.h"
39 #include "mythdirs.h"
40 #include "mythlogging.h"
41 #include "mythlocale.h"
42 #include "mythtranslation.h"
43 #include "iso3166.h"
44 #include "iso639.h"
45 #include "mythtimer.h"
46 
47 // libmythui
48 #include "mythuibuttonlist.h"
49 #include "mythuibutton.h"
50 #include "mythmainwindow.h"
51 #include "mythscreenstack.h"
52 #include "mythuistatetype.h"
53 #include "mythuiprogressbar.h"
54 #include "mythdialogbox.h"
55 
56 #include "guistartup.h"
57 
58 using namespace std::chrono_literals;
59 
60 GUIStartup::GUIStartup(MythScreenStack *parent, QEventLoop *eventLoop)
61  :MythScreenType(parent, "GUIStartup"),
62  m_loop(eventLoop),
63  m_dlgLoop(this)
64 {
65 }
66 
68 {
69  delete m_progressTimer;
70 }
71 
73 {
74  if (!LoadWindowFromXML("config-ui.xml", "guistartup", this))
75  return false;
76 
77  bool err = false;
78  UIUtilE::Assign(this, m_dummyButton, "dummy", &err);
79  if (!err)
80  UIUtilE::Assign(this, m_retryButton, "retry", &err);
81  if (!err)
82  UIUtilE::Assign(this, m_searchButton, "search", &err);
83  if (!err)
84  UIUtilE::Assign(this, m_setupButton, "setup", &err);
85  if (!err)
86  UIUtilE::Assign(this, m_exitButton, "exit", &err);
87  if (!err)
88  UIUtilE::Assign(this, m_statusState, "statusstate", &err);
89  if (!err)
90  UIUtilE::Assign(this, m_progressBar, "progress", &err);
91  if (!err)
92  UIUtilE::Assign(this, m_messageState, "messagestate", &err);
93 
94  if (err)
95  {
96  LOG(VB_GENERAL, LOG_ALERT,
97  "Cannot load screen 'guistartup'");
98  return false;
99  }
100 
105  connect(&m_timer, &QTimer::timeout, this, qOverload<>(&GUIStartup::updateProgress));
106 
107  BuildFocusList();
108 
109  return true;
110 }
111 
112 bool GUIStartup::setStatusState(const QString &name)
113 {
114  bool ret = m_statusState->DisplayState(name);
115  m_Exit = false;
116  m_Setup = false;
117  m_Search = false;
118  m_Retry = false;
119  return ret;
120 }
121 
122 bool GUIStartup::setMessageState(const QString &name)
123 {
124  bool ret = m_messageState->DisplayState(name);
125  m_Exit = false;
126  m_Setup = false;
127  m_Search = false;
128  m_Retry = false;
129  return ret;
130 }
131 
132 
133 void GUIStartup::setTotal(int total)
134 {
135  delete m_progressTimer;
137  m_timer.start(500ms);
138  m_total = total*1000;
141 
142  m_Exit = false;
143  m_Setup = false;
144  m_Search = false;
145  m_Retry = false;
146 }
147 
148 // return = true if time is up
149 bool GUIStartup::updateProgress(bool finished)
150 {
151  if (m_progressTimer)
152  {
153  int elapsed = 0;
154  if (finished)
155  elapsed = m_total;
156  else
157  elapsed = m_progressTimer->elapsed();
158  m_progressBar->SetUsed(elapsed);
159  if (elapsed >= m_total)
160  {
161  m_timer.stop();
162  emit cancelPortCheck();
163  delete m_progressTimer;
164  m_progressTimer = nullptr;
165  }
166  return elapsed >= m_total;
167  }
168  m_timer.stop();
169  return false;
170 }
171 
173 {
174  updateProgress(false);
175 }
176 
178 {
179  int elapsed = 0;
180  if (m_progressTimer)
181  {
182  elapsed = m_progressTimer->elapsed();
184  m_timer.stop();
185  }
186  QString message = tr("Do you really want to exit MythTV?");
187  MythScreenStack *popupStack
188  = GetMythMainWindow()->GetStack("popup stack");
189  auto *confirmdialog = new MythConfirmationDialog(popupStack, message);
190 
191  if (confirmdialog->Create())
192  popupStack->AddScreen(confirmdialog);
193 
194  connect(confirmdialog, &MythConfirmationDialog::haveResult,
196 
197  m_dlgLoop.exec();
198 
199  if (m_progressTimer && !m_Exit)
200  {
202  m_progressTimer->addMSecs(elapsed);
203  m_timer.start();
204  }
205 }
206 
208 {
209  if (m_dlgLoop.isRunning())
210  m_dlgLoop.exit();
211 
212  if (submit)
213  {
214  if (m_loop->isRunning())
215  m_loop->exit();
216  m_Exit = true;
217  emit cancelPortCheck();
219  }
220 }
221 
223 {
224  m_Retry = true;
225  emit cancelPortCheck();
226  if (m_loop->isRunning())
227  m_loop->exit();
228 }
229 
231 {
232  m_Search = true;
233  emit cancelPortCheck();
234  if (m_loop->isRunning())
235  m_loop->exit();
236 }
237 
239 {
240  m_Setup = true;
241  emit cancelPortCheck();
242  if (m_loop->isRunning())
243  m_loop->exit();
244 }
245 
GUIStartup::m_progressTimer
MythTimer * m_progressTimer
Definition: guistartup.h:89
GUIStartup::setTotal
void setTotal(int total)
Definition: guistartup.cpp:133
MythUIButton::Clicked
void Clicked()
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:103
GUIStartup::Create
bool Create(void) override
Definition: guistartup.cpp:72
mythuiprogressbar.h
GUIStartup::m_dummyButton
MythUIButton * m_dummyButton
Definition: guistartup.h:81
MythTimer
A QElapsedTimer based timer to replace use of QTime as a timer.
Definition: mythtimer.h:13
MythScreenType::Close
virtual void Close()
Definition: mythscreentype.cpp:402
MythTimer::addMSecs
void addMSecs(int ms)
Adds an offset to the last call to start() or restart().
Definition: mythtimer.cpp:145
mythscreenstack.h
MythConfirmationDialog::haveResult
void haveResult(bool)
MythUIProgressBar::SetUsed
void SetUsed(int value)
Definition: mythuiprogressbar.cpp:59
mythdialogbox.h
MythScreenStack
Definition: mythscreenstack.h:15
MythTimer::stop
void stop(void)
Stops timer, next call to isRunning() will return false and any calls to elapsed() or restart() will ...
Definition: mythtimer.cpp:77
GUIStartup::Close
void Close(void) override
Definition: guistartup.cpp:177
MythTimer::start
void start(void)
starts measuring elapsed time.
Definition: mythtimer.cpp:47
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
MythScreenType
Screen in which all other widgets are contained and rendered.
Definition: mythscreentype.h:44
mythuistatetype.h
GUIStartup::m_dlgLoop
QEventLoop m_dlgLoop
Definition: guistartup.h:91
mythdirs.h
GUIStartup::m_setupButton
MythUIButton * m_setupButton
Definition: guistartup.h:84
mythuibuttonlist.h
GUIStartup::m_Search
bool m_Search
Definition: guistartup.h:57
langsettings.h
MythUIProgressBar::SetTotal
void SetTotal(int value)
Definition: mythuiprogressbar.cpp:71
guistartup.h
mythlogging.h
GUIStartup::m_total
int m_total
Definition: guistartup.h:92
MythScreenType::SetFocusWidget
bool SetFocusWidget(MythUIType *widget=nullptr)
Definition: mythscreentype.cpp:117
GUIStartup::m_messageState
MythUIStateType * m_messageState
Definition: guistartup.h:87
MythScreenType::BuildFocusList
void BuildFocusList(void)
Definition: mythscreentype.cpp:222
GUIStartup::OnClosePromptReturn
void OnClosePromptReturn(bool submit)
Definition: guistartup.cpp:207
GUIStartup::GUIStartup
GUIStartup(MythScreenStack *parent, QEventLoop *eventLoop)
Definition: guistartup.cpp:60
GUIStartup::m_statusState
MythUIStateType * m_statusState
Definition: guistartup.h:86
mythtranslation.h
mythlocale.h
UIUtilDisp::Assign
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition: mythuiutils.h:27
GUIStartup::m_progressBar
MythUIProgressBar * m_progressBar
Definition: guistartup.h:88
GUIStartup::m_searchButton
MythUIButton * m_searchButton
Definition: guistartup.h:83
MythTimer::elapsed
int elapsed(void)
Returns milliseconds elapsed since last start() or restart()
Definition: mythtimer.cpp:90
GUIStartup::m_Retry
bool m_Retry
Definition: guistartup.h:56
GUIStartup::Setup
void Setup(void)
Definition: guistartup.cpp:238
GUIStartup::Search
void Search(void)
Definition: guistartup.cpp:230
GUIStartup::setMessageState
bool setMessageState(const QString &name)
Definition: guistartup.cpp:122
GUIStartup::setStatusState
bool setStatusState(const QString &name)
Definition: guistartup.cpp:112
GUIStartup::m_loop
QEventLoop * m_loop
Definition: guistartup.h:90
MythTimer::kStartRunning
@ kStartRunning
Definition: mythtimer.h:17
MythConfirmationDialog
Dialog asking for user confirmation. Ok and optional Cancel button.
Definition: mythdialogbox.h:271
mythcorecontext.h
XMLParseBase::LoadWindowFromXML
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
Definition: xmlparsebase.cpp:692
GUIStartup::~GUIStartup
~GUIStartup(void) override
Definition: guistartup.cpp:67
iso3166.h
ISO 3166-1 support functions.
GUIStartup::updateProgress
void updateProgress(void)
Definition: guistartup.cpp:172
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:104
GUIStartup::m_exitButton
MythUIButton * m_exitButton
Definition: guistartup.h:85
mythuibutton.h
mythtimer.h
MythMainWindow::GetStack
MythScreenStack * GetStack(const QString &Stackname)
Definition: mythmainwindow.cpp:320
iso639.h
ISO 639-1 and ISO 639-2 support functions.
GUIStartup::m_Setup
bool m_Setup
Definition: guistartup.h:55
mythstorage.h
GUIStartup::Retry
void Retry(void)
Definition: guistartup.cpp:222
mythmainwindow.h
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:52
GUIStartup::m_timer
QTimer m_timer
Definition: guistartup.h:93
GUIStartup::m_retryButton
MythUIButton * m_retryButton
Definition: guistartup.h:82
MythUIStateType::DisplayState
bool DisplayState(const QString &name)
Definition: mythuistatetype.cpp:84
GUIStartup::cancelPortCheck
void cancelPortCheck(void)
GUIStartup::m_Exit
bool m_Exit
Definition: guistartup.h:54