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

« back to all changes in this revision

Viewing changes to mmsdmanager.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 "mmsdmanager.h"
 
23
 
 
24
struct ServiceStruct {
 
25
    QDBusObjectPath path;
 
26
    QVariantMap properties;
 
27
};
 
28
 
 
29
typedef QList<ServiceStruct> ServiceList;
 
30
Q_DECLARE_METATYPE(ServiceStruct)
 
31
Q_DECLARE_METATYPE(ServiceList)
 
32
 
 
33
QDBusArgument &operator<<(QDBusArgument &argument, const ServiceStruct &service)
 
34
{
 
35
    argument.beginStructure();
 
36
    argument << service.path << service.properties;
 
37
    argument.endStructure();
 
38
    return argument;
 
39
}
 
40
 
 
41
const QDBusArgument &operator>>(const QDBusArgument &argument, ServiceStruct &service)
 
42
{
 
43
    argument.beginStructure();
 
44
    argument >> service.path >> service.properties;
 
45
    argument.endStructure();
 
46
    return argument;
 
47
}
 
48
 
 
49
MMSDManager::MMSDManager(QObject *parent)
 
50
    : QObject(parent)
 
51
{
 
52
    QDBusReply<ServiceList> reply;
 
53
    ServiceList services;
 
54
 
 
55
    QDBusMessage request;
 
56
 
 
57
    qDBusRegisterMetaType<ServiceStruct>();
 
58
    qDBusRegisterMetaType<ServiceList>();
 
59
 
 
60
    request = QDBusMessage::createMethodCall("org.ofono.mms",
 
61
                                             "/org/ofono/mms", "org.ofono.mms.Manager",
 
62
                                             "GetServices");
 
63
    reply = QDBusConnection::sessionBus().call(request);
 
64
 
 
65
    services = reply;
 
66
    Q_FOREACH(ServiceStruct service, services) {
 
67
        m_services << service.path.path();
 
68
    }
 
69
 
 
70
    QDBusConnection::sessionBus().connect("org.ofono.mms","/org/ofono/mms","org.ofono.mms.Manager",
 
71
                                          "ServiceAdded", this, 
 
72
                                          SLOT(onServiceAdded(const QDBusObjectPath&, const QVariantMap&)));
 
73
    QDBusConnection::sessionBus().connect("org.ofono.mms","/org/ofono/mms","org.ofono.mms.Manager",
 
74
                                          "ServiceRemoved", this, 
 
75
                                          SLOT(onServiceRemoved(const QDBusObjectPath&)));
 
76
}
 
77
 
 
78
MMSDManager::~MMSDManager()
 
79
{
 
80
}
 
81
 
 
82
QStringList MMSDManager::services() const
 
83
{
 
84
    return m_services;
 
85
}
 
86
 
 
87
void MMSDManager::onServiceAdded(const QDBusObjectPath& path, const QVariantMap& map)
 
88
{
 
89
    qDebug() << "service added" << path.path() << map;
 
90
    m_services << path.path();
 
91
    Q_EMIT serviceAdded(path.path());
 
92
}
 
93
 
 
94
void MMSDManager::onServiceRemoved(const QDBusObjectPath& path)
 
95
{
 
96
    qDebug() << "service removed" << path.path();
 
97
    m_services.removeAll(path.path());
 
98
    Q_EMIT serviceRemoved(path.path());
 
99
}