mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-24 10:33:15 +08:00
feat: Improve rule-set selection in route section &&
fix: Fix Download assets timeout
This commit is contained in:
parent
205830fcc3
commit
26f3bc986e
@ -70,6 +70,7 @@ namespace Qv2ray::ui::widgets {
|
|||||||
c->setWidget(this);
|
c->setWidget(this);
|
||||||
c->setCompletionMode(QCompleter::PopupCompletion);
|
c->setCompletionMode(QCompleter::PopupCompletion);
|
||||||
c->setCaseSensitivity(Qt::CaseInsensitive);
|
c->setCaseSensitivity(Qt::CaseInsensitive);
|
||||||
|
c->setFilterMode(Qt::MatchContains);
|
||||||
QObject::connect(c, static_cast<void (QCompleter::*)(const QString &)>(&QCompleter::activated), this, &AutoCompleteTextEdit::insertCompletion);
|
QObject::connect(c, static_cast<void (QCompleter::*)(const QString &)>(&QCompleter::activated), this, &AutoCompleteTextEdit::insertCompletion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,10 +79,9 @@ namespace Qv2ray::ui::widgets {
|
|||||||
|
|
||||||
void AutoCompleteTextEdit::insertCompletion(const QString &completion) {
|
void AutoCompleteTextEdit::insertCompletion(const QString &completion) {
|
||||||
QTextCursor tc = textCursor();
|
QTextCursor tc = textCursor();
|
||||||
int extra = completion.length() - c->completionPrefix().length();
|
tc.select(QTextCursor::WordUnderCursor);
|
||||||
tc.movePosition(QTextCursor::Left);
|
tc.removeSelectedText();
|
||||||
tc.movePosition(QTextCursor::EndOfWord);
|
tc.insertText(completion);
|
||||||
tc.insertText(completion.right(extra).toLower());
|
|
||||||
setTextCursor(tc);
|
setTextCursor(tc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -77,7 +77,6 @@ namespace NekoGui_network {
|
|||||||
QString NetworkRequestHelper::DownloadGeoAsset(const QString &url, const QString &fileName) {
|
QString NetworkRequestHelper::DownloadGeoAsset(const QString &url, const QString &fileName) {
|
||||||
cpr::Session session;
|
cpr::Session session;
|
||||||
session.SetUrl(cpr::Url{url.toStdString()});
|
session.SetUrl(cpr::Url{url.toStdString()});
|
||||||
session.SetTimeout(3000);
|
|
||||||
if (NekoGui::dataStore->spmode_system_proxy) {
|
if (NekoGui::dataStore->spmode_system_proxy) {
|
||||||
session.SetProxies({{"http", "127.0.0.1:" + QString(Int2String(NekoGui::dataStore->inbound_socks_port)).toStdString()},
|
session.SetProxies({{"http", "127.0.0.1:" + QString(Int2String(NekoGui::dataStore->inbound_socks_port)).toStdString()},
|
||||||
{"https", "127.0.0.1:" + QString(Int2String(NekoGui::dataStore->inbound_socks_port)).toStdString()}});
|
{"https", "127.0.0.1:" + QString(Int2String(NekoGui::dataStore->inbound_socks_port)).toStdString()}});
|
||||||
|
|||||||
@ -67,14 +67,15 @@ RouteItem::RouteItem(QWidget *parent, const std::shared_ptr<NekoGui::RoutingChai
|
|||||||
auto geoIpList = NekoGui_rpc::defaultClient->GetGeoList(&ok, NekoGui_rpc::GeoRuleSetType::ip);
|
auto geoIpList = NekoGui_rpc::defaultClient->GetGeoList(&ok, NekoGui_rpc::GeoRuleSetType::ip);
|
||||||
auto geoSiteList = NekoGui_rpc::defaultClient->GetGeoList(&ok, NekoGui_rpc::GeoRuleSetType::site);
|
auto geoSiteList = NekoGui_rpc::defaultClient->GetGeoList(&ok, NekoGui_rpc::GeoRuleSetType::site);
|
||||||
geo_items << geoIpList << geoSiteList;
|
geo_items << geoIpList << geoSiteList;
|
||||||
helperModel = new QStringListModel(geo_items, this);
|
rule_set_editor = new AutoCompleteTextEdit("", geo_items, this);
|
||||||
ui->rule_set_helper->hide();
|
ui->rule_attr_data->layout()->addWidget(rule_set_editor);
|
||||||
ui->rule_set_helper->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
ui->rule_attr_data->adjustSize();
|
||||||
ui->rule_set_helper->setSelectionMode(QAbstractItemView::SingleSelection);
|
rule_set_editor->hide();
|
||||||
ui->rule_set_helper->setSelectionRectVisible(false);
|
connect(rule_set_editor, &QPlainTextEdit::textChanged, this, [=]{
|
||||||
ui->rule_set_helper->setModel(helperModel);
|
if (currentIndex == -1) return;
|
||||||
connect(ui->rule_set_helper, &QListView::clicked, this, [=](const QModelIndex& index){
|
auto currentVal = rule_set_editor->toPlainText().split('\n');
|
||||||
applyRuleHelperSelect(index);
|
chain->Rules[currentIndex]->set_field_value(ui->rule_attr->currentText(), currentVal);
|
||||||
|
updateRulePreview();
|
||||||
});
|
});
|
||||||
|
|
||||||
std::map<QString, int> valueMap;
|
std::map<QString, int> valueMap;
|
||||||
@ -180,11 +181,10 @@ RouteItem::RouteItem(QWidget *parent, const std::shared_ptr<NekoGui::RoutingChai
|
|||||||
updateRulePreview();
|
updateRulePreview();
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(ui->rule_attr_text, &QTextEdit::textChanged, this, [=] {
|
connect(ui->rule_attr_text, &QPlainTextEdit::textChanged, this, [=] {
|
||||||
if (currentIndex == -1) return;
|
if (currentIndex == -1) return;
|
||||||
auto currentVal = ui->rule_attr_text->toPlainText().split('\n');
|
auto currentVal = ui->rule_attr_text->toPlainText().split('\n');
|
||||||
chain->Rules[currentIndex]->set_field_value(ui->rule_attr->currentText(), currentVal);
|
chain->Rules[currentIndex]->set_field_value(ui->rule_attr->currentText(), currentVal);
|
||||||
if (ui->rule_attr->currentText() == "rule_set") updateHelperItems(currentVal.last());
|
|
||||||
updateRulePreview();
|
updateRulePreview();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -297,15 +297,13 @@ void RouteItem::updateRuleSection() {
|
|||||||
}
|
}
|
||||||
case NekoGui::text: {
|
case NekoGui::text: {
|
||||||
auto currentItems = ruleItem->get_current_value_string(currentAttr);
|
auto currentItems = ruleItem->get_current_value_string(currentAttr);
|
||||||
showTextEnterItem(currentItems);
|
showTextEnterItem(currentItems, currentAttr == "rule_set");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ui->rule_name->setText(ruleItem->name);
|
ui->rule_name->setText(ruleItem->name);
|
||||||
ui->rule_attr_box->setDisabled(chain->isViewOnly());
|
ui->rule_attr_box->setDisabled(chain->isViewOnly());
|
||||||
ui->rule_out->setCurrentText(get_outbound_name(ruleItem->outboundID));
|
ui->rule_out->setCurrentText(get_outbound_name(ruleItem->outboundID));
|
||||||
if (currentAttr == "rule_set") ui->rule_set_helper->show();
|
|
||||||
else ui->rule_set_helper->hide();
|
|
||||||
|
|
||||||
updateRulePreview();
|
updateRulePreview();
|
||||||
}
|
}
|
||||||
@ -324,6 +322,7 @@ void RouteItem::setDefaultRuleData(const QString& currentData) {
|
|||||||
|
|
||||||
void RouteItem::showSelectItem(const QStringList& items, const QString& currentItem) {
|
void RouteItem::showSelectItem(const QStringList& items, const QString& currentItem) {
|
||||||
ui->rule_attr_text->hide();
|
ui->rule_attr_text->hide();
|
||||||
|
rule_set_editor->hide();
|
||||||
ui->rule_attr_selector->clear();
|
ui->rule_attr_selector->clear();
|
||||||
ui->rule_attr_selector->show();
|
ui->rule_attr_selector->show();
|
||||||
ui->rule_attr_selector->addItems(items);
|
ui->rule_attr_selector->addItems(items);
|
||||||
@ -331,37 +330,22 @@ void RouteItem::showSelectItem(const QStringList& items, const QString& currentI
|
|||||||
adjustSize();
|
adjustSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RouteItem::showTextEnterItem(const QStringList& items) {
|
void RouteItem::showTextEnterItem(const QStringList& items, bool isRuleSet) {
|
||||||
ui->rule_attr_selector->hide();
|
ui->rule_attr_selector->hide();
|
||||||
ui->rule_attr_text->clear();
|
if (isRuleSet) {
|
||||||
ui->rule_attr_text->show();
|
ui->rule_attr_text->hide();
|
||||||
ui->rule_attr_text->setText(items.join('\n'));
|
rule_set_editor->clear();
|
||||||
|
rule_set_editor->show();
|
||||||
|
rule_set_editor->setPlainText(items.join('\n'));
|
||||||
|
} else {
|
||||||
|
rule_set_editor->hide();
|
||||||
|
ui->rule_attr_text->clear();
|
||||||
|
ui->rule_attr_text->show();
|
||||||
|
ui->rule_attr_text->setPlainText(items.join('\n'));
|
||||||
|
}
|
||||||
adjustSize();
|
adjustSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RouteItem::updateHelperItems(const QString& base) {
|
|
||||||
ui->rule_set_helper->clearSelection();
|
|
||||||
current_helper_items.clear();
|
|
||||||
for (const auto& item: geo_items) {
|
|
||||||
if (item.toLower().contains(base.toLower())) current_helper_items << item;
|
|
||||||
}
|
|
||||||
for (int i=0;i<current_helper_items.size();i++) {
|
|
||||||
for (int j=i+1;j<current_helper_items.size();j++) {
|
|
||||||
if (current_helper_items[i].length() > current_helper_items[j].length()) current_helper_items.swapItemsAt(i, j);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
helperModel->setStringList(current_helper_items);
|
|
||||||
ui->rule_set_helper->setModel(helperModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RouteItem::applyRuleHelperSelect(const QModelIndex& index) {
|
|
||||||
auto option = ui->rule_set_helper->model()->data(index, Qt::DisplayRole).toString();
|
|
||||||
auto currentText = ui->rule_attr_text->toPlainText();
|
|
||||||
auto parts = currentText.split('\n');
|
|
||||||
parts[parts.size() - 1] = option;
|
|
||||||
ui->rule_attr_text->setText(parts.join('\n'));
|
|
||||||
}
|
|
||||||
|
|
||||||
void RouteItem::on_new_route_item_clicked() {
|
void RouteItem::on_new_route_item_clicked() {
|
||||||
if (chain->isViewOnly()) return;
|
if (chain->isViewOnly()) return;
|
||||||
auto routeItem = std::make_shared<NekoGui::RouteRule>();
|
auto routeItem = std::make_shared<NekoGui::RouteRule>();
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
|
|
||||||
#include "db/RouteEntity.h"
|
#include "db/RouteEntity.h"
|
||||||
|
#include "3rdparty/qv2ray/v2/ui/QvAutoCompleteTextEdit.hpp"
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
@ -33,6 +34,8 @@ private:
|
|||||||
|
|
||||||
QStringList geo_items;
|
QStringList geo_items;
|
||||||
|
|
||||||
|
AutoCompleteTextEdit* rule_set_editor;
|
||||||
|
|
||||||
QStringList current_helper_items;
|
QStringList current_helper_items;
|
||||||
|
|
||||||
QStringListModel* helperModel;
|
QStringListModel* helperModel;
|
||||||
@ -45,7 +48,7 @@ private:
|
|||||||
|
|
||||||
void showSelectItem(const QStringList& items, const QString& currentItem);
|
void showSelectItem(const QStringList& items, const QString& currentItem);
|
||||||
|
|
||||||
void showTextEnterItem(const QStringList& items);
|
void showTextEnterItem(const QStringList& items, bool isRuleSet);
|
||||||
|
|
||||||
void setDefaultRuleData(const QString& currentData);
|
void setDefaultRuleData(const QString& currentData);
|
||||||
|
|
||||||
@ -54,11 +57,6 @@ private:
|
|||||||
void updateRulePreview();
|
void updateRulePreview();
|
||||||
|
|
||||||
void updateRouteItemsView();
|
void updateRouteItemsView();
|
||||||
|
|
||||||
void updateHelperItems(const QString& base);
|
|
||||||
|
|
||||||
void applyRuleHelperSelect(const QModelIndex& index);
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void accept() override;
|
void accept() override;
|
||||||
|
|
||||||
|
|||||||
@ -139,10 +139,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTextEdit" name="rule_attr_text"/>
|
<widget class="QPlainTextEdit" name="rule_attr_text"/>
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QListView" name="rule_set_helper"/>
|
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QComboBox" name="rule_attr_selector"/>
|
<widget class="QComboBox" name="rule_attr_selector"/>
|
||||||
@ -156,10 +153,10 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item alignment="Qt::AlignHCenter">
|
<item alignment="Qt::AlignmentFlag::AlignHCenter">
|
||||||
<widget class="QDialogButtonBox" name="buttonBox">
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
<property name="standardButtons">
|
<property name="standardButtons">
|
||||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user