From 3b015db77d25deec45b77b8552b061dfe4e905ba Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 16 Jun 2019 16:55:58 +0800 Subject: [PATCH] Add comparison operators for ProxyConfiguration --- src/base/net/proxyconfigurationmanager.cpp | 23 +++++++++++++--------- src/base/net/proxyconfigurationmanager.h | 2 ++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/base/net/proxyconfigurationmanager.cpp b/src/base/net/proxyconfigurationmanager.cpp index 1255fc6c1..4867cd69f 100644 --- a/src/base/net/proxyconfigurationmanager.cpp +++ b/src/base/net/proxyconfigurationmanager.cpp @@ -41,15 +41,20 @@ const QString KEY_PASSWORD = SETTINGS_KEY("Password"); namespace { inline SettingsStorage *settings() { return SettingsStorage::instance(); } +} - inline bool isSameConfig(const Net::ProxyConfiguration &conf1, const Net::ProxyConfiguration &conf2) - { - return conf1.type == conf2.type - && conf1.ip == conf2.ip - && conf1.port == conf2.port - && conf1.username == conf2.username - && conf1.password == conf2.password; - } +bool Net::operator==(const ProxyConfiguration &left, const ProxyConfiguration &right) +{ + return (left.type == right.type) + && (left.ip == right.ip) + && (left.port == right.port) + && (left.username == right.username) + && (left.password == right.password); +} + +bool Net::operator!=(const ProxyConfiguration &left, const ProxyConfiguration &right) +{ + return !(left == right); } using namespace Net; @@ -97,7 +102,7 @@ ProxyConfiguration ProxyConfigurationManager::proxyConfiguration() const void ProxyConfigurationManager::setProxyConfiguration(const ProxyConfiguration &config) { - if (!isSameConfig(config, m_config)) { + if (config != m_config) { m_config = config; settings()->storeValue(KEY_TYPE, static_cast(config.type)); settings()->storeValue(KEY_IP, config.ip); diff --git a/src/base/net/proxyconfigurationmanager.h b/src/base/net/proxyconfigurationmanager.h index 87f1f88e9..c336cc8df 100644 --- a/src/base/net/proxyconfigurationmanager.h +++ b/src/base/net/proxyconfigurationmanager.h @@ -51,6 +51,8 @@ namespace Net QString username; QString password; }; + bool operator==(const ProxyConfiguration &left, const ProxyConfiguration &right); + bool operator!=(const ProxyConfiguration &left, const ProxyConfiguration &right); class ProxyConfigurationManager : public QObject {