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