From e3f325ef38a43f10769bbdd286b2ee6a8f81631f Mon Sep 17 00:00:00 2001 From: arm64v8a <48624112+arm64v8a@users.noreply.github.com> Date: Sat, 20 May 2023 14:25:51 +0900 Subject: [PATCH] feat: import as new group --- sub/GroupUpdater.cpp | 23 +++++++++++++++++++---- translations/fa_IR.ts | 12 ++++++++---- translations/zh_CN.ts | 12 ++++++++---- ui/mainwindow.cpp | 11 +++++++---- 4 files changed, 42 insertions(+), 16 deletions(-) diff --git a/sub/GroupUpdater.cpp b/sub/GroupUpdater.cpp index e36ea5e..9f77ccd 100644 --- a/sub/GroupUpdater.cpp +++ b/sub/GroupUpdater.cpp @@ -408,21 +408,36 @@ namespace NekoRay::sub { void GroupUpdater::AsyncUpdate(const QString &str, int _sub_gid, const std::function &finish) { auto content = str.trimmed(); bool asURL = false; + bool createNewGroup = false; if (_sub_gid < 0 && (content.startsWith("http://") || content.startsWith("https://"))) { - auto items = QStringList{QObject::tr("As Subscription"), QObject::tr("As link")}; + auto items = QStringList{ + QObject::tr("As Subscription (add to this group)"), + QObject::tr("As Subscription (create new group)"), + QObject::tr("As link"), + }; bool ok; auto a = QInputDialog::getItem(nullptr, QObject::tr("url detected"), QObject::tr("%1\nHow to update?").arg(content), items, 0, false, &ok); if (!ok) return; - if (items.indexOf(a) == 0) asURL = true; + if (items.indexOf(a) <= 1) asURL = true; + if (items.indexOf(a) == 1) createNewGroup = true; } runOnNewThread([=] { - Update(str, _sub_gid, asURL); - emit asyncUpdateCallback(_sub_gid); + auto gid = _sub_gid; + if (createNewGroup) { + auto group = ProfileManager::NewGroup(); + group->name = QUrl(str).host(); + group->url = str; + profileManager->AddGroup(group); + gid = group->id; + MW_dialog_message("SubUpdater", "NewGroup"); + } + Update(str, gid, asURL); + emit asyncUpdateCallback(gid); if (finish != nullptr) finish(); }); } diff --git a/translations/fa_IR.ts b/translations/fa_IR.ts index 699e1d9..47b9ee0 100644 --- a/translations/fa_IR.ts +++ b/translations/fa_IR.ts @@ -1517,10 +1517,6 @@ Release note: Update is ready, restart to install? به روز رسانی آماده است، برای نصب مجدد راه اندازی شود؟ - - As Subscription - - As link به عنوان لینک @@ -1602,6 +1598,14 @@ Direct: %2 Core exits too frequently, stop automatic restart this profile. + + As Subscription (create new group) + + + + As Subscription (add to this group) + + Qv2ray::ui::widgets::AutoCompleteTextEdit diff --git a/translations/zh_CN.ts b/translations/zh_CN.ts index d5759a3..31dd760 100644 --- a/translations/zh_CN.ts +++ b/translations/zh_CN.ts @@ -1490,10 +1490,6 @@ Split by line. QObject - - As Subscription - 作为订阅 - As link 作为链接 @@ -1608,6 +1604,14 @@ Release note: Core exits too frequently, stop automatic restart this profile. Core 退出太频繁,停止自动重启。 + + As Subscription (create new group) + 作为订阅(创建新组) + + + As Subscription (add to this group) + 作为订阅(添加到该组) + Qv2ray::ui::widgets::AutoCompleteTextEdit diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index cd07026..4e34fd2 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -565,10 +565,13 @@ void MainWindow::dialog_message_impl(const QString &sender, const QString &info) this->refresh_groups(); } } else if (sender == "SubUpdater") { - // 订阅完毕 - refresh_proxy_list(); - if (!info.contains("dingyue")) { - show_log_impl(tr("Imported %1 profile(s)").arg(NekoRay::dataStore->imported_count)); + if (info.startsWith("finish")) { + refresh_proxy_list(); + if (!info.contains("dingyue")) { + show_log_impl(tr("Imported %1 profile(s)").arg(NekoRay::dataStore->imported_count)); + } + } else if (info == "NewGroup") { + refresh_groups(); } } else if (sender == "ExternalProcess") { if (info == "Crashed") {