diff --git a/plasmoid/lib/syncthingapplet.cpp b/plasmoid/lib/syncthingapplet.cpp index fea3047..955a2c6 100644 --- a/plasmoid/lib/syncthingapplet.cpp +++ b/plasmoid/lib/syncthingapplet.cpp @@ -552,7 +552,7 @@ void SyncthingApplet::handleDevicesChanged() void SyncthingApplet::handleInternalError( const QString &errorMsg, SyncthingErrorCategory category, int networkError, const QNetworkRequest &request, const QByteArray &response) { - if (!InternalError::isRelevant(m_connection, category, networkError)) { + if (!InternalError::isRelevant(m_connection, category, errorMsg, networkError)) { return; } auto error = InternalError(errorMsg, request.url(), response); diff --git a/syncthingwidgets/misc/internalerror.cpp b/syncthingwidgets/misc/internalerror.cpp index a4f96ec..b3098bf 100644 --- a/syncthingwidgets/misc/internalerror.cpp +++ b/syncthingwidgets/misc/internalerror.cpp @@ -12,11 +12,58 @@ using namespace Data; namespace QtGui { +/*! + * \brief Returns whether to ignore inavailability after start or standby-wakeup. + */ +static bool ignoreInavailabilityAfterStart( + const Settings::Settings &settings, const SyncthingLauncher *launcher, const SyncthingService *service, const QString &message, int networkError) +{ + if (!settings.ignoreInavailabilityAfterStart) { + return false; + } + + // ignore only certain types of errors + // note: Not sure how to check for "Forbidden" except for checking the error message. + switch (networkError) { + case QNetworkReply::ConnectionRefusedError: + case QNetworkReply::HostNotFoundError: + case QNetworkReply::TemporaryNetworkFailureError: + case QNetworkReply::NetworkSessionFailedError: + case QNetworkReply::ProxyConnectionRefusedError: + case QNetworkReply::ProxyNotFoundError: + break; + default: + if (message.contains(QLatin1String("Forbidden"))) { + break; + } + return false; + }; + + // ignore inavailable shorty after the start + if ((launcher && launcher->isRunning()) +#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD + && ((service && service->isSystemdAvailable() + && !service->isActiveWithoutSleepFor(launcher->activeSince(), settings.ignoreInavailabilityAfterStart)) + || !launcher->isActiveFor(settings.ignoreInavailabilityAfterStart)) +#else + && !launcher->isActiveFor(settings.ignoreInavailabilityAfterStart) +#endif + ) { + return true; + } +#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD + if (service && !service->isActiveWithoutSleepFor(settings.ignoreInavailabilityAfterStart)) { + return true; + } +#endif + return false; +} + /*! * \brief Returns whether the error is relevant. Only in this case a notification for the error should be shown. * \todo Unify with SyncthingNotifier::isDisconnectRelevant(). */ -bool InternalError::isRelevant(const SyncthingConnection &connection, SyncthingErrorCategory category, int networkError) +bool InternalError::isRelevant(const SyncthingConnection &connection, SyncthingErrorCategory category, const QString &message, int networkError) { // ignore overall connection errors when auto reconnect tries >= 1 if (category != SyncthingErrorCategory::OverallConnection && category != SyncthingErrorCategory::TLS && connection.autoReconnectTries() >= 1) { @@ -50,35 +97,6 @@ bool InternalError::isRelevant(const SyncthingConnection &connection, SyncthingE } #endif - // ignore inavailability after start or standby-wakeup - if (settings.ignoreInavailabilityAfterStart) { - switch (networkError) { - case QNetworkReply::ConnectionRefusedError: - case QNetworkReply::HostNotFoundError: - case QNetworkReply::TemporaryNetworkFailureError: - case QNetworkReply::NetworkSessionFailedError: - case QNetworkReply::ProxyConnectionRefusedError: - case QNetworkReply::ProxyNotFoundError: - if ((launcher && launcher->isRunning()) -#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD - && ((service && service->isSystemdAvailable() - && !service->isActiveWithoutSleepFor(launcher->activeSince(), settings.ignoreInavailabilityAfterStart)) - || !launcher->isActiveFor(settings.ignoreInavailabilityAfterStart)) -#else - && !launcher->isActiveFor(settings.ignoreInavailabilityAfterStart) -#endif - ) { - return false; - } -#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD - if (service && !service->isActiveWithoutSleepFor(settings.ignoreInavailabilityAfterStart)) { - return false; - } -#endif - break; - } - } - - return true; + return !ignoreInavailabilityAfterStart(settings, launcher, service, message, networkError); } } // namespace QtGui diff --git a/syncthingwidgets/misc/internalerror.h b/syncthingwidgets/misc/internalerror.h index 92126ed..2e9eb61 100644 --- a/syncthingwidgets/misc/internalerror.h +++ b/syncthingwidgets/misc/internalerror.h @@ -19,7 +19,8 @@ namespace QtGui { struct SYNCTHINGWIDGETS_EXPORT InternalError { explicit InternalError(const QString &message = QString(), const QUrl &url = QUrl(), const QByteArray &response = QByteArray()); - static bool isRelevant(const Data::SyncthingConnection &connection, Data::SyncthingErrorCategory category, int networkError); + static bool isRelevant( + const Data::SyncthingConnection &connection, Data::SyncthingErrorCategory category, const QString &message, int networkError); QString message; QUrl url; diff --git a/tray/gui/trayicon.cpp b/tray/gui/trayicon.cpp index 6f61d83..cd9988f 100644 --- a/tray/gui/trayicon.cpp +++ b/tray/gui/trayicon.cpp @@ -199,7 +199,7 @@ void TrayIcon::handleErrorsCleared() void TrayIcon::showInternalError( const QString &errorMessage, SyncthingErrorCategory category, int networkError, const QNetworkRequest &request, const QByteArray &response) { - if (!InternalError::isRelevant(trayMenu().widget().connection(), category, networkError)) { + if (!InternalError::isRelevant(trayMenu().widget().connection(), category, errorMessage, networkError)) { return; } auto error = InternalError(errorMessage, request.url(), response); diff --git a/tray/gui/traywidget.cpp b/tray/gui/traywidget.cpp index 53df842..6f6d479 100644 --- a/tray/gui/traywidget.cpp +++ b/tray/gui/traywidget.cpp @@ -396,7 +396,7 @@ void TrayWidget::showUsingPositioningSettings() void TrayWidget::showInternalError( const QString &errorMessage, SyncthingErrorCategory category, int networkError, const QNetworkRequest &request, const QByteArray &response) { - if (!InternalError::isRelevant(connection(), category, networkError)) { + if (!InternalError::isRelevant(connection(), category, errorMessage, networkError)) { return; } InternalErrorsDialog::addError(errorMessage, request.url(), response);