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_proxywidget.h"
0019 #include "sbi_networkproxy.h"
0020 #include "ui_sbi_proxywidget.h"
0021 
0022 SBI_ProxyWidget::SBI_ProxyWidget(QWidget* parent) :
0023     QWidget(parent),
0024     ui(new Ui::SBI_ProxyWidget)
0025 {
0026     ui->setupUi(this);
0027 }
0028 
0029 void SBI_ProxyWidget::clear()
0030 {
0031     ui->proxyServer->clear();
0032     ui->proxyPort->clear();
0033     ui->proxyUsername->clear();
0034     ui->proxyPassword->clear();
0035 
0036     ui->proxyType->setCurrentIndex(0);
0037     ui->systemProxy->setChecked(true);
0038 }
0039 
0040 SBI_NetworkProxy* SBI_ProxyWidget::getProxy() const
0041 {
0042     auto* proxy = new SBI_NetworkProxy;
0043 
0044     proxy->setHostName(ui->proxyServer->text());
0045     proxy->setPort(ui->proxyPort->text().toInt());
0046     proxy->setUserName(ui->proxyUsername->text());
0047     proxy->setPassword(ui->proxyPassword->text());
0048 
0049     if (ui->systemProxy->isChecked()) {
0050         proxy->setType(QNetworkProxy::NoProxy);
0051     } else {
0052         proxy->setType(ui->proxyType->currentIndex() == 0 ? QNetworkProxy::HttpProxy : QNetworkProxy::Socks5Proxy);
0053     }
0054 
0055     return proxy;
0056 }
0057 
0058 void SBI_ProxyWidget::setProxy(const SBI_NetworkProxy &proxy)
0059 {
0060     ui->proxyServer->setText(proxy.hostName());
0061     ui->proxyPort->setText(QString::number(proxy.port()));
0062     ui->proxyUsername->setText(proxy.userName());
0063     ui->proxyPassword->setText(proxy.password());
0064     ui->proxyType->setCurrentIndex(0);
0065 
0066     switch (proxy.type()) {
0067     case QNetworkProxy::NoProxy:
0068         ui->systemProxy->setChecked(true);
0069         break;
0070 
0071     case QNetworkProxy::HttpProxy:
0072         ui->manualProxy->setChecked(true);
0073         ui->proxyType->setCurrentIndex(0);
0074         break;
0075 
0076     case QNetworkProxy::Socks5Proxy:
0077         ui->manualProxy->setChecked(true);
0078         ui->proxyType->setCurrentIndex(1);
0079         break;
0080 
0081     default:
0082         break;
0083     }
0084 }
0085 
0086 SBI_ProxyWidget::~SBI_ProxyWidget()
0087 {
0088     delete ui;
0089 }