MythTV  0.28pre
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
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  m_haveNewMessage(false), m_messageText(NULL)
19 {
20  if (!message.isEmpty())
21  m_message = message;
22  else
23  m_message = tr("Please Wait...");
25 }
26 
28 {
29  if (!CopyWindowFromBase("MythBusyDialog", this))
30  return false;
31 
32  m_messageText = dynamic_cast<MythUIText *>(GetChild("message"));
33 
34  if (m_messageText)
36 
37  return true;
38 }
39 
40 void MythUIBusyDialog::SetMessage(const QString &message)
41 {
42  m_newMessageLock.lock();
43  m_newMessage = message;
44  m_haveNewMessage = true;
45  m_newMessageLock.unlock();
46 }
47 
49 {
51 }
52 
54 {
56  {
57  m_newMessageLock.lock();
60  m_newMessageLock.unlock();
61  }
62 
64 }
65 
66 bool MythUIBusyDialog::keyPressEvent(QKeyEvent *event)
67 {
68  QStringList actions;
69  bool handled = GetMythMainWindow()->TranslateKeyPress("qt", event, actions, false);
70 
71  for (int i = 0; i < actions.size() && !handled; i++)
72  {
73  QString action = actions[i];
74  handled = true;
75 
76  if (action == "ESCAPE")
77  {
78  // eat the escape keypress
79  }
80  else
81  handled = false;
82  }
83 
84  if (!handled && MythScreenType::keyPressEvent(event))
85  handled = true;
86 
87  return handled;
88 }
89 
90 MythUIBusyDialog *ShowBusyPopup(const QString &message)
91 {
92  QString LOC = "ShowBusyPopup('" + message + "') - ";
93  MythUIBusyDialog *pop = NULL;
94  static MythScreenStack *stk = NULL;
95 
96 
97  if (!stk)
98  {
100 
101  if (win)
102  stk = win->GetStack("popup stack");
103  else
104  {
105  LOG(VB_GENERAL, LOG_ERR, LOC + "no main window?");
106  return NULL;
107  }
108 
109  if (!stk)
110  {
111  LOG(VB_GENERAL, LOG_ERR, LOC + "no popup stack? "
112  "Is there a MythThemeBase?");
113  return NULL;
114  }
115  }
116 
117  pop = new MythUIBusyDialog(message, stk, "showBusyPopup");
118  if (pop->Create())
119  stk->AddScreen(pop);
120 
121  return pop;
122 }
123 //---------------------------------------------------------
124 
126  MythScreenStack *parent, const char *name)
127  : MythScreenType(parent, name, false),
128  m_total(0), m_count(0),
129  m_messageText(NULL), m_progressText(NULL), m_progressBar(NULL)
130 {
131  m_message = message;
132 }
133 
135 {
136  if (!CopyWindowFromBase("MythProgressDialog", this))
137  return false;
138 
139  m_messageText = dynamic_cast<MythUIText *>(GetChild("message"));
140  m_progressText = dynamic_cast<MythUIText *>(GetChild("progresstext"));
141  m_progressBar = dynamic_cast<MythUIProgressBar *>(GetChild("progressbar"));
142 
143  if (m_messageText)
145 
146  return true;
147 }
148 
150 {
151  QStringList actions;
152  bool handled = GetMythMainWindow()->TranslateKeyPress("qt", event, actions, false);
153 
154  for (int i = 0; i < actions.size() && !handled; i++)
155  {
156  QString action = actions[i];
157  handled = true;
158 
159  if (action == "ESCAPE")
160  {
161  // eat the escape keypress
162  }
163  else
164  handled = false;
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  ProgressUpdateEvent *pue = dynamic_cast<ProgressUpdateEvent*>(event);
178 
179  if (!pue)
180  {
181  LOG(VB_GENERAL, LOG_ERR,
182  "Error, event claims to be a progress update but fails "
183  "to cast");
184  return;
185  }
186 
187  QString message = pue->GetMessage();
188  if (!message.isEmpty())
189  m_message = message;
190  uint total = pue->GetTotal();
191  if (total > 0)
192  m_total = total;
193  m_count = pue->GetCount();
194  UpdateProgress();
195  }
196 }
197 
199 {
200  m_total = total;
201  UpdateProgress();
202 }
203 
205 {
206  m_count = count;
207  UpdateProgress();
208 }
209 
210 void MythUIProgressDialog::SetMessage(const QString &message)
211 {
212  m_message = message;
213  UpdateProgress();
214 }
215 
217 {
218  if (m_messageText)
220 
221  if (m_total == 0)
222  return;
223 
224  if (m_count > m_total)
225  {
226  LOG(VB_GENERAL, LOG_ERR, QString("Progress count (%1) is higher "
227  "than total (%2)")
228  .arg(m_count) .arg(m_total));
229  return;
230  }
231 
232  if (m_progressBar)
233  {
236  }
237 
238  uint percentage = (uint)(((float)m_count/(float)m_total) * 100.0);
239 
240  if (m_progressText)
241  m_progressText->SetText(QString("%1%").arg(percentage));
242 }
void SetMessage(const QString &message)
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:83
void SetMessage(const QString &message)
void customEvent(QEvent *event)
void SetProgress(uint count)
All purpose text widget, displays a text string.
Definition: mythuitext.h:28
MythUIProgressDialog(const QString &message, MythScreenStack *parent, const char *name)
void Reset(void)
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:166
AllMusic * parent
MythScreenStack * GetStack(const QString &stackname)
unsigned int uint
Definition: compat.h:136
MythUIText * m_messageText
bool keyPressEvent(QKeyEvent *event)
Key event handler.
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
MythUIProgressBar * m_progressBar
static bool CopyWindowFromBase(const QString &windowname, MythScreenType *win)
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:146
virtual void Pulse(void)
Pulse is called 70 times a second to trigger a single frame of an animation.
Definition: mythuitype.cpp:456
const char * name
Definition: ParseText.cpp:338
MythUIBusyDialog(const QString &message, MythScreenStack *parent, const char *name)
MythMainWindow * GetMythMainWindow(void)
MythUIBusyDialog * ShowBusyPopup(const QString &message)
virtual bool keyPressEvent(QKeyEvent *)
Key event handler.
bool TranslateKeyPress(const QString &context, QKeyEvent *e, QStringList &actions, bool allowJumps=true) MUNUSED_RESULT
Get a list of actions for a keypress in the given context.
static const QString LOC
bool keyPressEvent(QKeyEvent *event)
Key event handler.
Screen in which all other widgets are contained and rendered.
virtual void Pulse(void)
Pulse is called 70 times a second to trigger a single frame of an animation.
Progress bar widget.