mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-15 03:28:49 -07:00
Fix crash on logger; make log window modalless (#2659)
This commit is contained in:
parent
9dd3a04a08
commit
ce77d51a8f
6 changed files with 39 additions and 18 deletions
|
|
@ -33,3 +33,8 @@ void DlgViewLog::logEntryAdded(QString message)
|
||||||
{
|
{
|
||||||
logArea->appendPlainText(message);
|
logArea->appendPlainText(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DlgViewLog::closeEvent(QCloseEvent * /* event */)
|
||||||
|
{
|
||||||
|
logArea->clear();
|
||||||
|
}
|
||||||
|
|
@ -4,11 +4,14 @@
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
|
||||||
class QPlainTextEdit;
|
class QPlainTextEdit;
|
||||||
|
class QCloseEvent;
|
||||||
|
|
||||||
class DlgViewLog : public QDialog {
|
class DlgViewLog : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
DlgViewLog(QWidget *parent);
|
DlgViewLog(QWidget *parent);
|
||||||
|
protected:
|
||||||
|
void closeEvent(QCloseEvent *event);
|
||||||
private:
|
private:
|
||||||
QPlainTextEdit *logArea;
|
QPlainTextEdit *logArea;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,21 +48,24 @@ void Logger::closeLogfileSession()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Logger::log(QtMsgType /* type */, const QMessageLogContext & /* ctx */, const QString &message)
|
void Logger::log(QtMsgType /* type */, const QMessageLogContext & /* ctx */, const QString message)
|
||||||
{
|
{
|
||||||
|
QMetaObject::invokeMethod(this, "internalLog", Qt::QueuedConnection,
|
||||||
|
Q_ARG(const QString &, message)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::internalLog(const QString message)
|
||||||
|
{
|
||||||
|
QMutexLocker locker(&mutex);
|
||||||
|
|
||||||
logBuffer.append(message);
|
logBuffer.append(message);
|
||||||
if (logBuffer.size() > LOGGER_MAX_ENTRIES)
|
if (logBuffer.size() > LOGGER_MAX_ENTRIES)
|
||||||
logBuffer.clear();
|
logBuffer.removeFirst();
|
||||||
|
|
||||||
if (message.size() > 0) {
|
emit logEntryAdded(message);
|
||||||
emit logEntryAdded(message);
|
std::cerr << message.toStdString() << std::endl; // Print to stdout
|
||||||
std::cerr << message.toStdString() << std::endl; // Print to stdout
|
|
||||||
|
|
||||||
if (logToFileEnabled)
|
if (logToFileEnabled)
|
||||||
fileStream << message << endl; // Print to fileStream
|
fileStream << message << endl; // Print to fileStream
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QMutex>
|
||||||
|
|
||||||
class Logger : public QObject {
|
class Logger : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
@ -24,15 +25,17 @@ private:
|
||||||
bool logToFileEnabled;
|
bool logToFileEnabled;
|
||||||
QTextStream fileStream;
|
QTextStream fileStream;
|
||||||
QFile fileHandle;
|
QFile fileHandle;
|
||||||
|
|
||||||
QList<QString> logBuffer;
|
QList<QString> logBuffer;
|
||||||
|
QMutex mutex;
|
||||||
public:
|
public:
|
||||||
void logToFile(bool enabled);
|
void logToFile(bool enabled);
|
||||||
void log(QtMsgType type, const QMessageLogContext &ctx, const QString &message);
|
void log(QtMsgType type, const QMessageLogContext &ctx, const QString message);
|
||||||
QList<QString> getLogBuffer() { return logBuffer; }
|
QList<QString> getLogBuffer() { return logBuffer; }
|
||||||
protected:
|
protected:
|
||||||
void openLogfileSession();
|
void openLogfileSession();
|
||||||
void closeLogfileSession();
|
void closeLogfileSession();
|
||||||
|
protected slots:
|
||||||
|
void internalLog(const QString message);
|
||||||
signals:
|
signals:
|
||||||
void logEntryAdded(QString message);
|
void logEntryAdded(QString message);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -314,8 +314,13 @@ void MainWindow::actUpdate()
|
||||||
|
|
||||||
void MainWindow::actViewLog()
|
void MainWindow::actViewLog()
|
||||||
{
|
{
|
||||||
DlgViewLog dlg(this);
|
if (logviewDialog == nullptr) {
|
||||||
dlg.exec();
|
logviewDialog = new DlgViewLog(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
logviewDialog->show();
|
||||||
|
logviewDialog->raise();
|
||||||
|
logviewDialog->activateWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::serverTimeout()
|
void MainWindow::serverTimeout()
|
||||||
|
|
@ -652,7 +657,7 @@ void MainWindow::createMenus()
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent), localServer(0), bHasActivated(false), cardUpdateProcess(0)
|
: QMainWindow(parent), localServer(0), bHasActivated(false), cardUpdateProcess(0), logviewDialog(0)
|
||||||
{
|
{
|
||||||
connect(settingsCache, SIGNAL(pixmapCacheSizeChanged(int)), this, SLOT(pixmapCacheSizeChanged(int)));
|
connect(settingsCache, SIGNAL(pixmapCacheSizeChanged(int)), this, SLOT(pixmapCacheSizeChanged(int)));
|
||||||
pixmapCacheSizeChanged(settingsCache->getPixmapCacheSize());
|
pixmapCacheSizeChanged(settingsCache->getPixmapCacheSize());
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ class LocalClient;
|
||||||
class LocalServer;
|
class LocalServer;
|
||||||
class ServerInfo_User;
|
class ServerInfo_User;
|
||||||
class QThread;
|
class QThread;
|
||||||
|
class DlgViewLog;
|
||||||
|
|
||||||
class MainWindow : public QMainWindow {
|
class MainWindow : public QMainWindow {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
@ -125,6 +126,7 @@ private:
|
||||||
QMessageBox serverShutdownMessageBox;
|
QMessageBox serverShutdownMessageBox;
|
||||||
QProcess * cardUpdateProcess;
|
QProcess * cardUpdateProcess;
|
||||||
|
|
||||||
|
DlgViewLog * logviewDialog;
|
||||||
public:
|
public:
|
||||||
MainWindow(QWidget *parent = 0);
|
MainWindow(QWidget *parent = 0);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue