Skip to content

Commit

Permalink
[nemo-qml-plugin-time] Suspend updates when the display is blanked.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjones committed Dec 6, 2013
1 parent 4618bae commit 84790fa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
15 changes: 13 additions & 2 deletions src/nemowallclock.cpp
Expand Up @@ -39,7 +39,7 @@
extern WallClockPrivate *nemoCreateWallClockPrivate(WallClock *wc);

WallClockPrivate::WallClockPrivate(WallClock *wallClock)
: q(wallClock), m_updateFreq(WallClock::Second), m_enabled(true)
: q(wallClock), m_updateFreq(WallClock::Second), m_enabled(true), m_suspended(false)
{
setLoopCount(-1);
update();
Expand Down Expand Up @@ -71,6 +71,17 @@ void WallClockPrivate::setEnabled(bool e)
emit q->timeChanged();
}

void WallClockPrivate::setSuspended(bool s)
{
if (m_suspended == s)
return;

m_suspended = s;
update();
if (m_enabled && !m_suspended)
emit q->timeChanged();
}

QDateTime WallClockPrivate::time() const
{
return QDateTime::currentDateTime();
Expand All @@ -87,7 +98,7 @@ QString WallClockPrivate::timezoneAbbreviation() const
}

void WallClockPrivate::update() {
if (m_enabled) {
if (m_enabled && !m_suspended) {
QTime current = QTime::currentTime();
int initDelay = 0;
switch (m_updateFreq) {
Expand Down
12 changes: 8 additions & 4 deletions src/nemowallclock_meego.cpp
Expand Up @@ -78,6 +78,13 @@ WallClockPrivateMeego::WallClockPrivateMeego(WallClock *wc)
this,
SLOT(onDisplayStatusChanged(QString))))
qWarning() << "Can't connect to mce";

QDBusReply<QString> reply = QDBusConnection::systemBus().call(QDBusMessage::createMethodCall(MCE_SERVICE,
MCE_REQUEST_PATH,
MCE_REQUEST_IF,
MCE_DISPLAY_STATUS_GET));
if (reply.isValid())
onDisplayStatusChanged(reply.value());
}

WallClockPrivateMeego::~WallClockPrivateMeego()
Expand All @@ -88,10 +95,7 @@ WallClockPrivateMeego::~WallClockPrivateMeego()

void WallClockPrivateMeego::onDisplayStatusChanged(const QString &status)
{
if (status == MCE_DISPLAY_ON_STRING) {
update();
timeChanged();
}
setSuspended(status == MCE_DISPLAY_OFF_STRING);
}

QString WallClockPrivateMeego::timezone() const
Expand Down
4 changes: 4 additions & 0 deletions src/nemowallclock_p.h
Expand Up @@ -49,12 +49,15 @@ class WallClockPrivate : public QPauseAnimation
bool enabled() const { return m_enabled; }
virtual void setEnabled(bool);

bool suspended() const { return m_suspended; }

virtual QDateTime time() const;
virtual QString timezone() const;
virtual QString timezoneAbbreviation() const;

protected:
virtual void update();
virtual void setSuspended(bool);
void timezoneChanged();
void timezoneAbbreviationChanged();
void timeChanged();
Expand All @@ -66,6 +69,7 @@ class WallClockPrivate : public QPauseAnimation
WallClock *q;
WallClock::UpdateFrequency m_updateFreq;
bool m_enabled;
bool m_suspended;
};

#endif // WALLCLOCK_P_H

0 comments on commit 84790fa

Please sign in to comment.