diff --git a/makespec/BUILDVERSION b/makespec/BUILDVERSION index af5c7e6c..f0e04c0a 100644 --- a/makespec/BUILDVERSION +++ b/makespec/BUILDVERSION @@ -1 +1 @@ -5269 +5270 \ No newline at end of file diff --git a/src/base/models/QvSettingsObject.hpp b/src/base/models/QvSettingsObject.hpp index 47e60340..a05bfa78 100644 --- a/src/base/models/QvSettingsObject.hpp +++ b/src/base/models/QvSettingsObject.hpp @@ -102,14 +102,17 @@ namespace Qv2ray::base::config { QString theme; QString language; + QList recentConnections; bool quietMode; bool useDarkTheme; bool useDarkTrayIcon; int maximumLogLines; - Qv2rayUIConfig() : theme("Fusion"), language("en_US"), useDarkTheme(false), useDarkTrayIcon(true), maximumLogLines(500) + int maxJumpListCount; + Qv2rayUIConfig() + : theme("Fusion"), language("en_US"), useDarkTheme(false), useDarkTrayIcon(true), maximumLogLines(500), maxJumpListCount(20) { } - XTOSTRUCT(O(theme, language, quietMode, useDarkTheme, useDarkTrayIcon, maximumLogLines)) + XTOSTRUCT(O(theme, language, quietMode, useDarkTheme, useDarkTrayIcon, maximumLogLines, maxJumpListCount, recentConnections)) }; struct Qv2rayRouteConfig_Impl diff --git a/src/core/handler/ConfigHandler.cpp b/src/core/handler/ConfigHandler.cpp index 995243a6..8ea9d3f5 100644 --- a/src/core/handler/ConfigHandler.cpp +++ b/src/core/handler/ConfigHandler.cpp @@ -338,6 +338,29 @@ namespace Qv2ray::core::handlers CheckConnectionExistance(id); connections[id].lastConnected = system_clock::to_time_t(system_clock::now()); CONFIGROOT root = GetConnectionRoot(id); + auto &list = GlobalConfig.uiConfig.recentConnections; + + bool recentListChanged = false; + // If the 1st of the list is NOT the current connection. + if (!list.isEmpty() && list.first() != id.toString()) + { + list.removeAll(id.toString()); + // Make it the first. + list.push_front(id.toString()); + recentListChanged = true; + } + + while (list.count() > GlobalConfig.uiConfig.maxJumpListCount) + { + recentListChanged = true; + list.removeLast(); + } + + if (recentListChanged) + { + emit OnRecentConnectionsChanged(list); + } + return kernelHandler->StartConnection(id, root); } @@ -501,7 +524,7 @@ namespace Qv2ray::core::handlers // Anyway, we try our best to preserve the connection id. QMultiMap nameMap; QMultiMap, ConnectionId> typeMap; - for (const auto conn : groups[id].connections) + for (const auto &conn : groups[id].connections) { nameMap.insertMulti(GetDisplayName(conn), conn); auto [protocol, host, port] = GetConnectionInfo(conn); @@ -526,7 +549,7 @@ namespace Qv2ray::core::handlers // Things may go wrong when updating a subscription with ssd:// link for (auto _alias : conf.keys()) { - for (const auto config : conf.values(_alias)) + for (const auto &config : conf.values(_alias)) { if (!errMessage.isEmpty()) { diff --git a/src/core/handler/ConfigHandler.hpp b/src/core/handler/ConfigHandler.hpp index d4220c28..d3c3c284 100644 --- a/src/core/handler/ConfigHandler.hpp +++ b/src/core/handler/ConfigHandler.hpp @@ -103,6 +103,7 @@ namespace Qv2ray::core::handlers const tuple GetSubscriptionData(const GroupId &id) const; signals: + void OnRecentConnectionsChanged(const QList &connections); void OnKernelLogAvailable(const ConnectionId &id, const QString &log); void OnStatsAvailable(const ConnectionId &id, const quint64 upS, const quint64 downS, const quint64 upD, const quint64 downD); // diff --git a/src/ui/w_MainWindow.cpp b/src/ui/w_MainWindow.cpp index 579da158..2baea04c 100644 --- a/src/ui/w_MainWindow.cpp +++ b/src/ui/w_MainWindow.cpp @@ -113,6 +113,34 @@ void MainWindow::SortConnectionList(MW_ITEM_COL byCol, bool asending) on_locateBtn_clicked(); } +void MainWindow::ReloadRecentConnectionList(const QList &items) +{ + QList newActions; + for (const auto &item : items) + { + auto action = new QAction(tray_RecentConnectionsMenu); + action->setText(GetDisplayName(ConnectionId{ item })); + action->setData(item); + connect(ConnectionManager, &QvConfigHandler::OnConnectionRenamed, + [action](const ConnectionId &_t1, const QString &, const QString &_t3) { + if (_t1.toString() == action->data().toString()) + { + action->setText(_t3); + } + }); + connect(action, &QAction::triggered, [action]() { // + emit ConnectionManager->StartConnection(ConnectionId{ action->data().toString() }); + }); + newActions << action; + } + for (const auto action : tray_RecentConnectionsMenu->actions()) + { + tray_RecentConnectionsMenu->removeAction(action); + action->deleteLater(); + } + tray_RecentConnectionsMenu->addActions(newActions); +} + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { setupUi(this); @@ -159,6 +187,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) if (connectionNodes.contains(id)) connectionNodes.value(id)->setText(MW_ITEM_COL_PING, NumericString(avg)); // }); + connect(ConnectionManager, &QvConfigHandler::OnRecentConnectionsChanged, this, &MainWindow::ReloadRecentConnectionList); // connect(infoWidget, &ConnectionInfoWidget::OnEditRequested, this, &MainWindow::OnEditRequested); connect(infoWidget, &ConnectionInfoWidget::OnJsonEditRequested, this, &MainWindow::OnEditJsonRequested); @@ -292,6 +321,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) connectionListWidget->setCurrentItem(item); on_connectionListWidget_itemClicked(item, 0); } + ReloadRecentConnectionList(GlobalConfig.uiConfig.recentConnections); if (needShowWindow) this->show(); diff --git a/src/ui/w_MainWindow.hpp b/src/ui/w_MainWindow.hpp index a8b036ee..a80cb816 100644 --- a/src/ui/w_MainWindow.hpp +++ b/src/ui/w_MainWindow.hpp @@ -96,6 +96,8 @@ class MainWindow void OnGroupDeleted(const GroupId &id, const QList &connections); // void SortConnectionList(MW_ITEM_COL byCol, bool asending); + // + void ReloadRecentConnectionList(const QList &items); protected: void timerEvent(QTimerEvent *event) override; diff --git a/src/ui/w_PreferencesWindow.cpp b/src/ui/w_PreferencesWindow.cpp index 4bb4e185..ab0a2665 100644 --- a/src/ui/w_PreferencesWindow.cpp +++ b/src/ui/w_PreferencesWindow.cpp @@ -1249,3 +1249,8 @@ void PreferencesWindow::on_customProxySettingsGroupBox_clicked(bool checked) { CurrentConfig.networkConfig.useCustomProxy = checked; } + +void PreferencesWindow::on_jumpListCountSB_valueChanged(int arg1) +{ + CurrentConfig.uiConfig.maxJumpListCount = arg1; +} diff --git a/src/ui/w_PreferencesWindow.hpp b/src/ui/w_PreferencesWindow.hpp index e0f02285..68123e7e 100644 --- a/src/ui/w_PreferencesWindow.hpp +++ b/src/ui/w_PreferencesWindow.hpp @@ -192,6 +192,8 @@ class PreferencesWindow void on_customProxySettingsGroupBox_clicked(bool checked); + void on_jumpListCountSB_valueChanged(int arg1); + private: // RouteSettingsMatrixWidget *routeSettingsWidget; diff --git a/src/ui/w_PreferencesWindow.ui b/src/ui/w_PreferencesWindow.ui index cd2d3bd6..d8025d42 100644 --- a/src/ui/w_PreferencesWindow.ui +++ b/src/ui/w_PreferencesWindow.ui @@ -116,14 +116,14 @@ - + Maximum log lines - + @@ -148,6 +148,29 @@ + + + + Recent Jumplist + + + + + + + Connections + + + 3 + + + 30 + + + 10 + + +