Ticket #46496: Use-a-property-cache-to-cut-down-on-blocking-calls.patch

File Use-a-property-cache-to-cut-down-on-blocking-calls.patch, 165.7 KB (added by RJVB (René Bertin), 9 years ago)

from Ubuntu

  • qtbase/src/plugins/bearer/connman/connman.pro

    From 1df2cd6af5c40db588fc3ec40c7adfafc1b5eea3 Mon Sep 17 00:00:00 2001
    From: Lorn Potter <lorn.potter@gmail.com>
    Date: Wed, 29 Oct 2014 19:40:43 +1000
    Subject: [PATCH] Use a property cache to cut down on blocking calls
    
    Refactor old code
    Stop memory leaks
    Properly support mobile data (ofono)
    
    Change-Id: I7f23882ee0ee345a049a4a93ddd452b6d2e53710
    ---
     src/plugins/bearer/connman/connman.pro             |   4 +-
     src/plugins/bearer/connman/qconnmanengine.h        |   2 +-
     src/plugins/bearer/connman/qofonoservice_linux.cpp | 303 ---------
     src/plugins/bearer/connman/qofonoservice_linux_p.h | 172 -----
     .../bearer/linux_common/qofonoservice_linux.cpp    | 370 +++++++++++
     .../bearer/linux_common/qofonoservice_linux_p.h    | 195 ++++++
     .../bearer/networkmanager/networkmanager.pro       |   6 +-
     .../networkmanager/qnetworkmanagerengine.cpp       | 364 +++++------
     .../bearer/networkmanager/qnetworkmanagerengine.h  |  22 +-
     .../networkmanager/qnetworkmanagerservice.cpp      | 693 +++++++++++++++------
     .../bearer/networkmanager/qnetworkmanagerservice.h | 105 +++-
     .../bearer/networkmanager/qnmdbushelper.cpp        | 140 -----
     src/plugins/bearer/networkmanager/qnmdbushelper.h  |  73 ---
     13 files changed, 1318 insertions(+), 1131 deletions(-)
     delete mode 100644 src/plugins/bearer/connman/qofonoservice_linux.cpp
     delete mode 100644 src/plugins/bearer/connman/qofonoservice_linux_p.h
     create mode 100644 src/plugins/bearer/linux_common/qofonoservice_linux.cpp
     create mode 100644 src/plugins/bearer/linux_common/qofonoservice_linux_p.h
     delete mode 100644 src/plugins/bearer/networkmanager/qnmdbushelper.cpp
     delete mode 100644 src/plugins/bearer/networkmanager/qnmdbushelper.h
    
     
    88CONFIG += link_pkgconfig
    99
    1010HEADERS += qconnmanservice_linux_p.h \
    11            qofonoservice_linux_p.h \
     11           ../linux_common/qofonoservice_linux_p.h \
    1212           qconnmanengine.h \
    1313           ../qnetworksession_impl.h \
    1414           ../qbearerengine_impl.h
    1515
    1616SOURCES += main.cpp \
    1717           qconnmanservice_linux.cpp \
    18            qofonoservice_linux.cpp \
     18           ../linux_common/qofonoservice_linux.cpp \
    1919           qconnmanengine.cpp \
    2020           ../qnetworksession_impl.cpp
    2121
  • qtbase/src/plugins/bearer/connman/qconnmanengine.h

     
    5656#include "../qbearerengine_impl.h"
    5757
    5858#include "qconnmanservice_linux_p.h"
    59 #include "qofonoservice_linux_p.h"
     59#include "../linux_common/qofonoservice_linux_p.h"
    6060
    6161#include <QMap>
    6262#include <QVariant>
  • new file qtbase/src/plugins/bearer/linux_common/qofonoservice_linux.cpp

    - +  
     1/****************************************************************************
     2**
     3** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
     4** Contact: http://www.qt-project.org/legal
     5**
     6** This file is part of the plugins of the Qt Toolkit.
     7**
     8** $QT_BEGIN_LICENSE:LGPL21$
     9** Commercial License Usage
     10** Licensees holding valid commercial Qt licenses may use this file in
     11** accordance with the commercial license agreement provided with the
     12** Software or, alternatively, in accordance with the terms contained in
     13** a written agreement between you and Digia. For licensing terms and
     14** conditions see http://qt.digia.com/licensing. For further information
     15** use the contact form at http://qt.digia.com/contact-us.
     16**
     17** GNU Lesser General Public License Usage
     18** Alternatively, this file may be used under the terms of the GNU Lesser
     19** General Public License version 2.1 or version 3 as published by the Free
     20** Software Foundation and appearing in the file LICENSE.LGPLv21 and
     21** LICENSE.LGPLv3 included in the packaging of this file. Please review the
     22** following information to ensure the GNU Lesser General Public License
     23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
     24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
     25**
     26** In addition, as a special exception, Digia gives you certain additional
     27** rights. These rights are described in the Digia Qt LGPL Exception
     28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
     29**
     30** $QT_END_LICENSE$
     31**
     32****************************************************************************/
     33
     34#include <QObject>
     35#include <QList>
     36#include <QtDBus/QtDBus>
     37#include <QtDBus/QDBusConnection>
     38#include <QtDBus/QDBusError>
     39#include <QtDBus/QDBusInterface>
     40#include <QtDBus/QDBusMessage>
     41#include <QtDBus/QDBusReply>
     42#include <QtDBus/QDBusPendingCallWatcher>
     43#include <QtDBus/QDBusObjectPath>
     44#include <QtDBus/QDBusPendingCall>
     45
     46#include "qofonoservice_linux_p.h"
     47
     48#ifndef QT_NO_BEARERMANAGEMENT
     49#ifndef QT_NO_DBUS
     50
     51QDBusArgument &operator<<(QDBusArgument &argument, const ObjectPathProperties &item)
     52{
     53    argument.beginStructure();
     54    argument << item.path << item.properties;
     55    argument.endStructure();
     56    return argument;
     57}
     58
     59const QDBusArgument &operator>>(const QDBusArgument &argument, ObjectPathProperties &item)
     60{
     61    argument.beginStructure();
     62    argument >> item.path >> item.properties;
     63    argument.endStructure();
     64    return argument;
     65}
     66
     67QT_BEGIN_NAMESPACE
     68
     69QOfonoManagerInterface::QOfonoManagerInterface( QObject *parent)
     70        : QDBusAbstractInterface(QStringLiteral(OFONO_SERVICE),
     71                                 QStringLiteral(OFONO_MANAGER_PATH),
     72                                 OFONO_MANAGER_INTERFACE,
     73                                 QDBusConnection::systemBus(), parent)
     74{
     75    qDBusRegisterMetaType<ObjectPathProperties>();
     76    qDBusRegisterMetaType<PathPropertiesList>();
     77
     78    QDBusConnection::systemBus().connect(QStringLiteral(OFONO_SERVICE),
     79                           QStringLiteral(OFONO_MANAGER_PATH),
     80                           QStringLiteral(OFONO_MANAGER_INTERFACE),
     81                           QStringLiteral("ModemAdded"),
     82                           this,SLOT(modemAdded(QDBusObjectPath, QVariantMap)));
     83    QDBusConnection::systemBus().connect(QStringLiteral(OFONO_SERVICE),
     84                           QStringLiteral(OFONO_MANAGER_PATH),
     85                           QStringLiteral(OFONO_MANAGER_INTERFACE),
     86                           QStringLiteral("ModemRemoved"),
     87                           this,SLOT(modemRemoved(QDBusObjectPath)));
     88}
     89
     90QOfonoManagerInterface::~QOfonoManagerInterface()
     91{
     92}
     93
     94QStringList QOfonoManagerInterface::getModems()
     95{
     96    if (modemList.isEmpty()) {
     97        QList<QVariant> argumentList;
     98        QDBusPendingReply<PathPropertiesList> reply = callWithArgumentList(QDBus::Block, QLatin1String("GetModems"), argumentList);
     99        reply.waitForFinished();
     100        if (!reply.isError()) {
     101            foreach (ObjectPathProperties modem, reply.value()) {
     102                modemList << modem.path.path();
     103            }
     104        }
     105    }
     106
     107    return modemList;
     108}
     109
     110QString QOfonoManagerInterface::currentModem()
     111{
     112    QStringList modems = getModems();
     113    foreach (const QString &modem, modems) {
     114        QOfonoModemInterface device(modem);
     115        if (device.isPowered() && device.isOnline())
     116        return modem;
     117    }
     118    return QString();
     119}
     120
     121void QOfonoManagerInterface::modemAdded(const QDBusObjectPath &path, const QVariantMap &/*var*/)
     122{
     123    if (!modemList.contains(path.path())) {
     124        modemList << path.path();
     125        Q_EMIT modemChanged();
     126    }
     127}
     128
     129void QOfonoManagerInterface::modemRemoved(const QDBusObjectPath &path)
     130{
     131    if (modemList.contains(path.path())) {
     132        modemList.removeOne(path.path());
     133        Q_EMIT modemChanged();
     134    }
     135}
     136
     137
     138QOfonoModemInterface::QOfonoModemInterface(const QString &dbusPathName, QObject *parent)
     139    : QDBusAbstractInterface(QStringLiteral(OFONO_SERVICE),
     140                             dbusPathName,
     141                             OFONO_MODEM_INTERFACE,
     142                             QDBusConnection::systemBus(), parent)
     143{
     144    QDBusConnection::systemBus().connect(QStringLiteral(OFONO_SERVICE),
     145                                         path(),
     146                                         OFONO_MODEM_INTERFACE,
     147                                         QStringLiteral("PropertyChanged"),
     148                                         this,SLOT(propertyChanged(QString,QDBusVariant)));
     149}
     150
     151QOfonoModemInterface::~QOfonoModemInterface()
     152{
     153}
     154
     155void QOfonoModemInterface::propertyChanged(const QString &name,const QDBusVariant &value)
     156{
     157    propertiesMap[name] = value.variant();
     158}
     159
     160bool QOfonoModemInterface::isPowered()
     161{
     162    QVariant var = getProperty(QStringLiteral("Powered"));
     163    return qdbus_cast<bool>(var);
     164}
     165
     166bool QOfonoModemInterface::isOnline()
     167{
     168    QVariant var = getProperty(QStringLiteral("Online"));
     169    return qdbus_cast<bool>(var);
     170}
     171
     172QVariantMap QOfonoModemInterface::getProperties()
     173{
     174    if (propertiesMap.isEmpty()) {
     175        QList<QVariant> argumentList;
     176        QDBusPendingReply<QVariantMap> reply = callWithArgumentList(QDBus::Block, QLatin1String("GetProperties"), argumentList);
     177        if (!reply.isError()) {
     178            propertiesMap = reply.value();
     179        }
     180    }
     181    return propertiesMap;
     182}
     183
     184QVariant QOfonoModemInterface::getProperty(const QString &property)
     185{
     186    QVariant var;
     187    QVariantMap map = getProperties();
     188    if (map.contains(property))
     189        var = map.value(property);
     190    return var;
     191}
     192
     193
     194QOfonoNetworkRegistrationInterface::QOfonoNetworkRegistrationInterface(const QString &dbusPathName, QObject *parent)
     195    : QDBusAbstractInterface(QStringLiteral(OFONO_SERVICE),
     196                             dbusPathName,
     197                             OFONO_NETWORK_REGISTRATION_INTERFACE,
     198                             QDBusConnection::systemBus(), parent)
     199{
     200}
     201
     202QOfonoNetworkRegistrationInterface::~QOfonoNetworkRegistrationInterface()
     203{
     204}
     205
     206QString QOfonoNetworkRegistrationInterface::getTechnology()
     207{
     208    QVariant var = getProperty(QStringLiteral("Technology"));
     209    return qdbus_cast<QString>(var);
     210}
     211
     212QVariant QOfonoNetworkRegistrationInterface::getProperty(const QString &property)
     213{
     214    QVariant var;
     215    QVariantMap map = getProperties();
     216    if (map.contains(property))
     217        var = map.value(property);
     218    return var;
     219}
     220
     221QVariantMap QOfonoNetworkRegistrationInterface::getProperties()
     222{
     223    if (propertiesMap.isEmpty()) {
     224        QList<QVariant> argumentList;
     225        QDBusPendingReply<QVariantMap> reply = callWithArgumentList(QDBus::Block, QLatin1String("GetProperties"), argumentList);
     226        reply.waitForFinished();
     227        if (!reply.isError()) {
     228            propertiesMap = reply.value();
     229        }
     230    }
     231    return propertiesMap;
     232}
     233
     234QOfonoDataConnectionManagerInterface::QOfonoDataConnectionManagerInterface(const QString &dbusPathName, QObject *parent)
     235    : QDBusAbstractInterface(QLatin1String(OFONO_SERVICE),
     236                             dbusPathName,
     237                             OFONO_DATA_CONNECTION_MANAGER_INTERFACE,
     238                             QDBusConnection::systemBus(), parent)
     239{
     240    QDBusConnection::systemBus().connect(QLatin1String(OFONO_SERVICE),
     241                                         path(),
     242                                         QLatin1String(OFONO_MODEM_INTERFACE),
     243                                         QLatin1String("PropertyChanged"),
     244                                         this,SLOT(propertyChanged(QString,QDBusVariant)));
     245}
     246
     247QOfonoDataConnectionManagerInterface::~QOfonoDataConnectionManagerInterface()
     248{
     249}
     250
     251QStringList QOfonoDataConnectionManagerInterface::contexts()
     252{
     253    if (contextList.isEmpty()) {
     254        QDBusPendingReply<PathPropertiesList > reply = call(QLatin1String("GetContexts"));
     255        reply.waitForFinished();
     256        if (!reply.isError()) {
     257            foreach (ObjectPathProperties context, reply.value()) {
     258                contextList << context.path.path();
     259            }
     260        }
     261    }
     262    return contextList;
     263}
     264
     265bool QOfonoDataConnectionManagerInterface::roamingAllowed()
     266{
     267    QVariant var = getProperty(QStringLiteral("RoamingAllowed"));
     268    return qdbus_cast<bool>(var);
     269}
     270
     271QString QOfonoDataConnectionManagerInterface::bearer()
     272{
     273    QVariant var = getProperty(QStringLiteral("Bearer"));
     274    return qdbus_cast<QString>(var);
     275}
     276
     277QVariant QOfonoDataConnectionManagerInterface::getProperty(const QString &property)
     278{
     279    QVariant var;
     280    QVariantMap map = getProperties();
     281    if (map.contains(property))
     282        var = map.value(property);
     283    return var;
     284}
     285
     286QVariantMap QOfonoDataConnectionManagerInterface::getProperties()
     287{
     288    if (propertiesMap.isEmpty()) {
     289        QList<QVariant> argumentList;
     290        QDBusPendingReply<QVariantMap> reply = callWithArgumentList(QDBus::Block, QLatin1String("GetProperties"), argumentList);
     291        if (!reply.isError()) {
     292            propertiesMap = reply.value();
     293        }
     294    }
     295    return propertiesMap;
     296}
     297
     298void QOfonoDataConnectionManagerInterface::propertyChanged(const QString &name, const QDBusVariant &value)
     299{
     300    propertiesMap[name] = value.variant();
     301    if (name == QLatin1String("RoamingAllowed"))
     302        Q_EMIT roamingAllowedChanged(value.variant().toBool());
     303}
     304
     305
     306QOfonoConnectionContextInterface::QOfonoConnectionContextInterface(const QString &dbusPathName, QObject *parent)
     307    : QDBusAbstractInterface(QLatin1String(OFONO_SERVICE),
     308                             dbusPathName,
     309                             OFONO_CONNECTION_CONTEXT_INTERFACE,
     310                             QDBusConnection::systemBus(), parent)
     311{
     312    QDBusConnection::systemBus().connect(QLatin1String(OFONO_SERVICE),
     313                                         path(),
     314                                         QLatin1String(OFONO_MODEM_INTERFACE),
     315                                         QLatin1String("PropertyChanged"),
     316                                         this,SLOT(propertyChanged(QString,QDBusVariant)));
     317}
     318
     319QOfonoConnectionContextInterface::~QOfonoConnectionContextInterface()
     320{
     321}
     322
     323QVariantMap QOfonoConnectionContextInterface::getProperties()
     324{
     325    if (propertiesMap.isEmpty()) {
     326        QList<QVariant> argumentList;
     327        QDBusPendingReply<QVariantMap> reply = callWithArgumentList(QDBus::Block, QLatin1String("GetProperties"), argumentList);
     328        if (!reply.isError()) {
     329            propertiesMap = reply.value();
     330        }
     331    }
     332    return propertiesMap;
     333}
     334
     335void QOfonoConnectionContextInterface::propertyChanged(const QString &name, const QDBusVariant &value)
     336{
     337    propertiesMap[name] = value.variant();
     338}
     339
     340QVariant QOfonoConnectionContextInterface::getProperty(const QString &property)
     341{
     342    QVariant var;
     343    QVariantMap map = getProperties();
     344    if (map.contains(property))
     345        var = map.value(property);
     346    return var;
     347}
     348
     349bool QOfonoConnectionContextInterface::active()
     350{
     351    QVariant var = getProperty(QStringLiteral("Active"));
     352    return qdbus_cast<bool>(var);
     353}
     354
     355QString QOfonoConnectionContextInterface::accessPointName()
     356{
     357    QVariant var = getProperty(QStringLiteral("AccessPointName"));
     358    return qdbus_cast<QString>(var);
     359}
     360
     361QString QOfonoConnectionContextInterface::name()
     362{
     363    QVariant var = getProperty(QStringLiteral("Name"));
     364    return qdbus_cast<QString>(var);
     365}
     366
     367QT_END_NAMESPACE
     368
     369#endif // QT_NO_DBUS
     370#endif // QT_NO_BEARERMANAGEMENT
  • new file qtbase/src/plugins/bearer/linux_common/qofonoservice_linux_p.h

    - +  
     1/****************************************************************************
     2**
     3** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
     4** Contact: http://www.qt-project.org/legal
     5**
     6** This file is part of the plugins of the Qt Toolkit.
     7**
     8** $QT_BEGIN_LICENSE:LGPL21$
     9** Commercial License Usage
     10** Licensees holding valid commercial Qt licenses may use this file in
     11** accordance with the commercial license agreement provided with the
     12** Software or, alternatively, in accordance with the terms contained in
     13** a written agreement between you and Digia. For licensing terms and
     14** conditions see http://qt.digia.com/licensing. For further information
     15** use the contact form at http://qt.digia.com/contact-us.
     16**
     17** GNU Lesser General Public License Usage
     18** Alternatively, this file may be used under the terms of the GNU Lesser
     19** General Public License version 2.1 or version 3 as published by the Free
     20** Software Foundation and appearing in the file LICENSE.LGPLv21 and
     21** LICENSE.LGPLv3 included in the packaging of this file. Please review the
     22** following information to ensure the GNU Lesser General Public License
     23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
     24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
     25**
     26** In addition, as a special exception, Digia gives you certain additional
     27** rights. These rights are described in the Digia Qt LGPL Exception
     28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
     29**
     30** $QT_END_LICENSE$
     31**
     32****************************************************************************/
     33
     34#ifndef QOFONOSERVICE_H
     35#define QOFONOSERVICE_H
     36
     37//
     38//  W A R N I N G
     39//  -------------
     40//
     41// This file is not part of the Qt API.  It exists purely as an
     42// implementation detail.  This header file may change from version to
     43// version without notice, or even be removed.
     44//
     45// We mean it.
     46//
     47
     48#include <QtDBus/QtDBus>
     49#include <QtDBus/QDBusConnection>
     50#include <QtDBus/QDBusError>
     51#include <QtDBus/QDBusInterface>
     52#include <QtDBus/QDBusMessage>
     53#include <QtDBus/QDBusReply>
     54
     55#include <QtDBus/QDBusPendingCallWatcher>
     56#include <QtDBus/QDBusObjectPath>
     57#include <QtDBus/QDBusContext>
     58#include <QMap>
     59
     60#ifndef QT_NO_BEARERMANAGEMENT
     61#ifndef QT_NO_DBUS
     62
     63#define OFONO_SERVICE                            "org.ofono"
     64#define OFONO_MANAGER_INTERFACE                  "org.ofono.Manager"
     65#define OFONO_MANAGER_PATH                       "/"
     66
     67#define OFONO_MODEM_INTERFACE                    "org.ofono.Modem"
     68#define OFONO_NETWORK_REGISTRATION_INTERFACE     "org.ofono.NetworkRegistration"
     69#define OFONO_DATA_CONNECTION_MANAGER_INTERFACE  "org.ofono.ConnectionManager"
     70#define OFONO_CONNECTION_CONTEXT_INTERFACE       "org.ofono.ConnectionContext"
     71
     72QT_BEGIN_NAMESPACE
     73
     74QT_END_NAMESPACE
     75
     76struct ObjectPathProperties
     77{
     78    QDBusObjectPath path;
     79    QVariantMap properties;
     80};
     81typedef QList<ObjectPathProperties> PathPropertiesList;
     82Q_DECLARE_METATYPE(ObjectPathProperties)
     83Q_DECLARE_METATYPE (PathPropertiesList)
     84
     85QT_BEGIN_NAMESPACE
     86
     87class QOfonoManagerInterface : public  QDBusAbstractInterface
     88{
     89    Q_OBJECT
     90
     91public:
     92
     93    QOfonoManagerInterface( QObject *parent = 0);
     94    ~QOfonoManagerInterface();
     95
     96    QStringList getModems();
     97    QString currentModem();
     98signals:
     99    void modemChanged();
     100private:
     101    QStringList modemList;
     102private slots:
     103    void modemAdded(const QDBusObjectPath &path, const QVariantMap &var);
     104    void modemRemoved(const QDBusObjectPath &path);
     105};
     106
     107class QOfonoModemInterface : public QDBusAbstractInterface
     108{
     109    Q_OBJECT
     110
     111public:
     112
     113    explicit QOfonoModemInterface(const QString &dbusModemPathName, QObject *parent = 0);
     114    ~QOfonoModemInterface();
     115
     116    bool isPowered();
     117    bool isOnline();
     118private:
     119    QVariantMap getProperties();
     120    QVariantMap propertiesMap;
     121    QVariant getProperty(const QString &);
     122    void propertyChanged(const QString &, const QDBusVariant &value);
     123};
     124
     125
     126class QOfonoNetworkRegistrationInterface : public QDBusAbstractInterface
     127{
     128    Q_OBJECT
     129
     130public:
     131
     132    explicit QOfonoNetworkRegistrationInterface(const QString &dbusModemPathName, QObject *parent = 0);
     133    ~QOfonoNetworkRegistrationInterface();
     134
     135    QString getTechnology();
     136
     137private:
     138    QVariantMap getProperties();
     139    QVariant getProperty(const QString &);
     140    QVariantMap propertiesMap;
     141Q_SIGNALS:
     142    void propertyChanged(const QString &, const QDBusVariant &value);
     143};
     144
     145class QOfonoDataConnectionManagerInterface : public QDBusAbstractInterface
     146{
     147    Q_OBJECT
     148
     149public:
     150
     151    explicit QOfonoDataConnectionManagerInterface(const QString &dbusPathName, QObject *parent = 0);
     152    ~QOfonoDataConnectionManagerInterface();
     153
     154    QStringList contexts();
     155    bool roamingAllowed();
     156    QVariant getProperty(const QString &);
     157    QString bearer();
     158Q_SIGNALS:
     159    void roamingAllowedChanged(bool);
     160private:
     161    QVariantMap getProperties();
     162    QVariantMap propertiesMap;
     163    QStringList contextList;
     164private slots:
     165    void propertyChanged(const QString &, const QDBusVariant &value);
     166};
     167
     168class QOfonoConnectionContextInterface : public QDBusAbstractInterface
     169{
     170    Q_OBJECT
     171
     172public:
     173
     174    explicit QOfonoConnectionContextInterface(const QString &dbusPathName, QObject *parent = 0);
     175    ~QOfonoConnectionContextInterface();
     176
     177    QVariant getProperty(const QString &);
     178    bool active();
     179    QString accessPointName();
     180    QString name();
     181
     182Q_SIGNALS:
     183private:
     184    QVariantMap getProperties();
     185    QVariantMap propertiesMap;
     186private slots:
     187    void propertyChanged(const QString &, const QDBusVariant &value);
     188};
     189
     190QT_END_NAMESPACE
     191
     192#endif // QT_NO_DBUS
     193#endif // QT_NO_BEARERMANAGEMENT
     194
     195#endif //QOFONOSERVICE_H
  • deleted file qtbase/src/plugins/bearer/connman/qofonoservice_linux.cpp

    + -  
    1 /****************************************************************************
    2 **
    3 ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
    4 ** Contact: http://www.qt-project.org/legal
    5 **
    6 ** This file is part of the plugins of the Qt Toolkit.
    7 **
    8 ** $QT_BEGIN_LICENSE:LGPL$
    9 ** Commercial License Usage
    10 ** Licensees holding valid commercial Qt licenses may use this file in
    11 ** accordance with the commercial license agreement provided with the
    12 ** Software or, alternatively, in accordance with the terms contained in
    13 ** a written agreement between you and Digia.  For licensing terms and
    14 ** conditions see http://qt.digia.com/licensing.  For further information
    15 ** use the contact form at http://qt.digia.com/contact-us.
    16 **
    17 ** GNU Lesser General Public License Usage
    18 ** Alternatively, this file may be used under the terms of the GNU Lesser
    19 ** General Public License version 2.1 as published by the Free Software
    20 ** Foundation and appearing in the file LICENSE.LGPL included in the
    21 ** packaging of this file.  Please review the following information to
    22 ** ensure the GNU Lesser General Public License version 2.1 requirements
    23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    24 **
    25 ** In addition, as a special exception, Digia gives you certain additional
    26 ** rights.  These rights are described in the Digia Qt LGPL Exception
    27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    28 **
    29 ** GNU General Public License Usage
    30 ** Alternatively, this file may be used under the terms of the GNU
    31 ** General Public License version 3.0 as published by the Free Software
    32 ** Foundation and appearing in the file LICENSE.GPL included in the
    33 ** packaging of this file.  Please review the following information to
    34 ** ensure the GNU General Public License version 3.0 requirements will be
    35 ** met: http://www.gnu.org/copyleft/gpl.html.
    36 **
    37 **
    38 ** $QT_END_LICENSE$
    39 **
    40 ****************************************************************************/
    41 
    42 #include <QObject>
    43 #include <QList>
    44 #include <QtDBus/QtDBus>
    45 #include <QtDBus/QDBusConnection>
    46 #include <QtDBus/QDBusError>
    47 #include <QtDBus/QDBusInterface>
    48 #include <QtDBus/QDBusMessage>
    49 #include <QtDBus/QDBusReply>
    50 #include <QtDBus/QDBusPendingCallWatcher>
    51 #include <QtDBus/QDBusObjectPath>
    52 #include <QtDBus/QDBusPendingCall>
    53 
    54 #include "qofonoservice_linux_p.h"
    55 
    56 #ifndef QT_NO_BEARERMANAGEMENT
    57 #ifndef QT_NO_DBUS
    58 
    59 QDBusArgument &operator<<(QDBusArgument &argument, const ObjectPathProperties &item)
    60 {
    61     argument.beginStructure();
    62     argument << item.path << item.properties;
    63     argument.endStructure();
    64     return argument;
    65 }
    66 
    67 const QDBusArgument &operator>>(const QDBusArgument &argument, ObjectPathProperties &item)
    68 {
    69     argument.beginStructure();
    70     argument >> item.path >> item.properties;
    71     argument.endStructure();
    72     return argument;
    73 }
    74 
    75 QT_BEGIN_NAMESPACE
    76 
    77 QOfonoManagerInterface::QOfonoManagerInterface( QObject *parent)
    78         : QDBusAbstractInterface(QStringLiteral(OFONO_SERVICE),
    79                                  QStringLiteral(OFONO_MANAGER_PATH),
    80                                  OFONO_MANAGER_INTERFACE,
    81                                  QDBusConnection::systemBus(), parent)
    82 {
    83     qDBusRegisterMetaType<ObjectPathProperties>();
    84     qDBusRegisterMetaType<PathPropertiesList>();
    85 
    86     QDBusConnection::systemBus().connect(QStringLiteral(OFONO_SERVICE),
    87                            QStringLiteral(OFONO_MANAGER_PATH),
    88                            QStringLiteral(OFONO_MANAGER_INTERFACE),
    89                            QStringLiteral("ModemAdded"),
    90                            this,SLOT(modemAdded(QDBusObjectPath, QVariantMap)));
    91     QDBusConnection::systemBus().connect(QStringLiteral(OFONO_SERVICE),
    92                            QStringLiteral(OFONO_MANAGER_PATH),
    93                            QStringLiteral(OFONO_MANAGER_INTERFACE),
    94                            QStringLiteral("ModemRemoved"),
    95                            this,SLOT(modemRemoved(QDBusObjectPath)));
    96 }
    97 
    98 QOfonoManagerInterface::~QOfonoManagerInterface()
    99 {
    100 }
    101 
    102 QStringList QOfonoManagerInterface::getModems()
    103 {
    104     if (modemList.isEmpty()) {
    105         QList<QVariant> argumentList;
    106         QDBusPendingReply<PathPropertiesList> reply = asyncCallWithArgumentList(QLatin1String("GetModems"), argumentList);
    107         reply.waitForFinished();
    108         if (!reply.isError()) {
    109             foreach (ObjectPathProperties modem, reply.value()) {
    110                 modemList << modem.path.path();
    111             }
    112         } else {
    113             qDebug() << reply.error().message();
    114         }
    115     }
    116 
    117     return modemList;
    118 }
    119 
    120 QString QOfonoManagerInterface::currentModem()
    121 {
    122     QStringList modems = getModems();
    123     foreach (const QString &modem, modems) {
    124         QOfonoModemInterface device(modem);
    125         if (device.isPowered() && device.isOnline())
    126         return modem;
    127     }
    128     return QString();
    129 }
    130 
    131 void QOfonoManagerInterface::modemAdded(const QDBusObjectPath &path, const QVariantMap &/*var*/)
    132 {
    133     if (!modemList.contains(path.path())) {
    134         modemList << path.path();
    135         Q_EMIT modemChanged();
    136     }
    137 }
    138 
    139 void QOfonoManagerInterface::modemRemoved(const QDBusObjectPath &path)
    140 {
    141     if (modemList.contains(path.path())) {
    142         modemList.removeOne(path.path());
    143         Q_EMIT modemChanged();
    144     }
    145 }
    146 
    147 
    148 QOfonoModemInterface::QOfonoModemInterface(const QString &dbusPathName, QObject *parent)
    149     : QDBusAbstractInterface(QStringLiteral(OFONO_SERVICE),
    150                              dbusPathName,
    151                              OFONO_MODEM_INTERFACE,
    152                              QDBusConnection::systemBus(), parent)
    153 {
    154     QDBusConnection::systemBus().connect(QStringLiteral(OFONO_SERVICE),
    155                                          path(),
    156                                          OFONO_MODEM_INTERFACE,
    157                                          QStringLiteral("PropertyChanged"),
    158                                          this,SLOT(propertyChanged(QString,QDBusVariant)));
    159 }
    160 
    161 QOfonoModemInterface::~QOfonoModemInterface()
    162 {
    163 }
    164 
    165 void QOfonoModemInterface::propertyChanged(const QString &name,const QDBusVariant &value)
    166 {
    167     propertiesMap[name] = value.variant();
    168 }
    169 
    170 bool QOfonoModemInterface::isPowered()
    171 {
    172     QVariant var = getProperty(QStringLiteral("Powered"));
    173     return qdbus_cast<bool>(var);
    174 }
    175 
    176 bool QOfonoModemInterface::isOnline()
    177 {
    178     QVariant var = getProperty(QStringLiteral("Online"));
    179     return qdbus_cast<bool>(var);
    180 }
    181 
    182 QVariantMap QOfonoModemInterface::getProperties()
    183 {
    184     if (propertiesMap.isEmpty()) {
    185         QList<QVariant> argumentList;
    186         QDBusPendingReply<QVariantMap> reply = asyncCallWithArgumentList(QLatin1String("GetProperties"), argumentList);
    187         if (!reply.isError()) {
    188             propertiesMap = reply.value();
    189         }
    190     }
    191     return propertiesMap;
    192 }
    193 
    194 QVariant QOfonoModemInterface::getProperty(const QString &property)
    195 {
    196     QVariant var;
    197     QVariantMap map = getProperties();
    198     var = map.value(property);
    199     return var;
    200 }
    201 
    202 
    203 QOfonoNetworkRegistrationInterface::QOfonoNetworkRegistrationInterface(const QString &dbusPathName, QObject *parent)
    204     : QDBusAbstractInterface(QStringLiteral(OFONO_SERVICE),
    205                              dbusPathName,
    206                              OFONO_NETWORK_REGISTRATION_INTERFACE,
    207                              QDBusConnection::systemBus(), parent)
    208 {
    209 }
    210 
    211 QOfonoNetworkRegistrationInterface::~QOfonoNetworkRegistrationInterface()
    212 {
    213 }
    214 
    215 QString QOfonoNetworkRegistrationInterface::getTechnology()
    216 {
    217     QVariant var = getProperty(QStringLiteral("Technology"));
    218     return qdbus_cast<QString>(var);
    219 }
    220 
    221 QVariant QOfonoNetworkRegistrationInterface::getProperty(const QString &property)
    222 {
    223     QVariant var;
    224     QVariantMap map = getProperties();
    225     var = map.value(property);
    226     return var;
    227 }
    228 
    229 QVariantMap QOfonoNetworkRegistrationInterface::getProperties()
    230 {
    231     if (propertiesMap.isEmpty()) {
    232         QList<QVariant> argumentList;
    233         QDBusPendingReply<QVariantMap> reply = asyncCallWithArgumentList(QLatin1String("GetProperties"), argumentList);
    234         reply.waitForFinished();
    235         if (!reply.isError()) {
    236             propertiesMap = reply.value();
    237         } else {
    238             qDebug() << reply.error().message();
    239         }
    240     }
    241     return propertiesMap;
    242 }
    243 
    244 QOfonoDataConnectionManagerInterface::QOfonoDataConnectionManagerInterface(const QString &dbusPathName, QObject *parent)
    245     : QDBusAbstractInterface(QLatin1String(OFONO_SERVICE),
    246                              dbusPathName,
    247                              OFONO_DATA_CONNECTION_MANAGER_INTERFACE,
    248                              QDBusConnection::systemBus(), parent)
    249 {
    250     QDBusConnection::systemBus().connect(QLatin1String(OFONO_SERVICE),
    251                                          path(),
    252                                          QLatin1String(OFONO_MODEM_INTERFACE),
    253                                          QLatin1String("PropertyChanged"),
    254                                          this,SLOT(propertyChanged(QString,QDBusVariant)));
    255 }
    256 
    257 QOfonoDataConnectionManagerInterface::~QOfonoDataConnectionManagerInterface()
    258 {
    259 }
    260 
    261 QStringList QOfonoDataConnectionManagerInterface::contexts()
    262 {
    263     if (contextList.isEmpty()) {
    264         QDBusPendingReply<PathPropertiesList > reply = call(QLatin1String("GetContexts"));
    265         reply.waitForFinished();
    266         if (!reply.isError()) {
    267             foreach (ObjectPathProperties context, reply.value()) {
    268                 contextList << context.path.path();
    269             }
    270         }
    271     }
    272     return contextList;
    273 }
    274 
    275 bool QOfonoDataConnectionManagerInterface::roamingAllowed()
    276 {
    277     QVariant var = getProperty(QStringLiteral("RoamingAllowed"));
    278     return qdbus_cast<bool>(var);
    279 }
    280 
    281 QVariant QOfonoDataConnectionManagerInterface::getProperty(const QString &property)
    282 {
    283     QVariant var;
    284     QVariantMap map = getProperties();
    285     var = map.value(property);
    286     return var;
    287 }
    288 
    289 QVariantMap QOfonoDataConnectionManagerInterface::getProperties()
    290 {
    291     if (propertiesMap.isEmpty()) {
    292         QList<QVariant> argumentList;
    293         QDBusPendingReply<QVariantMap> reply = asyncCallWithArgumentList(QLatin1String("GetProperties"), argumentList);
    294         if (!reply.isError()) {
    295             propertiesMap = reply.value();
    296         }
    297     }
    298     return propertiesMap;
    299 }
    300 
    301 void QOfonoDataConnectionManagerInterface::propertyChanged(const QString &name, const QDBusVariant &value)
    302 {
    303     propertiesMap[name] = value.variant();
    304     if (name == QStringLiteral("RoamingAllowed"))
    305         Q_EMIT roamingAllowedChanged(value.variant().toBool());
    306 }
    307 
    308 QT_END_NAMESPACE
    309 
    310 #endif // QT_NO_DBUS
    311 #endif // QT_NO_BEARERMANAGEMENT
  • deleted file qtbase/src/plugins/bearer/connman/qofonoservice_linux_p.h

    + -  
    1 /****************************************************************************
    2 **
    3 ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
    4 ** Contact: http://www.qt-project.org/legal
    5 **
    6 ** This file is part of the plugins of the Qt Toolkit.
    7 **
    8 ** $QT_BEGIN_LICENSE:LGPL$
    9 ** Commercial License Usage
    10 ** Licensees holding valid commercial Qt licenses may use this file in
    11 ** accordance with the commercial license agreement provided with the
    12 ** Software or, alternatively, in accordance with the terms contained in
    13 ** a written agreement between you and Digia.  For licensing terms and
    14 ** conditions see http://qt.digia.com/licensing.  For further information
    15 ** use the contact form at http://qt.digia.com/contact-us.
    16 **
    17 ** GNU Lesser General Public License Usage
    18 ** Alternatively, this file may be used under the terms of the GNU Lesser
    19 ** General Public License version 2.1 as published by the Free Software
    20 ** Foundation and appearing in the file LICENSE.LGPL included in the
    21 ** packaging of this file.  Please review the following information to
    22 ** ensure the GNU Lesser General Public License version 2.1 requirements
    23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    24 **
    25 ** In addition, as a special exception, Digia gives you certain additional
    26 ** rights.  These rights are described in the Digia Qt LGPL Exception
    27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    28 **
    29 ** GNU General Public License Usage
    30 ** Alternatively, this file may be used under the terms of the GNU
    31 ** General Public License version 3.0 as published by the Free Software
    32 ** Foundation and appearing in the file LICENSE.GPL included in the
    33 ** packaging of this file.  Please review the following information to
    34 ** ensure the GNU General Public License version 3.0 requirements will be
    35 ** met: http://www.gnu.org/copyleft/gpl.html.
    36 **
    37 **
    38 ** $QT_END_LICENSE$
    39 **
    40 ****************************************************************************/
    41 
    42 #ifndef QOFONOSERVICE_H
    43 #define QOFONOSERVICE_H
    44 
    45 //
    46 //  W A R N I N G
    47 //  -------------
    48 //
    49 // This file is not part of the Qt API.  It exists purely as an
    50 // implementation detail.  This header file may change from version to
    51 // version without notice, or even be removed.
    52 //
    53 // We mean it.
    54 //
    55 
    56 #include <QtDBus/QtDBus>
    57 #include <QtDBus/QDBusConnection>
    58 #include <QtDBus/QDBusError>
    59 #include <QtDBus/QDBusInterface>
    60 #include <QtDBus/QDBusMessage>
    61 #include <QtDBus/QDBusReply>
    62 
    63 #include <QtDBus/QDBusPendingCallWatcher>
    64 #include <QtDBus/QDBusObjectPath>
    65 #include <QtDBus/QDBusContext>
    66 #include <QMap>
    67 
    68 #ifndef QT_NO_BEARERMANAGEMENT
    69 #ifndef QT_NO_DBUS
    70 
    71 #define OFONO_SERVICE                            "org.ofono"
    72 #define OFONO_MANAGER_INTERFACE                  "org.ofono.Manager"
    73 #define OFONO_MANAGER_PATH                       "/"
    74 
    75 #define OFONO_MODEM_INTERFACE                    "org.ofono.Modem"
    76 #define OFONO_NETWORK_REGISTRATION_INTERFACE     "org.ofono.NetworkRegistration"
    77 #define OFONO_DATA_CONNECTION_MANAGER_INTERFACE  "org.ofono.ConnectionManager"
    78 
    79 QT_BEGIN_NAMESPACE
    80 
    81 QT_END_NAMESPACE
    82 
    83 struct ObjectPathProperties
    84 {
    85     QDBusObjectPath path;
    86     QVariantMap properties;
    87 };
    88 typedef QList<ObjectPathProperties> PathPropertiesList;
    89 Q_DECLARE_METATYPE(ObjectPathProperties)
    90 Q_DECLARE_METATYPE (PathPropertiesList)
    91 
    92 QT_BEGIN_NAMESPACE
    93 
    94 class QOfonoManagerInterface : public  QDBusAbstractInterface
    95 {
    96     Q_OBJECT
    97 
    98 public:
    99 
    100     QOfonoManagerInterface( QObject *parent = 0);
    101     ~QOfonoManagerInterface();
    102 
    103     QStringList getModems();
    104     QString currentModem();
    105 signals:
    106     void modemChanged();
    107 private:
    108     QStringList modemList;
    109 private slots:
    110     void modemAdded(const QDBusObjectPath &path, const QVariantMap &var);
    111     void modemRemoved(const QDBusObjectPath &path);
    112 };
    113 
    114 class QOfonoModemInterface : public QDBusAbstractInterface
    115 {
    116     Q_OBJECT
    117 
    118 public:
    119 
    120     explicit QOfonoModemInterface(const QString &dbusModemPathName, QObject *parent = 0);
    121     ~QOfonoModemInterface();
    122 
    123     bool isPowered();
    124     bool isOnline();
    125 private:
    126     QVariantMap getProperties();
    127     QVariantMap propertiesMap;
    128     QVariant getProperty(const QString &);
    129     void propertyChanged(const QString &, const QDBusVariant &value);
    130 };
    131 
    132 
    133 class QOfonoNetworkRegistrationInterface : public QDBusAbstractInterface
    134 {
    135     Q_OBJECT
    136 
    137 public:
    138 
    139     explicit QOfonoNetworkRegistrationInterface(const QString &dbusModemPathName, QObject *parent = 0);
    140     ~QOfonoNetworkRegistrationInterface();
    141 
    142     QString getTechnology();
    143 
    144 private:
    145     QVariantMap getProperties();
    146     QVariant getProperty(const QString &);
    147     QVariantMap propertiesMap;
    148 Q_SIGNALS:
    149     void propertyChanged(const QString &, const QDBusVariant &value);
    150 };
    151 
    152 class QOfonoDataConnectionManagerInterface : public QDBusAbstractInterface
    153 {
    154     Q_OBJECT
    155 
    156 public:
    157 
    158     explicit QOfonoDataConnectionManagerInterface(const QString &dbusPathName, QObject *parent = 0);
    159     ~QOfonoDataConnectionManagerInterface();
    160 
    161     QStringList contexts();
    162     bool roamingAllowed();
    163 Q_SIGNALS:
    164     void roamingAllowedChanged(bool);
    165 private:
    166     QVariantMap getProperties();
    167     QVariantMap propertiesMap;
    168     QVariant getProperty(const QString &);
    169     QStringList contextList;
    170 private slots:
    171     void propertyChanged(const QString &, const QDBusVariant &value);
    172 };
    173 
    174 
    175 QT_END_NAMESPACE
    176 
    177 #endif // QT_NO_DBUS
    178 #endif // QT_NO_BEARERMANAGEMENT
    179 
    180 #endif //QOFONOSERVICE_H
  • qtbase/src/plugins/bearer/networkmanager/main.cpp

     
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
     3** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
    44** Contact: http://www.qt-project.org/legal
    55**
    66** This file is part of the plugins of the Qt Toolkit.
    77**
    8 ** $QT_BEGIN_LICENSE:LGPL$
     8** $QT_BEGIN_LICENSE:LGPL21$
    99** Commercial License Usage
    1010** Licensees holding valid commercial Qt licenses may use this file in
    1111** accordance with the commercial license agreement provided with the
    1212** Software or, alternatively, in accordance with the terms contained in
    13 ** a written agreement between you and Digia.  For licensing terms and
    14 ** conditions see http://qt.digia.com/licensing.  For further information
     13** a written agreement between you and Digia. For licensing terms and
     14** conditions see http://qt.digia.com/licensing. For further information
    1515** use the contact form at http://qt.digia.com/contact-us.
    1616**
    1717** GNU Lesser General Public License Usage
    1818** Alternatively, this file may be used under the terms of the GNU Lesser
    19 ** General Public License version 2.1 as published by the Free Software
    20 ** Foundation and appearing in the file LICENSE.LGPL included in the
    21 ** packaging of this file.  Please review the following information to
    22 ** ensure the GNU Lesser General Public License version 2.1 requirements
    23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
     19** General Public License version 2.1 or version 3 as published by the Free
     20** Software Foundation and appearing in the file LICENSE.LGPLv21 and
     21** LICENSE.LGPLv3 included in the packaging of this file. Please review the
     22** following information to ensure the GNU Lesser General Public License
     23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
     24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2425**
    2526** In addition, as a special exception, Digia gives you certain additional
    26 ** rights.  These rights are described in the Digia Qt LGPL Exception
     27** rights. These rights are described in the Digia Qt LGPL Exception
    2728** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2829**
    29 ** GNU General Public License Usage
    30 ** Alternatively, this file may be used under the terms of the GNU
    31 ** General Public License version 3.0 as published by the Free Software
    32 ** Foundation and appearing in the file LICENSE.GPL included in the
    33 ** packaging of this file.  Please review the following information to
    34 ** ensure the GNU General Public License version 3.0 requirements will be
    35 ** met: http://www.gnu.org/copyleft/gpl.html.
    36 **
    37 **
    3830** $QT_END_LICENSE$
    3931**
    4032****************************************************************************/
  • qtbase/src/plugins/bearer/networkmanager/networkmanager.pro

     
    66
    77QT = core network-private dbus
    88
    9 HEADERS += qnmdbushelper.h \
    10            qnetworkmanagerservice.h \
     9HEADERS += qnetworkmanagerservice.h \
    1110           qnetworkmanagerengine.h \
     11           ../linux_common/qofonoservice_linux_p.h \
    1212           ../qnetworksession_impl.h \
    1313           ../qbearerengine_impl.h
    1414
    1515SOURCES += main.cpp \
    16            qnmdbushelper.cpp \
    1716           qnetworkmanagerservice.cpp \
    1817           qnetworkmanagerengine.cpp \
     18           ../linux_common/qofonoservice_linux.cpp \
    1919           ../qnetworksession_impl.cpp
    2020
    2121OTHER_FILES += networkmanager.json
  • qtbase/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp

     
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
     3** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
    44** Contact: http://www.qt-project.org/legal
    55**
    66** This file is part of the plugins of the Qt Toolkit.
    77**
    8 ** $QT_BEGIN_LICENSE:LGPL$
     8** $QT_BEGIN_LICENSE:LGPL21$
    99** Commercial License Usage
    1010** Licensees holding valid commercial Qt licenses may use this file in
    1111** accordance with the commercial license agreement provided with the
    1212** Software or, alternatively, in accordance with the terms contained in
    13 ** a written agreement between you and Digia.  For licensing terms and
    14 ** conditions see http://qt.digia.com/licensing.  For further information
     13** a written agreement between you and Digia. For licensing terms and
     14** conditions see http://qt.digia.com/licensing. For further information
    1515** use the contact form at http://qt.digia.com/contact-us.
    1616**
    1717** GNU Lesser General Public License Usage
    1818** Alternatively, this file may be used under the terms of the GNU Lesser
    19 ** General Public License version 2.1 as published by the Free Software
    20 ** Foundation and appearing in the file LICENSE.LGPL included in the
    21 ** packaging of this file.  Please review the following information to
    22 ** ensure the GNU Lesser General Public License version 2.1 requirements
    23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
     19** General Public License version 2.1 or version 3 as published by the Free
     20** Software Foundation and appearing in the file LICENSE.LGPLv21 and
     21** LICENSE.LGPLv3 included in the packaging of this file. Please review the
     22** following information to ensure the GNU Lesser General Public License
     23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
     24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2425**
    2526** In addition, as a special exception, Digia gives you certain additional
    26 ** rights.  These rights are described in the Digia Qt LGPL Exception
     27** rights. These rights are described in the Digia Qt LGPL Exception
    2728** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2829**
    29 ** GNU General Public License Usage
    30 ** Alternatively, this file may be used under the terms of the GNU
    31 ** General Public License version 3.0 as published by the Free Software
    32 ** Foundation and appearing in the file LICENSE.GPL included in the
    33 ** packaging of this file.  Please review the following information to
    34 ** ensure the GNU General Public License version 3.0 requirements will be
    35 ** met: http://www.gnu.org/copyleft/gpl.html.
    36 **
    37 **
    3830** $QT_END_LICENSE$
    3931**
    4032****************************************************************************/
     
    5547#include <QDBusInterface>
    5648#include <QDBusMessage>
    5749#include <QDBusReply>
     50#include "../linux_common/qofonoservice_linux_p.h"
    5851
    5952#ifndef QT_NO_BEARERMANAGEMENT
    6053#ifndef QT_NO_DBUS
     
    6356
    6457QNetworkManagerEngine::QNetworkManagerEngine(QObject *parent)
    6558:   QBearerEngineImpl(parent),
    66     interface(new QNetworkManagerInterface(this)),
    67     systemSettings(new QNetworkManagerSettings(NM_DBUS_SERVICE_SYSTEM_SETTINGS, this)),
    68     userSettings(new QNetworkManagerSettings(NM_DBUS_SERVICE_USER_SETTINGS, this))
     59    managerInterface(new QNetworkManagerInterface(this)),
     60    systemSettings(new QNetworkManagerSettings(NM_DBUS_SERVICE, this)),
     61    ofonoManager(new QOfonoManagerInterface(this))
    6962{
    70     if (!interface->isValid())
     63
     64    if (!managerInterface->isValid())
    7165        return;
    7266
    73     interface->setConnections();
    74     connect(interface, SIGNAL(deviceAdded(QDBusObjectPath)),
     67    qDBusRegisterMetaType<QNmSettingsMap>();
     68
     69    connect(managerInterface, SIGNAL(deviceAdded(QDBusObjectPath)),
    7570            this, SLOT(deviceAdded(QDBusObjectPath)));
    76     connect(interface, SIGNAL(deviceRemoved(QDBusObjectPath)),
     71    connect(managerInterface, SIGNAL(deviceRemoved(QDBusObjectPath)),
    7772            this, SLOT(deviceRemoved(QDBusObjectPath)));
    78 #if 0
    79     connect(interface, SIGNAL(stateChanged(QString,quint32)),
    80             this, SIGNAL(configurationsChanged()));
    81 #endif
    82     connect(interface, SIGNAL(activationFinished(QDBusPendingCallWatcher*)),
     73    connect(managerInterface, SIGNAL(activationFinished(QDBusPendingCallWatcher*)),
    8374            this, SLOT(activationFinished(QDBusPendingCallWatcher*)));
    84     connect(interface, SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>)),
    85             this, SLOT(interfacePropertiesChanged(QString,QMap<QString,QVariant>)));
    86 
    87     qDBusRegisterMetaType<QNmSettingsMap>();
     75    connect(managerInterface, SIGNAL(propertiesChanged(QMap<QString,QVariant>)),
     76            this, SLOT(interfacePropertiesChanged(QMap<QString,QVariant>)));
     77    managerInterface->setConnections();
    8878
    89     systemSettings->setConnections();
    9079    connect(systemSettings, SIGNAL(newConnection(QDBusObjectPath)),
    9180            this, SLOT(newConnection(QDBusObjectPath)));
    92 
    93     userSettings->setConnections();
    94     connect(userSettings, SIGNAL(newConnection(QDBusObjectPath)),
    95             this, SLOT(newConnection(QDBusObjectPath)));
     81    systemSettings->setConnections();
    9682}
    9783
    9884QNetworkManagerEngine::~QNetworkManagerEngine()
    9985{
    10086    qDeleteAll(connections);
     87    connections.clear();
    10188    qDeleteAll(accessPoints);
     89    accessPoints.clear();
    10290    qDeleteAll(wirelessDevices);
    103     qDeleteAll(activeConnections);
     91    wirelessDevices.clear();
     92    qDeleteAll(activeConnectionsList);
     93    activeConnectionsList.clear();
     94    qDeleteAll(interfaceDevices);
     95    interfaceDevices.clear();
     96
     97    connectionInterfaces.clear();
     98
     99    qDeleteAll(ofonoContextManagers);
     100    ofonoContextManagers.clear();
     101
     102    qDeleteAll(wiredDevices);
     103    wiredDevices.clear();
    104104}
    105105
    106106void QNetworkManagerEngine::initialize()
    107107{
    108108    QMutexLocker locker(&mutex);
    109109
    110     // Get current list of access points.
    111     foreach (const QDBusObjectPath &devicePath, interface->getDevices()) {
     110    if (ofonoManager->isValid()) {
     111        Q_FOREACH (const QString &modem, ofonoManager->getModems()) {
     112            QOfonoDataConnectionManagerInterface *ofonoContextManager
     113                    = new QOfonoDataConnectionManagerInterface(modem,this);
     114            ofonoContextManagers.insert(modem, ofonoContextManager);
     115        }
     116    }
     117    // Get active connections.
     118    foreach (const QDBusObjectPath &acPath, managerInterface->activeConnections()) {
     119
     120        QNetworkManagerConnectionActive *activeConnection =
     121                new QNetworkManagerConnectionActive(acPath.path(),this);
     122        activeConnectionsList.insert(acPath.path(), activeConnection);
     123        connect(activeConnection, SIGNAL(propertiesChanged(QMap<QString,QVariant>)),
     124                this, SLOT(activeConnectionPropertiesChanged(QMap<QString,QVariant>)));
     125        activeConnection->setConnections();
     126
     127        QStringList devices = activeConnection->devices();
     128        if (!devices.isEmpty()) {
     129            QNetworkManagerInterfaceDevice device(devices.at(0),this);
     130            connectionInterfaces.insert(activeConnection->connection().path(),device.networkInterface());
     131        }
     132    }
     133
     134        // Get current list of access points.
     135    foreach (const QDBusObjectPath &devicePath, managerInterface->getDevices()) {
    112136        locker.unlock();
    113         deviceAdded(devicePath);
     137        deviceAdded(devicePath); //add all accesspoints
    114138        locker.relock();
    115139    }
    116140
    117141    // Get connections.
    118142    foreach (const QDBusObjectPath &settingsPath, systemSettings->listConnections()) {
    119143        locker.unlock();
    120         newConnection(settingsPath, systemSettings);
    121         locker.relock();
    122     }
    123     foreach (const QDBusObjectPath &settingsPath, userSettings->listConnections()) {
    124         locker.unlock();
    125         newConnection(settingsPath, userSettings);
     144        if (!hasIdentifier(settingsPath.path()))
     145            newConnection(settingsPath, systemSettings); //add system connection configs
    126146        locker.relock();
    127147    }
    128148
    129     // Get active connections.
    130     foreach (const QDBusObjectPath &acPath, interface->activeConnections()) {
    131         QNetworkManagerConnectionActive *activeConnection =
    132             new QNetworkManagerConnectionActive(acPath.path());
    133         activeConnections.insert(acPath.path(), activeConnection);
    134 
    135         activeConnection->setConnections();
    136         connect(activeConnection, SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>)),
    137                 this, SLOT(activeConnectionPropertiesChanged(QString,QMap<QString,QVariant>)));
    138     }
     149    Q_EMIT updateCompleted();
    139150}
    140151
    141152bool QNetworkManagerEngine::networkManagerAvailable() const
    142153{
    143     QMutexLocker locker(&mutex);
    144 
    145     return interface->isValid();
     154    return managerInterface->isValid();
    146155}
    147156
    148 QString QNetworkManagerEngine::getInterfaceFromId(const QString &id)
     157QString QNetworkManagerEngine::getInterfaceFromId(const QString &settingsPath)
    149158{
    150     QMutexLocker locker(&mutex);
    151 
    152     foreach (const QDBusObjectPath &acPath, interface->activeConnections()) {
    153         QNetworkManagerConnectionActive activeConnection(acPath.path());
    154 
    155         const QString identifier = QString::number(qHash(activeConnection.serviceName() + ' ' +
    156                                                          activeConnection.connection().path()));
    157 
    158         if (id == identifier) {
    159             QList<QDBusObjectPath> devices = activeConnection.devices();
    160 
    161             if (devices.isEmpty())
    162                 continue;
    163 
    164             QNetworkManagerInterfaceDevice device(devices.at(0).path());
    165             return device.networkInterface();
    166         }
    167     }
    168 
    169     return QString();
     159    return connectionInterfaces.value(settingsPath);
    170160}
    171161
    172162bool QNetworkManagerEngine::hasIdentifier(const QString &id)
    173163{
    174164    QMutexLocker locker(&mutex);
    175 
    176     if (connectionFromId(id))
    177         return true;
    178 
    179     for (int i = 0; i < accessPoints.count(); ++i) {
    180         QNetworkManagerInterfaceAccessPoint *accessPoint = accessPoints.at(i);
    181 
    182         const QString identifier =
    183             QString::number(qHash(accessPoint->connectionInterface()->path()));
    184 
    185         if (id == identifier)
    186             return true;
    187     }
    188 
    189     return false;
     165    return accessPointConfigurations.contains(id);
    190166}
    191167
    192168void QNetworkManagerEngine::connectToId(const QString &id)
     
    198174    if (!connection)
    199175        return;
    200176
    201     QNmSettingsMap map = connection->getSettings();
    202     const QString connectionType = map.value("connection").value("type").toString();
     177    NMDeviceType connectionType = connection->getType();
    203178
    204179    QString dbusDevicePath;
    205     foreach (const QDBusObjectPath &devicePath, interface->getDevices()) {
    206         QNetworkManagerInterfaceDevice device(devicePath.path());
    207         if (device.deviceType() == DEVICE_TYPE_802_3_ETHERNET &&
    208             connectionType == QLatin1String("802-3-ethernet")) {
    209             dbusDevicePath = devicePath.path();
     180    const QString settingsPath = connection->connectionInterface()->path();
     181    QString specificPath = configuredAccessPoints.key(settingsPath);
     182
     183    QHashIterator<QString, QNetworkManagerInterfaceDevice*> i(interfaceDevices);
     184    while (i.hasNext()) {
     185        i.next();
     186        if (i.value()->deviceType() == DEVICE_TYPE_ETHERNET &&
     187            connectionType == DEVICE_TYPE_ETHERNET) {
     188            dbusDevicePath = i.key();
    210189            break;
    211         } else if (device.deviceType() == DEVICE_TYPE_802_11_WIRELESS &&
    212                    connectionType == QLatin1String("802-11-wireless")) {
    213             dbusDevicePath = devicePath.path();
     190        } else if (i.value()->deviceType() == DEVICE_TYPE_WIFI &&
     191                   connectionType == DEVICE_TYPE_WIFI) {
     192            dbusDevicePath = i.key();
    214193            break;
    215         }
    216         else if (device.deviceType() == DEVICE_TYPE_GSM &&
    217                 connectionType == QLatin1String("gsm")) {
    218             dbusDevicePath = devicePath.path();
     194        } else if (i.value()->deviceType() == DEVICE_TYPE_MODEM &&
     195                connectionType == DEVICE_TYPE_MODEM) {
     196            dbusDevicePath = i.key();
    219197            break;
    220198        }
    221199    }
    222200
    223     const QString service = connection->connectionInterface()->service();
    224     const QString settingsPath = connection->connectionInterface()->path();
     201    if (specificPath.isEmpty())
     202        specificPath = "/";
    225203
    226     interface->activateConnection(service, QDBusObjectPath(settingsPath),
    227                                   QDBusObjectPath(dbusDevicePath), QDBusObjectPath("/"));
     204    managerInterface->activateConnection(QDBusObjectPath(settingsPath),
     205                                  QDBusObjectPath(dbusDevicePath), QDBusObjectPath(specificPath));
    228206}
    229207
    230208void QNetworkManagerEngine::disconnectFromId(const QString &id)
    231209{
    232210    QMutexLocker locker(&mutex);
    233211
    234     foreach (const QDBusObjectPath &acPath, interface->activeConnections()) {
    235         QNetworkManagerConnectionActive activeConnection(acPath.path());
    236 
    237         const QString identifier = QString::number(qHash(activeConnection.serviceName() + ' ' +
    238                                                          activeConnection.connection().path()));
     212    QNetworkManagerSettingsConnection *connection = connectionFromId(id);
     213    QNmSettingsMap map = connection->getSettings();
     214    bool connectionAutoconnect = map.value("connection").value("autoconnect",true).toBool(); //if not present is true !!
     215    if (connectionAutoconnect) { //autoconnect connections will simply be reconnected by nm
     216        emit connectionError(id, QBearerEngineImpl::OperationNotSupported);
     217        return;
     218    }
    239219
    240         if (id == identifier && accessPointConfigurations.contains(id)) {
    241             interface->deactivateConnection(acPath);
     220    QHashIterator<QString, QNetworkManagerConnectionActive*> i(activeConnectionsList);
     221    while (i.hasNext()) {
     222        i.next();
     223        if (id == i.value()->connection().path() && accessPointConfigurations.contains(id)) {
     224            managerInterface->deactivateConnection(QDBusObjectPath(i.key()));
    242225            break;
    243226        }
    244227    }
     
    246229
    247230void QNetworkManagerEngine::requestUpdate()
    248231{
     232    if (managerInterface->wirelessEnabled()) {
     233        QHashIterator<QString, QNetworkManagerInterfaceDeviceWireless *> i(wirelessDevices);
     234        while (i.hasNext()) {
     235            i.next();
     236            i.value()->requestScan();
     237        }
     238    }
    249239    QMetaObject::invokeMethod(this, "updateCompleted", Qt::QueuedConnection);
    250240}
    251241
    252 void QNetworkManagerEngine::interfacePropertiesChanged(const QString &path,
    253                                                        const QMap<QString, QVariant> &properties)
     242void QNetworkManagerEngine::scanFinished()
    254243{
    255     QMutexLocker locker(&mutex);
    256 
    257     Q_UNUSED(path)
     244    QMetaObject::invokeMethod(this, "updateCompleted", Qt::QueuedConnection);
     245}
    258246
     247void QNetworkManagerEngine::interfacePropertiesChanged(const QMap<QString, QVariant> &properties)
     248{
     249    QMutexLocker locker(&mutex);
    259250    QMapIterator<QString, QVariant> i(properties);
    260251    while (i.hasNext()) {
    261252        i.next();
     
    267258                qdbus_cast<QList<QDBusObjectPath> >(i.value().value<QDBusArgument>());
    268259
    269260            QStringList identifiers = accessPointConfigurations.keys();
    270             foreach (const QString &id, identifiers)
    271                 QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id);
    272 
    273             QStringList priorActiveConnections = this->activeConnections.keys();
     261            QStringList priorActiveConnections = activeConnectionsList.keys();
    274262
    275263            foreach (const QDBusObjectPath &acPath, activeConnections) {
    276264                priorActiveConnections.removeOne(acPath.path());
    277265                QNetworkManagerConnectionActive *activeConnection =
    278                     this->activeConnections.value(acPath.path());
     266                    activeConnectionsList.value(acPath.path());
     267
    279268                if (!activeConnection) {
    280                     activeConnection = new QNetworkManagerConnectionActive(acPath.path());
    281                     this->activeConnections.insert(acPath.path(), activeConnection);
     269                    activeConnection = new QNetworkManagerConnectionActive(acPath.path(),this);
     270                    activeConnectionsList.insert(acPath.path(), activeConnection);
    282271
     272                    connect(activeConnection, SIGNAL(propertiesChanged(QMap<QString,QVariant>)),
     273                            this, SLOT(activeConnectionPropertiesChanged(QMap<QString,QVariant>)));
    283274                    activeConnection->setConnections();
    284                     connect(activeConnection, SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>)),
    285                             this, SLOT(activeConnectionPropertiesChanged(QString,QMap<QString,QVariant>)));
    286275                }
    287276
    288                 const QString id = QString::number(qHash(activeConnection->serviceName() + ' ' +
    289                                                          activeConnection->connection().path()));
     277                const QString id = activeConnection->connection().path();
    290278
    291279                identifiers.removeOne(id);
    292280
    293281                QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id);
    294282                if (ptr) {
    295283                    ptr->mutex.lock();
    296                     if (activeConnection->state() == 2 &&
     284                    if (activeConnection->state() == NM_ACTIVE_CONNECTION_STATE_ACTIVATED &&
    297285                        ptr->state != QNetworkConfiguration::Active) {
    298286                        ptr->state = QNetworkConfiguration::Active;
     287
     288                        if (activeConnectionsList.value(id) && activeConnectionsList.value(id)->defaultRoute()
     289                                && managerInterface->state() < QNetworkManagerInterface::NM_STATE_CONNECTED_GLOBAL) {
     290                            ptr->purpose = QNetworkConfiguration::PrivatePurpose;
     291                        }
    299292                        ptr->mutex.unlock();
    300293
    301294                        locker.unlock();
     
    308301            }
    309302
    310303            while (!priorActiveConnections.isEmpty())
    311                 delete this->activeConnections.take(priorActiveConnections.takeFirst());
     304                delete activeConnectionsList.take(priorActiveConnections.takeFirst());
    312305
    313306            while (!identifiers.isEmpty()) {
    314                 // These configurations are not active
    315307                QNetworkConfigurationPrivatePointer ptr =
    316308                    accessPointConfigurations.value(identifiers.takeFirst());
    317309
    318310                ptr->mutex.lock();
    319311                if ((ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) {
    320                     ptr->state = QNetworkConfiguration::Discovered;
     312                    QNetworkConfiguration::StateFlags flag = QNetworkConfiguration::Defined;
     313                    ptr->state = (flag | QNetworkConfiguration::Discovered);
    321314                    ptr->mutex.unlock();
    322315
    323316                    locker.unlock();
     
    331324    }
    332325}
    333326
    334 void QNetworkManagerEngine::activeConnectionPropertiesChanged(const QString &path,
    335                                                               const QMap<QString, QVariant> &properties)
     327void QNetworkManagerEngine::activeConnectionPropertiesChanged(const QMap<QString, QVariant> &properties)
    336328{
    337329    QMutexLocker locker(&mutex);
    338330
    339331    Q_UNUSED(properties)
    340332
    341     QNetworkManagerConnectionActive *activeConnection = activeConnections.value(path);
     333    QNetworkManagerConnectionActive *activeConnection = qobject_cast<QNetworkManagerConnectionActive *>(sender());
    342334
    343335    if (!activeConnection)
    344336        return;
    345337
    346     const QString id = QString::number(qHash(activeConnection->serviceName() + ' ' +
    347                                              activeConnection->connection().path()));
     338    const QString id = activeConnection->connection().path();
    348339
    349340    QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id);
    350341    if (ptr) {
    351342        ptr->mutex.lock();
    352         if (activeConnection->state() == 2 &&
    353             ptr->state != QNetworkConfiguration::Active) {
    354             ptr->state = QNetworkConfiguration::Active;
     343        if (properties.value("State").toUInt() == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) {
     344            QStringList devices = activeConnection->devices();
     345            if (!devices.isEmpty()) {
     346                QNetworkManagerInterfaceDevice device(devices.at(0),this);
     347                connectionInterfaces.insert(id,device.networkInterface());
     348            }
     349
     350            ptr->state |= QNetworkConfiguration::Active;
    355351            ptr->mutex.unlock();
    356352
    357353            locker.unlock();
    358354            emit configurationChanged(ptr);
    359355            locker.relock();
    360356        } else {
     357            connectionInterfaces.remove(id);
    361358            ptr->mutex.unlock();
    362359        }
    363360    }
    364361}
    365362
    366 void QNetworkManagerEngine::devicePropertiesChanged(const QString &path,
    367                                                     const QMap<QString, QVariant> &properties)
     363void QNetworkManagerEngine::deviceConnectionsChanged(const QStringList &connectionsList)
    368364{
    369     Q_UNUSED(path);
    370     Q_UNUSED(properties);
     365    QMutexLocker locker(&mutex);
     366    for (int i = 0; i < connections.count(); ++i) {
     367        if (connectionsList.contains(connections.at(i)->connectionInterface()->path()))
     368            continue;
     369
     370        const QString settingsPath = connections.at(i)->connectionInterface()->path();
     371
     372        QNetworkConfigurationPrivatePointer ptr =
     373            accessPointConfigurations.value(settingsPath);
     374        ptr->mutex.lock();
     375        QNetworkConfiguration::StateFlags flag = QNetworkConfiguration::Defined;
     376        ptr->state = (flag | QNetworkConfiguration::Discovered);
     377        ptr->mutex.unlock();
     378
     379        locker.unlock();
     380        emit configurationChanged(ptr);
     381        locker.relock();
     382        Q_EMIT updateCompleted();
     383    }
    371384}
    372385
    373386void QNetworkManagerEngine::deviceAdded(const QDBusObjectPath &path)
    374387{
    375     QNetworkManagerInterfaceDevice device(path.path());
    376     if (device.deviceType() == DEVICE_TYPE_802_11_WIRELESS) {
     388    QNetworkManagerInterfaceDevice *iDevice;
     389    iDevice = new QNetworkManagerInterfaceDevice(path.path(),this);
     390    connect(iDevice,SIGNAL(connectionsChanged(QStringList)),
     391            this,SLOT(deviceConnectionsChanged(QStringList)));
     392
     393    iDevice->setConnections();
     394    interfaceDevices.insert(path.path(),iDevice);
     395    if (iDevice->deviceType() == DEVICE_TYPE_WIFI) {
    377396        QNetworkManagerInterfaceDeviceWireless *wirelessDevice =
    378             new QNetworkManagerInterfaceDeviceWireless(device.connectionInterface()->path());
     397            new QNetworkManagerInterfaceDeviceWireless(iDevice->connectionInterface()->path(),this);
    379398
     399        connect(wirelessDevice, SIGNAL(accessPointAdded(QString)),
     400                this, SLOT(newAccessPoint(QString)));
     401        connect(wirelessDevice, SIGNAL(accessPointRemoved(QString)),
     402                this, SLOT(removeAccessPoint(QString)));
     403        connect(wirelessDevice,SIGNAL(scanDone()),this,SLOT(scanFinished()));
    380404        wirelessDevice->setConnections();
    381         connect(wirelessDevice, SIGNAL(accessPointAdded(QString,QDBusObjectPath)),
    382                 this, SLOT(newAccessPoint(QString,QDBusObjectPath)));
    383         connect(wirelessDevice, SIGNAL(accessPointRemoved(QString,QDBusObjectPath)),
    384                 this, SLOT(removeAccessPoint(QString,QDBusObjectPath)));
    385         connect(wirelessDevice, SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>)),
    386                 this, SLOT(devicePropertiesChanged(QString,QMap<QString,QVariant>)));
    387405
    388406        foreach (const QDBusObjectPath &apPath, wirelessDevice->getAccessPoints())
    389             newAccessPoint(QString(), apPath);
     407            newAccessPoint(apPath.path());
    390408
    391         mutex.lock();
    392409        wirelessDevices.insert(path.path(), wirelessDevice);
    393         mutex.unlock();
     410    }
     411
     412    if (iDevice->deviceType() == DEVICE_TYPE_ETHERNET) {
     413        QNetworkManagerInterfaceDeviceWired *wiredDevice =
     414                new QNetworkManagerInterfaceDeviceWired(iDevice->connectionInterface()->path(),this);
     415        connect(wiredDevice,SIGNAL(carrierChanged(bool)),this,SLOT(wiredCarrierChanged(bool)));
     416        wiredDevices.insert(iDevice->connectionInterface()->path(), wiredDevice);
    394417    }
    395418}
    396419
     
    398421{
    399422    QMutexLocker locker(&mutex);
    400423
    401     delete wirelessDevices.take(path.path());
     424    if (interfaceDevices.contains(path.path())) {
     425        locker.unlock();
     426        delete interfaceDevices.take(path.path());
     427        locker.relock();
     428    }
     429    if (wirelessDevices.contains(path.path())) {
     430        locker.unlock();
     431        delete wirelessDevices.take(path.path());
     432        locker.relock();
     433    }
     434    if (wiredDevices.contains(path.path())) {
     435        locker.unlock();
     436        delete wiredDevices.take(path.path());
     437        locker.relock();
     438    }
     439}
     440
     441void QNetworkManagerEngine::wiredCarrierChanged(bool carrier)
     442{
     443    QNetworkManagerInterfaceDeviceWired *deviceWired = qobject_cast<QNetworkManagerInterfaceDeviceWired *>(sender());
     444    if (!deviceWired)
     445        return;
     446    QMutexLocker locker(&mutex);
     447    foreach (const QDBusObjectPath &settingsPath, systemSettings->listConnections()) {
     448        for (int i = 0; i < connections.count(); ++i) {
     449            QNetworkManagerSettingsConnection *connection = connections.at(i);
     450            if (connection->getType() == DEVICE_TYPE_ETHERNET
     451                    && settingsPath.path() == connection->connectionInterface()->path()) {
     452                QNetworkConfigurationPrivatePointer ptr =
     453                        accessPointConfigurations.value(settingsPath.path());
     454
     455                if (ptr) {
     456                    ptr->mutex.lock();
     457                    if (carrier)
     458                        ptr->state |= QNetworkConfiguration::Discovered;
     459                    else
     460                        ptr->state = QNetworkConfiguration::Defined;
     461                    ptr->mutex.unlock();
     462                    locker.unlock();
     463                    emit configurationChanged(ptr);
     464                    return;
     465                }
     466            }
     467        }
     468    }
    402469}
    403470
    404471void QNetworkManagerEngine::newConnection(const QDBusObjectPath &path,
    405472                                          QNetworkManagerSettings *settings)
    406473{
    407474    QMutexLocker locker(&mutex);
    408 
    409475    if (!settings)
    410476        settings = qobject_cast<QNetworkManagerSettings *>(sender());
    411477
    412     if (!settings)
     478    if (!settings) {
    413479        return;
     480    }
    414481
    415482    QNetworkManagerSettingsConnection *connection =
    416483        new QNetworkManagerSettingsConnection(settings->connectionInterface()->service(),
    417                                               path.path());
     484                                              path.path(),this);
     485    const QString settingsPath = connection->connectionInterface()->path();
     486    if (accessPointConfigurations.contains(settingsPath)) {
     487        return;
     488    }
     489
    418490    connections.append(connection);
    419491
    420     connect(connection, SIGNAL(removed(QString)), this, SLOT(removeConnection(QString)));
    421     connect(connection, SIGNAL(updated(QNmSettingsMap)),
    422             this, SLOT(updateConnection(QNmSettingsMap)));
     492    connect(connection,SIGNAL(removed(QString)),this,SLOT(removeConnection(QString)));
     493    connect(connection,SIGNAL(updated()),this,SLOT(updateConnection()));
     494    connection->setConnections();
    423495
    424     const QString service = connection->connectionInterface()->service();
    425     const QString settingsPath = connection->connectionInterface()->path();
     496    NMDeviceType deviceType = connection->getType();
     497
     498    if (deviceType == DEVICE_TYPE_WIFI) {
     499        QString apPath;
     500        for (int i = 0; i < accessPoints.count(); ++i) {
     501            if (connection->getSsid() == accessPoints.at(i)->ssid()) {
     502                // remove the corresponding accesspoint from configurations
     503                apPath = accessPoints.at(i)->connectionInterface()->path();
     504                QNetworkConfigurationPrivatePointer ptr
     505                        = accessPointConfigurations.take(apPath);
     506                if (ptr) {
     507                    locker.unlock();
     508                    emit configurationRemoved(ptr);
     509                    locker.relock();
     510                }
     511            }
     512        }
     513        if (!configuredAccessPoints.contains(settingsPath))
     514            configuredAccessPoints.insert(apPath,settingsPath);
     515    }
    426516
    427517    QNetworkConfigurationPrivate *cpPriv =
    428         parseConnection(service, settingsPath, connection->getSettings());
     518        parseConnection(settingsPath, connection->getSettings());
    429519
    430520    // Check if connection is active.
    431     foreach (const QDBusObjectPath &acPath, interface->activeConnections()) {
    432         QNetworkManagerConnectionActive activeConnection(acPath.path());
    433 
    434         if (activeConnection.serviceName() == service &&
    435             activeConnection.connection().path() == settingsPath &&
    436             activeConnection.state() == 2) {
     521    QHashIterator<QString, QNetworkManagerConnectionActive*> i(activeConnectionsList);
     522    while (i.hasNext()) {
     523        i.next();
     524        if (i.value()->connection().path() == settingsPath) {
    437525            cpPriv->state |= QNetworkConfiguration::Active;
    438526            break;
    439527        }
    440528    }
    441 
     529    if (deviceType == DEVICE_TYPE_ETHERNET) {
     530        QHashIterator<QString, QNetworkManagerInterfaceDevice*> i(interfaceDevices);
     531        while (i.hasNext()) {
     532             i.next();
     533             if (i.value()->deviceType() == deviceType) {
     534                QNetworkManagerInterfaceDeviceWired *wiredDevice
     535                        = wiredDevices.value(i.value()->connectionInterface()->path());
     536                 if (wiredDevice->carrier()) {
     537                     cpPriv->state |= QNetworkConfiguration::Discovered;
     538                 }
     539             }
     540         }
     541     }
    442542    QNetworkConfigurationPrivatePointer ptr(cpPriv);
    443543    accessPointConfigurations.insert(ptr->id, ptr);
    444 
    445544    locker.unlock();
    446545    emit configurationAdded(ptr);
    447546}
     
    450549{
    451550    QMutexLocker locker(&mutex);
    452551
    453     Q_UNUSED(path)
    454 
    455552    QNetworkManagerSettingsConnection *connection =
    456553        qobject_cast<QNetworkManagerSettingsConnection *>(sender());
     554
    457555    if (!connection)
    458556        return;
    459557
     558    connection->deleteLater();
    460559    connections.removeAll(connection);
    461560
    462     const QString id = QString::number(qHash(connection->connectionInterface()->service() + ' ' +
    463                                              connection->connectionInterface()->path()));
     561    const QString id = path;
    464562
    465563    QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(id);
    466564
    467     connection->deleteLater();
    468 
    469     locker.unlock();
    470     emit configurationRemoved(ptr);
     565    if (ptr) {
     566        locker.unlock();
     567        emit configurationRemoved(ptr);
     568        locker.relock();
     569    }
     570    // add base AP back into configurations
     571    QMapIterator<QString, QString> i(configuredAccessPoints);
     572    while (i.hasNext()) {
     573        i.next();
     574        if (i.value() == path) {
     575            configuredAccessPoints.remove(i.key());
     576            newAccessPoint(i.key());
     577        }
     578    }
    471579}
    472580
    473 void QNetworkManagerEngine::updateConnection(const QNmSettingsMap &settings)
     581void QNetworkManagerEngine::updateConnection()
    474582{
    475583    QMutexLocker locker(&mutex);
    476584
     
    478586        qobject_cast<QNetworkManagerSettingsConnection *>(sender());
    479587    if (!connection)
    480588        return;
    481 
    482     const QString service = connection->connectionInterface()->service();
    483589    const QString settingsPath = connection->connectionInterface()->path();
    484590
    485     QNetworkConfigurationPrivate *cpPriv = parseConnection(service, settingsPath, settings);
     591    QNetworkConfigurationPrivate *cpPriv = parseConnection(settingsPath, connection->getSettings());
    486592
    487593    // Check if connection is active.
    488     foreach (const QDBusObjectPath &acPath, interface->activeConnections()) {
     594    foreach (const QDBusObjectPath &acPath, managerInterface->activeConnections()) {
    489595        QNetworkManagerConnectionActive activeConnection(acPath.path());
    490596
    491         if (activeConnection.serviceName() == service &&
    492             activeConnection.connection().path() == settingsPath &&
     597        if (activeConnection.connection().path() == settingsPath &&
    493598            activeConnection.state() == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) {
    494599            cpPriv->state |= QNetworkConfiguration::Active;
    495600            break;
     
    509614
    510615    locker.unlock();
    511616    emit configurationChanged(ptr);
     617    locker.relock();
    512618    delete cpPriv;
    513619}
    514620
    515621void QNetworkManagerEngine::activationFinished(QDBusPendingCallWatcher *watcher)
    516622{
    517623    QMutexLocker locker(&mutex);
    518 
    519624    QDBusPendingReply<QDBusObjectPath> reply(*watcher);
     625    watcher->deleteLater();
     626
    520627    if (!reply.isError()) {
    521628        QDBusObjectPath result = reply.value();
    522629
    523630        QNetworkManagerConnectionActive activeConnection(result.path());
    524631
    525         const QString id = QString::number(qHash(activeConnection.serviceName() + ' ' +
    526                                                  activeConnection.connection().path()));
     632        const QString id = activeConnection.connection().path();
    527633
    528634        QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id);
    529635        if (ptr) {
    530636            ptr->mutex.lock();
    531             if (activeConnection.state() == 2 &&
     637            if (activeConnection.state() == NM_ACTIVE_CONNECTION_STATE_ACTIVATED &&
    532638                ptr->state != QNetworkConfiguration::Active) {
    533                 ptr->state = QNetworkConfiguration::Active;
     639                ptr->state |= QNetworkConfiguration::Active;
    534640                ptr->mutex.unlock();
    535641
    536642                locker.unlock();
     
    543649    }
    544650}
    545651
    546 void QNetworkManagerEngine::newAccessPoint(const QString &path, const QDBusObjectPath &objectPath)
     652void QNetworkManagerEngine::newAccessPoint(const QString &path)
    547653{
    548654    QMutexLocker locker(&mutex);
    549655
    550     Q_UNUSED(path)
    551 
    552656    QNetworkManagerInterfaceAccessPoint *accessPoint =
    553         new QNetworkManagerInterfaceAccessPoint(objectPath.path());
    554     accessPoints.append(accessPoint);
     657        new QNetworkManagerInterfaceAccessPoint(path,this);
    555658
    556     accessPoint->setConnections();
    557     connect(accessPoint, SIGNAL(propertiesChanged(QMap<QString,QVariant>)),
    558             this, SLOT(updateAccessPoint(QMap<QString,QVariant>)));
    559 
    560     // Check if configuration for this SSID already exists.
     659    bool okToAdd = true;
    561660    for (int i = 0; i < accessPoints.count(); ++i) {
    562         if (accessPoint != accessPoints.at(i) &&
    563             accessPoint->ssid() == accessPoints.at(i)->ssid()) {
    564             return;
     661        if (accessPoints.at(i)->connectionInterface()->path() == path) {
     662            okToAdd = false;
    565663        }
    566664    }
    567 
     665    if (okToAdd) {
     666        accessPoints.append(accessPoint);
     667        accessPoint->setConnections();
     668    }
    568669    // Check if configuration exists for connection.
    569670    if (!accessPoint->ssid().isEmpty()) {
     671
    570672        for (int i = 0; i < connections.count(); ++i) {
    571673            QNetworkManagerSettingsConnection *connection = connections.at(i);
     674            const QString settingsPath = connection->connectionInterface()->path();
    572675
    573676            if (accessPoint->ssid() == connection->getSsid()) {
    574                 const QString service = connection->connectionInterface()->service();
    575                 const QString settingsPath = connection->connectionInterface()->path();
    576                 const QString connectionId = QString::number(qHash(service + ' ' + settingsPath));
     677                if (!configuredAccessPoints.contains(path)) {
     678                    configuredAccessPoints.insert(path,settingsPath);
     679                }
    577680
    578681                QNetworkConfigurationPrivatePointer ptr =
    579                     accessPointConfigurations.value(connectionId);
     682                    accessPointConfigurations.value(settingsPath);
    580683                ptr->mutex.lock();
    581                 ptr->state = QNetworkConfiguration::Discovered;
     684                QNetworkConfiguration::StateFlags flag = QNetworkConfiguration::Defined;
     685                ptr->state = (flag | QNetworkConfiguration::Discovered);
    582686                ptr->mutex.unlock();
    583687
    584688                locker.unlock();
     
    593697
    594698    ptr->name = accessPoint->ssid();
    595699    ptr->isValid = true;
    596     ptr->id = QString::number(qHash(objectPath.path()));
     700    ptr->id = path;
    597701    ptr->type = QNetworkConfiguration::InternetAccessPoint;
    598     if(accessPoint->flags() == NM_802_11_AP_FLAGS_PRIVACY) {
    599         ptr->purpose = QNetworkConfiguration::PrivatePurpose;
    600     } else {
    601         ptr->purpose = QNetworkConfiguration::PublicPurpose;
    602     }
     702    ptr->purpose = QNetworkConfiguration::PublicPurpose;
    603703    ptr->state = QNetworkConfiguration::Undefined;
    604704    ptr->bearerType = QNetworkConfiguration::BearerWLAN;
    605705
     
    609709    emit configurationAdded(ptr);
    610710}
    611711
    612 void QNetworkManagerEngine::removeAccessPoint(const QString &path,
    613                                               const QDBusObjectPath &objectPath)
     712void QNetworkManagerEngine::removeAccessPoint(const QString &path)
    614713{
    615714    QMutexLocker locker(&mutex);
    616 
    617     Q_UNUSED(path)
    618 
    619715    for (int i = 0; i < accessPoints.count(); ++i) {
    620716        QNetworkManagerInterfaceAccessPoint *accessPoint = accessPoints.at(i);
    621 
    622         if (accessPoint->connectionInterface()->path() == objectPath.path()) {
     717        if (accessPoint->connectionInterface()->path() == path) {
    623718            accessPoints.removeOne(accessPoint);
    624719
    625             if (configuredAccessPoints.contains(accessPoint)) {
     720            if (configuredAccessPoints.contains(accessPoint->connectionInterface()->path())) {
    626721                // find connection and change state to Defined
    627                 configuredAccessPoints.removeOne(accessPoint);
     722                configuredAccessPoints.remove(accessPoint->connectionInterface()->path());
     723
    628724                for (int i = 0; i < connections.count(); ++i) {
    629725                    QNetworkManagerSettingsConnection *connection = connections.at(i);
    630726
    631                     if (accessPoint->ssid() == connection->getSsid()) {
    632                         const QString service = connection->connectionInterface()->service();
     727                    if (accessPoint->ssid() == connection->getSsid()) {//might not have bssid yet
    633728                        const QString settingsPath = connection->connectionInterface()->path();
    634                         const QString connectionId =
    635                             QString::number(qHash(service + ' ' + settingsPath));
     729                        const QString connectionId = settingsPath;
    636730
    637731                        QNetworkConfigurationPrivatePointer ptr =
    638732                            accessPointConfigurations.value(connectionId);
     
    648742                }
    649743            } else {
    650744                QNetworkConfigurationPrivatePointer ptr =
    651                     accessPointConfigurations.take(QString::number(qHash(objectPath.path())));
     745                    accessPointConfigurations.take(path);
    652746
    653747                if (ptr) {
    654748                    locker.unlock();
     
    656750                    locker.relock();
    657751                }
    658752            }
    659 
    660753            delete accessPoint;
    661 
    662754            break;
    663755        }
    664756    }
    665757}
    666758
    667 void QNetworkManagerEngine::updateAccessPoint(const QMap<QString, QVariant> &map)
    668 {
    669     QMutexLocker locker(&mutex);
    670 
    671     Q_UNUSED(map)
    672 
    673     QNetworkManagerInterfaceAccessPoint *accessPoint =
    674         qobject_cast<QNetworkManagerInterfaceAccessPoint *>(sender());
    675     if (!accessPoint)
    676         return;
    677 
    678     for (int i = 0; i < connections.count(); ++i) {
    679         QNetworkManagerSettingsConnection *connection = connections.at(i);
    680 
    681         if (accessPoint->ssid() == connection->getSsid()) {
    682             const QString service = connection->connectionInterface()->service();
    683             const QString settingsPath = connection->connectionInterface()->path();
    684             const QString connectionId = QString::number(qHash(service + ' ' + settingsPath));
    685 
    686             QNetworkConfigurationPrivatePointer ptr =
    687                 accessPointConfigurations.value(connectionId);
    688             ptr->mutex.lock();
    689             ptr->state = QNetworkConfiguration::Discovered;
    690             ptr->mutex.unlock();
    691 
    692             locker.unlock();
    693             emit configurationChanged(ptr);
    694             return;
    695         }
    696     }
    697 }
    698 
    699 QNetworkConfigurationPrivate *QNetworkManagerEngine::parseConnection(const QString &service,
    700                                                                      const QString &settingsPath,
     759QNetworkConfigurationPrivate *QNetworkManagerEngine::parseConnection(const QString &settingsPath,
    701760                                                                     const QNmSettingsMap &map)
    702761{
     762    QMutexLocker locker(&mutex);
    703763    QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate;
    704764    cpPriv->name = map.value("connection").value("id").toString();
     765
    705766    cpPriv->isValid = true;
    706     cpPriv->id = QString::number(qHash(service + ' ' + settingsPath));
     767    cpPriv->id = settingsPath;
    707768    cpPriv->type = QNetworkConfiguration::InternetAccessPoint;
    708769
    709770    cpPriv->purpose = QNetworkConfiguration::PublicPurpose;
    710771
    711772    cpPriv->state = QNetworkConfiguration::Defined;
    712 
    713773    const QString connectionType = map.value("connection").value("type").toString();
    714774
    715775    if (connectionType == QLatin1String("802-3-ethernet")) {
    716776        cpPriv->bearerType = QNetworkConfiguration::BearerEthernet;
    717         cpPriv->purpose = QNetworkConfiguration::PublicPurpose;
    718777
    719         foreach (const QDBusObjectPath &devicePath, interface->getDevices()) {
    720             QNetworkManagerInterfaceDevice device(devicePath.path());
    721             if (device.deviceType() == DEVICE_TYPE_802_3_ETHERNET) {
    722                 QNetworkManagerInterfaceDeviceWired wiredDevice(device.connectionInterface()->path());
    723                 if (wiredDevice.carrier()) {
     778        foreach (const QDBusObjectPath &devicePath, managerInterface->getDevices()) {
     779            QNetworkManagerInterfaceDevice device(devicePath.path(),this);
     780            if (device.deviceType() == DEVICE_TYPE_ETHERNET) {
     781                QNetworkManagerInterfaceDeviceWired *wiredDevice = wiredDevices.value(device.connectionInterface()->path());
     782                if (wiredDevice->carrier()) {
    724783                    cpPriv->state |= QNetworkConfiguration::Discovered;
    725784                    break;
    726785                }
    727 
    728786            }
    729787        }
    730788    } else if (connectionType == QLatin1String("802-11-wireless")) {
    731789        cpPriv->bearerType = QNetworkConfiguration::BearerWLAN;
    732790
    733791        const QString connectionSsid = map.value("802-11-wireless").value("ssid").toString();
    734         const QString connectionSecurity = map.value("802-11-wireless").value("security").toString();
    735         if(!connectionSecurity.isEmpty()) {
    736             cpPriv->purpose = QNetworkConfiguration::PrivatePurpose;
    737         } else {
    738             cpPriv->purpose = QNetworkConfiguration::PublicPurpose;
    739         }
    740792        for (int i = 0; i < accessPoints.count(); ++i) {
    741             if (connectionSsid == accessPoints.at(i)->ssid()) {
     793            if (connectionSsid == accessPoints.at(i)->ssid()
     794                    && map.value("802-11-wireless").value("seen-bssids").toStringList().contains(accessPoints.at(i)->hwAddress())) {
    742795                cpPriv->state |= QNetworkConfiguration::Discovered;
    743                 if (!configuredAccessPoints.contains(accessPoints.at(i))) {
    744                     configuredAccessPoints.append(accessPoints.at(i));
     796                if (!configuredAccessPoints.contains(accessPoints.at(i)->connectionInterface()->path())) {
     797                    configuredAccessPoints.insert(accessPoints.at(i)->connectionInterface()->path(),settingsPath);
    745798
    746                     const QString accessPointId =
    747                         QString::number(qHash(accessPoints.at(i)->connectionInterface()->path()));
     799                    const QString accessPointId = accessPoints.at(i)->connectionInterface()->path();
    748800                    QNetworkConfigurationPrivatePointer ptr =
    749801                        accessPointConfigurations.take(accessPointId);
    750802
    751803                    if (ptr) {
    752                         mutex.unlock();
     804                        locker.unlock();
    753805                        emit configurationRemoved(ptr);
    754                         mutex.lock();
     806                        locker.relock();
    755807                    }
    756808                }
    757809                break;
    758810            }
    759811        }
    760     } else if (connectionType == "gsm") {
    761         cpPriv->bearerType = QNetworkConfiguration::Bearer2G;
    762     } else if (connectionType == "cdma") {
    763         cpPriv->bearerType = QNetworkConfiguration::BearerCDMA2000;
     812    } else if (connectionType == QLatin1String("gsm")) {
     813
     814        const QString contextPath = map.value("connection").value("id").toString();
     815        cpPriv->name = contextName(contextPath);
     816        cpPriv->bearerType = currentBearerType(contextPath);
     817
     818        if (map.value("connection").contains("timestamp")) {
     819            cpPriv->state |= QNetworkConfiguration::Discovered;
     820        }
    764821    }
    765822
    766823    return cpPriv;
     
    770827{
    771828    for (int i = 0; i < connections.count(); ++i) {
    772829        QNetworkManagerSettingsConnection *connection = connections.at(i);
    773         const QString service = connection->connectionInterface()->service();
    774         const QString settingsPath = connection->connectionInterface()->path();
    775 
    776         const QString identifier = QString::number(qHash(service + ' ' + settingsPath));
    777 
    778         if (id == identifier)
     830        if (id == connection->connectionInterface()->path())
    779831            return connection;
    780832    }
    781833
     
    785837QNetworkSession::State QNetworkManagerEngine::sessionStateForId(const QString &id)
    786838{
    787839    QMutexLocker locker(&mutex);
    788 
    789840    QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id);
    790841
    791842    if (!ptr)
     
    794845    if (!ptr->isValid)
    795846        return QNetworkSession::Invalid;
    796847
    797     foreach (const QString &acPath, activeConnections.keys()) {
    798         QNetworkManagerConnectionActive *activeConnection = activeConnections.value(acPath);
     848    foreach (const QString &acPath, activeConnectionsList.keys()) {
     849        QNetworkManagerConnectionActive *activeConnection = activeConnectionsList.value(acPath);
    799850
    800         const QString identifier = QString::number(qHash(activeConnection->serviceName() + ' ' +
    801                                                          activeConnection->connection().path()));
     851        const QString identifier = activeConnection->connection().path();
    802852
    803853        if (id == identifier) {
    804854            switch (activeConnection->state()) {
     
    828878
    829879    QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id);
    830880    if (ptr && (ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) {
    831         const QString networkInterface = getInterfaceFromId(id);
     881        const QString networkInterface = connectionInterfaces.value(id);
    832882        if (!networkInterface.isEmpty()) {
    833883            const QString devFile = QLatin1String("/sys/class/net/") +
    834884                                    networkInterface +
     
    856906
    857907    QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id);
    858908    if (ptr && (ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) {
    859         const QString networkInterface = getInterfaceFromId(id);
     909        const QString networkInterface = connectionInterfaces.value(id);
    860910        if (!networkInterface.isEmpty()) {
    861911            const QString devFile = QLatin1String("/sys/class/net/") +
    862912                                    networkInterface +
     
    892942QNetworkConfigurationManager::Capabilities QNetworkManagerEngine::capabilities() const
    893943{
    894944    return QNetworkConfigurationManager::ForcedRoaming |
    895            QNetworkConfigurationManager::CanStartAndStopInterfaces;
     945            QNetworkConfigurationManager::DataStatistics |
     946            QNetworkConfigurationManager::CanStartAndStopInterfaces;
    896947}
    897948
    898949QNetworkSessionPrivate *QNetworkManagerEngine::createSessionBackend()
     
    902953
    903954QNetworkConfigurationPrivatePointer QNetworkManagerEngine::defaultConfiguration()
    904955{
     956    QHashIterator<QString, QNetworkManagerConnectionActive*> i(activeConnectionsList);
     957    while (i.hasNext()) {
     958        i.next();
     959        QNetworkManagerConnectionActive *activeConnection = i.value();
     960        if ((activeConnection->defaultRoute() || activeConnection->default6Route())) {
     961            return accessPointConfigurations.value(activeConnection->connection().path());
     962        }
     963    }
     964
    905965    return QNetworkConfigurationPrivatePointer();
    906966}
    907967
     968QNetworkConfiguration::BearerType QNetworkManagerEngine::currentBearerType(const QString &id)
     969{
     970    if (ofonoManager->isValid()) {
     971        QString contextPart = id.section('/', -1);
     972
     973        QHashIterator<QString, QOfonoDataConnectionManagerInterface*> i(ofonoContextManagers);
     974        while (i.hasNext()) {
     975            i.next();
     976            QString contextPath = i.key() +"/"+contextPart;
     977            if (i.value()->contexts().contains(contextPath)) {
     978
     979                QString bearer = i.value()->bearer();
     980                if (bearer == QStringLiteral("gsm")) {
     981                    return QNetworkConfiguration::Bearer2G;
     982                } else if (bearer == QStringLiteral("edge")) {
     983                    return QNetworkConfiguration::Bearer2G;
     984                } else if (bearer == QStringLiteral("umts")) {
     985                    return QNetworkConfiguration::BearerWCDMA;
     986                } else if (bearer == QStringLiteral("hspa")
     987                           || bearer == QStringLiteral("hsdpa")
     988                           || bearer == QStringLiteral("hsupa")) {
     989                    return QNetworkConfiguration::BearerHSPA;
     990                } else if (bearer == QStringLiteral("lte")) {
     991                    return QNetworkConfiguration::BearerLTE;
     992                }
     993            }
     994        }
     995    }
     996    return QNetworkConfiguration::BearerUnknown;
     997}
     998
     999QString QNetworkManagerEngine::contextName(const QString &path)
     1000{
     1001    if (ofonoManager->isValid()) {
     1002        QString contextPart = path.section('/', -1);
     1003        QHashIterator<QString, QOfonoDataConnectionManagerInterface*> i(ofonoContextManagers);
     1004        while (i.hasNext()) {
     1005            i.next();
     1006            Q_FOREACH (const QString &oContext, i.value()->contexts()) {
     1007                if (oContext.contains(contextPart)) {
     1008                    QOfonoConnectionContextInterface contextInterface(oContext,this);
     1009                    return contextInterface.name();
     1010                }
     1011            }
     1012        }
     1013    }
     1014    return path;
     1015}
     1016
    9081017QT_END_NAMESPACE
    9091018
    9101019#endif // QT_NO_DBUS
  • qtbase/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h

     
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
     3** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
    44** Contact: http://www.qt-project.org/legal
    55**
    66** This file is part of the plugins of the Qt Toolkit.
    77**
    8 ** $QT_BEGIN_LICENSE:LGPL$
     8** $QT_BEGIN_LICENSE:LGPL21$
    99** Commercial License Usage
    1010** Licensees holding valid commercial Qt licenses may use this file in
    1111** accordance with the commercial license agreement provided with the
    1212** Software or, alternatively, in accordance with the terms contained in
    13 ** a written agreement between you and Digia.  For licensing terms and
    14 ** conditions see http://qt.digia.com/licensing.  For further information
     13** a written agreement between you and Digia. For licensing terms and
     14** conditions see http://qt.digia.com/licensing. For further information
    1515** use the contact form at http://qt.digia.com/contact-us.
    1616**
    1717** GNU Lesser General Public License Usage
    1818** Alternatively, this file may be used under the terms of the GNU Lesser
    19 ** General Public License version 2.1 as published by the Free Software
    20 ** Foundation and appearing in the file LICENSE.LGPL included in the
    21 ** packaging of this file.  Please review the following information to
    22 ** ensure the GNU Lesser General Public License version 2.1 requirements
    23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
     19** General Public License version 2.1 or version 3 as published by the Free
     20** Software Foundation and appearing in the file LICENSE.LGPLv21 and
     21** LICENSE.LGPLv3 included in the packaging of this file. Please review the
     22** following information to ensure the GNU Lesser General Public License
     23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
     24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2425**
    2526** In addition, as a special exception, Digia gives you certain additional
    26 ** rights.  These rights are described in the Digia Qt LGPL Exception
     27** rights. These rights are described in the Digia Qt LGPL Exception
    2728** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2829**
    29 ** GNU General Public License Usage
    30 ** Alternatively, this file may be used under the terms of the GNU
    31 ** General Public License version 3.0 as published by the Free Software
    32 ** Foundation and appearing in the file LICENSE.GPL included in the
    33 ** packaging of this file.  Please review the following information to
    34 ** ensure the GNU General Public License version 3.0 requirements will be
    35 ** met: http://www.gnu.org/copyleft/gpl.html.
    36 **
    37 **
    3830** $QT_END_LICENSE$
    3931**
    4032****************************************************************************/
     
    5749
    5850#include "qnetworkmanagerservice.h"
    5951
     52#include "../linux_common/qofonoservice_linux_p.h"
     53
    6054#include <QMap>
    6155#include <QVariant>
    6256
     
    9791    QNetworkConfigurationPrivatePointer defaultConfiguration();
    9892
    9993private Q_SLOTS:
    100     void interfacePropertiesChanged(const QString &path,
    101                                     const QMap<QString, QVariant> &properties);
    102     void activeConnectionPropertiesChanged(const QString &path,
    103                                            const QMap<QString, QVariant> &properties);
    104     void devicePropertiesChanged(const QString &path,
    105                                  const QMap<QString, QVariant> &properties);
     94    void interfacePropertiesChanged(const QMap<QString, QVariant> &properties);
     95    void activeConnectionPropertiesChanged(const QMap<QString, QVariant> &properties);
    10696
    10797    void deviceAdded(const QDBusObjectPath &path);
    10898    void deviceRemoved(const QDBusObjectPath &path);
    10999
    110100    void newConnection(const QDBusObjectPath &path, QNetworkManagerSettings *settings = 0);
    111101    void removeConnection(const QString &path);
    112     void updateConnection(const QNmSettingsMap &settings);
     102    void updateConnection();
    113103    void activationFinished(QDBusPendingCallWatcher *watcher);
     104    void deviceConnectionsChanged(const QStringList &activeConnectionsList);
    114105
    115     void newAccessPoint(const QString &path, const QDBusObjectPath &objectPath);
    116     void removeAccessPoint(const QString &path, const QDBusObjectPath &objectPath);
    117     void updateAccessPoint(const QMap<QString, QVariant> &map);
     106    void newAccessPoint(const QString &path);
     107    void removeAccessPoint(const QString &path);
     108    void scanFinished();
     109
     110    void wiredCarrierChanged(bool);
    118111
    119112private:
    120     QNetworkConfigurationPrivate *parseConnection(const QString &service,
    121                                                   const QString &settingsPath,
     113    QNetworkConfigurationPrivate *parseConnection(const QString &settingsPath,
    122114                                                  const QNmSettingsMap &map);
    123115    QNetworkManagerSettingsConnection *connectionFromId(const QString &id) const;
    124116
    125 private:
    126     QNetworkManagerInterface *interface;
     117    QNetworkManagerInterface *managerInterface;
    127118    QNetworkManagerSettings *systemSettings;
    128     QNetworkManagerSettings *userSettings;
     119    QHash<QString, QNetworkManagerInterfaceDeviceWired *> wiredDevices;
    129120    QHash<QString, QNetworkManagerInterfaceDeviceWireless *> wirelessDevices;
    130     QHash<QString, QNetworkManagerConnectionActive *> activeConnections;
     121
     122    QHash<QString, QNetworkManagerConnectionActive *> activeConnectionsList;
    131123    QList<QNetworkManagerSettingsConnection *> connections;
    132124    QList<QNetworkManagerInterfaceAccessPoint *> accessPoints;
    133     QList<QNetworkManagerInterfaceAccessPoint *> configuredAccessPoints;
     125    QHash<QString, QNetworkManagerInterfaceDevice *> interfaceDevices;
     126
     127    QMap<QString,QString> configuredAccessPoints; //ap, settings path
     128    QHash<QString,QString> connectionInterfaces; // ac, interface
     129
     130    QOfonoManagerInterface *ofonoManager;
     131    QHash <QString, QOfonoDataConnectionManagerInterface *> ofonoContextManagers;
     132    QNetworkConfiguration::BearerType currentBearerType(const QString &id);
     133    QString contextName(const QString &path);
     134
    134135};
    135136
    136137QT_END_NAMESPACE
  • qtbase/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp

     
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
     3** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
    44** Contact: http://www.qt-project.org/legal
    55**
    66** This file is part of the plugins of the Qt Toolkit.
    77**
    8 ** $QT_BEGIN_LICENSE:LGPL$
     8** $QT_BEGIN_LICENSE:LGPL21$
    99** Commercial License Usage
    1010** Licensees holding valid commercial Qt licenses may use this file in
    1111** accordance with the commercial license agreement provided with the
    1212** Software or, alternatively, in accordance with the terms contained in
    13 ** a written agreement between you and Digia.  For licensing terms and
    14 ** conditions see http://qt.digia.com/licensing.  For further information
     13** a written agreement between you and Digia. For licensing terms and
     14** conditions see http://qt.digia.com/licensing. For further information
    1515** use the contact form at http://qt.digia.com/contact-us.
    1616**
    1717** GNU Lesser General Public License Usage
    1818** Alternatively, this file may be used under the terms of the GNU Lesser
    19 ** General Public License version 2.1 as published by the Free Software
    20 ** Foundation and appearing in the file LICENSE.LGPL included in the
    21 ** packaging of this file.  Please review the following information to
    22 ** ensure the GNU Lesser General Public License version 2.1 requirements
    23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
     19** General Public License version 2.1 or version 3 as published by the Free
     20** Software Foundation and appearing in the file LICENSE.LGPLv21 and
     21** LICENSE.LGPLv3 included in the packaging of this file. Please review the
     22** following information to ensure the GNU Lesser General Public License
     23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
     24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2425**
    2526** In addition, as a special exception, Digia gives you certain additional
    26 ** rights.  These rights are described in the Digia Qt LGPL Exception
     27** rights. These rights are described in the Digia Qt LGPL Exception
    2728** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2829**
    29 ** GNU General Public License Usage
    30 ** Alternatively, this file may be used under the terms of the GNU
    31 ** General Public License version 3.0 as published by the Free Software
    32 ** Foundation and appearing in the file LICENSE.GPL included in the
    33 ** packaging of this file.  Please review the following information to
    34 ** ensure the GNU General Public License version 3.0 requirements will be
    35 ** met: http://www.gnu.org/copyleft/gpl.html.
    36 **
    37 **
    3830** $QT_END_LICENSE$
    3931**
    4032****************************************************************************/
     
    5244#include <QtDBus/QDBusPendingCall>
    5345
    5446#include "qnetworkmanagerservice.h"
    55 #include "qnmdbushelper.h"
    5647
    5748#ifndef QT_NO_DBUS
    5849
     
    7263    d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE),
    7364                                                QLatin1String(NM_DBUS_PATH),
    7465                                                QLatin1String(NM_DBUS_INTERFACE),
    75                                                 QDBusConnection::systemBus());
     66                                                QDBusConnection::systemBus(),parent);
    7667    if (!d->connectionInterface->isValid()) {
    7768        d->valid = false;
    7869        return;
    7970    }
    8071    d->valid = true;
    81     nmDBusHelper = new QNmDBusHelper(this);
    82     connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(QString,QMap<QString,QVariant>)),
    83                     this,SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>)));
    84     connect(nmDBusHelper,SIGNAL(pathForStateChanged(QString,quint32)),
    85             this, SIGNAL(stateChanged(QString,quint32)));
    8672
     73    QDBusInterface managerPropertiesInterface(QLatin1String(NM_DBUS_SERVICE),
     74                                                  QLatin1String(NM_DBUS_PATH),
     75                                                  QLatin1String("org.freedesktop.DBus.Properties"),
     76                                                  QDBusConnection::systemBus());
     77    QList<QVariant> argumentList;
     78    argumentList << QLatin1String(NM_DBUS_INTERFACE);
     79    QDBusPendingReply<QVariantMap> propsReply
     80            = managerPropertiesInterface.callWithArgumentList(QDBus::Block,QLatin1String("GetAll"),
     81                                                                       argumentList);
     82    if (!propsReply.isError()) {
     83        propertyMap = propsReply.value();
     84    }
     85
     86    QDBusPendingReply<QList <QDBusObjectPath> > nmReply
     87            = d->connectionInterface->call(QLatin1String("GetDevices"));
     88    nmReply.waitForFinished();
     89    if (!nmReply.isError()) {
     90        devicesPathList = nmReply.value();
     91    }
     92
     93    QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE),
     94                                  QLatin1String(NM_DBUS_PATH),
     95                                  QLatin1String(NM_DBUS_INTERFACE),
     96                                  QLatin1String("PropertiesChanged"),
     97                                  this,SLOT(propertiesSwap(QMap<QString,QVariant>)));
    8798}
    8899
    89100QNetworkManagerInterface::~QNetworkManagerInterface()
     
    99110
    100111bool QNetworkManagerInterface::setConnections()
    101112{
    102     if(!isValid() )
     113    if (!isValid())
    103114        return false;
    104115
    105     QDBusConnection dbusConnection = QDBusConnection::systemBus();
    106 
    107     bool allOk = false;
    108     if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),
     116    QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE),
    109117                                  QLatin1String(NM_DBUS_PATH),
    110118                                  QLatin1String(NM_DBUS_INTERFACE),
    111119                                  QLatin1String("PropertiesChanged"),
    112                                 nmDBusHelper,SLOT(slotPropertiesChanged(QMap<QString,QVariant>)))) {
    113         allOk = true;
    114     }
    115     if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),
     120                                  this,SLOT(propertiesSwap(QMap<QString,QVariant>)));
     121
     122    bool allOk = false;
     123    if (QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE),
    116124                                  QLatin1String(NM_DBUS_PATH),
    117125                                  QLatin1String(NM_DBUS_INTERFACE),
    118126                                  QLatin1String("DeviceAdded"),
    119127                                this,SIGNAL(deviceAdded(QDBusObjectPath)))) {
    120128        allOk = true;
    121129    }
    122     if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),
     130    if (QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE),
    123131                                  QLatin1String(NM_DBUS_PATH),
    124132                                  QLatin1String(NM_DBUS_INTERFACE),
    125133                                  QLatin1String("DeviceRemoved"),
     
    135143    return d->connectionInterface;
    136144}
    137145
    138 QList <QDBusObjectPath> QNetworkManagerInterface::getDevices() const
     146QList <QDBusObjectPath> QNetworkManagerInterface::getDevices()
    139147{
    140     QDBusReply<QList<QDBusObjectPath> > reply =  d->connectionInterface->call(QLatin1String("GetDevices"));
    141     return reply.value();
     148    if (devicesPathList.isEmpty()) {
     149        qWarning() << "using blocking call!";
     150        QDBusReply<QList<QDBusObjectPath> > reply = d->connectionInterface->call(QLatin1String("GetDevices"));
     151        devicesPathList = reply.value();
     152    }
     153    return devicesPathList;
    142154}
    143155
    144 void QNetworkManagerInterface::activateConnection( const QString &serviceName,
    145                                                   QDBusObjectPath connectionPath,
     156void QNetworkManagerInterface::activateConnection(QDBusObjectPath connectionPath,
    146157                                                  QDBusObjectPath devicePath,
    147158                                                  QDBusObjectPath specificObject)
    148159{
    149160    QDBusPendingCall pendingCall = d->connectionInterface->asyncCall(QLatin1String("ActivateConnection"),
    150                                                                     QVariant(serviceName),
    151161                                                                    QVariant::fromValue(connectionPath),
    152162                                                                    QVariant::fromValue(devicePath),
    153163                                                                    QVariant::fromValue(specificObject));
    154164
    155    QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(pendingCall, this);
     165   QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(pendingCall);
    156166   connect(callWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
    157167                    this, SIGNAL(activationFinished(QDBusPendingCallWatcher*)));
    158168}
    159169
    160170void QNetworkManagerInterface::deactivateConnection(QDBusObjectPath connectionPath)  const
    161171{
    162     d->connectionInterface->call(QLatin1String("DeactivateConnection"), QVariant::fromValue(connectionPath));
     172    d->connectionInterface->asyncCall(QLatin1String("DeactivateConnection"), QVariant::fromValue(connectionPath));
    163173}
    164174
    165175bool QNetworkManagerInterface::wirelessEnabled()  const
    166176{
    167     return d->connectionInterface->property("WirelessEnabled").toBool();
     177    if (propertyMap.contains("WirelessEnabled"))
     178        return propertyMap.value("WirelessEnabled").toBool();
     179    return false;
    168180}
    169181
    170182bool QNetworkManagerInterface::wirelessHardwareEnabled()  const
    171183{
    172     return d->connectionInterface->property("WirelessHardwareEnabled").toBool();
     184    if (propertyMap.contains("WirelessHardwareEnabled"))
     185        return propertyMap.value("WirelessHardwareEnabled").toBool();
     186    return false;
    173187}
    174188
    175189QList <QDBusObjectPath> QNetworkManagerInterface::activeConnections() const
    176190{
    177     QVariant prop = d->connectionInterface->property("ActiveConnections");
    178     return prop.value<QList<QDBusObjectPath> >();
     191    if (propertyMap.contains("ActiveConnections")) {
     192
     193        const QDBusArgument &dbusArgs = propertyMap.value("ActiveConnections").value<QDBusArgument>();
     194        QDBusObjectPath path;
     195        QList <QDBusObjectPath> list;
     196
     197        dbusArgs.beginArray();
     198        while (!dbusArgs.atEnd()) {
     199            dbusArgs >> path;
     200            list.append(path);
     201        }
     202        dbusArgs.endArray();
     203
     204        return list;
     205    }
     206
     207    QList <QDBusObjectPath> list;
     208    list << QDBusObjectPath();
     209    return list;
    179210}
    180211
    181 quint32 QNetworkManagerInterface::state()
     212QNetworkManagerInterface::NMState QNetworkManagerInterface::state()
    182213{
    183     return d->connectionInterface->property("State").toUInt();
     214    if (propertyMap.contains("State"))
     215        return static_cast<QNetworkManagerInterface::NMState>(propertyMap.value("State").toUInt());
     216    return QNetworkManagerInterface::NM_STATE_UNKNOWN;
     217}
     218
     219QString QNetworkManagerInterface::version() const
     220{
     221    if (propertyMap.contains("Version"))
     222        return propertyMap.value("Version").toString();
     223    return QString();
     224}
     225
     226void QNetworkManagerInterface::propertiesSwap(QMap<QString,QVariant> map)
     227{
     228    QMapIterator<QString, QVariant> i(map);
     229    while (i.hasNext()) {
     230        i.next();
     231        propertyMap.insert(i.key(),i.value());
     232
     233        if (i.key() == QStringLiteral("State")) {
     234            quint32 state = i.value().toUInt();
     235            if (state == NM_DEVICE_STATE_ACTIVATED
     236                || state == NM_DEVICE_STATE_DISCONNECTED
     237                || state == NM_DEVICE_STATE_UNAVAILABLE
     238                || state == NM_DEVICE_STATE_FAILED) {
     239                Q_EMIT propertiesChanged(map);
     240                Q_EMIT stateChanged(state);
     241            }
     242        } else if (i.key() == QStringLiteral("ActiveConnections")) {
     243            Q_EMIT propertiesChanged(map);
     244        }
     245    }
    184246}
    185247
    186248class QNetworkManagerInterfaceAccessPointPrivate
     
    192254};
    193255
    194256QNetworkManagerInterfaceAccessPoint::QNetworkManagerInterfaceAccessPoint(const QString &dbusPathName, QObject *parent)
    195         : QObject(parent), nmDBusHelper(0)
     257        : QObject(parent)
    196258{
    197259    d = new QNetworkManagerInterfaceAccessPointPrivate();
    198260    d->path = dbusPathName;
    199261    d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE),
    200262                                                d->path,
    201263                                                QLatin1String(NM_DBUS_INTERFACE_ACCESS_POINT),
    202                                                 QDBusConnection::systemBus());
     264                                                QDBusConnection::systemBus(),parent);
    203265    if (!d->connectionInterface->isValid()) {
    204266        d->valid = false;
    205267        return;
    206268    }
     269    QDBusInterface accessPointPropertiesInterface(QLatin1String(NM_DBUS_SERVICE),
     270                                                  d->path,
     271                                                  QLatin1String("org.freedesktop.DBus.Properties"),
     272                                                  QDBusConnection::systemBus());
     273
     274    QList<QVariant> argumentList;
     275    argumentList << QLatin1String(NM_DBUS_INTERFACE_ACCESS_POINT);
     276    QDBusPendingReply<QVariantMap> propsReply
     277            = accessPointPropertiesInterface.callWithArgumentList(QDBus::Block,QLatin1String("GetAll"),
     278                                                                       argumentList);
     279    if (!propsReply.isError()) {
     280        propertyMap = propsReply.value();
     281    }
     282
     283    QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE),
     284                                  d->path,
     285                                  QLatin1String(NM_DBUS_INTERFACE_ACCESS_POINT),
     286                                  QLatin1String("PropertiesChanged"),
     287                                  this,SLOT(propertiesSwap(QMap<QString,QVariant>)));
     288
    207289    d->valid = true;
    208290
    209291}
     
    221303
    222304bool QNetworkManagerInterfaceAccessPoint::setConnections()
    223305{
    224     if(!isValid() )
     306    if (!isValid())
    225307        return false;
    226308
    227     bool allOk = false;
    228     delete nmDBusHelper;
    229     nmDBusHelper = new QNmDBusHelper(this);
    230     connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(QString,QMap<QString,QVariant>)),
    231             this,SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>)));
    232 
    233     if (QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE),
    234                               d->path,
    235                               QLatin1String(NM_DBUS_INTERFACE_ACCESS_POINT),
    236                               QLatin1String("PropertiesChanged"),
    237                               nmDBusHelper,SLOT(slotPropertiesChanged(QMap<QString,QVariant>))) ) {
    238         allOk = true;
    239 
    240     }
    241     return allOk;
     309    return true;
    242310}
    243311
    244312QDBusInterface *QNetworkManagerInterfaceAccessPoint::connectionInterface() const
     
    248316
    249317quint32 QNetworkManagerInterfaceAccessPoint::flags() const
    250318{
    251     return d->connectionInterface->property("Flags").toUInt();
     319    if (propertyMap.contains("Flags"))
     320        return propertyMap.value("Flags").toUInt();
     321    return 0;
    252322}
    253323
    254324quint32 QNetworkManagerInterfaceAccessPoint::wpaFlags() const
    255325{
    256     return d->connectionInterface->property("WpaFlags").toUInt();
     326    if (propertyMap.contains("WpaFlags"))
     327        return propertyMap.value("WpaFlags").toUInt();
     328    return 0;
    257329}
    258330
    259331quint32 QNetworkManagerInterfaceAccessPoint::rsnFlags() const
    260332{
    261     return d->connectionInterface->property("RsnFlags").toUInt();
     333    if (propertyMap.contains("RsnFlags"))
     334        return propertyMap.value("RsnFlags").toUInt();
     335    return 0;
    262336}
    263337
    264338QString QNetworkManagerInterfaceAccessPoint::ssid() const
    265339{
    266     return d->connectionInterface->property("Ssid").toString();
     340    if (propertyMap.contains("Ssid"))
     341        return propertyMap.value("Ssid").toString();
     342    return QString();
    267343}
    268344
    269345quint32 QNetworkManagerInterfaceAccessPoint::frequency() const
    270346{
    271     return d->connectionInterface->property("Frequency").toUInt();
     347    if (propertyMap.contains("Frequency"))
     348        return propertyMap.value("Frequency").toUInt();
     349    return 0;
    272350}
    273351
    274352QString QNetworkManagerInterfaceAccessPoint::hwAddress() const
    275353{
    276     return d->connectionInterface->property("HwAddress").toString();
     354    if (propertyMap.contains("HwAddress"))
     355        return propertyMap.value("HwAddress").toString();
     356    return QString();
    277357}
    278358
    279359quint32 QNetworkManagerInterfaceAccessPoint::mode() const
    280360{
    281     return d->connectionInterface->property("Mode").toUInt();
     361    if (propertyMap.contains("Mode"))
     362        return propertyMap.value("Mode").toUInt();
     363    return 0;
    282364}
    283365
    284366quint32 QNetworkManagerInterfaceAccessPoint::maxBitrate() const
    285367{
    286     return d->connectionInterface->property("MaxBitrate").toUInt();
     368    if (propertyMap.contains("MaxBitrate"))
     369        return propertyMap.value("MaxBitrate").toUInt();
     370    return 0;
    287371}
    288372
    289373quint32 QNetworkManagerInterfaceAccessPoint::strength() const
    290374{
    291     return d->connectionInterface->property("Strength").toUInt();
     375    if (propertyMap.contains("Strength"))
     376        return propertyMap.value("Strength").toUInt();
     377    return 0;
     378}
     379
     380void QNetworkManagerInterfaceAccessPoint::propertiesSwap(QMap<QString,QVariant> map)
     381{
     382    QMapIterator<QString, QVariant> i(map);
     383    while (i.hasNext()) {
     384        i.next();
     385        propertyMap.insert(i.key(),i.value());
     386    }
    292387}
    293388
    294389class QNetworkManagerInterfaceDevicePrivate
     
    300395};
    301396
    302397QNetworkManagerInterfaceDevice::QNetworkManagerInterfaceDevice(const QString &deviceObjectPath, QObject *parent)
    303         : QObject(parent), nmDBusHelper(0)
     398        : QObject(parent)
    304399{
     400
    305401    d = new QNetworkManagerInterfaceDevicePrivate();
    306402    d->path = deviceObjectPath;
    307403    d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE),
    308404                                                d->path,
    309405                                                QLatin1String(NM_DBUS_INTERFACE_DEVICE),
    310                                                 QDBusConnection::systemBus());
     406                                                QDBusConnection::systemBus(),parent);
    311407    if (!d->connectionInterface->isValid()) {
    312408        d->valid = false;
    313409        return;
    314410    }
     411    QDBusInterface devicePropertiesInterface(QLatin1String(NM_DBUS_SERVICE),
     412                                                  d->path,
     413                                                  QLatin1String("org.freedesktop.DBus.Properties"),
     414                                                  QDBusConnection::systemBus(),parent);
     415
     416    QList<QVariant> argumentList;
     417    argumentList << QLatin1String(NM_DBUS_INTERFACE_DEVICE);
     418    QDBusPendingReply<QVariantMap> propsReply
     419            = devicePropertiesInterface.callWithArgumentList(QDBus::Block,QLatin1String("GetAll"),
     420                                                                       argumentList);
     421
     422    if (!propsReply.isError()) {
     423        propertyMap = propsReply.value();
     424    }
     425
     426    QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE),
     427                                  d->path,
     428                                  QLatin1String(NM_DBUS_INTERFACE_DEVICE),
     429                                  QLatin1String("PropertiesChanged"),
     430                                  this,SLOT(propertiesSwap(QMap<QString,QVariant>)));
    315431    d->valid = true;
    316432}
    317433
     
    328444
    329445bool QNetworkManagerInterfaceDevice::setConnections()
    330446{
    331     if(!isValid() )
     447    if (!isValid())
    332448        return false;
    333449
    334     bool allOk = false;
    335     delete nmDBusHelper;
    336     nmDBusHelper = new QNmDBusHelper(this);
    337     connect(nmDBusHelper,SIGNAL(pathForStateChanged(QString,quint32)),
    338             this, SIGNAL(stateChanged(QString,quint32)));
    339     if (QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE),
    340                               d->path,
    341                               QLatin1String(NM_DBUS_INTERFACE_DEVICE),
    342                               QLatin1String("StateChanged"),
    343                               nmDBusHelper,SLOT(deviceStateChanged(quint32)))) {
    344         allOk = true;
    345     }
    346     return allOk;
     450    return true;
    347451}
    348452
    349453QDBusInterface *QNetworkManagerInterfaceDevice::connectionInterface() const
     
    353457
    354458QString QNetworkManagerInterfaceDevice::udi() const
    355459{
    356     return d->connectionInterface->property("Udi").toString();
     460    if (propertyMap.contains("Udi"))
     461        return propertyMap.value("Udi").toString();
     462    return QString();
    357463}
    358464
    359465QString QNetworkManagerInterfaceDevice::networkInterface() const
    360466{
    361     return d->connectionInterface->property("Interface").toString();
     467    if (propertyMap.contains("Interface"))
     468        return propertyMap.value("Interface").toString();
     469    return QString();
    362470}
    363471
    364472quint32 QNetworkManagerInterfaceDevice::ip4Address() const
    365473{
    366     return d->connectionInterface->property("Ip4Address").toUInt();
     474    if (propertyMap.contains("Ip4Address"))
     475        return propertyMap.value("Ip4Address").toUInt();
     476    return 0;
    367477}
    368478
    369479quint32 QNetworkManagerInterfaceDevice::state() const
    370480{
    371     return d->connectionInterface->property("State").toUInt();
     481    if (propertyMap.contains("State"))
     482        return propertyMap.value("State").toUInt();
     483    return 0;
    372484}
    373485
    374486quint32 QNetworkManagerInterfaceDevice::deviceType() const
    375487{
    376     return d->connectionInterface->property("DeviceType").toUInt();
     488    if (propertyMap.contains("DeviceType"))
     489        return propertyMap.value("DeviceType").toUInt();
     490    return 0;
    377491}
    378492
    379493QDBusObjectPath QNetworkManagerInterfaceDevice::ip4config() const
    380494{
    381     QVariant prop = d->connectionInterface->property("Ip4Config");
    382     return prop.value<QDBusObjectPath>();
     495    if (propertyMap.contains("Ip4Config"))
     496        return propertyMap.value("Ip4Config").value<QDBusObjectPath>();
     497    return QDBusObjectPath();
     498}
     499
     500void QNetworkManagerInterfaceDevice::propertiesSwap(QMap<QString,QVariant> map)
     501{
     502    QMapIterator<QString, QVariant> i(map);
     503    while (i.hasNext()) {
     504        i.next();
     505        if (i.key() == QStringLiteral("AvailableConnections")) { //Device
     506            const QDBusArgument &dbusArgs = i.value().value<QDBusArgument>();
     507            QDBusObjectPath path;
     508            QStringList paths;
     509            dbusArgs.beginArray();
     510            while (!dbusArgs.atEnd()) {
     511                dbusArgs >> path;
     512                paths << path.path();
     513            }
     514            dbusArgs.endArray();
     515            Q_EMIT connectionsChanged(paths);
     516        }
     517        propertyMap.insert(i.key(),i.value());
     518    }
     519    Q_EMIT propertiesChanged(map);
    383520}
    384521
    385522class QNetworkManagerInterfaceDeviceWiredPrivate
     
    391528};
    392529
    393530QNetworkManagerInterfaceDeviceWired::QNetworkManagerInterfaceDeviceWired(const QString &ifaceDevicePath, QObject *parent)
    394     : QObject(parent), nmDBusHelper(0)
     531    : QObject(parent)
    395532{
    396533    d = new QNetworkManagerInterfaceDeviceWiredPrivate();
    397534    d->path = ifaceDevicePath;
     
    403540        d->valid = false;
    404541        return;
    405542    }
     543    QDBusInterface deviceWiredPropertiesInterface(QLatin1String(NM_DBUS_SERVICE),
     544                                                  d->path,
     545                                                  QLatin1String("org.freedesktop.DBus.Properties"),
     546                                                  QDBusConnection::systemBus(),parent);
     547
     548    QList<QVariant> argumentList;
     549    argumentList << QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRED);
     550    QDBusPendingReply<QVariantMap> propsReply
     551            = deviceWiredPropertiesInterface.callWithArgumentList(QDBus::Block,QLatin1String("GetAll"),
     552                                                                       argumentList);
     553
     554    if (!propsReply.isError()) {
     555        propertyMap = propsReply.value();
     556    }
     557
     558    QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE),
     559                                  d->path,
     560                                  QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRED),
     561                                  QLatin1String("PropertiesChanged"),
     562                                  this,SLOT(propertiesSwap(QMap<QString,QVariant>)));
     563
    406564    d->valid = true;
    407565}
    408566
     
    420578
    421579bool QNetworkManagerInterfaceDeviceWired::setConnections()
    422580{
    423     if(!isValid() )
     581    if (!isValid())
    424582        return false;
    425 
    426     bool allOk = false;
    427 
    428     delete nmDBusHelper;
    429     nmDBusHelper = new QNmDBusHelper(this);
    430     connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(QString,QMap<QString,QVariant>)),
    431             this,SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>)));
    432     if (QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE),
    433                               d->path,
    434                               QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRED),
    435                               QLatin1String("PropertiesChanged"),
    436                               nmDBusHelper,SLOT(slotPropertiesChanged(QMap<QString,QVariant>))) )  {
    437         allOk = true;
    438     }
    439     return allOk;
     583    return true;
    440584}
    441585
    442586QDBusInterface *QNetworkManagerInterfaceDeviceWired::connectionInterface() const
     
    446590
    447591QString QNetworkManagerInterfaceDeviceWired::hwAddress() const
    448592{
    449     return d->connectionInterface->property("HwAddress").toString();
     593    if (propertyMap.contains("HwAddress"))
     594        return propertyMap.value("HwAddress").toString();
     595    return QString();
    450596}
    451597
    452598quint32 QNetworkManagerInterfaceDeviceWired::speed() const
    453599{
    454     return d->connectionInterface->property("Speed").toUInt();
     600    if (propertyMap.contains("Speed"))
     601        return propertyMap.value("Speed").toUInt();
     602    return 0;
    455603}
    456604
    457605bool QNetworkManagerInterfaceDeviceWired::carrier() const
    458606{
    459     return d->connectionInterface->property("Carrier").toBool();
     607    if (propertyMap.contains("Carrier"))
     608        return propertyMap.value("Carrier").toBool();
     609    return false;
     610}
     611
     612QStringList QNetworkManagerInterfaceDeviceWired::availableConnections()
     613{
     614    QStringList list;
     615    if (propertyMap.contains("AvailableConnections")) {
     616        const QDBusArgument &dbusArgs = propertyMap.value("Carrier").value<QDBusArgument>();
     617        QDBusObjectPath path;
     618        dbusArgs.beginArray();
     619        while (!dbusArgs.atEnd()) {
     620            dbusArgs >> path;
     621            list << path.path();
     622        }
     623        dbusArgs.endArray();
     624    }
     625
     626    return list;
     627}
     628
     629void QNetworkManagerInterfaceDeviceWired::propertiesSwap(QMap<QString,QVariant> map)
     630{
     631    QMapIterator<QString, QVariant> i(map);
     632    while (i.hasNext()) {
     633        i.next();
     634        propertyMap.insert(i.key(),i.value());
     635        if (i.key() == QStringLiteral("Carrier")) {
     636            Q_EMIT carrierChanged(i.value().toBool());
     637        }
     638    }
     639    Q_EMIT propertiesChanged(map);
    460640}
    461641
    462642class QNetworkManagerInterfaceDeviceWirelessPrivate
     
    468648};
    469649
    470650QNetworkManagerInterfaceDeviceWireless::QNetworkManagerInterfaceDeviceWireless(const QString &ifaceDevicePath, QObject *parent)
    471     : QObject(parent), nmDBusHelper(0)
     651    : QObject(parent)
    472652{
    473653    d = new QNetworkManagerInterfaceDeviceWirelessPrivate();
    474654    d->path = ifaceDevicePath;
     
    480660        d->valid = false;
    481661        return;
    482662    }
     663
     664
     665    QDBusPendingReply<QList <QDBusObjectPath> > nmReply
     666            = d->connectionInterface->call(QLatin1String("GetAccessPoints"));
     667
     668    if (!nmReply.isError()) {
     669        accessPointsList = nmReply.value();
     670    }
     671
     672    QDBusInterface deviceWirelessPropertiesInterface(QLatin1String(NM_DBUS_SERVICE),
     673                                                  d->path,
     674                                                  QLatin1String("org.freedesktop.DBus.Properties"),
     675                                                  QDBusConnection::systemBus(),parent);
     676
     677    QList<QVariant> argumentList;
     678    argumentList << QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS);
     679    QDBusPendingReply<QVariantMap> propsReply
     680            = deviceWirelessPropertiesInterface.callWithArgumentList(QDBus::Block,QLatin1String("GetAll"),
     681                                                                       argumentList);
     682    if (!propsReply.isError()) {
     683        propertyMap = propsReply.value();
     684    }
     685
     686    QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE),
     687                                  d->path,
     688                                  QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS),
     689                                  QLatin1String("PropertiesChanged"),
     690                                  this,SLOT(propertiesSwap(QMap<QString,QVariant>)));
    483691    d->valid = true;
    484692}
    485693
     
    494702    return d->valid;
    495703}
    496704
     705void QNetworkManagerInterfaceDeviceWireless::slotAccessPointAdded(QDBusObjectPath path)
     706{
     707    if (path.path().length() > 2)
     708        Q_EMIT accessPointAdded(path.path());
     709}
     710
     711void QNetworkManagerInterfaceDeviceWireless::slotAccessPointRemoved(QDBusObjectPath path)
     712{
     713    if (path.path().length() > 2)
     714        Q_EMIT accessPointRemoved(path.path());
     715}
     716
    497717bool QNetworkManagerInterfaceDeviceWireless::setConnections()
    498718{
    499     if(!isValid() )
     719    if (!isValid())
    500720        return false;
    501721
    502722    QDBusConnection dbusConnection = QDBusConnection::systemBus();
    503     bool allOk = false;
    504     delete nmDBusHelper;
    505     nmDBusHelper = new QNmDBusHelper(this);
    506     connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(QString,QMap<QString,QVariant>)),
    507             this,SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>)));
     723    bool allOk = true;
    508724
    509     connect(nmDBusHelper, SIGNAL(pathForAccessPointAdded(QString,QDBusObjectPath)),
    510             this,SIGNAL(accessPointAdded(QString,QDBusObjectPath)));
    511 
    512     connect(nmDBusHelper, SIGNAL(pathForAccessPointRemoved(QString,QDBusObjectPath)),
    513             this,SIGNAL(accessPointRemoved(QString,QDBusObjectPath)));
    514 
    515     if(!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),
    516                               d->path,
     725    if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),
     726                                d->path,
    517727                              QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS),
    518728                              QLatin1String("AccessPointAdded"),
    519                               nmDBusHelper, SLOT(slotAccessPointAdded(QDBusObjectPath)))) {
    520         allOk = true;
     729                              this, SLOT(slotAccessPointAdded(QDBusObjectPath)))) {
     730        allOk = false;
    521731    }
    522732
    523733
    524     if(!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),
     734    if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),
    525735                              d->path,
    526736                              QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS),
    527737                              QLatin1String("AccessPointRemoved"),
    528                               nmDBusHelper, SLOT(slotAccessPointRemoved(QDBusObjectPath)))) {
    529         allOk = true;
     738                              this, SLOT(slotAccessPointRemoved(QDBusObjectPath)))) {
     739        allOk = false;
    530740    }
    531741
    532 
    533     if(!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),
    534                               d->path,
    535                               QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS),
    536                               QLatin1String("PropertiesChanged"),
    537                               nmDBusHelper,SLOT(slotPropertiesChanged(QMap<QString,QVariant>)))) {
    538         allOk = true;
     742    if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),
     743                               d->path,
     744                               QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS),
     745                               QLatin1String("ScanDone"),
     746                               this, SLOT(scanIsDone()))) {
     747        allOk = false;
    539748    }
    540 
    541749    return allOk;
    542750}
    543751
     
    548756
    549757QList <QDBusObjectPath> QNetworkManagerInterfaceDeviceWireless::getAccessPoints()
    550758{
    551     QDBusReply<QList<QDBusObjectPath> > reply = d->connectionInterface->call(QLatin1String("GetAccessPoints"));
    552     return reply.value();
     759    if (accessPointsList.isEmpty()) {
     760        qWarning() << "Using blocking call!";
     761        QDBusReply<QList<QDBusObjectPath> > reply
     762                = d->connectionInterface->call(QLatin1String("GetAccessPoints"));
     763        accessPointsList = reply.value();
     764    }
     765    return accessPointsList;
    553766}
    554767
    555768QString QNetworkManagerInterfaceDeviceWireless::hwAddress() const
    556769{
    557     return d->connectionInterface->property("HwAddress").toString();
     770    if (propertyMap.contains("HwAddress"))
     771        return propertyMap.value("HwAddress").toString();
     772    return QString();
    558773}
    559774
    560775quint32 QNetworkManagerInterfaceDeviceWireless::mode() const
    561776{
    562     return d->connectionInterface->property("Mode").toUInt();
     777    if (propertyMap.contains("Mode"))
     778        return propertyMap.value("Mode").toUInt();
     779    return 0;
    563780}
    564781
    565782quint32 QNetworkManagerInterfaceDeviceWireless::bitrate() const
    566783{
    567     return d->connectionInterface->property("Bitrate").toUInt();
     784    if (propertyMap.contains("Bitrate"))
     785        return propertyMap.value("Bitrate").toUInt();
     786    return 0;
    568787}
    569788
    570789QDBusObjectPath QNetworkManagerInterfaceDeviceWireless::activeAccessPoint() const
    571790{
    572     return d->connectionInterface->property("ActiveAccessPoint").value<QDBusObjectPath>();
     791    if (propertyMap.contains("ActiveAccessPoint"))
     792        return propertyMap.value("ActiveAccessPoint").value<QDBusObjectPath>();
     793    return QDBusObjectPath();
    573794}
    574795
    575796quint32 QNetworkManagerInterfaceDeviceWireless::wirelessCapabilities() const
    576797{
    577     return d->connectionInterface->property("WirelelessCapabilities").toUInt();
     798    if (propertyMap.contains("WirelelessCapabilities"))
     799        return propertyMap.value("WirelelessCapabilities").toUInt();
     800    return 0;
     801}
     802
     803void QNetworkManagerInterfaceDeviceWireless::scanIsDone()
     804{
     805    Q_EMIT scanDone();
     806}
     807
     808void QNetworkManagerInterfaceDeviceWireless::requestScan()
     809{
     810    d->connectionInterface->asyncCall(QLatin1String("RequestScan"));
     811}
     812
     813void QNetworkManagerInterfaceDeviceWireless::propertiesSwap(QMap<QString,QVariant> map)
     814{
     815    QMapIterator<QString, QVariant> i(map);
     816    while (i.hasNext()) {
     817        i.next();
     818        propertyMap.insert(i.key(),i.value());
     819        if (i.key() == QStringLiteral("ActiveAccessPoint")) { //DeviceWireless
     820            Q_EMIT propertiesChanged(map);
     821        }
     822    }
     823}
     824
     825class QNetworkManagerInterfaceDeviceModemPrivate
     826{
     827public:
     828    QDBusInterface *connectionInterface;
     829    QString path;
     830    bool valid;
     831};
     832
     833QNetworkManagerInterfaceDeviceModem::QNetworkManagerInterfaceDeviceModem(const QString &ifaceDevicePath, QObject *parent)
     834    : QObject(parent)
     835{
     836    d = new QNetworkManagerInterfaceDeviceModemPrivate();
     837    d->path = ifaceDevicePath;
     838    d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE),
     839                                                d->path,
     840                                                QLatin1String(NM_DBUS_INTERFACE_DEVICE_MODEM),
     841                                                QDBusConnection::systemBus(), parent);
     842    if (!d->connectionInterface->isValid()) {
     843        d->valid = false;
     844        return;
     845    }
     846    QDBusInterface deviceModemPropertiesInterface(QLatin1String(NM_DBUS_SERVICE),
     847                                                  d->path,
     848                                                  QLatin1String("org.freedesktop.DBus.Properties"),
     849                                                  QDBusConnection::systemBus(),parent);
     850
     851    QList<QVariant> argumentList;
     852    argumentList << QLatin1String(NM_DBUS_INTERFACE_DEVICE_MODEM);
     853    QDBusPendingReply<QVariantMap> propsReply
     854            = deviceModemPropertiesInterface.callWithArgumentList(QDBus::Block,QLatin1String("GetAll"),
     855                                                                       argumentList);
     856    if (!propsReply.isError()) {
     857        propertyMap = propsReply.value();
     858    }
     859
     860    QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE),
     861                                  d->path,
     862                                  QLatin1String(NM_DBUS_INTERFACE_DEVICE_MODEM),
     863                                  QLatin1String("PropertiesChanged"),
     864                                  this,SLOT(propertiesSwap(QMap<QString,QVariant>)));
     865    d->valid = true;
     866}
     867
     868QNetworkManagerInterfaceDeviceModem::~QNetworkManagerInterfaceDeviceModem()
     869{
     870    delete d->connectionInterface;
     871    delete d;
     872}
     873
     874bool QNetworkManagerInterfaceDeviceModem::isValid()
     875{
     876
     877    return d->valid;
     878}
     879
     880bool QNetworkManagerInterfaceDeviceModem::setConnections()
     881{
     882    if (!isValid() )
     883        return false;
     884
     885    return true;
     886}
     887
     888QDBusInterface *QNetworkManagerInterfaceDeviceModem::connectionInterface() const
     889{
     890    return d->connectionInterface;
     891}
     892
     893QNetworkManagerInterfaceDeviceModem::ModemCapabilities QNetworkManagerInterfaceDeviceModem::modemCapabilities() const
     894{
     895    if (propertyMap.contains("ModemCapabilities"))
     896        return static_cast<QNetworkManagerInterfaceDeviceModem::ModemCapabilities>(propertyMap.value("ModemCapabilities").toUInt());
     897    return QNetworkManagerInterfaceDeviceModem::None;
     898}
     899
     900QNetworkManagerInterfaceDeviceModem::ModemCapabilities QNetworkManagerInterfaceDeviceModem::currentCapabilities() const
     901{
     902    if (propertyMap.contains("CurrentCapabilities"))
     903        return static_cast<QNetworkManagerInterfaceDeviceModem::ModemCapabilities>(propertyMap.value("CurrentCapabilities").toUInt());
     904    return QNetworkManagerInterfaceDeviceModem::None;
     905}
     906
     907void QNetworkManagerInterfaceDeviceModem::propertiesSwap(QMap<QString,QVariant> map)
     908{
     909    QMapIterator<QString, QVariant> i(map);
     910    while (i.hasNext()) {
     911        i.next();
     912        propertyMap.insert(i.key(),i.value());
     913    }
     914    Q_EMIT propertiesChanged(map);
    578915}
    579916
    580917class QNetworkManagerSettingsPrivate
     
    598935        d->valid = false;
    599936        return;
    600937    }
     938
     939    QDBusPendingReply<QList <QDBusObjectPath> > nmReply
     940            = d->connectionInterface->call(QLatin1String("ListConnections"));
     941
     942    if (!nmReply.isError()) {
     943        connectionsList = nmReply.value();
     944    }
     945
    601946    d->valid = true;
    602947}
    603948
     
    614959
    615960bool QNetworkManagerSettings::setConnections()
    616961{
    617     bool allOk = false;
     962    bool allOk = true;
    618963
    619     if (!QDBusConnection::systemBus().connect(d->path, QLatin1String(NM_DBUS_PATH_SETTINGS),
    620                            QLatin1String(NM_DBUS_IFACE_SETTINGS), QLatin1String("NewConnection"),
    621                            this, SIGNAL(newConnection(QDBusObjectPath)))) {
    622         allOk = true;
     964    if (!QDBusConnection::systemBus().connect(d->path,
     965                                             QLatin1String(NM_DBUS_PATH_SETTINGS),
     966                                             QLatin1String(NM_DBUS_IFACE_SETTINGS),
     967                                             QLatin1String("NewConnection"),
     968                                             this, SIGNAL(newConnection(QDBusObjectPath)))) {
     969        allOk = false;
    623970    }
    624971
    625972    return allOk;
     
    627974
    628975QList <QDBusObjectPath> QNetworkManagerSettings::listConnections()
    629976{
    630     QDBusReply<QList<QDBusObjectPath> > reply = d->connectionInterface->call(QLatin1String("ListConnections"));
    631     return  reply.value();
     977    if (connectionsList.isEmpty()) {
     978        qWarning() << "Using blocking call!";
     979        QDBusReply<QList<QDBusObjectPath> > reply
     980                = d->connectionInterface->call(QLatin1String("ListConnections"));
     981        connectionsList = reply.value();
     982    }
     983    return connectionsList;
     984}
     985
     986
     987QString QNetworkManagerSettings::getConnectionByUuid(const QString &uuid)
     988{
     989    QList<QVariant> argumentList;
     990    argumentList << QVariant::fromValue(uuid);
     991    QDBusReply<QDBusObjectPath > reply = d->connectionInterface->callWithArgumentList(QDBus::Block,QLatin1String("GetConnectionByUuid"), argumentList);
     992    return reply.value().path();
    632993}
    633994
    634995QDBusInterface *QNetworkManagerSettings::connectionInterface() const
     
    6481009};
    6491010
    6501011QNetworkManagerSettingsConnection::QNetworkManagerSettingsConnection(const QString &settingsService, const QString &connectionObjectPath, QObject *parent)
    651     : QObject(parent), nmDBusHelper(0)
     1012    : QObject(parent)
    6521013{
    6531014    qDBusRegisterMetaType<QNmSettingsMap>();
    6541015    d = new QNetworkManagerSettingsConnectionPrivate();
     
    6631024        return;
    6641025    }
    6651026    d->valid = true;
    666     QDBusReply< QNmSettingsMap > rep = d->connectionInterface->call(QLatin1String("GetSettings"));
    667     d->settingsMap = rep.value();
     1027
     1028    QDBusPendingReply<QNmSettingsMap> nmReply
     1029            = d->connectionInterface->call(QLatin1String("GetSettings"));
     1030    if (!nmReply.isError()) {
     1031        d->settingsMap = nmReply.value();
     1032    }
    6681033}
    6691034
    6701035QNetworkManagerSettingsConnection::~QNetworkManagerSettingsConnection()
     
    6801045
    6811046bool QNetworkManagerSettingsConnection::setConnections()
    6821047{
    683     if(!isValid() )
     1048    if (!isValid())
    6841049        return false;
    6851050
    6861051    QDBusConnection dbusConnection = QDBusConnection::systemBus();
    687     bool allOk = false;
    688     if(!dbusConnection.connect(d->service, d->path,
    689                            QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION), QLatin1String("Updated"),
    690                            this, SIGNAL(updated(QNmSettingsMap)))) {
    691         allOk = true;
    692     } else {
    693         QDBusError error = dbusConnection.lastError();
     1052    bool allOk = true;
     1053    if (!dbusConnection.connect(d->service,
     1054                               d->path,
     1055                               QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION),
     1056                               QLatin1String("Updated"),
     1057                               this, SIGNAL(updated()))) {
     1058        allOk = false;
    6941059    }
    6951060
    696     delete nmDBusHelper;
    697     nmDBusHelper = new QNmDBusHelper(this);
    698     connect(nmDBusHelper, SIGNAL(pathForSettingsRemoved(QString)),
    699             this,SIGNAL(removed(QString)));
    700 
    701     if (!dbusConnection.connect(d->service, d->path,
    702                            QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION), QLatin1String("Removed"),
    703                            nmDBusHelper, SIGNAL(slotSettingsRemoved()))) {
    704         allOk = true;
     1061    if (!dbusConnection.connect(d->service,
     1062                               d->path,
     1063                               QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION),
     1064                               QLatin1String("Removed"),
     1065                               this, SIGNAL(slotSettingsRemoved()))) {
     1066        allOk = false;
    7051067    }
    706 
    7071068    return allOk;
    7081069}
    7091070
     1071void QNetworkManagerSettingsConnection::slotSettingsRemoved()
     1072{
     1073    Q_EMIT removed(d->path);
     1074}
     1075
    7101076QDBusInterface *QNetworkManagerSettingsConnection::connectionInterface() const
    7111077{
    7121078    return d->connectionInterface;
     
    7141080
    7151081QNmSettingsMap QNetworkManagerSettingsConnection::getSettings()
    7161082{
    717     QDBusReply< QNmSettingsMap > rep = d->connectionInterface->call(QLatin1String("GetSettings"));
    718     d->settingsMap = rep.value();
     1083    if (d->settingsMap.isEmpty()) {
     1084        qWarning() << "Using blocking call!";
     1085        QDBusReply<QNmSettingsMap> reply = d->connectionInterface->call(QLatin1String("GetSettings"));
     1086        d->settingsMap = reply.value();
     1087    }
    7191088    return d->settingsMap;
    7201089}
    7211090
     
    7251094        d->settingsMap.value(QLatin1String("connection")).value(QLatin1String("type")).toString();
    7261095
    7271096    if (devType == QLatin1String("802-3-ethernet"))
    728         return DEVICE_TYPE_802_3_ETHERNET;
     1097        return DEVICE_TYPE_ETHERNET;
    7291098    else if (devType == QLatin1String("802-11-wireless"))
    730         return DEVICE_TYPE_802_11_WIRELESS;
     1099        return DEVICE_TYPE_WIFI;
     1100    else if (devType == QLatin1String("gsm"))
     1101        return DEVICE_TYPE_MODEM;
    7311102    else
    7321103        return DEVICE_TYPE_UNKNOWN;
    7331104}
     
    7741145{
    7751146    NMDeviceType type = getType();
    7761147
    777     if (type == DEVICE_TYPE_802_3_ETHERNET) {
     1148    if (type == DEVICE_TYPE_ETHERNET) {
    7781149        return d->settingsMap.value(QLatin1String("802-3-ethernet"))
    7791150                             .value(QLatin1String("mac-address")).toString();
    780     } else if (type == DEVICE_TYPE_802_11_WIRELESS) {
     1151    } else if (type == DEVICE_TYPE_WIFI) {
    7811152        return d->settingsMap.value(QLatin1String("802-11-wireless"))
    7821153                             .value(QLatin1String("mac-address")).toString();
    7831154    } else {
     
    7871158
    7881159QStringList QNetworkManagerSettingsConnection::getSeenBssids()
    7891160{
    790     if (getType() == DEVICE_TYPE_802_11_WIRELESS) {
     1161    if (getType() == DEVICE_TYPE_WIFI) {
    7911162        return d->settingsMap.value(QLatin1String("802-11-wireless"))
    7921163                             .value(QLatin1String("seen-bssids")).toStringList();
    7931164    } else {
     
    8031174    bool valid;
    8041175};
    8051176
    806 QNetworkManagerConnectionActive::QNetworkManagerConnectionActive( const QString &activeConnectionObjectPath, QObject *parent)
    807     : QObject(parent), nmDBusHelper(0)
     1177QNetworkManagerConnectionActive::QNetworkManagerConnectionActive(const QString &activeConnectionObjectPath, QObject *parent)
     1178    : QObject(parent)
    8081179{
    8091180    d = new QNetworkManagerConnectionActivePrivate();
    8101181    d->path = activeConnectionObjectPath;
     
    8161187        d->valid = false;
    8171188        return;
    8181189    }
     1190    QDBusInterface connectionActivePropertiesInterface(QLatin1String(NM_DBUS_SERVICE),
     1191                                                  d->path,
     1192                                                  QLatin1String("org.freedesktop.DBus.Properties"),
     1193                                                  QDBusConnection::systemBus());
     1194
     1195
     1196    QList<QVariant> argumentList;
     1197    argumentList << QLatin1String(NM_DBUS_INTERFACE_ACTIVE_CONNECTION);
     1198    QDBusPendingReply<QVariantMap> propsReply
     1199            = connectionActivePropertiesInterface.callWithArgumentList(QDBus::Block,QLatin1String("GetAll"),
     1200                                                                       argumentList);
     1201
     1202    if (!propsReply.isError()) {
     1203        propertyMap = propsReply.value();
     1204    } else {
     1205        qWarning() << propsReply.error().message();
     1206    }
     1207
     1208    QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE),
     1209                                  d->path,
     1210                                  QLatin1String(NM_DBUS_INTERFACE_ACTIVE_CONNECTION),
     1211                                  QLatin1String("PropertiesChanged"),
     1212                                  this,SLOT(propertiesSwap(QMap<QString,QVariant>)));
    8191213    d->valid = true;
    8201214}
    8211215
     
    8321226
    8331227bool QNetworkManagerConnectionActive::setConnections()
    8341228{
    835     if(!isValid() )
     1229    if (!isValid())
    8361230        return false;
    8371231
    838     bool allOk = false;
    839     delete nmDBusHelper;
    840     nmDBusHelper = new QNmDBusHelper(this);
    841     connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(QString,QMap<QString,QVariant>)),
    842             this,SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>)));
    843     if (QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE),
    844                               d->path,
    845                               QLatin1String(NM_DBUS_INTERFACE_ACTIVE_CONNECTION),
    846                               QLatin1String("PropertiesChanged"),
    847                               nmDBusHelper,SLOT(slotPropertiesChanged(QMap<QString,QVariant>))) )  {
    848         allOk = true;
    849     }
    850 
    851     return allOk;
     1232    return true;
    8521233}
    8531234
    8541235QDBusInterface *QNetworkManagerConnectionActive::connectionInterface() const
     
    8561237    return d->connectionInterface;
    8571238}
    8581239
    859 QString QNetworkManagerConnectionActive::serviceName() const
    860 {
    861     return d->connectionInterface->property("ServiceName").toString();
    862 }
    863 
    8641240QDBusObjectPath QNetworkManagerConnectionActive::connection() const
    8651241{
    866     QVariant prop = d->connectionInterface->property("Connection");
    867     return prop.value<QDBusObjectPath>();
     1242    if (propertyMap.contains("Connection"))
     1243        return propertyMap.value("Connection").value<QDBusObjectPath>();
     1244    return QDBusObjectPath();
    8681245}
    8691246
    8701247QDBusObjectPath QNetworkManagerConnectionActive::specificObject() const
    8711248{
    872     QVariant prop = d->connectionInterface->property("SpecificObject");
    873     return prop.value<QDBusObjectPath>();
    874 }
    875 
    876 QList<QDBusObjectPath> QNetworkManagerConnectionActive::devices() const
    877 {
    878     QVariant prop = d->connectionInterface->property("Devices");
    879     return prop.value<QList<QDBusObjectPath> >();
     1249    if (propertyMap.contains("SpecificObject"))
     1250        return propertyMap.value("SpecificObject").value<QDBusObjectPath>();
     1251    return QDBusObjectPath();
     1252}
     1253
     1254QStringList QNetworkManagerConnectionActive::devices() const
     1255{
     1256    QStringList list;
     1257    if (propertyMap.contains("Devices")) {
     1258        const QDBusArgument &dbusArgs = propertyMap.value("Devices").value<QDBusArgument>();
     1259        QDBusObjectPath path;
     1260
     1261        dbusArgs.beginArray();
     1262        while (!dbusArgs.atEnd()) {
     1263            dbusArgs >> path;
     1264            list.append(path.path());
     1265        }
     1266        dbusArgs.endArray();
     1267    }
     1268    return list;
    8801269}
    8811270
    8821271quint32 QNetworkManagerConnectionActive::state() const
    8831272{
    884     return d->connectionInterface->property("State").toUInt();
     1273    if (propertyMap.contains("State"))
     1274        return propertyMap.value("State").toUInt();
     1275    return 0;
    8851276}
    8861277
    8871278bool QNetworkManagerConnectionActive::defaultRoute() const
    8881279{
    889     return d->connectionInterface->property("Default").toBool();
     1280    if (propertyMap.contains("Default"))
     1281        return propertyMap.value("Default").toBool();
     1282    return false;
     1283}
     1284
     1285bool QNetworkManagerConnectionActive::default6Route() const
     1286{
     1287    if (propertyMap.contains("Default6"))
     1288        return propertyMap.value("Default6").toBool();
     1289    return false;
     1290}
     1291
     1292void QNetworkManagerConnectionActive::propertiesSwap(QMap<QString,QVariant> map)
     1293{
     1294    QMapIterator<QString, QVariant> i(map);
     1295    while (i.hasNext()) {
     1296        i.next();
     1297        propertyMap.insert(i.key(),i.value());
     1298        if (i.key() == QStringLiteral("State")) {
     1299            quint32 state = i.value().toUInt();
     1300            if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED
     1301                || state == NM_ACTIVE_CONNECTION_STATE_DEACTIVATED) {
     1302                Q_EMIT propertiesChanged(map);
     1303            }
     1304        }
     1305    }
    8901306}
    8911307
    8921308class QNetworkManagerIp4ConfigPrivate
  • qtbase/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h

     
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
     3** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
    44** Contact: http://www.qt-project.org/legal
    55**
    66** This file is part of the plugins of the Qt Toolkit.
    77**
    8 ** $QT_BEGIN_LICENSE:LGPL$
     8** $QT_BEGIN_LICENSE:LGPL21$
    99** Commercial License Usage
    1010** Licensees holding valid commercial Qt licenses may use this file in
    1111** accordance with the commercial license agreement provided with the
    1212** Software or, alternatively, in accordance with the terms contained in
    13 ** a written agreement between you and Digia.  For licensing terms and
    14 ** conditions see http://qt.digia.com/licensing.  For further information
     13** a written agreement between you and Digia. For licensing terms and
     14** conditions see http://qt.digia.com/licensing. For further information
    1515** use the contact form at http://qt.digia.com/contact-us.
    1616**
    1717** GNU Lesser General Public License Usage
    1818** Alternatively, this file may be used under the terms of the GNU Lesser
    19 ** General Public License version 2.1 as published by the Free Software
    20 ** Foundation and appearing in the file LICENSE.LGPL included in the
    21 ** packaging of this file.  Please review the following information to
    22 ** ensure the GNU Lesser General Public License version 2.1 requirements
    23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
     19** General Public License version 2.1 or version 3 as published by the Free
     20** Software Foundation and appearing in the file LICENSE.LGPLv21 and
     21** LICENSE.LGPLv3 included in the packaging of this file. Please review the
     22** following information to ensure the GNU Lesser General Public License
     23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
     24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2425**
    2526** In addition, as a special exception, Digia gives you certain additional
    26 ** rights.  These rights are described in the Digia Qt LGPL Exception
     27** rights. These rights are described in the Digia Qt LGPL Exception
    2728** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2829**
    29 ** GNU General Public License Usage
    30 ** Alternatively, this file may be used under the terms of the GNU
    31 ** General Public License version 3.0 as published by the Free Software
    32 ** Foundation and appearing in the file LICENSE.GPL included in the
    33 ** packaging of this file.  Please review the following information to
    34 ** ensure the GNU General Public License version 3.0 requirements will be
    35 ** met: http://www.gnu.org/copyleft/gpl.html.
    36 **
    37 **
    3830** $QT_END_LICENSE$
    3931**
    4032****************************************************************************/
     
    6456#include <QtDBus/QDBusObjectPath>
    6557#include <QtDBus/QDBusContext>
    6658#include <QMap>
    67 #include "qnmdbushelper.h"
    6859
    6960#ifndef QT_NO_DBUS
    7061
     
    7263typedef enum NMDeviceType
    7364{
    7465    DEVICE_TYPE_UNKNOWN = 0,
    75     DEVICE_TYPE_802_3_ETHERNET,
    76     DEVICE_TYPE_802_11_WIRELESS,
    77     DEVICE_TYPE_GSM,
    78     DEVICE_TYPE_CDMA
     66    DEVICE_TYPE_ETHERNET,
     67    DEVICE_TYPE_WIFI,
     68    DEVICE_TYPE_MODEM = 8
    7969} NMDeviceType;
    8070
    8171typedef enum
    8272{
    8373    NM_DEVICE_STATE_UNKNOWN = 0,
    84     NM_DEVICE_STATE_UNMANAGED,
    85     NM_DEVICE_STATE_UNAVAILABLE,
    86     NM_DEVICE_STATE_DISCONNECTED,
    87     NM_DEVICE_STATE_PREPARE,
    88     NM_DEVICE_STATE_CONFIG,
    89     NM_DEVICE_STATE_NEED_AUTH,
    90     NM_DEVICE_STATE_IP_CONFIG,
    91     NM_DEVICE_STATE_ACTIVATED,
    92     NM_DEVICE_STATE_FAILED
     74    NM_DEVICE_STATE_UNMANAGED = 10,
     75    NM_DEVICE_STATE_UNAVAILABLE = 20,
     76    NM_DEVICE_STATE_DISCONNECTED = 30,
     77    NM_DEVICE_STATE_PREPARE = 40,
     78    NM_DEVICE_STATE_CONFIG = 50,
     79    NM_DEVICE_STATE_NEED_AUTH = 60,
     80    NM_DEVICE_STATE_IP_CONFIG = 70,
     81    NM_DEVICE_STATE_ACTIVATED = 100,
     82    NM_DEVICE_STATE_DEACTIVATING = 110,
     83    NM_DEVICE_STATE_FAILED = 120
    9384} NMDeviceState;
    9485
    9586typedef enum
    9687{
    9788    NM_ACTIVE_CONNECTION_STATE_UNKNOWN = 0,
    9889    NM_ACTIVE_CONNECTION_STATE_ACTIVATING,
    99     NM_ACTIVE_CONNECTION_STATE_ACTIVATED
     90    NM_ACTIVE_CONNECTION_STATE_ACTIVATED,
     91    NM_ACTIVE_CONNECTION_STATE_DEACTIVATED = 4
    10092} NMActiveConnectionState;
    10193
    10294#define NM_DBUS_SERVICE                     "org.freedesktop.NetworkManager"
     
    10698#define NM_DBUS_INTERFACE_DEVICE            NM_DBUS_INTERFACE ".Device"
    10799#define NM_DBUS_INTERFACE_DEVICE_WIRED      NM_DBUS_INTERFACE_DEVICE ".Wired"
    108100#define NM_DBUS_INTERFACE_DEVICE_WIRELESS   NM_DBUS_INTERFACE_DEVICE ".Wireless"
     101#define NM_DBUS_INTERFACE_DEVICE_MODEM      NM_DBUS_INTERFACE_DEVICE ".Modem"
    109102#define NM_DBUS_PATH_ACCESS_POINT           NM_DBUS_PATH "/AccessPoint"
    110103#define NM_DBUS_INTERFACE_ACCESS_POINT      NM_DBUS_INTERFACE ".AccessPoint"
    111104
    112 #define NM_DBUS_PATH_SETTINGS               "/org/freedesktop/NetworkManagerSettings"
     105#define NM_DBUS_PATH_SETTINGS               "/org/freedesktop/NetworkManager/Settings"
    113106
    114 #define NM_DBUS_IFACE_SETTINGS_CONNECTION   "org.freedesktop.NetworkManagerSettings.Connection"
    115 #define NM_DBUS_IFACE_SETTINGS              "org.freedesktop.NetworkManagerSettings"
     107#define NM_DBUS_IFACE_SETTINGS_CONNECTION   "org.freedesktop.NetworkManager.Settings.Connection"
     108#define NM_DBUS_IFACE_SETTINGS              "org.freedesktop.NetworkManager.Settings"
    116109#define NM_DBUS_INTERFACE_ACTIVE_CONNECTION NM_DBUS_INTERFACE ".Connection.Active"
    117110#define NM_DBUS_INTERFACE_IP4_CONFIG        NM_DBUS_INTERFACE ".IP4Config"
    118111
     
    141134    Q_OBJECT
    142135
    143136public:
     137    typedef enum
     138    {
     139        NM_STATE_UNKNOWN = 0,
     140        NM_STATE_ASLEEP = 10,
     141        NM_STATE_DISCONNECTED = 20,
     142        NM_STATE_DISCONNECTING = 30,
     143        NM_STATE_CONNECTING = 40,
     144        NM_STATE_CONNECTED_LOCAL = 50,
     145        NM_STATE_CONNECTED_SITE = 60,
     146        NM_STATE_CONNECTED_GLOBAL = 70
     147    } NMState;
    144148
    145149    QNetworkManagerInterface(QObject *parent = 0);
    146150    ~QNetworkManagerInterface();
    147151
    148     QList <QDBusObjectPath> getDevices() const;
    149     void activateConnection(const QString &serviceName, QDBusObjectPath connection, QDBusObjectPath device, QDBusObjectPath specificObject);
     152    QList <QDBusObjectPath> getDevices();
     153    void activateConnection(QDBusObjectPath connection,QDBusObjectPath device, QDBusObjectPath specificObject);
    150154    void deactivateConnection(QDBusObjectPath connectionPath) const;
    151155
    152156    QDBusObjectPath path() const;
     
    155159    bool wirelessEnabled() const;
    156160    bool wirelessHardwareEnabled() const;
    157161    QList <QDBusObjectPath> activeConnections() const;
    158     quint32 state();
     162    NMState state();
     163    QString version() const;
    159164    bool setConnections();
    160165    bool isValid();
    161166
    162167Q_SIGNALS:
    163168    void deviceAdded(QDBusObjectPath);
    164169    void deviceRemoved(QDBusObjectPath);
    165     void propertiesChanged( const QString &, QMap<QString,QVariant>);
    166     void stateChanged(const QString&, quint32);
     170    void propertiesChanged(QMap<QString,QVariant>);
     171    void stateChanged(quint32);
    167172    void activationFinished(QDBusPendingCallWatcher*);
     173    void propertiesReady();
     174    void devicesListReady();
    168175
    169176private Q_SLOTS:
     177    void propertiesSwap(QMap<QString,QVariant>);
     178
    170179private:
    171180    QNetworkManagerInterfacePrivate *d;
    172     QNmDBusHelper *nmDBusHelper;
     181    QVariantMap propertyMap;
     182    QList<QDBusObjectPath> devicesPathList;
     183
    173184};
    174185
    175186class QNetworkManagerInterfaceAccessPointPrivate;
     
    234245
    235246Q_SIGNALS:
    236247    void propertiesChanged(QMap <QString,QVariant>);
    237     void propertiesChanged( const QString &, QMap<QString,QVariant>);
     248    void propertiesReady();
     249
     250private Q_SLOTS:
     251    void propertiesSwap(QMap<QString,QVariant>);
     252
    238253private:
    239254    QNetworkManagerInterfaceAccessPointPrivate *d;
    240     QNmDBusHelper *nmDBusHelper;
    241 
     255    QVariantMap propertyMap;
    242256};
    243257
    244258class QNetworkManagerInterfaceDevicePrivate;
     
    264278
    265279Q_SIGNALS:
    266280    void stateChanged(const QString &, quint32);
    267 
     281    void propertiesChanged(QMap<QString,QVariant>);
     282    void connectionsChanged(QStringList);
     283    void propertiesReady();
     284private Q_SLOTS:
     285    void propertiesSwap(QMap<QString,QVariant>);
    268286private:
    269287    QNetworkManagerInterfaceDevicePrivate *d;
    270     QNmDBusHelper *nmDBusHelper;
     288    QVariantMap propertyMap;
    271289};
    272290
    273291class QNetworkManagerInterfaceDeviceWiredPrivate;
     
    287305    bool carrier() const;
    288306    bool setConnections();
    289307    bool isValid();
     308    QStringList availableConnections();
    290309
    291310Q_SIGNALS:
    292     void propertiesChanged( const QString &, QMap<QString,QVariant>);
     311    void propertiesChanged(QMap<QString,QVariant>);
     312    void propertiesReady();
     313    void carrierChanged(bool);
     314
     315private Q_SLOTS:
     316    void propertiesSwap(QMap<QString,QVariant>);
     317
    293318private:
    294319    QNetworkManagerInterfaceDeviceWiredPrivate *d;
    295     QNmDBusHelper *nmDBusHelper;
     320    QVariantMap propertyMap;
    296321};
    297322
    298323class QNetworkManagerInterfaceDeviceWirelessPrivate;
     
    328353    bool setConnections();
    329354    bool isValid();
    330355
     356    void requestScan();
    331357Q_SIGNALS:
    332     void propertiesChanged( const QString &, QMap<QString,QVariant>);
    333     void accessPointAdded(const QString &,QDBusObjectPath);
    334     void accessPointRemoved(const QString &,QDBusObjectPath);
     358    void propertiesChanged(QMap<QString,QVariant>);
     359    void accessPointAdded(const QString &);
     360    void accessPointRemoved(const QString &);
     361    void scanDone();
     362    void propertiesReady();
     363    void accessPointsReady();
     364
     365private Q_SLOTS:
     366    void scanIsDone();
     367    void propertiesSwap(QMap<QString,QVariant>);
     368
     369    void slotAccessPointAdded(QDBusObjectPath);
     370    void slotAccessPointRemoved(QDBusObjectPath);
     371
    335372private:
    336373    QNetworkManagerInterfaceDeviceWirelessPrivate *d;
    337     QNmDBusHelper *nmDBusHelper;
     374    QVariantMap propertyMap;
     375    QList <QDBusObjectPath> accessPointsList;
     376};
     377
     378class QNetworkManagerInterfaceDeviceModemPrivate;
     379class QNetworkManagerInterfaceDeviceModem : public QObject
     380{
     381    Q_OBJECT
     382
     383public:
     384
     385    enum ModemCapability {
     386        None = 0x0,
     387        Pots = 0x1,
     388        Cmda_Edvo = 0x2,
     389        Gsm_Umts = 0x4,
     390        Lte = 0x08
     391       };
     392    Q_DECLARE_FLAGS(ModemCapabilities, ModemCapability)
     393
     394    explicit QNetworkManagerInterfaceDeviceModem(const QString &ifaceDevicePath,
     395                                                    QObject *parent = 0);
     396    ~QNetworkManagerInterfaceDeviceModem();
     397
     398    QDBusObjectPath path() const;
     399    QDBusInterface *connectionInterface() const;
     400
     401    bool setConnections();
     402    bool isValid();
     403
     404    ModemCapabilities modemCapabilities() const;
     405    ModemCapabilities currentCapabilities() const;
     406
     407Q_SIGNALS:
     408    void propertiesChanged(QMap<QString,QVariant>);
     409    void propertiesReady();
     410
     411private Q_SLOTS:
     412    void propertiesSwap(QMap<QString,QVariant>);
     413
     414private:
     415    QNetworkManagerInterfaceDeviceModemPrivate *d;
     416    QVariantMap propertyMap;
    338417};
    339418
     419Q_DECLARE_OPERATORS_FOR_FLAGS(QNetworkManagerInterfaceDeviceModem::ModemCapabilities)
     420
    340421class QNetworkManagerSettingsPrivate;
    341422class QNetworkManagerSettings : public QObject
    342423{
     
    349430
    350431    QDBusInterface  *connectionInterface() const;
    351432    QList <QDBusObjectPath> listConnections();
     433    QString getConnectionByUuid(const QString &uuid);
    352434    bool setConnections();
    353435    bool isValid();
    354436
    355437Q_SIGNALS:
    356438    void newConnection(QDBusObjectPath);
     439    void connectionsListReady();
    357440private:
    358441    QNetworkManagerSettingsPrivate *d;
     442    QList <QDBusObjectPath> connectionsList;
    359443};
    360444
    361445class QNetworkManagerSettingsConnectionPrivate;
     
    382466    bool isValid();
    383467
    384468Q_SIGNALS:
    385 
    386     void updated(const QNmSettingsMap &settings);
     469    void updated();
    387470    void removed(const QString &path);
     471    void settingsReady();
     472
     473private Q_SLOTS:
     474    void slotSettingsRemoved();
    388475
    389476private:
    390     QNmDBusHelper *nmDBusHelper;
    391477    QNetworkManagerSettingsConnectionPrivate *d;
    392478};
    393479
     
    408494    ~ QNetworkManagerConnectionActive();
    409495
    410496    QDBusInterface  *connectionInterface() const;
    411     QString serviceName() const;
    412497    QDBusObjectPath connection() const;
    413498    QDBusObjectPath specificObject() const;
    414     QList<QDBusObjectPath> devices() const;
     499    QStringList devices() const;
    415500    quint32 state() const;
    416501    bool defaultRoute() const;
     502    bool default6Route() const;
    417503    bool setConnections();
    418504    bool isValid();
    419505
    420506
    421507Q_SIGNALS:
    422     void propertiesChanged(QList<QDBusObjectPath>);
    423     void propertiesChanged( const QString &, QMap<QString,QVariant>);
     508    void propertiesChanged(QMap<QString,QVariant>);
     509    void propertiesReady();
     510
     511private Q_SLOTS:
     512    void propertiesSwap(QMap<QString,QVariant>);
     513
    424514private:
    425515    QNetworkManagerConnectionActivePrivate *d;
    426     QNmDBusHelper *nmDBusHelper;
     516    QVariantMap propertyMap;
    427517};
    428518
    429519class QNetworkManagerIp4ConfigPrivate;
  • deleted file qtbase/src/plugins/bearer/networkmanager/qnmdbushelper.cpp

    + -  
    1 /****************************************************************************
    2 **
    3 ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
    4 ** Contact: http://www.qt-project.org/legal
    5 **
    6 ** This file is part of the plugins of the Qt Toolkit.
    7 **
    8 ** $QT_BEGIN_LICENSE:LGPL$
    9 ** Commercial License Usage
    10 ** Licensees holding valid commercial Qt licenses may use this file in
    11 ** accordance with the commercial license agreement provided with the
    12 ** Software or, alternatively, in accordance with the terms contained in
    13 ** a written agreement between you and Digia.  For licensing terms and
    14 ** conditions see http://qt.digia.com/licensing.  For further information
    15 ** use the contact form at http://qt.digia.com/contact-us.
    16 **
    17 ** GNU Lesser General Public License Usage
    18 ** Alternatively, this file may be used under the terms of the GNU Lesser
    19 ** General Public License version 2.1 as published by the Free Software
    20 ** Foundation and appearing in the file LICENSE.LGPL included in the
    21 ** packaging of this file.  Please review the following information to
    22 ** ensure the GNU Lesser General Public License version 2.1 requirements
    23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    24 **
    25 ** In addition, as a special exception, Digia gives you certain additional
    26 ** rights.  These rights are described in the Digia Qt LGPL Exception
    27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    28 **
    29 ** GNU General Public License Usage
    30 ** Alternatively, this file may be used under the terms of the GNU
    31 ** General Public License version 3.0 as published by the Free Software
    32 ** Foundation and appearing in the file LICENSE.GPL included in the
    33 ** packaging of this file.  Please review the following information to
    34 ** ensure the GNU General Public License version 3.0 requirements will be
    35 ** met: http://www.gnu.org/copyleft/gpl.html.
    36 **
    37 **
    38 ** $QT_END_LICENSE$
    39 **
    40 ****************************************************************************/
    41 
    42 // this class is for helping qdbus get stuff
    43 
    44 #include "qnmdbushelper.h"
    45 
    46 #include "qnetworkmanagerservice.h"
    47 
    48 #include <QDBusError>
    49 #include <QDBusInterface>
    50 #include <QDBusMessage>
    51 #include <QDBusReply>
    52 
    53 #include <QDebug>
    54 
    55 #ifndef QT_NO_DBUS
    56 
    57 QT_BEGIN_NAMESPACE
    58 
    59 QNmDBusHelper::QNmDBusHelper(QObject * parent)
    60         : QObject(parent)
    61 {
    62 }
    63 
    64 QNmDBusHelper::~QNmDBusHelper()
    65 {
    66 }
    67 
    68 void QNmDBusHelper::deviceStateChanged(quint32 state)
    69  {
    70     QDBusMessage msg = this->message();
    71     if(state == NM_DEVICE_STATE_ACTIVATED
    72        || state == NM_DEVICE_STATE_DISCONNECTED
    73        || state == NM_DEVICE_STATE_UNAVAILABLE
    74        || state == NM_DEVICE_STATE_FAILED) {
    75         emit pathForStateChanged(msg.path(), state);
    76     }
    77  }
    78 
    79 void QNmDBusHelper::slotAccessPointAdded(QDBusObjectPath path)
    80 {
    81     if(path.path().length() > 2) {
    82         QDBusMessage msg = this->message();
    83         emit pathForAccessPointAdded(msg.path(), path);
    84     }
    85 }
    86 
    87 void QNmDBusHelper::slotAccessPointRemoved(QDBusObjectPath path)
    88 {
    89     if(path.path().length() > 2) {
    90         QDBusMessage msg = this->message();
    91         emit pathForAccessPointRemoved(msg.path(), path);
    92     }
    93 }
    94 
    95 void QNmDBusHelper::slotPropertiesChanged(QMap<QString,QVariant> map)
    96 {
    97     QDBusMessage msg = this->message();
    98     QMapIterator<QString, QVariant> i(map);
    99     while (i.hasNext()) {
    100         i.next();
    101         if( i.key() == "State") { //state only applies to device interfaces
    102             quint32 state = i.value().toUInt();
    103             if( state == NM_DEVICE_STATE_ACTIVATED
    104                 || state == NM_DEVICE_STATE_DISCONNECTED
    105                 || state == NM_DEVICE_STATE_UNAVAILABLE
    106                 || state == NM_DEVICE_STATE_FAILED) {
    107                 emit  pathForPropertiesChanged( msg.path(), map);
    108             }
    109         } else if( i.key() == "ActiveAccessPoint") {
    110             emit pathForPropertiesChanged(msg.path(), map);
    111             //            qWarning()  << __PRETTY_FUNCTION__ << i.key() << ": " << i.value().value<QDBusObjectPath>().path();
    112             //      } else if( i.key() == "Strength")
    113             //            qWarning()  << __PRETTY_FUNCTION__ << i.key() << ": " << i.value().toUInt();
    114             //   else
    115             //            qWarning()  << __PRETTY_FUNCTION__ << i.key() << ": " << i.value();
    116         } else if (i.key() == "ActiveConnections") {
    117             emit pathForPropertiesChanged(msg.path(), map);
    118         }
    119     }
    120 }
    121 
    122 void QNmDBusHelper::slotSettingsRemoved()
    123 {
    124     QDBusMessage msg = this->message();
    125     emit pathForSettingsRemoved(msg.path());
    126 }
    127 
    128 QT_END_NAMESPACE
    129 
    130 #endif // QT_NO_DBUS
  • deleted file qtbase/src/plugins/bearer/networkmanager/qnmdbushelper.h

    + -  
    1 /****************************************************************************
    2 **
    3 ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
    4 ** Contact: http://www.qt-project.org/legal
    5 **
    6 ** This file is part of the plugins of the Qt Toolkit.
    7 **
    8 ** $QT_BEGIN_LICENSE:LGPL$
    9 ** Commercial License Usage
    10 ** Licensees holding valid commercial Qt licenses may use this file in
    11 ** accordance with the commercial license agreement provided with the
    12 ** Software or, alternatively, in accordance with the terms contained in
    13 ** a written agreement between you and Digia.  For licensing terms and
    14 ** conditions see http://qt.digia.com/licensing.  For further information
    15 ** use the contact form at http://qt.digia.com/contact-us.
    16 **
    17 ** GNU Lesser General Public License Usage
    18 ** Alternatively, this file may be used under the terms of the GNU Lesser
    19 ** General Public License version 2.1 as published by the Free Software
    20 ** Foundation and appearing in the file LICENSE.LGPL included in the
    21 ** packaging of this file.  Please review the following information to
    22 ** ensure the GNU Lesser General Public License version 2.1 requirements
    23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    24 **
    25 ** In addition, as a special exception, Digia gives you certain additional
    26 ** rights.  These rights are described in the Digia Qt LGPL Exception
    27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    28 **
    29 ** GNU General Public License Usage
    30 ** Alternatively, this file may be used under the terms of the GNU
    31 ** General Public License version 3.0 as published by the Free Software
    32 ** Foundation and appearing in the file LICENSE.GPL included in the
    33 ** packaging of this file.  Please review the following information to
    34 ** ensure the GNU General Public License version 3.0 requirements will be
    35 ** met: http://www.gnu.org/copyleft/gpl.html.
    36 **
    37 **
    38 ** $QT_END_LICENSE$
    39 **
    40 ****************************************************************************/
    41 
    42 #ifndef QNMDBUSHELPERPRIVATE_H
    43 #define QNMDBUSHELPERPRIVATE_H
    44 
    45 #include <QDBusObjectPath>
    46 #include <QDBusContext>
    47 #include <QMap>
    48 
    49 #ifndef QT_NO_DBUS
    50 
    51 QT_BEGIN_NAMESPACE
    52 
    53 class QNmDBusHelper: public QObject, protected QDBusContext
    54  {
    55      Q_OBJECT
    56  public:
    57     QNmDBusHelper(QObject *parent = 0);
    58     ~QNmDBusHelper();
    59 
    60  public slots:
    61     void deviceStateChanged(quint32);
    62     void slotAccessPointAdded( QDBusObjectPath );
    63     void slotAccessPointRemoved( QDBusObjectPath );
    64     void slotPropertiesChanged( QMap<QString,QVariant>);
    65     void slotSettingsRemoved();
    66 
    67 Q_SIGNALS:
    68     void pathForStateChanged(const QString &, quint32);
    69     void pathForAccessPointAdded(const QString &,  QDBusObjectPath );
    70     void pathForAccessPointRemoved(const QString &,  QDBusObjectPath );
    71     void pathForPropertiesChanged(const QString &, QMap<QString,QVariant>);
    72     void pathForSettingsRemoved(const QString &);
    73 };
    74 
    75 QT_END_NAMESPACE
    76 
    77 #endif // QT_NO_DBUS
    78 
    79 #endif// QNMDBUSHELPERPRIVATE_H