2017-07-14 20:14:15 +02:00
|
|
|
|
#ifndef DATA_SYNCTHINGDIR_H
|
2016-10-04 23:55:20 +02:00
|
|
|
|
#define DATA_SYNCTHINGDIR_H
|
|
|
|
|
|
2020-03-02 15:38:38 +01:00
|
|
|
|
#include "./qstringhash.h"
|
2020-03-01 22:04:30 +01:00
|
|
|
|
#include "./syncthingcompletion.h"
|
2016-10-04 23:55:20 +02:00
|
|
|
|
|
2020-09-04 01:09:18 +02:00
|
|
|
|
#include <qtutilities/misc/compat.h>
|
|
|
|
|
|
2016-10-04 23:55:20 +02:00
|
|
|
|
#include <c++utilities/chrono/datetime.h>
|
|
|
|
|
|
|
|
|
|
#include <QFileInfo>
|
2017-04-23 14:15:03 +02:00
|
|
|
|
#include <QJsonObject>
|
2017-05-01 03:34:43 +02:00
|
|
|
|
#include <QMetaType>
|
|
|
|
|
#include <QString>
|
2016-10-04 23:55:20 +02:00
|
|
|
|
|
2020-04-27 23:08:41 +02:00
|
|
|
|
#include <unordered_map>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2016-10-04 23:55:20 +02:00
|
|
|
|
namespace Data {
|
|
|
|
|
|
2019-09-27 16:48:58 +02:00
|
|
|
|
/// \brief The SyncthingDirStatus enum represents a Syncthing directory status.
|
|
|
|
|
/// \remarks It needs to be kept in sync with the states defined in Syncthing's "syncthing/lib/model/folderstate.go".
|
2019-09-27 16:41:24 +02:00
|
|
|
|
enum class SyncthingDirStatus { Unknown, Idle, WaitingToScan, Scanning, PreparingToSync, Synchronizing, OutOfSync };
|
2016-10-04 23:55:20 +02:00
|
|
|
|
|
2020-01-29 18:51:10 +01:00
|
|
|
|
LIB_SYNCTHING_CONNECTOR_EXPORT QString statusString(SyncthingDirStatus status);
|
2018-05-12 23:08:57 +02:00
|
|
|
|
|
|
|
|
|
enum class SyncthingDirType { Unknown, SendReceive, SendOnly, ReceiveOnly };
|
|
|
|
|
|
2020-01-29 18:51:10 +01:00
|
|
|
|
LIB_SYNCTHING_CONNECTOR_EXPORT QString dirTypeString(SyncthingDirType dirType);
|
2017-02-20 18:00:42 +01:00
|
|
|
|
|
2017-07-14 20:14:15 +02:00
|
|
|
|
struct LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingItemError {
|
2020-03-01 22:04:30 +01:00
|
|
|
|
explicit SyncthingItemError(const QString &message = QString(), const QString &path = QString())
|
2017-05-01 03:34:43 +02:00
|
|
|
|
: message(message)
|
|
|
|
|
, path(path)
|
|
|
|
|
{
|
|
|
|
|
}
|
2016-10-04 23:55:20 +02:00
|
|
|
|
|
2017-07-14 20:14:15 +02:00
|
|
|
|
bool operator==(const SyncthingItemError &other) const
|
2016-10-04 23:55:20 +02:00
|
|
|
|
{
|
|
|
|
|
return message == other.message && path == other.path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString message;
|
|
|
|
|
QString path;
|
|
|
|
|
};
|
|
|
|
|
|
2018-08-04 22:06:31 +02:00
|
|
|
|
struct LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingFileChange {
|
|
|
|
|
QString action;
|
|
|
|
|
QString type;
|
|
|
|
|
QString modifiedBy;
|
|
|
|
|
QString path;
|
2019-06-10 22:48:26 +02:00
|
|
|
|
CppUtilities::DateTime eventTime;
|
2018-08-04 22:06:31 +02:00
|
|
|
|
bool local = false;
|
|
|
|
|
};
|
|
|
|
|
|
2017-05-01 03:34:43 +02:00
|
|
|
|
struct LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingItemDownloadProgress {
|
2020-03-01 22:04:30 +01:00
|
|
|
|
explicit SyncthingItemDownloadProgress(
|
2017-05-01 03:34:43 +02:00
|
|
|
|
const QString &containingDirPath = QString(), const QString &relativeItemPath = QString(), const QJsonObject &values = QJsonObject());
|
2016-10-04 23:55:20 +02:00
|
|
|
|
QString relativePath;
|
|
|
|
|
QFileInfo fileInfo;
|
|
|
|
|
int blocksCurrentlyDownloading = 0;
|
|
|
|
|
int blocksAlreadyDownloaded = 0;
|
|
|
|
|
int totalNumberOfBlocks = 0;
|
|
|
|
|
unsigned int downloadPercentage = 0;
|
|
|
|
|
int blocksCopiedFromOrigin = 0;
|
|
|
|
|
int blocksCopiedFromElsewhere = 0;
|
|
|
|
|
int blocksReused = 0;
|
|
|
|
|
int bytesAlreadyHandled;
|
|
|
|
|
int totalNumberOfBytes = 0;
|
|
|
|
|
QString label;
|
2019-06-10 22:48:26 +02:00
|
|
|
|
CppUtilities::DateTime lastUpdate;
|
2016-10-04 23:55:20 +02:00
|
|
|
|
static constexpr unsigned int syncthingBlockSize = 128 * 1024;
|
|
|
|
|
};
|
|
|
|
|
|
2018-01-27 23:27:50 +01:00
|
|
|
|
struct LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingStatistics {
|
2019-02-27 20:38:37 +01:00
|
|
|
|
Q_GADGET
|
|
|
|
|
Q_PROPERTY(quint64 bytes MEMBER bytes)
|
|
|
|
|
Q_PROPERTY(quint64 deletes MEMBER deletes)
|
|
|
|
|
Q_PROPERTY(quint64 dirs MEMBER dirs)
|
|
|
|
|
Q_PROPERTY(quint64 files MEMBER files)
|
|
|
|
|
Q_PROPERTY(quint64 symlinks MEMBER symlinks)
|
|
|
|
|
|
|
|
|
|
public:
|
2018-01-27 23:27:50 +01:00
|
|
|
|
quint64 bytes = 0;
|
|
|
|
|
quint64 deletes = 0;
|
|
|
|
|
quint64 dirs = 0;
|
|
|
|
|
quint64 files = 0;
|
|
|
|
|
quint64 symlinks = 0;
|
|
|
|
|
|
|
|
|
|
constexpr bool isNull() const;
|
2018-03-29 00:38:21 +02:00
|
|
|
|
constexpr bool operator==(const SyncthingStatistics &other) const;
|
|
|
|
|
constexpr bool operator!=(const SyncthingStatistics &other) const;
|
2018-07-30 23:00:22 +02:00
|
|
|
|
SyncthingStatistics &operator+=(const SyncthingStatistics &other);
|
2018-01-27 23:27:50 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
constexpr bool SyncthingStatistics::isNull() const
|
|
|
|
|
{
|
|
|
|
|
return bytes == 0 && deletes == 0 && dirs == 0 && files == 0 && symlinks == 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-29 00:38:21 +02:00
|
|
|
|
constexpr bool SyncthingStatistics::operator==(const SyncthingStatistics &other) const
|
|
|
|
|
{
|
|
|
|
|
return bytes == other.bytes && deletes == other.deletes && dirs == other.dirs && files == other.files && symlinks == other.symlinks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr bool SyncthingStatistics::operator!=(const SyncthingStatistics &other) const
|
|
|
|
|
{
|
|
|
|
|
return !(*this == other);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-01 03:34:43 +02:00
|
|
|
|
struct LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingDir {
|
2020-03-01 22:04:30 +01:00
|
|
|
|
explicit SyncthingDir(const QString &id = QString(), const QString &label = QString(), const QString &path = QString());
|
2019-06-10 22:48:26 +02:00
|
|
|
|
bool assignStatus(const QString &statusStr, CppUtilities::DateTime time);
|
|
|
|
|
bool assignStatus(SyncthingDirStatus newStatus, CppUtilities::DateTime time);
|
2018-05-12 23:08:57 +02:00
|
|
|
|
bool assignDirType(const QString &dirType);
|
2017-07-31 23:56:06 +02:00
|
|
|
|
const QString &displayName() const;
|
2017-02-20 21:00:18 +01:00
|
|
|
|
QString statusString() const;
|
2018-05-12 23:08:57 +02:00
|
|
|
|
QString dirTypeString() const;
|
2020-09-04 01:09:18 +02:00
|
|
|
|
QtUtilities::StringView pathWithoutTrailingSlash() const;
|
2018-01-27 23:27:50 +01:00
|
|
|
|
bool isLocallyUpToDate() const;
|
2018-01-25 00:03:31 +01:00
|
|
|
|
bool areRemotesUpToDate() const;
|
2018-07-22 22:07:41 +02:00
|
|
|
|
bool isUnshared() const;
|
2016-11-01 17:06:31 +01:00
|
|
|
|
|
2016-10-04 23:55:20 +02:00
|
|
|
|
QString id;
|
|
|
|
|
QString label;
|
|
|
|
|
QString path;
|
2017-08-22 19:45:07 +02:00
|
|
|
|
QStringList deviceIds;
|
|
|
|
|
QStringList deviceNames;
|
2018-05-12 23:08:57 +02:00
|
|
|
|
SyncthingDirType dirType = SyncthingDirType::Unknown;
|
2016-10-04 23:55:20 +02:00
|
|
|
|
int rescanInterval = 0;
|
|
|
|
|
int minDiskFreePercentage = 0;
|
2018-11-02 21:47:27 +01:00
|
|
|
|
SyncthingDirStatus status = SyncthingDirStatus::Unknown;
|
2019-06-10 22:48:26 +02:00
|
|
|
|
CppUtilities::DateTime lastStatusUpdate;
|
|
|
|
|
CppUtilities::DateTime lastSyncStarted;
|
2017-11-22 00:29:50 +01:00
|
|
|
|
int completionPercentage = 0;
|
|
|
|
|
int scanningPercentage = 0;
|
|
|
|
|
double scanningRate = 0;
|
2018-07-22 22:08:38 +02:00
|
|
|
|
double fileSystemWatcherDelay = 0.0;
|
2020-03-02 15:38:38 +01:00
|
|
|
|
std::unordered_map<QString, SyncthingCompletion> completionByDevice;
|
2017-07-14 20:14:15 +02:00
|
|
|
|
QString globalError;
|
2018-11-03 21:30:17 +01:00
|
|
|
|
quint64 pullErrorCount = 0;
|
2017-07-14 20:14:15 +02:00
|
|
|
|
std::vector<SyncthingItemError> itemErrors;
|
2018-08-04 22:06:31 +02:00
|
|
|
|
std::vector<SyncthingFileChange> recentChanges;
|
2018-01-27 23:27:50 +01:00
|
|
|
|
SyncthingStatistics globalStats, localStats, neededStats;
|
2019-06-10 22:48:26 +02:00
|
|
|
|
CppUtilities::DateTime lastStatisticsUpdate;
|
|
|
|
|
CppUtilities::DateTime lastScanTime;
|
|
|
|
|
CppUtilities::DateTime lastFileTime;
|
2016-10-04 23:55:20 +02:00
|
|
|
|
QString lastFileName;
|
|
|
|
|
std::vector<SyncthingItemDownloadProgress> downloadingItems;
|
|
|
|
|
int blocksAlreadyDownloaded = 0;
|
|
|
|
|
int blocksToBeDownloaded = 0;
|
|
|
|
|
QString downloadLabel;
|
2019-09-21 16:28:08 +02:00
|
|
|
|
QString rawStatus;
|
2017-08-23 23:57:26 +02:00
|
|
|
|
unsigned int downloadPercentage = 0;
|
2018-05-12 23:08:57 +02:00
|
|
|
|
bool ignorePermissions = false;
|
2018-07-22 22:08:38 +02:00
|
|
|
|
bool ignoreDelete = false;
|
2018-05-12 23:08:57 +02:00
|
|
|
|
bool ignorePatterns = false;
|
|
|
|
|
bool autoNormalize = false;
|
2017-08-23 23:57:26 +02:00
|
|
|
|
bool lastFileDeleted = false;
|
2018-07-22 22:08:38 +02:00
|
|
|
|
bool fileSystemWatcherEnabled = false;
|
|
|
|
|
bool paused = false;
|
2017-07-14 20:14:15 +02:00
|
|
|
|
|
|
|
|
|
private:
|
2019-06-10 22:48:26 +02:00
|
|
|
|
bool checkWhetherStatusUpdateRelevant(CppUtilities::DateTime time);
|
|
|
|
|
bool finalizeStatusUpdate(SyncthingDirStatus newStatus, CppUtilities::DateTime time);
|
2016-10-04 23:55:20 +02:00
|
|
|
|
};
|
|
|
|
|
|
2017-05-01 03:34:43 +02:00
|
|
|
|
inline SyncthingDir::SyncthingDir(const QString &id, const QString &label, const QString &path)
|
|
|
|
|
: id(id)
|
|
|
|
|
, label(label)
|
|
|
|
|
, path(path)
|
|
|
|
|
{
|
|
|
|
|
}
|
2016-11-01 17:06:31 +01:00
|
|
|
|
|
2017-07-31 23:56:06 +02:00
|
|
|
|
inline const QString &SyncthingDir::displayName() const
|
2016-11-08 19:44:45 +01:00
|
|
|
|
{
|
|
|
|
|
return label.isEmpty() ? id : label;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-12 23:08:57 +02:00
|
|
|
|
inline QString SyncthingDir::dirTypeString() const
|
|
|
|
|
{
|
|
|
|
|
return ::Data::dirTypeString(dirType);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-27 23:27:50 +01:00
|
|
|
|
inline bool SyncthingDir::isLocallyUpToDate() const
|
|
|
|
|
{
|
|
|
|
|
return neededStats.isNull();
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-22 22:07:41 +02:00
|
|
|
|
inline bool SyncthingDir::isUnshared() const
|
|
|
|
|
{
|
|
|
|
|
return deviceIds.empty() && (status == SyncthingDirStatus::Idle || status == SyncthingDirStatus::Unknown);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-10 22:48:26 +02:00
|
|
|
|
inline bool SyncthingDir::assignStatus(SyncthingDirStatus newStatus, CppUtilities::DateTime time)
|
2017-07-14 20:14:15 +02:00
|
|
|
|
{
|
2019-09-21 16:28:08 +02:00
|
|
|
|
if (!checkWhetherStatusUpdateRelevant(time)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
rawStatus.clear();
|
|
|
|
|
return finalizeStatusUpdate(newStatus, time);
|
2017-07-14 20:14:15 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-30 23:00:22 +02:00
|
|
|
|
struct LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingOverallDirStatistics {
|
2019-02-27 20:38:37 +01:00
|
|
|
|
Q_GADGET
|
|
|
|
|
Q_PROPERTY(SyncthingStatistics local MEMBER local)
|
|
|
|
|
Q_PROPERTY(SyncthingStatistics global MEMBER global)
|
|
|
|
|
Q_PROPERTY(SyncthingStatistics needed MEMBER needed)
|
|
|
|
|
|
|
|
|
|
public:
|
2020-03-01 22:04:30 +01:00
|
|
|
|
explicit SyncthingOverallDirStatistics();
|
|
|
|
|
explicit SyncthingOverallDirStatistics(const std::vector<SyncthingDir> &directories);
|
2018-07-30 23:00:22 +02:00
|
|
|
|
|
|
|
|
|
SyncthingStatistics local;
|
|
|
|
|
SyncthingStatistics global;
|
|
|
|
|
SyncthingStatistics needed;
|
|
|
|
|
|
|
|
|
|
bool isNull() const;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
inline SyncthingOverallDirStatistics::SyncthingOverallDirStatistics()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline bool SyncthingOverallDirStatistics::isNull() const
|
|
|
|
|
{
|
|
|
|
|
return local.isNull() && global.isNull();
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-04 23:55:20 +02:00
|
|
|
|
} // namespace Data
|
|
|
|
|
|
2017-07-14 20:14:15 +02:00
|
|
|
|
Q_DECLARE_METATYPE(Data::SyncthingItemError)
|
2017-04-23 13:48:55 +02:00
|
|
|
|
Q_DECLARE_METATYPE(Data::SyncthingItemDownloadProgress)
|
2018-07-30 23:00:22 +02:00
|
|
|
|
Q_DECLARE_METATYPE(Data::SyncthingStatistics)
|
|
|
|
|
Q_DECLARE_METATYPE(Data::SyncthingOverallDirStatistics)
|
2017-04-23 13:48:55 +02:00
|
|
|
|
Q_DECLARE_METATYPE(Data::SyncthingDir)
|
|
|
|
|
|
2016-10-04 23:55:20 +02:00
|
|
|
|
#endif // DATA_SYNCTHINGDIR_H
|