I have made the following changes intended for :
  CE:MW:Shared / connman-qt

Please review and accept or decline.
BOSS has already run some checks on this request.
See the "Messages from BOSS" section below.

https://build.pub.meego.com//request/show/7489

Thank You,
rojkov

[This message was auto-generated]

---

Request # 7489:

Messages from BOSS:

State: review at 2012-12-03T15:49:08 by bossbot

Reviews:
       accepted by bossbot : Prechecks succeeded.
       new for CE-maintainers : Please replace this text with a review and 
approve/reject the review (not the SR). BOSS will take care of the rest

Changes:
  submit: home:rojkov:branches:CE:MW:Shared / connman-qt -> CE:MW:Shared / 
connman-qt
  
changes files:
--------------
--- connman-qt.changes
+++ connman-qt.changes
@@ -0,0 +1,4 @@
+* Mon Dec 03 2012 Dmitry Rozhkov <[email protected]> - 0.3.1
+- Applied patch from Pascal Bach.
+- Initial refactoring of NetworkingModel.
+

old:
----
  connman-qt-0.3.0.tar.bz2

new:
----
  connman-qt-0.3.1.tar.bz2

spec files:
-----------
--- connman-qt.spec
+++ connman-qt.spec
@@ -9,7 +9,7 @@
 # << macros
 
 Summary:    qt bindings for connman
-Version:    0.3.0
+Version:    0.3.1
 Release:    1
 Group:      System/GUI/Other
 License:    Apache License

other changes:
--------------

++++++ connman-qt-0.3.0.tar.bz2 -> connman-qt-0.3.1.tar.bz2
--- libconnman-qt/networkmanager.cpp
+++ libconnman-qt/networkmanager.cpp
@@ -8,6 +8,7 @@
  *
  */
 
+#include "manager.h"
 #include "networkmanager.h"
 #include "debug.h"
 
--- libconnman-qt/networkmanager.h
+++ libconnman-qt/networkmanager.h
@@ -12,11 +12,12 @@
 #define NETWORKMANAGER_H
 
 #include "commondbustypes.h"
-#include "manager.h"
+
 #include "networktechnology.h"
 #include "networkservice.h"
 #include <QtDBus>
 
+class Manager;
 class NetworkManager;
 
 class NetworkManagerFactory
--- libconnman-qt/networkservice.cpp
+++ libconnman-qt/networkservice.cpp
@@ -8,6 +8,7 @@
  *
  */
 
+#include "service.h"
 #include "networkservice.h"
 #include "debug.h"
 
@@ -18,24 +19,29 @@
 const QString NetworkService::Strength("Strength");
 const QString NetworkService::Error("Error");
 const QString NetworkService::Favorite("Favorite");
+const QString NetworkService::AutoConnect("AutoConnect");
 const QString NetworkService::IPv4("IPv4");
 const QString NetworkService::IPv4Config("IPv4.Configuration");
+const QString NetworkService::IPv6("IPv6");
+const QString NetworkService::IPv6Config("IPv6.Configuration");
 const QString NetworkService::Nameservers("Nameservers");
 const QString NetworkService::NameserversConfig("Nameservers.Configuration");
 const QString NetworkService::Domains("Domains");
 const QString NetworkService::DomainsConfig("Domains.Configuration");
 const QString NetworkService::Proxy("Proxy");
 const QString NetworkService::ProxyConfig("Proxy.Configuration");
+const QString NetworkService::Ethernet("Ethernet");
 
 NetworkService::NetworkService(const QString &path, const QVariantMap 
&properties, QObject* parent)
   : QObject(parent),
-    m_service(NULL)
+    m_service(NULL),
+    m_path(path)
 {
-    Q_ASSERT(!path.isEmpty());
-    m_service = new Service("net.connman", path, QDBusConnection::systemBus(), 
this);
+    Q_ASSERT(!m_path.isEmpty());
+    m_service = new Service("net.connman", m_path, 
QDBusConnection::systemBus(), this);
 
     if (!m_service->isValid()) {
-        pr_dbg() << "Invalid service: " << path;
+        pr_dbg() << "Invalid service: " << m_path;
         throw -1; // FIXME
     }
 
@@ -65,14 +71,22 @@
     return m_propertiesCache.value(Security).toStringList();
 }
 
