Permalink
Browse files

Add a standby mode to mythfrontend to allow the backend to shutdown w…

…hen the frontends haven't been used for 30 minutes. This does away with the need for mythwelcome, but doesn't yet replace mythwelcome's status screen for those who like that additional feature.
  • Loading branch information...
1 parent 73492e1 commit 7867d7efbd4ed2a29c6cf2b92ca4e26916ffd5ff @stuartm stuartm committed Feb 1, 2012
@@ -295,11 +295,16 @@ bool TV::StartTV(ProgramInfo *tvrec, uint flags)
curProgram->SetIgnoreBookmark(flags & kStartTVIgnoreBookmark);
}
+ // Must be before Init() otherwise we swallow the PLAYBACK_START event
+ // with the event filter
+ sendPlaybackStart();
+
// Initialize TV
if (!tv->Init())
{
LOG(VB_GENERAL, LOG_ERR, LOC + "Failed initializing TV");
ReleaseTV(tv);
+ sendPlaybackEnd();
delete curProgram;
return false;
}
@@ -311,8 +316,6 @@ bool TV::StartTV(ProgramInfo *tvrec, uint flags)
tv->SetLastProgram(&pginfo);
}
- sendPlaybackStart();
-
if (curProgram)
{
startSysEventSent = true;
@@ -184,7 +184,10 @@ class MythMainWindowPrivate
m_udpListener(NULL),
- m_pendingUpdate(false)
+ m_pendingUpdate(false),
+
+ idleTimer(NULL),
+ standby(false)
{
}
@@ -272,6 +275,9 @@ class MythMainWindowPrivate
MythUDPListener *m_udpListener;
bool m_pendingUpdate;
+
+ QTimer *idleTimer;
+ bool standby;
};
// Make keynum in QKeyEvent be equivalent to what's in QKeySequence
@@ -492,6 +498,16 @@ MythMainWindow::MythMainWindow(const bool useDB)
connect(this, SIGNAL(signalRemoteScreenShot(QString,int,int)),
this, SLOT(doRemoteScreenShot(QString,int,int)),
Qt::BlockingQueuedConnection);
+
+ // We need to listen for playback start/end events
+ gCoreContext->addListener(this);
+
+ int idletime = gCoreContext->GetNumSetting("FrontendIdleTimeout", 30);
+ d->idleTimer = new QTimer(this);
+ d->idleTimer->setSingleShot(true);
+ d->idleTimer->setInterval(1000 * 60 * idletime); // 30 minutes
+ connect(d->idleTimer, SIGNAL(timeout()), SLOT(IdleTimeout()));
+ d->idleTimer->start();
}
MythMainWindow::~MythMainWindow()
@@ -1918,6 +1934,7 @@ bool MythMainWindow::eventFilter(QObject *, QEvent *e)
{
case QEvent::KeyPress:
{
+ ResetIdleTimer();
QKeyEvent *ke = dynamic_cast<QKeyEvent*>(e);
// Work around weird GCC run-time bug. Only manifest on Mac OS X
@@ -1953,6 +1970,7 @@ bool MythMainWindow::eventFilter(QObject *, QEvent *e)
}
case QEvent::MouseButtonPress:
{
+ ResetIdleTimer();
ShowMouseCursor(true);
if (!d->gesture.recording())
{
@@ -1968,6 +1986,7 @@ bool MythMainWindow::eventFilter(QObject *, QEvent *e)
}
case QEvent::MouseButtonRelease:
{
+ ResetIdleTimer();
ShowMouseCursor(true);
if (d->gestureTimer->isActive())
d->gestureTimer->stop();
@@ -2049,6 +2068,7 @@ bool MythMainWindow::eventFilter(QObject *, QEvent *e)
}
case QEvent::MouseMove:
{
+ ResetIdleTimer();
ShowMouseCursor(true);
if (d->gesture.recording())
{
@@ -2063,6 +2083,7 @@ bool MythMainWindow::eventFilter(QObject *, QEvent *e)
}
case QEvent::Wheel:
{
+ ResetIdleTimer();
ShowMouseCursor(true);
QWheelEvent* qmw = dynamic_cast<QWheelEvent*>(e);
int delta = qmw->delta();
@@ -2335,6 +2356,14 @@ void MythMainWindow::customEvent(QEvent *ce)
state.insert("currentlocation", GetMythUI()->GetCurrentLocation());
MythUIStateTracker::SetState(state);
}
+ else if (message.startsWith("PLAYBACK_START"))
+ {
+ PauseIdleTimer(true);
+ }
+ else if (message.startsWith("PLAYBACK_END"))
+ {
+ PauseIdleTimer(false);
+ }
}
else if ((MythEvent::Type)(ce->type()) == MythEvent::MythUserMessage)
{
@@ -2534,4 +2563,50 @@ void MythMainWindow::HideMouseTimeout(void)
ShowMouseCursor(false);
}
+void MythMainWindow::ResetIdleTimer(void)
+{
+ // If the timer isn't active then it's been paused
+ if (!d->idleTimer->isActive() && !d->standby)
+ return;
+
+ if (d->standby)
+ ExitStandby();
+
+ d->idleTimer->start();
+}
+
+void MythMainWindow::PauseIdleTimer(bool pause)
+{
+ if (pause)
+ d->idleTimer->stop();
+ else
+ d->idleTimer->start();
+
+ ResetIdleTimer();
+}
+
+void MythMainWindow::IdleTimeout(void)
+{
+ EnterStandby();
+}
+
+void MythMainWindow::EnterStandby()
+{
+ int idletimeout = gCoreContext->GetNumSetting("FrontendIdleTimeout");
+ LOG(VB_GENERAL, LOG_NOTICE, QString("Entering standby mode after "
+ "%1 minutes of inactivity")
+ .arg(idletimeout));
+ //JumpTo("Main Menu");
+ d->standby = true;
+ gCoreContext->AllowShutdown();
+}
+
+void MythMainWindow::ExitStandby()
+{
+ LOG(VB_GENERAL, LOG_NOTICE, "Leaving standby mode");
+ d->standby = false;
+ gCoreContext->BlockShutdown();
+}
+
+
/* vim: set expandtab tabstop=4 shiftwidth=4: */
@@ -126,10 +126,14 @@ class MUI_PUBLIC MythMainWindow : public QWidget
uint PopDrawDisabled(void);
void SetEffectsEnabled(bool enable);
void draw(void);
+
+ void ResetIdleTimer(void);
+ void PauseIdleTimer(bool pause);
public slots:
void mouseTimeout();
void HideMouseTimeout();
+ void IdleTimeout();
protected slots:
void animate();
@@ -161,6 +165,9 @@ class MUI_PUBLIC MythMainWindow : public QWidget
void LockInputDevices(bool locked);
void ShowMouseCursor(bool show);
+
+ void EnterStandby();
+ void ExitStandby();
MythMainWindowPrivate *d;
};

0 comments on commit 7867d7e

Please sign in to comment.