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 {
89 bRes = true;
90 }
91 else
92 {
94 bRes = true;
95 }
96
97 if (bRes)
99 else
100 m_updateScreenTimer->start(5s);
101
102 return bRes;
103}
104
106{
107 QString state = "idle";
108
110 {
111 if (m_secondsToShutdown >= 0s)
112 state = "shuttingdown";
113 else if (RemoteGetRecordingStatus())
114 state = "recording";
115 }
116 else
117 {
118 state = "offline";
119 }
120
122
123 MythUIType* shuttingdown = m_statusState->GetState("shuttingdown");
124
125 if (shuttingdown)
126 {
127 MythUIText *statusText = dynamic_cast<MythUIText *>(shuttingdown->GetChild("status"));
128
129 if (statusText)
130 {
131 if (m_secondsToShutdown >= 0s)
132 {
133 QString status = tr("Backend will shutdown in %n "
134 "second(s).", "", m_secondsToShutdown.count());
135
136 statusText->SetText(status);
137 }
138 else
139 {
140 statusText->Reset();
141 }
142 }
143 }
144}
145
147{
149 {
152 }
153
155 {
158 }
159
161 {
164 }
165
168
169 // update scheduled
170 if (!m_scheduledList.empty())
171 {
172 auto pit = m_scheduledList.begin();
173
174 while (pit != m_scheduledList.end())
175 {
176 ProgramInfo *progInfo = *pit;
177 if (progInfo)
178 {
179 MythUIButtonList *list = nullptr;
180 const RecStatus::Type recstatus = progInfo->GetRecordingStatus();
181
182 switch(recstatus)
183 {
187 list = m_currentRecordings;
188 break;
189
192 list = m_nextRecordings;
193 break;
194
197 break;
198
199 default:
200 list = nullptr;
201 break;
202 }
203
204 if (list != nullptr)
205 {
206 auto *item = new MythUIButtonListItem(list,"",
207 QVariant::fromValue(progInfo));
208
209 InfoMap infoMap;
210 progInfo->ToMap(infoMap);
211 item->SetTextFromMap(infoMap, "");
212 }
213 }
214 ++pit;
215 }
216 }
217
218 UpdateStatus();
219}
220
222{
223 {
224 // clear pending flag early in case something happens while
225 // we're updating
226 QMutexLocker lock(&m_schedUpdateMutex);
228 }
229
231
233 {
234 return false;
235 }
236
238 return false;
239
240 UpdateScreen();
241
242 return true;
243}
244
245bool IdleScreen::keyPressEvent(QKeyEvent* event)
246{
247 return MythScreenType::keyPressEvent(event);
248}
249
250void IdleScreen::customEvent(QEvent* event)
251{
252 if (event->type() == MythEvent::kMythEventMessage)
253 {
254 auto *me = dynamic_cast<MythEvent *>(event);
255 if (me == nullptr)
256 return;
257
258 if (me->Message().startsWith("RECONNECT_"))
259 {
261 UpdateStatus();
262 }
263 else if (me->Message().startsWith("SHUTDOWN_COUNTDOWN"))
264 {
265 QString secs = me->Message().mid(19);
266 m_secondsToShutdown = std::chrono::seconds(secs.toInt());
267 UpdateStatus();
268 }
269 else if (me->Message().startsWith("SHUTDOWN_NOW"))
270 {
272 {
273 // does the user want to shutdown this frontend only machine
274 // when the BE shuts down?
275 if (gCoreContext->GetNumSetting("ShutdownWithMasterBE", 0) == 1)
276 {
277 LOG(VB_GENERAL, LOG_NOTICE,
278 "Backend has gone offline, Shutting down frontend");
279 QString poweroff_cmd =
280 gCoreContext->GetSetting("MythShutdownPowerOff", "");
281 if (!poweroff_cmd.isEmpty())
282 myth_system(poweroff_cmd);
283 }
284 }
285 }
286 else if (me->Message().startsWith("SCHEDULE_CHANGE") ||
287 me->Message().startsWith("RECORDING_LIST_CHANGE") ||
288 me->Message() == "UPDATE_PROG_INFO")
289 {
290 QMutexLocker lock(&m_schedUpdateMutex);
291
292 if (!PendingSchedUpdate())
293 {
294 QTimer::singleShot(50ms, this, &IdleScreen::UpdateScheduledList);
296 }
297 }
298 }
299
301}
void clear(void)
iterator begin(void)
iterator end(void)
bool empty(void) const
~IdleScreen() override
Definition: idlescreen.cpp:35
bool UpdateScheduledList()
Definition: idlescreen.cpp:221
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:44
bool CheckConnectionToServer(void)
Definition: idlescreen.cpp:81
void UpdateScreen(void)
Definition: idlescreen.cpp:146
std::chrono::seconds m_secondsToShutdown
Definition: idlescreen.h:46
bool Create(void) override
Definition: idlescreen.cpp:44
void UpdateStatus(void)
Definition: idlescreen.cpp:105
MythUIStateType * m_statusState
Definition: idlescreen.h:40
MythUIButtonList * m_conflictingRecordings
Definition: idlescreen.h:43
IdleScreen(MythScreenStack *parent)
Definition: idlescreen.cpp:23
bool m_hasConflicts
Definition: idlescreen.h:51
void customEvent(QEvent *e) override
Definition: idlescreen.cpp:250
void SetPendingSchedUpdate(bool newState)
Definition: idlescreen.h:36
MythUIButtonList * m_currentRecordings
Definition: idlescreen.h:41
QTimer * m_updateScreenTimer
Definition: idlescreen.h:38
ProgramList m_scheduledList
Definition: idlescreen.h:50
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: idlescreen.cpp:245
MythUIButtonList * m_nextRecordings
Definition: idlescreen.h:42
QMutex m_schedUpdateMutex
Definition: idlescreen.h:48
bool PendingSchedUpdate() const
Definition: idlescreen.h:35
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:97
void SetCanTakeFocus(bool set=true)
Set whether this widget can take focus.
Definition: mythuitype.cpp:348
void customEvent(QEvent *event) override
Definition: mythuitype.cpp:989
virtual void SetVisible(bool visible)
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:130
Holds information on recordings and videos.
Definition: programinfo.h:74
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:458
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:945
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition: mythuiutils.h:27
bool RemoteGetRecordingStatus(std::vector< TunerStatus > *tunerList, bool list_inactive)