ModemManagerQt

modemtime.cpp
1/*
2 SPDX-FileCopyrightText: 2013 Lukas Tinkl <ltinkl@redhat.com>
3 SPDX-FileCopyrightText: 2013-2015 Jan Grulich <jgrulich@redhat.com>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
7
8#include "modemtime.h"
9#include "mmdebug_p.h"
10#include "modemtime_p.h"
11#ifdef MMQT_STATIC
12#include "dbus/fakedbus.h"
13#else
14#include "dbus/dbus.h"
15#endif
16
17namespace ModemManager
18{
19class ModemManager::NetworkTimezone::Private
20{
21public:
22 Private()
23 {
24 }
25 int offset;
26 int dstOffset;
27 int leapSecond;
28};
29
30}
31
33 : d(new Private())
34{
35}
36
38 : d(new Private)
39{
40 *this = other;
41}
42
47
49{
50 return d->offset;
51}
52
54{
55 d->offset = offset;
56}
57
59{
60 return d->dstOffset;
61}
62
64{
65 d->dstOffset = dstOffset;
66}
67
69{
70 return d->leapSecond;
71}
72
74{
75 d->leapSecond = leapSecond;
76}
77
79{
80 if (this == &other) {
81 return *this;
82 }
83
84 *d = *other.d;
85 return *this;
86}
87
88ModemManager::ModemTimePrivate::ModemTimePrivate(const QString &path, ModemTime *q)
89 : InterfacePrivate(path, q)
90#ifdef MMQT_STATIC
91 , modemTimeIface(QLatin1String(MMQT_DBUS_SERVICE), path, QDBusConnection::sessionBus())
92#else
93 , modemTimeIface(QLatin1String(MMQT_DBUS_SERVICE), path, QDBusConnection::systemBus())
94#endif
95 , q_ptr(q)
96{
97 if (modemTimeIface.isValid()) {
98 networkTimezone = variantMapToTimezone(modemTimeIface.networkTimezone());
99 }
100}
101
102ModemManager::ModemTime::ModemTime(const QString &path, QObject *parent)
103 : Interface(*new ModemTimePrivate(path, this), parent)
104{
105 Q_D(ModemTime);
106
107 connect(&d->modemTimeIface, &OrgFreedesktopModemManager1ModemTimeInterface::NetworkTimeChanged, d, &ModemTimePrivate::onNetworkTimeChanged);
108#ifdef MMQT_STATIC
110 d->uni,
111 QLatin1String(DBUS_INTERFACE_PROPS),
112 QStringLiteral("PropertiesChanged"),
113 d,
114 SLOT(onPropertiesChanged(QString, QVariantMap, QStringList)));
115#else
117 d->uni,
118 QLatin1String(DBUS_INTERFACE_PROPS),
119 QStringLiteral("PropertiesChanged"),
120 d,
121 SLOT(onPropertiesChanged(QString, QVariantMap, QStringList)));
122#endif
123}
124
125ModemManager::ModemTime::~ModemTime()
126{
127}
128
130{
131 Q_D(ModemTime);
132
133 return d->modemTimeIface.GetNetworkTime();
134}
135
137{
138 Q_D(const ModemTime);
139
140 return d->networkTimezone;
141}
142
143ModemManager::NetworkTimezone ModemManager::ModemTimePrivate::variantMapToTimezone(const QVariantMap &map)
144{
146 if (map.contains(QLatin1String("offset"))) {
147 result.setOffset(map.value(QStringLiteral("offset")).toInt());
148 }
149 if (map.contains(QLatin1String("dst-offset"))) {
150 result.setDstOffset(map.value(QStringLiteral("dst-offset")).toInt());
151 }
152 if (map.contains(QLatin1String("leap-seconds"))) {
153 result.setLeapSecond(map.value(QStringLiteral("leap-seconds")).toInt());
154 }
155
156 return result;
157}
158
160{
161 Q_D(ModemTime);
162 d->modemTimeIface.setTimeout(timeout);
163}
164
166{
167 Q_D(const ModemTime);
168 return d->modemTimeIface.timeout();
169}
170
171void ModemManager::ModemTimePrivate::onNetworkTimeChanged(const QString &isoDateTime)
172{
173 Q_Q(ModemTime);
174
175 const QDateTime result = QDateTime::fromString(isoDateTime, Qt::ISODate);
176 if (result.isValid()) {
177 Q_EMIT q->networkTimeChanged(result);
178 }
179}
180
181void ModemManager::ModemTimePrivate::onPropertiesChanged(const QString &interface, const QVariantMap &properties, const QStringList &invalidatedProps)
182{
183 Q_Q(ModemTime);
184 Q_UNUSED(invalidatedProps);
185 qCDebug(MMQT) << interface << properties.keys();
186
187 if (interface == QLatin1String(MMQT_DBUS_INTERFACE_MODEM_TIME)) {
188 QVariantMap::const_iterator it = properties.constFind(QLatin1String(MM_MODEM_TIME_PROPERTY_NETWORKTIMEZONE));
189 if (it != properties.constEnd()) {
190 networkTimezone = variantMapToTimezone(qdbus_cast<QVariantMap>(*it));
191 Q_EMIT q->networkTimezoneChanged(networkTimezone);
192 }
193 }
194}
195
196#include "moc_modemtime.cpp"
The ModemTime class.
Definition modemtime.h:89
void networkTimeChanged(const QDateTime &dateTime)
Sent when the network time is updated.
QDBusPendingReply< QString > networkTime()
ModemManager::NetworkTimezone networkTimezone() const
void setTimeout(int timeout)
Sets the timeout in milliseconds for all async method DBus calls.
int timeout() const
Returns the current value of the DBus timeout in milliseconds.
This class represents the timezone data provided by the network.
Definition modemtime.h:27
int leapSecond() const
Returns number of leap seconds included in the network time.
Definition modemtime.cpp:68
void setDstOffset(int dstOffset)
Sets amount of offset that is due to DST.
Definition modemtime.cpp:63
int offset() const
Returns offset of the timezone from UTC, in minutes (including DST, if applicable)
Definition modemtime.cpp:48
void setLeapSecond(int leapSecond)
Sets number of leap seconds included in the network timezone.
Definition modemtime.cpp:73
~NetworkTimezone()
Destroys this NetworkTimezone object.
Definition modemtime.cpp:43
void setOffset(int offset)
Sets offset of the timezone from UTC.
Definition modemtime.cpp:53
int dstOffset() const
Returns amount of offset that is due to DST (daylight saving time)
Definition modemtime.cpp:58
NetworkTimezone & operator=(const NetworkTimezone &other)
Makes a copy of the NetworkTimezone object other.
Definition modemtime.cpp:78
NetworkTimezone()
Constructs an empty timezone data object.
Definition modemtime.cpp:32
KGuiItem properties()
This namespace allows to query the underlying system to discover the available modem interfaces respo...
Definition bearer.cpp:20
QDateTime fromString(QStringView string, QStringView format, QCalendar cal)
bool isValid() const const
bool connect(const QString &service, const QString &path, const QString &interface, const QString &name, QObject *receiver, const char *slot)
QDBusConnection sessionBus()
QDBusConnection systemBus()
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:59:51 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.