Skip to content

Commit

Permalink
WIP: Add option to consider the status of remote devices for overall …
Browse files Browse the repository at this point in the history
…status

* See #74
* TODO: Better add distinct status e.g. "RemoteSynchronizing"?
* TODO: Add UI and configuration
* TODO: Maybe use an enum here instead of a boolean as it is also wanted
        by other users to have *less* states
        (see #76)?
  • Loading branch information
Martchus committed Dec 23, 2020
1 parent 1bf58bf commit 3389e1e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
12 changes: 12 additions & 0 deletions connector/syncthingconnection.cpp
Expand Up @@ -101,6 +101,7 @@ SyncthingConnection::SyncthingConnection(const QString &syncthingUrl, const QByt
, m_lastFileDeleted(false)
, m_dirStatsAltered(false)
, m_recordFileChanges(false)
, m_considerRemoteProgressForStatus(false)
{
m_trafficPollTimer.setInterval(SyncthingConnectionSettings::defaultTrafficPollInterval);
m_trafficPollTimer.setTimerType(Qt::VeryCoarseTimer);
Expand Down Expand Up @@ -775,6 +776,7 @@ bool SyncthingConnection::applySettings(SyncthingConnectionSettings &connectionS
setDevStatsPollInterval(connectionSettings.devStatsPollInterval);
setErrorsPollInterval(connectionSettings.errorsPollInterval);
setAutoReconnectInterval(connectionSettings.reconnectInterval);
setConsiderRemoteProgressForStatus(connectionSettings.considerRemoteProgressForStatus);

return reconnectRequired;
}
Expand Down Expand Up @@ -826,6 +828,16 @@ void SyncthingConnection::setStatus(SyncthingStatus status)
}
}

// set the status to "synchronizing" if at least one remote device is still in progress
if (!synchronizing && m_considerRemoteProgressForStatus) {
for (const SyncthingDev &dev : m_devs) {
if (dev.status == SyncthingDevStatus::Synchronizing) {
synchronizing = true;
break;
}
}
}

if (synchronizing) {
status = SyncthingStatus::Synchronizing;
} else if (scanning) {
Expand Down
23 changes: 23 additions & 0 deletions connector/syncthingconnection.h
Expand Up @@ -64,6 +64,7 @@ class LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingConnection : public QObject {
Q_PROPERTY(int trafficPollInterval READ trafficPollInterval WRITE setTrafficPollInterval)
Q_PROPERTY(int devStatsPollInterval READ devStatsPollInterval WRITE setDevStatsPollInterval)
Q_PROPERTY(bool recordFileChanges READ recordFileChanges WRITE setRecordFileChanges)
Q_PROPERTY(bool considerRemoteProgressForStatus READ considerRemoteProgressForStatus WRITE setConsiderRemoteProgressForStatus)
Q_PROPERTY(QString myId READ myId NOTIFY myIdChanged)
Q_PROPERTY(QString configDir READ configDir NOTIFY configDirChanged)
Q_PROPERTY(int totalIncomingTraffic READ totalIncomingTraffic NOTIFY trafficChanged)
Expand Down Expand Up @@ -119,6 +120,8 @@ class LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingConnection : public QObject {
void disablePolling();
bool recordFileChanges() const;
void setRecordFileChanges(bool recordFileChanges);
bool considerRemoteProgressForStatus() const;
void setConsiderRemoteProgressForStatus(bool considerRemoteProgressForStatus);

// getter for information retrieved from Syncthing
const QString &configDir() const;
Expand Down Expand Up @@ -359,6 +362,7 @@ private Q_SLOTS:
QJsonObject m_rawConfig;
bool m_dirStatsAltered;
bool m_recordFileChanges;
bool m_considerRemoteProgressForStatus;
};

/*!
Expand Down Expand Up @@ -607,6 +611,25 @@ inline void SyncthingConnection::setRecordFileChanges(bool recordFileChanges)
m_recordFileChanges = recordFileChanges;
}

/*!
* \brief Returns whether progress of remote devices is considered when computing the status.
*/
inline bool SyncthingConnection::considerRemoteProgressForStatus() const
{
return m_considerRemoteProgressForStatus;
}

/*!
* \brief Sets whether the progress of remote devices is considered when computing the status.
*/
inline void SyncthingConnection::setConsiderRemoteProgressForStatus(bool considerRemoteProgressForStatus)
{
if (m_considerRemoteProgressForStatus != considerRemoteProgressForStatus) {
m_considerRemoteProgressForStatus = considerRemoteProgressForStatus;
recalculateStatus();
}
}

/*!
* \brief Returns the Syncthing home/configuration directory.
*/
Expand Down
1 change: 1 addition & 0 deletions connector/syncthingconnectionsettings.h
Expand Up @@ -24,6 +24,7 @@ struct LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingConnectionSettings {
QString httpsCertPath;
QList<QSslError> expectedSslErrors;
bool autoConnect = false;
bool considerRemoteProgressForStatus = false;
bool loadHttpsCert();

static constexpr int defaultTrafficPollInterval = 5000;
Expand Down

0 comments on commit 3389e1e

Please sign in to comment.