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_Exit(false),
58  m_Setup(false),
59  m_Retry(false),
60  m_Search(false),
61  m_dummyButton(nullptr),
62  m_retryButton(nullptr),
63  m_searchButton(nullptr),
64  m_setupButton(nullptr),
65  m_exitButton(nullptr),
66  m_statusState(nullptr),
67  m_messageState(nullptr),
68  m_progressBar(nullptr),
69  m_progressTimer(nullptr),
70  m_loop(eventLoop),
71  m_dlgLoop(this),
72  m_total(0)
73 {
74 }
75 
77 {
78  if (m_progressTimer)
79  delete m_progressTimer;
80 
81 }
82 
84 {
85  if (!LoadWindowFromXML("config-ui.xml", "guistartup", this))
86  return false;
87 
88  bool err = false;
89  UIUtilE::Assign(this, m_dummyButton, "dummy", &err);
90  if (!err)
91  UIUtilE::Assign(this, m_retryButton, "retry", &err);
92  if (!err)
93  UIUtilE::Assign(this, m_searchButton, "search", &err);
94  if (!err)
95  UIUtilE::Assign(this, m_setupButton, "setup", &err);
96  if (!err)
97  UIUtilE::Assign(this, m_exitButton, "exit", &err);
98  if (!err)
99  UIUtilE::Assign(this, m_statusState, "statusstate", &err);
100  if (!err)
101  UIUtilE::Assign(this, m_progressBar, "progress", &err);
102  if (!err)
103  UIUtilE::Assign(this, m_messageState, "messagestate", &err);
104 
105  if (err)
106  {
107  LOG(VB_GENERAL, LOG_ALERT,
108  "Cannot load screen 'guistartup'");
109  return false;
110  }
111 
112  connect(m_retryButton, SIGNAL(Clicked()), SLOT(Retry()));
113  connect(m_searchButton, SIGNAL(Clicked()), SLOT(Search()));
114  connect(m_setupButton, SIGNAL(Clicked()), SLOT(Setup()));
115  connect(m_exitButton, SIGNAL(Clicked()), SLOT(Close()));
116  connect(&m_timer, SIGNAL(timeout()), SLOT(updateProgress()));
117 
118  BuildFocusList();
119 
120  return true;
121 }
122 
123 bool GUIStartup::setStatusState(const QString &name)
124 {
125  bool ret = m_statusState->DisplayState(name);
126  m_Exit = false;
127  m_Setup = false;
128  m_Search = false;
129  m_Retry = false;
130  return ret;
131 }
132 
133 bool GUIStartup::setMessageState(const QString &name)
134 {
135  bool ret = m_messageState->DisplayState(name);
136  m_Exit = false;
137  m_Setup = false;
138  m_Search = false;
139  m_Retry = false;
140  return ret;
141 }
142 
143 
144 void GUIStartup::setTotal(int total)
145 {
146  if (m_progressTimer)
147  delete m_progressTimer;
149  m_timer.start(500);
150  m_total = total*1000;
153 
154  m_Exit = false;
155  m_Setup = false;
156  m_Search = false;
157  m_Retry = false;
158 }
159 
160 // return = true if time is up
161 bool GUIStartup::updateProgress(bool finished)
162 {
163  if (m_progressTimer)
164  {
165  int elapsed;
166  if (finished)
167  elapsed = m_total;
168  else
169  elapsed = m_progressTimer->elapsed();
170  m_progressBar->SetUsed(elapsed);
171  if (elapsed >= m_total)
172  {
173  m_timer.stop();
174  emit cancelPortCheck();
175  delete m_progressTimer;
176  m_progressTimer = nullptr;
177  }
178  return elapsed >= m_total;
179  }
180  m_timer.stop();
181  return false;
182 }
183 
185 {
186  int elapsed = 0;
187  if (m_progressTimer)
188  {
189  elapsed = m_progressTimer->elapsed();
191  m_timer.stop();
192  }
193  QString message = tr("Do you really want to exit MythTV?");
194  MythScreenStack *popupStack
195  = GetMythMainWindow()->GetStack("popup stack");
196  MythConfirmationDialog *confirmdialog
198  popupStack, message);
199 
200  if (confirmdialog->Create())
201  popupStack->AddScreen(confirmdialog);
202 
203  connect(confirmdialog, SIGNAL(haveResult(bool)),
204  SLOT(OnClosePromptReturn(bool)));
205 
206  m_dlgLoop.exec();
207 
208  if (m_progressTimer && !m_Exit)
209  {
211  m_progressTimer->addMSecs(elapsed);
212  m_timer.start();
213  }
214 }
215 
217 {
218  if (m_dlgLoop.isRunning())
219  m_dlgLoop.exit();
220 
221  if (submit)
222  {
223  if (m_loop->isRunning())
224  m_loop->exit();
225  m_Exit = true;
226  emit cancelPortCheck();
228  }
229 }
230 
232 {
233  m_Retry = true;
234  emit cancelPortCheck();
235  if (m_loop->isRunning())
236  m_loop->exit();
237 }
238 
240 {
241  m_Search = true;
242  emit cancelPortCheck();
243  if (m_loop->isRunning())
244  m_loop->exit();
245 }
246 
248 {
249  m_Setup = true;
250  emit cancelPortCheck();
251  if (m_loop->isRunning())
252  m_loop->exit();
253 }
254 
void Setup(void)
Definition: guistartup.cpp:247
ISO 639-1 and ISO 639-2 support functions.
bool setStatusState(const QString &name)
Definition: guistartup.cpp:123
QEventLoop * m_loop
Definition: guistartup.h:89
MythUIStateType * m_statusState
Definition: guistartup.h:85
A QElapsedTimer based timer to replace use of QTime as a timer.
Definition: mythtimer.h:13
GUIStartup(MythScreenStack *parent, QEventLoop *eventLoop)
Definition: guistartup.cpp:55
int m_total
Definition: guistartup.h:91
Dialog asking for user confirmation.
bool setMessageState(const QString &name)
Definition: guistartup.cpp:133
void OnClosePromptReturn(bool submit)
Definition: guistartup.cpp:216
ISO 3166-1 support functions.
MythUIButton * m_searchButton
Definition: guistartup.h:82
bool m_Retry
Definition: guistartup.h:56
void Search(void)
Definition: guistartup.cpp:239
MythScreenStack * GetStack(const QString &stackname)
MythUIButton * m_exitButton
Definition: guistartup.h:84
MythUIProgressBar * m_progressBar
Definition: guistartup.h:87
void BuildFocusList(void)
void cancelPortCheck(void)
void Retry(void)
Definition: guistartup.cpp:231
virtual void Close()
QTimer m_timer
Definition: guistartup.h:92
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
MythUIButton * m_retryButton
Definition: guistartup.h:81
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:85
void setTotal(int total)
Definition: guistartup.cpp:144
bool m_Setup
Definition: guistartup.h:55
bool updateProgress(bool finished=false)
Definition: guistartup.cpp:161
MythUIButton * m_dummyButton
Definition: guistartup.h:80
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition: mythuiutils.h:27
const char * name
Definition: ParseText.cpp:339
void Close(void) override
Definition: guistartup.cpp:184
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
MythMainWindow * GetMythMainWindow(void)
MythTimer * m_progressTimer
Definition: guistartup.h:88
int elapsed(void) const
Returns milliseconds elapsed since last start() or restart()
Definition: mythtimer.cpp:90
bool m_Exit
Definition: guistartup.h:54
void addMSecs(int ms)
Adds an offset to the last call to start() or restart().
Definition: mythtimer.cpp:145
bool Create(void) override
Definition: guistartup.cpp:83
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
QEventLoop m_dlgLoop
Definition: guistartup.h:90
~GUIStartup(void)
Definition: guistartup.cpp:76
bool Create(void) override
bool DisplayState(const QString &name)
MythUIButton * m_setupButton
Definition: guistartup.h:83
bool SetFocusWidget(MythUIType *widget=nullptr)
bool m_Search
Definition: guistartup.h:57
Screen in which all other widgets are contained and rendered.
void stop(void)
Stops timer, next call to isRunning() will return false and any calls to elapsed() or restart() will ...
Definition: mythtimer.cpp:77
MythUIStateType * m_messageState
Definition: guistartup.h:86
void start(void)
starts measuring elapsed time.
Definition: mythtimer.cpp:47