syncthingtray/connector/utils.h

47 lines
1.3 KiB
C
Raw Normal View History

2016-09-01 16:34:30 +02:00
#ifndef DATA_UTILS_H
#define DATA_UTILS_H
#include "./global.h"
#include <QJsonValue>
2017-02-22 18:16:41 +01:00
#include <QStringList>
2016-09-01 16:34:30 +02:00
2017-08-24 00:00:57 +02:00
#include <limits>
QT_FORWARD_DECLARE_CLASS(QUrl)
QT_FORWARD_DECLARE_CLASS(QJsonObject)
2016-09-01 16:34:30 +02:00
namespace ChronoUtilities {
class DateTime;
}
namespace Data {
QString LIB_SYNCTHING_CONNECTOR_EXPORT agoString(ChronoUtilities::DateTime dateTime);
bool LIB_SYNCTHING_CONNECTOR_EXPORT isLocal(const QUrl &url);
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
inline quint64 LIB_SYNCTHING_CONNECTOR_EXPORT toUInt64(const QJsonValue &value, double defaultValue = 0.0)
{
return static_cast<quint64>(value.toDouble(defaultValue));
}
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);
}
2017-05-01 03:34:43 +02:00
template <class Objects> QStringList LIB_SYNCTHING_CONNECTOR_EXPORT ids(const Objects &objects)
2017-02-22 18:16:41 +01:00
{
QStringList ids;
ids.reserve(objects.size());
2017-05-01 03:34:43 +02:00
for (const auto &object : objects) {
2017-02-22 18:16:41 +01:00
ids << object.id;
}
return ids;
}
2016-09-01 16:34:30 +02:00
}
#endif // DATA_UTILS_H