Add console page

This commit is contained in:
morg 2021-10-05 09:18:18 +02:00 committed by Adam Honse
parent f834555fd1
commit 8de3928080
11 changed files with 215 additions and 2 deletions

View file

@ -9,7 +9,7 @@
#include "filesystem.h"
static const char* log_codes[] = {"FATAL:", "ERROR:", "Warning:", "Info:", "Verbose:", "Debug:", "Trace:"};
const char* LogManager::log_codes[] = {"FATAL:", "ERROR:", "Warning:", "Info:", "Verbose:", "Debug:", "Trace:"};
LogManager::LogManager()
{
@ -224,6 +224,8 @@ void LogManager::_append(const char* filename, int line, unsigned int level, con
\*-------------------------------------------------*/
temp_messages.push_back(mes);
all_messages.push_back(mes);
/*-------------------------------------------------*\
| Flush the queues |
\*-------------------------------------------------*/
@ -245,6 +247,16 @@ void LogManager::_append(const char* filename, int line, unsigned int level, con
//}
}
std::vector<PLogMessage> LogManager::messages()
{
return all_messages;
}
void LogManager::clearMessages()
{
all_messages.clear();
}
void LogManager::append(const char* filename, int line, unsigned int level, const char* fmt, ...)
{
va_list va;

View file

@ -57,6 +57,9 @@ private:
// A temporary log message storage to hold them until the stream opens
std::vector<PLogMessage> temp_messages;
// A log message storage that will be displayed in the app
std::vector<PLogMessage> all_messages;
// A flag that marks if the message source file name and line number should be printed on screen
bool print_source = false;
@ -87,6 +90,10 @@ public:
void unregisterErrorCallback(LogErrorCallback callback, void* receiver);
unsigned int getLoglevel() {return loglevel;}
unsigned int getVerbosity() {return verbosity;}
void clearMessages();
std::vector<PLogMessage> messages();
static const char* log_codes[];
};
#define LogAppend(level, ...) LogManager::get()->append(__FILE__, __LINE__, level, __VA_ARGS__)

View file

@ -165,6 +165,7 @@ HEADERS +=
filesystem.h \
qt/DetectorTableModel.h \
qt/OpenRGBClientInfoPage.h \
qt/OpenRGBConsolePage.h \
qt/OpenRGBDeviceInfoPage.h \
qt/OpenRGBDevicePage.h \
qt/OpenRGBDialog.h \
@ -503,6 +504,7 @@ SOURCES +=
SettingsManager.cpp \
qt/DetectorTableModel.cpp \
qt/OpenRGBClientInfoPage.cpp \
qt/OpenRGBConsolePage.cpp \
qt/OpenRGBDeviceInfoPage.cpp \
qt/OpenRGBDevicePage.cpp \
qt/OpenRGBDialog.cpp \
@ -867,6 +869,7 @@ RESOURCES +=
FORMS += \
qt/OpenRGBClientInfoPage.ui \
qt/OpenRGBConsolePage.ui \
qt/OpenRGBDeviceInfoPage.ui \
qt/OpenRGBDevicePage.ui \
qt/OpenRGBDialog.ui \

72
qt/OpenRGBConsolePage.cpp Normal file
View file

@ -0,0 +1,72 @@
#include "OpenRGBConsolePage.h"
#include "LogManager.h"
#include <stdio.h>
using namespace Ui;
OpenRGBConsolePage::OpenRGBConsolePage(QWidget *parent) :
QFrame(parent),
ui(new Ui::OpenRGBConsolePageUi)
{
ui->setupUi(this);
ui->log_level->blockSignals(true);
ui->log_level->addItems({
"Fatal",
"Error",
"Warning",
"Info",
"Verbose",
"Debug",
"Trace"
});
ui->log_level->setCurrentIndex(LogManager::get()->getLoglevel());
ui->log_level->blockSignals(false);
Refresh();
}
void OpenRGBConsolePage::Refresh()
{
QString log;
unsigned int current_level = LogManager::get()->getLoglevel();
for(PLogMessage& message: LogManager::get()->messages())
{
unsigned int message_level = message.get()->level;
if(message_level <= current_level)
{
log += "[";
log += LogManager::log_codes[message_level];
log += "] ";
log += QString::fromStdString(message.get()->buffer);
log += "\n";
}
}
ui->logs->setText(log);
}
void OpenRGBConsolePage::on_log_level_currentIndexChanged(int index)
{
LogManager::get()->setLoglevel(index);
}
void OpenRGBConsolePage::on_clear_clicked()
{
LogManager::get()->clearMessages();
ui->logs->clear();
}
void OpenRGBConsolePage::on_refresh_clicked()
{
Refresh();
}
OpenRGBConsolePage::~OpenRGBConsolePage()
{
delete ui;
}

30
qt/OpenRGBConsolePage.h Normal file
View file

@ -0,0 +1,30 @@
#ifndef OPENRGBCONSOLEPAGE_H
#define OPENRGBCONSOLEPAGE_H
#include <QFrame>
#include "ui_OpenRGBConsolePage.h"
namespace Ui {
class OpenRGBConsolePage;
}
class Ui::OpenRGBConsolePage : public QFrame
{
Q_OBJECT
public:
explicit OpenRGBConsolePage(QWidget *parent = nullptr);
~OpenRGBConsolePage();
private slots:
void on_log_level_currentIndexChanged(int);
void on_clear_clicked();
void on_refresh_clicked();
private:
Ui::OpenRGBConsolePageUi *ui;
void Refresh();
};
#endif // OPENRGBCONSOLEPAGE_H

54
qt/OpenRGBConsolePage.ui Normal file
View file

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>OpenRGBConsolePageUi</class>
<widget class="QFrame" name="OpenRGBConsolePageUi">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1328</width>
<height>915</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Log level</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="log_level"/>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="refresh">
<property name="text">
<string>Refresh logs</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QPushButton" name="clear">
<property name="text">
<string>Clear log</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="4">
<widget class="QTextEdit" name="logs">
<property name="font">
<font>
<family>Monospace</family>
</font>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -3,6 +3,7 @@
#include "OpenRGBDevicePage.h"
#include "OpenRGBDeviceInfoPage.h"
#include "OpenRGBServerInfoPage.h"
#include "OpenRGBConsolePage.h"
#include "OpenRGBPluginContainer.h"
#include "OpenRGBProfileSaveDialog.h"
#include "ResourceManager.h"
@ -474,7 +475,13 @@ OpenRGBDialog2::OpenRGBDialog2(QWidget *parent) : QMainWindow(parent), ui(new Op
if(ShowI2CTools)
{
AddI2CToolsPage();
}
}
/*-----------------------------------------------------*\
| Add the console page |
\*-----------------------------------------------------*/
AddConsolePage();
}
OpenRGBDialog2::~OpenRGBDialog2()
@ -1679,3 +1686,28 @@ void Ui::OpenRGBDialog2::TogglePluginsVisibility(int tab_idx, QTabWidget* tabBar
((OpenRGBPluginContainer*) tab)->Show();
}
}
void Ui::OpenRGBDialog2::AddConsolePage()
{
OpenRGBConsolePage* page = new OpenRGBConsolePage();
ui->InformationTabBar->addTab(page, "");
QString SoftwareLabelString;
if(IsDarkTheme())
{
SoftwareLabelString = "console_dark.png";
}
else
{
SoftwareLabelString = "console.png";
}
/*-----------------------------------------------------*\
| Create the tab label |
\*-----------------------------------------------------*/
TabLabel* SoftwareTabLabel = new TabLabel(SoftwareLabelString, "Console");
ui->InformationTabBar->tabBar()->setTabButton(ui->InformationTabBar->tabBar()->count() - 1, QTabBar::LeftSide, SoftwareTabLabel);
}

View file

@ -97,6 +97,7 @@ private:
void AddSerialSettingsPage();
void AddYeelightSettingsPage();
void AddPluginsPage(PluginManager* plugin_manager);
void AddConsolePage();
void ClearDevicesList();
void UpdateDevicesList();

BIN
qt/console.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

BIN
qt/console_dark.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

View file

@ -44,5 +44,7 @@
<file>serial_dark.png</file>
<file>wireless.png</file>
<file>wireless_dark.png</file>
<file>console.png</file>
<file>console_dark.png</file>
</qresource>
</RCC>