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 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  statusText->Reset();
137  }
138  }
139 }
140 
142 {
144  {
147  }
148 
149  if (m_nextRecordings)
150  {
153  }
154 
156  {
159  }
160 
161  if (m_conflictWarning)
163 
164  // update scheduled
165  if (!m_scheduledList.empty())
166  {
167  auto pit = m_scheduledList.begin();
168 
169  while (pit != m_scheduledList.end())
170  {
171  ProgramInfo *progInfo = *pit;
172  if (progInfo)
173  {
174  MythUIButtonList *list = nullptr;
175  const RecStatus::Type recstatus = progInfo->GetRecordingStatus();
176 
177  switch(recstatus)
178  {
180  case RecStatus::Tuning:
181  case RecStatus::Failing:
182  list = m_currentRecordings;
183  break;
184 
186  case RecStatus::Pending:
187  list = m_nextRecordings;
188  break;
189 
190  case RecStatus::Conflict:
192  break;
193 
194  default:
195  list = nullptr;
196  break;
197  }
198 
199  if (list != nullptr)
200  {
201  auto *item = new MythUIButtonListItem(list,"",
202  QVariant::fromValue(progInfo));
203 
204  InfoMap infoMap;
205  progInfo->ToMap(infoMap);
206  item->SetTextFromMap(infoMap, "");
207  }
208  }
209  ++pit;
210  }
211  }
212 
213  UpdateStatus();
214 }
215 
217 {
218  {
219  // clear pending flag early in case something happens while
220  // we're updating
221  QMutexLocker lock(&m_schedUpdateMutex);
222  SetPendingSchedUpdate(false);
223  }
224 
226 
228  {
229  return false;
230  }
231 
233  return false;
234 
235  UpdateScreen();
236 
237  return true;
238 }
239 
240 bool IdleScreen::keyPressEvent(QKeyEvent* event)
241 {
242  return MythScreenType::keyPressEvent(event);
243 }
244 
245 void IdleScreen::customEvent(QEvent* event)
246 {
247  if (event->type() == MythEvent::MythEventMessage)
248  {
249  auto *me = dynamic_cast<MythEvent *>(event);
250  if (me == nullptr)
251  return;
252 
253  if (me->Message().startsWith("RECONNECT_"))
254  {
255  m_secondsToShutdown = -1s;
256  UpdateStatus();
257  }
258  else if (me->Message().startsWith("SHUTDOWN_COUNTDOWN"))
259  {
260  QString secs = me->Message().mid(19);
261  m_secondsToShutdown = std::chrono::seconds(secs.toInt());
262  UpdateStatus();
263  }
264  else if (me->Message().startsWith("SHUTDOWN_NOW"))
265  {
267  {
268  // does the user want to shutdown this frontend only machine
269  // when the BE shuts down?
270  if (gCoreContext->GetNumSetting("ShutdownWithMasterBE", 0) == 1)
271  {
272  LOG(VB_GENERAL, LOG_NOTICE,
273  "Backend has gone offline, Shutting down frontend");
274  QString poweroff_cmd =
275  gCoreContext->GetSetting("MythShutdownPowerOff", "");
276  if (!poweroff_cmd.isEmpty())
277  myth_system(poweroff_cmd);
278  }
279  }
280  }
281  else if (me->Message().startsWith("SCHEDULE_CHANGE") ||
282  me->Message().startsWith("RECORDING_LIST_CHANGE") ||
283  me->Message() == "UPDATE_PROG_INFO")
284  {
285  QMutexLocker lock(&m_schedUpdateMutex);
286 
287  if (!PendingSchedUpdate())
288  {
289  QTimer::singleShot(50ms, this, &IdleScreen::UpdateScheduledList);
290  SetPendingSchedUpdate(true);
291  }
292  }
293  }
294 
296 }
IdleScreen::UpdateScreen
void UpdateScreen(void)
Definition: idlescreen.cpp:141
RecStatus::Type
Type
Definition: recStatus.h:16
MythEvent::MythEventMessage
static Type MythEventMessage
Definition: mythevent.h:78
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:43
LoadFromScheduler
bool LoadFromScheduler(AutoDeleteDeque< TYPE * > &destination, bool &hasConflicts, const QString &altTable="", int recordid=-1)
Definition: programinfo.h:894
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:83
MythCoreContext::IsFrontendOnly
bool IsFrontendOnly(void)
is there a frontend, but no backend, running on this host
Definition: mythcorecontext.cpp:769
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: 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: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: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:44
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:502
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:280
mythuibuttonlist.h
MythCoreContext::SafeConnectToMasterServer
bool SafeConnectToMasterServer(bool blockingClient=true, bool openEventSocket=true)
Definition: mythcorecontext.cpp:370
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:614
MythUIButtonListItem
Definition: mythuibuttonlist.h:27
IdleScreen::customEvent
void customEvent(QEvent *e) override
Definition: idlescreen.cpp:245
programinfo.h
IdleScreen::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: idlescreen.cpp:240
ProgramInfo::GetRecordingStatus
RecStatus::Type GetRecordingStatus(void) const
Definition: programinfo.h:446
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:498
IdleScreen::IdleScreen
IdleScreen(MythScreenStack *parent)
Definition: idlescreen.cpp:22
RecStatus::Failing
@ Failing
Definition: recStatus.h:18
RecStatus::Conflict
@ Conflict
Definition: recStatus.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:1560
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:60
AutoDeleteDeque::end
iterator end(void)
Definition: autodeletedeque.h:51
MythCoreContext::GetNumSetting
int GetNumSetting(const QString &key, int defaultval=0)
Definition: mythcorecontext.cpp:936
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:84
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:67
MythUIText
All purpose text widget, displays a text string.
Definition: mythuitext.h:30
MythScreenType::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: mythscreentype.cpp:397
IdleScreen::m_statusState
MythUIStateType * m_statusState
Definition: idlescreen.h:41
RecStatus::Recording
@ Recording
Definition: recStatus.h:30
MythMainWindow::EnterStandby
void EnterStandby(bool Manual=true)
Definition: mythmainwindow.cpp:2170
XMLParseBase::LoadWindowFromXML
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
Definition: xmlparsebase.cpp:692
IdleScreen::UpdateScheduledList
bool UpdateScheduledList()
Definition: idlescreen.cpp:216
MythUIText::SetText
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:133
MythUIType::SetVisible
virtual void SetVisible(bool visible)
Definition: mythuitype.cpp:1086
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:114
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:151
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:2205
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:922