Skip to content

Commit

Permalink
Drop slots that emit matching signal.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rainemak committed Jun 19, 2017
1 parent 2590266 commit 8ad283f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 97 deletions.
36 changes: 6 additions & 30 deletions connd/qconnectionagent.cpp
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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")
Expand Down
5 changes: 0 additions & 5 deletions connd/qconnectionagent.h
Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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 &);
Expand Down
38 changes: 6 additions & 32 deletions connectionagentplugin/declarativeconnectionagent.cpp
Expand Up @@ -69,27 +69,27 @@ 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)));

connect(connManagerInterface,SIGNAL(userInputCanceled()),
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)
Expand Down Expand Up @@ -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 <<url;
Q_EMIT browserRequested(url);
}

void DeclarativeConnectionAgent::onUserInputRequested(const QString &service, const QVariantMap &fields)
{
// we do this as qtdbus does not understand QVariantMap very well.
Expand All @@ -152,11 +141,6 @@ void DeclarativeConnectionAgent::onUserInputRequested(const QString &service, co
Q_EMIT userInputRequested(service, map);
}

void DeclarativeConnectionAgent::onConnectionRequested()
{
Q_EMIT connectionRequest();
}

void DeclarativeConnectionAgent::connectiondUnregistered(QString)
{
if (connManagerInterface) {
Expand All @@ -165,21 +149,11 @@ void DeclarativeConnectionAgent::connectiondUnregistered(QString)
}
}

void DeclarativeConnectionAgent::onConnectionState(const QString &state, const QString &type)
{
Q_EMIT connectionState(state, type);
}

void DeclarativeConnectionAgent::startTethering(const QString &type)
{
connManagerInterface->startTethering(type);
}

void DeclarativeConnectionAgent::onTetheringFinished(bool success)
{
Q_EMIT tetheringFinished(success);
}

void DeclarativeConnectionAgent::stopTethering(bool keepPowered)
{
connManagerInterface->stopTethering(keepPowered);
Expand Down
5 changes: 0 additions & 5 deletions connectionagentplugin/declarativeconnectionagent.h
Expand Up @@ -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());
Expand Down
25 changes: 0 additions & 25 deletions test/auto/tst_connectionagent/tst_connectionagent.cpp
Expand Up @@ -34,38 +34,13 @@ class Tst_connectionagent : public QObject
Q_OBJECT

private Q_SLOTS:
void tst_onUserInputRequested();
void tst_onUserInputCanceled();
void tst_onErrorReported();
void tst_onConnectionRequest();

private:
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<QVariant> 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)));
Expand Down

0 comments on commit 8ad283f

Please sign in to comment.