#ifndef DATA_UTILS_H #define DATA_UTILS_H #include "./global.h" #include #include #include #include #include #include QT_FORWARD_DECLARE_CLASS(QJsonObject) QT_FORWARD_DECLARE_CLASS(QHostAddress) namespace CppUtilities { class DateTime; } namespace Data { namespace Traits = CppUtilities::Traits; struct SyncthingStatistics; struct SyncthingDir; struct SyncthingDev; LIB_SYNCTHING_CONNECTOR_EXPORT QString agoString(CppUtilities::DateTime dateTime); LIB_SYNCTHING_CONNECTOR_EXPORT QString trafficString(std::uint64_t total, double rate); LIB_SYNCTHING_CONNECTOR_EXPORT QString directoryStatusString(const Data::SyncthingStatistics &stats); LIB_SYNCTHING_CONNECTOR_EXPORT QString syncCompleteString( const std::vector &completedDirs, const SyncthingDev *remoteDevice = nullptr); LIB_SYNCTHING_CONNECTOR_EXPORT QString rescanIntervalString(int rescanInterval, bool fileSystemWatcherEnabled); LIB_SYNCTHING_CONNECTOR_EXPORT bool isLocal(const QString &hostName); LIB_SYNCTHING_CONNECTOR_EXPORT bool isLocal(const QString &hostName, const QHostAddress &hostAddress); LIB_SYNCTHING_CONNECTOR_EXPORT bool setDirectoriesPaused(QJsonObject &syncthingConfig, const QStringList &dirIds, bool paused); LIB_SYNCTHING_CONNECTOR_EXPORT bool setDevicesPaused(QJsonObject &syncthingConfig, const QStringList &dirs, bool paused); /*! * \brief Returns whether the host specified by the given \a url is the local machine. */ inline bool isLocal(const QUrl &url) { return isLocal(url.host()); } template > * = nullptr> inline LIB_SYNCTHING_CONNECTOR_EXPORT IntType jsonValueToInt(const QJsonValue &value, double defaultValue = 0.0) { return static_cast(value.toDouble(defaultValue)); } constexpr LIB_SYNCTHING_CONNECTOR_EXPORT int trQuandity(quint64 quandity) { return quandity > std::numeric_limits::max() ? std::numeric_limits::max() : static_cast(quandity); } template LIB_SYNCTHING_CONNECTOR_EXPORT QStringList things(const Objects &objects, Accessor accessor) { QStringList things; things.reserve(static_cast(objects.size())); for (const auto &object : objects) { things << accessor(object); } return things; } template LIB_SYNCTHING_CONNECTOR_EXPORT QStringList ids(const Objects &objects) { return things(objects, [](const auto &object) { return Traits::dereferenceMaybe(object).id; }); } template LIB_SYNCTHING_CONNECTOR_EXPORT QStringList displayNames(const Objects &objects) { return things(objects, [](const auto &object) { return Traits::dereferenceMaybe(object).displayName(); }); } } // namespace Data #endif // DATA_UTILS_H