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 "libmythbase/iso3166.h"
38 #include "libmythbase/iso639.h"
39 #include "libmythbase/mythdirs.h"
40 #include "libmythbase/mythlocale.h"
43 #include "libmythbase/mythtimer.h"
45 
46 // libmythui
50 #include "libmythui/mythuibutton.h"
54 
55 #include "guistartup.h"
56 
57 GUIStartup::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 
104  BuildFocusList();
105 
106  return true;
107 }
108 
109 bool 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 
119 bool 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 
130 void GUIStartup::setTotal(std::chrono::seconds total)
131 {
132  delete m_progressTimer;
134  m_timer.start(500ms);
135  m_total = total;
136  m_progressBar->SetTotal(m_total.count());
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
146 bool 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 
GUIStartup::m_progressTimer
MythTimer * m_progressTimer
Definition: guistartup.h:92
MythUIButton::Clicked
void Clicked()
MythTimer::elapsed
std::chrono::milliseconds elapsed(void)
Returns milliseconds elapsed since last start() or restart()
Definition: mythtimer.cpp:91
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:101
GUIStartup::Create
bool Create(void) override
Definition: guistartup.cpp:69
mythuiprogressbar.h
GUIStartup::m_dummyButton
MythUIButton * m_dummyButton
Definition: guistartup.h:84
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:384
mythscreenstack.h
MythConfirmationDialog::haveResult
void haveResult(bool)
MythUIProgressBar::SetUsed
void SetUsed(int value)
Definition: mythuiprogressbar.cpp:72
mythdialogbox.h
MythScreenStack
Definition: mythscreenstack.h:16
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:78
GUIStartup::Close
void Close(void) override
Definition: guistartup.cpp:174
MythTimer::start
void start(void)
starts measuring elapsed time.
Definition: mythtimer.cpp:47
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythScreenType
Screen in which all other widgets are contained and rendered.
Definition: mythscreentype.h:45
mythuistatetype.h
GUIStartup::m_dlgLoop
QEventLoop m_dlgLoop
Definition: guistartup.h:94
mythdirs.h
GUIStartup::m_setupButton
MythUIButton * m_setupButton
Definition: guistartup.h:87
mythuibuttonlist.h
GUIStartup::m_Search
bool m_Search
Definition: guistartup.h:60
langsettings.h
MythUIProgressBar::SetTotal
void SetTotal(int value)
Definition: mythuiprogressbar.cpp:78
guistartup.h
mythlogging.h
MythScreenType::SetFocusWidget
bool SetFocusWidget(MythUIType *widget=nullptr)
Definition: mythscreentype.cpp:116
GUIStartup::m_messageState
MythUIStateType * m_messageState
Definition: guistartup.h:90
MythScreenType::BuildFocusList
void BuildFocusList(void)
Definition: mythscreentype.cpp:204
GUIStartup::OnClosePromptReturn
void OnClosePromptReturn(bool submit)
Definition: guistartup.cpp:204
GUIStartup::GUIStartup
GUIStartup(MythScreenStack *parent, QEventLoop *eventLoop)
Definition: guistartup.cpp:57
GUIStartup::m_statusState
MythUIStateType * m_statusState
Definition: guistartup.h:89
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:91
GUIStartup::setTotal
void setTotal(std::chrono::seconds total)
Definition: guistartup.cpp:130
GUIStartup::m_searchButton
MythUIButton * m_searchButton
Definition: guistartup.h:86
GUIStartup::m_Retry
bool m_Retry
Definition: guistartup.h:59
GUIStartup::Setup
void Setup(void)
Definition: guistartup.cpp:235
GUIStartup::Search
void Search(void)
Definition: guistartup.cpp:227
GUIStartup::setMessageState
bool setMessageState(const QString &name)
Definition: guistartup.cpp:119
GUIStartup::setStatusState
bool setStatusState(const QString &name)
Definition: guistartup.cpp:109
GUIStartup::m_loop
QEventLoop * m_loop
Definition: guistartup.h:93
MythConfirmationDialog
Dialog asking for user confirmation. Ok and optional Cancel button.
Definition: mythdialogbox.h:271
XMLParseBase::LoadWindowFromXML
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
Definition: xmlparsebase.cpp:701
GUIStartup::~GUIStartup
~GUIStartup(void) override
Definition: guistartup.cpp:64
MythTimer::addMSecs
void addMSecs(std::chrono::milliseconds ms)
Adds an offset to the last call to start() or restart().
Definition: mythtimer.cpp:146
MythTimer::kStartRunning
@ kStartRunning
Definition: mythtimer.h:17
iso3166.h
ISO 3166-1 support functions.
GUIStartup::updateProgress
void updateProgress(void)
Definition: guistartup.cpp:169
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:104
GUIStartup::m_exitButton
MythUIButton * m_exitButton
Definition: guistartup.h:88
mythuibutton.h
mythtimer.h
MythMainWindow::GetStack
MythScreenStack * GetStack(const QString &Stackname)
Definition: mythmainwindow.cpp:322
iso639.h
ISO 639-1 and ISO 639-2 support functions.
GUIStartup::m_Setup
bool m_Setup
Definition: guistartup.h:58
GUIStartup::m_total
std::chrono::milliseconds m_total
Definition: guistartup.h:95
mythstorage.h
GUIStartup::Retry
void Retry(void)
Definition: guistartup.cpp:219
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:96
GUIStartup::m_retryButton
MythUIButton * m_retryButton
Definition: guistartup.h:85
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:57