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/7900 Thank You, lpotter [This message was auto-generated] --- Request # 7900: Messages from BOSS: State: review at 2013-02-14T18:27:18 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:lpotter:branches:CE:MW:Shared / connman-qt -> CE:MW:Shared / connman-qt changes files: -------------- --- connman-qt.changes +++ connman-qt.changes @@ -0,0 +1,9 @@ +* Wed Feb 13 2013 Lorn Potter <[email protected]> - 0.4.3 +- bumped version to 0.4.2 +- add NetworkService, NetworkManager and NetworkTechnology to declarative plugin +- make more declarative friendly +- update xml files to new qtproject + +* Fri Jan 4 2013 Lorn Potter <[email protected]> - 0.4.1 +- Add ConnectRequest to agent API + old: ---- connman-qt-0.4.0.tar.bz2 new: ---- connman-qt-0.4.3.tar.bz2 spec files: ----------- --- connman-qt.spec +++ connman-qt.spec @@ -9,14 +9,14 @@ # << macros Summary: qt bindings for connman -Version: 0.4.0 +Version: 0.4.3 Release: 1 Group: System/GUI/Other License: Apache License -URL: http://www.meego.com +URL: https://github.com/nemomobile/libconnman-qt.git Source0: %{name}-%{version}.tar.bz2 Source100: connman-qt.yaml -Requires: connman >= 1.1 +Requires: connman >= 1.10 Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig BuildRequires: pkgconfig(QtCore) >= 4.6.0 other changes: -------------- ++++++ connman-qt-0.4.0.tar.bz2 -> connman-qt-0.4.3.tar.bz2 --- connman-qt.pro +++ connman-qt.pro @@ -1,4 +1,5 @@ TEMPLATE = subdirs -SUBDIRS += libconnman-qt test plugin +SUBDIRS += libconnman-qt plugin +SUBDIRS += test CONFIG += ordered --- libconnman-qt/connman-clock.xml +++ libconnman-qt/connman-clock.xml @@ -4,7 +4,7 @@ <interface name="net.connman.Clock"> <method name="GetProperties"> <arg type="a{sv}" direction="out"/> - <annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="QVariantMap"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/> </method> <method name="SetProperty"> <arg type="s" direction="in"/> --- libconnman-qt/connman-manager.xml +++ libconnman-qt/connman-manager.xml @@ -4,7 +4,7 @@ <method name="GetProperties" tp:name-for-bindings="Get_Properties"> <arg name="properties" type="a{sv}" direction="out"/> - <annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="QVariantMap"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/> </method> <method name="SetProperty" tp:name-for-bindings="Set_Property"> @@ -14,12 +14,12 @@ <method name="GetTechnologies" tp:name-for-bindings="Get_Technologies"> <arg name="technologies" type="a(oa{sv})" direction="out"/> - <annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="ConnmanObjectList"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="ConnmanObjectList"/> </method> <method name="GetServices" tp:name-for-bindings="Get_Services"> <arg name="services" type="a(oa{sv})" direction="out"/> - <annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="ConnmanObjectList"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="ConnmanObjectList"/> </method> <method name="RegisterAgent" tp:name-for-bindings="Register_Agent"> @@ -39,12 +39,6 @@ <method name="UnregisterCounter" tp:name-for-bindings="Unregister_Counter"> <arg name="path" type="o"/> </method> - - <method name="CreateSession" tp:name-for-bindings="Create_Session"> - <arg name="settings" type="a{sv}"> - <arg name="notifier" type="o"/> - </method> - <method name="DestroySession" tp:name-for-bindings="Destroy_Session"> <arg name="session" type="o"/> </method> @@ -54,6 +48,7 @@ <arg name="path" type="o" direction="out"/> <arg name="dict" type="a{sv}" direction="out"/> <arg name="fd" type="i" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVariantMap"/> </method> <method name="ReleasePrivateNetwork" tp:name-for-bindings="Release_Private_Network"> @@ -63,7 +58,7 @@ <signal name="TechnologyAdded" tp:name-for-bindings="Technology_Added"> <arg name="technology" type="o"/> <arg name="properties" type="a{sv}"/> - <annotation name="com.trolltech.QtDBus.QtTypeName.In1" value="QVariantMap"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="QVariantMap"/> </signal> <signal name="TechnologyRemoved" tp:name-for-bindings="Technology_Removed"> @@ -73,7 +68,7 @@ <signal name="ServicesChanged" tp:name-for-bindings="Services_Changed"> <arg name="changed" type="a(oa{sv})"/> <arg name="removed" type="ao"/> - <annotation name="com.trolltech.QtDBus.QtTypeName.In0" value="ConnmanObjectList"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="ConnmanObjectList"/> </signal> <signal name="PropertyChanged" tp:name-for-bindings="Property_Changed"> @@ -81,5 +76,13 @@ <arg name="value" type="v"/> </signal> + <method name="CreateSession" tp:name-for-bindings="Create_Session"> + <arg name="settings" type="a{sv}"> + <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVariantMap"/> + <arg name="notifier" type="o"/> + <arg type="o" direction="out"/> + </method> + + </interface> </node> --- libconnman-qt/connman-notification.xml +++ libconnman-qt/connman-notification.xml @@ -6,6 +6,7 @@ <method name="Update" tp:name-for-bindings="Update"/> <arg name="settings" type="a{sv}"> + <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value=QVariantMap"/> </method> </interface> --- libconnman-qt/connman-service.xml +++ libconnman-qt/connman-service.xml @@ -4,7 +4,7 @@ <method name="GetProperties" tp:name-for-bindings="Get_Properties"> <arg name="properties" type="a{sv}" direction="out"/> - <annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="QVariantMap"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/> </method> <method name="SetProperty" tp:name-for-bindings="Set_Property"> --- libconnman-qt/connman-session.xml +++ libconnman-qt/connman-session.xml @@ -15,6 +15,7 @@ <method name="Update" tp:name-for-bindings="Update"/> <arg name="settings" type="a{sv}"> + <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value=QVariantMap"/> </method> </interface> --- libconnman-qt/connman-technology.xml +++ libconnman-qt/connman-technology.xml @@ -2,6 +2,11 @@ <node name="/Service" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> <interface name="net.connman.Technology"> + <method name="GetProperties" tp:name-for-bindings="Get_Properties"> + <arg name="properties" type="a{sv}" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/> + </method> + <method name="SetProperty" tp:name-for-bindings="Set_Property"> <arg name="name" type="s"/> <arg name="value" type="v"/> --- libconnman-qt/manager.cpp +++ libconnman-qt/manager.cpp @@ -2,7 +2,7 @@ * This file was generated by qdbusxml2cpp version 0.7 * Command line was: qdbusxml2cpp -c Manager -p manager -N connman-manager.xml * - * qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + * qdbusxml2cpp is Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). * * This is an auto-generated file. * This file may have been hand-edited. Look for HAND-EDIT comments --- libconnman-qt/manager.h +++ libconnman-qt/manager.h @@ -92,15 +92,13 @@ return asyncCallWithArgumentList(QLatin1String("UnregisterCounter"), argumentList); } - inline QDBusPendingReply<> CreateSession(const QVariantMap &settings, const QDBusObjectPath ¬ifier) + inline QDBusPendingReply<QDBusObjectPath> CreateSession(const QVariantMap &settings, const QDBusObjectPath ¬ifier) { QList<QVariant> argumentList; - argumentList << QVariant::fromValue(settings); - argumentList << QVariant::fromValue(notifier); + argumentList << QVariant::fromValue(settings) << QVariant::fromValue(notifier); return asyncCallWithArgumentList(QLatin1String("CreateSession"), argumentList); } - inline QDBusPendingReply<> DestroySession(const QDBusObjectPath &path) { QList<QVariant> argumentList; --- libconnman-qt/networkmanager.cpp +++ libconnman-qt/networkmanager.cpp @@ -32,16 +32,12 @@ NetworkManager::NetworkManager(QObject* parent) : QObject(parent), m_manager(NULL), - m_getPropertiesWatcher(NULL), - m_getTechnologiesWatcher(NULL), - m_getServicesWatcher(NULL), m_defaultRoute(NULL), watcher(NULL), m_available(false) { registerCommonDataTypes(); - watcher = new QDBusServiceWatcher("net.connman",QDBusConnection::systemBus(), QDBusServiceWatcher::WatchForRegistration | QDBusServiceWatcher::WatchForUnregistration, this); @@ -55,9 +51,13 @@ if(m_available) connectToConnman(); + else + qDebug() << "connman not AVAILABLE"; } -NetworkManager::~NetworkManager() {} +NetworkManager::~NetworkManager() +{ +} void NetworkManager::connectToConnman(QString) { @@ -67,8 +67,6 @@ if (!m_manager->isValid()) { - pr_dbg() << "D-Bus net.connman.Manager object is invalid. Connman may not be running or is invalid."; - delete m_manager; m_manager = NULL; @@ -76,26 +74,20 @@ if(m_available) emit availabilityChanged(m_available = false); } else { + QDBusPendingReply<QVariantMap> props_reply = m_manager->GetProperties(); - m_getPropertiesWatcher = new QDBusPendingCallWatcher(props_reply, m_manager); - connect(m_getPropertiesWatcher, - SIGNAL(finished(QDBusPendingCallWatcher*)), - this, - SLOT(getPropertiesReply(QDBusPendingCallWatcher*))); + if (!props_reply.isError()) { + m_propertiesCache = props_reply.value(); - QDBusPendingReply<ConnmanObjectList> techs_reply = m_manager->GetTechnologies(); - m_getTechnologiesWatcher = new QDBusPendingCallWatcher(techs_reply, m_manager); - connect(m_getTechnologiesWatcher, - SIGNAL(finished(QDBusPendingCallWatcher*)), - this, - SLOT(getTechnologiesReply(QDBusPendingCallWatcher*))); + emit stateChanged(m_propertiesCache[State].toString()); - QDBusPendingReply<ConnmanObjectList> services_reply = m_manager->GetServices(); - m_getServicesWatcher = new QDBusPendingCallWatcher(services_reply, m_manager); - connect(m_getServicesWatcher, - SIGNAL(finished(QDBusPendingCallWatcher*)), - this, - SLOT(getServicesReply(QDBusPendingCallWatcher*))); + connect(m_manager, + SIGNAL(PropertyChanged(const QString&, const QDBusVariant&)), + this, + SLOT(propertyChanged(const QString&, const QDBusVariant&))); + } + setupTechnologies(); + setupServices(); if(!m_available) emit availabilityChanged(m_available = true); @@ -122,70 +114,18 @@ emit availabilityChanged(m_available = false); } - -// These functions is a part of setup procedure - -void NetworkManager::getPropertiesReply(QDBusPendingCallWatcher *call) -{ - Q_ASSERT(call); - - pr_dbg() << "Got reply with manager's properties"; - - QDBusPendingReply<QVariantMap> reply = *call; - if (reply.isError()) { - - 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()); - - connect(m_manager, - SIGNAL(PropertyChanged(const QString&, const QDBusVariant&)), - this, - SLOT(propertyChanged(const QString&, const QDBusVariant&))); - } -} - -void NetworkManager::getTechnologiesReply(QDBusPendingCallWatcher *call) +void NetworkManager::setupTechnologies() { - Q_ASSERT(call); - - pr_dbg() << "Got reply with technolgies"; - - QDBusPendingReply<ConnmanObjectList> reply = *call; - if (reply.isError()) { - - pr_dbg() << "Error getTechnologiesReply:" << reply.error().message(); - - disconnectFromConnman(); - - // TODO: set up timer to reconnect in a bit - //QTimer::singleShot(10000,this,SLOT(connectToConnman())); - } else { - + QDBusPendingReply<ConnmanObjectList> reply = m_manager->GetTechnologies(); + if (!reply.isError()) { ConnmanObjectList lst = reply.value(); ConnmanObject obj; foreach (obj, lst) { // TODO: consider optimizations NetworkTechnology *tech = new NetworkTechnology(obj.objpath.path(), - obj.properties, this); + obj.properties, this); m_technologiesCache.insert(tech->type(), tech); - - pr_dbg() << "Technology: " << tech->type(); - pr_dbg() << "\tConnected:" << tech->connected(); - pr_dbg() << "\tPowered:" << tech->powered(); } connect(m_manager, @@ -202,22 +142,10 @@ } } -void NetworkManager::getServicesReply(QDBusPendingCallWatcher *call) +void NetworkManager::setupServices() { - Q_ASSERT(call); - - pr_dbg() << "Got reply with services"; - - QDBusPendingReply<ConnmanObjectList> reply = *call; - if (reply.isError()) { - - pr_dbg() << "Error getServicesReply:" << reply.error().message(); - - disconnectFromConnman(); - - // TODO: set up timer to reconnect in a bit - //QTimer::singleShot(10000,this,SLOT(connectToConnman())); - } else { + QDBusPendingReply<ConnmanObjectList> reply = m_manager->GetServices(); + if (!reply.isError()) { ConnmanObjectList lst = reply.value(); ConnmanObject obj; @@ -231,13 +159,11 @@ order++; service = new NetworkService(obj.objpath.path(), - obj.properties, this); + obj.properties, this); m_servicesCache.insert(obj.objpath.path(), service); 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) @@ -260,10 +186,9 @@ void NetworkManager::updateServices(const ConnmanObjectList &changed, const QList<QDBusObjectPath> &removed) { - pr_dbg() << "Number of services that changed: " << changed.size(); foreach (QDBusObjectPath obj, removed) { - pr_dbg() << "Removing " << obj.path(); + Q_EMIT serviceRemoved(obj.path()); m_servicesCache.value(obj.path())->deleteLater(); m_servicesCache.remove(obj.path()); } @@ -274,20 +199,21 @@ // make sure we don't leak memory m_servicesOrder.clear(); - + QStringList serviceList; foreach (connmanobj, changed) { order++; if (!m_servicesCache.contains(connmanobj.objpath.path())) { service = new NetworkService(connmanobj.objpath.path(), - connmanobj.properties, this); + connmanobj.properties, this); m_servicesCache.insert(connmanobj.objpath.path(), service); - pr_dbg() << "Added service " << connmanobj.objpath.path(); + Q_EMIT serviceAdded(connmanobj.objpath.path()); } else { service = m_servicesCache.value(connmanobj.objpath.path()); } m_servicesOrder.push_back(service); + serviceList.push_back(service->path()); if (order == 0) updateDefaultRoute(service); @@ -297,6 +223,7 @@ updateDefaultRoute(NULL); emit servicesChanged(); + Q_EMIT servicesListChanged(serviceList); } void NetworkManager::updateDefaultRoute(NetworkService* defaultRoute) @@ -312,9 +239,6 @@ { 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(tmp.toString()); @@ -332,18 +256,13 @@ 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 + // if we weren'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()) { @@ -459,12 +378,11 @@ QDBusObjectPath NetworkManager::createSession(const QVariantMap &settings, const QString &sessionNotifierPath) { - qDebug() << Q_FUNC_INFO << sessionNotifierPath << m_manager; - QDBusPendingReply<QDBusObjectPath> reply; if(m_manager) reply = m_manager->CreateSession(settings,QDBusObjectPath(sessionNotifierPath)); - return reply; + reply.waitForFinished(); + return reply.value(); } void NetworkManager::destroySession(const QString &sessionAgentPath) @@ -476,10 +394,37 @@ void NetworkManager::setSessionMode(const bool &sessionMode) { if(m_manager) - m_manager->SetProperty(SessionMode, QDBusVariant(QVariant(sessionMode))); + m_manager->SetProperty(SessionMode, QDBusVariant(sessionMode)); } bool NetworkManager::sessionMode() const { return m_propertiesCache[SessionMode].toBool(); } + +QStringList NetworkManager::servicesList(const QString &tech) +{ + QStringList services; + foreach (NetworkService *service, m_servicesOrder) { + if (tech.isEmpty() || service->type() == tech) + services.push_back(service->path()); + } + return services; +} + +QString NetworkManager::technologyPathForService(const QString &servicePath) +{ + foreach (NetworkService *service, m_servicesOrder) { + if (service->path() == servicePath) + return service->path(); + } + return QString(); +} +QString NetworkManager::technologyPathForType(const QString &techType) +{ + foreach (NetworkTechnology *tech, m_technologiesCache) { + if (tech->type() == techType) + return tech->path(); + } + return QString(); +} --- libconnman-qt/networkmanager.h +++ libconnman-qt/networkmanager.h @@ -30,14 +30,15 @@ class NetworkManager : public QObject { - Q_OBJECT; + Q_OBJECT - Q_PROPERTY(bool available READ isAvailable NOTIFY availabilityChanged); - Q_PROPERTY(QString state READ state NOTIFY stateChanged); - Q_PROPERTY(bool offlineMode READ offlineMode WRITE setOfflineMode NOTIFY offlineModeChanged); - Q_PROPERTY(NetworkService* defaultRoute READ defaultRoute NOTIFY defaultRouteChanged); + Q_PROPERTY(bool available READ isAvailable NOTIFY availabilityChanged) + Q_PROPERTY(QString state READ state NOTIFY stateChanged) + Q_PROPERTY(bool offlineMode READ offlineMode WRITE setOfflineMode NOTIFY offlineModeChanged) + Q_PROPERTY(NetworkService* defaultRoute READ defaultRoute NOTIFY defaultRouteChanged) - Q_PROPERTY(bool sessionMode READ sessionMode WRITE setSessionMode NOTIFY sessionModeChanged); + Q_PROPERTY(bool sessionMode READ sessionMode WRITE setSessionMode NOTIFY sessionModeChanged) + Q_PROPERTY(QString serviceAdded NOTIFY serviceAdded) public: NetworkManager(QObject* parent=0); @@ -49,6 +50,12 @@ const QVector<NetworkTechnology *> getTechnologies() const; const QVector<NetworkService*> getServices(const QString &tech = "") const; + Q_INVOKABLE QStringList servicesList(const QString &tech); + Q_INVOKABLE QStringList technologiesList(); + Q_INVOKABLE QString technologyPathForService(const QString &path); + Q_INVOKABLE QString technologyPathForType(const QString &type); + + const QString state() const; bool offlineMode() const; NetworkService* defaultRoute() const; @@ -75,11 +82,13 @@ void servicesChanged(); void defaultRouteChanged(NetworkService* defaultRoute); void sessionModeChanged(bool); + void servicesListChanged(const QStringList &list); + void serviceAdded(const QString &servicePath); + void serviceRemoved(const QString &servicePath); private: Manager *m_manager; - QDBusPendingCallWatcher *m_getPropertiesWatcher; QDBusPendingCallWatcher *m_getTechnologiesWatcher; QDBusPendingCallWatcher *m_getServicesWatcher; @@ -101,6 +110,7 @@ static const QString State; static const QString OfflineMode; static const QString SessionMode; + QStringList m_servicesList; bool m_available; @@ -108,9 +118,8 @@ void connectToConnman(QString = ""); void disconnectFromConnman(QString = ""); void connmanUnregistered(QString = ""); - void getPropertiesReply(QDBusPendingCallWatcher *call); - void getTechnologiesReply(QDBusPendingCallWatcher *call); - void getServicesReply(QDBusPendingCallWatcher *call); + void setupTechnologies(); + void setupServices(); void propertyChanged(const QString &name, const QDBusVariant &value); void updateServices(const ConnmanObjectList &changed, const QList<QDBusObjectPath> &removed); void updateDefaultRoute(NetworkService* defaultRoute); --- libconnman-qt/networkservice.cpp +++ libconnman-qt/networkservice.cpp @@ -57,22 +57,18 @@ NetworkService::NetworkService(const QString &path, const QVariantMap &properties, QObject* parent) : QObject(parent), m_service(NULL), - m_path(path) + m_path(QString()) { - Q_ASSERT(!m_path.isEmpty()); - m_service = new Service("net.connman", m_path, QDBusConnection::systemBus(), this); - - if (!m_service->isValid()) { - pr_dbg() << "Invalid service: " << m_path; - throw -1; // FIXME - } - + Q_ASSERT(!path.isEmpty()); + setPath(path); m_propertiesCache = properties; +} - connect(m_service, - SIGNAL(PropertyChanged(const QString&, const QDBusVariant&)), - this, - SLOT(updateProperty(const QString&, const QDBusVariant&))); +NetworkService::NetworkService(QObject* parent) + : QObject(parent), + m_service(NULL), + m_path(QString()) +{ } NetworkService::~NetworkService() {} @@ -85,10 +81,6 @@ return m_propertiesCache.value(State).toString(); } -const QString NetworkService::error() const { - return m_propertiesCache.value(Error).toString(); -} - const QString NetworkService::type() const { return m_propertiesCache.value(Type).toString(); } @@ -169,11 +161,11 @@ QDBusPendingReply<> conn_reply = m_service->Connect(); m_service->setTimeout(old_timeout); - m_connectReqWatcher = new QDBusPendingCallWatcher(conn_reply, m_service); - connect(m_connectReqWatcher, + dbg_connectWatcher = new QDBusPendingCallWatcher(conn_reply, m_service); + connect(dbg_connectWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, - SLOT(handleConnectReply(QDBusPendingCallWatcher*))); + SLOT(dbg_connectReply(QDBusPendingCallWatcher*))); } void NetworkService::requestDisconnect() @@ -222,35 +214,30 @@ m_service->SetProperty(ProxyConfig, QDBusVariant(QVariant(adaptToConnmanProperties(proxy)))); } -void NetworkService::handleConnectReply(QDBusPendingCallWatcher *call) +/* this slot is used for debugging */ +void NetworkService::dbg_connectReply(QDBusPendingCallWatcher *call) { + pr_dbg() << "Got something from service.connect()"; Q_ASSERT(call); QDBusPendingReply<> reply = *call; - if (!reply.isFinished()) { pr_dbg() << "connect() not finished yet"; } if (reply.isError()) { pr_dbg() << "Reply from service.connect(): " << reply.error().message(); - emit connectRequestFailed(reply.error().message()); } } -void NetworkService::updateProperty(const QString &name, const QDBusVariant &value) +void NetworkService::propertyChanged(const QString &name, const QDBusVariant &value) { 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(tmp.toString()); - } else if (name == Error) { - emit errorChanged(tmp.toString()); } else if (name == State) { emit stateChanged(tmp.toString()); } else if (name == Security) { @@ -283,5 +270,34 @@ emit proxyConfigChanged(qdbus_cast<QVariantMap>(m_propertiesCache.value(ProxyConfig))); } else if (name == Ethernet) { emit ethernetChanged(qdbus_cast<QVariantMap>(m_propertiesCache.value(Ethernet))); + } else if (name == QLatin1String("type")) { + Q_EMIT typeChanged(tmp.toString()); + } +} + +void NetworkService::setPath(const QString &path) +{ + if (path != m_path) { + m_path = path; + + if (m_service) { + delete m_service; + m_service = 0; + } + m_service = new Service("net.connman", m_path, QDBusConnection::systemBus(), this); + + if (!m_service->isValid()) { + pr_dbg() << "Invalid service: " << m_path; + return; + } + QDBusPendingReply<QVariantMap> reply = m_service->GetProperties(); + if (reply.isError()) { + qDebug() << Q_FUNC_INFO << reply.error().message(); + } else { + m_propertiesCache = reply.value(); + } + + connect(m_service, SIGNAL(PropertyChanged(QString,QDBusVariant)), + this, SLOT(propertyChanged(QString,QDBusVariant))); } } --- libconnman-qt/networkservice.h +++ libconnman-qt/networkservice.h @@ -22,36 +22,35 @@ { Q_OBJECT; - Q_PROPERTY(QString name READ name NOTIFY nameChanged); - Q_PROPERTY(QString state READ state NOTIFY stateChanged); - Q_PROPERTY(QString error READ error NOTIFY errorChanged); - Q_PROPERTY(QString type READ type); - 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); + Q_PROPERTY(QString name READ name NOTIFY nameChanged) + Q_PROPERTY(QString state READ state NOTIFY stateChanged) + Q_PROPERTY(QString type READ type NOTIFY typeChanged) + 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 WRITE setPath 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); Q_UNUSED(parent); }; + NetworkService(QObject* parent = 0); + virtual ~NetworkService(); const QString name() const; const QString type() const; const QString state() const; - const QString error() const; const QStringList security() const; bool autoConnect() const; uint strength() const; @@ -69,10 +68,11 @@ const QVariantMap proxyConfig() const; const QVariantMap ethernet() const; + void setPath(const QString &path); + signals: void nameChanged(const QString &name); void stateChanged(const QString &state); - void errorChanged(const QString &error); void securityChanged(const QStringList &security); void strengthChanged(const uint strength); void favoriteChanged(const bool &favorite); @@ -89,7 +89,7 @@ void proxyChanged(const QVariantMap &proxy); void proxyConfigChanged(const QVariantMap &proxy); void ethernetChanged(const QVariantMap ðernet); - void connectRequestFailed(const QString &error); + void typeChanged(const QString &type); public slots: void requestConnect(); @@ -108,7 +108,7 @@ QString m_path; QVariantMap m_propertiesCache; - QDBusPendingCallWatcher *m_connectReqWatcher; + QDBusPendingCallWatcher *dbg_connectWatcher; static const QString Name; static const QString State; @@ -131,8 +131,8 @@ static const QString Ethernet; private slots: - void updateProperty(const QString &name, const QDBusVariant &value); - void handleConnectReply(QDBusPendingCallWatcher *call); + void propertyChanged(const QString &name, const QDBusVariant &value); + void dbg_connectReply(QDBusPendingCallWatcher *call); private: Q_DISABLE_COPY(NetworkService); --- libconnman-qt/networksession.cpp +++ libconnman-qt/networksession.cpp @@ -15,21 +15,24 @@ m_sessionAgent(0), m_path("/ConnmanQmlSessionAgent") { + createSession(); } NetworkSession::~NetworkSession() { } -void NetworkSession::registerSession() +void NetworkSession::createSession() { if (m_path.isEmpty()) return; + if (m_sessionAgent) { + delete m_sessionAgent; + m_sessionAgent = 0; + } m_sessionAgent = new SessionAgent(m_path ,this); connect(m_sessionAgent,SIGNAL(settingsUpdated(QVariantMap)), this,SLOT(sessionSettingsUpdated(QVariantMap))); - - m_sessionAgent->registerSession(); } QString NetworkSession::state() const @@ -74,13 +77,13 @@ void NetworkSession::setAllowedBearers(const QStringList &bearers) { - settingsMap.insert("AllowedBearers", qVariantFromValue(bearers)); + settingsMap.insert("AllowedBearers", qVariantFromValue(bearers)); m_sessionAgent->setAllowedBearers(bearers); } void NetworkSession::setConnectionType(const QString &type) { - settingsMap.insert("ConnectionType", qVariantFromValue(type)); + settingsMap.insert("ConnectionType", qVariantFromValue(type)); m_sessionAgent->setConnectionType(type); } @@ -103,6 +106,24 @@ { Q_FOREACH(const QString &name, settings.keys()) { settingsMap.insert(name,settings[name]); + + if (name == QLatin1String("State")) { + Q_EMIT stateChanged(settings[name].toString()); + } else if (name == QLatin1String("Name")) { + Q_EMIT nameChanged(settings[name].toString()); + } else if (name == QLatin1String("Bearer")) { + Q_EMIT bearerChanged(settings[name].toString()); + } else if (name == QLatin1String("Interface")) { + Q_EMIT sessionInterfaceChanged(settings[name].toString()); + } else if (name == QLatin1String("IPv4")) { + Q_EMIT ipv4Changed(ipv4()); + } else if (name == QLatin1String("IPv6")) { + Q_EMIT ipv6Changed(ipv6()); + } else if (name == QLatin1String("AllowedBearers")) { + Q_EMIT allowedBearersChanged(allowedBearers()); + } else if (name == QLatin1String("ConnectionType")) { + Q_EMIT connectionTypeChanged(settings[name].toString()); + } } Q_EMIT settingsChanged(settings); } @@ -114,5 +135,8 @@ void NetworkSession::setPath(const QString &path) { - m_path = path; + if (path != m_path) { + m_path = path; + createSession(); + } } --- libconnman-qt/networksession.h +++ libconnman-qt/networksession.h @@ -19,12 +19,12 @@ class NetworkSession : public QObject { Q_OBJECT - Q_PROPERTY(QString state READ state) - Q_PROPERTY(QString name READ name) - Q_PROPERTY(QString bearer READ bearer) - Q_PROPERTY(QString sessionInterface READ sessionInterface) - Q_PROPERTY(QVariantMap ipv4 READ ipv4) - Q_PROPERTY(QVariantMap ipv6 READ ipv6) + Q_PROPERTY(QString state READ state NOTIFY stateChanged) + Q_PROPERTY(QString name READ name NOTIFY nameChanged) + Q_PROPERTY(QString bearer READ bearer NOTIFY bearerChanged) + Q_PROPERTY(QString sessionInterface READ sessionInterface NOTIFY sessionInterfaceChanged) + Q_PROPERTY(QVariantMap ipv4 READ ipv4 NOTIFY ipv4Changed) + Q_PROPERTY(QVariantMap ipv6 READ ipv6 NOTIFY ipv6Changed) Q_PROPERTY(QString path READ path WRITE setPath) @@ -56,18 +56,25 @@ void connectionTypeChanged(const QString &type); void settingsChanged(const QVariantMap &settings); + void stateChanged(const QString &state); + void nameChanged(const QString &name); + void bearerChanged(const QString &bearer); + void sessionInterfaceChanged(const QString &sessionInterface); + void ipv4Changed(const QVariantMap&settings); + void ipv6Changed(const QVariantMap&settings); + public slots: void requestDestroy(); void requestConnect(); void requestDisconnect(); void sessionSettingsUpdated(const QVariantMap &settings); void setPath(const QString &path); - void registerSession(); private: SessionAgent *m_sessionAgent; QVariantMap settingsMap; QString m_path; + void createSession(); }; #endif // SESSIONSERVICE_H --- libconnman-qt/networktechnology.cpp +++ libconnman-qt/networktechnology.cpp @@ -16,13 +16,39 @@ const QString NetworkTechnology::Type("Type"); const QString NetworkTechnology::Powered("Powered"); const QString NetworkTechnology::Connected("Connected"); +const QString NetworkTechnology::State("State"); NetworkTechnology::NetworkTechnology(const QString &path, const QVariantMap &properties, QObject* parent) : QObject(parent), m_technology(NULL), - m_scanWatcher(NULL) + m_scanWatcher(NULL), + m_path(QString()) { Q_ASSERT(!path.isEmpty()); + m_propertiesCache = properties; + init(path); +} + +NetworkTechnology::NetworkTechnology(QObject* parent) + : QObject(parent), + m_technology(NULL), + m_scanWatcher(NULL), + m_path(QString()) +{ +} + +NetworkTechnology::~NetworkTechnology() +{ +} + +void NetworkTechnology::init(const QString &path) +{ + m_path = path; + + if (m_technology) { + delete m_technology; + m_technology = 0; + } m_technology = new Technology("net.connman", path, QDBusConnection::systemBus(), this); if (!m_technology->isValid()) { @@ -30,15 +56,18 @@ throw -1; // FIXME } - m_propertiesCache = properties; + if (m_propertiesCache.isEmpty()) { + QDBusReply<QVariantMap> reply; + reply = m_technology->GetProperties(); + m_propertiesCache = reply.value(); + } connect(m_technology, SIGNAL(PropertyChanged(const QString&, const QDBusVariant&)), this, SLOT(propertyChanged(const QString&, const QDBusVariant&))); -} -NetworkTechnology::~NetworkTechnology() {} +} // Public API @@ -46,22 +75,34 @@ const QString NetworkTechnology::name() const { - return m_propertiesCache[NetworkTechnology::Name].toString(); + if (m_propertiesCache.contains(NetworkTechnology::Name)) + return m_propertiesCache[NetworkTechnology::Name].toString(); + else + return QString(); } const QString NetworkTechnology::type() const { - return m_propertiesCache[NetworkTechnology::Type].toString(); + if (m_propertiesCache.contains(NetworkTechnology::Type)) + return m_propertiesCache[NetworkTechnology::Type].toString(); + else + return QString(); } bool NetworkTechnology::powered() const { - return m_propertiesCache[NetworkTechnology::Powered].toBool(); + if (m_propertiesCache.contains(NetworkTechnology::Powered)) + return m_propertiesCache[NetworkTechnology::Powered].toBool(); + else + return false; } bool NetworkTechnology::connected() const { - return m_propertiesCache[NetworkTechnology::Connected].toBool(); + if (m_propertiesCache.contains(NetworkTechnology::Connected)) + return m_propertiesCache[NetworkTechnology::Connected].toBool(); + else + return false; } const QString NetworkTechnology::objPath() const @@ -97,15 +138,14 @@ 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(tmp.toBool()); } else if (name == Connected) { emit connectedChanged(tmp.toBool()); + } else if (name == State) { + Q_EMIT stateChanged(tmp.toString()); } } @@ -113,7 +153,22 @@ { Q_UNUSED(call); - pr_dbg() << "Scan Finished"; - emit scanFinished(); } + +QString NetworkTechnology::state() const +{ + return m_propertiesCache[NetworkTechnology::State].toString(); +} + +QString NetworkTechnology::path() const +{ + return m_path; +} + +void NetworkTechnology::setPath(const QString &path) +{ + if (path != m_path) { + init(path); + } +} --- libconnman-qt/networktechnology.h +++ libconnman-qt/networktechnology.h @@ -17,15 +17,20 @@ class NetworkTechnology : public QObject { - Q_OBJECT; + Q_OBJECT - Q_PROPERTY(QString name READ name); - Q_PROPERTY(QString type READ type); - Q_PROPERTY(bool powered READ powered WRITE setPowered NOTIFY poweredChanged); - Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged); + Q_PROPERTY(QString name READ name) + Q_PROPERTY(QString type READ type) + Q_PROPERTY(bool powered READ powered WRITE setPowered NOTIFY poweredChanged) + Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged) + Q_PROPERTY(QString state READ state NOTIFY stateChanged) + + Q_PROPERTY(QString path READ path WRITE setPath) public: NetworkTechnology(const QString &path, const QVariantMap &properties, QObject* parent); + NetworkTechnology(QObject* parent=0); + virtual ~NetworkTechnology(); const QString name() const; @@ -33,15 +38,20 @@ bool powered() const; bool connected() const; const QString objPath() const; + QString state() const; + + QString path() const; public slots: void setPowered(const bool &powered); void scan(); + void setPath(const QString &path); signals: void poweredChanged(const bool &powered); void connectedChanged(const bool &connected); void scanFinished(); + void stateChanged(const QString &state); private: Technology *m_technology; @@ -52,13 +62,18 @@ static const QString Type; static const QString Powered; static const QString Connected; + static const QString State; + + QString m_path; + void init(const QString &path); + private slots: void propertyChanged(const QString &name, const QDBusVariant &value); void scanReply(QDBusPendingCallWatcher *call); private: - Q_DISABLE_COPY(NetworkTechnology); + Q_DISABLE_COPY(NetworkTechnology) }; #endif //NETWORKTECHNOLOGY_H --- libconnman-qt/sessionagent.cpp +++ libconnman-qt/sessionagent.cpp @@ -30,16 +30,17 @@ SessionAgent::SessionAgent(const QString &path, QObject* parent) : QObject(parent), agentPath(path), - m_session(0) + m_session(0), + m_manager(NetworkManagerFactory::createInstance()) { - m_manager = new Manager("net.connman", "/", QDBusConnection::systemBus(), this); - const QString sessionmode = "SessionMode"; - m_manager->SetProperty(sessionmode, QDBusVariant(true)); + m_manager->setSessionMode(true); + createSession(); } SessionAgent::~SessionAgent() { - m_manager->DestroySession(QDBusObjectPath(agentPath)); + m_manager->setSessionMode(false); + m_manager->destroySession(agentPath); } void SessionAgent::setAllowedBearers(const QStringList &bearers) @@ -48,7 +49,11 @@ return; QVariantMap map; map.insert("AllowedBearers", qVariantFromValue(bearers)); - m_session->Change("AllowedBearers",QDBusVariant(bearers)); + QDBusPendingReply<> reply = m_session->Change("AllowedBearers",QDBusVariant(bearers)); + if (reply.isError()) { + qDebug() << Q_FUNC_INFO << reply.error(); + } + } void SessionAgent::setConnectionType(const QString &type) @@ -60,20 +65,32 @@ m_session->Change("ConnectionType",QDBusVariant(type)); } -void SessionAgent::registerSession() +void SessionAgent::createSession() { - if (m_manager->isValid()) { - QDBusPendingReply<QDBusObjectPath> obpath = m_manager->CreateSession(QVariantMap(),QDBusObjectPath(agentPath)); - m_session = new Session(obpath.value().path(), this); - new SessionNotificationAdaptor(this); - QDBusConnection::systemBus().registerObject(agentPath, this); + if (m_manager->isAvailable()) { + QDBusObjectPath obpath = m_manager->createSession(QVariantMap(),agentPath); + if (!obpath.path().isEmpty()) { + m_session = new Session(obpath.path(), this); + new SessionNotificationAdaptor(this); + QDBusConnection::systemBus().unregisterObject(agentPath); + if (!QDBusConnection::systemBus().registerObject(agentPath, this)) { + qDebug() << "Could not register agent object"; + } + } else { + qDebug() << "agentPath is not valid" << agentPath; + } + } else { + qDebug() << Q_FUNC_INFO << "manager not valid"; } } void SessionAgent::requestConnect() { - if (m_session) - m_session->Connect(); + if (m_session) { + QDBusPendingReply<> reply = m_session->Connect(); + if (reply.isError()) + qDebug() << reply.error().message(); + } } void SessionAgent::requestDisconnect() --- libconnman-qt/sessionagent.h +++ libconnman-qt/sessionagent.h @@ -10,7 +10,7 @@ #ifndef SESSIONAGENT_H #define SESSIONAGENT_H -#include "manager.h" +#include "networkmanager.h" class Session; @@ -24,7 +24,6 @@ void setAllowedBearers(const QStringList &bearers); void setConnectionType(const QString &type); - void registerSession(); void requestConnect(); void requestDisconnect(); void requestDestroy(); @@ -32,6 +31,7 @@ public slots: void release(); void update(const QVariantMap &settings); + void createSession(); Q_SIGNALS: void settingsUpdated(const QVariantMap &settings); @@ -40,7 +40,7 @@ private: QString agentPath; QVariantMap sessionSettings; - Manager* m_manager; + NetworkManager* m_manager; Session *m_session; friend class SessionNotificationAdaptor; --- libconnman-qt/useragent.cpp +++ libconnman-qt/useragent.cpp @@ -16,6 +16,7 @@ QObject(parent), m_req_data(NULL), m_manager(NetworkManagerFactory::createInstance()) + , requestType(TYPE_DEFAULT) { new AgentAdaptor(this); // this object will be freed when UserAgent is freed QDBusConnection::systemBus().registerObject(AGENT_PATH, this); @@ -56,11 +57,13 @@ emit userInputCanceled(); } -void UserAgent::reportError(const QString &error) { +void UserAgent::reportError(const QString &error) +{ emit errorReported(error); } -void UserAgent::sendUserReply(const QVariantMap &input) { +void UserAgent::sendUserReply(const QVariantMap &input) +{ if (m_req_data == NULL) { qWarning("Got reply for non-existing request"); return; @@ -80,26 +83,86 @@ m_req_data = NULL; } -void UserAgent::updateMgrAvailability(bool &available) +void UserAgent::requestTimeout() +{ + setConnectionRequestType("Clear"); +} + +void UserAgent::sendConnectReply(const QString &replyMessage, int timeout) +{ + setConnectionRequestType(replyMessage); + QTimer::singleShot(timeout * 1000, this,SLOT(requestTimeout())); +} + +void UserAgent::updateMgrAvailability(bool available) { if (available) { m_manager->registerAgent(QString(AGENT_PATH)); } } +void UserAgent::setConnectionRequestType(const QString &type) +{ + if (type == "Suppress") { + requestType = TYPE_SUPPRESS; + } else if (type == "Clear") { + requestType = TYPE_CLEAR; + } else { + requestType = TYPE_DEFAULT; + } +} + +QString UserAgent::connectionRequestType() const +{ + switch (requestType) { + case TYPE_SUPPRESS: + return "Suppress"; + break; + case TYPE_CLEAR: + return "Clear"; + break; + default: + break; + } + return QString(); +} + +void UserAgent::requestConnect(const QDBusMessage &msg) +{ + QList<QVariant> arguments; + arguments << QVariant(connectionRequestType()); + QDBusMessage error = msg.createReply(arguments); + + if (!QDBusConnection::systemBus().send(error)) { + qDebug() << "Could not queue message"; + } + if (connectionRequestType() == "Suppress") { + return; + } + + setConnectionRequestType("Suppress"); + Q_EMIT userConnectRequested(msg); + Q_EMIT connectionRequest(); +} + +//////////////////// AgentAdaptor::AgentAdaptor(UserAgent* parent) : QDBusAbstractAdaptor(parent), m_userAgent(parent) { } -AgentAdaptor::~AgentAdaptor() {} +AgentAdaptor::~AgentAdaptor() +{ +} -void AgentAdaptor::Release() {} +void AgentAdaptor::Release() +{ +} void AgentAdaptor::ReportError(const QDBusObjectPath &service_path, const QString &error) { - pr_dbg() << "From " << service_path.path() << " got this error:\n" << error; + Q_UNUSED(service_path) m_userAgent->reportError(error); } @@ -112,8 +175,6 @@ const QVariantMap &fields, const QDBusMessage &message) { - pr_dbg() << "Service " << service_path.path() << " wants user input"; - QVariantMap json; foreach (const QString &key, fields.keys()){ QVariantMap payload = qdbus_cast<QVariantMap>(fields[key]); @@ -133,6 +194,10 @@ void AgentAdaptor::Cancel() { - pr_dbg() << "WARNING: request to agent got canceled"; m_userAgent->cancelUserInput(); } + +void AgentAdaptor::RequestConnect(const QDBusMessage &message) +{ + m_userAgent->requestConnect(message); +} --- libconnman-qt/useragent.h +++ libconnman-qt/useragent.h @@ -23,29 +23,48 @@ class UserAgent : public QObject { Q_OBJECT + Q_PROPERTY(QString connectionRequestType READ connectionRequestType WRITE setConnectionRequestType) Q_DISABLE_COPY(UserAgent) public: explicit UserAgent(QObject* parent = 0); virtual ~UserAgent(); +enum ConnectionRequestType { + TYPE_DEFAULT =0, + TYPE_SUPPRESS, + TYPE_CLEAR +}; + +public slots: + void sendUserReply(const QVariantMap &input); - Q_INVOKABLE void sendUserReply(const QVariantMap &input); + void sendConnectReply(const QString &replyMessage, int timeout = 120); + void setConnectionRequestType(const QString &type); + QString connectionRequestType() const; signals: void userInputRequested(const QString &servicePath, const QVariantList &fields); void userInputCanceled(); void errorReported(const QString &error); + void userConnectRequested(const QDBusMessage &message); + void connectionRequest(); + private slots: - void updateMgrAvailability(bool &available); + void updateMgrAvailability(bool); + + void requestTimeout(); private: void requestUserInput(ServiceRequestData* data); void cancelUserInput(); void reportError(const QString &error); + void requestConnect(const QDBusMessage &msg); ServiceRequestData* m_req_data; NetworkManager* m_manager; + QDBusMessage currentDbusMessage; + ConnectionRequestType requestType; friend class AgentAdaptor; }; @@ -63,6 +82,8 @@ void Release(); void ReportError(const QDBusObjectPath &service_path, const QString &error); void RequestBrowser(const QDBusObjectPath &service_path, const QString &url); + void RequestConnect(const QDBusMessage &message); + Q_NOREPLY void RequestInput(const QDBusObjectPath &service_path, const QVariantMap &fields, const QDBusMessage &message); --- plugin/components.cpp +++ plugin/components.cpp @@ -18,13 +18,15 @@ void Components::registerTypes(const char *uri) { - qmlRegisterUncreatableType<NetworkService>(uri,0,2,"NetworkService", - "Please don't create \"NetworkService\" objects manually."); + qmlRegisterType<NetworkService>(uri,0,2,"NetworkService"); qmlRegisterType<NetworkingModel>(uri,0,2,"NetworkingModel"); qmlRegisterType<TechnologyModel>(uri,0,2,"TechnologyModel"); qmlRegisterType<UserAgent>(uri,0,2,"UserAgent"); qmlRegisterType<ClockModel>(uri,0,2,"ClockModel"); qmlRegisterType<NetworkSession>(uri,0,2,"NetworkSession"); + qmlRegisterType<NetworkManager>(uri,0,2,"NetworkManager"); + qmlRegisterType<NetworkTechnology>(uri,0,2,"NetworkTechnology"); + } void Components::initializeEngine(QDeclarativeEngine *engine, const char *uri) --- plugin/technologymodel.cpp +++ plugin/technologymodel.cpp @@ -15,11 +15,16 @@ connect(tech, \ SIGNAL(poweredChanged(bool)), \ this, \ - SIGNAL(poweredChanged(bool))); \ + SLOT(changedPower(bool))); \ connect(tech, \ SIGNAL(scanFinished()), \ this, \ - SIGNAL(scanRequestFinished())) + SLOT(finishedScan())); \ + connect(tech, \ + SIGNAL(stateChanged(QString)), \ + this, \ + SIGNAL(stateChanged(QString))) + TechnologyModel::TechnologyModel(QAbstractListModel* parent) : QAbstractListModel(parent), @@ -109,38 +114,39 @@ if (m_techname == name) { return; } + QStringList netTypes; + netTypes << "ethernet"; + netTypes << "wifi"; + netTypes << "cellular"; + netTypes << "bluetooth"; - bool oldPowered(false); - - if (m_tech) { - oldPowered = m_tech->powered(); - disconnect(m_tech, SIGNAL(poweredChanged(bool)), - this, SIGNAL(poweredChanged(bool))); - disconnect(m_tech, SIGNAL(scanFinished()), - this, SIGNAL(scanRequestFinished())); + if (!netTypes.contains(name)) { + qDebug() << name << "is not a known technology name"; + return; } + bool oldPowered(false); + m_techname = name; m_tech = m_manager->getTechnology(m_techname); - emit nameChanged(m_techname); if (!m_tech) { if (oldPowered) { emit poweredChanged(false); } return; - } + } else { + emit nameChanged(m_techname); + if (oldPowered != m_tech->powered()) { + emit poweredChanged(!oldPowered); + } - if (oldPowered != m_tech->powered()) { - emit poweredChanged(!oldPowered); + CONNECT_TECHNOLOGY_SIGNALS(m_tech); } - - CONNECT_TECHNOLOGY_SIGNALS(m_tech); } void TechnologyModel::requestScan() const { - qDebug() << "scan requested for technology"; if (m_tech) { m_tech->scan(); } @@ -154,6 +160,7 @@ // if wifi is set and manager doesn't return a wifi, it means // that wifi was removed m_tech = NULL; + Q_EMIT technologiesChanged(); } } else { if ((test = m_manager->getTechnology(m_techname)) != NULL) { @@ -162,10 +169,9 @@ m_tech = test; CONNECT_TECHNOLOGY_SIGNALS(m_tech); + emit technologiesChanged(); } } - - emit technologiesChanged(); } void TechnologyModel::managerAvailabilityChanged(bool available) @@ -214,3 +220,17 @@ endRemoveRows(); } } + +void TechnologyModel::changedPower(bool b) +{ + NetworkTechnology *tech = qobject_cast<NetworkTechnology *>(sender()); + if (tech->type() == m_tech->type()) + Q_EMIT poweredChanged(b); +} + +void TechnologyModel::finishedScan() +{ + NetworkTechnology *tech = qobject_cast<NetworkTechnology *>(sender()); + if (tech->type() == m_tech->type()) + Q_EMIT scanRequestFinished(); +} --- plugin/technologymodel.h +++ plugin/technologymodel.h @@ -23,12 +23,12 @@ */ class TechnologyModel : public QAbstractListModel { - Q_OBJECT; - Q_DISABLE_COPY(TechnologyModel); + Q_OBJECT + Q_DISABLE_COPY(TechnologyModel) - Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged); - Q_PROPERTY(bool available READ isAvailable NOTIFY availabilityChanged); - Q_PROPERTY(bool powered READ isPowered WRITE setPowered NOTIFY poweredChanged); + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_PROPERTY(bool available READ isAvailable NOTIFY availabilityChanged) + Q_PROPERTY(bool powered READ isPowered WRITE setPowered NOTIFY poweredChanged) public: enum ItemRoles { @@ -58,6 +58,7 @@ void availabilityChanged(const bool &available); void poweredChanged(const bool &powered); void technologiesChanged(); + void stateChanged(const QString &state); void scanRequestFinished(); @@ -71,6 +72,8 @@ void updateTechnologies(); void updateServiceList(); void managerAvailabilityChanged(bool available); + void changedPower(bool); + void finishedScan(); }; #endif // TECHNOLOGYMODEL_H ++++++ connman-qt.yaml --- connman-qt.yaml +++ connman-qt.yaml @@ -1,17 +1,17 @@ Name: connman-qt Summary: qt bindings for connman -Version: 0.4.0 +Version: 0.4.3 Release: 1 Group: System/GUI/Other License: Apache License -URL: http://www.meego.com +URL: https://github.com/nemomobile/libconnman-qt.git Sources: - "%{name}-%{version}.tar.bz2" Description: | This is a library for working with connman using Qt Requires: - - connman >= 1.1 + - connman >= 1.10 PkgBR: - doxygen - qt-devel-tools
