MythTV master
mythprogressdialog.cpp
Go to the documentation of this file.
1
2
4
5// libmythbase headers
7
8// libmythui headers
9#include "mythuitext.h"
10#include "mythuiprogressbar.h"
11
12const 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
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
45void 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
71bool 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
97MythUIBusyDialog *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 {
110 s_stk = win->GetStack("popup stack");
111 }
112 else
113 {
114 LOG(VB_GENERAL, LOG_ERR, LOC + "no main window?");
115 return nullptr;
116 }
117
118 if (!s_stk)
119 {
120 LOG(VB_GENERAL, LOG_ERR, LOC + "no popup stack? "
121 "Is there a MythThemeBase?");
122 return nullptr;
123 }
124 }
125
126 pop = new MythUIBusyDialog(message, s_stk, "showBusyPopup");
127 if (pop->Create())
128 s_stk->AddScreen(pop);
129
130 return pop;
131}
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 const QString& action = actions[i];
157 handled = true;
158
159 if (action == "ESCAPE")
160 {
161 // eat the escape keypress
162 }
163 else
164 {
165 handled = false;
166 }
167 }
168
169 if (!handled && MythScreenType::keyPressEvent(event))
170 handled = true;
171
172 return handled;
173}
174
176{
177 if (event->type() == ProgressUpdateEvent::kEventType)
178 {
179 auto *pue = dynamic_cast<ProgressUpdateEvent*>(event);
180 if (!pue)
181 {
182 LOG(VB_GENERAL, LOG_ERR,
183 "Error, event claims to be a progress update but fails "
184 "to cast");
185 return;
186 }
187
188 QString message = pue->GetMessage();
189 if (!message.isEmpty())
190 m_message = message;
191 uint total = pue->GetTotal();
192 if (total > 0)
193 m_total = total;
194 m_count = pue->GetCount();
196 }
197}
198
200{
201 m_total = total;
203}
204
206{
207 m_count = count;
209}
210
211void MythUIProgressDialog::SetMessage(const QString &message)
212{
213 m_message = message;
215}
216
218{
219 if (m_messageText)
221
222 if (m_total == 0)
223 return;
224
225 if (m_count > m_total)
226 {
227 LOG(VB_GENERAL, LOG_ERR, QString("Progress count (%1) is higher "
228 "than total (%2)")
229 .arg(m_count) .arg(m_total));
230 return;
231 }
232
233 if (m_progressBar)
234 {
237 }
238
239 uint percentage = (uint)(((float)m_count/(float)m_total) * 100.0F);
240
241 if (m_progressText)
242 m_progressText->SetText(QString("%1%").arg(percentage));
243}
bool TranslateKeyPress(const QString &Context, QKeyEvent *Event, QStringList &Actions, bool AllowJumps=true)
Get a list of actions for a keypress in the given context.
MythScreenStack * GetStack(const QString &Stackname)
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Screen in which all other widgets are contained and rendered.
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
MythUIText * m_messageText
MythUIBusyDialog(const QString &message, MythScreenStack *parent, const char *name)
bool Create(void) override
void Pulse(void) override
Pulse is called 70 times a second to trigger a single frame of an animation.
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
void Reset(void) override
Reset the widget to it's original state, should not reset changes made by the theme.
void SetMessage(const QString &message)
Progress bar widget.
void SetUsed(int value)
void SetTotal(int value)
void customEvent(QEvent *event) override
MythUIProgressBar * m_progressBar
bool Create(void) override
void SetProgress(uint count)
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
void SetMessage(const QString &message)
All purpose text widget, displays a text string.
Definition: mythuitext.h:29
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:115
virtual void Pulse(void)
Pulse is called 70 times a second to trigger a single frame of an animation.
Definition: mythuitype.cpp:442
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:130
static const Type kEventType
static bool CopyWindowFromBase(const QString &windowname, MythScreenType *win)
unsigned int uint
Definition: compat.h:60
#define LOC
Definition: mythcontext.cpp:75
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythMainWindow * GetMythMainWindow(void)
MythUIBusyDialog * ShowBusyPopup(const QString &message)
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:80