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
8 #include "libmyth/mythcontext.h"
11 #include "libmythtv/tvremoteutil.h"
15 #include "libmythui/mythuitext.h"
16 
17 // MythFrontend
18 #include "idlescreen.h"
19 
20 static constexpr std::chrono::milliseconds UPDATE_INTERVAL { 15s };
21 
23  :MythScreenType(parent, "standbymode"),
24  m_updateScreenTimer(new QTimer(this))
25 {
28 
32 }
33 
35 {
38 
40  m_updateScreenTimer->disconnect();
41 }
42 
44 {
45  // Load the theme for this screen
46  bool foundtheme = LoadWindowFromXML("status-ui.xml", "standbymode", this);
47  if (!foundtheme)
48  return false;
49 
50  bool err = false;
51  UIUtilE::Assign(this, m_statusState, "backendstatus", &err);
52 
53  /* currentrecording, nextrecording, conflicts and conflictwarning are optional */
54  UIUtilW::Assign(this, m_currentRecordings, "currentrecording");
55  UIUtilW::Assign(this, m_nextRecordings, "nextrecording");
56  UIUtilW::Assign(this, m_conflictingRecordings, "conflicts");
57  UIUtilW::Assign(this, m_conflictWarning, "conflictwarning");
58 
59  if (err)
60  {
61  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'standbymode'");
62  return false;
63  }
64 
66 
67  return true;
68 }
69 
70 void IdleScreen::Load(void)
71 {
73 }
74 
75 void IdleScreen::Init(void)
76 {
77  UpdateScreen();
78 }
79 
81 {
82  m_updateScreenTimer->stop();
83 
84  bool bRes = false;
85 
87  bRes = true;
88  else
89  {
91  bRes = true;
92  }
93 
94  if (bRes)
96  else
97  m_updateScreenTimer->start(5s);
98 
99  return bRes;
100 }
101 
103 {
104  QString state = "idle";
105 
107  {
108  if (m_secondsToShutdown >= 0s)
109  state = "shuttingdown";
110  else if (RemoteGetRecordingStatus())
111  state = "recording";
112  }
113  else
114  {
115  state = "offline";
116  }
117 
118  m_statusState->DisplayState(state);
119 
120  MythUIType* shuttingdown = m_statusState->GetState("shuttingdown");
121 
122  if (shuttingdown)
123  {
124  MythUIText *statusText = dynamic_cast<MythUIText *>(shuttingdown->GetChild("status"));
125 
126  if (statusText)
127  {
128  if (m_secondsToShutdown >= 0s)
129  {
130  QString status = tr("Backend will shutdown in %n "
131  "second(s).", "", m_secondsToShutdown.count());
132 
133  statusText->SetText(status);
134  }
135  else
136  {
137  statusText->Reset();
138  }
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::kMythEventMessage)
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 = -1s;
258  UpdateStatus();
259  }
260  else if (me->Message().startsWith("SHUTDOWN_COUNTDOWN"))
261  {
262  QString secs = me->Message().mid(19);
263  m_secondsToShutdown = std::chrono::seconds(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: recordingstatus.h:16
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:102
IdleScreen::m_hasConflicts
bool m_hasConflicts
Definition: idlescreen.h:52
mythuitext.h
IdleScreen::SetPendingSchedUpdate
void SetPendingSchedUpdate(bool newState)
Definition: idlescreen.h:37
MythEvent::kMythEventMessage
static const Type kMythEventMessage
Definition: mythevent.h:79
IdleScreen::Create
bool Create(void) override
Definition: idlescreen.cpp:43
LoadFromScheduler
bool LoadFromScheduler(AutoDeleteDeque< TYPE * > &destination, bool &hasConflicts, const QString &altTable="", int recordid=-1)
Definition: programinfo.h:937
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:65
MythCoreContext::IsFrontendOnly
bool IsFrontendOnly(void)
is there a frontend, but no backend, running on this host
Definition: mythcorecontext.cpp:749
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:70
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: recordingstatus.h:22
MythUIType::GetChild
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:138
AutoDeleteDeque::clear
void clear(void)
Definition: autodeletedeque.h:40
MythEvent
This class is used as a container for messages.
Definition: mythevent.h:16
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:362
MythUIType::customEvent
void customEvent(QEvent *event) override
Definition: mythuitype.cpp:1003
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
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
myth_system
uint myth_system(const QString &command, uint flags, std::chrono::seconds timeout)
Definition: mythsystemlegacy.cpp:506
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:278
mythuibuttonlist.h
MythCoreContext::SafeConnectToMasterServer
bool SafeConnectToMasterServer(bool blockingClient=true, bool openEventSocket=true)
Definition: mythcorecontext.cpp:346
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: recordingstatus.h:31
MythCoreContext::IsConnectedToMaster
bool IsConnectedToMaster(void)
Definition: mythcorecontext.cpp:594
MythUIButtonListItem
Definition: mythuibuttonlist.h:41
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:451
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:505
IdleScreen::IdleScreen
IdleScreen(MythScreenStack *parent)
Definition: idlescreen.cpp:22
RecStatus::Failing
@ Failing
Definition: recordingstatus.h:18
RecStatus::Conflict
@ Conflict
Definition: recordingstatus.h:39
ProgramInfo::ToMap
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...
Definition: programinfo.cpp:1588
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:75
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:55
AutoDeleteDeque::end
iterator end(void)
Definition: autodeletedeque.h:51
MythCoreContext::GetNumSetting
int GetNumSetting(const QString &key, int defaultval=0)
Definition: mythcorecontext.cpp:916
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:80
tvremoteutil.h
MythUIType
The base class on which all widgets and screens are based.
Definition: mythuitype.h:85
RecStatus::Pending
@ Pending
Definition: recordingstatus.h:17
IdleScreen::m_scheduledList
ProgramList m_scheduledList
Definition: idlescreen.h:51
ProgramInfo
Holds information on recordings and videos.
Definition: programinfo.h:67
MythUIText
All purpose text widget, displays a text string.
Definition: mythuitext.h:28
MythScreenType::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: mythscreentype.cpp:401
IdleScreen::m_statusState
MythUIStateType * m_statusState
Definition: idlescreen.h:41
RecStatus::Recording
@ Recording
Definition: recordingstatus.h:30
MythMainWindow::EnterStandby
void EnterStandby(bool Manual=true)
Definition: mythmainwindow.cpp:2197
XMLParseBase::LoadWindowFromXML
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
Definition: xmlparsebase.cpp:701
IdleScreen::UpdateScheduledList
bool UpdateScheduledList()
Definition: idlescreen.cpp:218
MythUIText::SetText
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:115
MythUIType::SetVisible
virtual void SetVisible(bool visible)
Definition: mythuitype.cpp:1105
mythcontext.h
MythUIButtonList::Reset
void Reset() override
Reset the widget to it's original state, should not reset changes made by the theme.
Definition: mythuibuttonlist.cpp:116
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:104
IdleScreen::m_nextRecordings
MythUIButtonList * m_nextRecordings
Definition: idlescreen.h:43
IdleScreen::~IdleScreen
~IdleScreen() override
Definition: idlescreen.cpp:34
IdleScreen::UpdateStatus
void UpdateStatus(void)
Definition: idlescreen.cpp:102
IdleScreen::m_schedUpdateMutex
QMutex m_schedUpdateMutex
Definition: idlescreen.h:49
MythUIButtonList
List widget, displays list items in a variety of themeable arrangements and can trigger signals when ...
Definition: mythuibuttonlist.h:191
mythmainwindow.h
UPDATE_INTERVAL
static constexpr std::chrono::milliseconds UPDATE_INTERVAL
Definition: idlescreen.cpp:20
MythMainWindow::ExitStandby
void ExitStandby(bool Manual=true)
Definition: mythmainwindow.cpp:2232
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
IdleScreen::m_secondsToShutdown
std::chrono::seconds m_secondsToShutdown
Definition: idlescreen.h:47
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:902