Skip to content

Commit

Permalink
Add a standby mode to mythfrontend to allow the backend to shutdown w…
Browse files Browse the repository at this point in the history
…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
stuartm committed Feb 1, 2012
1 parent 73492e1 commit 7867d7e
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 3 deletions.
7 changes: 5 additions & 2 deletions mythtv/libs/libmythtv/tv_play.cpp
Expand Up @@ -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;
}
Expand All @@ -311,8 +316,6 @@ bool TV::StartTV(ProgramInfo *tvrec, uint flags)
tv->SetLastProgram(&pginfo);
}

sendPlaybackStart();

if (curProgram)
{
startSysEventSent = true;
Expand Down
77 changes: 76 additions & 1 deletion mythtv/libs/libmythui/mythmainwindow.cpp
Expand Up @@ -184,7 +184,10 @@ class MythMainWindowPrivate

m_udpListener(NULL),

m_pendingUpdate(false)
m_pendingUpdate(false),

idleTimer(NULL),
standby(false)
{
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1953,6 +1970,7 @@ bool MythMainWindow::eventFilter(QObject *, QEvent *e)
}
case QEvent::MouseButtonPress:
{
ResetIdleTimer();
ShowMouseCursor(true);
if (!d->gesture.recording())
{
Expand All @@ -1968,6 +1986,7 @@ bool MythMainWindow::eventFilter(QObject *, QEvent *e)
}
case QEvent::MouseButtonRelease:
{
ResetIdleTimer();
ShowMouseCursor(true);
if (d->gestureTimer->isActive())
d->gestureTimer->stop();
Expand Down Expand Up @@ -2049,6 +2068,7 @@ bool MythMainWindow::eventFilter(QObject *, QEvent *e)
}
case QEvent::MouseMove:
{
ResetIdleTimer();
ShowMouseCursor(true);
if (d->gesture.recording())
{
Expand All @@ -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();
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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: */
7 changes: 7 additions & 0 deletions mythtv/libs/libmythui/mythmainwindow.h
Expand Up @@ -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();
Expand Down Expand Up @@ -161,6 +165,9 @@ class MUI_PUBLIC MythMainWindow : public QWidget
void LockInputDevices(bool locked);

void ShowMouseCursor(bool show);

void EnterStandby();
void ExitStandby();

MythMainWindowPrivate *d;
};
Expand Down

0 comments on commit 7867d7e

Please sign in to comment.