ModemManagerQt

sms.cpp
1/*
2 SPDX-FileCopyrightText: 2013 Anant Kamath <kamathanant@gmail.com>
3 SPDX-FileCopyrightText: 2013 Lukas Tinkl <ltinkl@redhat.com>
4 SPDX-FileCopyrightText: 2013-2015 Jan Grulich <jgrulich@redhat.com>
5
6 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7*/
8
9#include "sms.h"
10#include "mmdebug_p.h"
11#include "sms_p.h"
12
13#ifdef MMQT_STATIC
14#include "dbus/fakedbus.h"
15#else
16#include "dbus/dbus.h"
17#endif
18
19#include <ModemManager/ModemManager.h>
20
21ModemManager::SmsPrivate::SmsPrivate(const QString &path, Sms *q)
22#ifdef MMQT_STATIC
23 : smsIface(QLatin1String(MMQT_DBUS_SERVICE), path, QDBusConnection::sessionBus())
24#else
25 : smsIface(QLatin1String(MMQT_DBUS_SERVICE), path, QDBusConnection::systemBus())
26#endif
27 , q_ptr(q)
28{
29 if (smsIface.isValid()) {
30 uni = path;
31 state = (MMSmsState)smsIface.state();
32 pduType = (MMSmsPduType)smsIface.pduType();
33 number = smsIface.number();
34 text = smsIface.text();
35 smsc = smsIface.SMSC();
36 data = smsIface.data();
37 validity = smsIface.validity();
38 smsClass = smsIface.smsClass();
39 deliveryReportRequest = smsIface.deliveryReportRequest();
40 messageReference = smsIface.messageReference();
41 timestamp = QDateTime::fromString(smsIface.timestamp(), Qt::ISODateWithMs);
42 dischargeTimestamp = QDateTime::fromString(smsIface.dischargeTimestamp(), Qt::ISODateWithMs);
43 deliveryState = (MMSmsDeliveryState)smsIface.deliveryState();
44 storage = (MMSmsStorage)smsIface.storage();
45#if MM_CHECK_VERSION(1, 2, 0)
46 serviceCategory = (MMSmsCdmaServiceCategory)smsIface.serviceCategory();
47 teleserviceId = (MMSmsCdmaTeleserviceId)smsIface.teleserviceId();
48#endif
49 }
50}
51
52ModemManager::Sms::Sms(const QString &path, QObject *parent)
53 : QObject(parent)
54 , d_ptr(new SmsPrivate(path, this))
55{
56 Q_D(Sms);
57
58 qRegisterMetaType<MMSmsDeliveryState>();
59 qRegisterMetaType<MMSmsPduType>();
60 qRegisterMetaType<MMSmsState>();
61 qRegisterMetaType<MMSmsStorage>();
62#if MM_CHECK_VERSION(1, 2, 0)
63 qRegisterMetaType<MMSmsCdmaServiceCategory>();
64 qRegisterMetaType<MMSmsCdmaTeleserviceId>();
65#endif
66
67#ifdef MMQT_STATIC
69 path,
70 QLatin1String(DBUS_INTERFACE_PROPS),
71 QStringLiteral("PropertiesChanged"),
72 d,
73 SLOT(onPropertiesChanged(QString, QVariantMap, QStringList)));
74#else
76 path,
77 QLatin1String(DBUS_INTERFACE_PROPS),
78 QStringLiteral("PropertiesChanged"),
79 d,
80 SLOT(onPropertiesChanged(QString, QVariantMap, QStringList)));
81#endif
82}
83
84ModemManager::Sms::~Sms()
85{
86 delete d_ptr;
87}
88
89QString ModemManager::Sms::uni() const
90{
91 Q_D(const Sms);
92 return d->uni;
93}
94
96{
97 Q_D(Sms);
98 return d->smsIface.Send();
99}
100
102{
103 Q_D(Sms);
104 return d->smsIface.Store(storage);
105}
106
107MMSmsState ModemManager::Sms::state() const
108{
109 Q_D(const Sms);
110 return d->state;
111}
112
113MMSmsPduType ModemManager::Sms::pduType() const
114{
115 Q_D(const Sms);
116 return d->pduType;
117}
118
120{
121 Q_D(const Sms);
122 return d->number;
123}
124
126{
127 Q_D(const Sms);
128 return d->text;
129}
130
132{
133 Q_D(const Sms);
134 return d->smsc;
135}
136
138{
139 Q_D(const Sms);
140 return d->data;
141}
142
143ModemManager::ValidityPair ModemManager::Sms::validity() const
144{
145 Q_D(const Sms);
146 return d->validity;
147}
148
150{
151 Q_D(const Sms);
152 return d->smsClass;
153}
154
156{
157 Q_D(const Sms);
158 return d->deliveryReportRequest;
159}
160
162{
163 Q_D(const Sms);
164 return d->messageReference;
165}
166
168{
169 Q_D(const Sms);
170 return d->timestamp;
171}
172
174{
175 Q_D(const Sms);
176 return d->dischargeTimestamp;
177}
178
179MMSmsDeliveryState ModemManager::Sms::deliveryState() const
180{
181 Q_D(const Sms);
182 return d->deliveryState;
183}
184
185MMSmsStorage ModemManager::Sms::storage() const
186{
187 Q_D(const Sms);
188 return d->storage;
189}
190#if MM_CHECK_VERSION(1, 2, 0)
191MMSmsCdmaServiceCategory ModemManager::Sms::serviceCategory() const
192{
193 Q_D(const Sms);
194 return d->serviceCategory;
195}
196
197MMSmsCdmaTeleserviceId ModemManager::Sms::teleserviceId() const
198{
199 Q_D(const Sms);
200 return d->teleserviceId;
201}
202#endif
203
205{
206 Q_D(Sms);
207 d->smsIface.setTimeout(timeout);
208}
209
211{
212 Q_D(const Sms);
213 return d->smsIface.timeout();
214}
215
216void ModemManager::SmsPrivate::onPropertiesChanged(const QString &interfaceName, const QVariantMap &changedProperties, const QStringList &invalidatedProperties)
217{
218 Q_UNUSED(invalidatedProperties);
219 Q_Q(Sms);
220
221 if (interfaceName == QLatin1String(MMQT_DBUS_INTERFACE_SMS)) {
222 QVariantMap::const_iterator it = changedProperties.constFind(QLatin1String(MM_SMS_PROPERTY_STATE));
223 if (it != changedProperties.constEnd()) {
224 state = (MMSmsState)it->toUInt();
225 qCDebug(MMQT) << state;
226 Q_EMIT q->stateChanged(state);
227 }
228 it = changedProperties.constFind(QLatin1String(MM_SMS_PROPERTY_PDUTYPE));
229 if (it != changedProperties.constEnd()) {
230 pduType = (MMSmsPduType)it->toUInt();
231 Q_EMIT q->pduTypeChanged(pduType);
232 }
233 it = changedProperties.constFind(QLatin1String(MM_SMS_PROPERTY_NUMBER));
234 if (it != changedProperties.constEnd()) {
235 number = it->toString();
236 Q_EMIT q->numberChanged(number);
237 }
238 it = changedProperties.constFind(QLatin1String(MM_SMS_PROPERTY_SMSC));
239 if (it != changedProperties.constEnd()) {
240 smsc = it->toString();
241 Q_EMIT q->SMSCChanged(smsc);
242 }
243 it = changedProperties.constFind(QLatin1String(MM_SMS_PROPERTY_DATA));
244 if (it != changedProperties.constEnd()) {
245 data = it->toByteArray();
246 Q_EMIT q->dataChanged(data);
247 }
248 it = changedProperties.constFind(QLatin1String(MM_SMS_PROPERTY_TEXT));
249 if (it != changedProperties.constEnd()) {
250 text = it->toString();
251 Q_EMIT q->textChanged(text);
252 }
253 it = changedProperties.constFind(QLatin1String(MM_SMS_PROPERTY_VALIDITY));
254 if (it != changedProperties.constEnd()) {
255 validity = it->value<ValidityPair>();
256 Q_EMIT q->validityChanged(validity);
257 }
258 it = changedProperties.constFind(QLatin1String(MM_SMS_PROPERTY_CLASS));
259 if (it != changedProperties.constEnd()) {
260 smsClass = it->toInt();
261 Q_EMIT q->smsClassChanged(smsClass);
262 }
263 it = changedProperties.constFind(QLatin1String(MM_SMS_PROPERTY_DELIVERYREPORTREQUEST));
264 if (it != changedProperties.constEnd()) {
265 deliveryReportRequest = it->toBool();
266 Q_EMIT q->deliveryReportRequestChanged(deliveryReportRequest);
267 }
268 it = changedProperties.constFind(QLatin1String(MM_SMS_PROPERTY_MESSAGEREFERENCE));
269 if (it != changedProperties.constEnd()) {
270 messageReference = it->toUInt();
271 Q_EMIT q->messageReferenceChanged(messageReference);
272 }
273 it = changedProperties.constFind(QLatin1String(MM_SMS_PROPERTY_TIMESTAMP));
274 if (it != changedProperties.constEnd()) {
275 timestamp = QDateTime::fromString(it->toString(), Qt::ISODate);
276 Q_EMIT q->timestampChanged(timestamp);
277 }
278 it = changedProperties.constFind(QLatin1String(MM_SMS_PROPERTY_DISCHARGETIMESTAMP));
279 if (it != changedProperties.constEnd()) {
280 dischargeTimestamp = QDateTime::fromString(it->toString(), Qt::ISODate);
281 Q_EMIT q->dischargeTimestampChanged(dischargeTimestamp);
282 }
283 it = changedProperties.constFind(QLatin1String(MM_SMS_PROPERTY_DELIVERYSTATE));
284 if (it != changedProperties.constEnd()) {
285 deliveryState = (MMSmsDeliveryState)it->toUInt();
286 Q_EMIT q->deliveryStateChanged(deliveryState);
287 }
288 it = changedProperties.constFind(QLatin1String(MM_SMS_PROPERTY_STORAGE));
289 if (it != changedProperties.constEnd()) {
290 storage = (MMSmsStorage)it->toUInt();
291 Q_EMIT q->storageChanged(storage);
292 }
293#if MM_CHECK_VERSION(1, 2, 0)
294 it = changedProperties.constFind(QLatin1String(MM_SMS_PROPERTY_SERVICECATEGORY));
295 if (it != changedProperties.constEnd()) {
296 serviceCategory = (MMSmsCdmaServiceCategory)it->toUInt();
297 Q_EMIT q->serviceCategoryChanged(serviceCategory);
298 }
299 it = changedProperties.constFind(QLatin1String(MM_SMS_PROPERTY_TELESERVICEID));
300 if (it != changedProperties.constEnd()) {
301 teleserviceId = (MMSmsCdmaTeleserviceId)it->toUInt();
302 Q_EMIT q->teleserviceIdChanged(teleserviceId);
303 }
304#endif
305 }
306}
307
308#include "moc_sms.cpp"
309#include "moc_sms_p.cpp"
Provides an interface to manipulate and control an SMS.
Definition sms.h:31
MMSmsDeliveryState deliveryState() const
This method returns the delivery state of the SMS.
Definition sms.cpp:179
QDateTime dischargeTimestamp() const
Time when the SMS left the SMSC.
Definition sms.cpp:173
uint messageReference() const
This method returns the message reference of the last PDU sent/received in the SMS.
Definition sms.cpp:161
QDBusPendingReply send()
Send the SMS.
Definition sms.cpp:95
MMSmsPduType pduType() const
This method returns the Protocol Data Unit (PDU) type of the SMS.
Definition sms.cpp:113
void setTimeout(int timeout)
Sets the timeout in milliseconds for all async method DBus calls.
Definition sms.cpp:204
QDateTime timestamp() const
Time when the SMS arrived at the SMSC.
Definition sms.cpp:167
QString SMSC() const
This method returns the SMS service center number.
Definition sms.cpp:131
int smsClass() const
This method returns the 3GPP class of the SMS.
Definition sms.cpp:149
ValidityPair validity() const
This method returns the validity of the SMS.
Definition sms.cpp:143
int timeout() const
Returns the current value of the DBus timeout in milliseconds.
Definition sms.cpp:210
QString number() const
This method returns the phone number to which the SMS is addressed to.
Definition sms.cpp:119
MMSmsStorage storage() const
This method returns the storage area/location of the SMS.
Definition sms.cpp:185
QDBusPendingReply store(MMSmsStorage storage=MM_SMS_STORAGE_UNKNOWN)
Store the SMS.
Definition sms.cpp:101
QByteArray data() const
This method returns the SMS message data.
Definition sms.cpp:137
QString text() const
This method returns the text of the SMS.
Definition sms.cpp:125
MMSmsState state() const
This method returns the state of the SMS.
Definition sms.cpp:107
bool deliveryReportRequest() const
Definition sms.cpp:155
KIOCORE_EXPORT QString number(KIO::filesize_t size)
QString path(const QString &relativePath)
QDateTime fromString(QStringView string, QStringView format, QCalendar cal)
bool connect(const QString &service, const QString &path, const QString &interface, const QString &name, QObject *receiver, const char *slot)
QDBusConnection sessionBus()
QDBusConnection systemBus()
QChar * data()
QString number(double n, char format, int precision)
ISODateWithMs
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:15:10 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.