[update] updated prefrence window UI and changed a config file entry

Former-commit-id: 6b0d8e1c14
This commit is contained in:
Leroy.H.Y 2019-11-24 20:35:43 +08:00
parent ec0ab9e3ff
commit d9b9dd8cc1
19 changed files with 712 additions and 607 deletions

@ -1 +1 @@
Subproject commit 812fd390ef9d6167555b364120773c9a9fe91023 Subproject commit c29307b6124e012ba1287ba0906e8807424e45c2

2
3rdparty/x2struct vendored

@ -1 +1 @@
Subproject commit 61abc0a4df4b5b3d730b926231b05593560369c2 Subproject commit f2200a5f662730f2c5e49bccb680edbd533f1ff8

View File

@ -1 +1 @@
742 791

View File

@ -58,6 +58,7 @@ INCLUDEPATH += \
src/ui/ \ src/ui/ \
src/utils/ \ src/utils/ \
libs/gen/ libs/gen/
HEADERS += \ HEADERS += \
src/Qv2rayBase.hpp \ src/Qv2rayBase.hpp \
src/QvCoreConfigObjects.hpp \ src/QvCoreConfigObjects.hpp \

View File

@ -8,7 +8,7 @@
#include "QvCoreConfigObjects.hpp" #include "QvCoreConfigObjects.hpp"
#include "QObjectMessageProxy.hpp" #include "QObjectMessageProxy.hpp"
#define QV2RAY_CONFIG_VERSION 9 #define QV2RAY_CONFIG_VERSION 11
// Linux DEs should handle the ui schemes themselves. // Linux DEs should handle the ui schemes themselves.
// --> Or.. should we change this into a modifyable setting? // --> Or.. should we change this into a modifyable setting?
@ -138,7 +138,7 @@ namespace Qv2ray
socksLocalIP = "0.0.0.0"; socksLocalIP = "0.0.0.0";
socksUDP = true; socksUDP = true;
} }
XTOSTRUCT(O(listenip, socks_port, socks_useAuth, socksAccount, socksUDP, socksLocalIP, http_port, http_useAuth, httpAccount)) XTOSTRUCT(O(pacConfig, listenip, socks_port, socks_useAuth, socksAccount, socksUDP, socksLocalIP, http_port, http_useAuth, httpAccount))
}; };
struct Qv2rayUIConfig { struct Qv2rayUIConfig {
@ -173,7 +173,7 @@ namespace Qv2ray
map<string, string> subscribes; map<string, string> subscribes;
// //
Qv2rayUIConfig uiConfig; Qv2rayUIConfig uiConfig;
Qv2rayInboundsConfig inBoundSettings; Qv2rayInboundsConfig inboundConfig;
Qv2rayToolBarConfig toolBarConfig; Qv2rayToolBarConfig toolBarConfig;
Qv2rayConfig(): Qv2rayConfig():
@ -193,7 +193,7 @@ namespace Qv2ray
configs(), configs(),
subscribes(), subscribes(),
uiConfig(), uiConfig(),
inBoundSettings(), inboundConfig(),
toolBarConfig() { } toolBarConfig() { }
Qv2rayConfig(const string &assetsPath, int log, const Qv2rayInboundsConfig &_inBoundSettings): Qv2rayConfig() Qv2rayConfig(const string &assetsPath, int log, const Qv2rayInboundsConfig &_inBoundSettings): Qv2rayConfig()
{ {
@ -201,7 +201,7 @@ namespace Qv2ray
ignoredVersion = ""; ignoredVersion = "";
autoStartConfig = ""; autoStartConfig = "";
v2AssetsPath = assetsPath; v2AssetsPath = assetsPath;
inBoundSettings = _inBoundSettings; inboundConfig = _inBoundSettings;
logLevel = log; logLevel = log;
tProxySupport = false; tProxySupport = false;
dnsList.push_back("8.8.8.8"); dnsList.push_back("8.8.8.8");
@ -227,7 +227,7 @@ namespace Qv2ray
bypassCN, bypassCN,
withLocalDNS, withLocalDNS,
dnsList, dnsList,
inBoundSettings, inboundConfig,
configs, configs,
subscribes, subscribes,
toolBarConfig)) toolBarConfig))

View File

@ -90,10 +90,24 @@ namespace Qv2ray
auto lang = root["language"].toString(); auto lang = root["language"].toString();
QJsonObject uiSettings; QJsonObject uiSettings;
uiSettings["language"] = lang; uiSettings["language"] = lang;
root["UISettings"] = uiSettings; root["uiConfig"] = uiSettings;
UPDATELOG("Reconstructing config file.") UPDATELOG("Reconstructing config file.")
break; break;
} }
case 9: {
root["uiConfig"] = root["UISettings"];
root.remove("UISettings");
UPDATELOG("Renamed UISettings to uiConfig.")
break;
}
case 10: {
root["inboundConfig"] = root["inBoundSettings"];
root.remove("inBoundSettings");
UPDATELOG("Renamed inBoundSettings to inboundConfig.")
break;
}
} }
root["config_version"] = root["config_version"].toInt() + 1; root["config_version"] = root["config_version"].toInt() + 1;

View File

@ -195,15 +195,15 @@ namespace Qv2ray
QJsonArray inboundsList; QJsonArray inboundsList;
// HTTP InBound // HTTP InBound
if (gConf.inBoundSettings.http_port != 0) { if (gConf.inboundConfig.http_port != 0) {
QJsonObject httpInBoundObject; QJsonObject httpInBoundObject;
httpInBoundObject.insert("listen", QString::fromStdString(gConf.inBoundSettings.listenip)); httpInBoundObject.insert("listen", QString::fromStdString(gConf.inboundConfig.listenip));
httpInBoundObject.insert("port", gConf.inBoundSettings.http_port); httpInBoundObject.insert("port", gConf.inboundConfig.http_port);
httpInBoundObject.insert("protocol", "http"); httpInBoundObject.insert("protocol", "http");
httpInBoundObject.insert("tag", "http_IN"); httpInBoundObject.insert("tag", "http_IN");
if (gConf.inBoundSettings.http_useAuth) { if (gConf.inboundConfig.http_useAuth) {
auto httpInSettings = GenerateHTTPIN(QList<AccountObject>() << gConf.inBoundSettings.httpAccount); auto httpInSettings = GenerateHTTPIN(QList<AccountObject>() << gConf.inboundConfig.httpAccount);
httpInBoundObject.insert("settings", httpInSettings); httpInBoundObject.insert("settings", httpInSettings);
} }
@ -211,16 +211,16 @@ namespace Qv2ray
} }
// SOCKS InBound // SOCKS InBound
if (gConf.inBoundSettings.socks_port != 0) { if (gConf.inboundConfig.socks_port != 0) {
QJsonObject socksInBoundObject; QJsonObject socksInBoundObject;
socksInBoundObject.insert("listen", QString::fromStdString(gConf.inBoundSettings.listenip)); socksInBoundObject.insert("listen", QString::fromStdString(gConf.inboundConfig.listenip));
socksInBoundObject.insert("port", gConf.inBoundSettings.socks_port); socksInBoundObject.insert("port", gConf.inboundConfig.socks_port);
socksInBoundObject.insert("protocol", "socks"); socksInBoundObject.insert("protocol", "socks");
socksInBoundObject.insert("tag", "socks_IN"); socksInBoundObject.insert("tag", "socks_IN");
auto socksInSettings = GenerateSocksIN(gConf.inBoundSettings.socks_useAuth ? "password" : "noauth", auto socksInSettings = GenerateSocksIN(gConf.inboundConfig.socks_useAuth ? "password" : "noauth",
QList<AccountObject>() << gConf.inBoundSettings.socksAccount, QList<AccountObject>() << gConf.inboundConfig.socksAccount,
gConf.inBoundSettings.socksUDP, gConf.inboundConfig.socksUDP,
QSTRING(gConf.inBoundSettings.socksLocalIP)); QSTRING(gConf.inboundConfig.socksLocalIP));
socksInBoundObject.insert("settings", socksInSettings); socksInBoundObject.insert("settings", socksInSettings);
inboundsList.append(socksInBoundObject); inboundsList.append(socksInBoundObject);
} }

