diff options
Diffstat (limited to 'walltimemonitor.cpp')
-rw-r--r-- | walltimemonitor.cpp | 65 |
1 files changed, 57 insertions, 8 deletions
diff --git a/walltimemonitor.cpp b/walltimemonitor.cpp index 29bccee..78d500b 100644 --- a/walltimemonitor.cpp +++ b/walltimemonitor.cpp @@ -52,28 +52,54 @@ #include <QtCore/QMessageLogger> #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<Maemo::Timed::WallClock::Info> 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(); +} + } |