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