mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 20:44:38 +03:00
feat: front proxy for group
This commit is contained in:
@@ -93,27 +93,46 @@ namespace NekoGui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString BuildChain(int chainId, const std::shared_ptr<BuildConfigStatus> &status) {
|
QString BuildChain(int chainId, const std::shared_ptr<BuildConfigStatus> &status) {
|
||||||
// Make list
|
auto group = profileManager->GetGroup(status->ent->gid);
|
||||||
QList<std::shared_ptr<ProxyEntity>> ents;
|
if (group == nullptr) {
|
||||||
auto ent = status->ent;
|
status->result->error = QString("This profile is not in any group, your data may be corrupted.");
|
||||||
auto result = status->result;
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
if (ent->type == "chain") {
|
auto resolveChain = [=](const std::shared_ptr<ProxyEntity> &ent) {
|
||||||
auto list = ent->ChainBean()->list;
|
QList<std::shared_ptr<ProxyEntity>> resolved;
|
||||||
std::reverse(std::begin(list), std::end(list));
|
if (ent->type == "chain") {
|
||||||
for (auto id: list) {
|
auto list = ent->ChainBean()->list;
|
||||||
ents += profileManager->GetProfile(id);
|
std::reverse(std::begin(list), std::end(list));
|
||||||
if (ents.last() == nullptr) {
|
for (auto id: list) {
|
||||||
status->result->error = QString("chain missing ent: %1").arg(id);
|
resolved += profileManager->GetProfile(id);
|
||||||
return {};
|
if (resolved.last() == nullptr) {
|
||||||
}
|
status->result->error = QString("chain missing ent: %1").arg(id);
|
||||||
if (ents.last()->type == "chain") {
|
break;
|
||||||
status->result->error = QString("chain in chain is not allowed: %1").arg(id);
|
}
|
||||||
return {};
|
if (resolved.last()->type == "chain") {
|
||||||
|
status->result->error = QString("chain in chain is not allowed: %1").arg(id);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
resolved += ent;
|
||||||
|
};
|
||||||
|
return resolved;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Make list
|
||||||
|
auto ents = resolveChain(status->ent);
|
||||||
|
if (!status->result->error.isEmpty()) return {};
|
||||||
|
|
||||||
|
if (group->front_proxy_id >= 0) {
|
||||||
|
auto fEnt = profileManager->GetProfile(group->front_proxy_id);
|
||||||
|
if (fEnt == nullptr) {
|
||||||
|
status->result->error = QString("front proxy ent not found.");
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
} else {
|
ents += resolveChain(fEnt);
|
||||||
ents += ent;
|
if (!status->result->error.isEmpty()) return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// BuildChain
|
// BuildChain
|
||||||
|
|||||||
@@ -207,6 +207,7 @@ namespace NekoGui {
|
|||||||
|
|
||||||
Group::Group() {
|
Group::Group() {
|
||||||
_add(new configItem("id", &id, itemType::integer));
|
_add(new configItem("id", &id, itemType::integer));
|
||||||
|
_add(new configItem("front_proxy_id", &front_proxy_id, itemType::integer));
|
||||||
_add(new configItem("archive", &archive, itemType::boolean));
|
_add(new configItem("archive", &archive, itemType::boolean));
|
||||||
_add(new configItem("name", &name, itemType::string));
|
_add(new configItem("name", &name, itemType::string));
|
||||||
_add(new configItem("order", &order, itemType::integerList));
|
_add(new configItem("order", &order, itemType::integerList));
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ namespace NekoGui {
|
|||||||
QString url = "";
|
QString url = "";
|
||||||
QString info = "";
|
QString info = "";
|
||||||
qint64 sub_last_update = 0;
|
qint64 sub_last_update = 0;
|
||||||
|
int front_proxy_id = -1;
|
||||||
|
|
||||||
// list ui
|
// list ui
|
||||||
bool manually_column_width = false;
|
bool manually_column_width = false;
|
||||||
|
|||||||
@@ -290,6 +290,14 @@ For NekoBox, this rewrites the underlying(localhost) DNS in VPN mode, normal mod
|
|||||||
<source>Manually column width</source>
|
<source>Manually column width</source>
|
||||||
<translation>عرض ستون به صورت دستی</translation>
|
<translation>عرض ستون به صورت دستی</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Front Proxy</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>None</source>
|
||||||
|
<translation type="unfinished">هیچ یک</translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>DialogEditProfile</name>
|
<name>DialogEditProfile</name>
|
||||||
|
|||||||
@@ -290,6 +290,14 @@ For NekoBox, this rewrites the underlying(localhost) DNS in VPN mode, normal mod
|
|||||||
<source>Manually column width</source>
|
<source>Manually column width</source>
|
||||||
<translation>手动调节列宽</translation>
|
<translation>手动调节列宽</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Front Proxy</source>
|
||||||
|
<translation>前置代理</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>None</source>
|
||||||
|
<translation>无</translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>DialogEditProfile</name>
|
<name>DialogEditProfile</name>
|
||||||
|
|||||||
@@ -2,12 +2,13 @@
|
|||||||
#include "ui_dialog_edit_group.h"
|
#include "ui_dialog_edit_group.h"
|
||||||
|
|
||||||
#include "db/Database.hpp"
|
#include "db/Database.hpp"
|
||||||
|
#include "ui/mainwindow_interface.h"
|
||||||
|
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
|
|
||||||
DialogEditGroup::DialogEditGroup(const std::shared_ptr<NekoGui::Group> &ent, QWidget *parent)
|
DialogEditGroup::DialogEditGroup(const std::shared_ptr<NekoGui::Group> &ent, QWidget *parent) : QDialog(parent), ui(new Ui::DialogEditGroup) {
|
||||||
: QDialog(parent), ui(new Ui::DialogEditGroup) {
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
this->ent = ent;
|
||||||
|
|
||||||
connect(ui->type, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [=](int index) {
|
connect(ui->type, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [=](int index) {
|
||||||
ui->cat_sub->setHidden(index == 0);
|
ui->cat_sub->setHidden(index == 0);
|
||||||
@@ -21,27 +22,20 @@ DialogEditGroup::DialogEditGroup(const std::shared_ptr<NekoGui::Group> &ent, QWi
|
|||||||
ui->manually_column_width->setChecked(ent->manually_column_width);
|
ui->manually_column_width->setChecked(ent->manually_column_width);
|
||||||
ui->copy_links->setVisible(false);
|
ui->copy_links->setVisible(false);
|
||||||
ui->copy_links_nkr->setVisible(false);
|
ui->copy_links_nkr->setVisible(false);
|
||||||
|
|
||||||
if (ent->id >= 0) { // already a group
|
if (ent->id >= 0) { // already a group
|
||||||
ui->type->setDisabled(true);
|
ui->type->setDisabled(true);
|
||||||
if (!ent->Profiles().isEmpty()) {
|
if (!ent->Profiles().isEmpty()) {
|
||||||
ui->copy_links->setVisible(true);
|
ui->copy_links->setVisible(true);
|
||||||
ui->copy_links_nkr->setVisible(true);
|
ui->copy_links_nkr->setVisible(true);
|
||||||
}
|
}
|
||||||
|
} else { // new group
|
||||||
|
ui->front_proxy->hide();
|
||||||
|
ui->front_proxy_l->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, [=] {
|
CACHE.front_proxy = ent->front_proxy_id;
|
||||||
if (ent->id >= 0) { // already a group
|
refresh_front_proxy();
|
||||||
if (!ent->url.isEmpty() && ui->url->text().isEmpty()) {
|
|
||||||
MessageBoxWarning(tr("Warning"), tr("Please input URL"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ent->name = ui->name->text();
|
|
||||||
ent->url = ui->url->text();
|
|
||||||
ent->archive = ui->archive->isChecked();
|
|
||||||
ent->manually_column_width = ui->manually_column_width->isChecked();
|
|
||||||
QDialog::accept();
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(ui->copy_links, &QPushButton::clicked, this, [=] {
|
connect(ui->copy_links, &QPushButton::clicked, this, [=] {
|
||||||
QStringList links;
|
QStringList links;
|
||||||
@@ -66,3 +60,35 @@ DialogEditGroup::DialogEditGroup(const std::shared_ptr<NekoGui::Group> &ent, QWi
|
|||||||
DialogEditGroup::~DialogEditGroup() {
|
DialogEditGroup::~DialogEditGroup() {
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DialogEditGroup::accept() {
|
||||||
|
if (ent->id >= 0) { // already a group
|
||||||
|
if (!ent->url.isEmpty() && ui->url->text().isEmpty()) {
|
||||||
|
MessageBoxWarning(tr("Warning"), tr("Please input URL"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ent->name = ui->name->text();
|
||||||
|
ent->url = ui->url->text();
|
||||||
|
ent->archive = ui->archive->isChecked();
|
||||||
|
ent->manually_column_width = ui->manually_column_width->isChecked();
|
||||||
|
ent->front_proxy_id = CACHE.front_proxy;
|
||||||
|
QDialog::accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DialogEditGroup::refresh_front_proxy() {
|
||||||
|
auto fEnt = NekoGui::profileManager->GetProfile(CACHE.front_proxy);
|
||||||
|
ui->front_proxy->setText(fEnt == nullptr ? tr("None") : fEnt->bean->DisplayTypeAndName());
|
||||||
|
}
|
||||||
|
|
||||||
|
void DialogEditGroup::on_front_proxy_clicked() {
|
||||||
|
auto parent = dynamic_cast<QWidget *>(this->parent());
|
||||||
|
parent->hide();
|
||||||
|
this->hide();
|
||||||
|
GetMainWindow()->start_select_mode(this, [=](int id) {
|
||||||
|
CACHE.front_proxy = id;
|
||||||
|
refresh_front_proxy();
|
||||||
|
parent->show();
|
||||||
|
show();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,4 +19,18 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::DialogEditGroup *ui;
|
Ui::DialogEditGroup *ui;
|
||||||
|
|
||||||
|
std::shared_ptr<NekoGui::Group> ent;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
int front_proxy;
|
||||||
|
} CACHE;
|
||||||
|
|
||||||
|
void refresh_front_proxy();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
|
||||||
|
void accept() override;
|
||||||
|
|
||||||
|
void on_front_proxy_clicked();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -84,6 +84,20 @@
|
|||||||
</item>
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QPushButton" name="front_proxy">
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true"/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="front_proxy_l">
|
||||||
|
<property name="text">
|
||||||
|
<string>Front Proxy</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@@ -177,5 +191,21 @@
|
|||||||
</hint>
|
</hint>
|
||||||
</hints>
|
</hints>
|
||||||
</connection>
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>DialogEditGroup</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>199</x>
|
||||||
|
<y>291</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>199</x>
|
||||||
|
<y>157</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
</connections>
|
</connections>
|
||||||
</ui>
|
</ui>
|
||||||
|
|||||||
@@ -592,13 +592,15 @@ void MainWindow::dialog_message_impl(const QString &sender, const QString &info)
|
|||||||
|
|
||||||
inline bool dialog_is_using = false;
|
inline bool dialog_is_using = false;
|
||||||
|
|
||||||
#define USE_DIALOG(a) \
|
#define USE_DIALOG(a) \
|
||||||
if (dialog_is_using) return; \
|
if (dialog_is_using) return; \
|
||||||
dialog_is_using = true; \
|
dialog_is_using = true; \
|
||||||
auto dialog = new a(this); \
|
auto dialog = new a(this); \
|
||||||
dialog->exec(); \
|
connect(dialog, &QDialog::finished, this, [=] { \
|
||||||
dialog->deleteLater(); \
|
dialog->deleteLater(); \
|
||||||
dialog_is_using = false;
|
dialog_is_using = false; \
|
||||||
|
}); \
|
||||||
|
dialog->show();
|
||||||
|
|
||||||
void MainWindow::on_menu_basic_settings_triggered() {
|
void MainWindow::on_menu_basic_settings_triggered() {
|
||||||
USE_DIALOG(DialogBasicSettings)
|
USE_DIALOG(DialogBasicSettings)
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ GroupItem::GroupItem(QWidget *parent, const std::shared_ptr<NekoGui::Group> &ent
|
|||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
this->setLayoutDirection(Qt::LeftToRight);
|
this->setLayoutDirection(Qt::LeftToRight);
|
||||||
|
|
||||||
|
this->parentWindow = parent;
|
||||||
this->ent = ent;
|
this->ent = ent;
|
||||||
this->item = item;
|
this->item = item;
|
||||||
if (ent == nullptr) return;
|
if (ent == nullptr) return;
|
||||||
@@ -102,15 +103,16 @@ void GroupItem::on_update_sub_clicked() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GroupItem::on_edit_clicked() {
|
void GroupItem::on_edit_clicked() {
|
||||||
auto dialog = new DialogEditGroup(ent, this);
|
auto dialog = new DialogEditGroup(ent, parentWindow);
|
||||||
int ret = dialog->exec();
|
connect(dialog, &QDialog::finished, this, [=] {
|
||||||
dialog->deleteLater();
|
if (dialog->result() == QDialog::Accepted) {
|
||||||
|
ent->Save();
|
||||||
if (ret == QDialog::Accepted) {
|
refresh_data();
|
||||||
ent->Save();
|
MW_dialog_message(Dialog_DialogManageGroups, "refresh" + Int2String(ent->id));
|
||||||
refresh_data();
|
}
|
||||||
MW_dialog_message(Dialog_DialogManageGroups, "refresh" + Int2String(ent->id));
|
dialog->deleteLater();
|
||||||
}
|
});
|
||||||
|
dialog->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GroupItem::on_remove_clicked() {
|
void GroupItem::on_remove_clicked() {
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
Ui::GroupItem *ui;
|
Ui::GroupItem *ui;
|
||||||
|
|
||||||
|
QWidget *parentWindow;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
void edit_clicked();
|
void edit_clicked();
|
||||||
|
|||||||
Reference in New Issue
Block a user