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 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();
194 }
195}
196
198{
199 m_total = total;
201}
202
204{
205 m_count = count;
207}
208
209void MythUIProgressDialog::SetMessage(const QString &message)
210{
211 m_message = message;
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}
#define LOC
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:456
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:138
static const Type kEventType
static bool CopyWindowFromBase(const QString &windowname, MythScreenType *win)
unsigned int uint
Definition: freesurround.h:24
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythMainWindow * GetMythMainWindow(void)
MythUIBusyDialog * ShowBusyPopup(const QString &message)
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:89