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))
23 {
26 
27  connect(m_updateScreenTimer, SIGNAL(timeout()),
28  this, SLOT(UpdateScreen()));
30 }
31 
33 {
36 
38  m_updateScreenTimer->disconnect();
39 }
40 
42 {
43  // Load the theme for this screen
44  bool foundtheme = LoadWindowFromXML("status-ui.xml", "standbymode", this);
45  if (!foundtheme)
46  return false;
47 
48  bool err = false;
49  UIUtilE::Assign(this, m_statusState, "backendstatus", &err);
50 
51  /* currentrecording, nextrecording, conflicts and conflictwarning are optional */
52  UIUtilW::Assign(this, m_currentRecordings, "currentrecording");
53  UIUtilW::Assign(this, m_nextRecordings, "nextrecording");
54  UIUtilW::Assign(this, m_conflictingRecordings, "conflicts");
55  UIUtilW::Assign(this, m_conflictWarning, "conflictwarning");
56 
57  if (err)
58  {
59  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'standbymode'");
60  return false;
61  }
62 
64 
65  return true;
66 }
67 
68 void IdleScreen::Load(void)
69 {
71 }
72 
73 void IdleScreen::Init(void)
74 {
75  UpdateScreen();
76 }
77 
79 {
80  m_updateScreenTimer->stop();
81 
82  bool bRes = false;
83 
85  bRes = true;
86  else
87  {
89  bRes = true;
90  }
91 
92  if (bRes)
94  else
95  m_updateScreenTimer->start(5000);
96 
97  return bRes;
98 }
99 
101 {
102  QString state = "idle";
103 
105  {
106  if (m_secondsToShutdown >= 0)
107  state = "shuttingdown";
108  else if (RemoteGetRecordingStatus())
109  state = "recording";
110  }
111  else
112  {
113  state = "offline";
114  }
115 
116  m_statusState->DisplayState(state);
117 
118  MythUIType* shuttingdown = m_statusState->GetState("shuttingdown");
119 
120  if (shuttingdown)
121  {
122  MythUIText *statusText = dynamic_cast<MythUIText *>(shuttingdown->GetChild("status"));
123 
124  if (statusText)
125  {
126  if (m_secondsToShutdown >= 0)
127  {
128  QString status = tr("Backend will shutdown in %n "
129  "second(s).", "", m_secondsToShutdown);
130 
131  statusText->SetText(status);
132  }
133  else
134  statusText->Reset();
135  }
136  }
137 }
138 
140 {
142  {
145  }
146 
147  if (m_nextRecordings)
148  {
151  }
152 
154  {
157  }
158 
159  if (m_conflictWarning)
161 
162  // update scheduled
163  if (!m_scheduledList.empty())
164  {
166  MythUIButtonListItem *item;
167 
168  while (pit != m_scheduledList.end())
169  {
170  ProgramInfo *progInfo = *pit;
171  if (progInfo)
172  {
173  MythUIButtonList *list = nullptr;
174  const RecStatus::Type recstatus = progInfo->GetRecordingStatus();
175 
176  switch(recstatus)
177  {
179  case RecStatus::Tuning:
180  case RecStatus::Failing:
181  list = m_currentRecordings;
182  break;
183 
185  case RecStatus::Pending:
186  list = m_nextRecordings;
187  break;
188 
189  case RecStatus::Conflict:
191  break;
192 
193  default:
194  list = nullptr;
195  break;
196  }
197 
198  if (list != nullptr)
199  {
200  item = new MythUIButtonListItem(list,"",
201  qVariantFromValue(progInfo));
202 
203  InfoMap infoMap;
204  progInfo->ToMap(infoMap);
205  item->SetTextFromMap(infoMap, "");
206  }
207  }
208  ++pit;
209  }
210  }
211 
212  UpdateStatus();
213 }
214 
216 {
217  {
218  // clear pending flag early in case something happens while
219  // we're updating
220  QMutexLocker lock(&m_schedUpdateMutex);
221  SetPendingSchedUpdate(false);
222  }
223 
225 
227  {
228  return false;
229  }
230 
232  return false;
233 
234  UpdateScreen();
235 
236  return true;
237 }
238 
239 bool IdleScreen::keyPressEvent(QKeyEvent* event)
240 {
241  return MythScreenType::keyPressEvent(event);
242 }
243 
244 void IdleScreen::customEvent(QEvent* event)
245 {
246  if (event->type() == MythEvent::MythEventMessage)
247  {
248  MythEvent *me = static_cast<MythEvent *>(event);
249 
250  if (me->Message().startsWith("RECONNECT_"))
251  {
252  m_secondsToShutdown = -1;
253  UpdateStatus();
254  }
255  else if (me->Message().startsWith("SHUTDOWN_COUNTDOWN"))
256  {
257  QString secs = me->Message().mid(19);
258  m_secondsToShutdown = secs.toInt();
259  UpdateStatus();
260  }
261  else if (me->Message().startsWith("SHUTDOWN_NOW"))
262  {
264  {
265  // does the user want to shutdown this frontend only machine
266  // when the BE shuts down?
267  if (gCoreContext->GetNumSetting("ShutdownWithMasterBE", 0) == 1)
268  {
269  LOG(VB_GENERAL, LOG_NOTICE,
270  "Backend has gone offline, Shutting down frontend");
271  QString poweroff_cmd =
272  gCoreContext->GetSetting("MythShutdownPowerOff", "");
273  if (!poweroff_cmd.isEmpty())
274  myth_system(poweroff_cmd);
275  }
276  }
277  }
278  else if (me->Message().startsWith("SCHEDULE_CHANGE") ||
279  me->Message().startsWith("RECORDING_LIST_CHANGE") ||
280  me->Message() == "UPDATE_PROG_INFO")
281  {
282  QMutexLocker lock(&m_schedUpdateMutex);
283 
284  if (!PendingSchedUpdate())
285  {
286  QTimer::singleShot(50, this, SLOT(UpdateScheduledList()));
287  SetPendingSchedUpdate(true);
288  }
289  }
290  }
291 
293 }
virtual ~IdleScreen()
Definition: idlescreen.cpp:32
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:977
static Type MythEventMessage
Definition: mythevent.h:66
void removeListener(QObject *listener)
Remove a listener to the observable.
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:136
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:215
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:68
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:73
This class is used as a container for messages.
Definition: mythevent.h:16
bool IsConnectedToMaster(void)
void clear(void)
bool empty(void) const
bool CheckConnectionToServer(void)
Definition: idlescreen.cpp:78
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
void UpdateScreen(void)
Definition: idlescreen.cpp:139
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:84
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:100
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:439
bool Create(void) override
Definition: idlescreen.cpp:41
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: idlescreen.cpp:239
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:58
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:244
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:132
void SetTextFromMap(const InfoMap &infoMap, const QString &state="")
void SetCanTakeFocus(bool set=true)
Set whether this widget can take focus.
Definition: mythuitype.cpp:344
bool PendingSchedUpdate() const
Definition: idlescreen.h:36