mirror of
https://github.com/Qv2ray/Qv2ray.git
synced 2025-05-20 02:40:20 +08:00
change: some more refactors
This commit is contained in:
parent
8a8afdea61
commit
0d8f0839f2
@ -1 +1 @@
|
||||
4411
|
||||
4427
|
||||
|
@ -44,15 +44,15 @@ namespace Qv2ray::components::plugins
|
||||
|
||||
if (req == "START")
|
||||
{
|
||||
emit instance->Connect();
|
||||
emit instance->StartConnection();
|
||||
}
|
||||
else if (req == "STOP")
|
||||
{
|
||||
emit instance->DisConnect();
|
||||
emit instance->StopConnection();
|
||||
}
|
||||
else if (req == "RESTART")
|
||||
{
|
||||
emit instance->ReConnect();
|
||||
emit instance->RestartConnection();
|
||||
}
|
||||
|
||||
auto BarConfig = GlobalConfig.toolBarConfig;
|
||||
|
@ -132,4 +132,20 @@ namespace Qv2ray::core
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
const QString GetDisplayName(const ConnectionId &id, int limit)
|
||||
{
|
||||
return TruncateString(ConnectionManager->GetConnectionMetaObject(id).displayName, limit);
|
||||
}
|
||||
|
||||
const QString GetDisplayName(const GroupId &id, int limit)
|
||||
{
|
||||
return TruncateString(ConnectionManager->GetGroupMetaObject(id).displayName, limit);
|
||||
}
|
||||
|
||||
const GroupId GetConnectionGroupId(const ConnectionId &id)
|
||||
{
|
||||
return ConnectionManager->GetConnectionMetaObject(id).groupId;
|
||||
}
|
||||
|
||||
} // namespace Qv2ray::core
|
||||
|
@ -39,7 +39,13 @@ namespace Qv2ray::core
|
||||
bool IsComplexConfig(const ConnectionId &id);
|
||||
//
|
||||
const QString GetConnectionProtocolString(const ConnectionId &id);
|
||||
//
|
||||
const QString GetDisplayName(const ConnectionId &id, int limit = -1);
|
||||
const QString GetDisplayName(const GroupId &id, int limit = -1);
|
||||
//
|
||||
|
||||
const GroupId GetConnectionGroupId(const ConnectionId &id);
|
||||
//
|
||||
} // namespace Qv2ray::core
|
||||
|
||||
using namespace Qv2ray::core;
|
||||
|
@ -9,6 +9,7 @@ namespace Qv2ray::core::connection
|
||||
{
|
||||
namespace Serialization
|
||||
{
|
||||
const QString ConvertConfigToString(const QString &alias, const CONFIGROOT &server, bool isSip002);
|
||||
CONFIGROOT ConvertConfigFromString(const QString &link, QString *alias, QString *errMessage)
|
||||
{
|
||||
CONFIGROOT config;
|
||||
@ -31,8 +32,13 @@ namespace Qv2ray::core::connection
|
||||
|
||||
const QString ConvertConfigToString(const ConnectionId &id, bool isSip002)
|
||||
{
|
||||
auto alias = GetDisplayName(id);
|
||||
if (IsComplexConfig(id))
|
||||
{
|
||||
DEBUG(MODULE_CONNECTION, "Ignored an complex config: " + alias)
|
||||
return QV2RAY_SERIALIZATION_COMPLEX_CONFIG_PLACEHOLDER;
|
||||
}
|
||||
auto server = ConnectionManager->GetConnectionRoot(id);
|
||||
auto alias = ConnectionManager->GetDisplayName(id);
|
||||
return ConvertConfigToString(alias, server, isSip002);
|
||||
}
|
||||
|
||||
@ -65,16 +71,16 @@ namespace Qv2ray::core::connection
|
||||
|
||||
// From
|
||||
// https://github.com/2dust/v2rayN/wiki/%E5%88%86%E4%BA%AB%E9%93%BE%E6%8E%A5%E6%A0%BC%E5%BC%8F%E8%AF%B4%E6%98%8E(ver-2)
|
||||
QString ConvertConfigToVMessString(const StreamSettingsObject &transfer, const VMessServerObject &serverConfig, const QString &alias)
|
||||
const QString ConvertConfigToVMessString(const StreamSettingsObject &transfer, const VMessServerObject &server, const QString &alias)
|
||||
{
|
||||
QJsonObject vmessUriRoot;
|
||||
// Constant
|
||||
vmessUriRoot["v"] = 2;
|
||||
vmessUriRoot["ps"] = alias;
|
||||
vmessUriRoot["add"] = serverConfig.address;
|
||||
vmessUriRoot["port"] = serverConfig.port;
|
||||
vmessUriRoot["id"] = serverConfig.users.front().id;
|
||||
vmessUriRoot["aid"] = serverConfig.users.front().alterId;
|
||||
vmessUriRoot["add"] = server.address;
|
||||
vmessUriRoot["port"] = server.port;
|
||||
vmessUriRoot["id"] = server.users.front().id;
|
||||
vmessUriRoot["aid"] = server.users.front().alterId;
|
||||
vmessUriRoot["net"] = transfer.network;
|
||||
vmessUriRoot["tls"] = transfer.security;
|
||||
|
||||
@ -216,14 +222,14 @@ namespace Qv2ray::core::connection
|
||||
CONFIGROOT root;
|
||||
OUTBOUNDS outbounds;
|
||||
outbounds.append(
|
||||
GenerateOutboundEntry("shadowsocks", GenerateShadowSocksOUT(QList<ShadowSocksServerObject>() << server), QJsonObject()));
|
||||
GenerateOutboundEntry("shadowsocks", GenerateShadowSocksOUT(QList<ShadowSocksServerObject>{ server }), QJsonObject()));
|
||||
JADD(outbounds)
|
||||
*alias = alias->isEmpty() ? d_name : *alias + "_" + d_name;
|
||||
LOG(MODULE_CONNECTION, "Deduced alias: " + *alias)
|
||||
return root;
|
||||
}
|
||||
|
||||
QString ConvertConfigToSSString(const ShadowSocksServerObject &server, const QString &alias, bool isSip002)
|
||||
const QString ConvertConfigToSSString(const ShadowSocksServerObject &server, const QString &alias, bool isSip002)
|
||||
{
|
||||
auto myAlias = QUrl::toPercentEncoding(alias);
|
||||
|
||||
@ -333,13 +339,17 @@ namespace Qv2ray::core::connection
|
||||
// used as default.
|
||||
// [[val.size() <= 1]] is used when only the default value
|
||||
// exists.
|
||||
///
|
||||
// - It can be empty, if so, if the key is not in
|
||||
// the JSON, or the value is empty, it'll report an error.
|
||||
//
|
||||
// - Else if it contains one thing. if the key is not in
|
||||
// the JSON, or the value is empty, it'll use that one.
|
||||
//
|
||||
// - Else if it contains many things, when the key IS in
|
||||
// the JSON but not in those THINGS, it'll use the first
|
||||
// one in the THINGS
|
||||
//
|
||||
// - Else, it'll use the value found from the JSON object.
|
||||
//
|
||||
#define empty_arg
|
||||
@ -464,11 +474,10 @@ namespace Qv2ray::core::connection
|
||||
auto outbound = GenerateOutboundEntry("vmess", vConf, GetRootObject(streaming), QJsonObject(), "0.0.0.0", OUTBOUND_TAG_PROXY);
|
||||
//
|
||||
root["outbounds"] = QJsonArray() << outbound;
|
||||
// If previous alias is empty, just the PS is needed, else, append a
|
||||
// "_"
|
||||
// If previous alias is empty, just the PS is needed, else, append a "_"
|
||||
*alias = alias->trimmed().isEmpty() ? ps : *alias + "_" + ps;
|
||||
#undef default
|
||||
return root;
|
||||
#undef default
|
||||
}
|
||||
} // namespace Serialization
|
||||
} // namespace Qv2ray::core::connection
|
||||
|
@ -5,21 +5,21 @@ namespace Qv2ray::core::connection
|
||||
{
|
||||
namespace Serialization
|
||||
{
|
||||
const auto QV2RAY_SERIALIZATION_COMPLEX_CONFIG_PLACEHOLDER = QObject::tr("(Complex Connection Config)");
|
||||
// int VerifyVMessProtocolString(QString vmess);
|
||||
QString DecodeSubscriptionString(QByteArray arr);
|
||||
|
||||
// General
|
||||
CONFIGROOT ConvertConfigFromString(const QString &link, QString *alias, QString *errMessage);
|
||||
const QString ConvertConfigToString(const ConnectionId &id, bool isSip002 = false);
|
||||
const QString ConvertConfigToString(const QString &alias, const CONFIGROOT &server, bool isSip002);
|
||||
|
||||
// VMess URI Protocol
|
||||
CONFIGROOT ConvertConfigFromVMessString(const QString &vmess, QString *alias, QString *errMessage);
|
||||
QString ConvertConfigToVMessString(const StreamSettingsObject &transfer, const VMessServerObject &serverConfig, const QString &alias);
|
||||
const QString ConvertConfigToVMessString(const StreamSettingsObject &transfer, const VMessServerObject &server, const QString &alias);
|
||||
|
||||
// SS URI Protocol
|
||||
CONFIGROOT ConvertConfigFromSSString(const QString &ss, QString *alias, QString *errMessage);
|
||||
QString ConvertConfigToSSString(const ShadowSocksServerObject &server, const QString &alias, bool isSip002);
|
||||
const QString ConvertConfigToSSString(const ShadowSocksServerObject &server, const QString &alias, bool isSip002);
|
||||
} // namespace Serialization
|
||||
} // namespace Qv2ray::core::connection
|
||||
|
||||
|
@ -165,18 +165,6 @@ namespace Qv2ray::core::handlers
|
||||
return subsList;
|
||||
}
|
||||
|
||||
const QString QvConfigHandler::GetDisplayName(const ConnectionId &id, int limit) const
|
||||
{
|
||||
CheckConnectionExistance(id);
|
||||
return TruncateString(connections[id].displayName, limit);
|
||||
}
|
||||
|
||||
const QString QvConfigHandler::GetDisplayName(const GroupId &id, int limit) const
|
||||
{
|
||||
CheckGroupExistance(id);
|
||||
return TruncateString(groups[id].displayName, limit);
|
||||
}
|
||||
|
||||
// Obsolated, Please use:
|
||||
// ConnectionId QvConnectionHandler::GetConnectionIdByDisplayName(const QString &displayName, const GroupId &group) const
|
||||
//
|
||||
@ -218,17 +206,6 @@ namespace Qv2ray::core::handlers
|
||||
return NullGroupId;
|
||||
}
|
||||
|
||||
const GroupId QvConfigHandler::GetConnectionGroupId(const ConnectionId &id) const
|
||||
{
|
||||
CheckConnectionExistanceEx(id, NullGroupId);
|
||||
if (!connections.contains(id))
|
||||
{
|
||||
LOG(MODULE_CORE_HANDLER, "Cannot find id: " + id.toString());
|
||||
}
|
||||
|
||||
return connections[id].groupId;
|
||||
}
|
||||
|
||||
const optional<QString> QvConfigHandler::RenameConnection(const ConnectionId &id, const QString &newName)
|
||||
{
|
||||
CheckConnectionExistance(id);
|
||||
|
@ -68,11 +68,8 @@ namespace Qv2ray::core::handlers
|
||||
//
|
||||
const QList<GroupId> Subscriptions() const;
|
||||
//
|
||||
// Generic Get Options
|
||||
const QString GetDisplayName(const GroupId &id, int limit = -1) const;
|
||||
const QString GetDisplayName(const ConnectionId &id, int limit = -1) const;
|
||||
// Get Options
|
||||
const GroupId GetGroupIdByDisplayName(const QString &displayName) const;
|
||||
// const ConnectionId GetConnectionIdByDisplayName(const QString &displayName) const;
|
||||
const ConnectionId GetConnectionIdByDisplayName(const QString &displayName, const GroupId &group) const;
|
||||
//
|
||||
// Connectivity Operationss
|
||||
@ -89,7 +86,6 @@ namespace Qv2ray::core::handlers
|
||||
const ConnectionId CreateConnection(const QString &displayName, const GroupId &groupId, const CONFIGROOT &root);
|
||||
//
|
||||
// Get Conncetion Property
|
||||
const GroupId GetConnectionGroupId(const ConnectionId &id) const;
|
||||
const CONFIGROOT GetConnectionRoot(const ConnectionId &id) const;
|
||||
const CONFIGROOT GetConnectionRoot(const GroupId &group, const ConnectionId &id) const;
|
||||
//
|
||||
|
@ -514,8 +514,8 @@ int main(int argc, char *argv[])
|
||||
QGuiApplication::setFallbackSessionManagementEnabled(false);
|
||||
QObject::connect(&_qApp, &QGuiApplication::commitDataRequest, []() { LOG(MODULE_INIT, "Quit triggered by session manager.") });
|
||||
#ifndef Q_OS_WIN
|
||||
signal(SIGUSR1, [](int) { emit MainWindow::mwInstance->Connect(); });
|
||||
signal(SIGUSR2, [](int) { emit MainWindow::mwInstance->DisConnect(); });
|
||||
signal(SIGUSR1, [](int) { emit MainWindow::mwInstance->StartConnection(); });
|
||||
signal(SIGUSR2, [](int) { emit MainWindow::mwInstance->StopConnection(); });
|
||||
#endif
|
||||
auto rcode = _qApp.exec();
|
||||
delete ConnectionManager;
|
||||
|
@ -54,7 +54,7 @@ void MainWindow::MWAddConnectionItem_p(const ConnectionId &connection, const Gro
|
||||
auto groupItem = groupNodes[groupId];
|
||||
auto connectionItem = make_shared<QTreeWidgetItem>(QStringList{
|
||||
"", //
|
||||
ConnectionManager->GetDisplayName(connection), //
|
||||
GetDisplayName(connection), //
|
||||
NumericString(GetConnectionLatency(connection)), //
|
||||
"IMPORTTIME_NOT_SUPPORTED", //
|
||||
"LAST_CONNECTED_NOT_SUPPORTED", //
|
||||
@ -69,7 +69,7 @@ void MainWindow::MWAddConnectionItem_p(const ConnectionId &connection, const Gro
|
||||
|
||||
void MainWindow::MWAddGroupItem_p(const GroupId &groupId)
|
||||
{
|
||||
auto groupItem = make_shared<QTreeWidgetItem>(QStringList{ "", ConnectionManager->GetDisplayName(groupId) });
|
||||
auto groupItem = make_shared<QTreeWidgetItem>(QStringList{ "", GetDisplayName(groupId) });
|
||||
groupNodes[groupId] = groupItem;
|
||||
connectionListWidget->addTopLevelItem(groupItem.get());
|
||||
connectionListWidget->setItemWidget(groupItem.get(), 0, new ConnectionItemWidget(groupId, connectionListWidget));
|
||||
@ -77,7 +77,6 @@ void MainWindow::MWAddGroupItem_p(const GroupId &groupId)
|
||||
|
||||
void MainWindow::SortConnectionList(MW_ITEM_COL byCol, bool asending)
|
||||
{
|
||||
|
||||
connectionListWidget->sortByColumn(MW_ITEM_COL_DISPLAYNAME, Qt::AscendingOrder);
|
||||
for (auto i = 0; i < connectionListWidget->topLevelItemCount(); i++)
|
||||
{
|
||||
@ -85,7 +84,7 @@ void MainWindow::SortConnectionList(MW_ITEM_COL byCol, bool asending)
|
||||
}
|
||||
}
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) //, vinstance(), hTray(this), tcpingHelper(3, this)
|
||||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
MainWindow::mwInstance = this;
|
||||
@ -138,25 +137,16 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) //, vinstance(), h
|
||||
//
|
||||
// Setup System tray icons and menus
|
||||
hTray.setToolTip(TRAY_TOOLTIP_PREFIX);
|
||||
//
|
||||
// Basic actions
|
||||
action_Tray_ShowHide = new QAction(this->windowIcon(), tr("Hide"), this);
|
||||
action_Tray_ShowPreferencesWindow = new QAction(tr("Preferences"), this);
|
||||
action_Tray_Quit = new QAction(tr("Quit"), this);
|
||||
action_Tray_Start = new QAction(tr("Connect"), this);
|
||||
action_Tray_Reconnect = new QAction(tr("Reconnect"), this);
|
||||
action_Tray_Stop = new QAction(tr("Disconnect"), this);
|
||||
//
|
||||
action_Tray_SetSystemProxy = new QAction(tr("Enable System Proxy"), this);
|
||||
action_Tray_ClearSystemProxy = new QAction(tr("Disable System Proxy"), this);
|
||||
//
|
||||
action_Tray_Start->setEnabled(true);
|
||||
action_Tray_Stop->setEnabled(false);
|
||||
action_Tray_Reconnect->setEnabled(false);
|
||||
action_Tray_Restart->setEnabled(false);
|
||||
//
|
||||
tray_SystemProxyMenu->addAction(action_Tray_SetSystemProxy);
|
||||
tray_SystemProxyMenu->addAction(action_Tray_ClearSystemProxy);
|
||||
tray_SystemProxyMenu->setTitle(tr("System Proxy"));
|
||||
tray_SystemProxyMenu->setEnabled(false);
|
||||
tray_SystemProxyMenu->addAction(action_Tray_SetSystemProxy);
|
||||
tray_SystemProxyMenu->addAction(action_Tray_ClearSystemProxy);
|
||||
//
|
||||
tray_RootMenu->addAction(action_Tray_ShowHide);
|
||||
tray_RootMenu->addSeparator();
|
||||
@ -165,7 +155,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) //, vinstance(), h
|
||||
tray_RootMenu->addSeparator();
|
||||
tray_RootMenu->addAction(action_Tray_Start);
|
||||
tray_RootMenu->addAction(action_Tray_Stop);
|
||||
tray_RootMenu->addAction(action_Tray_Reconnect);
|
||||
tray_RootMenu->addAction(action_Tray_Restart);
|
||||
tray_RootMenu->addSeparator();
|
||||
tray_RootMenu->addAction(action_Tray_Quit);
|
||||
//
|
||||
@ -174,7 +164,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) //, vinstance(), h
|
||||
//
|
||||
connect(action_Tray_Start, &QAction::triggered, [&] { ConnectionManager->StartConnection(lastConnectedId); });
|
||||
connect(action_Tray_Stop, &QAction::triggered, ConnectionManager, &QvConfigHandler::StopConnection);
|
||||
connect(action_Tray_Reconnect, &QAction::triggered, ConnectionManager, &QvConfigHandler::RestartConnection);
|
||||
connect(action_Tray_Restart, &QAction::triggered, ConnectionManager, &QvConfigHandler::RestartConnection);
|
||||
//
|
||||
connect(action_Tray_Quit, &QAction::triggered, this, &MainWindow::on_actionExit_triggered);
|
||||
connect(action_Tray_SetSystemProxy, &QAction::triggered, this, &MainWindow::MWSetSystemProxy);
|
||||
@ -196,9 +186,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) //, vinstance(), h
|
||||
connect(action_RCM_DuplicateThese, &QAction::triggered, this, &MainWindow::on_action_RCM_DuplicateThese_triggered);
|
||||
//
|
||||
// Globally invokable signals.
|
||||
connect(this, &MainWindow::Connect, [&] { ConnectionManager->StartConnection(lastConnectedId); });
|
||||
connect(this, &MainWindow::DisConnect, ConnectionManager, &QvConfigHandler::StopConnection);
|
||||
connect(this, &MainWindow::ReConnect, ConnectionManager, &QvConfigHandler::RestartConnection);
|
||||
connect(this, &MainWindow::StartConnection, ConnectionManager, &QvConfigHandler::RestartConnection);
|
||||
connect(this, &MainWindow::StopConnection, ConnectionManager, &QvConfigHandler::StopConnection);
|
||||
connect(this, &MainWindow::RestartConnection, ConnectionManager, &QvConfigHandler::RestartConnection);
|
||||
//
|
||||
hTray.setContextMenu(tray_RootMenu);
|
||||
hTray.show();
|
||||
@ -210,13 +200,13 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) //, vinstance(), h
|
||||
connectionListMenu->addAction(action_RCM_DeleteThese);
|
||||
connectionListMenu->addAction(action_RCM_ConvToComplex);
|
||||
//
|
||||
sortMenu = new QMenu(this);
|
||||
sortAction_SortByName_Asc = new QAction(tr("By connection name, A-Z"));
|
||||
sortAction_SortByName_Dsc = new QAction(tr("By connection name, Z-A"));
|
||||
sortAction_SortByData_Asc = new QAction(tr("By data, Ascending"));
|
||||
sortAction_SortByData_Dsc = new QAction(tr("By data, Descending"));
|
||||
sortAction_SortByLatency_Asc = new QAction(tr("By latency, Ascending"));
|
||||
sortAction_SortByLatency_Dsc = new QAction(tr("By latency, Descending"));
|
||||
QMenu *sortMenu = new QMenu(tr("Sort connection list."), this);
|
||||
QAction *sortAction_SortByName_Asc = new QAction(tr("By connection name, A-Z"));
|
||||
QAction *sortAction_SortByName_Dsc = new QAction(tr("By connection name, Z-A"));
|
||||
QAction *sortAction_SortByLatency_Asc = new QAction(tr("By data, Ascending"));
|
||||
QAction *sortAction_SortByLatency_Dsc = new QAction(tr("By data, Descending"));
|
||||
QAction *sortAction_SortByData_Asc = new QAction(tr("By latency, Ascending"));
|
||||
QAction *sortAction_SortByData_Dsc = new QAction(tr("By latency, Descending"));
|
||||
//
|
||||
connect(sortAction_SortByName_Asc, &QAction::triggered, [&] { SortConnectionList(MW_ITEM_COL_DISPLAYNAME, true); });
|
||||
connect(sortAction_SortByName_Dsc, &QAction::triggered, [&] { SortConnectionList(MW_ITEM_COL_DISPLAYNAME, false); });
|
||||
@ -411,12 +401,12 @@ void MainWindow::ToggleVisibility()
|
||||
QThread::msleep(20);
|
||||
SetWindowPos(HWND(this->winId()), HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
|
||||
#endif
|
||||
tray_RootMenu->actions()[0]->setText(tr("Hide"));
|
||||
action_Tray_ShowHide->setText(tr("Hide"));
|
||||
}
|
||||
else
|
||||
{
|
||||
this->hide();
|
||||
tray_RootMenu->actions()[0]->setText(tr("Show"));
|
||||
action_Tray_ShowHide->setText(tr("Show"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -549,11 +539,11 @@ void MainWindow::OnDisconnected(const ConnectionId &id)
|
||||
Q_UNUSED(id)
|
||||
action_Tray_Start->setEnabled(true);
|
||||
action_Tray_Stop->setEnabled(false);
|
||||
action_Tray_Reconnect->setEnabled(false);
|
||||
action_Tray_Restart->setEnabled(false);
|
||||
tray_SystemProxyMenu->setEnabled(false);
|
||||
lastConnectedId = id;
|
||||
locateBtn->setEnabled(false);
|
||||
this->hTray.showMessage("Qv2ray", tr("Disconnected from: ") + ConnectionManager->GetDisplayName(id), this->windowIcon());
|
||||
this->hTray.showMessage("Qv2ray", tr("Disconnected from: ") + GetDisplayName(id), this->windowIcon());
|
||||
hTray.setToolTip(TRAY_TOOLTIP_PREFIX NEWLINE);
|
||||
connetionStatusLabel->setText(tr("Not Connected"));
|
||||
if (GlobalConfig.inboundConfig.setSystemProxy)
|
||||
@ -573,12 +563,12 @@ void MainWindow::OnConnected(const ConnectionId &id)
|
||||
Q_UNUSED(id)
|
||||
action_Tray_Start->setEnabled(false);
|
||||
action_Tray_Stop->setEnabled(true);
|
||||
action_Tray_Reconnect->setEnabled(true);
|
||||
action_Tray_Restart->setEnabled(true);
|
||||
tray_SystemProxyMenu->setEnabled(true);
|
||||
lastConnectedId = id;
|
||||
locateBtn->setEnabled(true);
|
||||
on_clearlogButton_clicked();
|
||||
auto name = ConnectionManager->GetDisplayName(id);
|
||||
auto name = GetDisplayName(id);
|
||||
this->hTray.showMessage("Qv2ray", tr("Connected: ") + name, this->windowIcon());
|
||||
hTray.setToolTip(TRAY_TOOLTIP_PREFIX NEWLINE + tr("Connected: ") + name);
|
||||
connetionStatusLabel->setText(tr("Connected: ") + name);
|
||||
@ -727,8 +717,8 @@ void MainWindow::OnStatsAvailable(const ConnectionId &id, const quint64 upS, con
|
||||
netspeedLabel->setText(totalSpeedUp + NEWLINE + totalSpeedDown);
|
||||
dataamountLabel->setText(totalDataUp + NEWLINE + totalDataDown);
|
||||
//
|
||||
hTray.setToolTip(TRAY_TOOLTIP_PREFIX NEWLINE + tr("Connected: ") + //
|
||||
ConnectionManager->GetDisplayName(id) + NEWLINE "Up: " + totalSpeedUp + " Down: " + totalSpeedDown);
|
||||
hTray.setToolTip(TRAY_TOOLTIP_PREFIX NEWLINE + tr("Connected: ") + GetDisplayName(id) + //
|
||||
NEWLINE "Up: " + totalSpeedUp + " Down: " + totalSpeedDown);
|
||||
//
|
||||
// Set data accordingly
|
||||
connectionNodes[id]->setText(MW_ITEM_COL_DATAUSAGE, NumericString(GetConnectionTotalData(id)));
|
||||
@ -808,7 +798,7 @@ void MainWindow::OnJsonEditRequested(const ConnectionId &id)
|
||||
void MainWindow::OnConnectionCreated(const ConnectionId &id, const QString &displayName)
|
||||
{
|
||||
Q_UNUSED(displayName)
|
||||
MWAddConnectionItem_p(id, ConnectionManager->GetConnectionGroupId(id));
|
||||
MWAddConnectionItem_p(id, GetConnectionGroupId(id));
|
||||
}
|
||||
void MainWindow::OnConnectionDeleted(const ConnectionId &id, const GroupId &groupId)
|
||||
{
|
||||
@ -869,21 +859,16 @@ void MainWindow::on_action_RCM_DuplicateThese_triggered()
|
||||
|
||||
LOG(MODULE_UI, "Selected " + QSTRN(connlist.count()) + " items")
|
||||
|
||||
if (connlist.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (connlist.count() > 1 &&
|
||||
QvMessageBoxAsk(this, tr("Duplicating Connection(s)"), tr("Are you sure to duplicate these connection(s)?")) != QMessageBox::Yes)
|
||||
if (connlist.count() > 1 && QvMessageBoxAsk(this, tr("Duplicating Connection(s)"), //
|
||||
tr("Are you sure to duplicate these connection(s)?")) != QMessageBox::Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto conn : connlist)
|
||||
{
|
||||
ConnectionManager->CreateConnection(ConnectionManager->GetDisplayName(conn) + tr(" (Copy)"), //
|
||||
ConnectionManager->GetConnectionGroupId(conn), //
|
||||
ConnectionManager->CreateConnection(GetDisplayName(conn) + tr(" (Copy)"), //
|
||||
GetConnectionGroupId(conn), //
|
||||
ConnectionManager->GetConnectionRoot(conn));
|
||||
}
|
||||
}
|
||||
|
@ -35,9 +35,9 @@ class MainWindow
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow() override;
|
||||
signals:
|
||||
void Connect() const;
|
||||
void DisConnect() const;
|
||||
void ReConnect() const;
|
||||
void StartConnection() const;
|
||||
void StopConnection() const;
|
||||
void RestartConnection() const;
|
||||
public slots:
|
||||
QvMessageBusSlotDecl;
|
||||
private slots:
|
||||
@ -113,29 +113,19 @@ class MainWindow
|
||||
ConnectionInfoWidget *infoWidget;
|
||||
//
|
||||
// Actions in the system tray menu
|
||||
//
|
||||
QMenu *tray_RootMenu = new QMenu(this);
|
||||
QAction *action_Tray_ShowHide;
|
||||
QAction *action_Tray_ShowPreferencesWindow;
|
||||
QAction *action_Tray_Quit;
|
||||
QAction *action_Tray_ShowHide = new QAction(this->windowIcon(), tr("Hide"), this);
|
||||
QAction *action_Tray_ShowPreferencesWindow = new QAction(tr("Preferences"), this);
|
||||
QAction *action_Tray_Quit = new QAction(tr("Quit"), this);
|
||||
// --> Connectivities
|
||||
QAction *action_Tray_Start;
|
||||
QAction *action_Tray_Reconnect;
|
||||
QAction *action_Tray_Stop;
|
||||
QAction *action_Tray_Start = new QAction(tr("Connect"), this);
|
||||
QAction *action_Tray_Restart = new QAction(tr("Reconnect"), this);
|
||||
QAction *action_Tray_Stop = new QAction(tr("Disconnect"), this);
|
||||
// --> System proxy settings
|
||||
QMenu *tray_SystemProxyMenu = new QMenu(this);
|
||||
QAction *action_Tray_SetSystemProxy;
|
||||
QAction *action_Tray_ClearSystemProxy;
|
||||
QAction *action_Tray_SetSystemProxy = new QAction(tr("Enable System Proxy"), this);
|
||||
QAction *action_Tray_ClearSystemProxy = new QAction(tr("Disable System Proxy"), this);
|
||||
//
|
||||
QMenu *sortMenu;
|
||||
QAction *sortAction_SortByName_Asc;
|
||||
QAction *sortAction_SortByName_Dsc;
|
||||
QAction *sortAction_SortByLatency_Asc;
|
||||
QAction *sortAction_SortByLatency_Dsc;
|
||||
QAction *sortAction_SortByData_Asc;
|
||||
QAction *sortAction_SortByData_Dsc;
|
||||
//
|
||||
// Extra Headers For w_MainWindow_extra.cpp Handling V2ray Connectivities.
|
||||
ConnectionId lastConnectedId;
|
||||
void MWSetSystemProxy();
|
||||
void CheckSubscriptionsUpdate();
|
||||
|
@ -164,21 +164,21 @@ PreferencesWindow::PreferencesWindow(QWidget *parent) : QDialog(parent), Current
|
||||
//
|
||||
// Empty for global config.
|
||||
auto autoStartConnId = ConnectionId(CurrentConfig.autoStartId);
|
||||
auto autoStartGroupId = ConnectionManager->GetConnectionGroupId(autoStartConnId);
|
||||
auto autoStartGroupId = GetConnectionGroupId(autoStartConnId);
|
||||
|
||||
for (auto group : ConnectionManager->AllGroups())
|
||||
{
|
||||
autoStartSubsCombo->addItem(ConnectionManager->GetDisplayName(group));
|
||||
autoStartSubsCombo->addItem(GetDisplayName(group));
|
||||
}
|
||||
|
||||
autoStartSubsCombo->setCurrentText(ConnectionManager->GetDisplayName(autoStartGroupId));
|
||||
autoStartSubsCombo->setCurrentText(GetDisplayName(autoStartGroupId));
|
||||
|
||||
for (auto conn : ConnectionManager->Connections(autoStartGroupId))
|
||||
{
|
||||
autoStartConnCombo->addItem(ConnectionManager->GetDisplayName(conn));
|
||||
autoStartConnCombo->addItem(GetDisplayName(conn));
|
||||
}
|
||||
|
||||
autoStartConnCombo->setCurrentText(ConnectionManager->GetDisplayName(autoStartConnId));
|
||||
autoStartConnCombo->setCurrentText(GetDisplayName(autoStartConnId));
|
||||
|
||||
// FP Settings
|
||||
if (CurrentConfig.connectionConfig.forwardProxyConfig.type.trimmed().isEmpty())
|
||||
@ -1029,7 +1029,7 @@ void PreferencesWindow::on_autoStartSubsCombo_currentIndexChanged(const QString
|
||||
|
||||
for (auto id : list)
|
||||
{
|
||||
autoStartConnCombo->addItem(ConnectionManager->GetDisplayName(id));
|
||||
autoStartConnCombo->addItem(GetDisplayName(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ SubscribeEditor::SubscribeEditor(QWidget *parent) : QDialog(parent)
|
||||
|
||||
for (auto subs : ConnectionManager->Subscriptions())
|
||||
{
|
||||
subscriptionList->addTopLevelItem(new QTreeWidgetItem(QStringList{ ConnectionManager->GetDisplayName(subs), subs.toString() }));
|
||||
subscriptionList->addTopLevelItem(new QTreeWidgetItem(QStringList{ GetDisplayName(subs), subs.toString() }));
|
||||
}
|
||||
if (subscriptionList->topLevelItemCount() > 0)
|
||||
{
|
||||
@ -31,7 +31,7 @@ QvMessageBusSlotImpl(SubscribeEditor)
|
||||
|
||||
tuple<QString, CONFIGROOT> SubscribeEditor::GetSelectedConfig()
|
||||
{
|
||||
return { ConnectionManager->GetDisplayName(currentConnectionId), ConnectionManager->GetConnectionRoot(currentConnectionId) };
|
||||
return { GetDisplayName(currentConnectionId), ConnectionManager->GetConnectionRoot(currentConnectionId) };
|
||||
}
|
||||
|
||||
SubscribeEditor::~SubscribeEditor()
|
||||
@ -101,7 +101,7 @@ void SubscribeEditor::on_subscriptionList_itemClicked(QTreeWidgetItem *item, int
|
||||
groupBox_2->setEnabled(true);
|
||||
currentSubId = GroupId(item->text(1));
|
||||
//
|
||||
subNameTxt->setText(ConnectionManager->GetDisplayName(currentSubId));
|
||||
subNameTxt->setText(GetDisplayName(currentSubId));
|
||||
auto const [addr, lastUpdated, updateInterval] = ConnectionManager->GetSubscriptionData(currentSubId);
|
||||
subAddrTxt->setText(addr);
|
||||
lastUpdatedLabel->setText(timeToString(lastUpdated));
|
||||
@ -111,7 +111,7 @@ void SubscribeEditor::on_subscriptionList_itemClicked(QTreeWidgetItem *item, int
|
||||
|
||||
for (auto conn : ConnectionManager->Connections(currentSubId))
|
||||
{
|
||||
connectionsList->addItem(ConnectionManager->GetDisplayName(conn)); //
|
||||
connectionsList->addItem(GetDisplayName(conn)); //
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ void ConnectionInfoWidget::ShowDetails(const tuple<GroupId, ConnectionId> &_iden
|
||||
shareLinkTxt->setText(shareLink);
|
||||
protocolLabel->setText(GetConnectionProtocolString(connectionId));
|
||||
//
|
||||
groupLabel->setText(ConnectionManager->GetDisplayName(groupId, 175));
|
||||
groupLabel->setText(GetDisplayName(groupId, 175));
|
||||
auto [protocol, host, port] = GetConnectionInfo(connectionId);
|
||||
Q_UNUSED(protocol)
|
||||
addressLabel->setText(host);
|
||||
@ -65,12 +65,19 @@ void ConnectionInfoWidget::ShowDetails(const tuple<GroupId, ConnectionId> &_iden
|
||||
else
|
||||
{
|
||||
connectBtn->setIcon(QICON_R("connect.png"));
|
||||
groupNameLabel->setText(ConnectionManager->GetDisplayName(groupId));
|
||||
groupNameLabel->setText(GetDisplayName(groupId));
|
||||
QStringList shareLinks;
|
||||
for (auto connection : ConnectionManager->Connections(groupId))
|
||||
{
|
||||
shareLinks << ConvertConfigToString(connection, false);
|
||||
}
|
||||
//
|
||||
auto complexCount = shareLinks.removeAll(QV2RAY_SERIALIZATION_COMPLEX_CONFIG_PLACEHOLDER);
|
||||
if (complexCount > 0)
|
||||
{
|
||||
shareLinks << tr("(Ignored %1 complex config(s))").arg(complexCount);
|
||||
}
|
||||
//
|
||||
groupShareTxt->setPlainText(shareLinks.join(NEWLINE));
|
||||
groupSubsLinkLabel->setText(ConnectionManager->IsSubscription(groupId) ? get<0>(ConnectionManager->GetSubscriptionData(groupId)) :
|
||||
tr("Not a subscription"));
|
||||
|
@ -17,8 +17,8 @@ ConnectionItemWidget::ConnectionItemWidget(QWidget *parent) : QWidget(parent), c
|
||||
ConnectionItemWidget::ConnectionItemWidget(const ConnectionId &id, QWidget *parent) : ConnectionItemWidget(parent)
|
||||
{
|
||||
connectionId = id;
|
||||
groupId = ConnectionManager->GetConnectionGroupId(id);
|
||||
originalItemName = ConnectionManager->GetDisplayName(id);
|
||||
groupId = GetConnectionGroupId(id);
|
||||
originalItemName = GetDisplayName(id);
|
||||
itemType = NODE_ITEM;
|
||||
auto latency = GetConnectionLatency(id);
|
||||
|
||||
@ -55,7 +55,7 @@ ConnectionItemWidget::ConnectionItemWidget(const GroupId &id, QWidget *parent) :
|
||||
//
|
||||
groupId = id;
|
||||
itemType = GROUP_HEADER_ITEM;
|
||||
originalItemName = ConnectionManager->GetDisplayName(id);
|
||||
originalItemName = GetDisplayName(id);
|
||||
RecalculateConnectionsCount();
|
||||
//
|
||||
auto font = connNameLabel->font();
|
||||
|
@ -27,7 +27,7 @@ class ConnectionItemWidget
|
||||
inline bool NameMatched(const QString &arg)
|
||||
{
|
||||
auto searchString = arg.toLower();
|
||||
auto headerMatched = ConnectionManager->GetDisplayName(groupId).toLower().contains(arg);
|
||||
auto headerMatched = GetDisplayName(groupId).toLower().contains(arg);
|
||||
|
||||
if (itemType != NODE_ITEM)
|
||||
{
|
||||
@ -35,7 +35,7 @@ class ConnectionItemWidget
|
||||
}
|
||||
else
|
||||
{
|
||||
return headerMatched || ConnectionManager->GetDisplayName(connectionId).toLower().contains(searchString);
|
||||
return headerMatched || GetDisplayName(connectionId).toLower().contains(searchString);
|
||||
}
|
||||
}
|
||||
inline const tuple<GroupId, ConnectionId> Identifier() const
|
||||
|
Loading…
Reference in New Issue
Block a user