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 // qt
29 #include <QEventLoop>
30 #include <QDir>
31 #include <QFileInfo>
32 
33 // libmythbase
34 #include "mythcorecontext.h"
35 #include "mythstorage.h"
36 #include "mythdirs.h"
37 #include "mythlogging.h"
38 #include "mythlocale.h"
39 #include "mythtranslation.h"
40 #include "iso3166.h"
41 #include "iso639.h"
42 #include "mythtimer.h"
43 
44 // libmythui
45 #include "mythuibuttonlist.h"
46 #include "mythuibutton.h"
47 #include "mythmainwindow.h"
48 #include "mythscreenstack.h"
49 #include "mythuistatetype.h"
50 #include "mythuiprogressbar.h"
51 #include "mythdialogbox.h"
52 
53 #include "guistartup.h"
54 
55 GUIStartup::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 
96  connect(m_retryButton, SIGNAL(Clicked()), SLOT(Retry()));
97  connect(m_searchButton, SIGNAL(Clicked()), SLOT(Search()));
98  connect(m_setupButton, SIGNAL(Clicked()), SLOT(Setup()));
99  connect(m_exitButton, SIGNAL(Clicked()), SLOT(Close()));
100  connect(&m_timer, SIGNAL(timeout()), SLOT(updateProgress()));
101 
102  BuildFocusList();
103 
104  return true;
105 }
106 
107 bool 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 
117 bool 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 
128 void GUIStartup::setTotal(int total)
129 {
130  delete m_progressTimer;
132  m_timer.start(500);
133  m_total = total*1000;
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
144 bool GUIStartup::updateProgress(bool finished)
145 {
146  if (m_progressTimer)
147  {
148  int elapsed = 0;
149  if (finished)
150  elapsed = m_total;
151  else
152  elapsed = m_progressTimer->elapsed();
153  m_progressBar->SetUsed(elapsed);
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  int elapsed = 0;
170  if (m_progressTimer)
171  {
172  elapsed = m_progressTimer->elapsed();
174  m_timer.stop();
175  }
176  QString message = tr("Do you really want to exit MythTV?");
177  MythScreenStack *popupStack
178  = GetMythMainWindow()->GetStack("popup stack");
179  auto *confirmdialog = new MythConfirmationDialog(popupStack, message);
180 
181  if (confirmdialog->Create())
182  popupStack->AddScreen(confirmdialog);
183 
184  connect(confirmdialog, SIGNAL(haveResult(bool)),
185  SLOT(OnClosePromptReturn(bool)));
186 
187  m_dlgLoop.exec();
188 
189  if (m_progressTimer && !m_Exit)
190  {
192  m_progressTimer->addMSecs(elapsed);
193  m_timer.start();
194  }
195 }
196 
198 {
199  if (m_dlgLoop.isRunning())
200  m_dlgLoop.exit();
201 
202  if (submit)
203  {
204  if (m_loop->isRunning())
205  m_loop->exit();
206  m_Exit = true;
207  emit cancelPortCheck();
209  }
210 }
211 
213 {
214  m_Retry = true;
215  emit cancelPortCheck();
216  if (m_loop->isRunning())
217  m_loop->exit();
218 }
219 
221 {
222  m_Search = true;
223  emit cancelPortCheck();
224  if (m_loop->isRunning())
225  m_loop->exit();
226 }
227 
229 {
230  m_Setup = true;
231  emit cancelPortCheck();
232  if (m_loop->isRunning())
233  m_loop->exit();
234 }
235 
GUIStartup::m_progressTimer
MythTimer * m_progressTimer
Definition: guistartup.h:88
GUIStartup::setTotal
void setTotal(int total)
Definition: guistartup.cpp:128
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:103
GUIStartup::Create
bool Create(void) override
Definition: guistartup.cpp:67
mythuiprogressbar.h
GUIStartup::m_dummyButton
MythUIButton * m_dummyButton
Definition: guistartup.h:80
MythTimer
A QElapsedTimer based timer to replace use of QTime as a timer.
Definition: mythtimer.h:14
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
MythUIProgressBar::SetUsed
void SetUsed(int value)
Definition: mythuiprogressbar.cpp:59
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:77
GUIStartup::Close
void Close(void) override
Definition: guistartup.cpp:167
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:45
mythuistatetype.h
GUIStartup::m_dlgLoop
QEventLoop m_dlgLoop
Definition: guistartup.h:90
mythdirs.h
GUIStartup::m_setupButton
MythUIButton * m_setupButton
Definition: guistartup.h:83
MythMainWindow::GetStack
MythScreenStack * GetStack(const QString &stackname)
Definition: mythmainwindow.cpp:309
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:91
MythScreenType::SetFocusWidget
bool SetFocusWidget(MythUIType *widget=nullptr)
Definition: mythscreentype.cpp:117
GUIStartup::m_messageState
MythUIStateType * m_messageState
Definition: guistartup.h:86
MythScreenType::BuildFocusList
void BuildFocusList(void)
Definition: mythscreentype.cpp:222
GUIStartup::OnClosePromptReturn
void OnClosePromptReturn(bool submit)
Definition: guistartup.cpp:197
GUIStartup::GUIStartup
GUIStartup(MythScreenStack *parent, QEventLoop *eventLoop)
Definition: guistartup.cpp:55
GUIStartup::m_statusState
MythUIStateType * m_statusState
Definition: guistartup.h:85
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:87
GUIStartup::m_searchButton
MythUIButton * m_searchButton
Definition: guistartup.h:82
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:228
GUIStartup::Search
void Search(void)
Definition: guistartup.cpp:220
GUIStartup::setMessageState
bool setMessageState(const QString &name)
Definition: guistartup.cpp:117
GUIStartup::setStatusState
bool setStatusState(const QString &name)
Definition: guistartup.cpp:107
GUIStartup::m_loop
QEventLoop * m_loop
Definition: guistartup.h:89
MythTimer::kStartRunning
@ kStartRunning
Definition: mythtimer.h:17
MythConfirmationDialog
Dialog asking for user confirmation. Ok and optional Cancel button.
Definition: mythdialogbox.h:222
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:62
iso3166.h
ISO 3166-1 support functions.
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:107
GUIStartup::m_exitButton
MythUIButton * m_exitButton
Definition: guistartup.h:84
mythuibutton.h
mythtimer.h
iso639.h
ISO 639-1 and ISO 639-2 support functions.
GUIStartup::m_Setup
bool m_Setup
Definition: guistartup.h:55
GUIStartup::updateProgress
bool updateProgress(bool finished=false)
Definition: guistartup.cpp:144
mythstorage.h
GUIStartup::Retry
void Retry(void)
Definition: guistartup.cpp:212
mythmainwindow.h
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:49
GUIStartup::m_timer
QTimer m_timer
Definition: guistartup.h:92
GUIStartup::m_retryButton
MythUIButton * m_retryButton
Definition: guistartup.h:81
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