-const uint NetworkService::strength() const {
+uint NetworkService::strength() const {
     return m_propertiesCache.value(Strength).toUInt();
 }
 
-const bool NetworkService::favorite() const {
+bool NetworkService::favorite() const {
     return m_propertiesCache.value(Favorite).toBool();
 }
 
+bool NetworkService::autoConnect() const {
+    return m_propertiesCache.value(AutoConnect).toBool();
+}
+
+const QString NetworkService::path() const {
+    return m_path;
+}
+
 const QVariantMap NetworkService::ipv4() const {
     return qdbus_cast<QVariantMap>(m_propertiesCache.value(IPv4));
 }
@@ -81,6 +95,14 @@
     return qdbus_cast<QVariantMap>(m_propertiesCache.value(IPv4Config));
 }
 
+const QVariantMap NetworkService::ipv6() const {
+    return qdbus_cast<QVariantMap>(m_propertiesCache.value(IPv6));
+}
+
+const QVariantMap NetworkService::ipv6Config() const {
+    return qdbus_cast<QVariantMap>(m_propertiesCache.value(IPv6Config));
+}
+
 const QStringList NetworkService::nameservers() const {
     return m_propertiesCache.value(Nameservers).toStringList();
 }
@@ -105,6 +127,10 @@
     return qdbus_cast<QVariantMap>(m_propertiesCache.value(ProxyConfig));
 }
 
+const QVariantMap NetworkService::ethernet() const {
+    return qdbus_cast<QVariantMap>(m_propertiesCache.value(Ethernet));
+}
+
 void NetworkService::requestConnect()
 {
     // increase reply timeout when connecting
@@ -129,12 +155,24 @@
     m_service->Disconnect();
 }
 
+void NetworkService::setAutoConnect(const bool autoconnect)
+{
+    // QDBusPendingReply<void> reply =
+    m_service->SetProperty(AutoConnect, QDBusVariant(QVariant(autoconnect)));
+}
+
 void NetworkService::setIpv4Config(const QVariantMap &ipv4)
 {
     // QDBusPendingReply<void> reply =
     m_service->SetProperty(IPv4Config, QDBusVariant(QVariant(ipv4)));
 }
 
+void NetworkService::setIpv6Config(const QVariantMap &ipv6)
+{
+    // QDBusPendingReply<void> reply =
+    m_service->SetProperty(IPv6Config, QDBusVariant(QVariant(ipv6)));
+}
+
 void NetworkService::setNameserversConfig(const QStringList &nameservers)
 {
     // QDBusPendingReply<void> reply =
@@ -191,6 +229,10 @@
         emit 
ipv4Changed(qdbus_cast<QVariantMap>(m_propertiesCache.value(IPv4)));
     } else if (name == IPv4Config) {
         emit 
ipv4ConfigChanged(qdbus_cast<QVariantMap>(m_propertiesCache.value(IPv4Config)));
+    } else if (name == IPv6) {
+        emit 
ipv6Changed(qdbus_cast<QVariantMap>(m_propertiesCache.value(IPv6)));
+    } else if (name == IPv6Config) {
+        emit 
ipv6ConfigChanged(qdbus_cast<QVariantMap>(m_propertiesCache.value(IPv6Config)));
     } else if (name == Nameservers) {
         emit nameserversChanged(tmp.toStringList());
     } else if (name == NameserversConfig) {
@@ -203,5 +245,7 @@
         emit 
proxyChanged(qdbus_cast<QVariantMap>(m_propertiesCache.value(Proxy)));
     } else if (name == ProxyConfig) {
         emit 
proxyConfigChanged(qdbus_cast<QVariantMap>(m_propertiesCache.value(ProxyConfig)));
+    } else if (name == Ethernet) {
+        emit 
ethernetChanged(qdbus_cast<QVariantMap>(m_propertiesCache.value(Ethernet)));
     }
 }
--- libconnman-qt/networkservice.h
+++ libconnman-qt/networkservice.h
@@ -11,12 +11,13 @@
 #ifndef NETWORKSERVICE_H
 #define NETWORKSERVICE_H
 
-#include "service.h"
 #include <QtDBus>
 
 #define CONNECT_TIMEOUT 180000 // user is supposed to provide input for 
unconfigured networks
 #define CONNECT_TIMEOUT_FAVORITE 60000
 
