~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to solid/modemmanager-0.4/manager.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright 2008 Will Stephenson <wstephenson@kde.org>
 
3
Copyright 2010 Lamarque Souza <lamarque@gmail.com>
 
4
 
 
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.
 
11
 
 
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.
 
16
 
 
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/>.
 
19
*/
 
20
 
 
21
#include "manager.h"
 
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"
 
30
 
 
31
#include <KDebug>
 
32
 
 
33
const QString MMModemManager::DBUS_SERVICE(QString::fromLatin1("org.freedesktop.ModemManager"));
 
34
const QString MMModemManager::DBUS_DAEMON_PATH(QString::fromLatin1("/org/freedesktop/ModemManager"));
 
35
 
 
36
MMModemManagerPrivate::MMModemManagerPrivate() : iface(MMModemManager::DBUS_SERVICE, "/org/freedesktop/ModemManager", QDBusConnection::systemBus())
 
37
{
 
38
    kDebug(1441) << MMModemManager::DBUS_SERVICE;
 
39
}
 
40
 
 
41
MMModemManager::MMModemManager(QObject * parent, const QVariantList &)
 
42
    : Solid::Control::Ifaces::ModemManager(parent)
 
43
{
 
44
    qDBusRegisterMetaType<QList<QDBusObjectPath> >();
 
45
    registerModemManagerTypes();
 
46
    d_ptr = new MMModemManagerPrivate;
 
47
    Q_D(MMModemManager);
 
48
 
 
49
    // TODO: determinate ModemManager initial state: Connected (MM running), Unknown (MM not running).
 
50
    d->mmState = Solid::Networking::Connected;
 
51
 
 
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 &)));
 
56
 
 
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)));
 
61
 
 
62
    QDBusReply< QList<QDBusObjectPath> > deviceList = d->iface.EnumerateDevices();
 
63
    if (deviceList.isValid())
 
64
    {
 
65
        QList <QDBusObjectPath> devices = deviceList.value();
 
66
        foreach (const QDBusObjectPath &op, devices)
 
67
        {
 
68
            d->modemInterfaces.append(op.path());
 
69
        }
 
70
    }
 
71
}
 
72
 
 
73
MMModemManager::~MMModemManager()
 
74
{
 
75
    delete d_ptr;
 
76
}
 
77
 
 
78
Solid::Networking::Status MMModemManager::status() const
 
79
{
 
80
    Q_D(const MMModemManager);
 
81
    return d->mmState;
 
82
}
 
83
 
 
84
QStringList MMModemManager::modemInterfaces() const
 
85
{
 
86
    Q_D(const MMModemManager);
 
87
    return d->modemInterfaces;
 
88
}
 
89
 
 
90
QObject *MMModemManager::createModemInterface(const QString &udi, const Solid::Control::ModemInterface::GsmInterfaceType ifaceType)
 
91
{
 
92
    kDebug(1441);
 
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:
 
98
            switch (ifaceType) {
 
99
                case Solid::Control::ModemInterface::GsmCard:
 
100
                    createdInterface = new MMModemGsmCardInterface(udi, this, 0); // these are deleted by the frontend manager
 
101
                break;
 
102
                case Solid::Control::ModemInterface::GsmContacts:
 
103
                    createdInterface = new MMModemGsmContactsInterface(udi, this, 0); // these are deleted by the frontend manager
 
104
                break;
 
105
                case Solid::Control::ModemInterface::GsmNetwork:
 
106
                    createdInterface = new MMModemGsmNetworkInterface(udi, this, 0); // these are deleted by the frontend manager
 
107
                break;
 
108
                case Solid::Control::ModemInterface::GsmSms:
 
109
                    createdInterface = new MMModemGsmSmsInterface(udi, this, 0); // these are deleted by the frontend manager
 
110
                break;
 
111
                case Solid::Control::ModemInterface::GsmHso:
 
112
                    createdInterface = new MMModemGsmHsoInterface(udi, this, 0); // these are deleted by the frontend manager
 
113
                break;
 
114
                case Solid::Control::ModemInterface::GsmUssd:
 
115
                    createdInterface = new MMModemGsmUssdInterface(udi, this, 0); // these are deleted by the frontend manager
 
116
                break;
 
117
                case Solid::Control::ModemInterface::NotGsm: // to prevent compilation warning
 
118
                break;
 
119
            }
 
120
            break;
 
121
        case Solid::Control::ModemInterface::CdmaType:
 
122
            createdInterface = new MMModemCdmaInterface(udi, this, 0); // these are deleted by the frontend manager
 
123
            break;
 
124
        default:
 
125
            kDebug(1441) << "Can't create object of type " << modemType;
 
126
            break;
 
127
    }
 
128
 
 
129
    return createdInterface;
 
130
}
 
131
 
 
132
void MMModemManager::deviceAdded(const QDBusObjectPath & objpath)
 
133
{
 
134
    kDebug(1441);
 
135
    Q_D(MMModemManager);
 
136
    d->modemInterfaces.append(objpath.path());
 
137
    emit modemInterfaceAdded(objpath.path());
 
138
}
 
139
 
 
140
void MMModemManager::deviceRemoved(const QDBusObjectPath & objpath)
 
141
{
 
142
    kDebug(1441);
 
143
    Q_D(MMModemManager);
 
144
    d->modemInterfaces.removeAll(objpath.path());
 
145
    emit modemInterfaceRemoved(objpath.path());
 
146
}
 
147
 
 
148
void MMModemManager::stateChanged(Solid::Networking::Status state)
 
149
{
 
150
    Q_D(MMModemManager);
 
151
    if ( d->mmState != state ) {
 
152
        d->mmState = state;
 
153
        emit statusChanged( state );
 
154
    }
 
155
}
 
156
 
 
157
void MMModemManager::nameOwnerChanged(QString name, QString oldOwner, QString newOwner)
 
158
{
 
159
    Q_D(MMModemManager);
 
160
 
 
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);
 
165
        }
 
166
        if ( !oldOwner.isEmpty() && newOwner.isEmpty() ) {
 
167
            // ModemManager stopped, set status Unknown for safety
 
168
            stateChanged(Solid::Networking::Unknown);
 
169
            d->modemInterfaces.clear();
 
170
        }
 
171
    }
 
172
}
 
173
 
 
174
#include "manager.moc"
 
175