mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-05 11:24:15 +00:00
Make the GUI log listen to the logger class.
This commit is contained in:
parent
1504bbfe43
commit
91fc9e69ee
@ -30,50 +30,81 @@
|
|||||||
|
|
||||||
#include <QListWidgetItem>
|
#include <QListWidgetItem>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QDateTime>
|
||||||
|
#include <QColor>
|
||||||
|
#include <QPalette>
|
||||||
#include "executionlog.h"
|
#include "executionlog.h"
|
||||||
#include "ui_executionlog.h"
|
#include "ui_executionlog.h"
|
||||||
#include "qbtsession.h"
|
#include "logger.h"
|
||||||
#include "iconprovider.h"
|
#include "iconprovider.h"
|
||||||
#include "loglistwidget.h"
|
#include "loglistwidget.h"
|
||||||
|
|
||||||
ExecutionLog::ExecutionLog(QWidget *parent) :
|
ExecutionLog::ExecutionLog(QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
ui(new Ui::ExecutionLog),
|
ui(new Ui::ExecutionLog),
|
||||||
m_logList(new LogListWidget(MAX_LOG_MESSAGES)),
|
m_msgList(new LogListWidget(MAX_LOG_MESSAGES)),
|
||||||
m_banList(new LogListWidget(MAX_LOG_MESSAGES))
|
m_peerList(new LogListWidget(MAX_LOG_MESSAGES))
|
||||||
{
|
{
|
||||||
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->tabGeneral->layout()->addWidget(m_logList);
|
ui->tabGeneral->layout()->addWidget(m_msgList);
|
||||||
ui->tabBan->layout()->addWidget(m_banList);
|
ui->tabBan->layout()->addWidget(m_peerList);
|
||||||
|
|
||||||
const QStringList log_msgs = QBtSession::instance()->getConsoleMessages();
|
const Logger* const logger = Logger::instance();
|
||||||
foreach (const QString& msg, log_msgs)
|
foreach (const Log::Msg& msg, logger->getMessages())
|
||||||
addLogMessage(msg);
|
addLogMessage(msg);
|
||||||
const QStringList ban_msgs = QBtSession::instance()->getPeerBanMessages();
|
foreach (const Log::Peer& peer, logger->getPeers())
|
||||||
foreach (const QString& msg, ban_msgs)
|
addPeerMessage(peer);
|
||||||
addBanMessage(msg);
|
connect(logger, SIGNAL(newLogMessage(const Log::Msg &)), SLOT(addLogMessage(const Logg:Msg &)));
|
||||||
connect(QBtSession::instance(), SIGNAL(newConsoleMessage(QString)), SLOT(addLogMessage(QString)));
|
connect(logger, SIGNAL(newLogPeer(const Log::Peer &)), SLOT(addPeerMessage(const Log::Peer &)));
|
||||||
connect(QBtSession::instance(), SIGNAL(newBanMessage(QString)), SLOT(addBanMessage(QString)));
|
|
||||||
connect(m_logList, SIGNAL(logCleared()), QBtSession::instance(), SLOT(clearConsoleMessages()));
|
|
||||||
connect(m_banList, SIGNAL(logCleared()), QBtSession::instance(), SLOT(clearPeerBanMessages()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ExecutionLog::~ExecutionLog()
|
ExecutionLog::~ExecutionLog()
|
||||||
{
|
{
|
||||||
delete m_logList;
|
delete m_msgList;
|
||||||
delete m_banList;
|
delete m_peerList;
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExecutionLog::addLogMessage(const QString &msg)
|
void ExecutionLog::addLogMessage(const Log::Msg &msg)
|
||||||
{
|
{
|
||||||
m_logList->appendLine(msg);
|
QString text;
|
||||||
|
QDateTime time = QDateTime::fromMSecsSinceEpoch(msg.timestamp);
|
||||||
|
QColor color;
|
||||||
|
|
||||||
|
switch (msg.type) {
|
||||||
|
case Log::INFO:
|
||||||
|
color.setNamedColor("blue");
|
||||||
|
break;
|
||||||
|
case Log::WARNING:
|
||||||
|
color.setNamedColor("orange");
|
||||||
|
break;
|
||||||
|
case Log::CRITICAL:
|
||||||
|
color.setNamedColor("red");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
color = QApplication::palette().color(QPalette::WindowText);
|
||||||
|
}
|
||||||
|
|
||||||
|
text = "<font color='grey'>" + time.toString("dd/MM/yyyy hh:mm:ss") + "</font> - <font color='" + color.name() + "'>" + msg.message + "</font>";
|
||||||
|
m_msgList->appendLine(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExecutionLog::addBanMessage(const QString &msg)
|
void ExecutionLog::addPeerMessage(const Log::Peer& peer)
|
||||||
{
|
{
|
||||||
m_banList->appendLine(msg);
|
QString text;
|
||||||
|
QDateTime time = QDateTime::fromMSecsSinceEpoch(peer.timestamp);
|
||||||
|
|
||||||
|
if (peer.blocked)
|
||||||
|
#if LIBTORRENT_VERSION_NUM < 10000
|
||||||
|
text = "<font color='grey'>" + time.toString("dd/MM/yyyy hh:mm:ss") + "</font> - " + tr("<font color='red'>%1</font> was blocked", "x.y.z.w was blocked").arg(peer.ip);
|
||||||
|
#else
|
||||||
|
text = "<font color='grey'>" + time.toString("dd/MM/yyyy hh:mm:ss") + "</font> - " + tr("<font color='red'>%1</font> was blocked %2", "x.y.z.w was blocked").arg(peer.ip).arg(peer.reason);
|
||||||
|
#endif
|
||||||
|
else
|
||||||
|
text = "<font color='grey'>" + time.toString("dd/MM/yyyy hh:mm:ss") + "</font> - " + tr("<font color='red'>%1</font> was banned", "x.y.z.w was banned").arg(peer.ip);
|
||||||
|
|
||||||
|
m_peerList->appendLine(text);
|
||||||
}
|
}
|
||||||
|
@ -38,8 +38,15 @@ namespace Ui {
|
|||||||
class ExecutionLog;
|
class ExecutionLog;
|
||||||
}
|
}
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
class Logger;
|
||||||
class LogListWidget;
|
class LogListWidget;
|
||||||
|
|
||||||
|
namespace Log
|
||||||
|
{
|
||||||
|
struct Msg;
|
||||||
|
struct Peer;
|
||||||
|
}
|
||||||
|
|
||||||
class ExecutionLog : public QWidget
|
class ExecutionLog : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -48,15 +55,15 @@ public:
|
|||||||
explicit ExecutionLog(QWidget *parent = 0);
|
explicit ExecutionLog(QWidget *parent = 0);
|
||||||
~ExecutionLog();
|
~ExecutionLog();
|
||||||
|
|
||||||
public slots:
|
private slots:
|
||||||
void addLogMessage(const QString &msg);
|
void addLogMessage(const Log::Msg &msg);
|
||||||
void addBanMessage(const QString &msg);
|
void addPeerMessage(const Log::Peer &peer);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ExecutionLog *ui;
|
Ui::ExecutionLog *ui;
|
||||||
|
|
||||||
LogListWidget *m_logList;
|
LogListWidget *m_msgList;
|
||||||
LogListWidget *m_banList;
|
LogListWidget *m_peerList;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // EXECUTIONLOG_H
|
#endif // EXECUTIONLOG_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user