+class Service;
+
 class NetworkService : public QObject
 {
     Q_OBJECT;
@@ -27,34 +28,44 @@
     Q_PROPERTY(QStringList security READ security NOTIFY securityChanged);
     Q_PROPERTY(uint strength READ strength NOTIFY strengthChanged);
     Q_PROPERTY(bool favorite READ favorite NOTIFY favoriteChanged);
+    Q_PROPERTY(bool autoConnect READ autoConnect WRITE setAutoConnect NOTIFY 
autoConnectChanged);
+    Q_PROPERTY(QString path READ path NOTIFY pathChanged);
     Q_PROPERTY(QVariantMap ipv4 READ ipv4 NOTIFY ipv4Changed);
     Q_PROPERTY(QVariantMap ipv4Config READ ipv4Config WRITE setIpv4Config 
NOTIFY ipv4ConfigChanged);
+    Q_PROPERTY(QVariantMap ipv6 READ ipv6 NOTIFY ipv6Changed);
+    Q_PROPERTY(QVariantMap ipv6Config READ ipv6Config WRITE setIpv6Config 
NOTIFY ipv6ConfigChanged);
     Q_PROPERTY(QStringList nameservers READ nameservers NOTIFY 
nameserversChanged);
     Q_PROPERTY(QStringList nameserversConfig READ nameserversConfig WRITE 
setNameserversConfig NOTIFY nameserversConfigChanged);
     Q_PROPERTY(QStringList domains READ domains NOTIFY domainsChanged);
     Q_PROPERTY(QStringList domainsConfig READ domainsConfig WRITE 
setDomainsConfig NOTIFY domainsConfigChanged);
     Q_PROPERTY(QVariantMap proxy READ proxy NOTIFY proxyChanged);
     Q_PROPERTY(QVariantMap proxyConfig READ proxyConfig WRITE setProxyConfig 
NOTIFY proxyConfigChanged);
+    Q_PROPERTY(QVariantMap ethernet READ ethernet NOTIFY ethernetChanged);
 
 public:
     NetworkService(const QString &path, const QVariantMap &properties, 
QObject* parent);
-    NetworkService(QObject* parent = 0) { Q_ASSERT(false); };
+    NetworkService(QObject* parent = 0) { Q_ASSERT(false); Q_UNUSED(parent); };
     virtual ~NetworkService();
 
     const QString name() const;
     const QString type() const;
     const QString state() const;
     const QStringList security() const;
-    const uint strength() const;
-    const bool favorite() const;
+    bool autoConnect() const;
+    uint strength() const;
+    bool favorite() const;
+    const QString path() const;
     const QVariantMap ipv4() const;
     const QVariantMap ipv4Config() const;
+    const QVariantMap ipv6() const;
+    const QVariantMap ipv6Config() const;
     const QStringList nameservers() const;
     const QStringList nameserversConfig() const;
     const QStringList domains() const;
     const QStringList domainsConfig() const;
     const QVariantMap proxy() const;
     const QVariantMap proxyConfig() const;
+    const QVariantMap ethernet() const;
 
 signals:
     void nameChanged(const QString &name);
@@ -62,26 +73,34 @@
     void securityChanged(const QStringList &security);
     void strengthChanged(const uint strength);
     void favoriteChanged(const bool &favorite);
+    void autoConnectChanged(const bool autoconnect);
+    void pathChanged(const QString &path);
     void ipv4Changed(const QVariantMap &ipv4);
     void ipv4ConfigChanged(const QVariantMap &ipv4);
+    void ipv6Changed(const QVariantMap &ipv6);
+    void ipv6ConfigChanged(const QVariantMap &ipv6);
     void nameserversChanged(const QStringList &nameservers);
     void nameserversConfigChanged(const QStringList &nameservers);
     void domainsChanged(const QStringList &domains);
     void domainsConfigChanged(const QStringList &domains);
     void proxyChanged(const QVariantMap &proxy);
     void proxyConfigChanged(const QVariantMap &proxy);
+    void ethernetChanged(const QVariantMap &ethernet);
 
 public slots:
     void requestConnect();
     void requestDisconnect();
 
+    void setAutoConnect(const bool autoconnect);
     void setIpv4Config(const QVariantMap &ipv4);
+    void setIpv6Config(const QVariantMap &ipv6);
     void setNameserversConfig(const QStringList &nameservers);
     void setDomainsConfig(const QStringList &domains);
     void setProxyConfig(const QVariantMap &proxy);
 
 private:
     Service *m_service;
+    QString m_path;
     QVariantMap m_propertiesCache;
 
     QDBusPendingCallWatcher *dbg_connectWatcher;
@@ -93,14 +112,18 @@
     static const QString Strength;
     static const QString Error;
     static const QString Favorite;
+    static const QString AutoConnect;
     static const QString IPv4;
     static const QString IPv4Config;
+    static const QString IPv6;
+    static const QString IPv6Config;
     static const QString Nameservers;
     static const QString NameserversConfig;
     static const QString Domains;
     static const QString DomainsConfig;
     static const QString Proxy;
     static const QString ProxyConfig;
+    static const QString Ethernet;
 
 private slots:
     void propertyChanged(const QString &name, const QDBusVariant &value);
--- libconnman-qt/networktechnology.cpp
+++ libconnman-qt/networktechnology.cpp
@@ -8,6 +8,7 @@
  *
  */
 
+#include "technology.h"
 #include "networktechnology.h"
 #include "debug.h"
 
@@ -18,7 +19,8 @@
 
 NetworkTechnology::NetworkTechnology(const QString &path, const QVariantMap 
&properties, QObject* parent)
   : QObject(parent),
-    m_technology(NULL)
+    m_technology(NULL),
+    m_scanWatcher(NULL)
 {
     Q_ASSERT(!path.isEmpty());
     m_technology = new Technology("net.connman", path, 
QDBusConnection::systemBus(), this);
@@ -52,12 +54,12 @@
     return m_propertiesCache[NetworkTechnology::Type].toString();
 }
 
-const bool NetworkTechnology::powered() const
+bool NetworkTechnology::powered() const
 {
     return m_propertiesCache[NetworkTechnology::Powered].toBool();
 }
 
-const bool NetworkTechnology::connected() const
+bool NetworkTechnology::connected() const
 {
     return m_propertiesCache[NetworkTechnology::Connected].toBool();
 }
@@ -80,7 +82,11 @@
 void NetworkTechnology::scan()
 {
     Q_ASSERT(m_technology);
-    m_technology->Scan();
+
+    QDBusPendingReply<> reply = m_technology->Scan();
+    m_scanWatcher = new QDBusPendingCallWatcher(reply, m_technology);
+    connect(m_scanWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
+            this, SLOT(scanReply(QDBusPendingCallWatcher*)));
 }
 
 // Private
@@ -102,3 +108,12 @@
         emit connectedChanged(tmp.toBool());
     }
 }
