feat: Improve rule-set selection in route section &&

fix: Fix Download assets timeout
This commit is contained in:
unknown 2024-08-01 17:07:42 +03:30
parent 205830fcc3
commit 26f3bc986e
No known key found for this signature in database
GPG Key ID: C2CA486E4F771093
5 changed files with 35 additions and 57 deletions

View File

@ -70,6 +70,7 @@ namespace Qv2ray::ui::widgets {
c->setWidget(this);
c->setCompletionMode(QCompleter::PopupCompletion);
c->setCaseSensitivity(Qt::CaseInsensitive);
c->setFilterMode(Qt::MatchContains);
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) {
QTextCursor tc = textCursor();
int extra = completion.length() - c->completionPrefix().length();
tc.movePosition(QTextCursor::Left);
tc.movePosition(QTextCursor::EndOfWord);
tc.insertText(completion.right(extra).toLower());
tc.select(QTextCursor::WordUnderCursor);
tc.removeSelectedText();
tc.insertText(completion);
setTextCursor(tc);
}

View File

@ -77,7 +77,6 @@ namespace NekoGui_network {
QString NetworkRequestHelper::DownloadGeoAsset(const QString &url, const QString &fileName) {
cpr::Session session;
session.SetUrl(cpr::Url{url.toStdString()});
session.SetTimeout(3000);
if (NekoGui::dataStore->spmode_system_proxy) {
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()}});

View File

@ -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 geoSiteList = NekoGui_rpc::defaultClient->GetGeoList(&ok, NekoGui_rpc::GeoRuleSetType::site);
geo_items << geoIpList << geoSiteList;
helperModel = new QStringListModel(geo_items, this);
ui->rule_set_helper->hide();
ui->rule_set_helper->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->rule_set_helper->setSelectionMode(QAbstractItemView::SingleSelection);
ui->rule_set_helper->setSelectionRectVisible(false);
ui->rule_set_helper->setModel(helperModel);
connect(ui->rule_set_helper, &QListView::clicked, this, [=](const QModelIndex& index){
applyRuleHelperSelect(index);
rule_set_editor = new AutoCompleteTextEdit("", geo_items, this);
ui->rule_attr_data->layout()->addWidget(rule_set_editor);
ui->rule_attr_data->adjustSize();
rule_set_editor->hide();
connect(rule_set_editor, &QPlainTextEdit::textChanged, this, [=]{
if (currentIndex == -1) return;
auto currentVal = rule_set_editor->toPlainText().split('\n');
chain->Rules[currentIndex]->set_field_value(ui->rule_attr->currentText(), currentVal);
updateRulePreview();
});
std::map<QString, int> valueMap;
@ -180,11 +181,10 @@ RouteItem::RouteItem(QWidget *parent, const std::shared_ptr<NekoGui::RoutingChai
updateRulePreview();
});
connect(ui->rule_attr_text, &QTextEdit::textChanged, this, [=] {
connect(ui->rule_attr_text, &QPlainTextEdit::textChanged, this, [=] {
if (currentIndex == -1) return;
auto currentVal = ui->rule_attr_text->toPlainText().split('\n');
chain->Rules[currentIndex]->set_field_value(ui->rule_attr->currentText(), currentVal);
if (ui->rule_attr->currentText() == "rule_set") updateHelperItems(currentVal.last());
updateRulePreview();
});
@ -297,15 +297,13 @@ void RouteItem::updateRuleSection() {
}
case NekoGui::text: {
auto currentItems = ruleItem->get_current_value_string(currentAttr);
showTextEnterItem(currentItems);
showTextEnterItem(currentItems, currentAttr == "rule_set");
break;
}
}
ui->rule_name->setText(ruleItem->name);
ui->rule_attr_box->setDisabled(chain->isViewOnly());
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();
}
@ -324,6 +322,7 @@ void RouteItem::setDefaultRuleData(const QString& currentData) {
void RouteItem::showSelectItem(const QStringList& items, const QString& currentItem) {
ui->rule_attr_text->hide();
rule_set_editor->hide();
ui->rule_attr_selector->clear();
ui->rule_attr_selector->show();
ui->rule_attr_selector->addItems(items);
@ -331,37 +330,22 @@ void RouteItem::showSelectItem(const QStringList& items, const QString& currentI
adjustSize();
}
void RouteItem::showTextEnterItem(const QStringList& items) {
void RouteItem::showTextEnterItem(const QStringList& items, bool isRuleSet) {
ui->rule_attr_selector->hide();
ui->rule_attr_text->clear();
ui->rule_attr_text->show();
ui->rule_attr_text->setText(items.join('\n'));
if (isRuleSet) {
ui->rule_attr_text->hide();
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();
}
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() {
if (chain->isViewOnly()) return;
auto routeItem = std::make_shared<NekoGui::RouteRule>();

View File

@ -7,6 +7,7 @@
#include <QShortcut>
#include "db/RouteEntity.h"
#include "3rdparty/qv2ray/v2/ui/QvAutoCompleteTextEdit.hpp"
QT_BEGIN_NAMESPACE
namespace Ui {
@ -33,6 +34,8 @@ private:
QStringList geo_items;
AutoCompleteTextEdit* rule_set_editor;
QStringList current_helper_items;
QStringListModel* helperModel;
@ -45,7 +48,7 @@ private:
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);
@ -54,11 +57,6 @@ private:
void updateRulePreview();
void updateRouteItemsView();
void updateHelperItems(const QString& base);
void applyRuleHelperSelect(const QModelIndex& index);
private slots:
void accept() override;

View File

@ -139,10 +139,7 @@
</widget>
</item>
<item>
<widget class="QTextEdit" name="rule_attr_text"/>
</item>
<item>
<widget class="QListView" name="rule_set_helper"/>
<widget class="QPlainTextEdit" name="rule_attr_text"/>
</item>
<item>
<widget class="QComboBox" name="rule_attr_selector"/>
@ -156,10 +153,10 @@
</layout>
</widget>
</item>
<item alignment="Qt::AlignHCenter">
<item alignment="Qt::AlignmentFlag::AlignHCenter">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
</property>
</widget>
</item>