From 8ad283ff1ed86c8f555653bd910bc2cf924b5491 Mon Sep 17 00:00:00 2001 From: Raine Makelainen Date: Mon, 19 Jun 2017 16:25:03 +0300 Subject: [PATCH] Drop slots that emit matching signal. This also removes duplicated userInputRequested connection. Further, all UserAgent connections are unique by nature as previous user agent is destroyed and new created right before connecting signals and slots. --- connd/qconnectionagent.cpp | 36 +++--------------- connd/qconnectionagent.h | 5 --- .../declarativeconnectionagent.cpp | 38 +++---------------- .../declarativeconnectionagent.h | 5 --- .../tst_connectionagent.cpp | 25 ------------ 5 files changed, 12 insertions(+), 97 deletions(-) diff --git a/connd/qconnectionagent.cpp b/connd/qconnectionagent.cpp index abd6db6..da1c4fc 100644 --- a/connd/qconnectionagent.cpp +++ b/connd/qconnectionagent.cpp @@ -102,20 +102,6 @@ bool QConnectionAgent::isValid() const return valid; } -// from useragent -void QConnectionAgent::onUserInputRequested(const QString &servicePath, const QVariantMap &fields) -{ - qDebug() << servicePath; - // gets called when a connman service gets called to connect and needs more configurations. - Q_EMIT userInputRequested(servicePath, fields); -} - -// from useragent -void QConnectionAgent::onUserInputCanceled() -{ - Q_EMIT userInputCanceled(); -} - // from useragent void QConnectionAgent::onErrorReported(const QString &servicePath, const QString &error) { @@ -407,16 +393,15 @@ void QConnectionAgent::setup() delete ua; ua = new UserAgent(this); - connect(ua, &UserAgent::userInputRequested, - this, &QConnectionAgent::onUserInputRequested); - connect(ua, &UserAgent::connectionRequest, this, &QConnectionAgent::onConnectionRequest); connect(ua, &UserAgent::errorReported, this, &QConnectionAgent::onErrorReported); - connect(ua, &UserAgent::userInputCanceled, this, &QConnectionAgent::onUserInputCanceled); - connect(ua, &UserAgent::userInputRequested, - this, &QConnectionAgent::onUserInputRequested, Qt::UniqueConnection); + connect(ua, &UserAgent::userInputCanceled, this, &QConnectionAgent::userInputCanceled); + connect(ua, &UserAgent::userInputRequested, this, &QConnectionAgent::userInputRequested); connect(ua, &UserAgent::browserRequested, - this, &QConnectionAgent::browserRequest, Qt::UniqueConnection); + this, [=](const QString &servicePath, const QString &url) { + Q_UNUSED(servicePath); + Q_EMIT requestBrowser(url); + }); updateServices(); offlineModeChanged(netman->offlineMode()); @@ -484,15 +469,6 @@ void QConnectionAgent::techChanged() } } -void QConnectionAgent::browserRequest(const QString &servicePath, const QString &url) -{ - Q_UNUSED(servicePath) - qDebug() << servicePath; - qDebug() << url; - - Q_EMIT requestBrowser(url); -} - bool QConnectionAgent::isStateOnline(const QString &state) { if (state == "online" || state == "ready") diff --git a/connd/qconnectionagent.h b/connd/qconnectionagent.h index 956352c..2b8ee02 100644 --- a/connd/qconnectionagent.h +++ b/connd/qconnectionagent.h @@ -38,7 +38,6 @@ class QConnectionAgent : public QObject bool isValid() const; Q_SIGNALS: - void userInputRequested(const QString &servicePath, const QVariantMap &fields); void userInputCanceled(); void errorReported(const QString &servicePath, const QString &error); @@ -51,9 +50,6 @@ class QConnectionAgent : public QObject void tetheringFinished(bool); public Q_SLOTS: - - void onUserInputRequested(const QString &servicePath, const QVariantMap &fields); - void onUserInputCanceled(); void onErrorReported(const QString &servicePath, const QString &error); void onConnectionRequest(); @@ -136,7 +132,6 @@ private slots: void connmanAvailabilityChanged(bool b); void servicesError(const QString &); void technologyPowerChanged(bool); - void browserRequest(const QString &servicePath, const QString &url); void techChanged(); void servicesListChanged(const QStringList &); diff --git a/connectionagentplugin/declarativeconnectionagent.cpp b/connectionagentplugin/declarativeconnectionagent.cpp index e56c2a6..6ec7de6 100644 --- a/connectionagentplugin/declarativeconnectionagent.cpp +++ b/connectionagentplugin/declarativeconnectionagent.cpp @@ -69,7 +69,7 @@ void DeclarativeConnectionAgent::connectToConnectiond(QString) qDebug() << Q_FUNC_INFO << "is not valid interface"; } connect(connManagerInterface,SIGNAL(connectionRequest()), - this,SLOT(onConnectionRequested())); + this, SIGNAL(connectionRequest())); connect(connManagerInterface,SIGNAL(configurationNeeded(QString)), this,SIGNAL(configurationNeeded(QString))); @@ -77,19 +77,19 @@ void DeclarativeConnectionAgent::connectToConnectiond(QString) this,SIGNAL(userInputCanceled())); connect(connManagerInterface, SIGNAL(errorReported(QString, QString)), - this, SLOT(onErrorReported(QString, QString))); + this, SIGNAL(errorReported(QString, QString))); connect(connManagerInterface,SIGNAL(connectionState(QString, QString)), - this,SLOT(onConnectionState(QString, QString))); + this,SIGNAL(connectionState(QString, QString))); - connect(connManagerInterface,SIGNAL(requestBrowser(QString)), - this,SLOT(onRequestBrowser(QString))); + connect(connManagerInterface, SIGNAL(requestBrowser(QString)), + this, SIGNAL(browserRequested(QString))); connect(connManagerInterface,SIGNAL(userInputRequested(QString,QVariantMap)), this,SLOT(onUserInputRequested(QString,QVariantMap)), Qt::UniqueConnection); connect(connManagerInterface,SIGNAL(tetheringFinished(bool)), - this,SLOT(onTetheringFinished(bool))); + this,SLOT(tetheringFinished(bool))); } void DeclarativeConnectionAgent::sendUserReply(const QVariantMap &input) @@ -125,17 +125,6 @@ void DeclarativeConnectionAgent::connectToType(const QString &type) connManagerInterface->connectToType(type); } -void DeclarativeConnectionAgent::onErrorReported(const QString &servicePath, const QString &error) -{ - Q_EMIT errorReported(servicePath, error); -} - -void DeclarativeConnectionAgent::onRequestBrowser(const QString &url) -{ - qDebug() << Q_FUNC_INFO <startTethering(type); } -void DeclarativeConnectionAgent::onTetheringFinished(bool success) -{ - Q_EMIT tetheringFinished(success); -} - void DeclarativeConnectionAgent::stopTethering(bool keepPowered) { connManagerInterface->stopTethering(keepPowered); diff --git a/connectionagentplugin/declarativeconnectionagent.h b/connectionagentplugin/declarativeconnectionagent.h index befc985..ea45774 100644 --- a/connectionagentplugin/declarativeconnectionagent.h +++ b/connectionagentplugin/declarativeconnectionagent.h @@ -87,12 +87,7 @@ public slots: QDBusServiceWatcher *connectiondWatcher; private slots: - void onErrorReported(const QString &servicePath, const QString &error); - void onRequestBrowser(const QString &url); void onUserInputRequested(const QString &service, const QVariantMap &fields); - void onConnectionRequested(); - void onConnectionState(const QString &state, const QString &type); - void onTetheringFinished(bool); void connectToConnectiond(const QString = QString()); void connectiondUnregistered(const QString = QString()); diff --git a/test/auto/tst_connectionagent/tst_connectionagent.cpp b/test/auto/tst_connectionagent/tst_connectionagent.cpp index 96b9092..bd68d12 100644 --- a/test/auto/tst_connectionagent/tst_connectionagent.cpp +++ b/test/auto/tst_connectionagent/tst_connectionagent.cpp @@ -34,8 +34,6 @@ class Tst_connectionagent : public QObject Q_OBJECT private Q_SLOTS: - void tst_onUserInputRequested(); - void tst_onUserInputCanceled(); void tst_onErrorReported(); void tst_onConnectionRequest(); @@ -43,29 +41,6 @@ private Q_SLOTS: QConnectionAgent agent; }; -void Tst_connectionagent::tst_onUserInputRequested() -{ - QSignalSpy spy(&agent, SIGNAL(userInputRequested(QString,QVariantMap))); - QVariantMap map; - map.insert("test",true); - - agent.onUserInputRequested(QLatin1String("test_path"), map); - QCOMPARE(spy.count(),1); - QList arguments; - arguments = spy.takeFirst(); - QCOMPARE(arguments.at(0).toString(), QString("test_path")); - QVariantMap map2 = arguments.at(1).toMap(); - QCOMPARE(map2.keys().at(0), QString("test")); - -} - -void Tst_connectionagent::tst_onUserInputCanceled() -{ - QSignalSpy spy(&agent, SIGNAL(userInputCanceled())); - agent.onUserInputCanceled(); - QCOMPARE(spy.count(),1); -} - void Tst_connectionagent::tst_onErrorReported() { QSignalSpy spy(&agent, SIGNAL(errorReported(QString,QString)));