diff --git a/include/ui/setting/dialog_manage_routes.h b/include/ui/setting/dialog_manage_routes.h index c537410..b9fa936 100644 --- a/include/ui/setting/dialog_manage_routes.h +++ b/include/ui/setting/dialog_manage_routes.h @@ -31,7 +31,9 @@ private: QList> chainList; - int currentRouteProfileID = -1; + std::shared_ptr currentRoute; + + int tooltipID = 0; void set_dns_hijack_enability(bool enable) const; @@ -47,6 +49,8 @@ public slots: void on_new_route_clicked(); + void on_export_route_clicked(); + void on_clone_route_clicked(); void on_edit_route_clicked(); diff --git a/include/ui/setting/dialog_manage_routes.ui b/include/ui/setting/dialog_manage_routes.ui index 08462c0..7e54d84 100644 --- a/include/ui/setting/dialog_manage_routes.ui +++ b/include/ui/setting/dialog_manage_routes.ui @@ -545,6 +545,13 @@ For more information, see the document "Configuration/DNS". + + + + Export + + + diff --git a/src/dataStore/Database.cpp b/src/dataStore/Database.cpp index ec2bf9c..688a040 100644 --- a/src/dataStore/Database.cpp +++ b/src/dataStore/Database.cpp @@ -477,9 +477,9 @@ namespace NekoGui { for (const auto &item: newChain) { if (!AddRouteChain(item)) { routes[item->id] = item; + routesIdOrder << item->id; item->Save(); } - routesIdOrder << item->id; } auto currFiles = filterIntJsonFile("route_profiles"); for (const auto &item: currFiles) { // clean up removed route profiles diff --git a/src/ui/setting/dialog_manage_routes.cpp b/src/ui/setting/dialog_manage_routes.cpp index 216a688..5f058a1 100644 --- a/src/ui/setting/dialog_manage_routes.cpp +++ b/src/ui/setting/dialog_manage_routes.cpp @@ -1,4 +1,7 @@ #include "include/ui/setting/dialog_manage_routes.h" + +#include + #include "include/dataStore/Database.hpp" #include "3rdparty/qv2ray/v2/ui/widgets/editors/w_JsonEditor.hpp" @@ -8,6 +11,8 @@ #include #include #include +#include +#include #include void DialogManageRoutes::reloadProfileItems() { @@ -25,14 +30,14 @@ void DialogManageRoutes::reloadProfileItems() { for (const auto &item: chainList) { ui->route_prof->addItem(item->name); ui->route_profiles->addItem(item->name); - if (item->id == currentRouteProfileID) { + if (item == currentRoute) { ui->route_prof->setCurrentIndex(i); selectedChainGone=false; } i++; } if (selectedChainGone) { - currentRouteProfileID=chainList[0]->id; + currentRoute=chainList[0]; ui->route_prof->setCurrentIndex(0); } blocker.unblock(); @@ -65,8 +70,8 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent) : QDialog(parent), ui(ne NekoGui::profileManager->AddRouteChain(defaultChain); chainList.append(defaultChain); } - currentRouteProfileID = NekoGui::dataStore->routing->current_route_id; - if (currentRouteProfileID < 0) currentRouteProfileID = chainList[0]->id; + currentRoute = NekoGui::profileManager->GetRouteChain(NekoGui::dataStore->routing->current_route_id); + if (currentRoute == nullptr) currentRoute = chainList[0]; QStringList qsValue = {""}; QString dnsHelpDocumentUrl; @@ -173,7 +178,7 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent) : QDialog(parent), ui(ne } void DialogManageRoutes::updateCurrentRouteProfile(int idx) { - currentRouteProfileID = chainList[idx]->id; + currentRoute = chainList[idx]; } DialogManageRoutes::~DialogManageRoutes() { @@ -203,7 +208,7 @@ void DialogManageRoutes::accept() { NekoGui::dataStore->fake_dns = ui->enable_fakeip->isChecked(); NekoGui::profileManager->UpdateRouteChains(chainList); - NekoGui::dataStore->routing->current_route_id = currentRouteProfileID; + NekoGui::dataStore->routing->current_route_id = currentRoute->id; NekoGui::dataStore->routing->def_outbound = ui->default_out->currentText(); NekoGui::dataStore->enable_dns_server = ui->dnshijack_enable->isChecked(); @@ -241,6 +246,27 @@ void DialogManageRoutes::on_new_route_clicked() { }); } +void DialogManageRoutes::on_export_route_clicked() +{ + auto idx = ui->route_profiles->currentRow(); + if (idx < 0) return; + + QJsonArray arr = chainList[idx]->get_route_rules(true, {}); + QStringList res; + for (int i = 0; i < arr.count(); i++) + { + res.append(QJsonObject2QString(arr[i].toObject(), false)); + } + QApplication::clipboard()->setText("[" + res.join(",") + "]"); + + QToolTip::showText(QCursor::pos(), "Copied!", this); + int r = ++tooltipID; + QTimer::singleShot(1500, [=] { + if (tooltipID != r) return; + QToolTip::hideText(); + }); +} + void DialogManageRoutes::on_clone_route_clicked() { auto idx = ui->route_profiles->currentRow(); if (idx < 0) return; @@ -282,8 +308,8 @@ void DialogManageRoutes::on_delete_route_clicked() { return; } chainList.removeAt(idx); - if (profileToDel->id == currentRouteProfileID) { - currentRouteProfileID = chainList[0]->id; + if (profileToDel == currentRoute) { + currentRoute = chainList[0]; } reloadProfileItems(); } \ No newline at end of file