diff --git a/connd/com.jollamobile.Connectiond.xml b/connd/com.jollamobile.Connectiond.xml index 0ffc03c..208763e 100644 --- a/connd/com.jollamobile.Connectiond.xml +++ b/connd/com.jollamobile.Connectiond.xml @@ -1,27 +1,30 @@ - + - - - - - - - - - - - - - - + + - + - + - + + + + + + + + + + + + + + + + + diff --git a/connd/conn.xml b/connd/conn.xml index 64de275..53d8392 100644 --- a/connd/conn.xml +++ b/connd/conn.xml @@ -1,28 +1,30 @@ - - - - - - - - - - - - - - + + - - + - - + - + + + + + + + + + + + + + + + + + diff --git a/connd/connadaptor.cpp b/connd/connadaptor.cpp index 7348d4d..e67634d 100644 --- a/connd/connadaptor.cpp +++ b/connd/connadaptor.cpp @@ -1,18 +1,12 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Jolla Ltd -** Contact: lorn.potter@gmail.com -** -** -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -****************************************************************************/ +/* + * This file was generated by qdbusxml2cpp version 0.7 + * Command line was: qdbusxml2cpp -v -c ConnAdaptor -a connadaptor.h:connadaptor.cpp conn.xml + * + * qdbusxml2cpp is Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ #include "connadaptor.h" #include @@ -30,11 +24,19 @@ ConnAdaptor::ConnAdaptor(QObject *parent) : QDBusAbstractAdaptor(parent) { + // constructor setAutoRelaySignals(true); } ConnAdaptor::~ConnAdaptor() { + // destructor +} + +void ConnAdaptor::connectToType(const QString &in0) +{ + // handle method call com.jolla.Connectiond.connectToType + QMetaObject::invokeMethod(parent(), "connectToType", Q_ARG(QString, in0)); } void ConnAdaptor::sendConnectReply(const QString &in0, int in1) diff --git a/connd/connadaptor.h b/connd/connadaptor.h index 4256b31..307f38f 100644 --- a/connd/connadaptor.h +++ b/connd/connadaptor.h @@ -1,21 +1,16 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Jolla Ltd -** Contact: lorn.potter@gmail.com -** -** -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -****************************************************************************/ +/* + * This file was generated by qdbusxml2cpp version 0.7 + * Command line was: qdbusxml2cpp -v -c ConnAdaptor -a connadaptor.h:connadaptor.cpp conn.xml + * + * 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 + * before re-generating it. + */ -#ifndef CONNADAPTOR_H_1363412350 -#define CONNADAPTOR_H_1363412350 +#ifndef CONNADAPTOR_H_1363743442 +#define CONNADAPTOR_H_1363743442 #include #include @@ -35,27 +30,31 @@ class ConnAdaptor: public QDBusAbstractAdaptor Q_CLASSINFO("D-Bus Interface", "com.jolla.Connectiond") Q_CLASSINFO("D-Bus Introspection", "" " \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" +" \n" +" \n" " \n" -" \n" +" \n" " \n" " \n" -" \n" +" \n" " \n" -" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" " \n" "") public: @@ -64,6 +63,7 @@ class ConnAdaptor: public QDBusAbstractAdaptor public: // PROPERTIES public Q_SLOTS: // METHODS + void connectToType(const QString &in0); void sendConnectReply(const QString &in0, int in1); void sendUserReply(const QVariantMap &input); Q_SIGNALS: // SIGNALS @@ -72,6 +72,7 @@ public Q_SLOTS: // METHODS void requestBrowser(const QString &url); void userInputCanceled(); void userInputRequested(const QString &service, const QVariantMap &fields); + void wlanConfigurationNeeded(); }; #endif diff --git a/connd/connd.pro b/connd/connd.pro index 6cc3b6a..5514280 100644 --- a/connd/connd.pro +++ b/connd/connd.pro @@ -3,7 +3,7 @@ QT += core network dbus gui QT -= gui TARGET = connectionagent -CONFIG += console +CONFIG += console link_pkgconfig CONFIG -= app_bundle TEMPLATE = app diff --git a/connd/qconnectionmanager.cpp b/connd/qconnectionmanager.cpp index cdad241..c36c998 100644 --- a/connd/qconnectionmanager.cpp +++ b/connd/qconnectionmanager.cpp @@ -35,7 +35,10 @@ QConnectionManager* QConnectionManager::self = NULL; QConnectionManager::QConnectionManager(QObject *parent) : QObject(parent), - netman(NetworkManagerFactory::createInstance()) + netman(NetworkManagerFactory::createInstance()), + okToConnect(0), + currentNetworkState(QString()), + currentType(QString()) { connectionAdaptor = new ConnAdaptor(this); QDBusConnection dbus = QDBusConnection::sessionBus(); @@ -102,9 +105,12 @@ void QConnectionManager::onErrorReported(const QString &error) // from useragent void QConnectionManager::onConnectionRequest() { -// if (!autoConnect()) { + qDebug() << Q_FUNC_INFO; + if (!autoConnect()) { + qDebug() << Q_FUNC_INFO << "emit connectionRequest"; + Q_EMIT connectionRequest(); - // } + } } void QConnectionManager::sendMessage() @@ -150,6 +156,18 @@ void QConnectionManager::networkStateChanged(const QString &state) void QConnectionManager::onServiceAdded(const QString &servicePath) { // qDebug() << Q_FUNC_INFO << servicePath; + if (okToConnect) { + NetworkService *netService; + netService = new NetworkService(this); + netService->setPath(servicePath); + if (netService->favorite()) { + QObject::connect(netService, SIGNAL(stateChanged(QString)), + this,SLOT(stateChanged(QString))); + QObject::connect(netService, SIGNAL(connectRequestFailed(QString)), + this,SLOT(serviceErrorChanged(QString))); + netService->requestConnect(); + } + } } void QConnectionManager::serviceErrorChanged(const QString &error) @@ -166,6 +184,27 @@ void QConnectionManager::serviceErrorChanged(const QString &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); + + // if (!msg.isEmpty()) { + // emit serviceStateChanged(msg); + // } + // currentNetworkState = state; } bool QConnectionManager::autoConnect() @@ -184,10 +223,78 @@ bool QConnectionManager::autoConnect() this,SLOT(serviceErrorChanged(QString))); service->requestConnect(); + qDebug() << Q_FUNC_INFO << true; + return true; } } } + qDebug() << Q_FUNC_INFO << false; return false; } +void QConnectionManager::connectToType(const QString &type) +{ + qDebug() << Q_FUNC_INFO << type; + currentType = type; + QString techPath = netman->technologyPathForType(type); + + NetworkTechnology netTech; + netTech.setPath(techPath); + + if (!netTech.powered()) { + netTech.setPowered(true); + } + QStringList servicesList = netman->servicesList(type); +qDebug() << servicesList; + + if (servicesList.isEmpty()) { + if (type == "wifi") { + QObject::connect(&netTech,SIGNAL(scanFinished()),this,SLOT(onScanFinished())); + netTech.scan(); + } else { + onScanFinished(); + } + } else { + NetworkService *netService; + netService = new NetworkService(this); + bool needConfig = false; + Q_FOREACH (const QString path, servicesList) { + + netService->setPath(path); + + if (netService->favorite()) { + qDebug() << "power on, fav"; + needConfig = false; + QObject::connect(netService, SIGNAL(stateChanged(QString)), + this,SLOT(stateChanged(QString))); + + QObject::connect(netService, SIGNAL(connectRequestFailed(QString)), + this,SLOT(serviceErrorChanged(QString))); + + qDebug() << Q_FUNC_INFO << "just connect to this thing"; + + //window->rootContext()->setContextProperty("connecting", QVariant(true)); + +// NetworkTechnology *tech = netman->getTechnology(netService->type()); +// tech->setIdleTimeout(120); + + netService->requestConnect(); + okToConnect = false; + return; + } else { + needConfig = true; + } + } + if (needConfig) { + qDebug() << Q_FUNC_INFO << "no favorite service found. Configuration needed"; + Q_EMIT wlanConfigurationNeeded(); + } + } + +} + +void QConnectionManager::onScanFinished() +{ + qDebug() << Q_FUNC_INFO; +} diff --git a/connd/qconnectionmanager.h b/connd/qconnectionmanager.h index 1c49e65..27a89ea 100644 --- a/connd/qconnectionmanager.h +++ b/connd/qconnectionmanager.h @@ -47,6 +47,7 @@ class QConnectionManager : public QObject void userInputCanceled(); void errorReported(const QString &error); void connectionRequest(); + void wlanConfigurationNeeded(); public Q_SLOTS: @@ -66,14 +67,23 @@ public Q_SLOTS: void serviceErrorChanged(const QString &error); void stateChanged(const QString &state); + void connectToType(const QString &type); + private: explicit QConnectionManager(QObject *parent = 0); static QConnectionManager *self; ConnAdaptor *connectionAdaptor; UserAgent *ua; - NetworkManager *netman; + bool autoConnect(); + NetworkManager *netman; + bool okToConnect; QString currentNetworkState; + QString currentType; + +private slots: + void onScanFinished(); + }; #endif // QCONNECTIONMANAGER_H diff --git a/connectionagentplugin/connectionagentplugin.cpp b/connectionagentplugin/connectionagentplugin.cpp index cb1e44d..9ed9b02 100644 --- a/connectionagentplugin/connectionagentplugin.cpp +++ b/connectionagentplugin/connectionagentplugin.cpp @@ -17,6 +17,12 @@ #include "connectionagentplugin.h" #include "connectionamanagerinterface.h" +#include +#include +#include + +//#include "notifications/notificationmanager.h" + #include #define CONND_SERVICE "com.jolla.Connectiond" @@ -54,6 +60,12 @@ void ConnectionAgentPlugin::sendConnectReply(const QString &replyMessage, int ti connManagerInterface->sendConnectReply(replyMessage,timeout); } +void ConnectionAgentPlugin::connectToType(const QString &type) +{ + qDebug() << Q_FUNC_INFO << type;; + connManagerInterface->connectToType(type); +} + void ConnectionAgentPlugin::onErrorReported(const QString &error) { Q_EMIT errorReported(error); @@ -106,6 +118,9 @@ void ConnectionAgentPlugin::connectToConnectiond(QString) connect(connManagerInterface,SIGNAL(connectionRequest()), this,SLOT(onConnectionRequested())); + connect(connManagerInterface,SIGNAL(wlanConfigurationNeeded()), + this,SIGNAL(wlanConfigurationNeeded())); + connect(connManagerInterface,SIGNAL(userInputCanceled()), this,SIGNAL(userInputCanceled())); @@ -126,3 +141,9 @@ void ConnectionAgentPlugin::connectiondUnregistered(QString) connManagerInterface = 0; } } + +void ConnectionAgentPlugin::onWlanConfigurationNeeded() +{ + qDebug() << Q_FUNC_INFO; + Q_EMIT wlanConfigurationNeeded(); +} diff --git a/connectionagentplugin/connectionagentplugin.h b/connectionagentplugin/connectionagentplugin.h index 25804f9..180dacc 100644 --- a/connectionagentplugin/connectionagentplugin.h +++ b/connectionagentplugin/connectionagentplugin.h @@ -21,6 +21,7 @@ #include "connectionagentplugin.h" #include "connectionamanagerinterface.h" +class NetworkManager; class ConnectionAgentPlugin : public QObject { Q_OBJECT @@ -33,12 +34,14 @@ class ConnectionAgentPlugin : public QObject public slots: void sendUserReply(const QVariantMap &input); void sendConnectReply(const QString &replyMessage, int timeout = 120); + void connectToType(const QString &type); signals: void userInputRequested(const QString &servicePath, const QVariantMap &fields); void userInputCanceled(); void errorReported(const QString &error); void connectionRequest(); + void wlanConfigurationNeeded(); private: com::jolla::Connectiond *connManagerInterface; @@ -49,6 +52,7 @@ private slots: void onRequestBrowser(const QString &url); void onUserInputRequested(const QString &service, const QVariantMap &fields); void onConnectionRequested(); + void onWlanConfigurationNeeded(); void connectToConnectiond(const QString = QString()); void connectiondUnregistered(const QString = QString()); diff --git a/connectionagentplugin/connectionagentplugin.pro b/connectionagentplugin/connectionagentplugin.pro index 173794d..63be5f6 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.cpp b/connectionagentplugin/connectionamanagerinterface.cpp index 3fef0bd..2fd88a5 100644 --- a/connectionagentplugin/connectionamanagerinterface.cpp +++ b/connectionagentplugin/connectionamanagerinterface.cpp @@ -1,19 +1,13 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Jolla Ltd -** Contact: lorn.potter@gmail.com -** -** -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -****************************************************************************/ - +/* + * This file was generated by qdbusxml2cpp version 0.7 + * Command line was: qdbusxml2cpp ../connd/conn.xml -c ConnectionManagerInterface -p connectionamanagerinterface + * + * 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 + * before re-generating it. + */ #include "connectionamanagerinterface.h" diff --git a/connectionagentplugin/connectionamanagerinterface.h b/connectionagentplugin/connectionamanagerinterface.h index 9a03ce1..861c8db 100644 --- a/connectionagentplugin/connectionamanagerinterface.h +++ b/connectionagentplugin/connectionamanagerinterface.h @@ -1,22 +1,15 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Jolla Ltd -** Contact: lorn.potter@gmail.com -** -** -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -****************************************************************************/ - +/* + * This file was generated by qdbusxml2cpp version 0.7 + * Command line was: qdbusxml2cpp ../connd/conn.xml -c ConnectionManagerInterface -p connectionamanagerinterface + * + * qdbusxml2cpp is Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ -#ifndef CONNECTIONAMANAGERINTERFACE_H_1363426405 -#define CONNECTIONAMANAGERINTERFACE_H_1363426405 +#ifndef CONNECTIONAMANAGERINTERFACE_H_1363743454 +#define CONNECTIONAMANAGERINTERFACE_H_1363743454 #include #include @@ -43,6 +36,13 @@ class ConnectionManagerInterface: public QDBusAbstractInterface ~ConnectionManagerInterface(); public Q_SLOTS: // METHODS + inline QDBusPendingReply<> connectToType(const QString &in0) + { + QList argumentList; + argumentList << QVariant::fromValue(in0); + return asyncCallWithArgumentList(QLatin1String("connectToType"), argumentList); + } + inline QDBusPendingReply<> sendConnectReply(const QString &in0, int in1) { QList argumentList; @@ -52,7 +52,6 @@ public Q_SLOTS: // METHODS inline QDBusPendingReply<> sendUserReply(const QVariantMap &input) { - qDebug() << Q_FUNC_INFO; QList argumentList; argumentList << QVariant::fromValue(input); return asyncCallWithArgumentList(QLatin1String("sendUserReply"), argumentList); @@ -64,6 +63,7 @@ public Q_SLOTS: // METHODS void requestBrowser(const QString &url); void userInputCanceled(); void userInputRequested(const QString &service, const QVariantMap &fields); + void wlanConfigurationNeeded(); }; namespace com {