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"
40 #include "libmythbase/mythdirs.h"
41 #include "libmythbase/mythlocale.h"
44 #include "libmythbase/mythtimer.h"
46 
47 // libmythui
51 #include "libmythui/mythuibutton.h"
55 
56 #include "guistartup.h"
57 
58 GUIStartup::GUIStartup(MythScreenStack *parent, QEventLoop *eventLoop)
59  :MythScreenType(parent, "GUIStartup"),
60  m_loop(eventLoop),
61  m_dlgLoop(this)
62 {
63 }
64 
66 {
67  delete m_progressTimer;
68 }
69 
71 {
72  if (!LoadWindowFromXML("config-ui.xml", "guistartup", this))
73  return false;
74 
75  bool err = false;
76  UIUtilE::Assign(this, m_dummyButton, "dummy", &err);
77  if (!err)
78  UIUtilE::Assign(this, m_retryButton, "retry", &err);
79  if (!err)
80  UIUtilE::Assign(this, m_searchButton, "search", &err);
81  if (!err)
82  UIUtilE::Assign(this, m_setupButton, "setup", &err);
83  if (!err)
84  UIUtilE::Assign(this, m_exitButton, "exit", &err);
85  if (!err)
86  UIUtilE::Assign(this, m_statusState, "statusstate", &err);
87  if (!err)
88  UIUtilE::Assign(this, m_progressBar, "progress", &err);
89  if (!err)
90  UIUtilE::Assign(this, m_messageState, "messagestate", &err);
91 
92  if (err)
93  {
94  LOG(VB_GENERAL, LOG_ALERT,
95  "Cannot load screen 'guistartup'");
96  return false;
97  }
98 
103  connect(&m_timer, &QTimer::timeout, this, qOverload<>(&GUIStartup::updateProgress));
104 
105  BuildFocusList();
106 
107  return true;
108 }
109 
110 bool GUIStartup::setStatusState(const QString &name)
111 {
112  bool ret = m_statusState->DisplayState(name);
113  m_Exit = false;
114  m_Setup = false;
115  m_Search = false;
116  m_Retry = false;
117  return ret;
118 }
119 
120 bool GUIStartup::setMessageState(const QString &name)
121 {
122  bool ret = m_messageState->DisplayState(name);
123  m_Exit = false;
124  m_Setup = false;
125  m_Search = false;
126  m_Retry = false;
127  return ret;
128 }
129 
130 
131 void GUIStartup::setTotal(std::chrono::seconds total)
132 {
133  delete m_progressTimer;
135  m_timer.start(500ms);
136  m_total = total;
137  m_progressBar->SetTotal(m_total.count());
139 
140  m_Exit = false;
141  m_Setup = false;
142  m_Search = false;
143  m_Retry = false;
144 }
145 
146 // return = true if time is up
147 bool GUIStartup::updateProgress(bool finished)
148 {
149  if (m_progressTimer)
150  {
151  std::chrono::milliseconds elapsed { 0ms };
152  if (finished)
153  elapsed = m_total;
154  else
155  elapsed = m_progressTimer->elapsed();
156  m_progressBar->SetUsed(elapsed.count());
157  if (elapsed >= m_total)
158  {
159  m_timer.stop();
160  emit cancelPortCheck();
161  delete m_progressTimer;
162  m_progressTimer = nullptr;
163  }
164  return elapsed >= m_total;
165  }
166  m_timer.stop();
167  return false;
168 }
169 
171 {
172  updateProgress(false);
173 }
174 
176 {
177  std::chrono::milliseconds elapsed { 0ms };
178  if (m_progressTimer)
179  {
180  elapsed = m_progressTimer->elapsed();
182  m_timer.stop();
183  }
184  QString message = tr("Do you really want to exit MythTV?");
185  MythScreenStack *popupStack
186  = GetMythMainWindow()->GetStack("popup stack");
187  auto *confirmdialog = new MythConfirmationDialog(popupStack, message);
188 
189  if (confirmdialog->Create())
190  popupStack->AddScreen(confirmdialog);
191 
192  connect(confirmdialog, &MythConfirmationDialog::haveResult,
194 
195  m_dlgLoop.exec();
196 
197  if (m_progressTimer && !m_Exit)
198  {
200  m_progressTimer->addMSecs(elapsed);
201  m_timer.start();
202  }
203 }
204 
206 {
207  if (m_dlgLoop.isRunning())
208  m_dlgLoop.exit();
209 
210  if (submit)
211  {
212  if (m_loop->isRunning())
213  m_loop->exit();
214  m_Exit = true;
215  emit cancelPortCheck();
217  }
218 }
219 
221 {
222  m_Retry = true;
223  emit cancelPortCheck();
224  if (m_loop->isRunning())
225  m_loop->exit();
226 }
227 
229 {
230  m_Search = true;
231  emit cancelPortCheck();
232  if (m_loop->isRunning())
233  m_loop->exit();
234 }
235 
237 {
238  m_Setup = true;
239  emit cancelPortCheck();
240  if (m_loop->isRunning())
241  m_loop->exit();
242 }
243 
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:102
GUIStartup::Create
bool Create(void) override
Definition: guistartup.cpp:70
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:386
mythscreenstack.h
MythConfirmationDialog::haveResult
void haveResult(bool)
MythUIProgressBar::SetUsed
void SetUsed(int value)
Definition: mythuiprogressbar.cpp:69
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:175
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:81
guistartup.h
mythlogging.h
MythScreenType::SetFocusWidget
bool SetFocusWidget(MythUIType *widget=nullptr)
Definition: mythscreentype.cpp:118
GUIStartup::m_messageState
MythUIStateType * m_messageState
Definition: guistartup.h:90
MythScreenType::BuildFocusList
void BuildFocusList(void)
Definition: mythscreentype.cpp:206
GUIStartup::OnClosePromptReturn
void OnClosePromptReturn(bool submit)
Definition: guistartup.cpp:205
GUIStartup::GUIStartup
GUIStartup(MythScreenStack *parent, QEventLoop *eventLoop)
Definition: guistartup.cpp:58
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:131
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:236
GUIStartup::Search
void Search(void)
Definition: guistartup.cpp:228
GUIStartup::setMessageState
bool setMessageState(const QString &name)
Definition: guistartup.cpp:120
GUIStartup::setStatusState
bool setStatusState(const QString &name)
Definition: guistartup.cpp:110
GUIStartup::m_loop
QEventLoop * m_loop
Definition: guistartup.h:93
MythTimer::kStartRunning
@ kStartRunning
Definition: mythtimer.h:17
MythConfirmationDialog
Dialog asking for user confirmation. Ok and optional Cancel button.
Definition: mythdialogbox.h:272
mythcorecontext.h
XMLParseBase::LoadWindowFromXML
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
Definition: xmlparsebase.cpp:687
GUIStartup::~GUIStartup
~GUIStartup(void) override
Definition: guistartup.cpp:65
MythTimer::addMSecs
void addMSecs(std::chrono::milliseconds ms)
Adds an offset to the last call to start() or restart().
Definition: mythtimer.cpp:146
iso3166.h
ISO 3166-1 support functions.
GUIStartup::updateProgress
void updateProgress(void)
Definition: guistartup.cpp:170
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:323
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:220
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