|
|
@ -35,6 +35,7 @@ |
|
|
|
#include <QPalette> |
|
|
|
#include <QPalette> |
|
|
|
|
|
|
|
|
|
|
|
#include "base/global.h" |
|
|
|
#include "base/global.h" |
|
|
|
|
|
|
|
#include "uithememanager.h" |
|
|
|
|
|
|
|
|
|
|
|
namespace |
|
|
|
namespace |
|
|
|
{ |
|
|
|
{ |
|
|
@ -72,6 +73,7 @@ QVariant BaseLogModel::Message::type() const |
|
|
|
BaseLogModel::BaseLogModel(QObject *parent) |
|
|
|
BaseLogModel::BaseLogModel(QObject *parent) |
|
|
|
: QAbstractListModel(parent) |
|
|
|
: QAbstractListModel(parent) |
|
|
|
, m_messages(MAX_VISIBLE_MESSAGES) |
|
|
|
, m_messages(MAX_VISIBLE_MESSAGES) |
|
|
|
|
|
|
|
, m_timeForeground(UIThemeManager::instance()->getColor(QLatin1String("Log.TimeStamp"), Qt::darkGray)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -100,7 +102,9 @@ QVariant BaseLogModel::data(const QModelIndex &index, const int role) const |
|
|
|
return message.time(); |
|
|
|
return message.time(); |
|
|
|
case MessageRole: |
|
|
|
case MessageRole: |
|
|
|
return message.message(); |
|
|
|
return message.message(); |
|
|
|
case ForegroundRole: |
|
|
|
case TimeForegroundRole: |
|
|
|
|
|
|
|
return m_timeForeground; |
|
|
|
|
|
|
|
case MessageForegroundRole: |
|
|
|
return message.foreground(); |
|
|
|
return message.foreground(); |
|
|
|
case TypeRole: |
|
|
|
case TypeRole: |
|
|
|
return message.type(); |
|
|
|
return message.type(); |
|
|
@ -134,6 +138,12 @@ void BaseLogModel::reset() |
|
|
|
|
|
|
|
|
|
|
|
LogMessageModel::LogMessageModel(QObject *parent) |
|
|
|
LogMessageModel::LogMessageModel(QObject *parent) |
|
|
|
: BaseLogModel(parent) |
|
|
|
: BaseLogModel(parent) |
|
|
|
|
|
|
|
, m_foregroundForMessageTypes { |
|
|
|
|
|
|
|
{Log::NORMAL, UIThemeManager::instance()->getColor(QLatin1String("Log.Normal"), QApplication::palette().color(QPalette::WindowText))}, |
|
|
|
|
|
|
|
{Log::INFO, UIThemeManager::instance()->getColor(QLatin1String("Log.Info"), Qt::blue)}, |
|
|
|
|
|
|
|
{Log::WARNING, UIThemeManager::instance()->getColor(QLatin1String("Log.Warning"), QColor {255, 165, 0})}, // orange
|
|
|
|
|
|
|
|
{Log::CRITICAL, UIThemeManager::instance()->getColor(QLatin1String("Log.Critical"), Qt::red)} |
|
|
|
|
|
|
|
} |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (const Log::Msg &msg : asConst(Logger::instance()->getMessages())) |
|
|
|
for (const Log::Msg &msg : asConst(Logger::instance()->getMessages())) |
|
|
|
handleNewMessage(msg); |
|
|
|
handleNewMessage(msg); |
|
|
@ -144,32 +154,14 @@ void LogMessageModel::handleNewMessage(const Log::Msg &message) |
|
|
|
{ |
|
|
|
{ |
|
|
|
const QString time = QDateTime::fromMSecsSinceEpoch(message.timestamp).toString(Qt::SystemLocaleShortDate); |
|
|
|
const QString time = QDateTime::fromMSecsSinceEpoch(message.timestamp).toString(Qt::SystemLocaleShortDate); |
|
|
|
const QString messageText = message.message; |
|
|
|
const QString messageText = message.message; |
|
|
|
|
|
|
|
const QColor foreground = m_foregroundForMessageTypes[message.type]; |
|
|
|
QColor foreground; |
|
|
|
|
|
|
|
switch (message.type) { |
|
|
|
|
|
|
|
// The RGB QColor constructor is used for performance
|
|
|
|
|
|
|
|
case Log::NORMAL: |
|
|
|
|
|
|
|
foreground = QApplication::palette().color(QPalette::WindowText); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case Log::INFO: |
|
|
|
|
|
|
|
foreground = QColor(0, 0, 255); // blue
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case Log::WARNING: |
|
|
|
|
|
|
|
foreground = QColor(255, 165, 0); // orange
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case Log::CRITICAL: |
|
|
|
|
|
|
|
foreground = QColor(255, 0, 0); // red
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
Q_ASSERT(false); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addNewMessage({time, messageText, foreground, message.type}); |
|
|
|
addNewMessage({time, messageText, foreground, message.type}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
LogPeerModel::LogPeerModel(QObject *parent) |
|
|
|
LogPeerModel::LogPeerModel(QObject *parent) |
|
|
|
: BaseLogModel(parent) |
|
|
|
: BaseLogModel(parent) |
|
|
|
|
|
|
|
, m_bannedPeerForeground(UIThemeManager::instance()->getColor(QLatin1String("Log.BannedPeer"), Qt::red)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (const Log::Peer &peer : asConst(Logger::instance()->getPeers())) |
|
|
|
for (const Log::Peer &peer : asConst(Logger::instance()->getPeers())) |
|
|
|
handleNewMessage(peer); |
|
|
|
handleNewMessage(peer); |
|
|
@ -182,7 +174,6 @@ void LogPeerModel::handleNewMessage(const Log::Peer &peer) |
|
|
|
const QString message = peer.blocked |
|
|
|
const QString message = peer.blocked |
|
|
|
? tr("%1 was blocked due to %2", "0.0.0.0 was blocked due to reason").arg(peer.ip, peer.reason) |
|
|
|
? tr("%1 was blocked due to %2", "0.0.0.0 was blocked due to reason").arg(peer.ip, peer.reason) |
|
|
|
: tr("%1 was banned", "0.0.0.0 was banned").arg(peer.ip); |
|
|
|
: tr("%1 was banned", "0.0.0.0 was banned").arg(peer.ip); |
|
|
|
const QColor foreground = Qt::red; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addNewMessage({time, message, foreground, Log::NORMAL}); |
|
|
|
addNewMessage({time, message, m_bannedPeerForeground, Log::NORMAL}); |
|
|
|
} |
|
|
|
} |
|
|
|