MythTV  master
mythprogressdialog.cpp
Go to the documentation of this file.
1 
2 
3 #include "mythprogressdialog.h"
4 
5 // libmythbase headers
7 
8 // libmythui headers
9 #include "mythuitext.h"
10 #include "mythuiprogressbar.h"
11 
13  (QEvent::Type) QEvent::registerEventType();
14 
15 // Force this class to have a vtable so that dynamic_cast works.
16 // NOLINTNEXTLINE(modernize-use-equals-default)
18 {
19 }
20 
21 MythUIBusyDialog::MythUIBusyDialog(const QString &message,
22  MythScreenStack *parent, const char *name)
23  : MythScreenType(parent, name, false)
24 {
25  if (!message.isEmpty())
26  m_message = message;
27  else
28  m_message = tr("Please Wait...");
30 }
31 
33 {
34  if (!CopyWindowFromBase("MythBusyDialog", this))
35  return false;
36 
37  m_messageText = dynamic_cast<MythUIText *>(GetChild("message"));
38 
39  if (m_messageText)
41 
42  return true;
43 }
44 
45 void MythUIBusyDialog::SetMessage(const QString &message)
46 {
47  m_newMessageLock.lock();
48  m_newMessage = message;
49  m_haveNewMessage = true;
50  m_newMessageLock.unlock();
51 }
52 
54 {
56 }
57 
59 {
61  {
62  m_newMessageLock.lock();
65  m_newMessageLock.unlock();
66  }
67 
69 }
70 
71 bool MythUIBusyDialog::keyPressEvent(QKeyEvent *event)
72 {
73  QStringList actions;
74  bool handled = GetMythMainWindow()->TranslateKeyPress("qt", event, actions, false);
75 
76  for (int i = 0; i < actions.size() && !handled; i++)
77  {
78  QString action = actions[i];
79  handled = true;
80 
81  if (action == "ESCAPE")
82  {
83  // eat the escape keypress
84  }
85  else
86  handled = false;
87  }
88 
89  if (!handled && MythScreenType::keyPressEvent(event))
90  handled = true;
91 
92  return handled;
93 }
94 
95 MythUIBusyDialog *ShowBusyPopup(const QString &message)
96 {
97  QString LOC = "ShowBusyPopup('" + message + "') - ";
98  MythUIBusyDialog *pop = nullptr;
99  static MythScreenStack *s_stk = nullptr;
100 
101 
102  if (!s_stk)
103  {
105 
106  if (win)
107  s_stk = win->GetStack("popup stack");
108  else
109  {
110  LOG(VB_GENERAL, LOG_ERR, LOC + "no main window?");
111  return nullptr;
112  }
113 
114  if (!s_stk)
115  {
116  LOG(VB_GENERAL, LOG_ERR, LOC + "no popup stack? "
117  "Is there a MythThemeBase?");
118  return nullptr;
119  }
120  }
121 
122  pop = new MythUIBusyDialog(message, s_stk, "showBusyPopup");
123  if (pop->Create())
124  s_stk->AddScreen(pop);
125 
126  return pop;
127 }
128 //---------------------------------------------------------
129 
131 {
132  if (!CopyWindowFromBase("MythProgressDialog", this))
133  return false;
134 
135  m_messageText = dynamic_cast<MythUIText *>(GetChild("message"));
136  m_progressText = dynamic_cast<MythUIText *>(GetChild("progresstext"));
137  m_progressBar = dynamic_cast<MythUIProgressBar *>(GetChild("progressbar"));
138 
139  if (m_messageText)
141 
142  return true;
143 }
144 
146 {
147  QStringList actions;
148  bool handled = GetMythMainWindow()->TranslateKeyPress("qt", event, actions, false);
149 
150  for (int i = 0; i < actions.size() && !handled; i++)
151  {
152  QString action = actions[i];
153  handled = true;
154 
155  if (action == "ESCAPE")
156  {
157  // eat the escape keypress
158  }
159  else
160  handled = false;
161  }
162 
163  if (!handled && MythScreenType::keyPressEvent(event))
164  handled = true;
165 
166  return handled;
167 }
168 
170 {
171  if (event->type() == ProgressUpdateEvent::kEventType)
172  {
173  auto *pue = dynamic_cast<ProgressUpdateEvent*>(event);
174  if (!pue)
175  {
176  LOG(VB_GENERAL, LOG_ERR,
177  "Error, event claims to be a progress update but fails "
178  "to cast");
179  return;
180  }
181 
182  QString message = pue->GetMessage();
183  if (!message.isEmpty())
184  m_message = message;
185  uint total = pue->GetTotal();
186  if (total > 0)
187  m_total = total;
188  m_count = pue->GetCount();
189  UpdateProgress();
190  }
191 }
192 
194 {
195  m_total = total;
196  UpdateProgress();
197 }
198 
200 {
201  m_count = count;
202  UpdateProgress();
203 }
204 
205 void MythUIProgressDialog::SetMessage(const QString &message)
206 {
207  m_message = message;
208  UpdateProgress();
209 }
210 
212 {
213  if (m_messageText)
215 
216  if (m_total == 0)
217  return;
218 
219  if (m_count > m_total)
220  {
221  LOG(VB_GENERAL, LOG_ERR, QString("Progress count (%1) is higher "
222  "than total (%2)")
223  .arg(m_count) .arg(m_total));
224  return;
225  }
226 
227  if (m_progressBar)
228  {
231  }
232 
233  uint percentage = (uint)(((float)m_count/(float)m_total) * 100.0F);
234 
235  if (m_progressText)
236  m_progressText->SetText(QString("%1%").arg(percentage));
237 }
MythUIProgressDialog::Create
bool Create(void) override
Definition: mythprogressdialog.cpp:130
ShowBusyPopup
MythUIBusyDialog * ShowBusyPopup(const QString &message)
Definition: mythprogressdialog.cpp:95
MythUIBusyDialog::m_messageText
MythUIText * m_messageText
Definition: mythprogressdialog.h:56
mythuitext.h
mythuiprogressbar.h
MythUIBusyDialog::MythUIBusyDialog
MythUIBusyDialog(const QString &message, MythScreenStack *parent, const char *name)
Definition: mythprogressdialog.cpp:21
false
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:89
MythUIBusyDialog::Pulse
void Pulse(void) override
Pulse is called 70 times a second to trigger a single frame of an animation.
Definition: mythprogressdialog.cpp:58
MythUIType::GetChild
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:133
MythUIBusyDialog::Create
bool Create(void) override
Definition: mythprogressdialog.cpp:32
LOC
#define LOC
Definition: audioconvert.cpp:41
MythUIProgressBar::SetUsed
void SetUsed(int value)
Definition: mythuiprogressbar.cpp:69
MythScreenStack
Definition: mythscreenstack.h:16
MythUIProgressDialog::m_progressText
MythUIText * m_progressText
Definition: mythprogressdialog.h:82
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythUIBusyDialog::m_newMessageLock
QMutex m_newMessageLock
Definition: mythprogressdialog.h:54
MythScreenType
Screen in which all other widgets are contained and rendered.
Definition: mythscreentype.h:45
MythUIProgressDialog::SetMessage
void SetMessage(const QString &message)
Definition: mythprogressdialog.cpp:205
MythUIType::Pulse
virtual void Pulse(void)
Pulse is called 70 times a second to trigger a single frame of an animation.
Definition: mythuitype.cpp:455
mythprogressdialog.h
MythUIProgressDialog::m_total
uint m_total
Definition: mythprogressdialog.h:78
MythUIProgressDialog::customEvent
void customEvent(QEvent *event) override
Definition: mythprogressdialog.cpp:169
ProgressUpdateEvent
Definition: mythprogressdialog.h:16
MythUIProgressBar::SetTotal
void SetTotal(int value)
Definition: mythuiprogressbar.cpp:81
mythlogging.h
MythMainWindow::TranslateKeyPress
bool TranslateKeyPress(const QString &Context, QKeyEvent *Event, QStringList &Actions, bool AllowJumps=true)
Get a list of actions for a keypress in the given context.
Definition: mythmainwindow.cpp:1104
MythUIProgressBar
Progress bar widget.
Definition: mythuiprogressbar.h:12
ProgressUpdateEvent::kEventType
static Type kEventType
Definition: mythprogressdialog.h:28
MythUIProgressDialog::SetProgress
void SetProgress(uint count)
Definition: mythprogressdialog.cpp:199
MythUIProgressDialog::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: mythprogressdialog.cpp:145
XMLParseBase::CopyWindowFromBase
static bool CopyWindowFromBase(const QString &windowname, MythScreenType *win)
Definition: xmlparsebase.cpp:920
MythUIBusyDialog
Definition: mythprogressdialog.h:36
MythUIBusyDialog::m_newMessage
QString m_newMessage
Definition: mythprogressdialog.h:53
ProgressUpdateEvent::~ProgressUpdateEvent
~ProgressUpdateEvent() override
Definition: mythprogressdialog.cpp:17
uint
unsigned int uint
Definition: compat.h:81
MythUIProgressDialog::m_count
uint m_count
Definition: mythprogressdialog.h:79
MythUIText
All purpose text widget, displays a text string.
Definition: mythuitext.h:28
MythScreenType::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: mythscreentype.cpp:404
MythUIProgressDialog::SetTotal
void SetTotal(uint total)
Definition: mythprogressdialog.cpp:193
MythUIText::SetText
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:132
MythUIBusyDialog::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: mythprogressdialog.cpp:71
MythUIBusyDialog::SetMessage
void SetMessage(const QString &message)
Definition: mythprogressdialog.cpp:45
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:102
build_compdb.action
action
Definition: build_compdb.py:9
MythMainWindow::GetStack
MythScreenStack * GetStack(const QString &Stackname)
Definition: mythmainwindow.cpp:320
MythUIBusyDialog::Reset
void Reset(void) override
Reset the widget to it's original state, should not reset changes made by the theme.
Definition: mythprogressdialog.cpp:53
MythUIBusyDialog::m_message
QString m_message
Definition: mythprogressdialog.h:51
MythUIBusyDialog::m_origMessage
QString m_origMessage
Definition: mythprogressdialog.h:50
MythUIBusyDialog::m_haveNewMessage
bool m_haveNewMessage
Definition: mythprogressdialog.h:52
MythUIProgressDialog::m_message
QString m_message
Definition: mythprogressdialog.h:77
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:52
MythMainWindow
Definition: mythmainwindow.h:28
MythUIProgressDialog::m_progressBar
MythUIProgressBar * m_progressBar
Definition: mythprogressdialog.h:83
MythUIProgressDialog::m_messageText
MythUIText * m_messageText
Definition: mythprogressdialog.h:81
MythUIProgressDialog::UpdateProgress
void UpdateProgress(void)
Definition: mythprogressdialog.cpp:211