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/7450 Thank You, rojkov [This message was auto-generated] --- Request # 7450: Messages from BOSS: State: review at 2012-11-27T13:31:26 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,5 @@ +* Tue Nov 27 2012 Dmitry Rozhkov <[email protected]> - 0.3.0 +- Applied patch from Felipe Tonello adding TechnologyAdded and + TechnologyRemoved signals. +- Added technology filter to NetworkManager::getServies() method. + old: ---- connman-qt-0.2.2.tar.bz2 new: ---- connman-qt-0.3.0.tar.bz2 spec files: ----------- --- connman-qt.spec +++ connman-qt.spec @@ -1,6 +1,6 @@ # # Do NOT Edit the Auto-generated Part! -# Generated by: spectacle version 0.24.1 +# Generated by: spectacle version 0.25 # Name: connman-qt @@ -9,7 +9,7 @@ # << macros Summary: qt bindings for connman -Version: 0.2.2 +Version: 0.3.0 Release: 1 Group: System/GUI/Other License: Apache License other changes: -------------- ++++++ connman-qt-0.2.2.tar.bz2 -> connman-qt-0.3.0.tar.bz2 --- .dir-locals.el +++ .dir-locals.el @@ -0,0 +1,4 @@ +;;; Directory Local Variables +;;; See Info node `(emacs) Directory Variables' for more information. + +((c-mode . ((eval . (c++-mode))))) --- .gitignore +++ .gitignore @@ -1,3 +1,20 @@ +# temp files *.swp +\#*# + +# binaries *.o moc_*.cpp +*.so* +testconnman-qt + +# make files and pkgconfig +Makefile* +*.pc +*.prl + +# dbus api +clock.* +service.* +technology.* + --- libconnman-qt/clockmodel.cpp +++ libconnman-qt/clockmodel.cpp @@ -57,10 +57,10 @@ void ClockModel::getPropertiesFinished(QDBusPendingCallWatcher *call) { - QDBusPendingReply<QVariantMap> reply = *call; - if (reply.isError()) { - qCritical() << "ClockModel: getProperties: " << reply.error().name() << reply.error().message(); - } else { + QDBusPendingReply<QVariantMap> reply = *call; + if (reply.isError()) { + qCritical() << "ClockModel: getProperties: " << reply.error().name() << reply.error().message(); + } else { QVariantMap properties = reply.value(); Q_ASSERT(properties.contains("Timezone")); @@ -88,9 +88,9 @@ void ClockModel::setPropertyFinished(QDBusPendingCallWatcher *call) { - QDBusPendingReply<> reply = *call; - if (reply.isError()) { - qCritical() << "ClockModel: setProperty: " << reply.error().name() << reply.error().message(); + QDBusPendingReply<> reply = *call; + if (reply.isError()) { + qCritical() << "ClockModel: setProperty: " << reply.error().name() << reply.error().message(); } call->deleteLater(); } --- libconnman-qt/connman-clock.xml +++ libconnman-qt/connman-clock.xml @@ -1,18 +1,18 @@ <!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> <node> - <interface name="net.connman.Clock"> - <method name="GetProperties"> - <arg type="a{sv}" direction="out"/> + <interface name="net.connman.Clock"> + <method name="GetProperties"> + <arg type="a{sv}" direction="out"/> <annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="QVariantMap"/> - </method> - <method name="SetProperty"> - <arg type="s" direction="in"/> - <arg type="v" direction="in"/> - </method> - <signal name="PropertyChanged"> - <arg type="s"/> - <arg type="v"/> - </signal> - </interface> + </method> + <method name="SetProperty"> + <arg type="s" direction="in"/> + <arg type="v" direction="in"/> + </method> + <signal name="PropertyChanged"> + <arg type="s"/> + <arg type="v"/> + </signal> + </interface> </node> --- libconnman-qt/debug.cpp +++ libconnman-qt/debug.cpp @@ -0,0 +1,18 @@ +/* + * Copyright © 2012, Cercacor Labs. + * + * 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 "debug.h" + +QDebug operator<<(QDebug lhs, const __Debug &rhs) +{ + lhs.nospace() << "libconnman-qt(" << rhs.file << ":" << rhs.func << ":" << rhs.line << ")"; + + return lhs.space(); +} + --- libconnman-qt/debug.h +++ libconnman-qt/debug.h @@ -0,0 +1,28 @@ +/* + * Copyright © 2012, Cercacor Labs. + * + * 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 DEBUG_H +#define DEBUG_H + +#include <QDebug> + +struct __Debug { + __Debug(const char *_file, const char *_func, int _line) + : file(_file), func(_func), line(_line) {} + + const char *file; + const char *func; + int line; +}; + +QDebug operator<<(QDebug lhs, const __Debug &rhs); + +#define pr_dbg() qDebug() << __Debug(__FILE__, __func__, __LINE__) + +#endif // DEBUG_H --- libconnman-qt/libconnman-qt.pro +++ libconnman-qt/libconnman-qt.pro @@ -1,15 +1,17 @@ -#-*-Shell-Script-*- +TEMPLATE = lib +VERSION = 0.3.0 +CONFIG += qt debug +CONFIG += create_pc create_prl +QT += core dbus +QT -= gui +TARGET = $$qtLibraryTarget(connman-qt4) + +OBJECTS_DIR += build +MOC_DIR += build -TEMPLATE = lib -VERSION=0.1.4 -CONFIG += qt \ - debug -QT += dbus -TARGET = $$qtLibraryTarget(connman-qt4) isEmpty(PREFIX) { PREFIX=/usr } -target.path = $$INSTALL_ROOT$$PREFIX/lib #system(qdbusxml2cpp -c Manager -p manager -N connman-manager.xml) system(qdbusxml2cpp -c Service -p service -N connman-service.xml) @@ -21,30 +23,31 @@ networkmanager.h \ networktechnology.h \ networkservice.h \ - commondbustypes.h \ + commondbustypes.h \ clockproxy.h \ - clockmodel.h + clockmodel.h \ + debug.h + +SOURCES += \ + networkmanager.cpp \ + networktechnology.cpp \ + networkservice.cpp \ + manager.cpp \ + service.cpp \ + technology.cpp \ + clockproxy.cpp \ + clockmodel.cpp \ + commondbustypes.cpp \ + debug.cpp -headers.files = manager.h service.h technology.h \ - commondbustypes.h clockproxy.h clockmodel.h networkmanager.h \ - networktechnology.h networkservice.h +target.path = $$INSTALL_ROOT$$PREFIX/lib + +headers.files = $$HEADERS headers.path = $$INSTALL_ROOT$$PREFIX/include/connman-qt -CONFIG += create_pc create_prl QMAKE_PKGCONFIG_DESCRIPTION = Qt Connman Library QMAKE_PKGCONFIG_INCDIR = $$headers.path pkgconfig.path = $$INSTALL_ROOT$$PREFIX/lib/pkgconfig pkgconfig.files = connman-qt4.pc -SOURCES += \ - networkmanager.cpp \ - networktechnology.cpp \ - networkservice.cpp \ - manager.cpp \ - service.cpp \ - technology.cpp \ - clockproxy.cpp \ - clockmodel.cpp \ - commondbustypes.cpp - INSTALLS += target headers pkgconfig --- libconnman-qt/networkmanager.cpp +++ libconnman-qt/networkmanager.cpp @@ -9,6 +9,7 @@ */ #include "networkmanager.h" +#include "debug.h" static NetworkManager* staticInstance = NULL; @@ -63,7 +64,9 @@ QDBusConnection::systemBus(), this); if (!m_manager->isValid()) { - qDebug("manager is invalid. connman may not be running or is invalid"); + + pr_dbg() << "D-Bus net.connman.Manager object is invalid. Connman may not be running or is invalid."; + delete m_manager; m_manager = NULL; @@ -95,7 +98,7 @@ if(!m_available) emit availabilityChanged(m_available = true); - qDebug("connected"); + pr_dbg() << "Connected"; } } @@ -123,16 +126,28 @@ void NetworkManager::getPropertiesReply(QDBusPendingCallWatcher *call) { Q_ASSERT(call); + + pr_dbg() << "Got reply with manager's properties"; + QDBusPendingReply<QVariantMap> reply = *call; if (reply.isError()) { - qDebug() << "Error getPropertiesReply: " << reply.error().message(); + + pr_dbg() << "Error getPropertiesReply: " << reply.error().message(); + disconnectFromConnman(); + // TODO: set up timer to reconnect in a bit QTimer::singleShot(10000,this,SLOT(connectToConnman())); } else { + m_propertiesCache = reply.value(); + + pr_dbg() << "Initial Manager's properties"; + pr_dbg() << "\tState: " << m_propertiesCache[State].toString(); + pr_dbg() << "\tOfflineMode: " << m_propertiesCache[OfflineMode].toString(); + emit stateChanged(m_propertiesCache[State].toString()); - qDebug() << "State: " << m_propertiesCache["State"].toString(); + connect(m_manager, SIGNAL(PropertyChanged(const QString&, const QDBusVariant&)), this, @@ -143,92 +158,142 @@ void NetworkManager::getTechnologiesReply(QDBusPendingCallWatcher *call) { Q_ASSERT(call); + + pr_dbg() << "Got reply with technolgies"; + QDBusPendingReply<ConnmanObjectList> reply = *call; if (reply.isError()) { - qDebug() << "Error getTechnologiesReply: " << reply.error().message(); + + pr_dbg() << "Error getTechnologiesReply:" << reply.error().message(); + disconnectFromConnman(); + // TODO: set up timer to reconnect in a bit //QTimer::singleShot(10000,this,SLOT(connectToConnman())); } else { + ConnmanObjectList lst = reply.value(); ConnmanObject obj; foreach (obj, lst) { // TODO: consider optimizations + NetworkTechnology *tech = new NetworkTechnology(obj.objpath.path(), obj.properties, this); + m_technologiesCache.insert(tech->type(), tech); - qDebug() << "From NT: " << tech->type() << " " << tech->connected() << " " << tech->powered(); - } - if (!m_technologiesCache.isEmpty()) { - emit technologiesChanged(m_technologiesCache, QStringList()); + + pr_dbg() << "Technology: " << tech->type(); + pr_dbg() << "\tConnected:" << tech->connected(); + pr_dbg() << "\tPowered:" << tech->powered(); } + + connect(m_manager, + SIGNAL(TechnologyAdded(const QDBusObjectPath &, const QVariantMap &)), + this, + SLOT(technologyAdded(const QDBusObjectPath &, const QVariantMap &))); + + connect(m_manager, + SIGNAL(TechnologyRemoved(const QDBusObjectPath &)), + this, + SLOT(technologyRemoved(const QDBusObjectPath &))); + + emit technologiesChanged(); } - qDebug() << "Got reply with technolgies"; } void NetworkManager::getServicesReply(QDBusPendingCallWatcher *call) { Q_ASSERT(call); + + pr_dbg() << "Got reply with services"; + QDBusPendingReply<ConnmanObjectList> reply = *call; if (reply.isError()) { - qDebug() << "Error getServicesReply: " << reply.error().message(); + + pr_dbg() << "Error getServicesReply:" << reply.error().message(); + disconnectFromConnman(); + // TODO: set up timer to reconnect in a bit //QTimer::singleShot(10000,this,SLOT(connectToConnman())); } else { + ConnmanObjectList lst = reply.value(); ConnmanObject obj; int order = -1; + NetworkService *service = NULL; + + // make sure we don't leak memory + m_servicesOrder.clear(); + foreach (obj, lst) { // TODO: consider optimizations order++; - NetworkService *service = new NetworkService(obj.objpath.path(), + + service = new NetworkService(obj.objpath.path(), obj.properties, this); + m_servicesCache.insert(obj.objpath.path(), service); - m_servicesOrder.insert(obj.objpath.path(), order); - qDebug() << "From Service: " << obj.objpath.path(); - if (order == 0) { + m_servicesOrder.push_back(service); + + pr_dbg() << "From Service: " << obj.objpath.path(); + + // by connman's documentation, first service is always + // the default route's one + if (order == 0) updateDefaultRoute(service); - } } - if (order == -1) { + + // if no service was replied + if (order == -1) updateDefaultRoute(NULL); - } + emit servicesChanged(); + connect(m_manager, SIGNAL(ServicesChanged(ConnmanObjectList, QList<QDBusObjectPath>)), this, SLOT(updateServices(ConnmanObjectList, QList<QDBusObjectPath>))); } - qDebug() << "Got reply with services"; } void NetworkManager::updateServices(const ConnmanObjectList &changed, const QList<QDBusObjectPath> &removed) { - qDebug() << "services changed: " << changed.size(); + pr_dbg() << "Number of services that changed: " << changed.size(); + foreach (QDBusObjectPath obj, removed) { - qDebug() << "removing " << obj.path(); + pr_dbg() << "Removing " << obj.path(); m_servicesCache.value(obj.path())->deleteLater(); m_servicesCache.remove(obj.path()); - m_servicesOrder.remove(obj.path()); } + ConnmanObject connmanobj; int order = -1; + NetworkService *service = NULL; + + // make sure we don't leak memory + m_servicesOrder.clear(); + foreach (connmanobj, changed) { order++; - m_servicesOrder.insert(connmanobj.objpath.path(), order); + if (!m_servicesCache.contains(connmanobj.objpath.path())) { - NetworkService *service = new NetworkService(connmanobj.objpath.path(), + service = new NetworkService(connmanobj.objpath.path(), connmanobj.properties, this); m_servicesCache.insert(connmanobj.objpath.path(), service); - qDebug() << "Added service " << connmanobj.objpath.path(); - } - if (order == 0) { - updateDefaultRoute(m_servicesCache.value(connmanobj.objpath.path())); + pr_dbg() << "Added service " << connmanobj.objpath.path(); + } else { + service = m_servicesCache.value(connmanobj.objpath.path()); } + + m_servicesOrder.push_back(service); + + if (order == 0) + updateDefaultRoute(service); } - if (order == -1) { + + if (order == -1) updateDefaultRoute(NULL); - } + emit servicesChanged(); } @@ -243,15 +308,54 @@ void NetworkManager::propertyChanged(const QString &name, const QDBusVariant &value) { - qDebug() << "NetworkManager::propertyChanged(" << name << ")"; - m_propertiesCache[name] = value.variant(); + QVariant tmp = value.variant(); + + pr_dbg() << "Manager's property" << name << "changed from" + << m_propertiesCache[name].toString() << "to" << tmp.toString(); + + m_propertiesCache[name] = tmp; if (name == State) { - emit stateChanged(m_propertiesCache[State].toString()); + emit stateChanged(tmp.toString()); } else if (name == OfflineMode) { - emit offlineModeChanged(m_propertiesCache[OfflineMode].toBool()); + emit offlineModeChanged(tmp.toBool()); + } +} + +void NetworkManager::technologyAdded(const QDBusObjectPath &technology, + const QVariantMap &properties) +{ + NetworkTechnology *tech = new NetworkTechnology(technology.path(), + properties, this); + + m_technologiesCache.insert(tech->type(), tech); + + pr_dbg() << "Technology: " << tech->type(); + pr_dbg() << "\tConnected:" << tech->connected(); + pr_dbg() << "\tPowered:" << tech->powered(); + + emit technologiesChanged(); +} + +void NetworkManager::technologyRemoved(const QDBusObjectPath &technology) +{ + NetworkTechnology *net; + // if we wasn't storing by type() this loop would be unecessary + // but since this function will be triggered rarely that's fine + foreach (net, m_technologiesCache) { + if (net->objPath() == technology.path()) { + + pr_dbg() << "Removing " << net->objPath(); + m_technologiesCache.remove(net->type()); + net->deleteLater(); + + break; + } } + + emit technologiesChanged(); } + // Public API ///////////// // Getters @@ -283,18 +387,34 @@ if (m_technologiesCache.contains(type)) return m_technologiesCache.value(type); else { - qDebug() << "Technology " << type << " doesn't exist"; + pr_dbg() << "Technology " << type << " doesn't exist"; return NULL; } } -const QVector<NetworkService*> NetworkManager::getServices() const +const QVector<NetworkTechnology *> NetworkManager::getTechnologies() const +{ + QVector<NetworkTechnology *> techs(m_technologiesCache.size(), NULL); + + foreach (NetworkTechnology *tech, m_technologiesCache) { + techs.push_back(tech); + } + + return techs; +} + +const QVector<NetworkService*> NetworkManager::getServices(const QString &tech) const { - QVector<NetworkService*> networks(m_servicesCache.size(), NULL); - foreach (const QString &path, m_servicesCache.keys()) { - networks[m_servicesOrder.value(path)] = m_servicesCache.value(path); + QVector<NetworkService *> services; + + // this foreach is based on the m_servicesOrder to keep connman's sort + // of services. + foreach (NetworkService *service, m_servicesOrder) { + if (tech.isEmpty() || service->type() == tech) + services.push_back(service); } - return networks; // TODO: optimizations + + return services; } // Setters --- libconnman-qt/networkmanager.h +++ libconnman-qt/networkmanager.h @@ -43,7 +43,8 @@ bool isAvailable() const; NetworkTechnology* getTechnology(const QString &type) const; - const QVector<NetworkService*> getServices() const; + const QVector<NetworkTechnology *> getTechnologies() const; + const QVector<NetworkService*> getServices(const QString &tech = "") const; const QString state() const; bool offlineMode() const; @@ -59,8 +60,7 @@ void stateChanged(const QString &state); void offlineModeChanged(bool offlineMode); - void technologiesChanged(const QMap<QString, NetworkTechnology*> &added, - const QStringList &removed); + void technologiesChanged(); void servicesChanged(); void defaultRouteChanged(NetworkService* defaultRoute); @@ -70,10 +70,18 @@ QDBusPendingCallWatcher *m_getPropertiesWatcher; QDBusPendingCallWatcher *m_getTechnologiesWatcher; QDBusPendingCallWatcher *m_getServicesWatcher; + + /* Contains all property related to this net.connman.Manager object */ QVariantMap m_propertiesCache; - QMap<QString, NetworkTechnology *> m_technologiesCache; - QMap<QString, NetworkService *> m_servicesCache; - QMap<QString, uint> m_servicesOrder; + + /* Not just for cache, but actual containers of Network* type objects */ + QHash<QString, NetworkTechnology *> m_technologiesCache; + QHash<QString, NetworkService *> m_servicesCache; + + /* This is for sorting purpose only, never delete an object from here */ + QVector<NetworkService *> m_servicesOrder; + + /* This variable is used just to send signal if changed */ NetworkService* m_defaultRoute; QDBusServiceWatcher *watcher; @@ -93,6 +101,9 @@ void propertyChanged(const QString &name, const QDBusVariant &value); void updateServices(const ConnmanObjectList &changed, const QList<QDBusObjectPath> &removed); void updateDefaultRoute(NetworkService* defaultRoute); + void technologyAdded(const QDBusObjectPath &technology, const QVariantMap &properties); + void technologyRemoved(const QDBusObjectPath &technology); + private: Q_DISABLE_COPY(NetworkManager); --- libconnman-qt/networkservice.cpp +++ libconnman-qt/networkservice.cpp @@ -9,6 +9,7 @@ */ #include "networkservice.h" +#include "debug.h" const QString NetworkService::Name("Name"); const QString NetworkService::State("State"); @@ -34,7 +35,7 @@ m_service = new Service("net.connman", path, QDBusConnection::systemBus(), this); if (!m_service->isValid()) { - qDebug() << "invalid service: " << path; + pr_dbg() << "Invalid service: " << path; throw -1; // FIXME } @@ -154,44 +155,50 @@ /* this slot is used for debugging */ void NetworkService::dbg_connectReply(QDBusPendingCallWatcher *call){ - qDebug() << "Got something from service.connect()"; + pr_dbg() << "Got something from service.connect()"; Q_ASSERT(call); QDBusPendingReply<> reply = *call; if (!reply.isFinished()) { - qDebug() << "connect() not finished yet"; + pr_dbg() << "connect() not finished yet"; } if (reply.isError()) { - qDebug() << "Reply from service.connect(): " << reply.error().message(); + pr_dbg() << "Reply from service.connect(): " << reply.error().message(); } } void NetworkService::propertyChanged(const QString &name, const QDBusVariant &value) { - qDebug() << "NetworkService: property " << name << " changed to " << value.variant(); - m_propertiesCache[name] = value.variant(); + QVariant tmp = value.variant(); + + Q_ASSERT(m_service); + + pr_dbg() << m_service->path() << "property" << name << "changed from" + << m_propertiesCache[name].toString() << "to" << tmp.toString(); + + m_propertiesCache[name] = tmp; if (name == Name) { - emit nameChanged(m_propertiesCache[name].toString()); + emit nameChanged(tmp.toString()); } else if (name == State) { - emit stateChanged(m_propertiesCache[name].toString()); + emit stateChanged(tmp.toString()); } else if (name == Security) { - emit securityChanged(m_propertiesCache[name].toStringList()); + emit securityChanged(tmp.toStringList()); } else if (name == Strength) { - emit strengthChanged(m_propertiesCache[name].toUInt()); + emit strengthChanged(tmp.toUInt()); } else if (name == Favorite) { - emit favoriteChanged(m_propertiesCache[name].toBool()); + emit favoriteChanged(tmp.toBool()); } else if (name == IPv4) { 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 == Nameservers) { - emit nameserversChanged(m_propertiesCache[name].toStringList()); + emit nameserversChanged(tmp.toStringList()); } else if (name == NameserversConfig) { - emit nameserversConfigChanged(m_propertiesCache[name].toStringList()); + emit nameserversConfigChanged(tmp.toStringList()); } else if (name == Domains) { - emit domainsChanged(m_propertiesCache[name].toStringList()); + emit domainsChanged(tmp.toStringList()); } else if (name == DomainsConfig) { - emit domainsConfigChanged(m_propertiesCache[name].toStringList()); + emit domainsConfigChanged(tmp.toStringList()); } else if (name == Proxy) { emit proxyChanged(qdbus_cast<QVariantMap>(m_propertiesCache.value(Proxy))); } else if (name == ProxyConfig) { --- libconnman-qt/networktechnology.cpp +++ libconnman-qt/networktechnology.cpp @@ -9,6 +9,7 @@ */ #include "networktechnology.h" +#include "debug.h" const QString NetworkTechnology::Name("Name"); const QString NetworkTechnology::Type("Type"); @@ -23,7 +24,7 @@ m_technology = new Technology("net.connman", path, QDBusConnection::systemBus(), this); if (!m_technology->isValid()) { - qDebug() << "invalid technology: " << path; + pr_dbg() << "Invalid technology: " << path; throw -1; // FIXME } @@ -61,6 +62,13 @@ return m_propertiesCache[NetworkTechnology::Connected].toBool(); } +const QString NetworkTechnology::objPath() const +{ + Q_ASSERT(m_technology); + + return m_technology->path(); +} + // Setters void NetworkTechnology::setPowered(const bool &powered) @@ -79,12 +87,18 @@ void NetworkTechnology::propertyChanged(const QString &name, const QDBusVariant &value) { - qDebug() << "NetworkTechnology: property " << name << " changed to " << value.variant(); - m_propertiesCache[name] = value.variant(); + QVariant tmp = value.variant(); + + Q_ASSERT(m_technology); + + pr_dbg() << m_technology->path() << "property" << name << "changed from" + << m_propertiesCache[name].toString() << "to" << tmp.toString(); + + m_propertiesCache[name] = tmp; if (name == Powered) { - emit poweredChanged(m_propertiesCache[name].toBool()); + emit poweredChanged(tmp.toBool()); } else if (name == Connected) { - emit connectedChanged(m_propertiesCache[name].toBool()); + emit connectedChanged(tmp.toBool()); } } --- libconnman-qt/networktechnology.h +++ libconnman-qt/networktechnology.h @@ -31,6 +31,7 @@ const QString type() const; const bool powered() const; const bool connected() const; + const QString objPath() const; public slots: void setPowered(const bool &powered); --- plugin/networkingmodel.cpp +++ plugin/networkingmodel.cpp @@ -8,10 +8,10 @@ * */ -#include "QDebug" +#include <QDebug> #include "networkingmodel.h" -#define AGENT_PATH "/WifiSettings" +static const char AGENT_PATH[] = "/WifiSettings"; NetworkingModel::NetworkingModel(QObject* parent) : QObject(parent), @@ -19,7 +19,8 @@ m_wifi(NULL) { m_manager = NetworkManagerFactory::createInstance(); - new UserInputAgent(this); + + new UserInputAgent(this); // this object will be freed when NetworkingModel is freed m_wifi = m_manager->getTechnology("wifi"); // TODO: use constant literal if (m_wifi) { @@ -28,16 +29,20 @@ this, SIGNAL(wifiPoweredChanged(bool))); } + connect(m_manager, SIGNAL(availabilityChanged(bool)), this, SLOT(managerAvailabilityChanged(bool))); + connect(m_manager, - SIGNAL(technologiesChanged(QMap<QString, NetworkTechnology*>, QStringList)), + SIGNAL(technologiesChanged()), this, - SLOT(updateTechnologies(QMap<QString, NetworkTechnology*>, QStringList))); + SLOT(updateTechnologies())); + connect(m_manager, SIGNAL(servicesChanged()), this, SIGNAL(networksChanged())); + QDBusConnection::systemBus().registerObject(AGENT_PATH, this); m_manager->registerAgent(QString(AGENT_PATH)); } @@ -54,13 +59,11 @@ QList<QObject*> NetworkingModel::networks() const { - const QString wifi("wifi"); QList<QObject*> networks; - // TODO: get rid of double looping, do filtering in NM::getServices() - foreach (NetworkService* network, m_manager->getServices()) { - if (network->type() == wifi) { - networks.append(network); - } + // 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); } return networks; } @@ -92,20 +95,28 @@ } } -void NetworkingModel::updateTechnologies(const QMap<QString, NetworkTechnology*> &added, - const QStringList &removed) +void NetworkingModel::updateTechnologies() { - QString wifi_str = QString("wifi"); - if (added.contains(wifi_str)) { - m_wifi = added.value(wifi_str); - connect(m_wifi, - SIGNAL(poweredChanged(bool)), - this, - SIGNAL(wifiPoweredChanged(bool))); - } - if (removed.contains(wifi_str)) { - m_wifi = NULL; // FIXME: is it needed? - } + 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))); + } + } + emit technologiesChanged(); } @@ -172,17 +183,21 @@ const QVariantMap &fields, const QDBusMessage &message) { - QVariantMap json; 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); + ServiceReqData *reqdata = new ServiceReqData; reqdata->fields = json; - message.setDelayedReply(true); reqdata->reply = message.createReply(); reqdata->msg = message; + m_networkingmodel->requestUserInput(reqdata); } --- plugin/networkingmodel.h +++ plugin/networkingmodel.h @@ -61,8 +61,7 @@ ServiceReqData* m_req_data; private slots: - void updateTechnologies(const QMap<QString, NetworkTechnology*> &added, - const QStringList &removed); + void updateTechnologies(); void managerAvailabilityChanged(bool available); --- test/main.qml +++ test/main.qml @@ -1,7 +1,7 @@ import QtQuick 1.1 import com.nokia.meego 1.0 import MeeGo.Connman 0.2 -import "/usr/lib/qt4/imports/Connman/js/mustache.js" as M +import "mustache.js" as M PageStack { id: wifiPageStack ++++++ connman-qt.yaml --- connman-qt.yaml +++ connman-qt.yaml @@ -1,6 +1,6 @@ Name: connman-qt Summary: qt bindings for connman -Version: 0.2.2 +Version: 0.3.0 Release: 1 Group: System/GUI/Other License: Apache License
