Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[connectionagent] Align error reporting code paths. Contributes to JB…
…#20091
  • Loading branch information
rainemak committed Jun 19, 2017
1 parent 0b91974 commit 904c8e6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
31 changes: 18 additions & 13 deletions connd/qconnectionagent.cpp
Expand Up @@ -118,8 +118,7 @@ void QConnectionAgent::onUserInputCanceled()
// from useragent
void QConnectionAgent::onErrorReported(const QString &servicePath, const QString &error)
{
// Suppress errors when switching to offline mode
if (error == "connect-failed" && servicePath.contains("cellular") && netman->offlineMode())
if (shouldSuppressError(error, servicePath.contains("cellular")))
return;

if (!tetheringWifiTech) return;
Expand Down Expand Up @@ -189,19 +188,11 @@ void QConnectionAgent::servicesListChanged(const QStringList &list)

void QConnectionAgent::serviceErrorChanged(const QString &error)
{
qDebug() << error;
if (error == "Operation aborted")
return;
NetworkService *service = static_cast<NetworkService *>(sender());

if (error == "connect-failed"
&& (service->type() == "cellular") && netman->offlineMode()) {
return;
}
if (error == "In progress" || error.contains("Method")) // catch dbus errors and discard
if (shouldSuppressError(error, service->type() == QLatin1String("cellular")))
return;

Q_EMIT errorReported(service->path(),error);
Q_EMIT errorReported(service->path(), error);
}

void QConnectionAgent::serviceStateChanged(const QString &state)
Expand Down Expand Up @@ -363,7 +354,7 @@ void QConnectionAgent::servicesError(const QString &errorMessage)
return;
NetworkService *serv = static_cast<NetworkService *>(sender());
qDebug() << serv->name() << errorMessage;
Q_EMIT onErrorReported(serv->path(), errorMessage);
onErrorReported(serv->path(), errorMessage);
}

void QConnectionAgent::networkStateChanged(const QString &state)
Expand Down Expand Up @@ -658,6 +649,20 @@ void QConnectionAgent::removeAllTypes(const QString &type)
}
}

bool QConnectionAgent::shouldSuppressError(const QString &error, bool cellular) const
{
if (error.isEmpty())
return true;
if (error == QLatin1String("Operation aborted"))
return true;
if (error == QLatin1String("connect-failed") && cellular && netman->offlineMode()) // Suppress errors when switching to offline mode
return true;
if (error == QLatin1String("In progress") || error.contains(QLatin1String("Method"))) // Catch dbus errors and discard
return true;

return false;
}

void QConnectionAgent::openConnectionDialog(const QString &type)
{
// open Connection Selector
Expand Down
2 changes: 2 additions & 0 deletions connd/qconnectionagent.h
Expand Up @@ -110,6 +110,8 @@ public Q_SLOTS:
QString findBestConnectableService();
void removeAllTypes(const QString &type);

bool shouldSuppressError(const QString &error, bool cellular) const;

UserAgent *ua;
NetworkManager *netman;
QString currentNetworkState;
Expand Down

0 comments on commit 904c8e6

Please sign in to comment.