View File

@ -11,7 +11,7 @@ namespace Qv2ray
{ {
namespace QvInteration namespace QvInteration
{ {
bool Qv2Instance::ValidateConfig(const QString *path) bool ConnectionInstance::ValidateConfig(const QString *path)
{ {
if (ValidateKernal()) { if (ValidateKernal()) {
QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
@ -38,7 +38,7 @@ namespace Qv2ray
return false; return false;
} }
Qv2Instance::Qv2Instance(QWidget *parent) ConnectionInstance::ConnectionInstance(QWidget *parent)
{ {
auto proc = new QProcess(); auto proc = new QProcess();
vProcess = proc; vProcess = proc;
@ -46,7 +46,7 @@ namespace Qv2ray
VCoreStatus = STOPPED; VCoreStatus = STOPPED;
} }
void Qv2Instance::SetAPIPort(int port) void ConnectionInstance::SetAPIPort(int port)
{ {
// Config API // Config API
this->port = port; this->port = port;
@ -55,12 +55,12 @@ namespace Qv2ray
Stub = service.NewStub(Channel); Stub = service.NewStub(Channel);
} }
QString Qv2Instance::ReadProcessOutput() QString ConnectionInstance::ReadProcessOutput()
{ {
return vProcess->readAllStandardOutput(); return vProcess->readAllStandardOutput();
} }
bool Qv2Instance::ValidateKernal() bool ConnectionInstance::ValidateKernal()
{ {
if (!QFile::exists(QSTRING(GetGlobalConfig().v2CorePath))) { if (!QFile::exists(QSTRING(GetGlobalConfig().v2CorePath))) {
Utils::QvMessageBox(nullptr, QObject::tr("Cannot start v2ray"), Utils::QvMessageBox(nullptr, QObject::tr("Cannot start v2ray"),
@ -72,7 +72,7 @@ namespace Qv2ray
} else return true; } else return true;
} }
bool Qv2Instance::StartVCore() bool ConnectionInstance::StartVCore()
{ {
if (VCoreStatus != STOPPED) { if (VCoreStatus != STOPPED) {
return false; return false;
@ -101,7 +101,7 @@ namespace Qv2ray
} }
} }
void Qv2Instance::StopVCore() void ConnectionInstance::StopVCore()
{ {
vProcess->close(); vProcess->close();
totalDataTransfered = QMap<QString, long>(); totalDataTransfered = QMap<QString, long>();
@ -109,13 +109,13 @@ namespace Qv2ray
VCoreStatus = STOPPED; VCoreStatus = STOPPED;
} }
Qv2Instance::~Qv2Instance() ConnectionInstance::~ConnectionInstance()
{ {
StopVCore(); StopVCore();
delete vProcess; delete vProcess;
} }
long Qv2Instance::CallStatsAPIByName(QString name) long ConnectionInstance::CallStatsAPIByName(QString name)
{ {
GetStatsRequest request; GetStatsRequest request;
request.set_name(name.toStdString()); request.set_name(name.toStdString());
@ -131,7 +131,7 @@ namespace Qv2ray
return response.stat().value(); return response.stat().value();
} }
long Qv2Instance::getTagLastUplink(QString tag) long ConnectionInstance::getTagLastUplink(QString tag)
{ {
auto val = CallStatsAPIByName("inbound>>>" + tag + ">>>traffic>>>uplink"); auto val = CallStatsAPIByName("inbound>>>" + tag + ">>>traffic>>>uplink");
auto data = val - totalDataTransfered[tag + "_up"]; auto data = val - totalDataTransfered[tag + "_up"];
@ -140,7 +140,7 @@ namespace Qv2ray
return data; return data;
} }
long Qv2Instance::getTagLastDownlink(QString tag) long ConnectionInstance::getTagLastDownlink(QString tag)
{ {
auto val = CallStatsAPIByName("inbound>>>" + tag + ">>>traffic>>>downlink"); auto val = CallStatsAPIByName("inbound>>>" + tag + ">>>traffic>>>downlink");
auto data = val - totalDataTransfered[tag + "_down"]; auto data = val - totalDataTransfered[tag + "_down"];
@ -149,12 +149,12 @@ namespace Qv2ray
return data; return data;
} }
long Qv2Instance::getTagTotalUplink(QString tag) long ConnectionInstance::getTagTotalUplink(QString tag)
{ {
return totalDataTransfered[tag + "_up"]; return totalDataTransfered[tag + "_up"];
} }
long Qv2Instance::getTagTotalDownlink(QString tag) long ConnectionInstance::getTagTotalDownlink(QString tag)
{ {
return totalDataTransfered[tag + "_down"]; return totalDataTransfered[tag + "_down"];
} }

View File

@ -24,10 +24,10 @@ namespace Qv2ray
STARTED STARTED
}; };
class Qv2Instance class ConnectionInstance
{ {
public: public:
explicit Qv2Instance(QWidget *parent = nullptr); explicit ConnectionInstance(QWidget *parent = nullptr);
void SetAPIPort(int port); void SetAPIPort(int port);
long getTagTotalDownlink(QString tag); long getTagTotalDownlink(QString tag);
long getTagTotalUplink(QString tag); long getTagTotalUplink(QString tag);
@ -40,7 +40,7 @@ namespace Qv2ray
static bool ValidateKernal(); static bool ValidateKernal();
QString ReadProcessOutput(); QString ReadProcessOutput();
~Qv2Instance(); ~ConnectionInstance();
QMap<QString, long> totalDataTransfered; QMap<QString, long> totalDataTransfered;
QMap<QString, long> dataTransferSpeed; QMap<QString, long> dataTransferSpeed;
private: private:

View File

@ -21,8 +21,8 @@ namespace Qv2ray
QString randomString; QString randomString;
for (int i = 0; i < len; ++i) { for (int i = 0; i < len; ++i) {
int index = static_cast<int>(QRandomGenerator::system()->generate() % static_cast<uint>(possibleCharacters.length())); int index = static_cast<int>(QRandomGenerator::system()->generate()) % possibleCharacters.length();
QChar nextChar = possibleCharacters.at(index); QChar nextChar = possibleCharacters[index];
randomString.append(nextChar); randomString.append(nextChar);
} }

View File

@ -256,7 +256,7 @@ int main(int argc, char *argv[])
#if QV2RAY_USE_BUILTIN_DARKTHEME #if QV2RAY_USE_BUILTIN_DARKTHEME
LOG(MODULE_UI, "Using built-in theme.") LOG(MODULE_UI, "Using built-in theme.")
if (confObject.UISettings.useDarkTheme) { if (confObject.uiConfig.useDarkTheme) {
LOG(MODULE_UI, " --> Using built-in dark theme.") LOG(MODULE_UI, " --> Using built-in dark theme.")
// From https://forum.qt.io/topic/101391/windows-10-dark-theme/4 // From https://forum.qt.io/topic/101391/windows-10-dark-theme/4
_qApp.setStyle("Fusion"); _qApp.setStyle("Fusion");

View File

@ -87,7 +87,7 @@ void ImportConfigWindow::on_beginImportBtn_clicked()
if (config.isEmpty()) { if (config.isEmpty()) {
QvMessageBox(this, tr("Import config file"), tr("Import from file failed, for more information, please check the log file.")); QvMessageBox(this, tr("Import config file"), tr("Import from file failed, for more information, please check the log file."));
return; return;
} else if (!Qv2Instance::ValidateConfig(&path)) { } else if (!ConnectionInstance::ValidateConfig(&path)) {
QvMessageBox(this, tr("Import config file"), tr("Failed to check the validity of the config file.")); QvMessageBox(this, tr("Import config file"), tr("Failed to check the validity of the config file."));
return; return;
} else { } else {

View File

@ -35,7 +35,7 @@ MainWindow::MainWindow(QWidget *parent)
hTray(new QSystemTrayIcon(this)) hTray(new QSystemTrayIcon(this))
{ {
auto conf = GetGlobalConfig(); auto conf = GetGlobalConfig();
vinstance = new Qv2Instance(this); vinstance = new ConnectionInstance(this);
setupUi(this); setupUi(this);
// //
this->setWindowIcon(QIcon(":/icons/qv2ray.png")); this->setWindowIcon(QIcon(":/icons/qv2ray.png"));
@ -103,7 +103,6 @@ MainWindow::MainWindow(QWidget *parent)
LoadConnections(); LoadConnections();
QObject::connect(&HTTPRequestHelper, &QvHttpRequestHelper::httpRequestFinished, this, &MainWindow::VersionUpdate); QObject::connect(&HTTPRequestHelper, &QvHttpRequestHelper::httpRequestFinished, this, &MainWindow::VersionUpdate);
HTTPRequestHelper.get("https://api.github.com/repos/lhy0403/Qv2ray/releases/latest"); HTTPRequestHelper.get("https://api.github.com/repos/lhy0403/Qv2ray/releases/latest");
bool hasAutoStart = false;
// //
// For charts // For charts
uploadSerie = new QSplineSeries(this); uploadSerie = new QSplineSeries(this);
@ -135,29 +134,27 @@ MainWindow::MainWindow(QWidget *parent)
auto layout = new QHBoxLayout(speedChart); auto layout = new QHBoxLayout(speedChart);
layout->addWidget(speedChartView); layout->addWidget(speedChartView);
speedChart->setLayout(layout); speedChart->setLayout(layout);
// //
if (vinstance->ValidateKernal()) { bool hasAutoStart = vinstance->ValidateKernal();
if (hasAutoStart) {
// At least kernal is ready.
if (conf.autoStartConfig != "" && QList<string>::fromStdList(conf.configs).contains(conf.autoStartConfig)) { if (conf.autoStartConfig != "" && QList<string>::fromStdList(conf.configs).contains(conf.autoStartConfig)) {
// Has auto start.
CurrentConnectionName = QSTRING(conf.autoStartConfig); CurrentConnectionName = QSTRING(conf.autoStartConfig);
auto item = connectionListWidget->findItems(QSTRING(conf.autoStartConfig), Qt::MatchExactly).front(); auto item = connectionListWidget->findItems(QSTRING(conf.autoStartConfig), Qt::MatchExactly).front();
item->setSelected(true); item->setSelected(true);
connectionListWidget->setCurrentItem(item); connectionListWidget->setCurrentItem(item);
on_connectionListWidget_itemClicked(item); on_connectionListWidget_itemClicked(item);
on_startButton_clicked();
hasAutoStart = true;
trayMenu->actions()[0]->setText(tr("Show")); trayMenu->actions()[0]->setText(tr("Show"));
} else { this->hide();
if (connectionListWidget->count() != 0) { on_startButton_clicked();
} else if (connectionListWidget->count() != 0) {
// The first one is default. // The first one is default.
connectionListWidget->setCurrentRow(0); connectionListWidget->setCurrentRow(0);
ShowAndSetConnection(connectionListWidget->item(0)->text(), true, false); ShowAndSetConnection(connectionListWidget->item(0)->text(), true, false);
this->show();
} }
}
}
if (hasAutoStart) {
this->hide();
} else { } else {
this->show(); this->show();
} }
@ -175,7 +172,6 @@ void MainWindow::on_action_StartThis_triggered()
CurrentConnectionName = connectionListWidget->currentItem()->text(); CurrentConnectionName = connectionListWidget->currentItem()->text();
on_reconnectButton_clicked(); on_reconnectButton_clicked();
} }
void MainWindow::VersionUpdate(QByteArray &data) void MainWindow::VersionUpdate(QByteArray &data)
{ {
auto conf = GetGlobalConfig(); auto conf = GetGlobalConfig();
@ -210,7 +206,6 @@ void MainWindow::VersionUpdate(QByteArray &data)
} }
} }
} }
void MainWindow::LoadConnections() void MainWindow::LoadConnections()
{ {
auto conf = GetGlobalConfig(); auto conf = GetGlobalConfig();
@ -238,7 +233,6 @@ void MainWindow::LoadConnections()
ShowAndSetConnection(CurrentConnectionName, false, false); ShowAndSetConnection(CurrentConnectionName, false, false);
} }
} }
void MainWindow::OnConfigListChanged(bool need_restart) void MainWindow::OnConfigListChanged(bool need_restart)
{ {
auto statusText = statusLabel->text(); auto statusText = statusLabel->text();
@ -256,19 +250,16 @@ void MainWindow::OnConfigListChanged(bool need_restart)
if (isRunning && need_restart) on_startButton_clicked(); if (isRunning && need_restart) on_startButton_clicked();
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
hTray->hide(); hTray->hide();
delete this->hTray; delete this->hTray;
delete this->vinstance; delete this->vinstance;
} }
void MainWindow::UpdateLog() void MainWindow::UpdateLog()
{ {
logText->append(vinstance->ReadProcessOutput().trimmed()); logText->append(vinstance->ReadProcessOutput().trimmed());
} }
void MainWindow::on_startButton_clicked() void MainWindow::on_startButton_clicked()
{ {
if (vinstance->VCoreStatus != STARTED) { if (vinstance->VCoreStatus != STARTED) {
@ -280,6 +271,7 @@ void MainWindow::on_startButton_clicked()
downloadSerie->replace(i, 0, 0); downloadSerie->replace(i, 0, 0);
} }
// Check Selection
if (CurrentConnectionName.isEmpty()) { if (CurrentConnectionName.isEmpty()) {
QvMessageBox(this, tr("No connection selected!"), tr("Please select a config from the list.")); QvMessageBox(this, tr("No connection selected!"), tr("Please select a config from the list."));
return; return;
@ -287,6 +279,7 @@ void MainWindow::on_startButton_clicked()
LOG(MODULE_VCORE, ("Connecting to: " + CurrentConnectionName).toStdString()) LOG(MODULE_VCORE, ("Connecting to: " + CurrentConnectionName).toStdString())
logText->clear(); logText->clear();
//
CurrentFullConfig = GenerateRuntimeConfig(connections[CurrentConnectionName]); CurrentFullConfig = GenerateRuntimeConfig(connections[CurrentConnectionName]);
StartPreparation(CurrentFullConfig); StartPreparation(CurrentFullConfig);
bool startFlag = this->vinstance->StartVCore(); bool startFlag = this->vinstance->StartVCore();
@ -300,6 +293,9 @@ void MainWindow::on_startButton_clicked()
vinstance->SetAPIPort(GetGlobalConfig().statsPort); vinstance->SetAPIPort(GetGlobalConfig().statsPort);
speedTimerId = startTimer(1000); speedTimerId = startTimer(1000);
} }
} else {
// If failed, show mainwindow
this->show();
} }
trayMenu->actions()[2]->setEnabled(!startFlag); trayMenu->actions()[2]->setEnabled(!startFlag);
@ -310,7 +306,6 @@ void MainWindow::on_startButton_clicked()
stopButton->setEnabled(startFlag); stopButton->setEnabled(startFlag);
} }
} }
void MainWindow::on_stopButton_clicked() void MainWindow::on_stopButton_clicked()
{ {
if (vinstance->VCoreStatus != STOPPED) { if (vinstance->VCoreStatus != STOPPED) {
@ -331,14 +326,12 @@ void MainWindow::on_stopButton_clicked()
dataamountLabel->setText("0.00 B\r\n0.00 B"); dataamountLabel->setText("0.00 B\r\n0.00 B");
} }
} }
void MainWindow::closeEvent(QCloseEvent *event) void MainWindow::closeEvent(QCloseEvent *event)
{ {
this->hide(); this->hide();
trayMenu->actions()[0]->setText(tr("Show")); trayMenu->actions()[0]->setText(tr("Show"));
event->ignore(); event->ignore();
} }
void MainWindow::on_activatedTray(QSystemTrayIcon::ActivationReason reason) void MainWindow::on_activatedTray(QSystemTrayIcon::ActivationReason reason)
{ {
switch (reason) { switch (reason) {
@ -370,7 +363,6 @@ void MainWindow::on_activatedTray(QSystemTrayIcon::ActivationReason reason)
break; break;
} }
} }
void MainWindow::ToggleVisibility() void MainWindow::ToggleVisibility()
{ {
if (this->isHidden()) { if (this->isHidden()) {
@ -386,26 +378,22 @@ void MainWindow::ToggleVisibility()
trayMenu->actions()[0]->setText(tr("Show")); trayMenu->actions()[0]->setText(tr("Show"));
} }
} }
void MainWindow::quit() void MainWindow::quit()
{ {
Utils::NetSpeedPlugin::StopProcessingPlugins(); Utils::NetSpeedPlugin::StopProcessingPlugins();
on_stopButton_clicked(); on_stopButton_clicked();
QApplication::quit(); QApplication::quit();
} }
void MainWindow::on_actionExit_triggered() void MainWindow::on_actionExit_triggered()
{ {
quit(); quit();
} }
void MainWindow::QTextScrollToBottom() void MainWindow::QTextScrollToBottom()
{ {
auto bar = logText->verticalScrollBar(); auto bar = logText->verticalScrollBar();
if (bar->value() >= bar->maximum() - 10) bar->setValue(bar->maximum()); if (bar->value() >= bar->maximum() - 10) bar->setValue(bar->maximum());
} }
void MainWindow::ShowAndSetConnection(QString guiConnectionName, bool SetConnection, bool ApplyConnection) void MainWindow::ShowAndSetConnection(QString guiConnectionName, bool SetConnection, bool ApplyConnection)
{ {
// Check empty again... // Check empty again...
@ -452,7 +440,6 @@ void MainWindow::ShowAndSetConnection(QString guiConnectionName, bool SetConnect
on_reconnectButton_clicked(); on_reconnectButton_clicked();
} }
} }
void MainWindow::on_connectionListWidget_itemClicked(QListWidgetItem *item) void MainWindow::on_connectionListWidget_itemClicked(QListWidgetItem *item)
{ {
Q_UNUSED(item) Q_UNUSED(item)
@ -464,14 +451,12 @@ void MainWindow::on_connectionListWidget_itemClicked(QListWidgetItem *item)
bool canSetConnection = !isRenamingInProgress && vinstance->VCoreStatus != STARTED; bool canSetConnection = !isRenamingInProgress && vinstance->VCoreStatus != STARTED;
ShowAndSetConnection(currentText, canSetConnection, false); ShowAndSetConnection(currentText, canSetConnection, false);
} }
void MainWindow::on_prefrencesBtn_clicked() void MainWindow::on_prefrencesBtn_clicked()
{ {
PrefrencesWindow *w = new PrefrencesWindow(this); PrefrencesWindow *w = new PrefrencesWindow(this);
connect(w, &PrefrencesWindow::s_reload_config, this, &MainWindow::OnConfigListChanged); connect(w, &PrefrencesWindow::s_reload_config, this, &MainWindow::OnConfigListChanged);
w->show(); w->show();
} }
void MainWindow::on_connectionListWidget_doubleClicked(const QModelIndex &index) void MainWindow::on_connectionListWidget_doubleClicked(const QModelIndex &index)
{ {
Q_UNUSED(index) Q_UNUSED(index)
@ -482,25 +467,21 @@ void MainWindow::on_connectionListWidget_doubleClicked(const QModelIndex &index)
QString currentText = connectionListWidget->currentItem()->text(); QString currentText = connectionListWidget->currentItem()->text();
ShowAndSetConnection(currentText, true, true); ShowAndSetConnection(currentText, true, true);
} }
void MainWindow::on_clearlogButton_clicked() void MainWindow::on_clearlogButton_clicked()
{ {
logText->clear(); logText->clear();
} }
void MainWindow::on_connectionListWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous) void MainWindow::on_connectionListWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
{ {
Q_UNUSED(previous) Q_UNUSED(previous)
isRenamingInProgress = false; isRenamingInProgress = false;
on_connectionListWidget_itemClicked(current); on_connectionListWidget_itemClicked(current);
} }
void MainWindow::on_connectionListWidget_customContextMenuRequested(const QPoint &pos) void MainWindow::on_connectionListWidget_customContextMenuRequested(const QPoint &pos)
{ {
Q_UNUSED(pos) Q_UNUSED(pos)
listMenu.popup(QCursor::pos()); listMenu.popup(QCursor::pos());
} }
void MainWindow::on_action_RenameConnection_triggered() void MainWindow::on_action_RenameConnection_triggered()
{ {
auto item = connectionListWidget->currentItem(); auto item = connectionListWidget->currentItem();
@ -509,7 +490,6 @@ void MainWindow::on_action_RenameConnection_triggered()
originalName = item->text(); originalName = item->text();
isRenamingInProgress = true; isRenamingInProgress = true;
} }
void MainWindow::on_connectionListWidget_itemChanged(QListWidgetItem *item) void MainWindow::on_connectionListWidget_itemChanged(QListWidgetItem *item)
{ {
DEBUG(MODULE_UI, "A connection ListViewItem is changed.") DEBUG(MODULE_UI, "A connection ListViewItem is changed.")
@ -553,7 +533,6 @@ void MainWindow::on_connectionListWidget_itemChanged(QListWidgetItem *item)
} }
} }
} }
void MainWindow::on_removeConfigButton_clicked() void MainWindow::on_removeConfigButton_clicked()
{ {
if (connectionListWidget->currentIndex().row() < 0) return; if (connectionListWidget->currentIndex().row() < 0) return;
@ -580,14 +559,12 @@ void MainWindow::on_removeConfigButton_clicked()
ShowAndSetConnection(CurrentConnectionName, false, false); ShowAndSetConnection(CurrentConnectionName, false, false);
} }
} }
void MainWindow::on_importConfigButton_clicked() void MainWindow::on_importConfigButton_clicked()
{ {
ImportConfigWindow *w = new ImportConfigWindow(this); ImportConfigWindow *w = new ImportConfigWindow(this);
w->exec(); w->exec();
OnConfigListChanged(false); OnConfigListChanged(false);
} }
void MainWindow::on_editConfigButton_clicked() void MainWindow::on_editConfigButton_clicked()
{ {
// Check if we have a connection selected... // Check if we have a connection selected...
@ -624,13 +601,11 @@ void MainWindow::on_editConfigButton_clicked()
ShowAndSetConnection(CurrentConnectionName, false, false); ShowAndSetConnection(CurrentConnectionName, false, false);
} }
} }
void MainWindow::on_reconnectButton_clicked() void MainWindow::on_reconnectButton_clicked()
{ {
on_stopButton_clicked(); on_stopButton_clicked();
on_startButton_clicked(); on_startButton_clicked();
} }
void MainWindow::on_action_RCM_EditJson_triggered() void MainWindow::on_action_RCM_EditJson_triggered()
{ {
// Check if we have a connection selected... // Check if we have a connection selected...
@ -652,18 +627,15 @@ void MainWindow::on_action_RCM_EditJson_triggered()
ShowAndSetConnection(CurrentConnectionName, false, false); ShowAndSetConnection(CurrentConnectionName, false, false);
} }
} }
void MainWindow::on_editJsonBtn_clicked() void MainWindow::on_editJsonBtn_clicked()
{ {
// See above. // See above.
on_action_RCM_EditJson_triggered(); on_action_RCM_EditJson_triggered();
} }
void MainWindow::on_pingTestBtn_clicked() void MainWindow::on_pingTestBtn_clicked()
{ {
// Ping // Ping
} }
void MainWindow::on_shareBtn_clicked() void MainWindow::on_shareBtn_clicked()
{ {
// Share QR // Share QR
@ -687,12 +659,10 @@ void MainWindow::on_shareBtn_clicked()
QvMessageBox(this, tr("Share Connection"), tr("There're no support of sharing configs other than vmess")); QvMessageBox(this, tr("Share Connection"), tr("There're no support of sharing configs other than vmess"));
} }
} }
void MainWindow::on_action_RCM_ShareQR_triggered(bool checked) void MainWindow::on_action_RCM_ShareQR_triggered(bool checked)
{ {
on_shareBtn_clicked(); on_shareBtn_clicked();
} }
void MainWindow::timerEvent(QTimerEvent *event) void MainWindow::timerEvent(QTimerEvent *event)
{ {
Q_UNUSED(event) Q_UNUSED(event)

View File

@ -69,7 +69,7 @@ class MainWindow : public QMainWindow, Ui::MainWindow
public: public:
QJsonObject CurrentFullConfig; QJsonObject CurrentFullConfig;
QString CurrentConnectionName = ""; QString CurrentConnectionName = "";
Qv2Instance *vinstance; ConnectionInstance *vinstance;
QString totalDataUp; QString totalDataUp;
QString totalDataDown; QString totalDataDown;
QString totalSpeedUp; QString totalSpeedUp;

View File

@ -46,36 +46,46 @@ PrefrencesWindow::PrefrencesWindow(QWidget *parent) : QDialog(parent),
tProxyCheckBox->setChecked(CurrentConfig.tProxySupport); tProxyCheckBox->setChecked(CurrentConfig.tProxySupport);
// //
// //
listenIPTxt->setText(QSTRING(CurrentConfig.inBoundSettings.listenip)); listenIPTxt->setText(QSTRING(CurrentConfig.inboundConfig.listenip));
bool pacEnabled = CurrentConfig.inboundConfig.pacConfig.enablePAC;
enablePACCB->setChecked(pacEnabled);
// //
bool have_http = CurrentConfig.inBoundSettings.http_port != 0; pacGroupBox->setEnabled(pacEnabled);
if (pacEnabled) {
pacPortSB->setValue(CurrentConfig.inboundConfig.pacConfig.port);
gfwListCB->setCurrentIndex(CurrentConfig.inboundConfig.pacConfig.sourceId);
}
//
bool have_http = CurrentConfig.inboundConfig.http_port != 0;
httpCB->setChecked(have_http); httpCB->setChecked(have_http);
httpPortLE->setValue(CurrentConfig.inBoundSettings.http_port); httpGroupBox->setEnabled(have_http);
httpAuthCB->setChecked(CurrentConfig.inBoundSettings.http_useAuth); httpPortLE->setValue(CurrentConfig.inboundConfig.http_port);
httpAuthCB->setChecked(CurrentConfig.inboundConfig.http_useAuth);
// //
httpAuthCB->setEnabled(have_http); httpAuthCB->setChecked(CurrentConfig.inboundConfig.http_useAuth);
httpAuthCB->setChecked(CurrentConfig.inBoundSettings.http_useAuth); httpAuthUsernameTxt->setEnabled(have_http && CurrentConfig.inboundConfig.http_useAuth);
httpAuthUsernameTxt->setEnabled(have_http && CurrentConfig.inBoundSettings.http_useAuth); httpAuthPasswordTxt->setEnabled(have_http && CurrentConfig.inboundConfig.http_useAuth);
httpAuthPasswordTxt->setEnabled(have_http && CurrentConfig.inBoundSettings.http_useAuth); httpAuthUsernameTxt->setText(QSTRING(CurrentConfig.inboundConfig.httpAccount.user));
httpAuthUsernameTxt->setText(QSTRING(CurrentConfig.inBoundSettings.httpAccount.user)); httpAuthPasswordTxt->setText(QSTRING(CurrentConfig.inboundConfig.httpAccount.pass));
httpAuthPasswordTxt->setText(QSTRING(CurrentConfig.inBoundSettings.httpAccount.pass));
// //
// //
bool have_socks = CurrentConfig.inBoundSettings.socks_port != 0; bool have_socks = CurrentConfig.inboundConfig.socks_port != 0;
socksCB->setChecked(have_socks); socksCB->setChecked(have_socks);
socksPortLE->setValue(CurrentConfig.inBoundSettings.socks_port); socksGroupBox->setEnabled(have_socks);
socksAuthCB->setChecked(CurrentConfig.inBoundSettings.socks_useAuth); socksPortLE->setValue(CurrentConfig.inboundConfig.socks_port);
socksAuthCB->setChecked(CurrentConfig.inboundConfig.socks_useAuth);
// //
socksAuthCB->setEnabled(have_socks); socksAuthCB->setChecked(CurrentConfig.inboundConfig.socks_useAuth);
socksAuthCB->setChecked(CurrentConfig.inBoundSettings.socks_useAuth); socksAuthUsernameTxt->setEnabled(have_socks && CurrentConfig.inboundConfig.socks_useAuth);
socksAuthUsernameTxt->setEnabled(have_socks && CurrentConfig.inBoundSettings.socks_useAuth); socksAuthPasswordTxt->setEnabled(have_socks && CurrentConfig.inboundConfig.socks_useAuth);
socksAuthPasswordTxt->setEnabled(have_socks && CurrentConfig.inBoundSettings.socks_useAuth); socksAuthUsernameTxt->setText(QSTRING(CurrentConfig.inboundConfig.socksAccount.user));
socksAuthUsernameTxt->setText(QSTRING(CurrentConfig.inBoundSettings.socksAccount.user)); socksAuthPasswordTxt->setText(QSTRING(CurrentConfig.inboundConfig.socksAccount.pass));
socksAuthPasswordTxt->setText(QSTRING(CurrentConfig.inBoundSettings.socksAccount.pass));
// Socks UDP Options // Socks UDP Options
socksUDPCB->setChecked(CurrentConfig.inBoundSettings.socksUDP); socksUDPCB->setChecked(CurrentConfig.inboundConfig.socksUDP);
socksUDPIP->setEnabled(CurrentConfig.inBoundSettings.socksUDP); socksUDPIP->setEnabled(CurrentConfig.inboundConfig.socksUDP);
socksUDPIP->setText(QSTRING(CurrentConfig.inBoundSettings.socksLocalIP)); socksUDPIP->setText(QSTRING(CurrentConfig.inboundConfig.socksLocalIP));
// //
// //
vCorePathTxt->setText(QSTRING(CurrentConfig.v2CorePath)); vCorePathTxt->setText(QSTRING(CurrentConfig.v2CorePath));
@ -149,13 +159,13 @@ void PrefrencesWindow::on_buttonBox_accepted()
void PrefrencesWindow::on_httpCB_stateChanged(int checked) void PrefrencesWindow::on_httpCB_stateChanged(int checked)
{ {
NEEDRESTART NEEDRESTART
httpPortLE->setEnabled(checked == Qt::Checked); bool enabled = checked == Qt::Checked;
httpAuthCB->setEnabled(checked == Qt::Checked); httpGroupBox->setEnabled(enabled);
httpAuthUsernameTxt->setEnabled(checked == Qt::Checked && httpAuthCB->isChecked()); httpAuthUsernameTxt->setEnabled(enabled && httpAuthCB->isChecked());
httpAuthPasswordTxt->setEnabled(checked == Qt::Checked && httpAuthCB->isChecked()); httpAuthPasswordTxt->setEnabled(enabled && httpAuthCB->isChecked());
CurrentConfig.inBoundSettings.http_port = checked == Qt::Checked ? CurrentConfig.inBoundSettings.http_port : 0; CurrentConfig.inboundConfig.http_port = enabled ? CurrentConfig.inboundConfig.http_port : 0;
if (checked != Qt::Checked) { if (!enabled) {
httpPortLE->setValue(0); httpPortLE->setValue(0);
} }
} }
@ -163,13 +173,11 @@ void PrefrencesWindow::on_httpCB_stateChanged(int checked)
void PrefrencesWindow::on_socksCB_stateChanged(int checked) void PrefrencesWindow::on_socksCB_stateChanged(int checked)
{ {
NEEDRESTART NEEDRESTART
socksPortLE->setEnabled(checked == Qt::Checked); bool enabled = checked == Qt::Checked;
socksAuthCB->setEnabled(checked == Qt::Checked); socksGroupBox->setEnabled(enabled);
socksAuthUsernameTxt->setEnabled(checked == Qt::Checked && socksAuthCB->isChecked()); CurrentConfig.inboundConfig.socks_port = enabled ? CurrentConfig.inboundConfig.socks_port : 0;
socksAuthPasswordTxt->setEnabled(checked == Qt::Checked && socksAuthCB->isChecked());
CurrentConfig.inBoundSettings.socks_port = checked == Qt::Checked ? CurrentConfig.inBoundSettings.socks_port : 0;
if (checked != Qt::Checked) { if (!enabled) {
socksPortLE->setValue(0); socksPortLE->setValue(0);
} }
} }
@ -177,32 +185,39 @@ void PrefrencesWindow::on_socksCB_stateChanged(int checked)
void PrefrencesWindow::on_httpAuthCB_stateChanged(int checked) void PrefrencesWindow::on_httpAuthCB_stateChanged(int checked)
{ {
NEEDRESTART NEEDRESTART
httpAuthUsernameTxt->setEnabled(checked == Qt::Checked); bool enabled = checked == Qt::Checked;
httpAuthPasswordTxt->setEnabled(checked == Qt::Checked); httpAuthUsernameTxt->setEnabled(enabled);
CurrentConfig.inBoundSettings.http_useAuth = checked == Qt::Checked; httpAuthPasswordTxt->setEnabled(enabled);
CurrentConfig.inboundConfig.http_useAuth = enabled;
} }
void PrefrencesWindow::on_socksAuthCB_stateChanged(int checked) void PrefrencesWindow::on_socksAuthCB_stateChanged(int checked)
{ {
NEEDRESTART NEEDRESTART
socksAuthUsernameTxt->setEnabled(checked == Qt::Checked); bool enabled = checked == Qt::Checked;
socksAuthPasswordTxt->setEnabled(checked == Qt::Checked); socksAuthUsernameTxt->setEnabled(enabled);
CurrentConfig.inBoundSettings.socks_useAuth = checked == Qt::Checked; socksAuthPasswordTxt->setEnabled(enabled);
CurrentConfig.inboundConfig.socks_useAuth = enabled;
} }
void PrefrencesWindow::on_languageComboBox_currentTextChanged(const QString &arg1) void PrefrencesWindow::on_languageComboBox_currentTextChanged(const QString &arg1)
{ {
CurrentConfig.uiConfig.language = arg1.toStdString(); LOADINGCHECK
// //
// A strange bug prevents us to change the UI language online // A strange bug prevents us to change the UI language online
// https://github.com/lhy0403/Qv2ray/issues/34 // https://github.com/lhy0403/Qv2ray/issues/34
// //
//if (QApplication::installTranslator(getTranslator(&arg1))) { CurrentConfig.uiConfig.language = arg1.toStdString();
//
//
//if (QApplication::installTranslator(getTranslator(arg1))) {
// LOG(MODULE_UI, "Loaded translations " + arg1.toStdString()) // LOG(MODULE_UI, "Loaded translations " + arg1.toStdString())
// retranslateUi(this); // retranslateUi(this);
//} else { //} else {
// QvMessageBox(this, tr("#Prefrences"), tr("#SwitchTranslationError")); // QvMessageBox(this, tr("#Prefrences"), tr("#SwitchTranslationError"));
//} //}
//
//emit retranslateUi(this);
} }
void PrefrencesWindow::on_logLevelComboBox_currentIndexChanged(int index) void PrefrencesWindow::on_logLevelComboBox_currentIndexChanged(int index)
@ -220,32 +235,32 @@ void PrefrencesWindow::on_vCoreAssetsPathTxt_textEdited(const QString &arg1)
void PrefrencesWindow::on_listenIPTxt_textEdited(const QString &arg1) void PrefrencesWindow::on_listenIPTxt_textEdited(const QString &arg1)
{ {
NEEDRESTART NEEDRESTART
CurrentConfig.inBoundSettings.listenip = arg1.toStdString(); CurrentConfig.inboundConfig.listenip = arg1.toStdString();
pacAddressLabel->setText("http://" + arg1 + ":"); pacAccessPathTxt->setText("http://" + arg1 + ":" + QString::number(pacPortSB->value()) + "/pac.txt");
} }
void PrefrencesWindow::on_httpAuthUsernameTxt_textEdited(const QString &arg1) void PrefrencesWindow::on_httpAuthUsernameTxt_textEdited(const QString &arg1)
{ {
NEEDRESTART NEEDRESTART
CurrentConfig.inBoundSettings.httpAccount.user = arg1.toStdString(); CurrentConfig.inboundConfig.httpAccount.user = arg1.toStdString();
} }
void PrefrencesWindow::on_httpAuthPasswordTxt_textEdited(const QString &arg1) void PrefrencesWindow::on_httpAuthPasswordTxt_textEdited(const QString &arg1)
{ {
NEEDRESTART NEEDRESTART
CurrentConfig.inBoundSettings.httpAccount.pass = arg1.toStdString(); CurrentConfig.inboundConfig.httpAccount.pass = arg1.toStdString();
} }
void PrefrencesWindow::on_socksAuthUsernameTxt_textEdited(const QString &arg1) void PrefrencesWindow::on_socksAuthUsernameTxt_textEdited(const QString &arg1)
{ {
NEEDRESTART NEEDRESTART
CurrentConfig.inBoundSettings.socksAccount.user = arg1.toStdString(); CurrentConfig.inboundConfig.socksAccount.user = arg1.toStdString();
} }
void PrefrencesWindow::on_socksAuthPasswordTxt_textEdited(const QString &arg1) void PrefrencesWindow::on_socksAuthPasswordTxt_textEdited(const QString &arg1)
{ {
NEEDRESTART NEEDRESTART
CurrentConfig.inBoundSettings.socksAccount.pass = arg1.toStdString(); CurrentConfig.inboundConfig.socksAccount.pass = arg1.toStdString();
} }
void PrefrencesWindow::on_proxyDefaultCb_stateChanged(int arg1) void PrefrencesWindow::on_proxyDefaultCb_stateChanged(int arg1)
@ -439,26 +454,26 @@ void PrefrencesWindow::on_statsPortBox_valueChanged(int arg1)
void PrefrencesWindow::on_socksPortLE_valueChanged(int arg1) void PrefrencesWindow::on_socksPortLE_valueChanged(int arg1)
{ {
NEEDRESTART NEEDRESTART
CurrentConfig.inBoundSettings.socks_port = arg1; CurrentConfig.inboundConfig.socks_port = arg1;
} }
void PrefrencesWindow::on_httpPortLE_valueChanged(int arg1) void PrefrencesWindow::on_httpPortLE_valueChanged(int arg1)
{ {
NEEDRESTART NEEDRESTART
CurrentConfig.inBoundSettings.http_port = arg1; CurrentConfig.inboundConfig.http_port = arg1;
} }
void PrefrencesWindow::on_socksUDPCB_stateChanged(int arg1) void PrefrencesWindow::on_socksUDPCB_stateChanged(int arg1)
{ {
NEEDRESTART NEEDRESTART
CurrentConfig.inBoundSettings.socksUDP = arg1 == Qt::Checked; CurrentConfig.inboundConfig.socksUDP = arg1 == Qt::Checked;
socksUDPIP->setEnabled(arg1 == Qt::Checked); socksUDPIP->setEnabled(arg1 == Qt::Checked);
} }
void PrefrencesWindow::on_socksUDPIP_textEdited(const QString &arg1) void PrefrencesWindow::on_socksUDPIP_textEdited(const QString &arg1)
{ {
NEEDRESTART NEEDRESTART
CurrentConfig.inBoundSettings.socksLocalIP = arg1.toStdString(); CurrentConfig.inboundConfig.socksLocalIP = arg1.toStdString();
} }
// ------------------- NET SPEED PLUGIN OPERATIONS ----------------------------------------------------------------- // ------------------- NET SPEED PLUGIN OPERATIONS -----------------------------------------------------------------
@ -634,45 +649,45 @@ void PrefrencesWindow::on_nsBarFontSizeSB_valueChanged(double arg1)
SET_LINE_LIST_TEXT SET_LINE_LIST_TEXT
} }
QString PrefrencesWindow::GetBarLineDescription(QvBarLine line) QString PrefrencesWindow::GetBarLineDescription(QvBarLine barLine)
{ {
QString result = "Empty"; QString result = "Empty";
result = NetSpeedPluginMessages[line.ContentType]; result = NetSpeedPluginMessages[barLine.ContentType];
if (line.ContentType == 0) { if (barLine.ContentType == 0) {
result += " (" + QSTRING(line.Message) + ")"; result += " (" + QSTRING(barLine.Message) + ")";
} }
result = result.append(line.Bold ? ", " + tr("Bold") : ""); result = result.append(barLine.Bold ? ", " + tr("Bold") : "");
result = result.append(line.Italic ? ", " + tr("Italic") : ""); result = result.append(barLine.Italic ? ", " + tr("Italic") : "");
return result; return result;
} }
void PrefrencesWindow::ShowLineParameters(QvBarLine &line) void PrefrencesWindow::ShowLineParameters(QvBarLine &barLine)
{ {
finishedLoading = false; finishedLoading = false;
if (!line.Family.empty()) { if (!barLine.Family.empty()) {
fontComboBox->setCurrentFont(QFont(QSTRING(line.Family))); fontComboBox->setCurrentFont(QFont(QSTRING(barLine.Family)));
} }
// Colors // Colors
nsBarFontASB->setValue(line.ColorA); nsBarFontASB->setValue(barLine.ColorA);
nsBarFontBSB->setValue(line.ColorB); nsBarFontBSB->setValue(barLine.ColorB);
nsBarFontGSB->setValue(line.ColorG); nsBarFontGSB->setValue(barLine.ColorG);
nsBarFontRSB->setValue(line.ColorR); nsBarFontRSB->setValue(barLine.ColorR);
// //
QColor color = QColor::fromRgb(line.ColorR, line.ColorG, line.ColorB, line.ColorA); QColor color = QColor::fromRgb(barLine.ColorR, barLine.ColorG, barLine.ColorB, barLine.ColorA);
QString s("background: #" QString s("background: #"
+ QString(color.red() < 16 ? "0" : "") + QString::number(color.red(), 16) + QString(color.red() < 16 ? "0" : "") + QString::number(color.red(), 16)
+ QString(color.green() < 16 ? "0" : "") + QString::number(color.green(), 16) + QString(color.green() < 16 ? "0" : "") + QString::number(color.green(), 16)
+ QString(color.blue() < 16 ? "0" : "") + QString::number(color.blue(), 16) + ";"); + QString(color.blue() < 16 ? "0" : "") + QString::number(color.blue(), 16) + ";");
chooseColorBtn->setStyleSheet(s); chooseColorBtn->setStyleSheet(s);
nsBarFontSizeSB->setValue(line.Size); nsBarFontSizeSB->setValue(barLine.Size);
nsBarFontBoldCB->setChecked(line.Bold); nsBarFontBoldCB->setChecked(barLine.Bold);
nsBarFontItalicCB->setChecked(line.Italic); nsBarFontItalicCB->setChecked(barLine.Italic);
nsBarContentCombo->setCurrentText(NetSpeedPluginMessages[line.ContentType]); nsBarContentCombo->setCurrentText(NetSpeedPluginMessages[barLine.ContentType]);
nsBarTagTxt->setText(QSTRING(line.Message)); nsBarTagTxt->setText(QSTRING(barLine.Message));
finishedLoading = true; finishedLoading = true;
nsBarVerticalLayout->setEnabled(true); nsBarVerticalLayout->setEnabled(true);
} }
@ -740,5 +755,18 @@ void PrefrencesWindow::on_darkTrayCB_stateChanged(int arg1)
void PrefrencesWindow::on_enablePACCB_stateChanged(int arg1) void PrefrencesWindow::on_enablePACCB_stateChanged(int arg1)
{ {
pacSettingsLayout_2->setEnabled(arg1 == Qt::Checked); bool enabled = arg1 == Qt::Checked;
CurrentConfig.inboundConfig.pacConfig.enablePAC = enabled;
pacGroupBox->setEnabled(enabled);
}
void PrefrencesWindow::on_pacGoBtn_clicked()
{
//
}
void PrefrencesWindow::on_pacPortSB_valueChanged(int arg1)
{
CurrentConfig.inboundConfig.pacConfig.port = arg1;
pacAccessPathTxt->setText("http://" + listenIPTxt->text() + ":" + QString::number(arg1) + "/pac.txt");
} }