+
+void NetworkTechnology::scanReply(QDBusPendingCallWatcher *call)
+{
+    Q_UNUSED(call);
+
+    pr_dbg() << "Scan Finished";
+
+    emit scanFinished();
+}
--- libconnman-qt/networktechnology.h
+++ libconnman-qt/networktechnology.h
@@ -11,9 +11,10 @@
 #ifndef NETWORKTECHNOLOGY_H
 #define NETWORKTECHNOLOGY_H
 
-#include "technology.h"
 #include <QtDBus>
 
+class Technology;
+
 class NetworkTechnology : public QObject
 {
     Q_OBJECT;
@@ -29,8 +30,8 @@
 
     const QString name() const;
     const QString type() const;
-    const bool powered() const;
-    const bool connected() const;
+    bool powered() const;
+    bool connected() const;
     const QString objPath() const;
 
 public slots:
@@ -40,10 +41,12 @@
 signals:
     void poweredChanged(const bool &powered);
     void connectedChanged(const bool &connected);
+    void scanFinished();
 
 private:
     Technology *m_technology;
     QVariantMap m_propertiesCache;
+    QDBusPendingCallWatcher *m_scanWatcher;
 
     static const QString Name;
     static const QString Type;
@@ -52,6 +55,7 @@
 
 private slots:
     void propertyChanged(const QString &name, const QDBusVariant &value);
+    void scanReply(QDBusPendingCallWatcher *call);
 
 private:
     Q_DISABLE_COPY(NetworkTechnology);
--- plugin/components.cpp
+++ plugin/components.cpp
@@ -10,22 +10,23 @@
 #include "components.h"
 
 #include <networkservice.h>
-#include "networkingmodel.h"
 #include <clockmodel.h>
-
+#include "networkingmodel.h"
+#include "technologymodel.h"
 
 void Components::registerTypes(const char *uri)
 {
-       qmlRegisterUncreatableType<NetworkService>(uri,0,2,"NetworkService",
-            "Please don't create \"NetworkService\" objects manually.");
-       qmlRegisterType<NetworkingModel>(uri,0,2,"NetworkingModel");
-       qmlRegisterType<ClockModel>(uri,0,2,"ClockModel");
+    qmlRegisterUncreatableType<NetworkService>(uri,0,2,"NetworkService",
+        "Please don't create \"NetworkService\" objects manually.");
+    qmlRegisterType<NetworkingModel>(uri,0,2,"NetworkingModel");
+    qmlRegisterType<TechnologyModel>(uri,0,2,"TechnologyModel");
+    qmlRegisterType<ClockModel>(uri,0,2,"ClockModel");
 }
 
 void Components::initializeEngine(QDeclarativeEngine *engine, const char *uri)
 {
     Q_UNUSED(uri);
-       Q_UNUSED(engine);
+    Q_UNUSED(engine);
 }
 
 Q_EXPORT_PLUGIN(Components);
--- plugin/networkingmodel.cpp
+++ plugin/networkingmodel.cpp
@@ -13,6 +13,16 @@
 
 static const char AGENT_PATH[] = "/WifiSettings";
 
+#define CONNECT_WIFI_SIGNALS(wifi) \
+    connect(wifi, \
+        SIGNAL(poweredChanged(bool)), \
+        this, \
+        SIGNAL(wifiPoweredChanged(bool))); \
+    connect(wifi, \
+            SIGNAL(scanFinished()), \
+            this, \
+            SIGNAL(scanRequestFinished()))
+
 NetworkingModel::NetworkingModel(QObject* parent)
   : QObject(parent),
     m_manager(NULL),
@@ -24,10 +34,7 @@
 
     m_wifi = m_manager->getTechnology("wifi"); // TODO: use constant literal
     if (m_wifi) {
-        connect(m_wifi,
-                SIGNAL(poweredChanged(bool)),
-                this,
-                SIGNAL(wifiPoweredChanged(bool)));
+        CONNECT_WIFI_SIGNALS(m_wifi);
     }
 
     connect(m_manager, SIGNAL(availabilityChanged(bool)),
@@ -63,7 +70,7 @@
     // FIXME: how to get rid of this douple looping since we
     // must return a QList<QObject*>?
     foreach (NetworkService* network, m_manager->getServices("wifi")) {
-           networks.append(network);
+      networks.append(network);
     }
     return networks;
 }
@@ -97,25 +104,22 @@
 
 void NetworkingModel::updateTechnologies()
 {
-       NetworkTechnology *test = NULL;
-       if (m_wifi) {
-               if ((test = m_manager->getTechnology("wifi")) == NULL) {
-                       // if wifi is set and manager doesn't return a wifi, it 
means
-                       // that wifi was removed
-                       m_wifi = NULL;
-               }
-       } else {
-               if (test = m_manager->getTechnology("wifi")) {
-                       // if wifi is not set and manager returns a wifi, it 
means
-                       // that wifi was added
-                       m_wifi = test;
-
-                       connect(m_wifi,
-                               SIGNAL(poweredChanged(bool)),
-                               this,
-                               SIGNAL(wifiPoweredChanged(bool)));
-               }
-       }
+    NetworkTechnology *test = NULL;
+    if (m_wifi) {
+        if ((test = m_manager->getTechnology("wifi")) == NULL) {
+            // if wifi is set and manager doesn't return a wifi, it means
+            // that wifi was removed
+            m_wifi = NULL;
+        }
+    } else {
+        if (test = m_manager->getTechnology("wifi")) {
+            // if wifi is not set and manager returns a wifi, it means
+            // that wifi was added
+            m_wifi = test;
+
+            CONNECT_WIFI_SIGNALS(m_wifi);
+        }
+    }
 
     emit technologiesChanged();
 }
--- plugin/networkingmodel.h
+++ plugin/networkingmodel.h
@@ -30,6 +30,7 @@
     Q_PROPERTY(bool available READ isAvailable NOTIFY availabilityChanged);
     Q_PROPERTY(bool wifiPowered READ isWifiPowered WRITE setWifiPowered NOTIFY 
wifiPoweredChanged);
     Q_PROPERTY(QList<QObject*> networks READ networks NOTIFY networksChanged);
+    Q_PROPERTY(NOTIFY scanRequestFinished);
 
 public:
     NetworkingModel(QObject* parent=0);
@@ -54,6 +55,7 @@
     void technologiesChanged();
     void userInputRequested(QVariantMap fields);
     void errorReported(const QString &error);
+    void scanRequestFinished();
 
 private:
     NetworkManager* m_manager;
@@ -62,7 +64,6 @@
 
 private slots:
     void updateTechnologies();
-
     void managerAvailabilityChanged(bool available);
 
 private:
--- plugin/plugin.pro
+++ plugin/plugin.pro
@@ -2,8 +2,8 @@
 TEMPLATE = lib
 QT += declarative dbus
 CONFIG += plugin
-SOURCES = components.cpp networkingmodel.cpp
-HEADERS = components.h networkingmodel.h
+SOURCES = components.cpp networkingmodel.cpp technologymodel.cpp useragent.cpp
+HEADERS = components.h networkingmodel.h technologymodel.h useragent.h
 
 INCLUDEPATH += ../libconnman-qt
 LIBS += -L../libconnman-qt -lconnman-qt4
--- plugin/technologymodel.cpp
+++ plugin/technologymodel.cpp
@@ -0,0 +1,218 @@
+/*
+ * Copyright © 2010, Intel Corporation.
+ * Copyright © 2012, Jolla.
+ *
+ * This program is licensed under the terms and conditions of the
+ * Apache License, version 2.0.  The full text of the Apache License is at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ */
+
+#include <QDebug>
+#include "technologymodel.h"
+#include "useragent.h"
+
+static const char AGENT_PATH[] = "/ConnectivitySettings";
+
+#define CONNECT_TECHNOLOGY_SIGNALS(tech) \
+    connect(tech, \
+        SIGNAL(poweredChanged(bool)), \
+        this, \
+        SIGNAL(poweredChanged(bool))); \
+    connect(tech, \
+            SIGNAL(scanFinished()), \
+            this, \
+            SIGNAL(scanRequestFinished()))
+
+TechnologyModel::TechnologyModel(QAbstractListModel* parent)
+  : QAbstractListModel(parent),
+    m_manager(NULL),
+    m_tech(NULL)
+{
+    m_manager = NetworkManagerFactory::createInstance();
+
+    // set default value of the "name" property
+    m_techname = QString("wifi");
+
+    QHash<int, QByteArray> roles;
+    roles[ServiceRole] = "networkService";
+    setRoleNames(roles);
+
+    new UserAgent(this); // this object will be freed when TechnologyModel is 
freed
+
+    m_tech = m_manager->getTechnology(m_techname);
+    if (m_tech) {
+        CONNECT_TECHNOLOGY_SIGNALS(m_tech);
+    }
+
+    connect(m_manager, SIGNAL(availabilityChanged(bool)),
+            this, SLOT(managerAvailabilityChanged(bool)));
+
+    connect(m_manager,
+            SIGNAL(technologiesChanged()),
+            this,
+            SLOT(updateTechnologies()));
+
+    connect(m_manager,
+            SIGNAL(servicesChanged()),
+            this,
+            SLOT(updateServiceList()));
+
+    QDBusConnection::systemBus().registerObject(AGENT_PATH, this);
+    m_manager->registerAgent(QString(AGENT_PATH));
+}
+
+TechnologyModel::~TechnologyModel()
+{
+    m_manager->unregisterAgent(QString(AGENT_PATH));
+}
+
+QVariant TechnologyModel::data(const QModelIndex &index, int role) const
+{
+    switch (role) {
+    case ServiceRole:
+        return QVariant::fromValue(static_cast<QObject 
*>(m_services.value(index.row())));
+    }
+
+    return QVariant();
+}
+
+int TechnologyModel::rowCount(const QModelIndex &parent) const
+{
+    Q_UNUSED(parent);
+
+    return m_services.count();
+}
+
+const QString TechnologyModel::name() const
+{
+    return m_techname;
+}
+
+bool TechnologyModel::isAvailable() const
+{
+    return m_manager->isAvailable();
+}
+
+bool TechnologyModel::isPowered() const
+{
+    if (m_tech) {
+        return m_tech->powered();
+    } else {
+        qWarning() << "Can't get: technology is NULL";
+        return false;
+    }
+}
+
+void TechnologyModel::setPowered(const bool &powered)
+{
+    if (m_tech) {
+        m_tech->setPowered(powered);
+    } else {
+        qWarning() << "Can't set: technology is NULL";
+    }
+}
+
+void TechnologyModel::requestScan() const
+{
+    qDebug() << "scan requested for technology";
+    if (m_tech) {
+        m_tech->scan();
+    }
+}
+
+void TechnologyModel::updateTechnologies()
+{
+    NetworkTechnology *test = NULL;
+    if (m_tech) {
+        if ((test = m_manager->getTechnology(m_techname)) == NULL) {
+            // if wifi is set and manager doesn't return a wifi, it means
+            // that wifi was removed
+            m_tech = NULL;
+        }
+    } else {
+        if ((test = m_manager->getTechnology(m_techname)) != NULL) {
+            // if wifi is not set and manager returns a wifi, it means
+            // that wifi was added
+            m_tech = test;
+
+            CONNECT_TECHNOLOGY_SIGNALS(m_tech);
+        }
+    }
+
+    emit technologiesChanged();
+}
+
+void TechnologyModel::managerAvailabilityChanged(bool available)
+{
+    if(available)
+        m_manager->registerAgent(QString(AGENT_PATH));
+
+    emit availabilityChanged(available);
+}
+
+void TechnologyModel::requestUserInput(ServiceRequestData* data)
+{
+    m_req_data = data;
+    emit userInputRequested(data->objectPath, data->fields);
+}
+
+void TechnologyModel::reportError(const QString &error) {
+    emit errorReported(error);
+}
+
+void TechnologyModel::sendUserReply(const QVariantMap &input) {
+    if (!input.isEmpty()) {
+        QDBusMessage &reply = m_req_data->reply;
+        reply << input;
+        QDBusConnection::systemBus().send(reply);
+    } else {
+        QDBusMessage error = m_req_data->msg.createErrorReply(
+            QString("net.connman.Agent.Error.Canceled"),
+            QString("canceled by user"));
+        QDBusConnection::systemBus().send(error);
+    }
+    delete m_req_data;
+}
+
+int TechnologyModel::indexOf(const QString &dbusObjectPath) const
+{
+    int idx(-1);
+
+    foreach (NetworkService *service, m_services) {
+        idx++;
+        if (service->path() == dbusObjectPath) return idx;
+    }
+
+    return -1;
+}
+
+void TechnologyModel::updateServiceList()
+{
+    const QVector<NetworkService *> new_services = 
m_manager->getServices(m_techname);
+    int num_new = new_services.count();
+
+    for (int i = 0; i < num_new; i++) {
+        int j = m_services.indexOf(new_services.value(i));
+        if (j == -1) {
+            // wifi service not found -> remove from list
+            beginInsertRows(QModelIndex(), i, i);
+            m_services.insert(i, new_services.value(i));
+            endInsertRows();
+        } else if (i != j) {
+            // wifi service changed its position -> move it
+            NetworkService* service = m_services.value(j);
+            beginMoveRows(QModelIndex(), j, j, QModelIndex(), i);
+            m_services.remove(j);
+            m_services.insert(i, service);
+            endMoveRows();
+        }
+    }
+
+    int num_old = m_services.count();
+    if (num_old > num_new) {
+        beginRemoveRows(QModelIndex(), num_new, num_old - 1);
+        m_services.remove(num_new, num_old - num_new);
+        endRemoveRows();
+    }
+}
--- plugin/technologymodel.h
+++ plugin/technologymodel.h
@@ -0,0 +1,94 @@
+/*
+ * Copyright © 2010, Intel Corporation.
+ * Copyright © 2012, Jolla.
+ *
+ * This program is licensed under the terms and conditions of the
+ * Apache License, version 2.0.  The full text of the Apache License is at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * WARNING: this class is experimetal and is about to be refactored in order
+ *          to deprecate NetworkingModel.
+ */
+
+#ifndef TECHNOLOGYMODEL_H
+#define TECHNOLOGYMODEL_H
+
+#include <QAbstractListModel>
+#include <networkmanager.h>
+#include <networktechnology.h>
+#include <networkservice.h>
+
+struct ServiceRequestData
+{
+    QString objectPath;
+    QVariantMap fields;
+    QDBusMessage reply;
+    QDBusMessage msg;
+};
+
+/*
+ * TechnologyModel is a list model specific to a certain technology (wifi by 
default).
+ * TODO: 1. consider refactoring this class to NetworkServiceModel with
+ *          "technologyName" as a filtering property;
+ *       2. drop properties NetworkServiceModel.available, 
NetworkServiceModel.powered;
+ *       2. expose NetworkTechnology as QtQuick component.
+ */
+class TechnologyModel : public QAbstractListModel
+{
+    Q_OBJECT;
+    Q_DISABLE_COPY(TechnologyModel);
+
+    // TODO: consider "name" as writeable property of TechnologyModel QtQuck 
component
+    Q_PROPERTY(QString name READ name NOTIFY nameChanged);
+    Q_PROPERTY(bool available READ isAvailable NOTIFY availabilityChanged);
+    Q_PROPERTY(bool powered READ isPowered WRITE setPowered NOTIFY 
poweredChanged);
+
+public:
+    enum ItemRoles {
+        ServiceRole = Qt::UserRole + 1
+    };
+
+    TechnologyModel(QAbstractListModel* parent = 0);
+    virtual ~TechnologyModel();
+
+    QVariant data(const QModelIndex &index, int role) const;
+    int rowCount(const QModelIndex &parent = QModelIndex()) const;
+
+    const QString name() const;
+    bool isAvailable() const;
+    bool isPowered() const;
+
+    void requestUserInput(ServiceRequestData* data);
+    void reportError(const QString &error);
+
+    Q_INVOKABLE void sendUserReply(const QVariantMap &input);
+    Q_INVOKABLE int indexOf(const QString &dbusObjectPath) const;
+
+public slots:
+    void setPowered(const bool &powered);
+    void requestScan() const;
+
+signals:
+    void nameChanged(const QString &name);
+    void availabilityChanged(const bool &available);
+    void poweredChanged(const bool &powered);
+    void technologiesChanged();
+
+    void userInputRequested(const QString &servicePath, const QVariantMap 
&fields);
+    void errorReported(const QString &error);
+    void scanRequestFinished();
+
+private:
+    QString m_techname;
+    NetworkManager* m_manager;
+    NetworkTechnology* m_tech;
+    ServiceRequestData* m_req_data;
+    QVector<NetworkService *> m_services;
+
+private slots:
+    void updateTechnologies();
+    void updateServiceList();
+    void managerAvailabilityChanged(bool available);
+};
+
+#endif // TECHNOLOGYMODEL_H
--- plugin/useragent.cpp
+++ plugin/useragent.cpp
@@ -0,0 +1,63 @@
+/*
+ * Copyright © 2012, Jolla.
+ *
+ * This program is licensed under the terms and conditions of the
+ * Apache License, version 2.0.  The full text of the Apache License is at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ */
+
+#include "useragent.h"
+
+UserAgent::UserAgent(TechnologyModel* parent)
+  : QDBusAbstractAdaptor(parent),
+    m_model(parent)
+{
+    // TODO
+}
+
+UserAgent::~UserAgent() {}
+
+void UserAgent::Release()
+{
+    // here do clean up
+}
+
+void UserAgent::ReportError(const QDBusObjectPath &service_path, const QString 
&error)
+{
+    qDebug() << "From " << service_path.path() << " got this error:\n" << 
error;
+    m_model->reportError(error);
+}
+
+void UserAgent::RequestBrowser(const QDBusObjectPath &service_path, const 
QString &url)
+{
+    qDebug() << "Service " << service_path.path() << " wants browser to open 
hotspot's url " << url;
+}
+
+void UserAgent::RequestInput(const QDBusObjectPath &service_path,
+                                       const QVariantMap &fields,
+                                       const QDBusMessage &message)
+{
+    qDebug() << "Service " << service_path.path() << " wants user input";
+
+    QVariantMap json;
+    foreach (const QString &key, fields.keys()){
+        QVariantMap payload = qdbus_cast<QVariantMap>(fields[key]);
+        json.insert(key, payload);
+    }
+
+    message.setDelayedReply(true);
+
+    ServiceRequestData *reqdata = new ServiceRequestData;
+    reqdata->objectPath = service_path.path();
+    reqdata->fields = json;
+    reqdata->reply = message.createReply();
+    reqdata->msg = message;
+
+    m_model->requestUserInput(reqdata);
+}
+
+void UserAgent::Cancel()
+{
+    qDebug() << "WARNING: request to agent got canceled";
+}
--- plugin/useragent.h
+++ plugin/useragent.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright © 2012, Jolla.
+ *
+ * This program is licensed under the terms and conditions of the
+ * Apache License, version 2.0.  The full text of the Apache License is at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ */
+
+#ifndef USERAGENT_H
+#define USERAGENT_H
+
+#include <QDBusAbstractAdaptor>
+#include "technologymodel.h"
+
+class UserAgent : public QDBusAbstractAdaptor
+{
+    Q_OBJECT;
+    Q_CLASSINFO("D-Bus Interface", "net.connman.Agent");
+
+public:
+    UserAgent(TechnologyModel* parent);
+    virtual ~UserAgent();
+
+public slots:
+    void Release();
+    void ReportError(const QDBusObjectPath &service_path, const QString 
&error);
+    void RequestBrowser(const QDBusObjectPath &service_path, const QString 
&url);
+    Q_NOREPLY void RequestInput(const QDBusObjectPath &service_path,
+                                const QVariantMap &fields,
+                                const QDBusMessage &message);
+    void Cancel();
+
+private:
+    TechnologyModel* m_model;
+};
+
+#endif // USERAGENT_H
--- test/main.qml
+++ test/main.qml
@@ -26,7 +26,10 @@
         running: false
         repeat: true
         triggeredOnStart: true
-        onTriggered: networkingModel.requestScan();
+        onTriggered: {
+            networkingModel.requestScan();
+            txtScanning.text = "Scanning...";
+        }
     }
 
     NetworkingModel {
@@ -75,6 +78,11 @@
             scanTimer.running = networkingModel.wifiPowered;
         }
 
+        onScanRequestFinished: {
+            txtScanning.text = "";
+            console.log("scan finished");
+        }
+
         onUserInputRequested: {
             scanTimer.running = false;
             scanTimer.triggeredOnStart = false;
@@ -158,6 +166,13 @@
                     color: "white"
                     font.pointSize: 16
                 }
+                Text {
+                    id: txtScanning
+                    anchors { right: parent.right; verticalCenter: 
parent.verticalCenter; rightMargin: 20 }
+                    text: ""
+                    color: "red"
+                    font.pointSize: 13
+                }
                 Switch {
                     id: wifiSwitch
                     anchors { right: parent.right; verticalCenter: 
parent.verticalCenter; rightMargin: 40 }

++++++ connman-qt.yaml
--- connman-qt.yaml
+++ connman-qt.yaml
@@ -1,6 +1,6 @@
 Name: connman-qt
 Summary: qt bindings for connman
-Version: 0.3.0
+Version: 0.3.1
 Release: 1
 Group: System/GUI/Other
 License: Apache License



Reply via email to