Skip to content

Commit

Permalink
update to fix these and make things work better
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorn Potter committed Mar 23, 2013
1 parent 21ba09e commit 668d739
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 60 deletions.
5 changes: 4 additions & 1 deletion connd/com.jollamobile.Connectiond.xml
Expand Up @@ -2,7 +2,7 @@
<node>
<interface name="com.jolla.Connectiond">
<signal name="connectionRequest"/>
<signal name="configurationNeeded"/>
<signal name="wlanConfigurationNeeded"/>
<signal name="errorReported">
<arg direction="out" type="s" name="error"/>
</signal>
Expand All @@ -15,6 +15,9 @@
<arg direction="out" type="a{sv}" name="fields"/>
<annotation value="QVariantMap" name="org.qtproject.QtDBus.QtTypeName.In1"/>
</signal>
<signal name="connectionState">
<arg direction="out" type="s" name="state"/>
</signal>
<method name="sendConnectReply">
<arg direction="in" type="s" name="in0"/>
<arg direction="in" type="i" name="in1"/>
Expand Down
8 changes: 6 additions & 2 deletions connd/connadaptor.h
Expand Up @@ -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 <QtCore/QObject>
#include <QtDBus/QtDBus>
Expand Down Expand Up @@ -44,6 +44,9 @@ class ConnAdaptor: public QDBusAbstractAdaptor
" <arg direction=\"out\" type=\"a{sv}\" name=\"fields\"/>\n"
" <annotation value=\"QVariantMap\" name=\"org.qtproject.QtDBus.QtTypeName.In1\"/>\n"
" </signal>\n"
" <signal name=\"connectionState\">\n"
" <arg direction=\"out\" type=\"s\" name=\"state\"/>\n"
" </signal>\n"
" <method name=\"sendConnectReply\">\n"
" <arg direction=\"in\" type=\"s\" name=\"in0\"/>\n"
" <arg direction=\"in\" type=\"i\" name=\"in1\"/>\n"
Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion connd/connd.pro
Expand Up @@ -13,6 +13,7 @@ QT -= gui


INCLUDEPATH += libconnman-qt
#INCLUDEPATH += lipstick

OTHER_FILES += com.jolla.Connectiond.xml

Expand All @@ -29,7 +30,7 @@ HEADERS+= \
connadaptor.h

LIBS += -lconnman-qt4
# LIBS += -llipstick
#LIBS += -llipstick

target.path = /usr/bin
INSTALLS += target
Expand Down
102 changes: 49 additions & 53 deletions connd/qconnectionmanager.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -99,6 +101,7 @@ void QConnectionManager::onUserInputCanceled()
// from useragent
void QConnectionManager::onErrorReported(const QString &error)
{
qDebug() << Q_FUNC_INFO << error;
Q_EMIT errorReported(error);
}

Expand All @@ -107,8 +110,6 @@ void QConnectionManager::onConnectionRequest()
{
qDebug() << Q_FUNC_INFO;
if (!autoConnect()) {
qDebug() << Q_FUNC_INFO << "emit connectionRequest";

Q_EMIT connectionRequest();
}
}
Expand All @@ -125,46 +126,50 @@ 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;
}

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();
}
}
Expand All @@ -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()
Expand All @@ -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;
}

Expand All @@ -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") {
Expand All @@ -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) {
Expand All @@ -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);

Expand Down
5 changes: 5 additions & 0 deletions connd/qconnectionmanager.h
Expand Up @@ -29,6 +29,7 @@ class SessionAgent;

class ConnAdaptor;
class NetworkManager;
class NetworkService;

class QConnectionManager : public QObject
{
Expand All @@ -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:

Expand Down Expand Up @@ -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();
Expand Down
11 changes: 11 additions & 0 deletions connectionagentplugin/connectionagentplugin.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -89,6 +90,7 @@ void ConnectionAgentPlugin::onUserInputRequested(const QString &service, const Q
QVariantMap vmap = qdbus_cast<QVariantMap>(arg);
map.insert(i.key(), vmap);
}
qDebug() << Q_FUNC_INFO << map;
Q_EMIT userInputRequested(service, map);
}

Expand Down Expand Up @@ -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)));

Expand All @@ -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);
}
2 changes: 2 additions & 0 deletions connectionagentplugin/connectionagentplugin.h
Expand Up @@ -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;
Expand All @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion connectionagentplugin/connectionagentplugin.pro
Expand Up @@ -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 \
Expand Down
5 changes: 3 additions & 2 deletions connectionagentplugin/connectionamanagerinterface.h
Expand Up @@ -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 <QtCore/QObject>
#include <QtCore/QByteArray>
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 668d739

Please sign in to comment.