File indexing completed on 2024-05-19 04:59:19

0001 /* ============================================================
0002 * StatusBarIcons - Extra icons in statusbar for Falkon
0003 * Copyright (C) 2013-2014  David Rosca <nowrep@gmail.com>
0004 *
0005 * This program is free software: you can redistribute it and/or modify
0006 * it under the terms of the GNU General Public License as published by
0007 * the Free Software Foundation, either version 3 of the License, or
0008 * (at your option) any later version.
0009 *
0010 * This program is distributed in the hope that it will be useful,
0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 * GNU General Public License for more details.
0014 *
0015 * You should have received a copy of the GNU General Public License
0016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017 * ============================================================ */
0018 #include "sbi_networkproxy.h"
0019 
0020 #include <QSettings>
0021 
0022 SBI_NetworkProxy::SBI_NetworkProxy()
0023     : m_port(0)
0024     , m_type(QNetworkProxy::NoProxy)
0025 {
0026 }
0027 
0028 bool SBI_NetworkProxy::operator ==(const SBI_NetworkProxy &other) const
0029 {
0030     return m_port == other.m_port && m_hostname == other.m_hostname &&
0031            m_username == other.m_username && m_password == other.m_password &&
0032            m_type == other.m_type;
0033 }
0034 
0035 quint16 SBI_NetworkProxy::port() const
0036 {
0037     return m_port;
0038 }
0039 
0040 void SBI_NetworkProxy::setPort(quint16 port)
0041 {
0042     m_port = port;
0043 }
0044 
0045 QString SBI_NetworkProxy::hostName() const
0046 {
0047     return m_hostname;
0048 }
0049 
0050 void SBI_NetworkProxy::setHostName(const QString &hostName)
0051 {
0052     m_hostname = hostName;
0053 }
0054 
0055 QString SBI_NetworkProxy::userName() const
0056 {
0057     return m_username;
0058 }
0059 
0060 void SBI_NetworkProxy::setUserName(const QString &userName)
0061 {
0062     m_username = userName;
0063 }
0064 
0065 QString SBI_NetworkProxy::password() const
0066 {
0067     return m_password;
0068 }
0069 
0070 void SBI_NetworkProxy::setPassword(const QString &password)
0071 {
0072     m_password = password;
0073 }
0074 
0075 QNetworkProxy::ProxyType SBI_NetworkProxy::type() const
0076 {
0077     return m_type;
0078 }
0079 
0080 void SBI_NetworkProxy::setType(QNetworkProxy::ProxyType type)
0081 {
0082     m_type = type;
0083 }
0084 
0085 void SBI_NetworkProxy::loadFromSettings(const QSettings &settings)
0086 {
0087     m_hostname = settings.value("HostName", QString()).toString();
0088     m_port = settings.value("Port", 0).toInt();
0089     m_username = settings.value("Username", QString()).toString();
0090     m_password = settings.value("Password", QString()).toString();
0091 
0092     m_type = QNetworkProxy::ProxyType(settings.value("ProxyType", QNetworkProxy::NoProxy).toInt());
0093 }
0094 
0095 void SBI_NetworkProxy::saveToSettings(QSettings &settings) const
0096 {
0097     settings.setValue("HostName", m_hostname);
0098     settings.setValue("Port", m_port);
0099     settings.setValue("Username", m_username);
0100     settings.setValue("Password", m_password);
0101 
0102     settings.setValue("ProxyType", m_type);
0103 }
0104 
0105 void SBI_NetworkProxy::applyProxy()
0106 {
0107     QNetworkProxy proxy;
0108     proxy.setHostName(m_hostname);
0109     proxy.setPort(m_port);
0110     proxy.setUser(m_username);
0111     proxy.setPassword(m_password);
0112     proxy.setType(m_type);
0113 
0114     QNetworkProxy::setApplicationProxy(proxy);
0115 }