diff --git a/Build.Counter b/Build.Counter
index d47755d1..11befb00 100644
--- a/Build.Counter
+++ b/Build.Counter
@@ -1 +1 @@
-2944
+2957
diff --git a/src/Qv2rayBase.hpp b/src/Qv2rayBase.hpp
index ab293d99..a5b3c5c9 100644
--- a/src/Qv2rayBase.hpp
+++ b/src/Qv2rayBase.hpp
@@ -179,8 +179,9 @@ namespace Qv2ray
QString language;
bool useDarkTheme;
bool useDarkTrayIcon;
- Qv2rayUIConfig() : theme("Fusion"), language("en-US"), useDarkTheme(false), useDarkTrayIcon(true) { }
- XTOSTRUCT(O(theme, language, useDarkTheme, useDarkTrayIcon))
+ int maximumLogLines;
+ Qv2rayUIConfig() : theme("Fusion"), language("en-US"), useDarkTheme(false), useDarkTrayIcon(true), maximumLogLines(2000) { }
+ XTOSTRUCT(O(theme, language, useDarkTheme, useDarkTrayIcon, maximumLogLines))
};
struct Qv2rayConnectionConfig {
diff --git a/src/ui/w_MainWindow.cpp b/src/ui/w_MainWindow.cpp
index 68e33376..a60fe885 100644
--- a/src/ui/w_MainWindow.cpp
+++ b/src/ui/w_MainWindow.cpp
@@ -56,6 +56,23 @@
#define IsConnectableItem(item) (item != nullptr && item->childCount() == 0 && (CheckConfigType(item, REGULAR) || CheckConfigType(item, SUBSCRIPTION)))
#define IsSelectionConnectable (!connectionListWidget->selectedItems().empty() && IsConnectableItem(connectionListWidget->selectedItems().first()))
+// From https://gist.github.com/jemyzhang/7130092
+#define CleanUpLogs(browser) \
+ {\
+ auto maxLines = currentConfig.uiConfig.maximumLogLines; \
+ QTextBlock block = browser->document()->begin();\
+ while (block.isValid()) {\
+ if (browser->document()->blockCount() > maxLines) {\
+ QTextCursor cursor(block);\
+ block = block.next();\
+ cursor.select(QTextCursor::BlockUnderCursor);\
+ cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor);\
+ cursor.removeSelectedText();\
+ } else {\
+ break;\
+ }\
+ }\
+ }
MainWindow *MainWindow::mwInstance = nullptr;
@@ -95,7 +112,7 @@ MainWindow::MainWindow(QWidget *parent):
masterLogBrowser->document()->adjustSize();
masterLogBrowser->setLineWrapMode(QTextBrowser::LineWrapMode::NoWrap);
//
- logTimerId = startTimer(500);
+ qvLogTimerId = startTimer(500);
//
pacServer = new PACServer();
tcpingModel = new QvTCPingModel(3, this);
@@ -414,7 +431,7 @@ void MainWindow::OnConfigListChanged(bool need_restart)
}
MainWindow::~MainWindow()
{
- killTimer(logTimerId);
+ killTimer(qvLogTimerId);
hTray->hide();
delete this->hTray;
delete this->vinstance;
@@ -422,6 +439,7 @@ MainWindow::~MainWindow()
void MainWindow::UpdateVCoreLog(const QString &log)
{
vCoreLogBrowser->append(log);
+ CleanUpLogs(vCoreLogBrowser)
setMasterLogHBar();
}
void MainWindow::setMasterLogHBar()
@@ -1038,12 +1056,14 @@ void MainWindow::timerEvent(QTimerEvent *event)
dataamountLabel->setText(totalDataUp + NEWLINE + totalDataDown);
//
hTray->setToolTip(TRAY_TOOLTIP_PREFIX NEWLINE + tr("Connected: ") + CurrentConnectionIdentifier.IdentifierString() + NEWLINE "Up: " + totalSpeedUp + " Down: " + totalSpeedDown);
- } else if (event->timerId() == logTimerId) {
+ } else if (event->timerId() == qvLogTimerId) {
QString lastLog = readLastLog();
if (!lastLog.isEmpty()) {
qvAppLogBrowser->append(lastLog);
}
+
+ CleanUpLogs(vCoreLogBrowser)
} else if (event->timerId() == pingTimerId) {
MWTryPingConnection(CurrentConnectionIdentifier);
}
diff --git a/src/ui/w_MainWindow.hpp b/src/ui/w_MainWindow.hpp
index a9a20a35..eae25992 100644
--- a/src/ui/w_MainWindow.hpp
+++ b/src/ui/w_MainWindow.hpp
@@ -112,7 +112,7 @@ class MainWindow : public QMainWindow, Ui::MainWindow
//
// ID for QTimers
//
- int logTimerId;
+ int qvLogTimerId;
int speedTimerId;
int pingTimerId;
//
diff --git a/src/ui/w_PreferencesWindow.cpp b/src/ui/w_PreferencesWindow.cpp
index 4f464f75..b40d5e5f 100644
--- a/src/ui/w_PreferencesWindow.cpp
+++ b/src/ui/w_PreferencesWindow.cpp
@@ -170,6 +170,8 @@ PreferencesWindow::PreferencesWindow(QWidget *parent) : QDialog(parent),
fpUsernameTx->setEnabled(fpUseAuthCB->isChecked());
fpPasswordTx->setEnabled(fpUseAuthCB->isChecked());
//
+ maxLogLinesSB->setValue(CurrentConfig.uiConfig.maximumLogLines);
+ //
pacListenAddrLabel->setText("http://" + (pacProxyTxt->text().isEmpty() ? "127.0.0.1" : pacProxyTxt->text()) + ":" + QSTRN(pacPortSB->value()) + "/pac");
//
finishedLoading = true;
@@ -1012,3 +1014,10 @@ void PreferencesWindow::on_fpGroupBox_clicked(bool checked)
NEEDRESTART
CurrentConfig.connectionConfig.forwardProxyConfig.enableForwardProxy = checked;
}
+
+void PreferencesWindow::on_maxLogLinesSB_valueChanged(int arg1)
+{
+ LOADINGCHECK
+ NEEDRESTART
+ CurrentConfig.uiConfig.maximumLogLines = arg1;
+}
diff --git a/src/ui/w_PreferencesWindow.hpp b/src/ui/w_PreferencesWindow.hpp
index ae6ebb15..30cf02c8 100644
--- a/src/ui/w_PreferencesWindow.hpp
+++ b/src/ui/w_PreferencesWindow.hpp
@@ -158,6 +158,8 @@ class PreferencesWindow : public QDialog, private Ui::PreferencesWindow
void on_fpGroupBox_clicked(bool checked);
+ void on_maxLogLinesSB_valueChanged(int arg1);
+
private:
void SetAutoStartButtonsState(bool isAutoStart);
// Set ui parameters for a line;
diff --git a/src/ui/w_PreferencesWindow.ui b/src/ui/w_PreferencesWindow.ui
index 18ff2ab3..67163299 100644
--- a/src/ui/w_PreferencesWindow.ui
+++ b/src/ui/w_PreferencesWindow.ui
@@ -44,26 +44,141 @@
0
0
647
- 440
+ 476
-
-
-
- UI Theme
-
-
+
+
-
+
+
+ Qt::Vertical
+
+
+
+ 0
+ 0
+
+
+
+
+ -
+
+
+ UI Settings
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 0
+ 0
+
+
+
+
+
-
-
-
-
- 200
- 0
-
-
-
+
+
-
+
+
+ UI Theme
+
+
+
+ -
+
+
+ Enabled
+
+
+
+ -
+
+
+ Enabled
+
+
+
+ -
+
+
+ Language
+
+
+
+ -
+
+
+ QFrame::Plain
+
+
+ 2
+
+
+ Qt::Vertical
+
+
+
+ -
+
+
+ Darkmode Tray Icon
+
+
+
+ -
+
+
+
+ 200
+ 0
+
+
+
+
+ -
+
+
+ Darkmode UI Icons
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+ 100
+ 0
+
+
+
-
+
+ zh-CN
+
+
+ -
+
+ en-US
+
+
+
+
+
-
@@ -104,141 +219,13 @@
-
-
-
-
-
-
- Qt::Vertical
-
-
-
- 0
- 0
-
-
-
-
- -
-
-
- Theme Settings
-
-
-
- -
-
-
- Qt::Vertical
-
-
-
- 0
- 0
-
-
-
-
-
-
- -
-
-
-
-
-
- Enabled
-
-
-
- -
-
-
- Qt::Horizontal
-
-
-
- 40
- 20
-
-
-
-
- -
-
-
- Enabled
-
-
-
- -
-
-
- Darkmode UI Icons
-
-
-
- -
-
-
- Darkmode Tray Icon
-
-
-
- -
-
-
- QFrame::Plain
-
-
- 2
-
-
- Qt::Vertical
-
-
-
-
-
- -
-
-
- Language
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
-
- 100
- 0
-
-
-
-
-
- zh-CN
-
-
- -
-
- en-US
-
-
-
-
- -
Log Level
- -
+
-
@@ -279,7 +266,7 @@
- -
+
-
-
@@ -316,7 +303,7 @@
- -
+
-
-
@@ -365,21 +352,21 @@
- -
+
-
Transparent Proxy
- -
+
-
Enabled
- -
+
-
-
@@ -416,7 +403,7 @@
- -
+
-
-
@@ -478,7 +465,7 @@
- -
+
-
Qt::Vertical
@@ -491,6 +478,29 @@
+ -
+
+
+ Maximum log lines
+
+
+
+ -
+
+
+ true
+
+
+ lines
+
+
+ 50
+
+
+ 2000
+
+
+
diff --git a/src/utils/QvHelpers.cpp b/src/utils/QvHelpers.cpp
index 48a4d0cd..806daa9c 100644
--- a/src/utils/QvHelpers.cpp
+++ b/src/utils/QvHelpers.cpp
@@ -22,7 +22,11 @@ const QString readLastLog()
QString result;
while (!__loggerBuffer.isEmpty()) {
- result += __loggerBuffer.dequeue();
+ auto str = __loggerBuffer.dequeue();
+
+ if (!str.trimmed().isEmpty()) {
+ result += str;
+ }
}
return result;