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;
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  MythConfirmationDialog *confirmdialog
181  popupStack, message);
182 
183  if (confirmdialog->Create())
184  popupStack->AddScreen(confirmdialog);
185 
186  connect(confirmdialog, SIGNAL(haveResult(bool)),
187  SLOT(OnClosePromptReturn(bool)));
188 
189  m_dlgLoop.exec();
190 
191  if (m_progressTimer && !m_Exit)
192  {
194  m_progressTimer->addMSecs(elapsed);
195  m_timer.start();
196  }
197 }
198 
200 {
201  if (m_dlgLoop.isRunning())
202  m_dlgLoop.exit();
203 
204  if (submit)
205  {
206  if (m_loop->isRunning())
207  m_loop->exit();
208  m_Exit = true;
209  emit cancelPortCheck();
211  }
212 }
213 
215 {
216  m_Retry = true;
217  emit cancelPortCheck();
218  if (m_loop->isRunning())
219  m_loop->exit();
220 }
221 
223 {
224  m_Search = true;
225  emit cancelPortCheck();
226  if (m_loop->isRunning())
227  m_loop->exit();
228 }
229 
231 {
232  m_Setup = true;
233  emit cancelPortCheck();
234  if (m_loop->isRunning())
235  m_loop->exit();
236 }
237 
void Setup(void)
Definition: guistartup.cpp:230
ISO 639-1 and ISO 639-2 support functions.
bool setStatusState(const QString &name)
Definition: guistartup.cpp:107
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:117
void OnClosePromptReturn(bool submit)
Definition: guistartup.cpp:199
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:222
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:214
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
void setTotal(int total)
Definition: guistartup.cpp:128
bool m_Setup
Definition: guistartup.h:55
bool updateProgress(bool finished=false)
Definition: guistartup.cpp:144
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:328
void Close(void) override
Definition: guistartup.cpp:167
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:67
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
QEventLoop m_dlgLoop
Definition: guistartup.h:90
~GUIStartup(void)
Definition: guistartup.cpp:62
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