add checkbox option to clear log (#2963)
This commit is contained in:
parent
297f1f2555
commit
0eae4dbe54
5 changed files with 48 additions and 8 deletions
|
@ -1,18 +1,26 @@
|
||||||
#include "dlg_viewlog.h"
|
#include "dlg_viewlog.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include "settingscache.h"
|
||||||
|
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QPlainTextEdit>
|
#include <QPlainTextEdit>
|
||||||
|
|
||||||
DlgViewLog::DlgViewLog(QWidget *parent)
|
DlgViewLog::DlgViewLog(QWidget *parent) : QDialog(parent)
|
||||||
: QDialog(parent)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
logArea = new QPlainTextEdit;
|
logArea = new QPlainTextEdit;
|
||||||
logArea->setReadOnly(true);
|
logArea->setReadOnly(true);
|
||||||
|
|
||||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
auto *mainLayout = new QVBoxLayout;
|
||||||
mainLayout->addWidget(logArea);
|
mainLayout->addWidget(logArea);
|
||||||
|
|
||||||
|
coClearLog = new QCheckBox;
|
||||||
|
coClearLog->setText(tr("Clear log when closing"));
|
||||||
|
coClearLog->setChecked(settingsCache->servers().getClearDebugLogStatus(true));
|
||||||
|
connect(coClearLog, SIGNAL(toggled(bool)), this, SLOT(actCheckBoxChanged(bool)));
|
||||||
|
mainLayout->addWidget(coClearLog);
|
||||||
|
|
||||||
setLayout(mainLayout);
|
setLayout(mainLayout);
|
||||||
|
|
||||||
setWindowTitle(tr("Debug Log"));
|
setWindowTitle(tr("Debug Log"));
|
||||||
|
@ -22,6 +30,11 @@ DlgViewLog::DlgViewLog(QWidget *parent)
|
||||||
connect(&Logger::getInstance(), SIGNAL(logEntryAdded(QString)), this, SLOT(logEntryAdded(QString)));
|
connect(&Logger::getInstance(), SIGNAL(logEntryAdded(QString)), this, SLOT(logEntryAdded(QString)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DlgViewLog::actCheckBoxChanged(bool abNewValue)
|
||||||
|
{
|
||||||
|
settingsCache->servers().setClearDebugLogStatus(abNewValue);
|
||||||
|
}
|
||||||
|
|
||||||
void DlgViewLog::loadInitialLogBuffer()
|
void DlgViewLog::loadInitialLogBuffer()
|
||||||
{
|
{
|
||||||
QList<QString> logBuffer = Logger::getInstance().getLogBuffer();
|
QList<QString> logBuffer = Logger::getInstance().getLogBuffer();
|
||||||
|
@ -36,6 +49,10 @@ void DlgViewLog::logEntryAdded(QString message)
|
||||||
|
|
||||||
void DlgViewLog::closeEvent(QCloseEvent * /* event */)
|
void DlgViewLog::closeEvent(QCloseEvent * /* event */)
|
||||||
{
|
{
|
||||||
logArea->clear();
|
if (coClearLog->isChecked())
|
||||||
|
{
|
||||||
|
logArea->clear();
|
||||||
|
}
|
||||||
|
|
||||||
logArea->appendPlainText(Logger::getInstance().getClientVersion());
|
logArea->appendPlainText(Logger::getInstance().getClientVersion());
|
||||||
}
|
}
|
|
@ -2,6 +2,7 @@
|
||||||
#define DLG_VIEWLOG_H
|
#define DLG_VIEWLOG_H
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include <QCheckBox>
|
||||||
|
|
||||||
class QPlainTextEdit;
|
class QPlainTextEdit;
|
||||||
class QCloseEvent;
|
class QCloseEvent;
|
||||||
|
@ -13,11 +14,13 @@ public:
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *event);
|
void closeEvent(QCloseEvent *event);
|
||||||
private:
|
private:
|
||||||
QPlainTextEdit *logArea;
|
QPlainTextEdit *logArea;
|
||||||
|
QCheckBox *coClearLog;
|
||||||
|
|
||||||
void loadInitialLogBuffer();
|
void loadInitialLogBuffer();
|
||||||
|
void actCheckBoxChanged(bool abNewValue);
|
||||||
private slots:
|
private slots:
|
||||||
void logEntryAdded(QString message);
|
void logEntryAdded(QString message);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -21,9 +21,13 @@ Logger::~Logger()
|
||||||
void Logger::logToFile(bool enabled)
|
void Logger::logToFile(bool enabled)
|
||||||
{
|
{
|
||||||
if (enabled)
|
if (enabled)
|
||||||
|
{
|
||||||
openLogfileSession();
|
openLogfileSession();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
closeLogfileSession();
|
closeLogfileSession();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Logger::getClientVersion()
|
QString Logger::getClientVersion()
|
||||||
|
@ -34,7 +38,9 @@ QString Logger::getClientVersion()
|
||||||
void Logger::openLogfileSession()
|
void Logger::openLogfileSession()
|
||||||
{
|
{
|
||||||
if (logToFileEnabled)
|
if (logToFileEnabled)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
fileHandle.setFileName(LOGGER_FILENAME);
|
fileHandle.setFileName(LOGGER_FILENAME);
|
||||||
fileHandle.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
|
fileHandle.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
|
||||||
|
|
|
@ -164,6 +164,17 @@ QString ServersSettings::getFPPlayerName(QString defaultName)
|
||||||
return name == QVariant() ? defaultName : name.toString();
|
return name == QVariant() ? defaultName : name.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ServersSettings::setClearDebugLogStatus(bool abIsChecked)
|
||||||
|
{
|
||||||
|
setValue(abIsChecked, "save_debug_log", "server");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ServersSettings::getClearDebugLogStatus(bool abDefaultValue)
|
||||||
|
{
|
||||||
|
QVariant cbFlushLog = getValue("save_debug_log", "server");
|
||||||
|
return cbFlushLog == QVariant() ? abDefaultValue : cbFlushLog.toBool();
|
||||||
|
}
|
||||||
|
|
||||||
void ServersSettings::addNewServer(QString saveName, QString serv, QString port, QString username, QString password, bool savePassword)
|
void ServersSettings::addNewServer(QString saveName, QString serv, QString port, QString username, QString password, bool savePassword)
|
||||||
{
|
{
|
||||||
if (updateExistingServer(saveName, serv, port, username, password, savePassword))
|
if (updateExistingServer(saveName, serv, port, username, password, savePassword))
|
||||||
|
|
|
@ -39,6 +39,9 @@ public:
|
||||||
void setFPPlayerName(QString playerName);
|
void setFPPlayerName(QString playerName);
|
||||||
void addNewServer(QString saveName, QString serv, QString port, QString username, QString password, bool savePassword);
|
void addNewServer(QString saveName, QString serv, QString port, QString username, QString password, bool savePassword);
|
||||||
bool updateExistingServer(QString saveName, QString serv, QString port, QString username, QString password, bool savePassword);
|
bool updateExistingServer(QString saveName, QString serv, QString port, QString username, QString password, bool savePassword);
|
||||||
|
void setClearDebugLogStatus(bool abIsChecked);
|
||||||
|
bool getClearDebugLogStatus(bool abDefaultValue);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
Loading…
Reference in a new issue