2017-07-14 20:14:15 +02:00
|
|
|
|
#ifndef DATA_SYNCTHINGDIR_H
|
2016-10-04 23:55:20 +02:00
|
|
|
|
#define DATA_SYNCTHINGDIR_H
|
|
|
|
|
|
|
|
|
|
#include "./global.h"
|
|
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
|
namespace Data {
|
|
|
|
|
|
2017-05-01 03:34:43 +02:00
|
|
|
|
enum class SyncthingDirStatus { Unknown, Idle, Unshared, Scanning, Synchronizing, OutOfSync };
|
2016-10-04 23:55:20 +02:00
|
|
|
|
|
2017-02-20 18:00:42 +01:00
|
|
|
|
QString statusString(SyncthingDirStatus status);
|
|
|
|
|
|
2017-07-14 20:14:15 +02:00
|
|
|
|
struct LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingItemError {
|
|
|
|
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
2017-05-01 03:34:43 +02:00
|
|
|
|
struct LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingItemDownloadProgress {
|
|
|
|
|
SyncthingItemDownloadProgress(
|
|
|
|
|
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;
|
|
|
|
|
ChronoUtilities::DateTime lastUpdate;
|
|
|
|
|
static constexpr unsigned int syncthingBlockSize = 128 * 1024;
|
|
|
|
|
};
|
|
|
|
|
|
2018-01-24 21:46:18 +01:00
|
|
|
|
struct LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingCompletion {
|
|
|
|
|
ChronoUtilities::DateTime lastUpdate;
|
2018-01-25 00:03:31 +01:00
|
|
|
|
double percentage = 0;
|
2018-01-24 21:46:18 +01:00
|
|
|
|
quint64 globalBytes = 0;
|
2018-03-29 00:38:21 +02:00
|
|
|
|
struct Needed {
|
|
|
|
|
quint64 bytes = 0;
|
|
|
|
|
quint64 items = 0;
|
|
|
|
|
quint64 deletes = 0;
|
|
|
|
|
constexpr bool isNull() const;
|
|
|
|
|
constexpr bool operator==(const Needed &other) const;
|
|
|
|
|
constexpr bool operator!=(const Needed &other) const;
|
|
|
|
|
} needed;
|
2018-01-24 21:46:18 +01:00
|
|
|
|
};
|
|
|
|
|
|
2018-03-29 00:38:21 +02:00
|
|
|
|
constexpr bool SyncthingCompletion::Needed::isNull() const
|
|
|
|
|
{
|
|
|
|
|
return bytes == 0 && items == 0 && deletes == 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr bool SyncthingCompletion::Needed::operator==(const SyncthingCompletion::Needed &other) const
|
|
|
|
|
{
|
|
|
|
|
return bytes == other.bytes && items == other.items && deletes == other.deletes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr bool SyncthingCompletion::Needed::operator!=(const SyncthingCompletion::Needed &other) const
|
|
|
|
|
{
|
|
|
|
|
return !(*this == other);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-27 23:27:50 +01:00
|
|
|
|
struct LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingStatistics {
|
|
|
|
|
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-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 {
|
2016-11-01 17:06:31 +01:00
|
|
|
|
SyncthingDir(const QString &id = QString(), const QString &label = QString(), const QString &path = QString());
|
|
|
|
|
bool assignStatus(const QString &statusStr, ChronoUtilities::DateTime time);
|
|
|
|
|
bool assignStatus(SyncthingDirStatus newStatus, ChronoUtilities::DateTime time);
|
2017-07-31 23:56:06 +02:00
|
|
|
|
const QString &displayName() const;
|
2017-02-20 21:00:18 +01:00
|
|
|
|
QString statusString() const;
|
2017-03-29 23:17:53 +02:00
|
|
|
|
QStringRef pathWithoutTrailingSlash() const;
|
2018-01-27 23:27:50 +01:00
|
|
|
|
bool isLocallyUpToDate() const;
|
2018-01-25 00:03:31 +01:00
|
|
|
|
bool areRemotesUpToDate() 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;
|
2016-10-04 23:55:20 +02:00
|
|
|
|
bool readOnly = false;
|
|
|
|
|
bool ignorePermissions = false;
|
2017-08-23 00:22:02 +02:00
|
|
|
|
bool ignorePatterns = false;
|
2016-10-04 23:55:20 +02:00
|
|
|
|
bool autoNormalize = false;
|
|
|
|
|
int rescanInterval = 0;
|
|
|
|
|
int minDiskFreePercentage = 0;
|
|
|
|
|
SyncthingDirStatus status = SyncthingDirStatus::Idle;
|
|
|
|
|
ChronoUtilities::DateTime lastStatusUpdate;
|
2017-11-22 00:29:50 +01:00
|
|
|
|
int completionPercentage = 0;
|
|
|
|
|
int scanningPercentage = 0;
|
|
|
|
|
double scanningRate = 0;
|
2018-01-24 21:46:18 +01:00
|
|
|
|
std::map<QString, SyncthingCompletion> completionByDevice;
|
2017-07-14 20:14:15 +02:00
|
|
|
|
QString globalError;
|
|
|
|
|
std::vector<SyncthingItemError> itemErrors;
|
|
|
|
|
std::vector<SyncthingItemError> previousItemErrors;
|
2018-01-27 23:27:50 +01:00
|
|
|
|
SyncthingStatistics globalStats, localStats, neededStats;
|
2017-08-23 23:57:26 +02:00
|
|
|
|
ChronoUtilities::DateTime lastStatisticsUpdate;
|
2016-10-04 23:55:20 +02:00
|
|
|
|
ChronoUtilities::DateTime lastScanTime;
|
|
|
|
|
ChronoUtilities::DateTime lastFileTime;
|
|
|
|
|
QString lastFileName;
|
|
|
|
|
std::vector<SyncthingItemDownloadProgress> downloadingItems;
|
|
|
|
|
int blocksAlreadyDownloaded = 0;
|
|
|
|
|
int blocksToBeDownloaded = 0;
|
|
|
|
|
QString downloadLabel;
|
2017-08-23 23:57:26 +02:00
|
|
|
|
unsigned int downloadPercentage = 0;
|
|
|
|
|
bool paused = false;
|
|
|
|
|
bool lastFileDeleted = false;
|
2017-07-14 20:14:15 +02:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool checkWhetherStatusUpdateRelevant(ChronoUtilities::DateTime time);
|
|
|
|
|
bool finalizeStatusUpdate(SyncthingDirStatus newStatus);
|
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-01-27 23:27:50 +01:00
|
|
|
|
inline bool SyncthingDir::isLocallyUpToDate() const
|
|
|
|
|
{
|
|
|
|
|
return neededStats.isNull();
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-14 20:14:15 +02:00
|
|
|
|
inline bool SyncthingDir::assignStatus(SyncthingDirStatus newStatus, ChronoUtilities::DateTime time)
|
|
|
|
|
{
|
|
|
|
|
return checkWhetherStatusUpdateRelevant(time) && finalizeStatusUpdate(newStatus);
|
|
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
|
|
Q_DECLARE_METATYPE(Data::SyncthingDir)
|
|
|
|
|
|
2016-10-04 23:55:20 +02:00
|
|
|
|
#endif // DATA_SYNCTHINGDIR_H
|