Clean up code

This commit is contained in:
Chocobo1
2019-03-08 17:14:20 +08:00
parent 04fd6e9d04
commit a3019f56b0
5 changed files with 34 additions and 36 deletions

View File

@@ -40,7 +40,7 @@
ExecutionLogWidget::ExecutionLogWidget(QWidget *parent, const Log::MsgTypes &types)
: QWidget(parent)
, m_ui(new Ui::ExecutionLogWidget)
, m_msgList(new LogListWidget(MAX_LOG_MESSAGES, Log::MsgTypes(types)))
, m_msgList(new LogListWidget(MAX_LOG_MESSAGES, types))
, m_peerList(new LogListWidget(MAX_LOG_MESSAGES))
{
m_ui->setupUi(this);
@@ -75,38 +75,35 @@ void ExecutionLogWidget::showMsgTypes(const Log::MsgTypes &types)
void ExecutionLogWidget::addLogMessage(const Log::Msg &msg)
{
QString text;
QDateTime time = QDateTime::fromMSecsSinceEpoch(msg.timestamp);
QColor color;
QString colorName;
switch (msg.type) {
case Log::INFO:
color.setNamedColor("blue");
colorName = QLatin1String("blue");
break;
case Log::WARNING:
color.setNamedColor("orange");
colorName = QLatin1String("orange");
break;
case Log::CRITICAL:
color.setNamedColor("red");
colorName = QLatin1String("red");
break;
default:
color = QApplication::palette().color(QPalette::WindowText);
colorName = QApplication::palette().color(QPalette::WindowText).name();
}
text = "<font color='grey'>" + time.toString(Qt::SystemLocaleShortDate) + "</font> - <font color='" + color.name() + "'>" + msg.message + "</font>";
const QDateTime time = QDateTime::fromMSecsSinceEpoch(msg.timestamp);
const QString text = QString(QLatin1String("<font color='grey'>%1</font> - <font color='%2'>%3</font>"))
.arg(time.toString(Qt::SystemLocaleShortDate), colorName, msg.message);
m_msgList->appendLine(text, msg.type);
}
void ExecutionLogWidget::addPeerMessage(const Log::Peer &peer)
{
QString text;
QDateTime time = QDateTime::fromMSecsSinceEpoch(peer.timestamp);
if (peer.blocked)
text = "<font color='grey'>" + time.toString(Qt::SystemLocaleShortDate) + "</font> - "
+ tr("<font color='red'>%1</font> was blocked %2", "x.y.z.w was blocked").arg(peer.ip, peer.reason);
else
text = "<font color='grey'>" + time.toString(Qt::SystemLocaleShortDate) + "</font> - " + tr("<font color='red'>%1</font> was banned", "x.y.z.w was banned").arg(peer.ip);
const QDateTime time = QDateTime::fromMSecsSinceEpoch(peer.timestamp);
const QString msg = QString(QLatin1String("<font color='grey'>%1</font> - <font color='red'>%2</font>"))
.arg(time.toString(Qt::SystemLocaleShortDate), peer.ip);
const QString text = peer.blocked
? tr("%1 was blocked %2", "0.0.0.0 was blocked due to reason").arg(msg, peer.reason)
: tr("%1 was banned", "0.0.0.0 was banned").arg(msg);
m_peerList->appendLine(text, Log::NORMAL);
}