2016-09-01 16:34:30 +02:00
|
|
|
#ifndef DATA_UTILS_H
|
|
|
|
#define DATA_UTILS_H
|
|
|
|
|
2016-09-30 23:55:25 +02:00
|
|
|
#include "./global.h"
|
|
|
|
|
2018-01-25 00:03:31 +01:00
|
|
|
#include <c++utilities/misc/traits.h>
|
2017-08-29 23:50:34 +02:00
|
|
|
|
2017-08-23 00:22:02 +02:00
|
|
|
#include <QJsonValue>
|
2017-02-22 18:16:41 +01:00
|
|
|
#include <QStringList>
|
2018-10-10 22:46:55 +02:00
|
|
|
#include <QUrl>
|
2016-09-01 16:34:30 +02:00
|
|
|
|
2017-08-24 00:00:57 +02:00
|
|
|
#include <limits>
|
2017-12-30 00:57:35 +01:00
|
|
|
#include <vector>
|
2017-08-24 00:00:57 +02:00
|
|
|
|
2017-07-02 21:47:23 +02:00
|
|
|
QT_FORWARD_DECLARE_CLASS(QJsonObject)
|
2018-11-01 19:55:08 +01:00
|
|
|
QT_FORWARD_DECLARE_CLASS(QHostAddress)
|
2016-09-01 16:34:30 +02:00
|
|
|
|
2019-06-10 22:48:26 +02:00
|
|
|
namespace CppUtilities {
|
2016-09-01 16:34:30 +02:00
|
|
|
class DateTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Data {
|
|
|
|
|
2019-06-10 22:48:26 +02:00
|
|
|
namespace Traits = CppUtilities::Traits;
|
|
|
|
|
2018-01-27 23:27:50 +01:00
|
|
|
struct SyncthingStatistics;
|
2017-12-30 00:57:35 +01:00
|
|
|
struct SyncthingDir;
|
2018-03-29 00:38:21 +02:00
|
|
|
struct SyncthingDev;
|
2017-12-30 00:57:35 +01:00
|
|
|
|
2019-06-10 22:48:26 +02:00
|
|
|
QString LIB_SYNCTHING_CONNECTOR_EXPORT agoString(CppUtilities::DateTime dateTime);
|
2019-03-13 19:12:23 +01:00
|
|
|
QString LIB_SYNCTHING_CONNECTOR_EXPORT trafficString(std::uint64_t total, double rate);
|
2018-01-27 23:27:50 +01:00
|
|
|
QString LIB_SYNCTHING_CONNECTOR_EXPORT directoryStatusString(const Data::SyncthingStatistics &stats);
|
2018-03-29 00:38:21 +02:00
|
|
|
QString LIB_SYNCTHING_CONNECTOR_EXPORT syncCompleteString(
|
|
|
|
const std::vector<const SyncthingDir *> &completedDirs, const SyncthingDev *remoteDevice = nullptr);
|
2018-09-15 18:18:15 +02:00
|
|
|
QString LIB_SYNCTHING_CONNECTOR_EXPORT rescanIntervalString(int rescanInterval, bool fileSystemWatcherEnabled);
|
2018-11-01 19:55:08 +01:00
|
|
|
bool LIB_SYNCTHING_CONNECTOR_EXPORT isLocal(const QString &hostName);
|
|
|
|
bool LIB_SYNCTHING_CONNECTOR_EXPORT isLocal(const QString &hostName, const QHostAddress &hostAddress);
|
2017-07-02 21:47:23 +02:00
|
|
|
bool LIB_SYNCTHING_CONNECTOR_EXPORT setDirectoriesPaused(QJsonObject &syncthingConfig, const QStringList &dirIds, bool paused);
|
|
|
|
bool LIB_SYNCTHING_CONNECTOR_EXPORT setDevicesPaused(QJsonObject &syncthingConfig, const QStringList &dirs, bool paused);
|
2016-09-01 16:34:30 +02:00
|
|
|
|
2018-10-10 22:46:55 +02:00
|
|
|
/*!
|
|
|
|
* \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());
|
|
|
|
}
|
|
|
|
|
2018-05-08 00:38:49 +02:00
|
|
|
template <typename IntType = quint64, Traits::EnableIf<std::is_integral<IntType>> * = nullptr>
|
2018-01-25 00:03:31 +01:00
|
|
|
inline IntType LIB_SYNCTHING_CONNECTOR_EXPORT jsonValueToInt(const QJsonValue &value, double defaultValue = 0.0)
|
2017-08-23 00:22:02 +02:00
|
|
|
{
|
2018-01-25 00:03:31 +01:00
|
|
|
return static_cast<IntType>(value.toDouble(defaultValue));
|
2017-08-23 00:22:02 +02:00
|
|
|
}
|
|
|
|
|
2017-08-24 00:00:57 +02:00
|
|
|
constexpr int LIB_SYNCTHING_CONNECTOR_EXPORT trQuandity(quint64 quandity)
|
|
|
|
{
|
|
|
|
return quandity > std::numeric_limits<int>::max() ? std::numeric_limits<int>::max() : static_cast<int>(quandity);
|
|
|
|
}
|
|
|
|
|
2018-03-29 00:38:21 +02:00
|
|
|
template <class Objects, class Accessor> QStringList LIB_SYNCTHING_CONNECTOR_EXPORT things(const Objects &objects, Accessor accessor)
|
2017-02-22 18:16:41 +01:00
|
|
|
{
|
2018-03-29 00:38:21 +02:00
|
|
|
QStringList things;
|
|
|
|
things.reserve(objects.size());
|
2017-05-01 03:34:43 +02:00
|
|
|
for (const auto &object : objects) {
|
2018-03-29 00:38:21 +02:00
|
|
|
things << accessor(object);
|
2017-02-22 18:16:41 +01:00
|
|
|
}
|
2018-03-29 00:38:21 +02:00
|
|
|
return things;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Objects> QStringList LIB_SYNCTHING_CONNECTOR_EXPORT ids(const Objects &objects)
|
|
|
|
{
|
2018-07-05 17:39:35 +02:00
|
|
|
return things(objects, [](const auto &object) { return Traits::dereferenceMaybe(object).id; });
|
2017-02-22 18:16:41 +01:00
|
|
|
}
|
2018-07-05 17:39:35 +02:00
|
|
|
|
|
|
|
template <class Objects> QStringList LIB_SYNCTHING_CONNECTOR_EXPORT displayNames(const Objects &objects)
|
|
|
|
{
|
|
|
|
return things(objects, [](const auto &object) { return Traits::dereferenceMaybe(object).displayName(); });
|
|
|
|
}
|
|
|
|
|
2017-09-17 21:48:15 +02:00
|
|
|
} // namespace Data
|
2016-09-01 16:34:30 +02:00
|
|
|
|
|
|
|
#endif // DATA_UTILS_H
|