Commit 76752400 authored by martinjones's avatar martinjones

Merge pull request #7 from martinjones/jb10895

[nemo-qml-plugin-time] Suspend updates when the display is blanked.
parents 4618baec 84790fa4
......@@ -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();
......@@ -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();
......@@ -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) {
......
......@@ -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()
......@@ -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
......
......@@ -49,12 +49,15 @@ public:
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();
......@@ -66,6 +69,7 @@ private:
WallClock *q;
WallClock::UpdateFrequency m_updateFreq;
bool m_enabled;
bool m_suspended;
};
#endif // WALLCLOCK_P_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment