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 // MythTV headers
2 #include "mythprogressdialog.h"
3 #include "mythlogging.h"
4 
6  (QEvent::Type) QEvent::registerEventType();
7 
8 MythUIBusyDialog::MythUIBusyDialog(const QString &message,
9  MythScreenStack *parent, const char *name)
10  : MythScreenType(parent, name, false),
11  m_haveNewMessage(false), m_messageText(NULL)
12 {
13  if (!message.isEmpty())
14  m_message = message;
15  else
16  m_message = tr("Please Wait...");
18 }
19 
21 {
22  if (!CopyWindowFromBase("MythBusyDialog", this))
23  return false;
24 
25  m_messageText = dynamic_cast<MythUIText *>(GetChild("message"));
26 
27  if (m_messageText)
29 
30  return true;
31 }
32 
33 void MythUIBusyDialog::SetMessage(const QString &message)
34 {
35  m_newMessageLock.lock();
36  m_newMessage = message;
37  m_haveNewMessage = true;
38  m_newMessageLock.unlock();
39 }
40 
42 {
44 }
45 
47 {
49  {
50  m_newMessageLock.lock();
53  m_newMessageLock.unlock();
54  }
55 
57 }
58 
59 bool MythUIBusyDialog::keyPressEvent(QKeyEvent *event)
60 {
61  QStringList actions;
62  bool handled = GetMythMainWindow()->TranslateKeyPress("qt", event, actions, false);
63 
64  for (int i = 0; i < actions.size() && !handled; i++)
65  {
66  QString action = actions[i];
67  handled = true;
68 
69  if (action == "ESCAPE")
70  {
71  // eat the escape keypress
72  }
73  else
74  handled = false;
75  }
76 
77  if (!handled && MythScreenType::keyPressEvent(event))
78  handled = true;
79 
80  return handled;
81 }
82 
83 MythUIBusyDialog *ShowBusyPopup(const QString &message)
84 {
85  QString LOC = "ShowBusyPopup('" + message + "') - ";
86  MythUIBusyDialog *pop = NULL;
87  static MythScreenStack *stk = NULL;
88 
89 
90  if (!stk)
91  {
93 
94  if (win)
95  stk = win->GetStack("popup stack");
96  else
97  {
98  LOG(VB_GENERAL, LOG_ERR, LOC + "no main window?");
99  return NULL;
100  }
101 
102  if (!stk)
103  {
104  LOG(VB_GENERAL, LOG_ERR, LOC + "no popup stack? "
105  "Is there a MythThemeBase?");
106  return NULL;
107  }
108  }
109 
110  pop = new MythUIBusyDialog(message, stk, "showBusyPopup");
111  if (pop->Create())
112  stk->AddScreen(pop);
113 
114  return pop;
115 }
116 //---------------------------------------------------------
117 
119  MythScreenStack *parent, const char *name)
120  : MythScreenType(parent, name, false),
121  m_total(0), m_count(0),
122  m_messageText(NULL), m_progressText(NULL), m_progressBar(NULL)
123 {
124  m_message = message;
125 }
126 
128 {
129  if (!CopyWindowFromBase("MythProgressDialog", this))
130  return false;
131 
132  m_messageText = dynamic_cast<MythUIText *>(GetChild("message"));
133  m_progressText = dynamic_cast<MythUIText *>(GetChild("progresstext"));
134  m_progressBar = dynamic_cast<MythUIProgressBar *>(GetChild("progressbar"));
135 
136  if (m_messageText)
138 
139  return true;
140 }
141 
143 {
144  QStringList actions;
145  bool handled = GetMythMainWindow()->TranslateKeyPress("qt", event, actions, false);
146 
147  for (int i = 0; i < actions.size() && !handled; i++)
148  {
149  QString action = actions[i];
150  handled = true;
151 
152  if (action == "ESCAPE")
153  {
154  // eat the escape keypress
155  }
156  else
157  handled = false;
158  }
159 
160  if (!handled && MythScreenType::keyPressEvent(event))
161  handled = true;
162 
163  return handled;
164 }
165 
167 {
168  if (event->type() == ProgressUpdateEvent::kEventType)
169  {
170  ProgressUpdateEvent *pue = dynamic_cast<ProgressUpdateEvent*>(event);
171 
172  if (!pue)
173  {
174  LOG(VB_GENERAL, LOG_ERR,
175  "Error, event claims to be a progress update but fails "
176  "to cast");
177  return;
178  }
179 
180  QString message = pue->GetMessage();
181  if (!message.isEmpty())
182  m_message = message;
183  uint total = pue->GetTotal();
184  if (total > 0)
185  m_total = total;
186  m_count = pue->GetCount();
187  UpdateProgress();
188  }
189 }
190 
192 {
193  m_total = total;
194  UpdateProgress();
195 }
196 
198 {
199  m_count = count;
200  UpdateProgress();
201 }
202 
203 void MythUIProgressDialog::SetMessage(const QString &message)
204 {
205  m_message = message;
206  UpdateProgress();
207 }
208 
210 {
211  if (m_messageText)
213 
214  if (m_total == 0)
215  return;
216 
217  if (m_count > m_total)
218  {
219  LOG(VB_GENERAL, LOG_ERR, QString("Progress count (%1) is higher "
220  "than total (%2)")
221  .arg(m_count) .arg(m_total));
222  return;
223  }
224 
225  if (m_progressBar)
226  {
229  }
230 
231  uint percentage = (uint)(((float)m_count/(float)m_total) * 100.0);
232 
233  if (m_progressText)
234  m_progressText->SetText(QString("%1%").arg(percentage));
235 }
void SetMessage(const QString &message)
void SetMessage(const QString &message)
void customEvent(QEvent *event)
void SetProgress(uint count)
All purpose text widget, displays a text string.
Definition: mythuitext.h:27
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:135
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:83
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:143
virtual void Pulse(void)
Pulse is called 70 times a second to trigger a single frame of an animation.
Definition: mythuitype.cpp:453
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.