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