View File

@ -122,6 +122,10 @@ class PrefrencesWindow : public QDialog, private Ui::PrefrencesWindow
void on_enablePACCB_stateChanged(int arg1); void on_enablePACCB_stateChanged(int arg1);
void on_pacGoBtn_clicked();
void on_pacPortSB_valueChanged(int arg1);
private: private:
// Set ui parameters for a line; // Set ui parameters for a line;
void ShowLineParameters(QvBarLine &line); void ShowLineParameters(QvBarLine &line);
@ -132,7 +136,7 @@ class PrefrencesWindow : public QDialog, private Ui::PrefrencesWindow
// //
bool IsConnectionPropertyChanged = false; bool IsConnectionPropertyChanged = false;
bool finishedLoading = false; bool finishedLoading = false;
Qv2ray::QvConfigModels::Qv2rayConfig CurrentConfig; Qv2rayConfig CurrentConfig;
Ui::PrefrencesWindow *ui; Ui::PrefrencesWindow *ui;
}; };
#endif // HVCONF_H #endif // HVCONF_H

View File

@ -39,7 +39,7 @@
<enum>QTabWidget::Rounded</enum> <enum>QTabWidget::Rounded</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="tab"> <widget class="QWidget" name="tab">
<attribute name="title"> <attribute name="title">
@ -323,7 +323,7 @@
<attribute name="title"> <attribute name="title">
<string>Inbound Settings</string> <string>Inbound Settings</string>
</attribute> </attribute>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,1"> <layout class="QVBoxLayout" name="verticalLayout" stretch="0,1">
<item> <item>
<layout class="QFormLayout" name="formLayout_4"> <layout class="QFormLayout" name="formLayout_4">
<item row="0" column="0"> <item row="0" column="0">
@ -340,62 +340,29 @@
</property> </property>
</widget> </widget>
</item> </item>
</layout> <item row="1" column="0">
</item>
<item>
<widget class="QGroupBox" name="">
<property name="title">
<string>PAC Settings</string>
</property>
<layout class="QFormLayout" name="formLayout_10">
<item row="0" column="0">
<widget class="QLabel" name="label_59"> <widget class="QLabel" name="label_59">
<property name="text"> <property name="text">
<string>Enable PAC</string> <string>Features</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="1" column="1">
<widget class="QCheckBox" name="enablePACCB"> <layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="text">
<string>Enabled</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QFrame" name="pacSettingsLayout_2">
<layout class="QHBoxLayout" name="pacSettingsLayout">
<item> <item>
<widget class="QLabel" name="label_57"> <widget class="QCheckBox" name="httpCB">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text"> <property name="text">
<string>Access Path</string> <string>HTTP</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="pacAddressLabel"> <widget class="QCheckBox" name="socksCB">
<property name="text"> <property name="text">
<string>http://0.0.0.0:</string> <string>SOCKS</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="pacPortEdit">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>8088</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_56">
<property name="text">
<string>/pac</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -413,14 +380,113 @@
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_58"> <widget class="QLabel" name="label_56">
<property name="text"> <property name="text">
<string>GFWList Import Source</string> <string>PAC Support</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="comboBox_2"> <widget class="QCheckBox" name="enablePACCB">
<property name="text">
<string>Enabled</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_7">
<item row="0" column="1">
<widget class="QGroupBox" name="httpGroupBox">
<property name="title">
<string>HTTP Settings</string>
</property>
<layout class="QFormLayout" name="formLayout_7">
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Port</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="httpPortLE">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>18001</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Authentication</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="httpAuthCB">
<property name="text">
<string>Enabled</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Username</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="httpAuthUsernameTxt">
<property name="placeholderText">
<string notr="true">user</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="httpAuthPasswordTxt">
<property name="placeholderText">
<string notr="true">pass</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="1">
<widget class="QGroupBox" name="pacGroupBox">
<property name="title">
<string>PAC Settings</string>
</property>
<layout class="QFormLayout" name="formLayout_11">
<item row="0" column="0">
<widget class="QLabel" name="label_58">
<property name="text">
<string>GFWList Source</string>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QComboBox" name="gfwListCB">
<item> <item>
<property name="text"> <property name="text">
<string>Github</string> <string>Github</string>
@ -459,33 +525,71 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="pacChooseFileBtn"> <widget class="QToolButton" name="pacGoBtn">
<property name="text"> <property name="text">
<string>Go</string> <string>Go</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_62">
<property name="text">
<string>Edit PAC</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Open PAC Folder</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_57">
<property name="text">
<string>Port</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="pacPortSB">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>8088</number>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_61">
<property name="text">
<string>Access URL</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="pacAccessPathTxt">
<property name="readOnly">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
</item> </item>
<item> <item row="0" column="0" rowspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2"> <widget class="QGroupBox" name="socksGroupBox">
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title"> <property name="title">
<string>SOCKS Inbound Settings</string> <string>SOCKS Settings</string>
</property> </property>
<layout class="QFormLayout" name="formLayout_2"> <layout class="QFormLayout" name="formLayout_2">
<item row="0" column="1">
<widget class="QCheckBox" name="socksCB">
<property name="text">
<string>Enabled</string>
</property>
</widget>
</item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="label_4"> <widget class="QLabel" name="label_4">
<property name="text"> <property name="text">
@ -501,12 +605,15 @@
<property name="maximum"> <property name="maximum">
<number>65535</number> <number>65535</number>
</property> </property>
<property name="value">
<number>1081</number>
</property>
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item row="2" column="0">
<widget class="QLabel" name="label_14"> <widget class="QLabel" name="label_14">
<property name="text"> <property name="text">
<string>SOCKS UDP</string> <string>UDP Support</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -520,7 +627,7 @@
<item row="3" column="0"> <item row="3" column="0">
<widget class="QLabel" name="label_25"> <widget class="QLabel" name="label_25">
<property name="text"> <property name="text">
<string>Local IP</string> <string>Local IP (For UDP)</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -576,84 +683,6 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item>
<widget class="QGroupBox" name="groupBox_7">
<property name="title">
<string>HTTP Inbound Settings</string>
</property>
<layout class="QFormLayout" name="formLayout_7">
<item row="0" column="1">
<widget class="QCheckBox" name="httpCB">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>Enabled</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Port</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="httpPortLE">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>65535</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Authentication</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="httpAuthCB">
<property name="text">
<string>Enabled</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Username</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="httpAuthUsernameTxt">
<property name="placeholderText">
<string notr="true">user</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="httpAuthPasswordTxt">
<property name="placeholderText">
<string notr="true">pass</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>

