Logger tweaks

Commit amended for code style and minor cleanup by Adam Honse <calcprogrammer1@gmail.com>
This commit is contained in:
k1-801 2021-03-24 02:38:30 +04:00 committed by Adam Honse
parent 0089852395
commit f1d6c2953d
6 changed files with 387 additions and 125 deletions

View file

@ -13,10 +13,12 @@
#include "ProfileManager.h"
#include "RGBController.h"
#include "i2c_smbus.h"
#include "LogManager.h"
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <thread>
#include <QMessageBox>
#include "OpenRGBDialog2.h"
@ -132,6 +134,50 @@ bool AttemptLocalConnection()
return success;
}
/******************************************************************************************\
* *
* MessageBoxCallback *
* *
* Displays a message box when an error occurs. Only call once GUI is initialized *
* *
\******************************************************************************************/
void MessageBoxCallback(void*, PLogMessage message)
{
/*---------------------------------------------------------*\
| Create a message box |
\*---------------------------------------------------------*/
QMessageBox box;
/*---------------------------------------------------------*\
| Set the box main text to the log message text |
\*---------------------------------------------------------*/
box.setText(QString::fromStdString(message->buffer));
/*---------------------------------------------------------*\
| Set the informative text from the message information |
\*---------------------------------------------------------*/
QString info = "Occured in ";
info += message->filename;
info += " on line " + QVariant(message->line).toString();
box.setInformativeText(info);
/*---------------------------------------------------------*\
| Set the message box icon according to message level |
\*---------------------------------------------------------*/
switch(message->level)
{
case LL_CRITICAL: box.setIcon(QMessageBox::Critical); break;
case LL_ERROR: box.setIcon(QMessageBox::Warning); break;
case LL_MESSAGE: box.setIcon(QMessageBox::Information); break;
}
/*---------------------------------------------------------*\
| Show the message box |
\*---------------------------------------------------------*/
box.exec();
}
/******************************************************************************************\
* *
* main *
@ -232,6 +278,11 @@ int main(int argc, char* argv[])
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication a(argc, argv);
/*---------------------------------------------------------*\
| Register the message box callback with the log manager |
\*---------------------------------------------------------*/
LogManager::get()->registerErrorCallback(&MessageBoxCallback, nullptr);
Ui::OpenRGBDialog2 dlg;
if(ret_flags & RET_FLAG_I2C_TOOLS)