Browse Source

Add ability to filter log messages by type.

adaptive-webui-19844
sledgehammer999 9 years ago
parent
commit
73832a5ed8
  1. 12
      src/base/logger.h
  2. 12
      src/base/preferences.cpp
  3. 2
      src/base/preferences.h
  4. 15
      src/gui/executionlog.cpp
  5. 9
      src/gui/executionlog.h
  6. 31
      src/gui/loglistwidget.cpp
  7. 9
      src/gui/loglistwidget.h
  8. 74
      src/gui/mainwindow.cpp
  9. 6
      src/gui/mainwindow.h
  10. 70
      src/gui/mainwindow.ui

12
src/base/logger.h

@ -12,11 +12,13 @@ namespace Log
{ {
enum MsgType enum MsgType
{ {
NORMAL, ALL = -1,
INFO, NORMAL = 0x1,
WARNING, INFO = 0x2,
CRITICAL //ERROR is defined by libtorrent and results in compiler error WARNING = 0x4,
CRITICAL = 0x8 //ERROR is defined by libtorrent and results in compiler error
}; };
Q_DECLARE_FLAGS(MsgTypes, MsgType)
struct Msg struct Msg
{ {
@ -36,6 +38,8 @@ namespace Log
}; };
} }
Q_DECLARE_OPERATORS_FOR_FLAGS(Log::MsgTypes)
class Logger : public QObject class Logger : public QObject
{ {
Q_OBJECT Q_OBJECT

12
src/base/preferences.cpp

@ -871,6 +871,18 @@ void Preferences::setExecutionLogEnabled(bool b)
setValue("Preferences/ExecutionLog/enabled", b); setValue("Preferences/ExecutionLog/enabled", b);
} }
int Preferences::executionLogMessageTypes() const
{
// as default value we need all the bits set
// -1 is considered the portable way to achieve that
return value("MainWindow/ExecutionLog/Types", -1).toInt();
}
void Preferences::setExecutionLogMessageTypes(const int &value)
{
setValue("MainWindow/ExecutionLog/Types", value);
}
// Queueing system // Queueing system
bool Preferences::isQueueingSystemEnabled() const bool Preferences::isQueueingSystemEnabled() const
{ {

2
src/base/preferences.h

@ -276,6 +276,8 @@ public:
// Execution Log // Execution Log
bool isExecutionLogEnabled() const; bool isExecutionLogEnabled() const;
void setExecutionLogEnabled(bool b); void setExecutionLogEnabled(bool b);
int executionLogMessageTypes() const;
void setExecutionLogMessageTypes(const int &value);
// Queueing system // Queueing system
bool isQueueingSystemEnabled() const; bool isQueueingSystemEnabled() const;

15
src/gui/executionlog.cpp

@ -35,18 +35,20 @@
#include <QPalette> #include <QPalette>
#include "executionlog.h" #include "executionlog.h"
#include "ui_executionlog.h" #include "ui_executionlog.h"
#include "base/logger.h" #include "base/preferences.h"
#include "guiiconprovider.h" #include "guiiconprovider.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_msgList(new LogListWidget(MAX_LOG_MESSAGES))
, m_peerList(new LogListWidget(MAX_LOG_MESSAGES)) , m_peerList(new LogListWidget(MAX_LOG_MESSAGES))
{ {
ui->setupUi(this); ui->setupUi(this);
m_msgList = new LogListWidget(MAX_LOG_MESSAGES,
Log::MsgTypes(Preferences::instance()->executionLogMessageTypes()));
ui->tabConsole->setTabIcon(0, GuiIconProvider::instance()->getIcon("view-calendar-journal")); ui->tabConsole->setTabIcon(0, GuiIconProvider::instance()->getIcon("view-calendar-journal"));
ui->tabConsole->setTabIcon(1, GuiIconProvider::instance()->getIcon("view-filter")); ui->tabConsole->setTabIcon(1, GuiIconProvider::instance()->getIcon("view-filter"));
ui->tabGeneral->layout()->addWidget(m_msgList); ui->tabGeneral->layout()->addWidget(m_msgList);
@ -68,6 +70,11 @@ ExecutionLog::~ExecutionLog()
delete ui; delete ui;
} }
void ExecutionLog::showMsgTypes(const Log::MsgTypes &types)
{
m_msgList->showMsgTypes(types);
}
void ExecutionLog::addLogMessage(const Log::Msg &msg) void ExecutionLog::addLogMessage(const Log::Msg &msg)
{ {
QString text; QString text;
@ -89,7 +96,7 @@ void ExecutionLog::addLogMessage(const Log::Msg &msg)
} }
text = "<font color='grey'>" + time.toString(Qt::SystemLocaleShortDate) + "</font> - <font color='" + color.name() + "'>" + msg.message + "</font>"; text = "<font color='grey'>" + time.toString(Qt::SystemLocaleShortDate) + "</font> - <font color='" + color.name() + "'>" + msg.message + "</font>";
m_msgList->appendLine(text); m_msgList->appendLine(text, msg.type);
} }
void ExecutionLog::addPeerMessage(const Log::Peer& peer) void ExecutionLog::addPeerMessage(const Log::Peer& peer)
@ -102,5 +109,5 @@ void ExecutionLog::addPeerMessage(const Log::Peer& peer)
else 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); 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);
m_peerList->appendLine(text); m_peerList->appendLine(text, Log::NORMAL);
} }

