diff --git a/cli/application.cpp b/cli/application.cpp index bbc538a..4ef4f9b 100644 --- a/cli/application.cpp +++ b/cli/application.cpp @@ -227,6 +227,11 @@ int Application::loadConfig() return res; } + // disable polling for information which is not used by any CLI operation so far + m_settings.trafficPollInterval = 0; + m_settings.devStatsPollInterval = 0; + m_settings.errorsPollInterval = 0; + return 0; } diff --git a/connector/syncthingconnection.cpp b/connector/syncthingconnection.cpp index 2872c76..3a2661c 100644 --- a/connector/syncthingconnection.cpp +++ b/connector/syncthingconnection.cpp @@ -102,19 +102,20 @@ SyncthingConnection::SyncthingConnection(const QString &syncthingUrl, const QByt , m_hasDiskEvents(false) , m_lastFileDeleted(false) { - m_trafficPollTimer.setInterval(2000); + m_trafficPollTimer.setInterval(SyncthingConnectionSettings::defaultTrafficPollInterval); m_trafficPollTimer.setTimerType(Qt::VeryCoarseTimer); m_trafficPollTimer.setSingleShot(true); QObject::connect(&m_trafficPollTimer, &QTimer::timeout, this, &SyncthingConnection::requestConnections); - m_devStatsPollTimer.setInterval(60000); + m_devStatsPollTimer.setInterval(SyncthingConnectionSettings::defaultDevStatusPollInterval); m_devStatsPollTimer.setTimerType(Qt::VeryCoarseTimer); m_devStatsPollTimer.setSingleShot(true); QObject::connect(&m_devStatsPollTimer, &QTimer::timeout, this, &SyncthingConnection::requestDeviceStatistics); - m_errorsPollTimer.setInterval(30000); + m_errorsPollTimer.setInterval(SyncthingConnectionSettings::defaultErrorsPollInterval); m_errorsPollTimer.setTimerType(Qt::VeryCoarseTimer); m_errorsPollTimer.setSingleShot(true); QObject::connect(&m_errorsPollTimer, &QTimer::timeout, this, &SyncthingConnection::requestErrors); m_autoReconnectTimer.setTimerType(Qt::VeryCoarseTimer); + m_autoReconnectTimer.setInterval(SyncthingConnectionSettings::defaultReconnectInterval); QObject::connect(&m_autoReconnectTimer, &QTimer::timeout, this, &SyncthingConnection::autoReconnect); #ifdef LIB_SYNCTHING_CONNECTOR_CONNECTION_MOCKED setupTestData(); @@ -176,6 +177,17 @@ bool SyncthingConnection::hasOutOfSyncDirs() const return false; } +/*! + * \brief Sets all polling intervals (traffic, device statistics, errors) to 0 so polling is disabled. + * \remarks Does not affect the auto-reconnect and does not affect the *long* polling for the event API. + */ +void SyncthingConnection::disablePolling() +{ + setTrafficPollInterval(0); + setDevStatsPollInterval(0); + setErrorsPollInterval(0); +} + /*! * \brief Connects asynchronously to Syncthing. Does nothing if already connected. */ diff --git a/connector/syncthingconnection.h b/connector/syncthingconnection.h index 8eb08f7..9cea97d 100644 --- a/connector/syncthingconnection.h +++ b/connector/syncthingconnection.h @@ -127,6 +127,7 @@ public: int autoReconnectInterval() const; unsigned int autoReconnectTries() const; void setAutoReconnectInterval(int interval); + void disablePolling(); // getter for information retrieved from Syncthing const QString &configDir() const; @@ -491,8 +492,8 @@ inline void SyncthingConnection::considerAllNotificationsRead() } /*! - * \brief Returns the interval for polling traffic status (which currently can not be received via event API) in milliseconds. - * \remarks Default value is 2000 milliseconds. + * \brief Returns the interval for polling traffic status (which can not be received via event API) in milliseconds. + * \remarks For default value see SyncthingConnectionSettings. Zero means polling is disabled. */ inline int SyncthingConnection::trafficPollInterval() const { @@ -500,8 +501,8 @@ inline int SyncthingConnection::trafficPollInterval() const } /*! - * \brief Sets the interval for polling traffic status (which currently can not be received via event API) in milliseconds. - * \remarks Default value is 2000 milliseconds. + * \brief Sets the interval for polling traffic status (which can not be received via event API) in milliseconds. + * \remarks For default value see SyncthingConnectionSettings. Zero means polling is disabled. */ inline void SyncthingConnection::setTrafficPollInterval(int trafficPollInterval) { @@ -512,8 +513,8 @@ inline void SyncthingConnection::setTrafficPollInterval(int trafficPollInterval) } /*! - * \brief Returns the interval for polling device statistics (which currently can not be received via event API) in milliseconds. - * \remarks Default value is 60000 milliseconds. + * \brief Returns the interval for polling device statistics (which can not be received via event API) in milliseconds. + * \remarks For default value see SyncthingConnectionSettings. Zero means polling is disabled. */ inline int SyncthingConnection::devStatsPollInterval() const { @@ -521,8 +522,8 @@ inline int SyncthingConnection::devStatsPollInterval() const } /*! - * \brief Sets the interval for polling device statistics (which currently can not be received via event API) in milliseconds. - * \remarks Default value is 60000 milliseconds. + * \brief Sets the interval for polling device statistics (which can not be received via event API) in milliseconds. + * \remarks For default value see SyncthingConnectionSettings. Zero means polling is disabled. */ inline void SyncthingConnection::setDevStatsPollInterval(int devStatsPollInterval) { @@ -533,8 +534,8 @@ inline void SyncthingConnection::setDevStatsPollInterval(int devStatsPollInterva } /*! - * \brief Returns the interval for polling Syncthing errors (which currently can not be received via event API) in milliseconds. - * \remarks Default value is 30000 milliseconds. + * \brief Returns the interval for polling Syncthing errors (which can not be received via event API) in milliseconds. + * \remarks For default value see SyncthingConnectionSettings. Zero means polling is disabled. */ inline int SyncthingConnection::errorsPollInterval() const { @@ -542,8 +543,8 @@ inline int SyncthingConnection::errorsPollInterval() const } /*! - * \brief Sets the interval for polling Syncthing errors (which currently can not be received via event API) in milliseconds. - * \remarks Default value is 30000 milliseconds. + * \brief Sets the interval for polling Syncthing errors (which can not be received via event API) in milliseconds. + * \remarks For default value see SyncthingConnectionSettings. Zero means polling is disabled. */ inline void SyncthingConnection::setErrorsPollInterval(int errorPollInterval) { @@ -555,7 +556,7 @@ inline void SyncthingConnection::setErrorsPollInterval(int errorPollInterval) /*! * \brief Returns the reconnect interval in milliseconds. - * \remarks Default value is 0 which indicates disabled auto-reconnect. + * \remarks For default value see SyncthingConnectionSettings. A value of 0 indicates that auto-reconnect is disabled. */ inline int SyncthingConnection::autoReconnectInterval() const { @@ -572,7 +573,7 @@ inline unsigned int SyncthingConnection::autoReconnectTries() const /*! * \brief Sets the reconnect interval in milliseconds. - * \remarks Default value is 0 which indicates disabled auto-reconnect. + * \remarks For default value see SyncthingConnectionSettings. A value of 0 indicates that auto-reconnect is disabled. */ inline void SyncthingConnection::setAutoReconnectInterval(int interval) { diff --git a/connector/syncthingconnectionsettings.h b/connector/syncthingconnectionsettings.h index 4b6988d..22d5c96 100644 --- a/connector/syncthingconnectionsettings.h +++ b/connector/syncthingconnectionsettings.h @@ -16,13 +16,18 @@ struct LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingConnectionSettings { QString userName; QString password; QByteArray apiKey; - int trafficPollInterval = 2000; - int devStatsPollInterval = 60000; - int errorsPollInterval = 30000; - int reconnectInterval = 30000; + int trafficPollInterval = defaultTrafficPollInterval; + int devStatsPollInterval = defaultDevStatusPollInterval; + int errorsPollInterval = defaultErrorsPollInterval; + int reconnectInterval = defaultReconnectInterval; QString httpsCertPath; QList expectedSslErrors; bool loadHttpsCert(); + + static constexpr int defaultTrafficPollInterval = 5000; + static constexpr int defaultDevStatusPollInterval = 60000; + static constexpr int defaultErrorsPollInterval = 30000; + static constexpr int defaultReconnectInterval = 0; }; } // namespace Data