From 3b6a0066ef584a076b1a05dc5524cbfa2e2a0bb6 Mon Sep 17 00:00:00 2001 From: Javier Date: Sun, 13 Dec 2015 02:38:35 +0100 Subject: Implement WallTimeMonitor --- walltimemonitor.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 8 deletions(-) (limited to 'walltimemonitor.cpp') diff --git a/walltimemonitor.cpp b/walltimemonitor.cpp index 29bccee..78d500b 100644 --- a/walltimemonitor.cpp +++ b/walltimemonitor.cpp @@ -52,28 +52,54 @@ #include #include "walltimemonitor.h" +#include "walltimemonitor_p.h" namespace watchfish { -class WallTimeMonitorPrivate -{ - WallTimeMonitor * const q_ptr; - Q_DECLARE_PUBLIC(WallTimeMonitor) - - WallTimeMonitorPrivate(WallTimeMonitor *q); - ~WallTimeMonitorPrivate(); -}; +Q_LOGGING_CATEGORY(walltimeMonitorCat, "watchfish-WallTimeMonitor") WallTimeMonitorPrivate::WallTimeMonitorPrivate(WallTimeMonitor *q) : q_ptr(q) { + Maemo::Timed::Interface ifc; + ifc.settings_changed_connect(this, SLOT(handleTimedSettingsChanged(Maemo::Timed::WallClock::Info,bool))); + QDBusReply reply = ifc.get_wall_clock_info_sync(); + if (reply.isValid()) { + info = reply.value(); + } else { + qCWarning(walltimeMonitorCat) << "D-Bus error while contacting timed:" << reply.error().message(); + } } WallTimeMonitorPrivate::~WallTimeMonitorPrivate() { + Maemo::Timed::Interface ifc; + ifc.settings_changed_disconnect(this, SLOT(handleTimedSettingsChanged(Maemo::Timed::WallClock::Info,bool))); +} + +void WallTimeMonitorPrivate::handleTimedSettingsChanged(const Maemo::Timed::WallClock::Info &newInfo, bool timeChanged) +{ + Q_Q(WallTimeMonitor); + bool tzChange = newInfo.humanReadableTz() != info.humanReadableTz(); + bool tzaChange = newInfo.tzAbbreviation() != info.tzAbbreviation(); + bool tzoChange = newInfo.secondsEastOfGmt() != info.secondsEastOfGmt(); + bool hourModeChange = newInfo.flagFormat24() != info.flagFormat24(); + + info = newInfo; + + if (tzChange) + emit q->timezoneChanged(); + if (tzaChange) + emit q->timezoneAbbreviationChanged(); + if (tzoChange) + emit q->timezoneOffsetFromUtcChanged(); + if (timeChanged) + emit q->systemTimeChanged(); + if (tzChange || tzaChange || tzoChange || timeChanged || hourModeChange) + emit q->timeChanged(); } WallTimeMonitor::WallTimeMonitor(QObject *parent) @@ -87,4 +113,27 @@ WallTimeMonitor::~WallTimeMonitor() delete d_ptr; } +QDateTime WallTimeMonitor::time() const +{ + return QDateTime::currentDateTime(); +} + +QString WallTimeMonitor::timezone() const +{ + Q_D(const WallTimeMonitor); + return d->info.humanReadableTz(); +} + +QString WallTimeMonitor::timezoneAbbreviation() const +{ + Q_D(const WallTimeMonitor); + return d->info.tzAbbreviation(); +} + +int WallTimeMonitor::timezoneOffsetFromUtc() const +{ + Q_D(const WallTimeMonitor); + return d->info.secondsEastOfGmt(); +} + } -- cgit v1.2.3