From 5e1d0cdce45614b98c2484de2380ad93b657243a Mon Sep 17 00:00:00 2001 From: arm64v8a <48624112+arm64v8a@users.noreply.github.com> Date: Mon, 2 Jan 2023 13:53:11 +0900 Subject: [PATCH] feat: max log lines --- main/NekoRay.cpp | 1 + main/NekoRay_DataStore.hpp | 1 + translations/fa_IR.ts | 4 + translations/zh_CN.ts | 4 + ui/dialog_basic_settings.cpp | 6 + ui/dialog_basic_settings.ui | 282 +++++++++++++++++++---------------- ui/mainwindow.cpp | 3 +- 7 files changed, 168 insertions(+), 133 deletions(-) diff --git a/main/NekoRay.cpp b/main/NekoRay.cpp index 4d6e3c9..40a98d9 100644 --- a/main/NekoRay.cpp +++ b/main/NekoRay.cpp @@ -69,6 +69,7 @@ namespace NekoRay { _add(new configItem("enable_js_hook", &enable_js_hook, itemType::integer)); _add(new configItem("log_ignore", &log_ignore, itemType::stringList)); _add(new configItem("start_minimal", &start_minimal, itemType::boolean)); + _add(new configItem("max_log_line", &max_log_line, itemType::integer)); } void DataStore::UpdateStartedId(int id) { diff --git a/main/NekoRay_DataStore.hpp b/main/NekoRay_DataStore.hpp index 9da8d7c..3ef13bc 100644 --- a/main/NekoRay_DataStore.hpp +++ b/main/NekoRay_DataStore.hpp @@ -76,6 +76,7 @@ namespace NekoRay { QString system_proxy_format = ""; QStringList log_ignore = {}; bool start_minimal = false; + int max_log_line = 200; // Subscription QString user_agent = "Nekoray/1.0 (Prefer Clash Format)"; diff --git a/translations/fa_IR.ts b/translations/fa_IR.ts index c19ee12..a248846 100644 --- a/translations/fa_IR.ts +++ b/translations/fa_IR.ts @@ -213,6 +213,10 @@ Please select a valid square image. لطفاً یک تصویر مربع معتبر انتخاب کنید. + + Max log lines + + DialogEditGroup diff --git a/translations/zh_CN.ts b/translations/zh_CN.ts index 261081b..9fdbec9 100644 --- a/translations/zh_CN.ts +++ b/translations/zh_CN.ts @@ -211,6 +211,10 @@ Hide dashboard at startup 启动时不显示仪表盘 + + Max log lines + 日志最大行数限制 + DialogEditGroup diff --git a/ui/dialog_basic_settings.cpp b/ui/dialog_basic_settings.cpp index f258b14..36941c7 100644 --- a/ui/dialog_basic_settings.cpp +++ b/ui/dialog_basic_settings.cpp @@ -101,6 +101,7 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent) D_LOAD_BOOL(check_include_pre) D_LOAD_BOOL(connection_statistics) D_LOAD_BOOL(start_minimal) + D_LOAD_INT(max_log_line) // if (NekoRay::dataStore->traffic_loop_interval == 500) { ui->rfsh_r->setCurrentIndex(0); @@ -256,6 +257,11 @@ void DialogBasicSettings::accept() { D_SAVE_BOOL(connection_statistics) D_SAVE_BOOL(check_include_pre) D_SAVE_BOOL(start_minimal) + D_SAVE_INT(max_log_line) + + if (NekoRay::dataStore->max_log_line <= 0) { + NekoRay::dataStore->max_log_line = 200; + } if (ui->rfsh_r->currentIndex() == 0) { NekoRay::dataStore->traffic_loop_interval = 500; diff --git a/ui/dialog_basic_settings.ui b/ui/dialog_basic_settings.ui index 25447b2..8ca0c68 100644 --- a/ui/dialog_basic_settings.ui +++ b/ui/dialog_basic_settings.ui @@ -20,16 +20,6 @@ Basic Settings - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - @@ -250,93 +240,139 @@ Style + + + + + + + + + + 0 + 0 + + + + Set custom icon + + + + + + + + + + + + + + 0 + 0 + + + + Hide dashboard at startup + + + + + + + + - - - - - - - 0 - 0 - - - - Theme - - - - - + + + + - - System - + + + + 0 + 0 + + + + Theme + + - - flatgray - + + + + System + + + + + flatgray + + + + + lightblue + + + + + blacksoft + + + + + + + + + + + + + + + 0 + 0 + + + + Language + + - - lightblue - + + + + System + + + + + English + + + + + 简体中文 + + + + + فارسی + + + - - - blacksoft - - - - - - + + + + - - - - - - - - 0 - 0 - - - - Language - - - - - - - - System - - - - - English - - - - - 简体中文 - - - - - فارسی - - - - - - - - + @@ -392,47 +428,21 @@ - - - - - - - - - - 0 - 0 - - - - Set custom icon - - - - - - - - - - - - - - 0 - 0 - - - - Hide dashboard at startup - - - - - - - + + + + + + + Max log lines + + + + + + + + @@ -492,7 +502,7 @@ - + @@ -654,6 +664,16 @@ + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index 4454c60..1a9abea 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -1295,11 +1295,10 @@ void MainWindow::show_log_impl(const QString &log) { FastAppendTextDocument(newLines.join("\n"), qvLogDocument); // qvLogDocument->setPlainText(qvLogDocument->toPlainText() + log); // From https://gist.github.com/jemyzhang/7130092 - auto maxLines = 200; auto block = qvLogDocument->begin(); while (block.isValid()) { - if (qvLogDocument->blockCount() > maxLines) { + if (qvLogDocument->blockCount() > NekoRay::dataStore->max_log_line) { QTextCursor cursor(block); block = block.next(); cursor.select(QTextCursor::BlockUnderCursor);