Skip to content

Commit 8de3928

Browse files
moooorgCalcProgrammer1
authored andcommitted
Add console page
1 parent f834555 commit 8de3928

File tree

11 files changed

+215
-2
lines changed

11 files changed

+215
-2
lines changed

LogManager.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include "filesystem.h"
1111

12-
static const char* log_codes[] = {"FATAL:", "ERROR:", "Warning:", "Info:", "Verbose:", "Debug:", "Trace:"};
12+
const char* LogManager::log_codes[] = {"FATAL:", "ERROR:", "Warning:", "Info:", "Verbose:", "Debug:", "Trace:"};
1313

1414
LogManager::LogManager()
1515
{
@@ -224,6 +224,8 @@ void LogManager::_append(const char* filename, int line, unsigned int level, con
224224
\*-------------------------------------------------*/
225225
temp_messages.push_back(mes);
226226

227+
all_messages.push_back(mes);
228+
227229
/*-------------------------------------------------*\
228230
| Flush the queues |
229231
\*-------------------------------------------------*/
@@ -245,6 +247,16 @@ void LogManager::_append(const char* filename, int line, unsigned int level, con
245247
//}
246248
}
247249

250+
std::vector<PLogMessage> LogManager::messages()
251+
{
252+
return all_messages;
253+
}
254+
255+
void LogManager::clearMessages()
256+
{
257+
all_messages.clear();
258+
}
259+
248260
void LogManager::append(const char* filename, int line, unsigned int level, const char* fmt, ...)
249261
{
250262
va_list va;

LogManager.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ class LogManager
5757
// A temporary log message storage to hold them until the stream opens
5858
std::vector<PLogMessage> temp_messages;
5959

60+
// A log message storage that will be displayed in the app
61+
std::vector<PLogMessage> all_messages;
62+
6063
// A flag that marks if the message source file name and line number should be printed on screen
6164
bool print_source = false;
6265

@@ -87,6 +90,10 @@ class LogManager
8790
void unregisterErrorCallback(LogErrorCallback callback, void* receiver);
8891
unsigned int getLoglevel() {return loglevel;}
8992
unsigned int getVerbosity() {return verbosity;}
93+
void clearMessages();
94+
std::vector<PLogMessage> messages();
95+
96+
static const char* log_codes[];
9097
};
9198

9299
#define LogAppend(level, ...) LogManager::get()->append(__FILE__, __LINE__, level, __VA_ARGS__)

OpenRGB.pro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ HEADERS +=
165165
filesystem.h \
166166
qt/DetectorTableModel.h \
167167
qt/OpenRGBClientInfoPage.h \
168+
qt/OpenRGBConsolePage.h \
168169
qt/OpenRGBDeviceInfoPage.h \
169170
qt/OpenRGBDevicePage.h \
170171
qt/OpenRGBDialog.h \
@@ -503,6 +504,7 @@ SOURCES +=
503504
SettingsManager.cpp \
504505
qt/DetectorTableModel.cpp \
505506
qt/OpenRGBClientInfoPage.cpp \
507+
qt/OpenRGBConsolePage.cpp \
506508
qt/OpenRGBDeviceInfoPage.cpp \
507509
qt/OpenRGBDevicePage.cpp \
508510
qt/OpenRGBDialog.cpp \
@@ -867,6 +869,7 @@ RESOURCES +=
867869

868870
FORMS += \
869871
qt/OpenRGBClientInfoPage.ui \
872+
qt/OpenRGBConsolePage.ui \
870873
qt/OpenRGBDeviceInfoPage.ui \
871874
qt/OpenRGBDevicePage.ui \
872875
qt/OpenRGBDialog.ui \

qt/OpenRGBConsolePage.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#include "OpenRGBConsolePage.h"
2+
#include "LogManager.h"
3+
#include <stdio.h>
4+
5+
using namespace Ui;
6+
7+
OpenRGBConsolePage::OpenRGBConsolePage(QWidget *parent) :
8+
QFrame(parent),
9+
ui(new Ui::OpenRGBConsolePageUi)
10+
{
11+
ui->setupUi(this);
12+
13+
ui->log_level->blockSignals(true);
14+
ui->log_level->addItems({
15+
"Fatal",
16+
"Error",
17+
"Warning",
18+
"Info",
19+
"Verbose",
20+
"Debug",
21+
"Trace"
22+
});
23+
24+
ui->log_level->setCurrentIndex(LogManager::get()->getLoglevel());
25+
ui->log_level->blockSignals(false);
26+
27+
Refresh();
28+
}
29+
30+
void OpenRGBConsolePage::Refresh()
31+
{
32+
QString log;
33+
34+
unsigned int current_level = LogManager::get()->getLoglevel();
35+
36+
for(PLogMessage& message: LogManager::get()->messages())
37+
{
38+
unsigned int message_level = message.get()->level;
39+
40+
if(message_level <= current_level)
41+
{
42+
log += "[";
43+
log += LogManager::log_codes[message_level];
44+
log += "] ";
45+
log += QString::fromStdString(message.get()->buffer);
46+
log += "\n";
47+
}
48+
}
49+
50+
ui->logs->setText(log);
51+
}
52+
53+
void OpenRGBConsolePage::on_log_level_currentIndexChanged(int index)
54+
{
55+
LogManager::get()->setLoglevel(index);
56+
}
57+
58+
void OpenRGBConsolePage::on_clear_clicked()
59+
{
60+
LogManager::get()->clearMessages();
61+
ui->logs->clear();
62+
}
63+
64+
void OpenRGBConsolePage::on_refresh_clicked()
65+
{
66+
Refresh();
67+
}
68+
69+
OpenRGBConsolePage::~OpenRGBConsolePage()
70+
{
71+
delete ui;
72+
}

qt/OpenRGBConsolePage.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef OPENRGBCONSOLEPAGE_H
2+
#define OPENRGBCONSOLEPAGE_H
3+
4+
#include <QFrame>
5+
#include "ui_OpenRGBConsolePage.h"
6+
7+
namespace Ui {
8+
class OpenRGBConsolePage;
9+
}
10+
11+
class Ui::OpenRGBConsolePage : public QFrame
12+
{
13+
Q_OBJECT
14+
15+
public:
16+
explicit OpenRGBConsolePage(QWidget *parent = nullptr);
17+
~OpenRGBConsolePage();
18+
19+
private slots:
20+
void on_log_level_currentIndexChanged(int);
21+
void on_clear_clicked();
22+
void on_refresh_clicked();
23+
24+
private:
25+
Ui::OpenRGBConsolePageUi *ui;
26+
27+
void Refresh();
28+
};
29+
30+
#endif // OPENRGBCONSOLEPAGE_H

qt/OpenRGBConsolePage.ui

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>OpenRGBConsolePageUi</class>
4+
<widget class="QFrame" name="OpenRGBConsolePageUi">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>1328</width>
10+
<height>915</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Form</string>
15+
</property>
16+
<layout class="QGridLayout" name="gridLayout">
17+
<item row="1" column="0">
18+
<widget class="QLabel" name="label">
19+
<property name="text">
20+
<string>Log level</string>
21+
</property>
22+
</widget>
23+
</item>
24+
<item row="1" column="1">
25+
<widget class="QComboBox" name="log_level"/>
26+
</item>
27+
<item row="1" column="2">
28+
<widget class="QPushButton" name="refresh">
29+
<property name="text">
30+
<string>Refresh logs</string>
31+
</property>
32+
</widget>
33+
</item>
34+
<item row="1" column="3">
35+
<widget class="QPushButton" name="clear">
36+
<property name="text">
37+
<string>Clear log</string>
38+
</property>
39+
</widget>
40+
</item>
41+
<item row="0" column="0" colspan="4">
42+
<widget class="QTextEdit" name="logs">
43+
<property name="font">
44+
<font>
45+
<family>Monospace</family>
46+
</font>
47+
</property>
48+
</widget>
49+
</item>
50+
</layout>
51+
</widget>
52+
<resources/>
53+
<connections/>
54+
</ui>

qt/OpenRGBDialog2.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "OpenRGBDevicePage.h"
44
#include "OpenRGBDeviceInfoPage.h"
55
#include "OpenRGBServerInfoPage.h"
6+
#include "OpenRGBConsolePage.h"
67
#include "OpenRGBPluginContainer.h"
78
#include "OpenRGBProfileSaveDialog.h"
89
#include "ResourceManager.h"
@@ -474,7 +475,13 @@ OpenRGBDialog2::OpenRGBDialog2(QWidget *parent) : QMainWindow(parent), ui(new Op
474475
if(ShowI2CTools)
475476
{
476477
AddI2CToolsPage();
477-
}
478+
}
479+
480+
/*-----------------------------------------------------*\
481+
| Add the console page |
482+
\*-----------------------------------------------------*/
483+
AddConsolePage();
484+
478485
}
479486

480487
OpenRGBDialog2::~OpenRGBDialog2()
@@ -1679,3 +1686,28 @@ void Ui::OpenRGBDialog2::TogglePluginsVisibility(int tab_idx, QTabWidget* tabBar
16791686
((OpenRGBPluginContainer*) tab)->Show();
16801687
}
16811688
}
1689+
1690+
void Ui::OpenRGBDialog2::AddConsolePage()
1691+
{
1692+
OpenRGBConsolePage* page = new OpenRGBConsolePage();
1693+
1694+
ui->InformationTabBar->addTab(page, "");
1695+
1696+
QString SoftwareLabelString;
1697+
1698+
if(IsDarkTheme())
1699+
{
1700+
SoftwareLabelString = "console_dark.png";
1701+
}
1702+
else
1703+
{
1704+
SoftwareLabelString = "console.png";
1705+
}
1706+
1707+
/*-----------------------------------------------------*\
1708+
| Create the tab label |
1709+
\*-----------------------------------------------------*/
1710+
TabLabel* SoftwareTabLabel = new TabLabel(SoftwareLabelString, "Console");
1711+
1712+
ui->InformationTabBar->tabBar()->setTabButton(ui->InformationTabBar->tabBar()->count() - 1, QTabBar::LeftSide, SoftwareTabLabel);
1713+
}

qt/OpenRGBDialog2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class Ui::OpenRGBDialog2 : public QMainWindow
9797
void AddSerialSettingsPage();
9898
void AddYeelightSettingsPage();
9999
void AddPluginsPage(PluginManager* plugin_manager);
100+
void AddConsolePage();
100101

101102
void ClearDevicesList();
102103
void UpdateDevicesList();

qt/console.png

5.44 KB
Loading

qt/console_dark.png

5.46 KB
Loading

0 commit comments

Comments
 (0)