mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 20:44:38 +03:00
feat: import as new group
This commit is contained in:
@@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user