From 668d7395ad95a0db2f3163ab2bd29e35723fc97a Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Sat, 23 Mar 2013 21:30:14 +0000 Subject: [PATCH] update to fix these and make things work better --- connd/com.jollamobile.Connectiond.xml | 5 +- connd/connadaptor.h | 8 +- connd/connd.pro | 3 +- connd/qconnectionmanager.cpp | 102 +++++++++--------- connd/qconnectionmanager.h | 5 + .../connectionagentplugin.cpp | 11 ++ connectionagentplugin/connectionagentplugin.h | 2 + .../connectionagentplugin.pro | 2 +- .../connectionamanagerinterface.h | 5 +- 9 files changed, 83 insertions(+), 60 deletions(-) diff --git a/connd/com.jollamobile.Connectiond.xml b/connd/com.jollamobile.Connectiond.xml index 208763e..1e4f17e 100644 --- a/connd/com.jollamobile.Connectiond.xml +++ b/connd/com.jollamobile.Connectiond.xml @@ -2,7 +2,7 @@ - + @@ -15,6 +15,9 @@ + + + diff --git a/connd/connadaptor.h b/connd/connadaptor.h index 307f38f..bad84e4 100644 --- a/connd/connadaptor.h +++ b/connd/connadaptor.h @@ -9,8 +9,8 @@ * before re-generating it. */ -#ifndef CONNADAPTOR_H_1363743442 -#define CONNADAPTOR_H_1363743442 +#ifndef CONNADAPTOR_H_1363752885 +#define CONNADAPTOR_H_1363752885 #include #include @@ -44,6 +44,9 @@ class ConnAdaptor: public QDBusAbstractAdaptor " \n" " \n" " \n" +" \n" +" \n" +" \n" " \n" " \n" " \n" @@ -68,6 +71,7 @@ public Q_SLOTS: // METHODS void sendUserReply(const QVariantMap &input); Q_SIGNALS: // SIGNALS void connectionRequest(); + void connectionState(const QString &state); void errorReported(const QString &error); void requestBrowser(const QString &url); void userInputCanceled(); diff --git a/connd/connd.pro b/connd/connd.pro index 5514280..6e3b784 100644 --- a/connd/connd.pro +++ b/connd/connd.pro @@ -13,6 +13,7 @@ QT -= gui INCLUDEPATH += libconnman-qt +#INCLUDEPATH += lipstick OTHER_FILES += com.jolla.Connectiond.xml @@ -29,7 +30,7 @@ HEADERS+= \ connadaptor.h LIBS += -lconnman-qt4 -# LIBS += -llipstick +#LIBS += -llipstick target.path = /usr/bin INSTALLS += target diff --git a/connd/qconnectionmanager.cpp b/connd/qconnectionmanager.cpp index c36c998..d7afcda 100644 --- a/connd/qconnectionmanager.cpp +++ b/connd/qconnectionmanager.cpp @@ -36,9 +36,11 @@ QConnectionManager* QConnectionManager::self = NULL; QConnectionManager::QConnectionManager(QObject *parent) : QObject(parent), netman(NetworkManagerFactory::createInstance()), + netService(0), okToConnect(0), currentNetworkState(QString()), - currentType(QString()) + currentType(QString()), + serviceConnect(0) { connectionAdaptor = new ConnAdaptor(this); QDBusConnection dbus = QDBusConnection::sessionBus(); @@ -99,6 +101,7 @@ void QConnectionManager::onUserInputCanceled() // from useragent void QConnectionManager::onErrorReported(const QString &error) { + qDebug() << Q_FUNC_INFO << error; Q_EMIT errorReported(error); } @@ -107,8 +110,6 @@ void QConnectionManager::onConnectionRequest() { qDebug() << Q_FUNC_INFO; if (!autoConnect()) { - qDebug() << Q_FUNC_INFO << "emit connectionRequest"; - Q_EMIT connectionRequest(); } } @@ -125,31 +126,30 @@ void QConnectionManager::sendConnectReply(const QString &in0, int in1) void QConnectionManager::sendUserReply(const QVariantMap &input) { + qDebug() << Q_FUNC_INFO << input; ua->sendUserReply(input); } void QConnectionManager::networkStateChanged(const QString &state) { + if (serviceConnect) + return; QString msg; - if (currentNetworkState == "idle" && state == "association") { + if (currentNetworkState == "idle" && state == "ready") { msg = "Connecting..."; } else if (currentNetworkState == "ready" && state == "online") { msg = "Connected"; } else if (state == "offline") { msg = "Offline"; + } else if (state == "idle") { + msg = "Disconnected"; } qDebug() << Q_FUNC_INFO << currentNetworkState << state << msg; + Q_EMIT connectionState(msg); -// NotificationManager *manager = NotificationManager::instance(); -// QVariantHash hints; -// hints.insert(NotificationManager::HINT_URGENCY, 2); -// hints.insert(NotificationManager::HINT_CATEGORY, "device.error"); -// hints.insert(NotificationManager::HINT_PREVIEW_BODY, msg); -// manager->Notify(qApp->applicationName(), 0, QString(), QString(), QString(), QStringList(), hints, -1); - -// if (!msg.isEmpty()) { -// emit serviceStateChanged(msg); -// } + // if (!msg.isEmpty()) { + // emit serviceStateChanged(msg); + // } currentNetworkState = state; } @@ -157,14 +157,19 @@ void QConnectionManager::onServiceAdded(const QString &servicePath) { // qDebug() << Q_FUNC_INFO << servicePath; if (okToConnect) { - NetworkService *netService; + if (netService) { + delete netService; + netService = 0; + } netService = new NetworkService(this); netService->setPath(servicePath); if (netService->favorite()) { + serviceConnect = true; QObject::connect(netService, SIGNAL(stateChanged(QString)), - this,SLOT(stateChanged(QString))); + this,SLOT(stateChanged(QString)), Qt::UniqueConnection); QObject::connect(netService, SIGNAL(connectRequestFailed(QString)), - this,SLOT(serviceErrorChanged(QString))); + this,SLOT(serviceErrorChanged(QString)), Qt::UniqueConnection); + netService->requestConnect(); } } @@ -173,38 +178,29 @@ void QConnectionManager::onServiceAdded(const QString &servicePath) void QConnectionManager::serviceErrorChanged(const QString &error) { qDebug() << Q_FUNC_INFO << error; -// NotificationManager *manager = NotificationManager::instance(); -// QVariantHash hints; -// hints.insert(NotificationManager::HINT_URGENCY, 1); -// hints.insert(NotificationManager::HINT_CATEGORY, "device.error"); -// hints.insert(NotificationManager::HINT_PREVIEW_BODY, error); -// manager->Notify(qApp->applicationName(), 0, QString(), QString(), QString(), QStringList(), hints, -1); + Q_EMIT errorReported(error); } void QConnectionManager::stateChanged(const QString &state) { Q_UNUSED(state) - // QString msg; - // if (currentNetworkState == "idle" && state == "association") { - // msg = "Connecting..."; - // } else if (currentNetworkState == "ready" && state == "online") { - // msg = "Connected"; - // } else if (state == "offline") { - // msg = "Offline"; - // } - // qDebug() << Q_FUNC_INFO << currentNetworkState << state << msg; - - //// NotificationManager *manager = NotificationManager::instance(); - //// QVariantHash hints; - //// hints.insert(NotificationManager::HINT_URGENCY, 2); - //// hints.insert(NotificationManager::HINT_CATEGORY, "device.error"); - //// hints.insert(NotificationManager::HINT_PREVIEW_BODY, msg); - //// manager->Notify(qApp->applicationName(), 0, QString(), QString(), QString(), QStringList(), hints, -1); - + QString msg; + if ((currentNetworkState == "idle" && state == "association") + || (currentNetworkState == "association" && state == "configuration") + || (currentNetworkState == "configuration" && state == "ready")) { + msg = "Connecting..."; + } else if (currentNetworkState == "ready" && state == "online") { + msg = "Connected"; + serviceConnect = false; + } else if (state == "offline") { + msg = "Offline"; + } + qDebug() << Q_FUNC_INFO << currentNetworkState << state << msg; + Q_EMIT connectionState(msg); // if (!msg.isEmpty()) { // emit serviceStateChanged(msg); // } - // currentNetworkState = state; + currentNetworkState = state; } bool QConnectionManager::autoConnect() @@ -216,20 +212,17 @@ bool QConnectionManager::autoConnect() Q_FOREACH (NetworkService *service, serviceList) { if(service->autoConnect() && service->favorite()) { - + serviceConnect = true; QObject::connect(service, SIGNAL(stateChanged(QString)), - this,SLOT(stateChanged(QString))); + this,SLOT(stateChanged(QString)), Qt::UniqueConnection); QObject::connect(service, SIGNAL(connectRequestFailed(QString)), - this,SLOT(serviceErrorChanged(QString))); + this,SLOT(serviceErrorChanged(QString)), Qt::UniqueConnection); service->requestConnect(); - qDebug() << Q_FUNC_INFO << true; - return true; } } } - qDebug() << Q_FUNC_INFO << false; return false; } @@ -246,7 +239,8 @@ void QConnectionManager::connectToType(const QString &type) netTech.setPowered(true); } QStringList servicesList = netman->servicesList(type); -qDebug() << servicesList; + + qDebug() << servicesList; if (servicesList.isEmpty()) { if (type == "wifi") { @@ -256,7 +250,10 @@ qDebug() << servicesList; onScanFinished(); } } else { - NetworkService *netService; + if (netService) { + delete netService; + netService = 0; + } netService = new NetworkService(this); bool needConfig = false; Q_FOREACH (const QString path, servicesList) { @@ -266,16 +263,15 @@ qDebug() << servicesList; if (netService->favorite()) { qDebug() << "power on, fav"; needConfig = false; + serviceConnect = true; QObject::connect(netService, SIGNAL(stateChanged(QString)), - this,SLOT(stateChanged(QString))); + this,SLOT(stateChanged(QString)), Qt::UniqueConnection); QObject::connect(netService, SIGNAL(connectRequestFailed(QString)), - this,SLOT(serviceErrorChanged(QString))); + this,SLOT(serviceErrorChanged(QString)), Qt::UniqueConnection); qDebug() << Q_FUNC_INFO << "just connect to this thing"; - //window->rootContext()->setContextProperty("connecting", QVariant(true)); - // NetworkTechnology *tech = netman->getTechnology(netService->type()); // tech->setIdleTimeout(120); diff --git a/connd/qconnectionmanager.h b/connd/qconnectionmanager.h index 27a89ea..7e2d0a4 100644 --- a/connd/qconnectionmanager.h +++ b/connd/qconnectionmanager.h @@ -29,6 +29,7 @@ class SessionAgent; class ConnAdaptor; class NetworkManager; +class NetworkService; class QConnectionManager : public QObject { @@ -48,6 +49,7 @@ class QConnectionManager : public QObject void errorReported(const QString &error); void connectionRequest(); void wlanConfigurationNeeded(); + void connectionState(const QString &state); public Q_SLOTS: @@ -77,9 +79,12 @@ public Q_SLOTS: bool autoConnect(); NetworkManager *netman; + NetworkService *netService; + bool okToConnect; QString currentNetworkState; QString currentType; + bool serviceConnect; private slots: void onScanFinished(); diff --git a/connectionagentplugin/connectionagentplugin.cpp b/connectionagentplugin/connectionagentplugin.cpp index 9ed9b02..1fdb1c9 100644 --- a/connectionagentplugin/connectionagentplugin.cpp +++ b/connectionagentplugin/connectionagentplugin.cpp @@ -49,6 +49,7 @@ ConnectionAgentPlugin::~ConnectionAgentPlugin() void ConnectionAgentPlugin::sendUserReply(const QVariantMap &input) { + qDebug() << Q_FUNC_INFO; QDBusPendingReply<> reply = connManagerInterface->sendUserReply(input); if (reply.isError()) { qDebug() << Q_FUNC_INFO << reply.error().message(); @@ -89,6 +90,7 @@ void ConnectionAgentPlugin::onUserInputRequested(const QString &service, const Q QVariantMap vmap = qdbus_cast(arg); map.insert(i.key(), vmap); } + qDebug() << Q_FUNC_INFO << map; Q_EMIT userInputRequested(service, map); } @@ -127,6 +129,9 @@ void ConnectionAgentPlugin::connectToConnectiond(QString) connect(connManagerInterface,SIGNAL(errorReported(QString)), this,SLOT(onErrorReported(QString))); + connect(connManagerInterface,SIGNAL(connectionState(QString)), + this,SLOT(onConnectionState(QString))); + connect(connManagerInterface,SIGNAL(requestBrowser(QString)), this,SLOT(onRequestBrowser(QString))); @@ -147,3 +152,9 @@ void ConnectionAgentPlugin::onWlanConfigurationNeeded() qDebug() << Q_FUNC_INFO; Q_EMIT wlanConfigurationNeeded(); } + +void ConnectionAgentPlugin::onConnectionState(const QString &state) +{ + qDebug() << Q_FUNC_INFO << state; + Q_EMIT connectionState(state); +} diff --git a/connectionagentplugin/connectionagentplugin.h b/connectionagentplugin/connectionagentplugin.h index 180dacc..e372fc3 100644 --- a/connectionagentplugin/connectionagentplugin.h +++ b/connectionagentplugin/connectionagentplugin.h @@ -42,6 +42,7 @@ public slots: void errorReported(const QString &error); void connectionRequest(); void wlanConfigurationNeeded(); + void connectionState(const QString &state); private: com::jolla::Connectiond *connManagerInterface; @@ -53,6 +54,7 @@ private slots: void onUserInputRequested(const QString &service, const QVariantMap &fields); void onConnectionRequested(); void onWlanConfigurationNeeded(); + void onConnectionState(const QString &state); void connectToConnectiond(const QString = QString()); void connectiondUnregistered(const QString = QString()); diff --git a/connectionagentplugin/connectionagentplugin.pro b/connectionagentplugin/connectionagentplugin.pro index 63be5f6..173794d 100644 --- a/connectionagentplugin/connectionagentplugin.pro +++ b/connectionagentplugin/connectionagentplugin.pro @@ -6,7 +6,7 @@ CONFIG += qt plugin uri = com.jolla.connection #create client -system(qdbusxml2cpp ../connd/com.jolla.Connectiond.xml -c ConnectionManagerInterface -p connectionamanagerinterface) +#system(qdbusxml2cpp ../connd/com.jolla.Connectiond.xml -c ConnectionManagerInterface -p connectionamanagerinterface) SOURCES += \ connectionagentplugin_plugin.cpp \ diff --git a/connectionagentplugin/connectionamanagerinterface.h b/connectionagentplugin/connectionamanagerinterface.h index 861c8db..2f47828 100644 --- a/connectionagentplugin/connectionamanagerinterface.h +++ b/connectionagentplugin/connectionamanagerinterface.h @@ -8,8 +8,8 @@ * Do not edit! All changes made to it will be lost. */ -#ifndef CONNECTIONAMANAGERINTERFACE_H_1363743454 -#define CONNECTIONAMANAGERINTERFACE_H_1363743454 +#ifndef CONNECTIONAMANAGERINTERFACE_H_1363759925 +#define CONNECTIONAMANAGERINTERFACE_H_1363759925 #include #include @@ -59,6 +59,7 @@ public Q_SLOTS: // METHODS Q_SIGNALS: // SIGNALS void connectionRequest(); + void connectionState(const QString &state); void errorReported(const QString &error); void requestBrowser(const QString &url); void userInputCanceled();