1 /* Copyright 2013-2019 MultiMC Contributors
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "ProxyPage.h"
17 #include "ui_ProxyPage.h"
18
19 #include <QTabBar>
20
21 #include "settings/SettingsObject.h"
22 #include "MultiMC.h"
23 #include "Env.h"
24
ProxyPage(QWidget * parent)25 ProxyPage::ProxyPage(QWidget *parent) : QWidget(parent), ui(new Ui::ProxyPage)
26 {
27 ui->setupUi(this);
28 ui->tabWidget->tabBar()->hide();
29 loadSettings();
30 updateCheckboxStuff();
31
32 connect(ui->proxyGroup, SIGNAL(buttonClicked(int)), SLOT(proxyChanged(int)));
33 }
34
~ProxyPage()35 ProxyPage::~ProxyPage()
36 {
37 delete ui;
38 }
39
apply()40 bool ProxyPage::apply()
41 {
42 applySettings();
43 return true;
44 }
45
updateCheckboxStuff()46 void ProxyPage::updateCheckboxStuff()
47 {
48 ui->proxyAddrBox->setEnabled(!ui->proxyNoneBtn->isChecked() &&
49 !ui->proxyDefaultBtn->isChecked());
50 ui->proxyAuthBox->setEnabled(!ui->proxyNoneBtn->isChecked() &&
51 !ui->proxyDefaultBtn->isChecked());
52 }
53
proxyChanged(int)54 void ProxyPage::proxyChanged(int)
55 {
56 updateCheckboxStuff();
57 }
58
applySettings()59 void ProxyPage::applySettings()
60 {
61 auto s = MMC->settings();
62
63 // Proxy
64 QString proxyType = "None";
65 if (ui->proxyDefaultBtn->isChecked())
66 proxyType = "Default";
67 else if (ui->proxyNoneBtn->isChecked())
68 proxyType = "None";
69 else if (ui->proxySOCKS5Btn->isChecked())
70 proxyType = "SOCKS5";
71 else if (ui->proxyHTTPBtn->isChecked())
72 proxyType = "HTTP";
73
74 s->set("ProxyType", proxyType);
75 s->set("ProxyAddr", ui->proxyAddrEdit->text());
76 s->set("ProxyPort", ui->proxyPortEdit->value());
77 s->set("ProxyUser", ui->proxyUserEdit->text());
78 s->set("ProxyPass", ui->proxyPassEdit->text());
79
80 ENV.updateProxySettings(proxyType, ui->proxyAddrEdit->text(), ui->proxyPortEdit->value(),
81 ui->proxyUserEdit->text(), ui->proxyPassEdit->text());
82 }
loadSettings()83 void ProxyPage::loadSettings()
84 {
85 auto s = MMC->settings();
86 // Proxy
87 QString proxyType = s->get("ProxyType").toString();
88 if (proxyType == "Default")
89 ui->proxyDefaultBtn->setChecked(true);
90 else if (proxyType == "None")
91 ui->proxyNoneBtn->setChecked(true);
92 else if (proxyType == "SOCKS5")
93 ui->proxySOCKS5Btn->setChecked(true);
94 else if (proxyType == "HTTP")
95 ui->proxyHTTPBtn->setChecked(true);
96
97 ui->proxyAddrEdit->setText(s->get("ProxyAddr").toString());
98 ui->proxyPortEdit->setValue(s->get("ProxyPort").value<qint16>());
99 ui->proxyUserEdit->setText(s->get("ProxyUser").toString());
100 ui->proxyPassEdit->setText(s->get("ProxyPass").toString());
101 }
102