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 
12 const QEvent::Type ProgressUpdateEvent::kEventType =
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  const QString& action = actions[i];
79  handled = true;
80 
81  if (action == "ESCAPE")
82  {
83  // eat the escape keypress
84  }
85  else
86  {
87  handled = false;
88  }
89  }
90 
91  if (!handled && MythScreenType::keyPressEvent(event))
92  handled = true;
93 
94  return handled;
95 }
96 
97 MythUIBusyDialog *ShowBusyPopup(const QString &message)
98 {
99  QString LOC = "ShowBusyPopup('" + message + "') - ";
100  MythUIBusyDialog *pop = nullptr;
101  static MythScreenStack *s_stk = nullptr;
102 
103 
104  if (!s_stk)
105  {
107 
108  if (win)
109  s_stk = win->GetStack("popup stack");
110  else
111  {
112  LOG(VB_GENERAL, LOG_ERR, LOC + "no main window?");
113  return nullptr;
114  }
115 
116  if (!s_stk)
117  {
118  LOG(VB_GENERAL, LOG_ERR, LOC + "no popup stack? "
119  "Is there a MythThemeBase?");
120  return nullptr;
121  }
122  }
123 
124  pop = new MythUIBusyDialog(message, s_stk, "showBusyPopup");
125  if (pop->Create())
126  s_stk->AddScreen(pop);
127 
128  return pop;
129 }
130 //---------------------------------------------------------
131 
133 {
134  if (!CopyWindowFromBase("MythProgressDialog", this))
135  return false;
136 
137  m_messageText = dynamic_cast<MythUIText *>(GetChild("message"));
138  m_progressText = dynamic_cast<MythUIText *>(GetChild("progresstext"));
139  m_progressBar = dynamic_cast<MythUIProgressBar *>(GetChild("progressbar"));
140 
141  if (m_messageText)
143 
144  return true;
145 }
146 
148 {
149  QStringList actions;
150  bool handled = GetMythMainWindow()->TranslateKeyPress("qt", event, actions, false);
151 
152  for (int i = 0; i < actions.size() && !handled; i++)
153  {
154  const QString& action = actions[i];
155  handled = true;
156 
157  if (action == "ESCAPE")
158  {
159  // eat the escape keypress
160  }
161  else
162  {
163  handled = false;
164  }
165  }
166 
167  if (!handled && MythScreenType::keyPressEvent(event))
168  handled = true;
169 
170  return handled;
171 }
172 
174 {
175  if (event->type() == ProgressUpdateEvent::kEventType)
176  {
177  auto *pue = dynamic_cast<ProgressUpdateEvent*>(event);
178  if (!pue)
179  {
180  LOG(VB_GENERAL, LOG_ERR,
181  "Error, event claims to be a progress update but fails "
182  "to cast");
183  return;
184  }
185 
186  QString message = pue->GetMessage();
187  if (!message.isEmpty())
188  m_message = message;
189  uint total = pue->GetTotal();
190  if (total > 0)
191  m_total = total;
192  m_count = pue->GetCount();
193  UpdateProgress();
194  }
195 }
196 
198 {
199  m_total = total;
200  UpdateProgress();
201 }
202 
204 {
205  m_count = count;
206  UpdateProgress();
207 }
208 
209 void MythUIProgressDialog::SetMessage(const QString &message)
210 {
211  m_message = message;
212  UpdateProgress();
213 }
214 
216 {
217  if (m_messageText)
219 
220  if (m_total == 0)
221  return;
222 
223  if (m_count > m_total)
224  {
225  LOG(VB_GENERAL, LOG_ERR, QString("Progress count (%1) is higher "
226  "than total (%2)")
227  .arg(m_count) .arg(m_total));
228  return;
229  }
230 
231  if (m_progressBar)
232  {
235  }
236 
237  uint percentage = (uint)(((float)m_count/(float)m_total) * 100.0F);
238 
239  if (m_progressText)
240  m_progressText->SetText(QString("%1%").arg(percentage));
241 }
MythUIProgressDialog::Create
bool Create(void) override
Definition: mythprogressdialog.cpp:132
ShowBusyPopup
MythUIBusyDialog * ShowBusyPopup(const QString &message)
Definition: mythprogressdialog.cpp:97
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:138
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:72
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:209
MythUIType::Pulse
virtual void Pulse(void)
Pulse is called 70 times a second to trigger a single frame of an animation.
Definition: mythuitype.cpp:456
mythprogressdialog.h
MythUIProgressDialog::m_total
uint m_total
Definition: mythprogressdialog.h:78
MythUIProgressDialog::customEvent
void customEvent(QEvent *event) override
Definition: mythprogressdialog.cpp:173
ProgressUpdateEvent
Definition: mythprogressdialog.h:16
MythUIProgressBar::SetTotal
void SetTotal(int value)
Definition: mythuiprogressbar.cpp:78
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:1111
ProgressUpdateEvent::kEventType
static const Type kEventType
Definition: mythprogressdialog.h:28
MythUIProgressBar
Progress bar widget.
Definition: mythuiprogressbar.h:12
MythUIProgressDialog::SetProgress
void SetProgress(uint count)
Definition: mythprogressdialog.cpp:203
MythUIProgressDialog::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: mythprogressdialog.cpp:147
XMLParseBase::CopyWindowFromBase
static bool CopyWindowFromBase(const QString &windowname, MythScreenType *win)
Definition: xmlparsebase.cpp:941
MythUIBusyDialog
Definition: mythprogressdialog.h:36
MythUIBusyDialog::m_newMessage
QString m_newMessage
Definition: mythprogressdialog.h:53
ProgressUpdateEvent::~ProgressUpdateEvent
~ProgressUpdateEvent() override
Definition: mythprogressdialog.cpp:17
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:401
MythUIProgressDialog::SetTotal
void SetTotal(uint total)
Definition: mythprogressdialog.cpp:197
MythUIText::SetText
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:115
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:104
build_compdb.action
action
Definition: build_compdb.py:9
MythMainWindow::GetStack
MythScreenStack * GetStack(const QString &Stackname)
Definition: mythmainwindow.cpp:322
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:215
uint
unsigned int uint
Definition: freesurround.h:24