2
Copyright 2008 Will Stephenson <wstephenson@kde.org>
3
Copyright 2010 Lamarque Souza <lamarque@gmail.com>
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of
7
the License or (at your option) version 3 or any later version
8
accepted by the membership of KDE e.V. (or its successor approved
9
by the membership of KDE e.V.), which shall act as a proxy
10
defined in Section 14 of version 3 of the license.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program. If not, see <http://www.gnu.org/licenses/>.
22
#include "manager_p.h"
23
#include "modemcdmainterface.h"
24
#include "modemgsmcardinterface.h"
25
#include "modemgsmcontactsinterface.h"
26
#include "modemgsmnetworkinterface.h"
27
#include "modemgsmsmsinterface.h"
28
#include "modemgsmhsointerface.h"
29
#include "modemgsmussdinterface.h"
33
const QString MMModemManager::DBUS_SERVICE(QString::fromLatin1("org.freedesktop.ModemManager"));
34
const QString MMModemManager::DBUS_DAEMON_PATH(QString::fromLatin1("/org/freedesktop/ModemManager"));
36
MMModemManagerPrivate::MMModemManagerPrivate() : iface(MMModemManager::DBUS_SERVICE, "/org/freedesktop/ModemManager", QDBusConnection::systemBus())
38
kDebug(1441) << MMModemManager::DBUS_SERVICE;
41
MMModemManager::MMModemManager(QObject * parent, const QVariantList &)
42
: Solid::Control::Ifaces::ModemManager(parent)
44
qDBusRegisterMetaType<QList<QDBusObjectPath> >();
45
registerModemManagerTypes();
46
d_ptr = new MMModemManagerPrivate;
49
// TODO: determinate ModemManager initial state: Connected (MM running), Unknown (MM not running).
50
d->mmState = Solid::Networking::Connected;
52
connect( &d->iface, SIGNAL(DeviceAdded(const QDBusObjectPath &)),
53
this, SLOT(deviceAdded(const QDBusObjectPath &)));
54
connect( &d->iface, SIGNAL(DeviceRemoved(const QDBusObjectPath &)),
55
this, SLOT(deviceRemoved(const QDBusObjectPath &)));
57
d->iface.connection().connect(QLatin1String("org.freedesktop.DBus"),
58
QLatin1String("/org/freedesktop/DBus"), QLatin1String("org.freedesktop.DBus"),
59
QLatin1String("NameOwnerChanged"), QLatin1String("sss"),
60
this, SLOT(nameOwnerChanged(QString,QString,QString)));
62
QDBusReply< QList<QDBusObjectPath> > deviceList = d->iface.EnumerateDevices();
63
if (deviceList.isValid())
65
QList <QDBusObjectPath> devices = deviceList.value();
66
foreach (const QDBusObjectPath &op, devices)
68
d->modemInterfaces.append(op.path());
73
MMModemManager::~MMModemManager()
78
Solid::Networking::Status MMModemManager::status() const
80
Q_D(const MMModemManager);
84
QStringList MMModemManager::modemInterfaces() const
86
Q_D(const MMModemManager);
87
return d->modemInterfaces;
90
QObject *MMModemManager::createModemInterface(const QString &udi, const Solid::Control::ModemInterface::GsmInterfaceType ifaceType)
93
OrgFreedesktopModemManagerModemInterface modemIface(MMModemManager::DBUS_SERVICE, udi, QDBusConnection::systemBus());
94
uint modemType = modemIface.type();
95
MMModemInterface * createdInterface = 0;
96
switch ( modemType ) {
97
case Solid::Control::ModemInterface::GsmType:
99
case Solid::Control::ModemInterface::GsmCard:
100
createdInterface = new MMModemGsmCardInterface(udi, this, 0); // these are deleted by the frontend manager
102
case Solid::Control::ModemInterface::GsmContacts:
103
createdInterface = new MMModemGsmContactsInterface(udi, this, 0); // these are deleted by the frontend manager
105
case Solid::Control::ModemInterface::GsmNetwork:
106
createdInterface = new MMModemGsmNetworkInterface(udi, this, 0); // these are deleted by the frontend manager
108
case Solid::Control::ModemInterface::GsmSms:
109
createdInterface = new MMModemGsmSmsInterface(udi, this, 0); // these are deleted by the frontend manager
111
case Solid::Control::ModemInterface::GsmHso:
112
createdInterface = new MMModemGsmHsoInterface(udi, this, 0); // these are deleted by the frontend manager
114
case Solid::Control::ModemInterface::GsmUssd:
115
createdInterface = new MMModemGsmUssdInterface(udi, this, 0); // these are deleted by the frontend manager
117
case Solid::Control::ModemInterface::NotGsm: // to prevent compilation warning
121
case Solid::Control::ModemInterface::CdmaType:
122
createdInterface = new MMModemCdmaInterface(udi, this, 0); // these are deleted by the frontend manager
125
kDebug(1441) << "Can't create object of type " << modemType;
129
return createdInterface;
132
void MMModemManager::deviceAdded(const QDBusObjectPath & objpath)
136
d->modemInterfaces.append(objpath.path());
137
emit modemInterfaceAdded(objpath.path());
140
void MMModemManager::deviceRemoved(const QDBusObjectPath & objpath)
144
d->modemInterfaces.removeAll(objpath.path());
145
emit modemInterfaceRemoved(objpath.path());
148
void MMModemManager::stateChanged(Solid::Networking::Status state)
151
if ( d->mmState != state ) {
153
emit statusChanged( state );
157
void MMModemManager::nameOwnerChanged(QString name, QString oldOwner, QString newOwner)
161
if ( name == QLatin1String("org.freedesktop.ModemManager") ) {
162
kDebug(1441) << "name: " << name << ", old owner: " << oldOwner << ", new owner: " << newOwner;
163
if ( oldOwner.isEmpty() && !newOwner.isEmpty() ) {
164
stateChanged(Solid::Networking::Connected);
166
if ( !oldOwner.isEmpty() && newOwner.isEmpty() ) {
167
// ModemManager stopped, set status Unknown for safety
168
stateChanged(Solid::Networking::Unknown);
169
d->modemInterfaces.clear();
174
#include "manager.moc"