ModemManagerQt

modemmessaging.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 "modemmessaging.h"
10#include "modemmessaging_p.h"
11
12#ifdef MMQT_STATIC
13#include "dbus/fakedbus.h"
14#else
15#include "dbus/dbus.h"
16#endif
17#include "mmdebug_p.h"
18
19#include <ModemManager/ModemManager.h>
20
21ModemManager::ModemMessagingPrivate::ModemMessagingPrivate(const QString &path, ModemMessaging *q)
22 : InterfacePrivate(path, q)
23#ifdef MMQT_STATIC
24 , modemMessagingIface(QLatin1String(MMQT_DBUS_SERVICE), path, QDBusConnection::sessionBus())
25#else
26 , modemMessagingIface(QLatin1String(MMQT_DBUS_SERVICE), path, QDBusConnection::systemBus())
27#endif
28 , q_ptr(q)
29{
30 if (modemMessagingIface.isValid()) {
31 QList<MMSmsStorage> storages;
32 Q_FOREACH (uint storage, modemMessagingIface.supportedStorages()) {
33 storages.append((MMSmsStorage)storage);
34 }
35 supportedStorages = storages;
36 defaultStorage = (MMSmsStorage)modemMessagingIface.defaultStorage();
37
38 connect(&modemMessagingIface, &OrgFreedesktopModemManager1ModemMessagingInterface::Added, this, &ModemMessagingPrivate::onMessageAdded);
39 connect(&modemMessagingIface, &OrgFreedesktopModemManager1ModemMessagingInterface::Deleted, this, &ModemMessagingPrivate::onMessageDeleted);
40 }
41}
42
43ModemManager::ModemMessaging::ModemMessaging(const QString &path, QObject *parent)
44 : Interface(*new ModemMessagingPrivate(path, this), parent)
45{
46 Q_D(ModemMessaging);
47#ifdef MMQT_STATIC
49 path,
50 QLatin1String(DBUS_INTERFACE_PROPS),
51 QStringLiteral("PropertiesChanged"),
52 this,
53 SLOT(onPropertiesChanged(QString, QVariantMap, QStringList)));
54#else
56 path,
57 QLatin1String(DBUS_INTERFACE_PROPS),
58 QStringLiteral("PropertiesChanged"),
59 this,
60 SLOT(onPropertiesChanged(QString, QVariantMap, QStringList)));
61#endif
62 QList<QDBusObjectPath> messages = d->modemMessagingIface.messages();
63 Q_FOREACH (const QDBusObjectPath &op, messages) {
64 const QString objectPathAsString = op.path();
65 d->messageList.insert(objectPathAsString, ModemManager::Sms::Ptr());
66 Q_EMIT messageAdded(objectPathAsString, false);
67 }
68}
69
70ModemManager::ModemMessaging::~ModemMessaging()
71{
72}
73
74ModemManager::Sms::Ptr ModemManager::ModemMessagingPrivate::findMessage(const QString &uni)
75{
77 if (messageList.contains(uni)) {
78 if (messageList.value(uni)) {
79 sms = messageList.value(uni);
80 } else {
82 messageList[uni] = sms;
83 }
84 }
85 return sms;
86}
87
88ModemManager::Sms::List ModemManager::ModemMessagingPrivate::ModemMessagingPrivate::messages()
89{
91
93 for (i = messageList.constBegin(); i != messageList.constEnd(); ++i) {
94 ModemManager::Sms::Ptr sms = findMessage(i.key());
95 if (sms) {
96 list.append(sms);
97 } else {
98 qCWarning(MMQT) << "warning: null message for" << i.key();
99 }
100 }
101
102 return list;
103}
104
105void ModemManager::ModemMessagingPrivate::onPropertiesChanged(const QString &interfaceName,
106 const QVariantMap &changedProperties,
107 const QStringList &invalidatedProperties)
108{
109 Q_UNUSED(invalidatedProperties);
110
111 if (interfaceName == QLatin1String(MMQT_DBUS_INTERFACE_MODEM_MESSAGING)) {
112 QVariantMap::const_iterator it = changedProperties.constFind(QLatin1String(MM_MODEM_MESSAGING_PROPERTY_SUPPORTEDSTORAGES));
113 if (it != changedProperties.constEnd()) {
114 QList<MMSmsStorage> storages;
115 Q_FOREACH (uint storage, it->value<UIntList>()) {
116 storages.append((MMSmsStorage)storage);
117 }
118 supportedStorages = storages;
119 }
120 it = changedProperties.constFind(QLatin1String(MM_MODEM_MESSAGING_PROPERTY_DEFAULTSTORAGE));
121 if (it != changedProperties.constEnd()) {
122 defaultStorage = (MMSmsStorage)it->toInt();
123 }
124 // MESSAGES? should be handled by Added/Deleted signals
125 }
126}
127
128void ModemManager::ModemMessagingPrivate::onMessageAdded(const QDBusObjectPath &path, bool received)
129{
130 Q_Q(ModemMessaging);
131 messageList.insert(path.path(), ModemManager::Sms::Ptr());
132 Q_EMIT q->messageAdded(path.path(), received);
133}
134
135void ModemManager::ModemMessagingPrivate::onMessageDeleted(const QDBusObjectPath &path)
136{
137 Q_Q(ModemMessaging);
138 messageList.remove(path.path());
139 Q_EMIT q->messageDeleted(path.path());
140}
141
143{
144 Q_D(const ModemMessaging);
145 return d->supportedStorages;
146}
147
149{
150 Q_D(const ModemMessaging);
151 return d->defaultStorage;
152}
153
155{
156 Q_D(const ModemMessaging);
157 return const_cast<ModemMessagingPrivate *>(d)->messages();
158}
159
161{
162 QVariantMap map;
163 map.insert(QStringLiteral("number"), message.number);
164 map.insert(QStringLiteral("text"), message.text);
165 map.insert(QStringLiteral("data"), message.data);
166
167 return createMessage(map);
168}
169
171{
173
174 if (!message.contains(QLatin1String("number")) || (!message.contains(QLatin1String("text")) && !message.contains(QLatin1String("data")))) {
175 qCDebug(MMQT) << "Unable to create message, missing some property";
177 }
178
179 return d->modemMessagingIface.Create(message);
180}
181
183{
185 return d->modemMessagingIface.Delete(QDBusObjectPath(uni));
186}
187
189{
191 return d->findMessage(uni);
192}
193
195{
197 d->modemMessagingIface.setTimeout(timeout);
198}
199
201{
202 Q_D(const ModemMessaging);
203 return d->modemMessagingIface.timeout();
204}
205
206#include "moc_modemmessaging.cpp"
The ModemMessaging class.
QList< MMSmsStorage > supportedStorages() const
MMSmsStorage defaultStorage() const
QDBusPendingReply< QDBusObjectPath > createMessage(const Message &message)
Creates a new message object.
ModemManager::Sms::List messages() const
Retrieve all SMS messages.
int timeout() const
Returns the current value of the DBus timeout in milliseconds.
ModemManager::Sms::Ptr findMessage(const QString &uni)
QDBusPendingReply< void > deleteMessage(const QString &uni)
Delete an SMS message.
void setTimeout(int timeout)
Sets the timeout in milliseconds for all async method DBus calls.
Provides an interface to manipulate and control an SMS.
Definition sms.h:31
QString path(const QString &relativePath)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
bool connect(const QString &service, const QString &path, const QString &interface, const QString &name, QObject *receiver, const char *slot)
QDBusConnection sessionBus()
QDBusConnection systemBus()
QString path() const const
void append(QList< T > &&value)
void deleteLater()
QString & insert(qsizetype position, QChar ch)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 13 2024 11:49:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.