WebUI: fix window can not close regression
[qBittorrent.git] / src / base / net / proxyconfigurationmanager.cpp
blob4494280d4cda7c00eea49153bc5121be50cbb3a6
1 /*
2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2016-2023 Vladimir Golovnev <glassez@yandex.ru>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * In addition, as a special exception, the copyright holders give permission to
20 * link this program with the OpenSSL project's "OpenSSL" library (or with
21 * modified versions of it that use the same license as the "OpenSSL" library),
22 * and distribute the linked executables. You must obey the GNU General Public
23 * License in all respects for all of the code used other than "OpenSSL". If you
24 * modify file(s), you may extend this exception to your version of the file(s),
25 * but you are not obligated to do so. If you do not wish to do so, delete this
26 * exception statement from your version.
29 #include "proxyconfigurationmanager.h"
31 #define SETTINGS_KEY(name) (u"Network/Proxy/" name)
33 bool Net::operator==(const ProxyConfiguration &left, const ProxyConfiguration &right)
35 return (left.type == right.type)
36 && (left.ip == right.ip)
37 && (left.port == right.port)
38 && (left.authEnabled == right.authEnabled)
39 && (left.username == right.username)
40 && (left.password == right.password)
41 && (left.hostnameLookupEnabled == right.hostnameLookupEnabled);
44 using namespace Net;
46 ProxyConfigurationManager *ProxyConfigurationManager::m_instance = nullptr;
48 ProxyConfigurationManager::ProxyConfigurationManager(QObject *parent)
49 : QObject(parent)
50 , m_storeProxyType {SETTINGS_KEY(u"Type"_s)}
51 , m_storeProxyIP {SETTINGS_KEY(u"IP"_s)}
52 , m_storeProxyPort {SETTINGS_KEY(u"Port"_s)}
53 , m_storeProxyAuthEnabled {SETTINGS_KEY(u"AuthEnabled"_s)}
54 , m_storeProxyUsername {SETTINGS_KEY(u"Username"_s)}
55 , m_storeProxyPassword {SETTINGS_KEY(u"Password"_s)}
56 , m_storeProxyHostnameLookupEnabled {SETTINGS_KEY(u"HostnameLookupEnabled"_s)}
58 m_config.type = m_storeProxyType.get(ProxyType::None);
59 if ((m_config.type < ProxyType::None) || (m_config.type > ProxyType::SOCKS4))
60 m_config.type = ProxyType::None;
61 m_config.ip = m_storeProxyIP.get((m_config.type == ProxyType::None) ? u""_s : u"0.0.0.0"_s);
62 m_config.port = m_storeProxyPort.get(8080);
63 m_config.authEnabled = m_storeProxyAuthEnabled;
64 m_config.username = m_storeProxyUsername;
65 m_config.password = m_storeProxyPassword;
66 m_config.hostnameLookupEnabled = m_storeProxyHostnameLookupEnabled.get(true);
69 void ProxyConfigurationManager::initInstance()
71 if (!m_instance)
72 m_instance = new ProxyConfigurationManager;
75 void ProxyConfigurationManager::freeInstance()
77 delete m_instance;
78 m_instance = nullptr;
81 ProxyConfigurationManager *ProxyConfigurationManager::instance()
83 return m_instance;
86 ProxyConfiguration ProxyConfigurationManager::proxyConfiguration() const
88 return m_config;
91 void ProxyConfigurationManager::setProxyConfiguration(const ProxyConfiguration &config)
93 if (m_config != config)
95 m_config = config;
96 m_storeProxyType = config.type;
97 m_storeProxyIP = config.ip;
98 m_storeProxyPort = config.port;
99 m_storeProxyAuthEnabled = config.authEnabled;
100 m_storeProxyUsername = config.username;
101 m_storeProxyPassword = config.password;
102 m_storeProxyHostnameLookupEnabled = config.hostnameLookupEnabled;
104 emit proxyConfigurationChanged();