MythTV master
idlescreen.cpp
Go to the documentation of this file.
1// C++
2#include <chrono>
3
4// Ct
5#include <QTimer>
6
7// MythTV
17
18// MythFrontend
19#include "idlescreen.h"
20
21static constexpr std::chrono::milliseconds UPDATE_INTERVAL { 15s };
22
24 :MythScreenType(parent, "standbymode"),
25 m_updateScreenTimer(new QTimer(this))
26{
29
33}
34
36{
39
41 m_updateScreenTimer->disconnect();
42}
43
45{
46 // Load the theme for this screen
47 bool foundtheme = LoadWindowFromXML("status-ui.xml", "standbymode", this);
48 if (!foundtheme)
49 return false;
50
51 bool err = false;
52 UIUtilE::Assign(this, m_statusState, "backendstatus", &err);
53
54 /* currentrecording, nextrecording, conflicts and conflictwarning are optional */
55 UIUtilW::Assign(this, m_currentRecordings, "currentrecording");
56 UIUtilW::Assign(this, m_nextRecordings, "nextrecording");
57 UIUtilW::Assign(this, m_conflictingRecordings, "conflicts");
58 UIUtilW::Assign(this, m_conflictWarning, "conflictwarning");
59
60 if (err)
61 {
62 LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'standbymode'");
63 return false;
64 }
65
67
68 return true;
69}
70
72{
74}
75
77{
79}
80
82{
83 m_updateScreenTimer->stop();
84
85 bool bRes = false;
86
88 bRes = true;
89 else
90 {
92 bRes = true;
93 }
94
95 if (bRes)
97 else
98 m_updateScreenTimer->start(5s);
99
100 return bRes;
101}
102
104{
105 QString state = "idle";
106
108 {
109 if (m_secondsToShutdown >= 0s)
110 state = "shuttingdown";
111 else if (RemoteGetRecordingStatus())
112 state = "recording";
113 }
114 else
115 {
116 state = "offline";
117 }
118
120
121 MythUIType* shuttingdown = m_statusState->GetState("shuttingdown");
122
123 if (shuttingdown)
124 {
125 MythUIText *statusText = dynamic_cast<MythUIText *>(shuttingdown->GetChild("status"));
126
127 if (statusText)
128 {
129 if (m_secondsToShutdown >= 0s)
130 {
131 QString status = tr("Backend will shutdown in %n "
132 "second(s).", "", m_secondsToShutdown.count());
133
134 statusText->SetText(status);
135 }
136 else
137 {
138 statusText->Reset();
139 }
140 }
141 }
142}
143
145{
147 {
150 }
151
153 {
156 }
157
159 {
162 }
163
166
167 // update scheduled
168 if (!m_scheduledList.empty())
169 {
170 auto pit = m_scheduledList.begin();
171
172 while (pit != m_scheduledList.end())
173 {
174 ProgramInfo *progInfo = *pit;
175 if (progInfo)
176 {
177 MythUIButtonList *list = nullptr;
178 const RecStatus::Type recstatus = progInfo->GetRecordingStatus();
179
180 switch(recstatus)
181 {
185 list = m_currentRecordings;
186 break;
187
190 list = m_nextRecordings;
191 break;
192
195 break;
196
197 default:
198 list = nullptr;
199 break;
200 }
201
202 if (list != nullptr)
203 {
204 auto *item = new MythUIButtonListItem(list,"",
205 QVariant::fromValue(progInfo));
206
207 InfoMap infoMap;
208 progInfo->ToMap(infoMap);
209 item->SetTextFromMap(infoMap, "");
210 }
211 }
212 ++pit;
213 }
214 }
215
216 UpdateStatus();
217}
218
220{
221 {
222 // clear pending flag early in case something happens while
223 // we're updating
224 QMutexLocker lock(&m_schedUpdateMutex);
226 }
227
229
231 {
232 return false;
233 }
234
236 return false;
237
238 UpdateScreen();
239
240 return true;
241}
242
243bool IdleScreen::keyPressEvent(QKeyEvent* event)
244{
245 return MythScreenType::keyPressEvent(event);
246}
247
248void IdleScreen::customEvent(QEvent* event)
249{
250 if (event->type() == MythEvent::kMythEventMessage)
251 {
252 auto *me = dynamic_cast<MythEvent *>(event);
253 if (me == nullptr)
254 return;
255
256 if (me->Message().startsWith("RECONNECT_"))
257 {
259 UpdateStatus();
260 }
261 else if (me->Message().startsWith("SHUTDOWN_COUNTDOWN"))
262 {
263 QString secs = me->Message().mid(19);
264 m_secondsToShutdown = std::chrono::seconds(secs.toInt());
265 UpdateStatus();
266 }
267 else if (me->Message().startsWith("SHUTDOWN_NOW"))
268 {
270 {
271 // does the user want to shutdown this frontend only machine
272 // when the BE shuts down?
273 if (gCoreContext->GetNumSetting("ShutdownWithMasterBE", 0) == 1)
274 {
275 LOG(VB_GENERAL, LOG_NOTICE,
276 "Backend has gone offline, Shutting down frontend");
277 QString poweroff_cmd =
278 gCoreContext->GetSetting("MythShutdownPowerOff", "");
279 if (!poweroff_cmd.isEmpty())
280 myth_system(poweroff_cmd);
281 }
282 }
283 }
284 else if (me->Message().startsWith("SCHEDULE_CHANGE") ||
285 me->Message().startsWith("RECORDING_LIST_CHANGE") ||
286 me->Message() == "UPDATE_PROG_INFO")
287 {
288 QMutexLocker lock(&m_schedUpdateMutex);
289
290 if (!PendingSchedUpdate())
291 {
292 QTimer::singleShot(50ms, this, &IdleScreen::UpdateScheduledList);
294 }
295 }
296 }
297
299}
void clear(void)
iterator begin(void)
iterator end(void)
bool empty(void) const
~IdleScreen() override
Definition: idlescreen.cpp:35
bool UpdateScheduledList()
Definition: idlescreen.cpp:219
void Load(void) override
Load data which will ultimately be displayed on-screen or used to determine what appears on-screen (S...
Definition: idlescreen.cpp:71
void Init(void) override
Used after calling Load() to assign data to widgets and other UI initilisation which is prohibited in...
Definition: idlescreen.cpp:76
MythUIText * m_conflictWarning
Definition: idlescreen.h:45
bool CheckConnectionToServer(void)
Definition: idlescreen.cpp:81
void UpdateScreen(void)
Definition: idlescreen.cpp:144
std::chrono::seconds m_secondsToShutdown
Definition: idlescreen.h:47
bool Create(void) override
Definition: idlescreen.cpp:44
void UpdateStatus(void)
Definition: idlescreen.cpp:103
MythUIStateType * m_statusState
Definition: idlescreen.h:41
MythUIButtonList * m_conflictingRecordings
Definition: idlescreen.h:44
IdleScreen(MythScreenStack *parent)
Definition: idlescreen.cpp:23
bool m_hasConflicts
Definition: idlescreen.h:52
void customEvent(QEvent *e) override
Definition: idlescreen.cpp:248
void SetPendingSchedUpdate(bool newState)
Definition: idlescreen.h:37
MythUIButtonList * m_currentRecordings
Definition: idlescreen.h:42
QTimer * m_updateScreenTimer
Definition: idlescreen.h:39
ProgramList m_scheduledList
Definition: idlescreen.h:51
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: idlescreen.cpp:243
MythUIButtonList * m_nextRecordings
Definition: idlescreen.h:43
QMutex m_schedUpdateMutex
Definition: idlescreen.h:49
bool PendingSchedUpdate() const
Definition: idlescreen.h:36
bool IsConnectedToMaster(void)
bool SafeConnectToMasterServer(bool blockingClient=true, bool openEventSocket=true)
QString GetSetting(const QString &key, const QString &defaultval="")
bool IsFrontendOnly(void)
is there a frontend, but no backend, running on this host
int GetNumSetting(const QString &key, int defaultval=0)
This class is used as a container for messages.
Definition: mythevent.h:17
static const Type kMythEventMessage
Definition: mythevent.h:79
void ExitStandby(bool Manual=true)
void EnterStandby(bool Manual=true)
void addListener(QObject *listener)
Add a listener to the observable.
void removeListener(QObject *listener)
Remove a listener to the observable.
Screen in which all other widgets are contained and rendered.
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
virtual void Load(void)
Load data which will ultimately be displayed on-screen or used to determine what appears on-screen (S...
List widget, displays list items in a variety of themeable arrangements and can trigger signals when ...
void Reset() override
Reset the widget to it's original state, should not reset changes made by the theme.
MythUIType * GetState(const QString &name)
bool DisplayState(const QString &name)
All purpose text widget, displays a text string.
Definition: mythuitext.h:29
void Reset(void) override
Reset the widget to it's original state, should not reset changes made by the theme.
Definition: mythuitext.cpp:65
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:115
The base class on which all widgets and screens are based.
Definition: mythuitype.h:86
void SetCanTakeFocus(bool set=true)
Set whether this widget can take focus.
Definition: mythuitype.cpp:362
void customEvent(QEvent *event) override
virtual void SetVisible(bool visible)
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:138
Holds information on recordings and videos.
Definition: programinfo.h:68
virtual void ToMap(InfoMap &progMap, bool showrerecord=false, uint star_range=10, uint date_format=0) const
Converts ProgramInfo into QString QHash containing each field in ProgramInfo converted into localized...
RecStatus::Type GetRecordingStatus(void) const
Definition: programinfo.h:451
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
static constexpr std::chrono::milliseconds UPDATE_INTERVAL
Definition: idlescreen.cpp:21
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythMainWindow * GetMythMainWindow(void)
uint myth_system(const QString &command, uint flags, std::chrono::seconds timeout)
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
bool LoadFromScheduler(AutoDeleteDeque< TYPE * > &destination, bool &hasConflicts, const QString &altTable="", int recordid=-1)
Definition: programinfo.h:937
int RemoteGetRecordingStatus(const ProgramInfo *pginfo, int overrecsecs, int underrecsecs)
Get status of an individual programme (with pre-post roll?).
Definition: remoteutil.cpp:505
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition: mythuiutils.h:27