Changeset View
Changeset View
Standalone View
Standalone View
dataengines/time/timeengine.cpp
Show All 27 Lines | |||||
28 | 28 | | |||
29 | #ifdef Q_OS_LINUX | 29 | #ifdef Q_OS_LINUX | ||
30 | #include <sys/timerfd.h> | 30 | #include <sys/timerfd.h> | ||
31 | #include <unistd.h> | 31 | #include <unistd.h> | ||
32 | #include <fcntl.h> | 32 | #include <fcntl.h> | ||
33 | #endif | 33 | #endif | ||
34 | 34 | | |||
35 | #include "timesource.h" | 35 | #include "timesource.h" | ||
36 | #include "debug.h" | ||||
36 | 37 | | |||
37 | //timezone is defined in msvc | 38 | //timezone is defined in msvc | ||
38 | #ifdef timezone | 39 | #ifdef timezone | ||
39 | #undef timezone | 40 | #undef timezone | ||
40 | #endif | 41 | #endif | ||
41 | 42 | | |||
42 | TimeEngine::TimeEngine(QObject *parent, const QVariantList &args) | 43 | TimeEngine::TimeEngine(QObject *parent, const QVariantList &args) | ||
43 | : Plasma::DataEngine(parent, args) | 44 | : Plasma::DataEngine(parent, args) | ||
Show All 21 Lines | 65 | #ifdef Q_OS_LINUX | |||
65 | //monitor for the system clock being changed | 66 | //monitor for the system clock being changed | ||
66 | auto timeChangedFd = timerfd_create(CLOCK_REALTIME, O_CLOEXEC | O_NONBLOCK); | 67 | auto timeChangedFd = timerfd_create(CLOCK_REALTIME, O_CLOEXEC | O_NONBLOCK); | ||
67 | itimerspec timespec; | 68 | itimerspec timespec; | ||
68 | memset(×pec, 0, sizeof(timespec)); //set all timers to 0 seconds, which creates a timer that won't do anything | 69 | memset(×pec, 0, sizeof(timespec)); //set all timers to 0 seconds, which creates a timer that won't do anything | ||
69 | 70 | | |||
70 | int err = timerfd_settime(timeChangedFd, 3, ×pec, nullptr); //monitor for the time changing | 71 | int err = timerfd_settime(timeChangedFd, 3, ×pec, nullptr); //monitor for the time changing | ||
71 | //(flags == TFD_TIMER_ABSTIME | TFD_TIMER_CANCEL_ON_SET). However these are not exposed in glibc so value is hardcoded | 72 | //(flags == TFD_TIMER_ABSTIME | TFD_TIMER_CANCEL_ON_SET). However these are not exposed in glibc so value is hardcoded | ||
72 | if (err) { | 73 | if (err) { | ||
73 | qWarning() << "Could not create timer with TFD_TIMER_CANCEL_ON_SET. Clock skews will not be detected. Error:" << qPrintable(strerror(err)); | 74 | qCWarning(DATAENGINE_TIME) << "Could not create timer with TFD_TIMER_CANCEL_ON_SET. Clock skews will not be detected. Error:" << qPrintable(strerror(err)); | ||
74 | } | 75 | } | ||
75 | 76 | | |||
76 | connect(this, &QObject::destroyed, [timeChangedFd]() { | 77 | connect(this, &QObject::destroyed, [timeChangedFd]() { | ||
77 | close(timeChangedFd); | 78 | close(timeChangedFd); | ||
78 | }); | 79 | }); | ||
79 | 80 | | |||
80 | auto notifier = new QSocketNotifier(timeChangedFd, QSocketNotifier::Read, this); | 81 | auto notifier = new QSocketNotifier(timeChangedFd, QSocketNotifier::Read, this); | ||
81 | connect(notifier, &QSocketNotifier::activated, this, [this](int fd) { | 82 | connect(notifier, &QSocketNotifier::activated, this, [this](int fd) { | ||
Show All 9 Lines | 89 | dbus.connect(QStringLiteral("org.kde.Solid.PowerManagement"), | |||
91 | QStringLiteral("resumingFromSuspend"), | 92 | QStringLiteral("resumingFromSuspend"), | ||
92 | this, | 93 | this, | ||
93 | SLOT(clockSkewed())); | 94 | SLOT(clockSkewed())); | ||
94 | #endif | 95 | #endif | ||
95 | } | 96 | } | ||
96 | 97 | | |||
97 | void TimeEngine::clockSkewed() | 98 | void TimeEngine::clockSkewed() | ||
98 | { | 99 | { | ||
99 | qDebug() << "Time engine Clock skew signaled"; | 100 | qCDebug(DATAENGINE_TIME) << "Time engine Clock skew signaled"; | ||
100 | updateAllSources(); | 101 | updateAllSources(); | ||
101 | forceImmediateUpdateOfAllVisualizations(); | 102 | forceImmediateUpdateOfAllVisualizations(); | ||
102 | } | 103 | } | ||
103 | 104 | | |||
104 | void TimeEngine::tzConfigChanged() | 105 | void TimeEngine::tzConfigChanged() | ||
105 | { | 106 | { | ||
106 | qDebug() << "Local timezone changed signaled"; | 107 | qCDebug(DATAENGINE_TIME) << "Local timezone changed signaled"; | ||
107 | TimeSource *s = qobject_cast<TimeSource *>(containerForSource(QStringLiteral("Local"))); | 108 | TimeSource *s = qobject_cast<TimeSource *>(containerForSource(QStringLiteral("Local"))); | ||
108 | 109 | | |||
109 | if (s) { | 110 | if (s) { | ||
110 | s->setTimeZone(QStringLiteral("Local")); | 111 | s->setTimeZone(QStringLiteral("Local")); | ||
111 | } | 112 | } | ||
112 | 113 | | |||
113 | updateAllSources(); | 114 | updateAllSources(); | ||
114 | forceImmediateUpdateOfAllVisualizations(); | 115 | forceImmediateUpdateOfAllVisualizations(); | ||
Show All 33 Lines |