~andreas-pokorny/telepathy-ofono/control-proximity-handling-in-powerd

« back to all changes in this revision

Viewing changes to mmsdservice.cpp

  • Committer: Tiago Salem Herrmann
  • Date: 2013-07-08 15:55:12 UTC
  • mto: This revision was merged to the branch mainline in revision 37.
  • Revision ID: tiago.herrmann@canonical.com-20130708155512-0n61cdowordh9sev
add initial mms support

Show diffs side-by-side

added added

removed removed

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