mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-27 06:54:20 +00:00
Fix important memory usage problem in log tab
This commit is contained in:
parent
16ad56c13f
commit
6d9e519cdc
@ -28,6 +28,8 @@
|
||||
* Contact : chris@qbittorrent.org
|
||||
*/
|
||||
|
||||
#include <QListWidgetItem>
|
||||
#include <QLabel>
|
||||
#include "executionlog.h"
|
||||
#include "ui_executionlog.h"
|
||||
#include "qbtsession.h"
|
||||
@ -40,9 +42,13 @@ ExecutionLog::ExecutionLog(QWidget *parent) :
|
||||
ui->setupUi(this);
|
||||
ui->tabConsole->setTabIcon(0, IconProvider::instance()->getIcon("view-calendar-journal"));
|
||||
ui->tabConsole->setTabIcon(1, IconProvider::instance()->getIcon("view-filter"));
|
||||
ui->textConsole->setHtml(QBtSession::instance()->getConsoleMessages().join("<br>"));
|
||||
const QStringList log_msgs = QBtSession::instance()->getConsoleMessages();
|
||||
foreach(const QString& msg, log_msgs)
|
||||
addLogMessage(msg);
|
||||
const QStringList ban_msgs = QBtSession::instance()->getPeerBanMessages();
|
||||
foreach(const QString& msg, ban_msgs)
|
||||
addBanMessage(msg);
|
||||
connect(QBtSession::instance(), SIGNAL(newConsoleMessage(QString)), SLOT(addLogMessage(QString)));
|
||||
ui->textBannedPeers->setHtml(QBtSession::instance()->getPeerBanMessages().join("<br>"));
|
||||
connect(QBtSession::instance(), SIGNAL(newBanMessage(QString)), SLOT(addBanMessage(QString)));
|
||||
}
|
||||
|
||||
@ -53,10 +59,24 @@ ExecutionLog::~ExecutionLog()
|
||||
|
||||
void ExecutionLog::addLogMessage(const QString &msg)
|
||||
{
|
||||
ui->textConsole->setHtml(msg+ui->textConsole->toHtml());
|
||||
QListWidgetItem *item = new QListWidgetItem;
|
||||
QLabel *lbl = new QLabel(msg);
|
||||
lbl->setContentsMargins(4, 2, 4, 2);
|
||||
item->setSizeHint(lbl->sizeHint());
|
||||
ui->logList->insertItem(0, item);
|
||||
ui->logList->setItemWidget(item, lbl);
|
||||
if(ui->logList->count() > MAX_LOG_MESSAGES)
|
||||
delete ui->logList->takeItem(ui->logList->count()-1);
|
||||
}
|
||||
|
||||
void ExecutionLog::addBanMessage(const QString &msg)
|
||||
{
|
||||
ui->textBannedPeers->setHtml(msg+ui->textBannedPeers->toHtml());
|
||||
QListWidgetItem *item = new QListWidgetItem;
|
||||
QLabel *lbl = new QLabel(msg);
|
||||
lbl->setContentsMargins(4, 2, 4, 2);
|
||||
item->setSizeHint(lbl->sizeHint());
|
||||
ui->banList->insertItem(0, item);
|
||||
ui->banList->setItemWidget(item, lbl);
|
||||
if(ui->banList->count() > MAX_LOG_MESSAGES)
|
||||
delete ui->banList->takeItem(ui->banList->count()-1);
|
||||
}
|
||||
|
@ -28,7 +28,11 @@
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout">
|
||||
<item>
|
||||
<widget class="QTextBrowser" name="textConsole"/>
|
||||
<widget class="QListWidget" name="logList">
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
@ -38,7 +42,11 @@
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="_2">
|
||||
<item>
|
||||
<widget class="QTextBrowser" name="textBannedPeers"/>
|
||||
<widget class="QListWidget" name="banList">
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
|
@ -1692,25 +1692,25 @@ void QBtSession::addConsoleMessage(QString msg, QString) {
|
||||
emit newConsoleMessage(QDateTime::currentDateTime().toString("dd/MM/yyyy hh:mm:ss") + " - " + msg);
|
||||
#else
|
||||
void QBtSession::addConsoleMessage(QString msg, QColor color) {
|
||||
if(consoleMessages.size() > 100) {
|
||||
consoleMessages.removeLast();
|
||||
if(consoleMessages.size() > MAX_LOG_MESSAGES) {
|
||||
consoleMessages.removeFirst();
|
||||
}
|
||||
msg = "<font color='grey'>"+ QDateTime::currentDateTime().toString(QString::fromUtf8("dd/MM/yyyy hh:mm:ss")) + "</font> - <font color='" + color.name() + "'><i>" + msg + "</i></font>";
|
||||
consoleMessages.prepend(msg);
|
||||
consoleMessages.append(msg);
|
||||
emit newConsoleMessage(msg);
|
||||
#endif
|
||||
}
|
||||
|
||||
void QBtSession::addPeerBanMessage(QString ip, bool from_ipfilter) {
|
||||
if(peerBanMessages.size() > 100) {
|
||||
peerBanMessages.removeLast();
|
||||
if(peerBanMessages.size() > MAX_LOG_MESSAGES) {
|
||||
peerBanMessages.removeFirst();
|
||||
}
|
||||
QString msg;
|
||||
if(from_ipfilter)
|
||||
msg = "<font color='grey'>" + QDateTime::currentDateTime().toString(QString::fromUtf8("dd/MM/yyyy hh:mm:ss")) + "</font> - " + tr("<font color='red'>%1</font> <i>was blocked due to your IP filter</i>", "x.y.z.w was blocked").arg(ip);
|
||||
else
|
||||
msg = "<font color='grey'>" + QDateTime::currentDateTime().toString(QString::fromUtf8("dd/MM/yyyy hh:mm:ss")) + "</font> - " + tr("<font color='red'>%1</font> <i>was banned due to corrupt pieces</i>", "x.y.z.w was banned").arg(ip);
|
||||
peerBanMessages.prepend(msg);
|
||||
peerBanMessages.append(msg);
|
||||
emit newBanMessage(msg);
|
||||
}
|
||||
|
||||
|
@ -60,6 +60,8 @@ class ScanFoldersModel;
|
||||
class TorrentSpeedMonitor;
|
||||
class DNSUpdater;
|
||||
|
||||
const int MAX_LOG_MESSAGES = 100;
|
||||
|
||||
class QBtSession : public QObject {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(QBtSession)
|
||||
|
Loading…
x
Reference in New Issue
Block a user