Use isLocal() in SyncthingConfig::syncthingUrl()
This commit is contained in:
parent
99cb584249
commit
c031440c05
|
@ -1,7 +1,7 @@
|
|||
#include "./syncthingconfig.h"
|
||||
#include "./utils.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QHostAddress>
|
||||
#include <QStandardPaths>
|
||||
#include <QXmlStreamReader>
|
||||
|
||||
|
@ -83,9 +83,7 @@ bool SyncthingConfig::restore(const QString &configFilePath)
|
|||
|
||||
QString SyncthingConfig::syncthingUrl() const
|
||||
{
|
||||
return (guiEnforcesSecureConnection || !QHostAddress(guiAddress.mid(0, guiAddress.indexOf(QChar(':')))).isLoopback() ? QStringLiteral("https://")
|
||||
: QStringLiteral("http://"))
|
||||
+ guiAddress;
|
||||
return (guiEnforcesSecureConnection || isLocal(guiAddress) ? QStringLiteral("https://") : QStringLiteral("http://")) + guiAddress;
|
||||
}
|
||||
|
||||
} // namespace Data
|
||||
|
|
|
@ -104,13 +104,12 @@ QString rescanIntervalString(int rescanInterval, bool fileSystemWatcherEnabled)
|
|||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns whether the host specified by the given \a url is the local machine.
|
||||
* \brief Returns whether the specified \a hostname is the local machine.
|
||||
*/
|
||||
bool isLocal(const QUrl &url)
|
||||
bool isLocal(const QString &hostname)
|
||||
{
|
||||
const QString host(url.host());
|
||||
const QHostAddress hostAddress(host);
|
||||
return host.compare(QLatin1String("localhost"), Qt::CaseInsensitive) == 0 || hostAddress.isLoopback()
|
||||
const QHostAddress hostAddress(hostname);
|
||||
return hostname.compare(QLatin1String("localhost"), Qt::CaseInsensitive) == 0 || hostAddress.isLoopback()
|
||||
|| QNetworkInterface::allAddresses().contains(hostAddress);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,11 +8,11 @@
|
|||
|
||||
#include <QJsonValue>
|
||||
#include <QStringList>
|
||||
#include <QUrl>
|
||||
|
||||
#include <limits>
|
||||
#include <vector>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QUrl)
|
||||
QT_FORWARD_DECLARE_CLASS(QJsonObject)
|
||||
|
||||
namespace ChronoUtilities {
|
||||
|
@ -31,10 +31,18 @@ QString LIB_SYNCTHING_CONNECTOR_EXPORT directoryStatusString(const Data::Syncthi
|
|||
QString LIB_SYNCTHING_CONNECTOR_EXPORT syncCompleteString(
|
||||
const std::vector<const SyncthingDir *> &completedDirs, const SyncthingDev *remoteDevice = nullptr);
|
||||
QString LIB_SYNCTHING_CONNECTOR_EXPORT rescanIntervalString(int rescanInterval, bool fileSystemWatcherEnabled);
|
||||
bool LIB_SYNCTHING_CONNECTOR_EXPORT isLocal(const QUrl &url);
|
||||
bool LIB_SYNCTHING_CONNECTOR_EXPORT isLocal(const QString &hostname);
|
||||
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);
|
||||
|
||||
/*!
|
||||
* \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 <typename IntType = quint64, Traits::EnableIf<std::is_integral<IntType>> * = nullptr>
|
||||
inline IntType LIB_SYNCTHING_CONNECTOR_EXPORT jsonValueToInt(const QJsonValue &value, double defaultValue = 0.0)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue