diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2a0338c4..d292507d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -57,6 +57,7 @@ add_executable(obliteration WIN32 MACOSX_BUNDLE initialize_wizard.cpp launch_settings.cpp log_formatter.cpp + logs_viewer.cpp main.cpp main_window.cpp path.cpp diff --git a/src/logs_viewer.cpp b/src/logs_viewer.cpp new file mode 100644 index 00000000..4ab317fb --- /dev/null +++ b/src/logs_viewer.cpp @@ -0,0 +1,39 @@ +#include "logs_viewer.hpp" +#include "log_formatter.hpp" + +#include +#include + +LogsViewer::LogsViewer() : + m_formatter(nullptr) +{ + auto layout = new QHBoxLayout(); + + setWindowTitle("Obliteration Logs"); + + // Setup viewer. + auto viewer = new QPlainTextEdit(); + + viewer->setReadOnly(true); + viewer->setLineWrapMode(QPlainTextEdit::NoWrap); + viewer->setMaximumBlockCount(10000); + +#ifdef _WIN32 + viewer->document()->setDefaultFont(QFont("Courier New", 10)); +#elif __APPLE__ + viewer->document()->setDefaultFont(QFont("menlo", 10)); +#else + viewer->document()->setDefaultFont(QFont("monospace", 10)); +#endif + + layout->addWidget(viewer); + + // Setup formatter. + m_formatter = new LogFormatter(viewer, this); + + setLayout(layout); +} + +LogsViewer::~LogsViewer() +{ +} diff --git a/src/logs_viewer.hpp b/src/logs_viewer.hpp new file mode 100644 index 00000000..159d395d --- /dev/null +++ b/src/logs_viewer.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include + +class LogFormatter; + +class LogsViewer final : public QWidget { +public: + LogsViewer(); + ~LogsViewer() override; +private: + LogFormatter *m_formatter; +}; diff --git a/src/main_window.cpp b/src/main_window.cpp index 03f891c4..463f14d1 100644 --- a/src/main_window.cpp +++ b/src/main_window.cpp @@ -3,7 +3,7 @@ #include "game_settings.hpp" #include "game_settings_dialog.hpp" #include "launch_settings.hpp" -#include "log_formatter.hpp" +#include "logs_viewer.hpp" #include "path.hpp" #include "pkg_installer.hpp" #include "resources.hpp" @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -39,8 +38,7 @@ MainWindow::MainWindow() : m_tab(nullptr), m_screen(nullptr), m_launch(nullptr), - m_games(nullptr), - m_log(nullptr) + m_games(nullptr) { setWindowTitle("Obliteration"); @@ -64,6 +62,14 @@ MainWindow::MainWindow() : fileMenu->addSeparator(); fileMenu->addAction(quit); + // View menu. + auto viewMenu = menuBar()->addMenu("&View"); + auto logs = new QAction("Logs", this); + + connect(logs, &QAction::triggered, this, &MainWindow::viewLogs); + + viewMenu->addAction(logs); + // Help menu. auto helpMenu = menuBar()->addMenu("&Help"); auto reportIssue = new QAction("&Report Issue", this); @@ -110,25 +116,6 @@ MainWindow::MainWindow() : m_tab->addTab(m_games, loadIcon(":/resources/view-comfy.svg"), "Games"); - // Setup log view. - auto log = new QPlainTextEdit(); - - log->setReadOnly(true); - log->setLineWrapMode(QPlainTextEdit::NoWrap); - log->setMaximumBlockCount(10000); - -#ifdef _WIN32 - log->document()->setDefaultFont(QFont("Courier New", 10)); -#elif __APPLE__ - log->document()->setDefaultFont(QFont("menlo", 10)); -#else - log->document()->setDefaultFont(QFont("monospace", 10)); -#endif - - m_log = new LogFormatter(log, this); - - m_tab->addTab(log, loadIcon(":/resources/card-text-outline.svg"), "Log"); - // Show the window. restoreGeometry(); } @@ -173,6 +160,9 @@ bool MainWindow::loadGames() void MainWindow::closeEvent(QCloseEvent *event) { + // This will set to accept by QMainWindow::closeEvent. + event->ignore(); + // Ask user to confirm. if (m_kernel) { QMessageBox confirm(this); @@ -184,13 +174,17 @@ void MainWindow::closeEvent(QCloseEvent *event) confirm.setIcon(QMessageBox::Warning); if (confirm.exec() != QMessageBox::Yes) { - event->ignore(); return; } m_kernel.free(); } + // Close child windows. + if (m_logs && !m_logs->close()) { + return; + } + // Save geometry. QSettings settings; @@ -244,6 +238,22 @@ void MainWindow::openSystemFolder() QDesktopServices::openUrl(QUrl::fromLocalFile(folderPath)); } +void MainWindow::viewLogs() +{ + // Check for previous window. + if (m_logs) { + m_logs->activateWindow(); + m_logs->raise(); + return; + } + + // Create a window. + m_logs = new LogsViewer(); + + m_logs->setAttribute(Qt::WA_DeleteOnClose); + m_logs->show(); +} + void MainWindow::reportIssue() { if (!QDesktopServices::openUrl(QUrl("https://github.com/obhq/obliteration/issues"))) { @@ -308,10 +318,6 @@ void MainWindow::startKernel() return; } - // Clear previous log and switch to screen tab. - m_log->reset(); - m_tab->setCurrentIndex(0); - // Get full path to kernel binary. std::string kernel; diff --git a/src/main_window.hpp b/src/main_window.hpp index 8904e65c..df737d88 100644 --- a/src/main_window.hpp +++ b/src/main_window.hpp @@ -3,9 +3,10 @@ #include "core.hpp" #include +#include class LaunchSettings; -class LogFormatter; +class LogsViewer; class QStackedWidget; class QTableView; @@ -23,6 +24,7 @@ protected: private slots: void installPkg(); void openSystemFolder(); + void viewLogs(); void reportIssue(); void aboutObliteration(); void requestGamesContextMenu(const QPoint &pos); @@ -38,6 +40,6 @@ private: QStackedWidget *m_screen; LaunchSettings *m_launch; QTableView *m_games; - LogFormatter *m_log; + QPointer m_logs; RustPtr m_kernel; }; diff --git a/src/resources.qrc b/src/resources.qrc index 1cc11c52..53b7e368 100644 --- a/src/resources.qrc +++ b/src/resources.qrc @@ -2,7 +2,6 @@ resources/archive-arrow-down-outline.svg - resources/card-text-outline.svg resources/cog-outline.svg resources/fallbackicon0.png resources/folder-open-outline.svg diff --git a/src/resources/card-text-outline.svg b/src/resources/card-text-outline.svg deleted file mode 100644 index c2e4c213..00000000 --- a/src/resources/card-text-outline.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file