9
src/gui/executionlog.h

@ -32,27 +32,22 @@
#define EXECUTIONLOG_H #define EXECUTIONLOG_H
#include <QWidget> #include <QWidget>
#include "base/logger.h"
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
namespace Ui { 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
public: public:
explicit ExecutionLog(QWidget *parent = 0); explicit ExecutionLog(QWidget *parent = 0);
void showMsgTypes(const Log::MsgTypes &types);
~ExecutionLog(); ~ExecutionLog();
private slots: private slots:

31
src/gui/loglistwidget.cpp

@ -37,9 +37,10 @@
#include "loglistwidget.h" #include "loglistwidget.h"
#include "guiiconprovider.h" #include "guiiconprovider.h"
LogListWidget::LogListWidget(int max_lines, QWidget *parent) : LogListWidget::LogListWidget(int maxLines, const Log::MsgTypes &types, QWidget *parent)
QListWidget(parent), : QListWidget(parent)
m_maxLines(max_lines) , m_maxLines(maxLines)
, m_types(types)
{ {
// Allow multiple selections // Allow multiple selections
setSelectionMode(QAbstractItemView::ExtendedSelection); setSelectionMode(QAbstractItemView::ExtendedSelection);
@ -53,6 +54,18 @@ LogListWidget::LogListWidget(int max_lines, QWidget *parent) :
setContextMenuPolicy(Qt::ActionsContextMenu); setContextMenuPolicy(Qt::ActionsContextMenu);
} }
void LogListWidget::showMsgTypes(const Log::MsgTypes &types)
{
m_types = types;
for (int i = 0; i < count(); ++i) {
QListWidgetItem *tempItem = item(i);
if (!tempItem) continue;
Log::MsgType itemType = static_cast<Log::MsgType>(tempItem->data(Qt::UserRole).toInt());
setRowHidden(i, !(m_types & itemType));
}
}
void LogListWidget::keyPressEvent(QKeyEvent *event) void LogListWidget::keyPressEvent(QKeyEvent *event)
{ {
if (event->matches(QKeySequence::Copy)) if (event->matches(QKeySequence::Copy))
@ -61,15 +74,18 @@ void LogListWidget::keyPressEvent(QKeyEvent *event)
selectAll(); selectAll();
} }
void LogListWidget::appendLine(const QString &line) void LogListWidget::appendLine(const QString &line, const Log::MsgType &type)
{ {
QListWidgetItem *item = new QListWidgetItem; QListWidgetItem *item = new QListWidgetItem;
// We need to use QLabel here to support rich text // We need to use QLabel here to support rich text
QLabel *lbl = new QLabel(line); QLabel *lbl = new QLabel(line);
lbl->setContentsMargins(4, 2, 4, 2); lbl->setContentsMargins(4, 2, 4, 2);
item->setSizeHint(lbl->sizeHint()); item->setSizeHint(lbl->sizeHint());
item->setData(Qt::UserRole, type);
insertItem(0, item); insertItem(0, item);
setItemWidget(item, lbl); setItemWidget(item, lbl);
setRowHidden(0, !(m_types & type));
const int nbLines = count(); const int nbLines = count();
// Limit log size // Limit log size
if (nbLines > m_maxLines) if (nbLines > m_maxLines)
@ -78,11 +94,10 @@ void LogListWidget::appendLine(const QString &line)
void LogListWidget::copySelection() void LogListWidget::copySelection()
{ {
static QRegExp html_tag("<[^>]+>"); static QRegExp htmlTag("<[^>]+>");
QList<QListWidgetItem*> items = selectedItems();
QStringList strings; QStringList strings;
foreach (QListWidgetItem* it, items) foreach (QListWidgetItem* it, selectedItems())
strings << static_cast<QLabel*>(itemWidget(it))->text().replace(html_tag, ""); strings << static_cast<QLabel*>(itemWidget(it))->text().replace(htmlTag, "");
QApplication::clipboard()->setText(strings.join("\n")); QApplication::clipboard()->setText(strings.join("\n"));
} }

9
src/gui/loglistwidget.h

@ -31,6 +31,7 @@
#define LOGLISTWIDGET_H #define LOGLISTWIDGET_H
#include <QListWidget> #include <QListWidget>
#include "base/logger.h"
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QKeyEvent; class QKeyEvent;
@ -41,10 +42,12 @@ class LogListWidget: public QListWidget
Q_OBJECT Q_OBJECT
public: public:
explicit LogListWidget(int max_lines = 100, QWidget *parent = 0); // -1 is the portable way to have all the bits set
explicit LogListWidget(int maxLines, const Log::MsgTypes &types = Log::ALL, QWidget *parent = 0);
void showMsgTypes(const Log::MsgTypes &types);
public slots: public slots:
void appendLine(const QString &line); void appendLine(const QString &line, const Log::MsgType &type);
protected slots: protected slots:
void copySelection(); void copySelection();
@ -54,7 +57,7 @@ protected:
private: private:
int m_maxLines; int m_maxLines;
Log::MsgTypes m_types;
}; };
#endif // LOGLISTWIDGET_H #endif // LOGLISTWIDGET_H

74
src/gui/mainwindow.cpp

@ -273,9 +273,20 @@ MainWindow::MainWindow(QWidget *parent)
actionSpeed_in_title_bar->setChecked(pref->speedInTitleBar()); actionSpeed_in_title_bar->setChecked(pref->speedInTitleBar());
actionRSS_Reader->setChecked(pref->isRSSEnabled()); actionRSS_Reader->setChecked(pref->isRSSEnabled());
actionSearch_engine->setChecked(pref->isSearchEnabled()); actionSearch_engine->setChecked(pref->isSearchEnabled());
actionExecution_Logs->setChecked(pref->isExecutionLogEnabled()); actionExecutionLogs->setChecked(pref->isExecutionLogEnabled());
Log::MsgTypes flags(pref->executionLogMessageTypes());
actionNormalMessages->setChecked(flags & Log::NORMAL);
actionInformationMessages->setChecked(flags & Log::INFO);
actionWarningMessages->setChecked(flags & Log::WARNING);
actionCriticalMessages->setChecked(flags & Log::CRITICAL);
displayRSSTab(actionRSS_Reader->isChecked()); displayRSSTab(actionRSS_Reader->isChecked());
on_actionExecution_Logs_triggered(actionExecution_Logs->isChecked()); on_actionExecutionLogs_triggered(actionExecutionLogs->isChecked());
on_actionNormalMessages_triggered(actionNormalMessages->isChecked());
on_actionInformationMessages_triggered(actionInformationMessages->isChecked());
on_actionWarningMessages_triggered(actionWarningMessages->isChecked());
on_actionCriticalMessages_triggered(actionCriticalMessages->isChecked());
if (actionSearch_engine->isChecked()) if (actionSearch_engine->isChecked())
QTimer::singleShot(0, this, SLOT(on_actionSearch_engine_triggered())); QTimer::singleShot(0, this, SLOT(on_actionSearch_engine_triggered()));
@ -1507,7 +1518,7 @@ void MainWindow::minimizeWindow()
setWindowState(windowState() ^ Qt::WindowMinimized); setWindowState(windowState() ^ Qt::WindowMinimized);
} }
void MainWindow::on_actionExecution_Logs_triggered(bool checked) void MainWindow::on_actionExecutionLogs_triggered(bool checked)
{ {
if (checked) { if (checked) {
Q_ASSERT(!m_executionLog); Q_ASSERT(!m_executionLog);
@ -1518,9 +1529,66 @@ void MainWindow::on_actionExecution_Logs_triggered(bool checked)
else if (m_executionLog) { else if (m_executionLog) {
delete m_executionLog; delete m_executionLog;
} }
actionNormalMessages->setEnabled(checked);
actionInformationMessages->setEnabled(checked);
actionWarningMessages->setEnabled(checked);
actionCriticalMessages->setEnabled(checked);
Preferences::instance()->setExecutionLogEnabled(checked); Preferences::instance()->setExecutionLogEnabled(checked);
} }
void MainWindow::on_actionNormalMessages_triggered(bool checked)
{
if (!m_executionLog)
return;
Preferences* const pref = Preferences::instance();
Log::MsgTypes flags(pref->executionLogMessageTypes());
checked ? (flags |= Log::NORMAL) : (flags &= ~Log::NORMAL);
m_executionLog->showMsgTypes(flags);
pref->setExecutionLogMessageTypes(flags);
}
void MainWindow::on_actionInformationMessages_triggered(bool checked)
{
if (!m_executionLog)
return;
Preferences* const pref = Preferences::instance();
Log::MsgTypes flags(pref->executionLogMessageTypes());
checked ? (flags |= Log::INFO) : (flags &= ~Log::INFO);
m_executionLog->showMsgTypes(flags);
pref->setExecutionLogMessageTypes(flags);
}
void MainWindow::on_actionWarningMessages_triggered(bool checked)
{
if (!m_executionLog)
return;
Preferences* const pref = Preferences::instance();
Log::MsgTypes flags(pref->executionLogMessageTypes());
checked ? (flags |= Log::WARNING) : (flags &= ~Log::WARNING);
m_executionLog->showMsgTypes(flags);
pref->setExecutionLogMessageTypes(flags);
}
void MainWindow::on_actionCriticalMessages_triggered(bool checked)
{
if (!m_executionLog)
return;
Preferences* const pref = Preferences::instance();
Log::MsgTypes flags(pref->executionLogMessageTypes());
checked ? (flags |= Log::CRITICAL) : (flags &= ~Log::CRITICAL);
m_executionLog->showMsgTypes(flags);
pref->setExecutionLogMessageTypes(flags);
}
void MainWindow::on_actionAutoExit_qBittorrent_toggled(bool enabled) void MainWindow::on_actionAutoExit_qBittorrent_toggled(bool enabled)
{ {
qDebug() << Q_FUNC_INFO << enabled; qDebug() << Q_FUNC_INFO << enabled;

6
src/gui/mainwindow.h

@ -214,7 +214,11 @@ private slots:
void on_actionTop_tool_bar_triggered(); void on_actionTop_tool_bar_triggered();
void on_action_Import_Torrent_triggered(); void on_action_Import_Torrent_triggered();
void on_actionDonate_money_triggered(); void on_actionDonate_money_triggered();
void on_actionExecution_Logs_triggered(bool checked); void on_actionExecutionLogs_triggered(bool checked);
void on_actionNormalMessages_triggered(bool checked);
void on_actionInformationMessages_triggered(bool checked);
void on_actionWarningMessages_triggered(bool checked);
void on_actionCriticalMessages_triggered(bool checked);
void on_actionAutoExit_qBittorrent_toggled(bool ); void on_actionAutoExit_qBittorrent_toggled(bool );
void on_actionAutoSuspend_system_toggled(bool ); void on_actionAutoSuspend_system_toggled(bool );
void on_actionAutoHibernate_system_toggled(bool ); void on_actionAutoHibernate_system_toggled(bool );

70
src/gui/mainwindow.ui

@ -35,7 +35,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>914</width> <width>914</width>
<height>22</height> <height>21</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menu_Edit"> <widget class="QMenu" name="menu_Edit">
@ -95,12 +95,23 @@
<property name="title"> <property name="title">
<string>&amp;View</string> <string>&amp;View</string>
</property> </property>
<widget class="QMenu" name="menuLog">
<property name="title">
<string>&amp;Log</string>
</property>
<addaction name="actionExecutionLogs"/>
<addaction name="separator"/>
<addaction name="actionNormalMessages"/>
<addaction name="actionInformationMessages"/>
<addaction name="actionWarningMessages"/>
<addaction name="actionCriticalMessages"/>
</widget>
<addaction name="actionTop_tool_bar"/> <addaction name="actionTop_tool_bar"/>
<addaction name="actionSpeed_in_title_bar"/> <addaction name="actionSpeed_in_title_bar"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionSearch_engine"/> <addaction name="actionSearch_engine"/>
<addaction name="actionRSS_Reader"/> <addaction name="actionRSS_Reader"/>
<addaction name="actionExecution_Logs"/> <addaction name="menuLog"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionStatistics"/> <addaction name="actionStatistics"/>
<addaction name="separator"/> <addaction name="separator"/>
@ -340,17 +351,6 @@
<string>P&amp;ause All</string> <string>P&amp;ause All</string>
</property> </property>
</action> </action>
<action name="actionExecution_Logs">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>&amp;Log</string>
</property>
<property name="toolTip">
<string>Execution Log</string>
</property>
</action>
<action name="actionAutoExit_qBittorrent"> <action name="actionAutoExit_qBittorrent">
<property name="checkable"> <property name="checkable">
<bool>true</bool> <bool>true</bool>
@ -414,9 +414,47 @@
<string>Check for Program Updates</string> <string>Check for Program Updates</string>
</property> </property>
</action> </action>
<action name="actionExecutionLogs">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Show</string>
</property>
</action>
<action name="actionNormalMessages">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Normal Messages</string>
</property>
</action>
<action name="actionInformationMessages">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Information Messages</string>
</property>
</action>
<action name="actionWarningMessages">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Warning Messages</string>
</property>
</action>
<action name="actionCriticalMessages">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Critical Messages</string>
</property>
</action>
</widget> </widget>
<resources> <resources/>
<include location="../icons.qrc"/>
</resources>
<connections/> <connections/>
</ui> </ui>

Loading…
Cancel
Save