forked from MatsuriDayo/nekoray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialog_vpn_settings.cpp
82 lines (75 loc) · 3.23 KB
/
dialog_vpn_settings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "dialog_vpn_settings.h"
#include "ui_dialog_vpn_settings.h"
#include "main/GuiUtils.hpp"
#include "main/NekoGui.hpp"
#include "ui/mainwindow_interface.h"
#include <QMessageBox>
DialogVPNSettings::DialogVPNSettings(QWidget *parent) : QDialog(parent), ui(new Ui::DialogVPNSettings) {
ui->setupUi(this);
ADD_ASTERISK(this);
ui->fake_dns->setChecked(NekoGui::dataStore->fake_dns);
ui->vpn_implementation->setCurrentIndex(NekoGui::dataStore->vpn_implementation);
ui->vpn_mtu->setCurrentText(Int2String(NekoGui::dataStore->vpn_mtu));
ui->vpn_ipv6->setChecked(NekoGui::dataStore->vpn_ipv6);
ui->hide_console->setChecked(NekoGui::dataStore->vpn_hide_console);
#ifndef Q_OS_WIN
ui->hide_console->setVisible(false);
#endif
ui->strict_route->setChecked(NekoGui::dataStore->vpn_strict_route);
ui->single_core->setVisible(IS_NEKO_BOX);
ui->single_core->setChecked(NekoGui::dataStore->vpn_internal_tun);
//
D_LOAD_STRING_PLAIN(vpn_rule_cidr)
D_LOAD_STRING_PLAIN(vpn_rule_process)
//
connect(ui->whitelist_mode, &QCheckBox::stateChanged, this, [=](int state) {
if (state == Qt::Checked) {
ui->gb_cidr->setTitle(tr("Proxy CIDR"));
ui->gb_process_name->setTitle(tr("Proxy Process Name"));
} else {
ui->gb_cidr->setTitle(tr("Bypass CIDR"));
ui->gb_process_name->setTitle(tr("Bypass Process Name"));
}
});
ui->whitelist_mode->setChecked(NekoGui::dataStore->vpn_rule_white);
}
DialogVPNSettings::~DialogVPNSettings() {
delete ui;
}
void DialogVPNSettings::accept() {
//
auto mtu = ui->vpn_mtu->currentText().toInt();
if (mtu > 10000 || mtu < 1000) mtu = 9000;
NekoGui::dataStore->vpn_implementation = ui->vpn_implementation->currentIndex();
NekoGui::dataStore->fake_dns = ui->fake_dns->isChecked();
NekoGui::dataStore->vpn_mtu = mtu;
NekoGui::dataStore->vpn_ipv6 = ui->vpn_ipv6->isChecked();
NekoGui::dataStore->vpn_hide_console = ui->hide_console->isChecked();
NekoGui::dataStore->vpn_strict_route = ui->strict_route->isChecked();
NekoGui::dataStore->vpn_rule_white = ui->whitelist_mode->isChecked();
bool isInternalChanged = NekoGui::dataStore->vpn_internal_tun != ui->single_core->isChecked();
NekoGui::dataStore->vpn_internal_tun = ui->single_core->isChecked();
//
D_SAVE_STRING_PLAIN(vpn_rule_cidr)
D_SAVE_STRING_PLAIN(vpn_rule_process)
//
QStringList msg{"UpdateDataStore"};
if (isInternalChanged) {
msg << "NeedRestart";
} else {
msg << "VPNChanged";
}
MW_dialog_message("", msg.join(","));
QDialog::accept();
}
void DialogVPNSettings::on_troubleshooting_clicked() {
auto r = QMessageBox::information(this, tr("Troubleshooting"),
tr("If you have trouble starting VPN, you can force reset nekobox_core process here.\n\n"
"If still not working, see documentation for more information.\n"
"https://matsuridayo.github.io/n-configuration/#vpn-tun"),
tr("Reset"), tr("Cancel"), "",
1, 1);
if (r == 0) {
GetMainWindow()->StopVPNProcess(true);
}
}