diff --git a/cockatrice/src/dlg_viewlog.cpp b/cockatrice/src/dlg_viewlog.cpp index 061698ce2..6341dd2f6 100644 --- a/cockatrice/src/dlg_viewlog.cpp +++ b/cockatrice/src/dlg_viewlog.cpp @@ -33,3 +33,8 @@ void DlgViewLog::logEntryAdded(QString message) { logArea->appendPlainText(message); } + +void DlgViewLog::closeEvent(QCloseEvent * /* event */) +{ + logArea->clear(); +} \ No newline at end of file diff --git a/cockatrice/src/dlg_viewlog.h b/cockatrice/src/dlg_viewlog.h index 5d420b1cd..f11be1845 100644 --- a/cockatrice/src/dlg_viewlog.h +++ b/cockatrice/src/dlg_viewlog.h @@ -4,11 +4,14 @@ #include class QPlainTextEdit; +class QCloseEvent; class DlgViewLog : public QDialog { Q_OBJECT public: DlgViewLog(QWidget *parent); +protected: + void closeEvent(QCloseEvent *event); private: QPlainTextEdit *logArea; diff --git a/cockatrice/src/logger.cpp b/cockatrice/src/logger.cpp index 16370af14..e0c1cb9b8 100644 --- a/cockatrice/src/logger.cpp +++ b/cockatrice/src/logger.cpp @@ -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); if (logBuffer.size() > LOGGER_MAX_ENTRIES) - logBuffer.clear(); + logBuffer.removeFirst(); - if (message.size() > 0) { - emit logEntryAdded(message); - std::cerr << message.toStdString() << std::endl; // Print to stdout + emit logEntryAdded(message); + std::cerr << message.toStdString() << std::endl; // Print to stdout - if (logToFileEnabled) - fileStream << message << endl; // Print to fileStream - } - - - - -} \ No newline at end of file + if (logToFileEnabled) + fileStream << message << endl; // Print to fileStream +} diff --git a/cockatrice/src/logger.h b/cockatrice/src/logger.h index c090846f0..ff8131598 100644 --- a/cockatrice/src/logger.h +++ b/cockatrice/src/logger.h @@ -5,6 +5,7 @@ #include #include #include +#include class Logger : public QObject { Q_OBJECT @@ -24,15 +25,17 @@ private: bool logToFileEnabled; QTextStream fileStream; QFile fileHandle; - QList logBuffer; + QMutex mutex; public: 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 getLogBuffer() { return logBuffer; } protected: void openLogfileSession(); void closeLogfileSession(); +protected slots: + void internalLog(const QString message); signals: void logEntryAdded(QString message); }; diff --git a/cockatrice/src/window_main.cpp b/cockatrice/src/window_main.cpp index 54a58da48..10951c738 100644 --- a/cockatrice/src/window_main.cpp +++ b/cockatrice/src/window_main.cpp @@ -314,8 +314,13 @@ void MainWindow::actUpdate() void MainWindow::actViewLog() { - DlgViewLog dlg(this); - dlg.exec(); + if (logviewDialog == nullptr) { + logviewDialog = new DlgViewLog(this); + } + + logviewDialog->show(); + logviewDialog->raise(); + logviewDialog->activateWindow(); } void MainWindow::serverTimeout() @@ -652,7 +657,7 @@ void MainWindow::createMenus() } 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))); pixmapCacheSizeChanged(settingsCache->getPixmapCacheSize()); diff --git a/cockatrice/src/window_main.h b/cockatrice/src/window_main.h index abeaa531a..15c40be83 100644 --- a/cockatrice/src/window_main.h +++ b/cockatrice/src/window_main.h @@ -36,6 +36,7 @@ class LocalClient; class LocalServer; class ServerInfo_User; class QThread; +class DlgViewLog; class MainWindow : public QMainWindow { Q_OBJECT @@ -125,6 +126,7 @@ private: QMessageBox serverShutdownMessageBox; QProcess * cardUpdateProcess; + DlgViewLog * logviewDialog; public: MainWindow(QWidget *parent = 0); ~MainWindow();