feat: front proxy for group

This commit is contained in:
arm64v8a
2023-05-25 09:34:56 +09:00
parent fbd2a3354c
commit b5e0b16a73
11 changed files with 162 additions and 49 deletions

View File

@@ -93,27 +93,46 @@ namespace NekoGui {
}
QString BuildChain(int chainId, const std::shared_ptr<BuildConfigStatus> &status) {
// Make list
QList<std::shared_ptr<ProxyEntity>> ents;
auto ent = status->ent;
auto result = status->result;
auto group = profileManager->GetGroup(status->ent->gid);
if (group == nullptr) {
status->result->error = QString("This profile is not in any group, your data may be corrupted.");
return {};
}
auto resolveChain = [=](const std::shared_ptr<ProxyEntity> &ent) {
QList<std::shared_ptr<ProxyEntity>> resolved;
if (ent->type == "chain") {
auto list = ent->ChainBean()->list;
std::reverse(std::begin(list), std::end(list));
for (auto id: list) {
ents += profileManager->GetProfile(id);
if (ents.last() == nullptr) {
resolved += profileManager->GetProfile(id);
if (resolved.last() == nullptr) {
status->result->error = QString("chain missing ent: %1").arg(id);
return {};
break;
}
if (ents.last()->type == "chain") {
if (resolved.last()->type == "chain") {
status->result->error = QString("chain in chain is not allowed: %1").arg(id);
return {};
break;
}
}
} else {
ents += ent;
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 {};
}
ents += resolveChain(fEnt);
if (!status->result->error.isEmpty()) return {};
}
// BuildChain

View File

@@ -207,6 +207,7 @@ namespace NekoGui {
Group::Group() {
_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("name", &name, itemType::string));
_add(new configItem("order", &order, itemType::integerList));

View File

@@ -12,6 +12,7 @@ namespace NekoGui {
QString url = "";
QString info = "";
qint64 sub_last_update = 0;
int front_proxy_id = -1;
// list ui
bool manually_column_width = false;

View File

@@ -290,6 +290,14 @@ For NekoBox, this rewrites the underlying(localhost) DNS in VPN mode, normal mod
<source>Manually column width</source>
<translation>عرض ستون به صورت دستی</translation>
</message>
<message>
<source>Front Proxy</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>None</source>
<translation type="unfinished">هیچ یک</translation>
</message>
</context>
<context>
<name>DialogEditProfile</name>

View File

@@ -290,6 +290,14 @@ For NekoBox, this rewrites the underlying(localhost) DNS in VPN mode, normal mod
<source>Manually column width</source>
<translation></translation>
</message>
<message>
<source>Front Proxy</source>
<translation></translation>
</message>
<message>
<source>None</source>
<translation></translation>
</message>
</context>
<context>
<name>DialogEditProfile</name>

View File

@@ -2,12 +2,13 @@
#include "ui_dialog_edit_group.h"
#include "db/Database.hpp"
#include "ui/mainwindow_interface.h"
#include <QClipboard>
DialogEditGroup::DialogEditGroup(const std::shared_ptr<NekoGui::Group> &ent, QWidget *parent)
: QDialog(parent), ui(new Ui::DialogEditGroup) {
DialogEditGroup::DialogEditGroup(const std::shared_ptr<NekoGui::Group> &ent, QWidget *parent) : QDialog(parent), ui(new Ui::DialogEditGroup) {
ui->setupUi(this);
this->ent = ent;
connect(ui->type, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [=](int index) {
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->copy_links->setVisible(false);
ui->copy_links_nkr->setVisible(false);
if (ent->id >= 0) { // already a group
ui->type->setDisabled(true);
if (!ent->Profiles().isEmpty()) {
ui->copy_links->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, [=] {
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();
QDialog::accept();
});
CACHE.front_proxy = ent->front_proxy_id;
refresh_front_proxy();
connect(ui->copy_links, &QPushButton::clicked, this, [=] {
QStringList links;
@@ -66,3 +60,35 @@ DialogEditGroup::DialogEditGroup(const std::shared_ptr<NekoGui::Group> &ent, QWi
DialogEditGroup::~DialogEditGroup() {
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();
});
}

View File

@@ -19,4 +19,18 @@ public:
private:
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();
};

View File

@@ -84,6 +84,20 @@
</item>
</widget>
</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>
</widget>
</item>
@@ -177,5 +191,21 @@
</hint>
</hints>
</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>
</ui>

View File

@@ -596,9 +596,11 @@ inline bool dialog_is_using = false;
if (dialog_is_using) return; \
dialog_is_using = true; \
auto dialog = new a(this); \
dialog->exec(); \
connect(dialog, &QDialog::finished, this, [=] { \
dialog->deleteLater(); \
dialog_is_using = false;
dialog_is_using = false; \
}); \
dialog->show();
void MainWindow::on_menu_basic_settings_triggered() {
USE_DIALOG(DialogBasicSettings)

View File

@@ -45,6 +45,7 @@ GroupItem::GroupItem(QWidget *parent, const std::shared_ptr<NekoGui::Group> &ent
ui->setupUi(this);
this->setLayoutDirection(Qt::LeftToRight);
this->parentWindow = parent;
this->ent = ent;
this->item = item;
if (ent == nullptr) return;
@@ -102,15 +103,16 @@ void GroupItem::on_update_sub_clicked() {
}
void GroupItem::on_edit_clicked() {
auto dialog = new DialogEditGroup(ent, this);
int ret = dialog->exec();
dialog->deleteLater();
if (ret == QDialog::Accepted) {
auto dialog = new DialogEditGroup(ent, parentWindow);
connect(dialog, &QDialog::finished, this, [=] {
if (dialog->result() == QDialog::Accepted) {
ent->Save();
refresh_data();
MW_dialog_message(Dialog_DialogManageGroups, "refresh" + Int2String(ent->id));
}
dialog->deleteLater();
});
dialog->show();
}
void GroupItem::on_remove_clicked() {

View File

@@ -27,6 +27,8 @@ public:
private:
Ui::GroupItem *ui;
QWidget *parentWindow;
signals:
void edit_clicked();