View File

@ -488,14 +488,16 @@ void RouteEditor::on_addRouteBtn_clicked()
Balancers[bTag] = QStringList(); Balancers[bTag] = QStringList();
// //
routesTable->insertRow(routesTable->rowCount()); routesTable->insertRow(routesTable->rowCount());
// WARNING There will be an additional check on the final configuration generation process. // There will be an additional check on the final configuration generation process.
auto enabledItem = new QTableWidgetItem(tr("Enabled")); auto enabledItem = new QTableWidgetItem(tr("Enabled"));
enabledItem->setCheckState(rule.QV2RAY_RULE_ENABLED ? Qt::Checked : Qt::Unchecked); enabledItem->setCheckState(rule.QV2RAY_RULE_ENABLED ? Qt::Checked : Qt::Unchecked);
//
routesTable->setItem(routesTable->rowCount() - 1, 0, enabledItem); routesTable->setItem(routesTable->rowCount() - 1, 0, enabledItem);
routesTable->setItem(routesTable->rowCount() - 1, 1, new QTableWidgetItem(rule.inboundTag.size() > 0 ? Stringify(rule.inboundTag) : tr("Any"))); routesTable->setItem(routesTable->rowCount() - 1, 1, new QTableWidgetItem(rule.inboundTag.size() > 0 ? Stringify(rule.inboundTag) : tr("Any")));
routesTable->setItem(routesTable->rowCount() - 1, 2, new QTableWidgetItem(QString::number(rule.domain.size() + rule.ip.size()) + " " + tr("Items"))); routesTable->setItem(routesTable->rowCount() - 1, 2, new QTableWidgetItem(QString::number(rule.domain.size() + rule.ip.size()) + " " + tr("Items")));
routesTable->setItem(routesTable->rowCount() - 1, 3, new QTableWidgetItem(QSTRING(rule.outboundTag))); routesTable->setItem(routesTable->rowCount() - 1, 3, new QTableWidgetItem(QSTRING(rule.outboundTag)));
rules.append(rule); rules.append(rule);
//
currentRuleIndex = routesTable->rowCount() - 1; currentRuleIndex = routesTable->rowCount() - 1;
routesTable->setCurrentCell(currentRuleIndex, 0); routesTable->setCurrentCell(currentRuleIndex, 0);
ShowRuleDetail(CurrentRule); ShowRuleDetail(CurrentRule);
@ -671,7 +673,7 @@ void RouteEditor::on_addDefaultBtn_clicked()
// Add default connection from GlobalConfig // Add default connection from GlobalConfig
auto conf = GetGlobalConfig(); auto conf = GetGlobalConfig();
// //
auto _in = conf.inBoundSettings; auto _in = conf.inboundConfig;
// //
auto _in_httpConf = GenerateHTTPIN(QList<AccountObject>() << _in.httpAccount); auto _in_httpConf = GenerateHTTPIN(QList<AccountObject>() << _in.httpAccount);
auto _in_socksConf = GenerateSocksIN((_in.socks_useAuth ? "password" : "noauth"), auto _in_socksConf = GenerateSocksIN((_in.socks_useAuth ? "password" : "noauth"),

File diff suppressed because it is too large Load Diff