Browse Source

Fix important memory usage problem in log tab

adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
6d9e519cdc
  1. 28
      src/executionlog.cpp
  2. 12
      src/executionlog.ui
  3. 12
      src/qtlibtorrent/qbtsession.cpp
  4. 2
      src/qtlibtorrent/qbtsession.h

28
src/executionlog.cpp

@ -28,6 +28,8 @@
* Contact : chris@qbittorrent.org * Contact : chris@qbittorrent.org
*/ */
#include <QListWidgetItem>
#include <QLabel>
#include "executionlog.h" #include "executionlog.h"
#include "ui_executionlog.h" #include "ui_executionlog.h"
#include "qbtsession.h" #include "qbtsession.h"
@ -40,9 +42,13 @@ ExecutionLog::ExecutionLog(QWidget *parent) :
ui->setupUi(this); ui->setupUi(this);
ui->tabConsole->setTabIcon(0, IconProvider::instance()->getIcon("view-calendar-journal")); ui->tabConsole->setTabIcon(0, IconProvider::instance()->getIcon("view-calendar-journal"));
ui->tabConsole->setTabIcon(1, IconProvider::instance()->getIcon("view-filter")); 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))); 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))); connect(QBtSession::instance(), SIGNAL(newBanMessage(QString)), SLOT(addBanMessage(QString)));
} }
@ -53,10 +59,24 @@ ExecutionLog::~ExecutionLog()
void ExecutionLog::addLogMessage(const QString &msg) 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) 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);
} }

12
src/executionlog.ui

@ -28,7 +28,11 @@
</attribute> </attribute>
<layout class="QVBoxLayout"> <layout class="QVBoxLayout">
<item> <item>
<widget class="QTextBrowser" name="textConsole"/> <widget class="QListWidget" name="logList">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>
@ -38,7 +42,11 @@
</attribute> </attribute>
<layout class="QVBoxLayout" name="_2"> <layout class="QVBoxLayout" name="_2">
<item> <item>
<widget class="QTextBrowser" name="textBannedPeers"/> <widget class="QListWidget" name="banList">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>

12
src/qtlibtorrent/qbtsession.cpp

@ -1692,25 +1692,25 @@ void QBtSession::addConsoleMessage(QString msg, QString) {
emit newConsoleMessage(QDateTime::currentDateTime().toString("dd/MM/yyyy hh:mm:ss") + " - " + msg); emit newConsoleMessage(QDateTime::currentDateTime().toString("dd/MM/yyyy hh:mm:ss") + " - " + msg);
#else #else
void QBtSession::addConsoleMessage(QString msg, QColor color) { void QBtSession::addConsoleMessage(QString msg, QColor color) {
if(consoleMessages.size() > 100) { if(consoleMessages.size() > MAX_LOG_MESSAGES) {
consoleMessages.removeLast(); 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>"; 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); emit newConsoleMessage(msg);
#endif #endif
} }
void QBtSession::addPeerBanMessage(QString ip, bool from_ipfilter) { void QBtSession::addPeerBanMessage(QString ip, bool from_ipfilter) {
if(peerBanMessages.size() > 100) { if(peerBanMessages.size() > MAX_LOG_MESSAGES) {
peerBanMessages.removeLast(); peerBanMessages.removeFirst();
} }
QString msg; QString msg;
if(from_ipfilter) 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); 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 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); 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); emit newBanMessage(msg);
} }

2
src/qtlibtorrent/qbtsession.h

@ -60,6 +60,8 @@ class ScanFoldersModel;
class TorrentSpeedMonitor; class TorrentSpeedMonitor;
class DNSUpdater; class DNSUpdater;
const int MAX_LOG_MESSAGES = 100;
class QBtSession : public QObject { class QBtSession : public QObject {
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY(QBtSession) Q_DISABLE_COPY(QBtSession)

Loading…
Cancel
Save