-
Notifications
You must be signed in to change notification settings - Fork 341
/
idlescreen.cpp
172 lines (133 loc) · 3.91 KB
/
idlescreen.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include "idlescreen.h"
#include <QTimer>
#include <mythcontext.h>
#include <mythsystem.h>
#include <mythuibuttonlist.h>
#include <mythuistatetype.h>
#include <mythmainwindow.h>
#include <programinfo.h>
#include <tvremoteutil.h>
#define UPDATE_STATUS_INTERVAL 30000
IdleScreen::IdleScreen(MythScreenStack *parent)
:MythScreenType(parent, "standbymode"),
m_updateStatusTimer(new QTimer(this)), m_statusState(NULL),
m_secondsToShutdown(0), m_backendRecording(false)
{
gCoreContext->addListener(this);
GetMythMainWindow()->EnterStandby();
connect(m_updateStatusTimer, SIGNAL(timeout()),
this, SLOT(UpdateStatus()));
m_updateStatusTimer->start(UPDATE_STATUS_INTERVAL);
}
IdleScreen::~IdleScreen()
{
GetMythMainWindow()->ExitStandby();
gCoreContext->removeListener(this);
if (m_updateStatusTimer)
m_updateStatusTimer->disconnect();
}
bool IdleScreen::Create(void)
{
bool foundtheme = false;
// Load the theme for this screen
foundtheme = LoadWindowFromXML("status-ui.xml", "standbymode", this);
if (!foundtheme)
return false;
m_statusState = dynamic_cast<MythUIStateType*>
(GetChild("backendstatus"));
if (!m_statusState)
return false;
return true;
}
void IdleScreen::Load(void)
{
MythScreenType::Load();
}
void IdleScreen::Init(void)
{
UpdateScreen();
}
bool IdleScreen::CheckConnectionToServer(void)
{
m_updateStatusTimer->stop();
bool bRes = false;
if (gCoreContext->IsConnectedToMaster())
bRes = true;
else
{
if (gCoreContext->SafeConnectToMasterServer(false))
bRes = true;
}
if (bRes)
m_updateStatusTimer->start(UPDATE_STATUS_INTERVAL);
else
m_updateStatusTimer->start(5000);
return bRes;
}
void IdleScreen::UpdateStatus(void)
{
QString state = "idle";
if (CheckConnectionToServer())
{
if (m_secondsToShutdown)
state = "shuttingdown";
else if (RemoteGetRecordingStatus())
state = "recording";
}
else
{
state = "offline";
}
m_statusState->DisplayState(state);
}
void IdleScreen::UpdateScreen(void)
{
MythUIText *statusText = dynamic_cast<MythUIText *>(GetChild("status"));
if (statusText)
{
QString status;
if (m_secondsToShutdown)
status = tr("MythTV is idle and will shutdown in %n "
"second(s).", "", m_secondsToShutdown);
if (!status.isEmpty())
statusText->SetText(status);
else
statusText->Reset();
}
UpdateStatus();
}
bool IdleScreen::keyPressEvent(QKeyEvent* event)
{
return MythScreenType::keyPressEvent(event);
}
void IdleScreen::customEvent(QEvent* event)
{
if ((MythEvent::Type)(event->type()) == MythEvent::MythEventMessage)
{
MythEvent *me = static_cast<MythEvent *>(event);
if (me->Message().left(18) == "SHUTDOWN_COUNTDOWN")
{
QString secs = me->Message().mid(19);
m_secondsToShutdown = secs.toInt();
UpdateStatus();
}
else if (me->Message().left(12) == "SHUTDOWN_NOW")
{
if (gCoreContext->IsFrontendOnly())
{
// does the user want to shutdown this frontend only machine
// when the BE shuts down?
if (gCoreContext->GetNumSetting("ShutdownWithMasterBE", 0) == 1)
{
LOG(VB_GENERAL, LOG_NOTICE,
"Backend has gone offline, Shutting down frontend");
QString poweroff_cmd =
gCoreContext->GetSetting("MythShutdownPowerOff", "");
if (!poweroff_cmd.isEmpty())
myth_system(poweroff_cmd);
}
}
}
}
MythUIType::customEvent(event);
}