diff --git a/LogManager.cpp b/LogManager.cpp index f1b10452..99921d06 100644 --- a/LogManager.cpp +++ b/LogManager.cpp @@ -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 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; diff --git a/LogManager.h b/LogManager.h index 36900b2d..cd8e349c 100644 --- a/LogManager.h +++ b/LogManager.h @@ -57,6 +57,9 @@ private: // A temporary log message storage to hold them until the stream opens std::vector temp_messages; + // A log message storage that will be displayed in the app + std::vector 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 messages(); + + static const char* log_codes[]; }; #define LogAppend(level, ...) LogManager::get()->append(__FILE__, __LINE__, level, __VA_ARGS__) diff --git a/OpenRGB.pro b/OpenRGB.pro index d3379bba..29cac60b 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -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 \ diff --git a/qt/OpenRGBConsolePage.cpp b/qt/OpenRGBConsolePage.cpp new file mode 100644 index 00000000..ad5b7edf --- /dev/null +++ b/qt/OpenRGBConsolePage.cpp @@ -0,0 +1,72 @@ +#include "OpenRGBConsolePage.h" +#include "LogManager.h" +#include + +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; +} diff --git a/qt/OpenRGBConsolePage.h b/qt/OpenRGBConsolePage.h new file mode 100644 index 00000000..c4ccbd2c --- /dev/null +++ b/qt/OpenRGBConsolePage.h @@ -0,0 +1,30 @@ +#ifndef OPENRGBCONSOLEPAGE_H +#define OPENRGBCONSOLEPAGE_H + +#include +#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 diff --git a/qt/OpenRGBConsolePage.ui b/qt/OpenRGBConsolePage.ui new file mode 100644 index 00000000..49c2b984 --- /dev/null +++ b/qt/OpenRGBConsolePage.ui @@ -0,0 +1,54 @@ + + + OpenRGBConsolePageUi + + + + 0 + 0 + 1328 + 915 + + + + Form + + + + + + Log level + + + + + + + + + + Refresh logs + + + + + + + Clear log + + + + + + + + Monospace + + + + + + + + + diff --git a/qt/OpenRGBDialog2.cpp b/qt/OpenRGBDialog2.cpp index fc380487..8bb0724c 100644 --- a/qt/OpenRGBDialog2.cpp +++ b/qt/OpenRGBDialog2.cpp @@ -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); +} diff --git a/qt/OpenRGBDialog2.h b/qt/OpenRGBDialog2.h index 823d3310..7488a74d 100644 --- a/qt/OpenRGBDialog2.h +++ b/qt/OpenRGBDialog2.h @@ -97,6 +97,7 @@ private: void AddSerialSettingsPage(); void AddYeelightSettingsPage(); void AddPluginsPage(PluginManager* plugin_manager); + void AddConsolePage(); void ClearDevicesList(); void UpdateDevicesList(); diff --git a/qt/console.png b/qt/console.png new file mode 100644 index 00000000..32ee953a Binary files /dev/null and b/qt/console.png differ diff --git a/qt/console_dark.png b/qt/console_dark.png new file mode 100644 index 00000000..876eebe0 Binary files /dev/null and b/qt/console_dark.png differ diff --git a/qt/resources.qrc b/qt/resources.qrc index 41ee0916..af368c38 100644 --- a/qt/resources.qrc +++ b/qt/resources.qrc @@ -44,5 +44,7 @@ serial_dark.png wireless.png wireless_dark.png + console.png + console_dark.png