From 686ebea22f478c2949403e96418a1bd9d1a53c8b Mon Sep 17 00:00:00 2001
From: arm64v8a <48624112+arm64v8a@users.noreply.github.com>
Date: Sun, 29 Jan 2023 15:11:52 +0900
Subject: [PATCH] speedtest current selected
---
translations/fa_IR.ts | 6 +++-
translations/zh_CN.ts | 8 +++--
ui/mainwindow.cpp | 76 +++++++++++++++++++++++++++++++++++-------
ui/mainwindow.h | 4 +++
ui/mainwindow.ui | 34 ++++++++++++++++---
ui/mainwindow_grpc.cpp | 25 +++++---------
6 files changed, 117 insertions(+), 36 deletions(-)
diff --git a/translations/fa_IR.ts b/translations/fa_IR.ts
index 0fe7623..04a18ad 100644
--- a/translations/fa_IR.ts
+++ b/translations/fa_IR.ts
@@ -1163,7 +1163,7 @@
کد QR یافت نشد
- Resolving current group domain to IP, if support.
+ Resolving domain to IP, if support.
@@ -1244,6 +1244,10 @@ End: %2
Stopping profile %1
متوقف کردن پروفایل %1
+
+ Current Select
+
+
ProxyItem
diff --git a/translations/zh_CN.ts b/translations/zh_CN.ts
index ca411c9..d3c918e 100644
--- a/translations/zh_CN.ts
+++ b/translations/zh_CN.ts
@@ -1202,8 +1202,8 @@ End: %2
将服务器域名解析为 IP
- Resolving current group domain to IP, if support.
- 将当前分组内服务器域名解析为 IP(如果支持)。
+ Resolving domain to IP, if support.
+ 将服务器域名解析为 IP(如果支持)。
Export %1 config
@@ -1255,6 +1255,10 @@ Split by line.
Edit
编辑
+
+ Current Select
+ 当前选中
+
ProxyItem
diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp
index 2e79b0a..ff5e05f 100644
--- a/ui/mainwindow.cpp
+++ b/ui/mainwindow.cpp
@@ -341,6 +341,42 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
connect(ui->menu_url_test, &QAction::triggered, this, [=]() { speedtest_current_group(1); });
connect(ui->menu_full_test, &QAction::triggered, this, [=]() { speedtest_current_group(2); });
//
+ auto set_selected_or_group = [=](int mode) {
+ // 0=group 1=select 2=unknown(menu is hide)
+ ui->menu_server->setProperty("selected_or_group", mode);
+ };
+ auto move_tests_to_menu = [=](bool menuCurrent_Select) {
+ return [=] {
+ if (menuCurrent_Select) {
+ ui->menuCurrent_Select->insertAction(ui->actionfake_4, ui->menu_tcp_ping);
+ ui->menuCurrent_Select->insertAction(ui->actionfake_4, ui->menu_url_test);
+ ui->menuCurrent_Select->insertAction(ui->actionfake_4, ui->menu_full_test);
+ ui->menuCurrent_Select->insertAction(ui->actionfake_4, ui->menu_clear_test_result);
+ ui->menuCurrent_Select->insertAction(ui->actionfake_4, ui->menu_resolve_domain);
+ } else {
+ ui->menuCurrent_Group->insertAction(ui->actionfake_5, ui->menu_tcp_ping);
+ ui->menuCurrent_Group->insertAction(ui->actionfake_5, ui->menu_url_test);
+ ui->menuCurrent_Group->insertAction(ui->actionfake_5, ui->menu_full_test);
+ ui->menuCurrent_Group->insertAction(ui->actionfake_5, ui->menu_clear_test_result);
+ ui->menuCurrent_Group->insertAction(ui->actionfake_5, ui->menu_resolve_domain);
+ }
+ ui->menu_full_test->setVisible(!IS_NEKO_BOX);
+ set_selected_or_group(menuCurrent_Select ? 1 : 0);
+ };
+ };
+ connect(ui->menuCurrent_Select, &QMenu::aboutToShow, this, move_tests_to_menu(true));
+ connect(ui->menuCurrent_Group, &QMenu::aboutToShow, this, move_tests_to_menu(false));
+ connect(ui->menu_server, &QMenu::aboutToHide, this, [=] {
+ auto timer = new QTimer(this);
+ timer->setInterval(100);
+ connect(timer, &QTimer::timeout, this, [=] {
+ set_selected_or_group(2);
+ timer->deleteLater();
+ });
+ timer->start();
+ });
+ set_selected_or_group(2);
+ //
connect(ui->menu_share_item, &QMenu::aboutToShow, this, [=] {
QString name;
auto selected = get_now_selected();
@@ -351,9 +387,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
ui->menu_export_config->setVisible(name == software_core_name);
ui->menu_export_config->setText(tr("Export %1 config").arg(name));
});
- connect(ui->menugroup, &QMenu::aboutToShow, this, [=] {
- ui->menu_full_test->setVisible(!IS_NEKO_BOX);
- });
refresh_status();
// Prepare core
@@ -1166,8 +1199,7 @@ void MainWindow::on_menu_scan_qr_triggered() {
}
void MainWindow::on_menu_clear_test_result_triggered() {
- for (const auto &profile: NekoRay::profileManager->profiles) {
- if (NekoRay::dataStore->current_group != profile->gid) continue;
+ for (const auto &profile: get_selected_or_group()) {
profile->latency = 0;
profile->full_test_report = "";
profile->Save();
@@ -1241,20 +1273,17 @@ void MainWindow::on_menu_remove_unavailable_triggered() {
}
void MainWindow::on_menu_resolve_domain_triggered() {
+ auto profiles = get_selected_or_group();
+ if (profiles.isEmpty()) return;
+
if (QMessageBox::question(this,
tr("Confirmation"),
- tr("Resolving current group domain to IP, if support.")) != QMessageBox::StandardButton::Yes) {
+ tr("Resolving domain to IP, if support.")) != QMessageBox::StandardButton::Yes) {
return;
}
if (mw_sub_updating) return;
mw_sub_updating = true;
- auto group = NekoRay::profileManager->CurrentGroup();
- if (group == nullptr) return;
-
- auto profiles = group->ProfilesWithOrder();
- NekoRay::dataStore->resolve_count = profiles.length();
-
for (const auto &profile: profiles) {
profile->bean->ResolveDomainToIP([=] {
profile->Save();
@@ -1280,6 +1309,29 @@ QMap> MainWindow::get_now_selected() {
return map;
}
+QList> MainWindow::get_now_selected_list() {
+ auto items = ui->proxyListTable->selectedItems();
+ QList> list;
+ for (auto item: items) {
+ auto id = item->data(114514).toInt();
+ auto ent = NekoRay::profileManager->GetProfile(id);
+ if (ent != nullptr && !list.contains(ent)) list += ent;
+ }
+ return list;
+}
+
+QList> MainWindow::get_selected_or_group() {
+ auto selected_or_group = ui->menu_server->property("selected_or_group").toInt();
+ QList> profiles;
+ if (selected_or_group > 0) {
+ profiles = get_now_selected_list();
+ if (profiles.isEmpty() && selected_or_group == 2) profiles = NekoRay::profileManager->CurrentGroup()->ProfilesWithOrder();
+ } else {
+ profiles = NekoRay::profileManager->CurrentGroup()->ProfilesWithOrder();
+ }
+ return profiles;
+}
+
void MainWindow::keyPressEvent(QKeyEvent *event) {
switch (event->key()) {
case Qt::Key_Escape:
diff --git a/ui/mainwindow.h b/ui/mainwindow.h
index 219abf5..1f3def5 100644
--- a/ui/mainwindow.h
+++ b/ui/mainwindow.h
@@ -153,6 +153,10 @@ private:
QMap> get_now_selected();
+ QList> get_now_selected_list();
+
+ QList> get_selected_or_group();
+
void dialog_message_impl(const QString &sender, const QString &info);
void refresh_proxy_list_impl(const int &id = -1, NekoRay::GroupSortAction groupSortAction = {});
diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui
index 6937fce..791ed15 100644
--- a/ui/mainwindow.ui
+++ b/ui/mainwindow.ui
@@ -523,21 +523,28 @@
-
diff --git a/ui/mainwindow_grpc.cpp b/ui/mainwindow_grpc.cpp
index 4b3ec14..fa18729 100644
--- a/ui/mainwindow_grpc.cpp
+++ b/ui/mainwindow_grpc.cpp
@@ -41,8 +41,11 @@ void MainWindow::setup_grpc() {
inline bool speedtesting = false;
void MainWindow::speedtest_current_group(int mode) {
-#ifndef NKR_NO_GRPC
if (speedtesting) return;
+ auto profiles = get_selected_or_group();
+ if (profiles.isEmpty()) return;
+ auto group = NekoRay::profileManager->CurrentGroup();
+ if (group->archive) return;
QStringList full_test_flags;
if (mode == libcore::FullTest) {
@@ -59,23 +62,13 @@ void MainWindow::speedtest_current_group(int mode) {
}
speedtesting = true;
-
- runOnNewThread([=]() {
- auto group = NekoRay::profileManager->CurrentGroup();
- if (group->archive) return;
- auto order = ui->proxyListTable->order; // copy
-
+#ifndef NKR_NO_GRPC
+ runOnNewThread([this, profiles, mode, full_test_flags]() {
QMutex lock_write;
QMutex lock_return;
- QList> profiles;
int threadN = mode == libcore::FullTest ? 1 : NekoRay::dataStore->test_concurrent;
int threadN_finished = 0;
-
- // 这个是按照显示的顺序
- for (auto id: order) {
- auto profile = NekoRay::profileManager->GetProfile(id);
- if (profile != nullptr) profiles += profile;
- }
+ auto profiles_test = profiles; // copy
// Threads
lock_return.lock();
@@ -84,13 +77,13 @@ void MainWindow::speedtest_current_group(int mode) {
forever {
//
lock_write.lock();
- if (profiles.isEmpty()) {
+ if (profiles_test.isEmpty()) {
threadN_finished++;
if (threadN == threadN_finished) lock_return.unlock();
lock_write.unlock();
return;
}
- auto profile = profiles.takeFirst();
+ auto profile = profiles_test.takeFirst();
lock_write.unlock();
//