diff --git a/cli/application.cpp b/cli/application.cpp index efeb671..b852c35 100644 --- a/cli/application.cpp +++ b/cli/application.cpp @@ -297,15 +297,15 @@ void Application::printStatus(const ArgumentOccurrence &) printProperty("Path", dir->path); const char *status; switch(dir->status) { - case DirStatus::Idle: + case SyncthingDirStatus::Idle: status = "idle"; break; - case DirStatus::Scanning: + case SyncthingDirStatus::Scanning: status = "scanning"; break; - case DirStatus::Synchronizing: + case SyncthingDirStatus::Synchronizing: status = "synchronizing"; break; - case DirStatus::Paused: + case SyncthingDirStatus::Paused: status = "paused"; break; - case DirStatus::OutOfSync: + case SyncthingDirStatus::OutOfSync: status = "out of sync"; break; default: status = "unknown"; @@ -323,7 +323,7 @@ void Application::printStatus(const ArgumentOccurrence &) printProperty("Min. free disk percentage", dir->minDiskFreePercentage); if(!dir->errors.empty()) { cout << " Errors\n"; - for(const DirError &error : dir->errors) { + for(const SyncthingDirError &error : dir->errors) { printProperty(" - Message", error.message); printProperty(" File", error.path); } @@ -348,17 +348,17 @@ void Application::printStatus(const ArgumentOccurrence &) status = "paused"; } else { switch(dev->status) { - case DevStatus::Disconnected: + case SyncthingDevStatus::Disconnected: status = "disconnected"; break; - case DevStatus::OwnDevice: + case SyncthingDevStatus::OwnDevice: status = "own device"; break; - case DevStatus::Idle: + case SyncthingDevStatus::Idle: status = "idle"; break; - case DevStatus::Synchronizing: + case SyncthingDevStatus::Synchronizing: status = "synchronizing"; break; - case DevStatus::OutOfSync: + case SyncthingDevStatus::OutOfSync: status = "out of sync"; break; - case DevStatus::Rejected: + case SyncthingDevStatus::Rejected: status = "rejected"; break; default: status = "unknown"; diff --git a/connector/CMakeLists.txt b/connector/CMakeLists.txt index cef2be3..fdf309f 100644 --- a/connector/CMakeLists.txt +++ b/connector/CMakeLists.txt @@ -9,6 +9,8 @@ set(META_PROJECT_VARNAME_UPPER LIB_SYNCTHING_CONNECTOR) # add project files set(HEADER_FILES + syncthingdir.h + syncthingdev.h syncthingconnection.h syncthingconnectionsettings.h syncthingconfig.h @@ -16,6 +18,8 @@ set(HEADER_FILES utils.h ) set(SRC_FILES + syncthingdir.cpp + syncthingdev.cpp syncthingconnection.cpp syncthingconnectionsettings.cpp syncthingconfig.cpp diff --git a/connector/syncthingconnection.cpp b/connector/syncthingconnection.cpp index aa78d21..6ee74de 100644 --- a/connector/syncthingconnection.cpp +++ b/connector/syncthingconnection.cpp @@ -34,101 +34,6 @@ QNetworkAccessManager &networkAccessManager() return *networkAccessManager; } -/*! - * \brief Assigns the status from the specified status string. - * \returns Returns whether the status has actually changed. - */ -bool SyncthingDir::assignStatus(const QString &statusStr, ChronoUtilities::DateTime time) -{ - if(lastStatusUpdate > time) { - return false; - } else { - lastStatusUpdate = time; - } - DirStatus newStatus; - if(statusStr == QLatin1String("idle")) { - progressPercentage = 0; - newStatus = errors.empty() ? DirStatus::Idle : DirStatus::OutOfSync; - } else if(statusStr == QLatin1String("scanning")) { - newStatus = DirStatus::Scanning; - } else if(statusStr == QLatin1String("syncing")) { - if(!errors.empty()) { - errors.clear(); // errors become obsolete - status = DirStatus::Unknown; // ensure status changed signal is emitted - } - newStatus = DirStatus::Synchronizing; - } else if(statusStr == QLatin1String("error")) { - progressPercentage = 0; - newStatus = DirStatus::OutOfSync; - } else { - newStatus = errors.empty() ? DirStatus::Idle : DirStatus::OutOfSync; - } - if(newStatus != status) { - switch(status) { - case DirStatus::Scanning: - lastScanTime = DateTime::now(); - break; - default: - ; - } - status = newStatus; - return true; - } - return false; -} - -bool SyncthingDir::assignStatus(DirStatus newStatus, DateTime time) -{ - if(lastStatusUpdate > time) { - return false; - } else { - lastStatusUpdate = time; - } - switch(newStatus) { - case DirStatus::Idle: - case DirStatus::Unknown: - if(!errors.empty()) { - newStatus = DirStatus::OutOfSync; - } - break; - default: - ; - } - if(newStatus != status) { - switch(status) { - case DirStatus::Scanning: - lastScanTime = DateTime::now(); - break; - default: - ; - } - status = newStatus; - return true; - } - return false; -} - -SyncthingItemDownloadProgress::SyncthingItemDownloadProgress(const QString &containingDirPath, const QString &relativeItemPath, const QJsonObject &values) : - relativePath(relativeItemPath), - fileInfo(containingDirPath % QChar('/') % QString(relativeItemPath).replace(QChar('\\'), QChar('/'))), - blocksCurrentlyDownloading(values.value(QStringLiteral("Pulling")).toInt()), - blocksAlreadyDownloaded(values.value(QStringLiteral("Pulled")).toInt()), - totalNumberOfBlocks(values.value(QStringLiteral("Total")).toInt()), - downloadPercentage((blocksAlreadyDownloaded > 0 && totalNumberOfBlocks > 0) - ? (static_cast(blocksAlreadyDownloaded) * 100 / static_cast(totalNumberOfBlocks)) - : 0), - blocksCopiedFromOrigin(values.value(QStringLiteral("CopiedFromOrigin")).toInt()), - blocksCopiedFromElsewhere(values.value(QStringLiteral("CopiedFromElsewhere")).toInt()), - blocksReused(values.value(QStringLiteral("Reused")).toInt()), - bytesAlreadyHandled(values.value(QStringLiteral("BytesDone")).toInt()), - totalNumberOfBytes(values.value(QStringLiteral("BytesTotal")).toInt()), - label(QStringLiteral("%1 / %2 - %3 %").arg( - QString::fromLatin1(dataSizeToString(blocksAlreadyDownloaded > 0 ? static_cast(blocksAlreadyDownloaded) * syncthingBlockSize : 0).data()), - QString::fromLatin1(dataSizeToString(totalNumberOfBlocks > 0 ? static_cast(totalNumberOfBlocks) * syncthingBlockSize : 0).data()), - QString::number(downloadPercentage)) - ) -{} - /*! * \class SyncthingConnection * \brief The SyncthingConnection class allows Qt applications to access Syncthing. @@ -199,7 +104,7 @@ QString SyncthingConnection::statusText() const bool SyncthingConnection::hasOutOfSyncDirs() const { for(const SyncthingDir &dir : m_dirs) { - if(dir.status == DirStatus::OutOfSync) { + if(dir.status == SyncthingDirStatus::OutOfSync) { return true; } } @@ -799,7 +704,7 @@ void SyncthingConnection::readDevs(const QJsonArray &devs) devItem.compression = devObj.value(QStringLiteral("compression")).toString(); devItem.certName = devObj.value(QStringLiteral("certName")).toString(); devItem.introducer = devObj.value(QStringLiteral("introducer")).toBool(false); - devItem.status = devItem.id == m_myId ? DevStatus::OwnDevice : DevStatus::Unknown; + devItem.status = devItem.id == m_myId ? SyncthingDevStatus::OwnDevice : SyncthingDevStatus::Unknown; m_devs.push_back(move(devItem)); } } @@ -829,7 +734,7 @@ void SyncthingConnection::readStatus() int index = 0; for(SyncthingDev &dev : m_devs) { if(dev.id == m_myId) { - dev.status = DevStatus::OwnDevice; + dev.status = SyncthingDevStatus::OwnDevice; emit devStatusChanged(dev, index); break; } @@ -888,19 +793,19 @@ void SyncthingConnection::readConnections() const QJsonObject connectionObj(connectionsObj.value(dev.id).toObject()); if(!connectionObj.isEmpty()) { switch(dev.status) { - case DevStatus::OwnDevice: + case SyncthingDevStatus::OwnDevice: break; - case DevStatus::Disconnected: - case DevStatus::Unknown: + case SyncthingDevStatus::Disconnected: + case SyncthingDevStatus::Unknown: if(connectionObj.value(QStringLiteral("connected")).toBool(false)) { - dev.status = DevStatus::Idle; + dev.status = SyncthingDevStatus::Idle; } else { - dev.status = DevStatus::Disconnected; + dev.status = SyncthingDevStatus::Disconnected; } break; default: if(!connectionObj.value(QStringLiteral("connected")).toBool(false)) { - dev.status = DevStatus::Disconnected; + dev.status = SyncthingDevStatus::Disconnected; } } dev.paused = connectionObj.value(QStringLiteral("paused")).toBool(false); @@ -1244,10 +1149,10 @@ void SyncthingConnection::readDirEvent(DateTime eventTime, const QString &eventT const QJsonObject error(errorVal.toObject()); if(!error.isEmpty()) { auto &errors = dirInfo->errors; - DirError dirError(error.value(QStringLiteral("error")).toString(), error.value(QStringLiteral("path")).toString()); + SyncthingDirError dirError(error.value(QStringLiteral("error")).toString(), error.value(QStringLiteral("path")).toString()); if(find(errors.cbegin(), errors.cend(), dirError) == errors.cend()) { errors.emplace_back(move(dirError)); - dirInfo->assignStatus(DirStatus::OutOfSync, eventTime); + dirInfo->assignStatus(SyncthingDirStatus::OutOfSync, eventTime); emitNotification(eventTime, dirInfo->errors.back().message); } } @@ -1286,7 +1191,7 @@ void SyncthingConnection::readDirEvent(DateTime eventTime, const QString &eventT if(current > 0 && total > 0) { dirInfo->progressPercentage = current * 100 / total; dirInfo->progressRate = rate; - dirInfo->assignStatus(DirStatus::Scanning, eventTime); // ensure state is scanning + dirInfo->assignStatus(SyncthingDirStatus::Scanning, eventTime); // ensure state is scanning emit dirStatusChanged(*dirInfo, index); } } @@ -1307,28 +1212,28 @@ void SyncthingConnection::readDeviceEvent(DateTime eventTime, const QString &eve // dev status changed, depending on event type int index; if(SyncthingDev *devInfo = findDevInfo(dev, index)) { - DevStatus status = devInfo->status; + SyncthingDevStatus status = devInfo->status; bool paused = devInfo->paused; if(eventType == QLatin1String("DeviceConnected")) { - status = DevStatus::Idle; // TODO: figure out when dev is actually syncing + status = SyncthingDevStatus::Idle; // TODO: figure out when dev is actually syncing } else if(eventType == QLatin1String("DeviceDisconnected")) { - status = DevStatus::Disconnected; + status = SyncthingDevStatus::Disconnected; } else if(eventType == QLatin1String("DevicePaused")) { paused = true; } else if(eventType == QLatin1String("DeviceRejected")) { - status = DevStatus::Rejected; + status = SyncthingDevStatus::Rejected; } else if(eventType == QLatin1String("DeviceResumed")) { paused = false; // FIXME: correct to assume device which has just been resumed is still disconnected? - status = DevStatus::Disconnected; + status = SyncthingDevStatus::Disconnected; } else if(eventType == QLatin1String("DeviceDiscovered")) { // we know about this device already, set status anyways because it might still be unknown - status = DevStatus::Disconnected; + status = SyncthingDevStatus::Disconnected; } else { return; // can't handle other event types currently } if(devInfo->status != status || devInfo->paused != paused) { - if(devInfo->status != DevStatus::OwnDevice) { // don't mess with the status of the own device + if(devInfo->status != SyncthingDevStatus::OwnDevice) { // don't mess with the status of the own device devInfo->status = status; } devInfo->paused = paused; @@ -1371,10 +1276,10 @@ void SyncthingConnection::readItemFinished(DateTime eventTime, const QJsonObject } emit dirStatusChanged(*dirInfo, index); } - } else if(dirInfo->status == DirStatus::OutOfSync) { + } else if(dirInfo->status == SyncthingDirStatus::OutOfSync) { // FIXME: find better way to check whether the event is still relevant dirInfo->errors.emplace_back(error, item); - dirInfo->status = DirStatus::OutOfSync; + dirInfo->status = SyncthingDirStatus::OutOfSync; emit dirStatusChanged(*dirInfo, index); emitNotification(eventTime, error); } @@ -1469,10 +1374,10 @@ void SyncthingConnection::setStatus(SyncthingStatus status) bool scanning = false; bool synchronizing = false; for(const SyncthingDir &dir : m_dirs) { - if(dir.status == DirStatus::Synchronizing) { + if(dir.status == SyncthingDirStatus::Synchronizing) { synchronizing = true; break; - } else if(dir.status == DirStatus::Scanning) { + } else if(dir.status == SyncthingDirStatus::Scanning) { scanning = true; } } diff --git a/connector/syncthingconnection.h b/connector/syncthingconnection.h index 76197c8..63bff60 100644 --- a/connector/syncthingconnection.h +++ b/connector/syncthingconnection.h @@ -1,14 +1,12 @@ #ifndef SYNCTHINGCONNECTION_H #define SYNCTHINGCONNECTION_H -#include "./global.h" - -#include +#include "./syncthingdir.h" +#include "./syncthingdev.h" #include #include #include -#include #include #include @@ -38,115 +36,6 @@ enum class SyncthingStatus BeingDestroyed }; -enum class DirStatus -{ - Unknown, - Idle, - Scanning, - Synchronizing, - Paused, - OutOfSync -}; - -struct LIB_SYNCTHING_CONNECTOR_EXPORT DirError -{ - DirError(const QString &message, const QString &path) : - message(message), - path(path) - {} - - bool operator ==(const DirError &other) const - { - return message == other.message && path == other.path; - } - - QString message; - QString path; -}; - -struct LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingItemDownloadProgress -{ - SyncthingItemDownloadProgress(const QString &containingDirPath, const QString &relativeItemPath, const QJsonObject &values); - 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; -}; - -struct LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingDir -{ - QString id; - QString label; - QString path; - QStringList devices; - bool readOnly = false; - bool ignorePermissions = false; - bool autoNormalize = false; - int rescanInterval = 0; - int minDiskFreePercentage = 0; - DirStatus status = DirStatus::Idle; - ChronoUtilities::DateTime lastStatusUpdate; - int progressPercentage = 0; - int progressRate = 0; - std::vector errors; - int globalBytes = 0, globalDeleted = 0, globalFiles = 0; - int localBytes = 0, localDeleted = 0, localFiles = 0; - int neededByted = 0, neededFiles = 0; - ChronoUtilities::DateTime lastScanTime; - ChronoUtilities::DateTime lastFileTime; - QString lastFileName; - bool lastFileDeleted = false; - std::vector downloadingItems; - int blocksAlreadyDownloaded = 0; - int blocksToBeDownloaded = 0; - unsigned int downloadPercentage = 0; - QString downloadLabel; - - bool assignStatus(const QString &statusStr, ChronoUtilities::DateTime time); - bool assignStatus(DirStatus newStatus, ChronoUtilities::DateTime time); -}; - -enum class DevStatus -{ - Unknown, - Disconnected, - OwnDevice, - Idle, - Synchronizing, - OutOfSync, - Rejected -}; - -struct LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingDev -{ - QString id; - QString name; - QStringList addresses; - QString compression; - QString certName; - DevStatus status; - int progressPercentage = 0; - int progressRate = 0; - bool introducer = false; - bool paused = false; - int totalIncomingTraffic = 0; - int totalOutgoingTraffic = 0; - QString connectionAddress; - QString connectionType; - QString clientVersion; - ChronoUtilities::DateTime lastSeen; -}; - struct LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingLogEntry { SyncthingLogEntry(const QString &when, const QString &message) : diff --git a/connector/syncthingdev.cpp b/connector/syncthingdev.cpp new file mode 100644 index 0000000..9c7bce5 --- /dev/null +++ b/connector/syncthingdev.cpp @@ -0,0 +1,7 @@ +#include "./syncthingdev.h" + +namespace Data { + + + +} // namespace Data diff --git a/connector/syncthingdev.h b/connector/syncthingdev.h new file mode 100644 index 0000000..8d2297d --- /dev/null +++ b/connector/syncthingdev.h @@ -0,0 +1,46 @@ +#ifndef DATA_SYNCTHINGDEV_H +#define DATA_SYNCTHINGDEV_H + +#include "./global.h" + +#include + +#include +#include + +namespace Data { + +enum class SyncthingDevStatus +{ + Unknown, + Disconnected, + OwnDevice, + Idle, + Synchronizing, + OutOfSync, + Rejected +}; + +struct LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingDev +{ + QString id; + QString name; + QStringList addresses; + QString compression; + QString certName; + SyncthingDevStatus status; + int progressPercentage = 0; + int progressRate = 0; + bool introducer = false; + bool paused = false; + int totalIncomingTraffic = 0; + int totalOutgoingTraffic = 0; + QString connectionAddress; + QString connectionType; + QString clientVersion; + ChronoUtilities::DateTime lastSeen; +}; + +} // namespace Data + +#endif // DATA_SYNCTHINGDEV_H diff --git a/connector/syncthingdir.cpp b/connector/syncthingdir.cpp new file mode 100644 index 0000000..5763d7e --- /dev/null +++ b/connector/syncthingdir.cpp @@ -0,0 +1,108 @@ +#include "./syncthingdir.h" + +#include + +#include +#include + +using namespace ChronoUtilities; +using namespace ConversionUtilities; + +namespace Data { + +/*! + * \brief Assigns the status from the specified status string. + * \returns Returns whether the status has actually changed. + */ +bool SyncthingDir::assignStatus(const QString &statusStr, ChronoUtilities::DateTime time) +{ + if(lastStatusUpdate > time) { + return false; + } else { + lastStatusUpdate = time; + } + SyncthingDirStatus newStatus; + if(statusStr == QLatin1String("idle")) { + progressPercentage = 0; + newStatus = errors.empty() ? SyncthingDirStatus::Idle : SyncthingDirStatus::OutOfSync; + } else if(statusStr == QLatin1String("scanning")) { + newStatus = SyncthingDirStatus::Scanning; + } else if(statusStr == QLatin1String("syncing")) { + if(!errors.empty()) { + errors.clear(); // errors become obsolete + status = SyncthingDirStatus::Unknown; // ensure status changed signal is emitted + } + newStatus = SyncthingDirStatus::Synchronizing; + } else if(statusStr == QLatin1String("error")) { + progressPercentage = 0; + newStatus = SyncthingDirStatus::OutOfSync; + } else { + newStatus = errors.empty() ? SyncthingDirStatus::Idle : SyncthingDirStatus::OutOfSync; + } + if(newStatus != status) { + switch(status) { + case SyncthingDirStatus::Scanning: + lastScanTime = DateTime::now(); + break; + default: + ; + } + status = newStatus; + return true; + } + return false; +} + +bool SyncthingDir::assignStatus(SyncthingDirStatus newStatus, DateTime time) +{ + if(lastStatusUpdate > time) { + return false; + } else { + lastStatusUpdate = time; + } + switch(newStatus) { + case SyncthingDirStatus::Idle: + case SyncthingDirStatus::Unknown: + if(!errors.empty()) { + newStatus = SyncthingDirStatus::OutOfSync; + } + break; + default: + ; + } + if(newStatus != status) { + switch(status) { + case SyncthingDirStatus::Scanning: + lastScanTime = DateTime::now(); + break; + default: + ; + } + status = newStatus; + return true; + } + return false; +} + +SyncthingItemDownloadProgress::SyncthingItemDownloadProgress(const QString &containingDirPath, const QString &relativeItemPath, const QJsonObject &values) : + relativePath(relativeItemPath), + fileInfo(containingDirPath % QChar('/') % QString(relativeItemPath).replace(QChar('\\'), QChar('/'))), + blocksCurrentlyDownloading(values.value(QStringLiteral("Pulling")).toInt()), + blocksAlreadyDownloaded(values.value(QStringLiteral("Pulled")).toInt()), + totalNumberOfBlocks(values.value(QStringLiteral("Total")).toInt()), + downloadPercentage((blocksAlreadyDownloaded > 0 && totalNumberOfBlocks > 0) + ? (static_cast(blocksAlreadyDownloaded) * 100 / static_cast(totalNumberOfBlocks)) + : 0), + blocksCopiedFromOrigin(values.value(QStringLiteral("CopiedFromOrigin")).toInt()), + blocksCopiedFromElsewhere(values.value(QStringLiteral("CopiedFromElsewhere")).toInt()), + blocksReused(values.value(QStringLiteral("Reused")).toInt()), + bytesAlreadyHandled(values.value(QStringLiteral("BytesDone")).toInt()), + totalNumberOfBytes(values.value(QStringLiteral("BytesTotal")).toInt()), + label(QStringLiteral("%1 / %2 - %3 %").arg( + QString::fromLatin1(dataSizeToString(blocksAlreadyDownloaded > 0 ? static_cast(blocksAlreadyDownloaded) * syncthingBlockSize : 0).data()), + QString::fromLatin1(dataSizeToString(totalNumberOfBlocks > 0 ? static_cast(totalNumberOfBlocks) * syncthingBlockSize : 0).data()), + QString::number(downloadPercentage)) + ) +{} + +} // namespace Data diff --git a/connector/syncthingdir.h b/connector/syncthingdir.h new file mode 100644 index 0000000..66201d1 --- /dev/null +++ b/connector/syncthingdir.h @@ -0,0 +1,95 @@ +#ifndef DATA_SYNCTHINGDIR_H +#define DATA_SYNCTHINGDIR_H + +#include "./global.h" + +#include + +#include +#include + +QT_FORWARD_DECLARE_CLASS(QJsonObject) + +namespace Data { + +enum class SyncthingDirStatus +{ + Unknown, + Idle, + Scanning, + Synchronizing, + Paused, + OutOfSync +}; + +struct LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingDirError +{ + SyncthingDirError(const QString &message, const QString &path) : + message(message), + path(path) + {} + + bool operator ==(const SyncthingDirError &other) const + { + return message == other.message && path == other.path; + } + + QString message; + QString path; +}; + +struct LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingItemDownloadProgress +{ + SyncthingItemDownloadProgress(const QString &containingDirPath, const QString &relativeItemPath, const QJsonObject &values); + 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; +}; + +struct LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingDir +{ + QString id; + QString label; + QString path; + QStringList devices; + bool readOnly = false; + bool ignorePermissions = false; + bool autoNormalize = false; + int rescanInterval = 0; + int minDiskFreePercentage = 0; + SyncthingDirStatus status = SyncthingDirStatus::Idle; + ChronoUtilities::DateTime lastStatusUpdate; + int progressPercentage = 0; + int progressRate = 0; + std::vector errors; + int globalBytes = 0, globalDeleted = 0, globalFiles = 0; + int localBytes = 0, localDeleted = 0, localFiles = 0; + int neededByted = 0, neededFiles = 0; + ChronoUtilities::DateTime lastScanTime; + ChronoUtilities::DateTime lastFileTime; + QString lastFileName; + bool lastFileDeleted = false; + std::vector downloadingItems; + int blocksAlreadyDownloaded = 0; + int blocksToBeDownloaded = 0; + unsigned int downloadPercentage = 0; + QString downloadLabel; + + bool assignStatus(const QString &statusStr, ChronoUtilities::DateTime time); + bool assignStatus(SyncthingDirStatus newStatus, ChronoUtilities::DateTime time); +}; + +} // namespace Data + +#endif // DATA_SYNCTHINGDIR_H diff --git a/model/syncthingdevicemodel.cpp b/model/syncthingdevicemodel.cpp index f97cbff..564942d 100644 --- a/model/syncthingdevicemodel.cpp +++ b/model/syncthingdevicemodel.cpp @@ -153,13 +153,13 @@ QVariant SyncthingDeviceModel::data(const QModelIndex &index, int role) const return tr("Paused"); } else { switch(dev.status) { - case DevStatus::Unknown: return tr("Unknown status"); - case DevStatus::OwnDevice: return tr("Own device"); - case DevStatus::Idle: return tr("Idle"); - case DevStatus::Disconnected: return tr("Disconnected"); - case DevStatus::Synchronizing: return dev.progressPercentage > 0 ? tr("Synchronizing (%1 %)").arg(dev.progressPercentage) : tr("Synchronizing"); - case DevStatus::OutOfSync: return tr("Out of sync"); - case DevStatus::Rejected: return tr("Rejected"); + case SyncthingDevStatus::Unknown: return tr("Unknown status"); + case SyncthingDevStatus::OwnDevice: return tr("Own device"); + case SyncthingDevStatus::Idle: return tr("Idle"); + case SyncthingDevStatus::Disconnected: return tr("Disconnected"); + case SyncthingDevStatus::Synchronizing: return dev.progressPercentage > 0 ? tr("Synchronizing (%1 %)").arg(dev.progressPercentage) : tr("Synchronizing"); + case SyncthingDevStatus::OutOfSync: return tr("Out of sync"); + case SyncthingDevStatus::Rejected: return tr("Rejected"); } } break; @@ -172,13 +172,13 @@ QVariant SyncthingDeviceModel::data(const QModelIndex &index, int role) const return m_pausedIcon; } else { switch(dev.status) { - case DevStatus::Unknown: - case DevStatus::Disconnected: return m_unknownIcon; - case DevStatus::OwnDevice: - case DevStatus::Idle: return m_idleIcon; - case DevStatus::Synchronizing: return m_syncIcon; - case DevStatus::OutOfSync: - case DevStatus::Rejected: return m_errorIcon; + case SyncthingDevStatus::Unknown: + case SyncthingDevStatus::Disconnected: return m_unknownIcon; + case SyncthingDevStatus::OwnDevice: + case SyncthingDevStatus::Idle: return m_idleIcon; + case SyncthingDevStatus::Synchronizing: return m_syncIcon; + case SyncthingDevStatus::OutOfSync: + case SyncthingDevStatus::Rejected: return m_errorIcon; } } break; @@ -196,13 +196,13 @@ QVariant SyncthingDeviceModel::data(const QModelIndex &index, int role) const case 1: if(!dev.paused) { switch(dev.status) { - case DevStatus::Unknown: break; - case DevStatus::Disconnected: break; - case DevStatus::OwnDevice: - case DevStatus::Idle: return QColor(Qt::darkGreen); - case DevStatus::Synchronizing: return QColor(Qt::darkBlue); - case DevStatus::OutOfSync: - case DevStatus::Rejected: return QColor(Qt::red); + case SyncthingDevStatus::Unknown: break; + case SyncthingDevStatus::Disconnected: break; + case SyncthingDevStatus::OwnDevice: + case SyncthingDevStatus::Idle: return QColor(Qt::darkGreen); + case SyncthingDevStatus::Synchronizing: return QColor(Qt::darkBlue); + case SyncthingDevStatus::OutOfSync: + case SyncthingDevStatus::Rejected: return QColor(Qt::red); } } break; @@ -213,7 +213,7 @@ QVariant SyncthingDeviceModel::data(const QModelIndex &index, int role) const case DevicePaused: return dev.paused; case IsOwnDevice: - return dev.status == DevStatus::OwnDevice; + return dev.status == SyncthingDevStatus::OwnDevice; default: ; } diff --git a/model/syncthingdirectorymodel.cpp b/model/syncthingdirectorymodel.cpp index 259cbc4..2bf22cf 100644 --- a/model/syncthingdirectorymodel.cpp +++ b/model/syncthingdirectorymodel.cpp @@ -165,12 +165,12 @@ QVariant SyncthingDirectoryModel::data(const QModelIndex &index, int role) const case 0: return dir.label.isEmpty() ? dir.id : dir.label; case 1: switch(dir.status) { - case DirStatus::Unknown: return tr("Unknown status"); - case DirStatus::Idle: return tr("Idle"); - case DirStatus::Scanning: return dir.progressPercentage > 0 ? tr("Scanning (%1 %)").arg(dir.progressPercentage) : tr("Scanning"); - case DirStatus::Synchronizing: return dir.progressPercentage > 0 ? tr("Synchronizing (%1 %)").arg(dir.progressPercentage) : tr("Synchronizing"); - case DirStatus::Paused: return tr("Paused"); - case DirStatus::OutOfSync: return tr("Out of sync"); + case SyncthingDirStatus::Unknown: return tr("Unknown status"); + case SyncthingDirStatus::Idle: return tr("Idle"); + case SyncthingDirStatus::Scanning: return dir.progressPercentage > 0 ? tr("Scanning (%1 %)").arg(dir.progressPercentage) : tr("Scanning"); + case SyncthingDirStatus::Synchronizing: return dir.progressPercentage > 0 ? tr("Synchronizing (%1 %)").arg(dir.progressPercentage) : tr("Synchronizing"); + case SyncthingDirStatus::Paused: return tr("Paused"); + case SyncthingDirStatus::OutOfSync: return tr("Out of sync"); } break; } @@ -179,12 +179,12 @@ QVariant SyncthingDirectoryModel::data(const QModelIndex &index, int role) const switch(index.column()) { case 0: switch(dir.status) { - case DirStatus::Unknown: return m_unknownIcon; - case DirStatus::Idle: return m_idleIcon; - case DirStatus::Scanning: return m_otherIcon; - case DirStatus::Synchronizing: return m_syncIcon; - case DirStatus::Paused: return m_pausedIcon; - case DirStatus::OutOfSync: return m_errorIcon; + case SyncthingDirStatus::Unknown: return m_unknownIcon; + case SyncthingDirStatus::Idle: return m_idleIcon; + case SyncthingDirStatus::Scanning: return m_otherIcon; + case SyncthingDirStatus::Synchronizing: return m_syncIcon; + case SyncthingDirStatus::Paused: return m_pausedIcon; + case SyncthingDirStatus::OutOfSync: return m_errorIcon; } break; } @@ -200,12 +200,12 @@ QVariant SyncthingDirectoryModel::data(const QModelIndex &index, int role) const case 0: break; case 1: switch(dir.status) { - case DirStatus::Unknown: break; - case DirStatus::Idle: return QColor(Qt::darkGreen); - case DirStatus::Scanning: return QColor(Qt::blue); - case DirStatus::Synchronizing: return QColor(Qt::blue); - case DirStatus::Paused: break; - case DirStatus::OutOfSync: return QColor(Qt::red); + case SyncthingDirStatus::Unknown: break; + case SyncthingDirStatus::Idle: return QColor(Qt::darkGreen); + case SyncthingDirStatus::Scanning: return QColor(Qt::blue); + case SyncthingDirStatus::Synchronizing: return QColor(Qt::blue); + case SyncthingDirStatus::Paused: break; + case SyncthingDirStatus::OutOfSync: return QColor(Qt::red); } break; } diff --git a/tray/gui/dirview.cpp b/tray/gui/dirview.cpp index bf1d45c..e9ffeb9 100644 --- a/tray/gui/dirview.cpp +++ b/tray/gui/dirview.cpp @@ -50,7 +50,7 @@ void DirView::mouseReleaseEvent(QMouseEvent *event) // show errors auto *textViewDlg = new TextViewDialog(tr("Errors of %1").arg(dir->label.isEmpty() ? dir->id : dir->label)); auto *browser = textViewDlg->browser(); - for(const DirError &error : dir->errors) { + for(const SyncthingDirError &error : dir->errors) { browser->append(error.path % QChar(':') % QChar(' ') % QChar('\n') % error.message % QChar('\n')); } textViewDlg->show(); diff --git a/tray/translations/syncthingtray_de_DE.ts b/tray/translations/syncthingtray_de_DE.ts index 8b8c91c..4888c22 100644 --- a/tray/translations/syncthingtray_de_DE.ts +++ b/tray/translations/syncthingtray_de_DE.ts @@ -287,17 +287,17 @@ - + Copy value - + Copy label/ID - + Copy path diff --git a/tray/translations/syncthingtray_en_US.ts b/tray/translations/syncthingtray_en_US.ts index 406a457..8f5ef4f 100644 --- a/tray/translations/syncthingtray_en_US.ts +++ b/tray/translations/syncthingtray_en_US.ts @@ -287,17 +287,17 @@ - + Copy value - + Copy label/ID - + Copy path