1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
/**
* Copyright (C) 2013 Canonical, Ltd.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 3, as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
* SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Tiago Salem Herrmann <tiago.herrmann@canonical.com>
*/
#include <QtDBus>
#include <QObject>
#include "dbustypes.h"
#include "mmsdservice.h"
QDBusArgument &operator<<(QDBusArgument &argument, const MessageStruct &message)
{
argument.beginStructure();
argument << message.path << message.properties;
argument.endStructure();
return argument;
}
const QDBusArgument &operator>>(const QDBusArgument &argument, MessageStruct &message)
{
argument.beginStructure();
argument >> message.path >> message.properties;
argument.endStructure();
return argument;
}
QDBusArgument &operator<<(QDBusArgument&argument, const OutgoingAttachmentStruct &attachment)
{
argument.beginStructure();
argument << attachment.id << attachment.contentType << attachment.filePath;
argument.endStructure();
return argument;
}
const QDBusArgument &operator>>(const QDBusArgument &argument, OutgoingAttachmentStruct &attachment)
{
argument.beginStructure();
argument >> attachment.id >> attachment.contentType >> attachment.filePath;
argument.endStructure();
return argument;
}
MMSDService::MMSDService(QString objectPath, oFonoConnection* connection, QObject *parent)
: QObject(parent),
m_servicePath(objectPath)
{
QDBusReply<MessageList> replyMessages;
QDBusReply<QVariantMap> replyProperties;
QDBusMessage request;
qDBusRegisterMetaType<MessageStruct>();
qDBusRegisterMetaType<MessageList>();
qDBusRegisterMetaType<OutgoingAttachmentList>();
qDBusRegisterMetaType<OutgoingAttachmentStruct>();
request = QDBusMessage::createMethodCall("org.ofono.mms",
m_servicePath, "org.ofono.mms.Service",
"GetProperties");
replyProperties = QDBusConnection::sessionBus().call(request);
m_properties = replyProperties;
request = QDBusMessage::createMethodCall("org.ofono.mms",
m_servicePath, "org.ofono.mms.Service",
"GetMessages");
replyMessages = QDBusConnection::sessionBus().call(request);
m_messages = replyMessages;
QDBusConnection::sessionBus().connect("org.ofono.mms", m_servicePath, "org.ofono.mms.Service",
"MessageAdded", this,
SLOT(onMessageAdded(const QDBusObjectPath&, const QVariantMap&)));
QDBusConnection::sessionBus().connect("org.ofono.mms", m_servicePath, "org.ofono.mms.Service",
"MessageRemoved", this,
SLOT(onMessageRemoved(const QDBusObjectPath&)));
}
MMSDService::~MMSDService()
{
}
QString MMSDService::path() const
{
return m_servicePath;
}
QString MMSDService::modemObjectPath() const
{
return m_properties["ModemObjectPath"].value<QDBusObjectPath>().path();
}
QVariantMap MMSDService::properties() const
{
return m_properties;
}
MessageList MMSDService::messages() const
{
return m_messages;
}
void MMSDService::onMessageAdded(const QDBusObjectPath &path, const QVariantMap &properties)
{
qDebug() << "message added" << path.path() << properties;
Q_EMIT messageAdded(path.path(), properties);
}
void MMSDService::onMessageRemoved(const QDBusObjectPath& path)
{
qDebug() << "message removed" << path.path();
Q_EMIT messageRemoved(path.path());
}
QDBusObjectPath MMSDService::sendMessage(QStringList recipients, OutgoingAttachmentList attachments)
{
QDBusMessage request;
QList<QVariant> arguments;
QDBusReply<QDBusObjectPath> reply;
arguments.append(recipients);
arguments.append(QVariant::fromValue(attachments));
request = QDBusMessage::createMethodCall("org.ofono.mms",
m_servicePath, "org.ofono.mms.Service",
"SendMessage");
request.setArguments(arguments);
reply = QDBusConnection::sessionBus().call(request);
return reply;
}
|