feat: import as new group

This commit is contained in:
arm64v8a
2023-05-20 14:25:51 +09:00
parent f9a8dc640a
commit e3f325ef38
4 changed files with 42 additions and 16 deletions

View File

@@ -408,21 +408,36 @@ namespace NekoRay::sub {
void GroupUpdater::AsyncUpdate(const QString &str, int _sub_gid, const std::function<void()> &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();
});
}

View File

@@ -1517,10 +1517,6 @@ Release note:
<source>Update is ready, restart to install?</source>
<translation>به روز رسانی آماده است، برای نصب مجدد راه اندازی شود؟</translation>
</message>
<message>
<source>As Subscription</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>As link</source>
<translation>به عنوان لینک</translation>
@@ -1602,6 +1598,14 @@ Direct: %2</source>
<source>Core exits too frequently, stop automatic restart this profile.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>As Subscription (create new group)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>As Subscription (add to this group)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Qv2ray::ui::widgets::AutoCompleteTextEdit</name>

View File

@@ -1490,10 +1490,6 @@ Split by line.</source>
</context>
<context>
<name>QObject</name>
<message>
<source>As Subscription</source>
<translation></translation>
</message>
<message>
<source>As link</source>
<translation></translation>
@@ -1608,6 +1604,14 @@ Release note:
<source>Core exits too frequently, stop automatic restart this profile.</source>
<translation>Core 退</translation>
</message>
<message>
<source>As Subscription (create new group)</source>
<translation></translation>
</message>
<message>
<source>As Subscription (add to this group)</source>
<translation></translation>
</message>
</context>
<context>
<name>Qv2ray::ui::widgets::AutoCompleteTextEdit</name>

View File

@@ -565,11 +565,14 @@ void MainWindow::dialog_message_impl(const QString &sender, const QString &info)
this->refresh_groups();
}
} else if (sender == "SubUpdater") {
// 订阅完毕
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") {
neko_stop();