From 2ee1bc0c632250fbb2ddb93a79068f3f1194c997 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sun, 28 Oct 2018 16:03:18 +0100 Subject: [PATCH] Discard previous item errors also on connect() Because errors might be gone now and should be repopulated if not. --- connector/syncthingconnection.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/connector/syncthingconnection.cpp b/connector/syncthingconnection.cpp index c9f84b6..f4f2bca 100644 --- a/connector/syncthingconnection.cpp +++ b/connector/syncthingconnection.cpp @@ -176,20 +176,41 @@ void SyncthingConnection::disablePolling() /*! * \brief Connects asynchronously to Syncthing. Does nothing if already connected. + * + * Use this to connect the first time or to connect to the same Syncthing instance again or to ensure + * the connection to the currently configured instance is established. Use reconnect() to connect to + * a different instance. + * + * \remarks Does not clear data from a previous connection (except error items). Use reconnect() if that + * is required. */ void SyncthingConnection::connect() { + // reset auto-reconnect m_autoReconnectTimer.stop(); m_autoReconnectTries = 0; + + // skip if already connected (see reconnect() to force reconnecting) if (isConnected()) { return; } + // reset status m_reconnecting = m_hasConfig = m_hasStatus = m_hasEvents = m_hasDiskEvents = false; + + // remove error items (might have been invalidated) + for (SyncthingDir &dir : m_dirs) { + dir.itemErrors.swap(dir.previousItemErrors); + dir.itemErrors.clear(); + } + + // check configuration if (m_apiKey.isEmpty() || m_syncthingUrl.isEmpty()) { emit error(tr("Connection configuration is insufficient."), SyncthingErrorCategory::OverallConnection, QNetworkReply::NoError); return; } + + // start by requesting config and status; if both are available request further info and events requestConfig(); requestStatus(); m_keepPolling = true;