ModemManagerQt

fakemodem/modemmessaging.cpp
1/*
2 SPDX-FileCopyrightText: 2015 Jan Grulich <jgrulich@redhat.com>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "modemmessaging.h"
8
9#include <QDBusConnection>
10#include <QDBusMessage>
11
12ModemMessaging::ModemMessaging(QObject *parent)
13 : QDBusAbstractAdaptor(parent)
14 , m_enabledNotifications(false)
15 , m_messageCounter(0)
16 , m_defaultStorage(0)
17{
18}
19
20ModemMessaging::~ModemMessaging()
21{
22}
23
24uint ModemMessaging::defaultStorage() const
25{
26 return m_defaultStorage;
27}
28
29QList<QDBusObjectPath> ModemMessaging::messages() const
30{
31 return m_messages.keys();
32}
33
34ModemManager::UIntList ModemMessaging::supportedStorages() const
35{
36 return m_supportedStorages;
37}
38
39QDBusObjectPath ModemMessaging::Create(const QVariantMap &properties)
40{
41 Q_UNUSED(properties);
42 return QDBusObjectPath();
43}
44
45void ModemMessaging::Delete(const QDBusObjectPath &path)
46{
47 m_messages.remove(path);
49
50 Q_EMIT Deleted(path);
51}
52
53QList<QDBusObjectPath> ModemMessaging::List()
54{
55 return m_messages.keys();
56}
57
58void ModemMessaging::setModemPath(const QString &path)
59{
60 m_modemPath = path;
61}
62
63void ModemMessaging::setEnableNotifications(bool enable)
64{
65 m_enabledNotifications = enable;
66}
67
68void ModemMessaging::addMessage(Sms *sms)
69{
70 QString newSmsPath = QStringLiteral("/org/kde/fakemodem/Sms/") + QString::number(m_messageCounter++);
71 sms->setSmsPath(newSmsPath);
72 sms->setEnableNotifications(true);
73 m_messages.insert(QDBusObjectPath(newSmsPath), sms);
75 Q_EMIT Added(QDBusObjectPath(newSmsPath), false);
76}
77
78void ModemMessaging::setDefaultStorage(uint defaultStorage)
79{
80 m_defaultStorage = defaultStorage;
81
82 if (m_enabledNotifications) {
83 QVariantMap map;
84 map.insert(QLatin1String("DefaultStorage"), m_defaultStorage);
85 QDBusMessage message = QDBusMessage::createSignal(m_modemPath, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
86 message << QLatin1String("org.kde.fakemodem.Modem.Messaging") << map << QStringList();
88 }
89}
90
91void ModemMessaging::setSupportedStorages(const ModemManager::UIntList &supportedStorages)
92{
93 m_supportedStorages = supportedStorages;
94
95 if (m_enabledNotifications) {
96 QVariantMap map;
97 map.insert(QLatin1String("SupportedStorages"), QVariant::fromValue<ModemManager::UIntList>(m_supportedStorages));
98 QDBusMessage message = QDBusMessage::createSignal(m_modemPath, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
99 message << QLatin1String("org.kde.fakemodem.Modem.Messaging") << map << QStringList();
101 }
102}
103
104QVariantMap ModemMessaging::toMap() const
105{
106 QVariantMap map;
107#if MM_CHECK_VERSION(1, 2, 0)
108 map.insert(QLatin1String(MM_MODEM_MESSAGING_PROPERTY_MESSAGES), QVariant::fromValue<QList<QDBusObjectPath>>(m_messages.keys()));
109#endif
110 map.insert(QLatin1String(MM_MODEM_MESSAGING_PROPERTY_SUPPORTEDSTORAGES), QVariant::fromValue<ModemManager::UIntList>(m_supportedStorages));
111 map.insert(QLatin1String(MM_MODEM_MESSAGING_PROPERTY_DEFAULTSTORAGE), m_defaultStorage);
112 return map;
113}
114
115#include "moc_modemmessaging.cpp"
QString path(const QString &relativePath)
bool registerObject(const QString &path, QObject *object, RegisterOptions options)
bool send(const QDBusMessage &message) const const
QDBusConnection sessionBus()
void unregisterObject(const QString &path, UnregisterMode mode)
QDBusMessage createSignal(const QString &path, const QString &interface, const QString &name)
iterator insert(const Key &key, const T &value)
QList< Key > keys() const const
size_type remove(const Key &key)
Q_EMITQ_EMIT
QString number(double n, char format, int precision)
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)
QVariant fromValue(T &&value)
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.