2 * This file is part of ofono-qt
4 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 * Contact: Alexander Kanavin <alexander.kanavin@nokia.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * version 2.1 as published by the Free Software Foundation.
12 * This library is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 #include <QtDBus/QtDBus>
25 #include <QtCore/QObject>
27 #include "ofonomodemmanager.h"
28 #include "ofonointerface.h"
30 struct OfonoModemStruct {
32 QVariantMap properties;
34 typedef QList<OfonoModemStruct> OfonoModemList;
35 Q_DECLARE_METATYPE(OfonoModemStruct)
36 Q_DECLARE_METATYPE(OfonoModemList)
38 QDBusArgument &operator<<(QDBusArgument &argument, const OfonoModemStruct &modem)
40 argument.beginStructure();
41 argument << modem.path << modem.properties;
42 argument.endStructure();
46 const QDBusArgument &operator>>(const QDBusArgument &argument, OfonoModemStruct &modem)
48 argument.beginStructure();
49 argument >> modem.path >> modem.properties;
50 argument.endStructure();
54 OfonoModemManager::OfonoModemManager(QObject *parent)
57 QDBusReply<OfonoModemList> reply;
58 OfonoModemList modems;
62 qDBusRegisterMetaType<OfonoModemStruct>();
63 qDBusRegisterMetaType<OfonoModemList>();
65 request = QDBusMessage::createMethodCall("org.ofono",
66 "/", "org.ofono.Manager",
68 reply = QDBusConnection::systemBus().call(request);
71 foreach(OfonoModemStruct modem, modems) {
72 m_modems << modem.path.path();
75 QDBusConnection::systemBus().connect("org.ofono","/","org.ofono.Manager",
77 SLOT(onModemAdded(const QDBusObjectPath&, const QVariantMap&)));
78 QDBusConnection::systemBus().connect("org.ofono","/","org.ofono.Manager",
80 SLOT(onModemRemoved(const QDBusObjectPath&)));
84 OfonoModemManager::~OfonoModemManager()
88 QStringList OfonoModemManager::modems() const
93 void OfonoModemManager::onModemAdded(const QDBusObjectPath& path, const QVariantMap& /*map*/)
95 m_modems << path.path();
96 emit modemAdded(path.path());
99 void OfonoModemManager::onModemRemoved(const QDBusObjectPath& path)
101 m_modems.removeAll(path.path());
102 emit modemRemoved(path.path());