Moves logs viewer into a dedicated Window (#899)

This commit is contained in:
Putta Khunchalee 2024-07-25 13:18:44 +07:00 committed by GitHub
parent fbf1a45cf6
commit f873631e05
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 91 additions and 32 deletions

View File

@ -57,6 +57,7 @@ add_executable(obliteration WIN32 MACOSX_BUNDLE
initialize_wizard.cpp initialize_wizard.cpp
launch_settings.cpp launch_settings.cpp
log_formatter.cpp log_formatter.cpp
logs_viewer.cpp
main.cpp main.cpp
main_window.cpp main_window.cpp
path.cpp path.cpp

39
src/logs_viewer.cpp Normal file
View File

@ -0,0 +1,39 @@
#include "logs_viewer.hpp"
#include "log_formatter.hpp"
#include <QHBoxLayout>
#include <QPlainTextEdit>
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()
{
}

13
src/logs_viewer.hpp Normal file
View File

@ -0,0 +1,13 @@
#pragma once
#include <QWidget>
class LogFormatter;
class LogsViewer final : public QWidget {
public:
LogsViewer();
~LogsViewer() override;
private:
LogFormatter *m_formatter;
};

View File

@ -3,7 +3,7 @@
#include "game_settings.hpp" #include "game_settings.hpp"
#include "game_settings_dialog.hpp" #include "game_settings_dialog.hpp"
#include "launch_settings.hpp" #include "launch_settings.hpp"
#include "log_formatter.hpp" #include "logs_viewer.hpp"
#include "path.hpp" #include "path.hpp"
#include "pkg_installer.hpp" #include "pkg_installer.hpp"
#include "resources.hpp" #include "resources.hpp"
@ -21,7 +21,6 @@
#include <QMenu> #include <QMenu>
#include <QMenuBar> #include <QMenuBar>
#include <QMessageBox> #include <QMessageBox>
#include <QPlainTextEdit>
#include <QProgressDialog> #include <QProgressDialog>
#include <QResizeEvent> #include <QResizeEvent>
#include <QScrollBar> #include <QScrollBar>
@ -39,8 +38,7 @@ MainWindow::MainWindow() :
m_tab(nullptr), m_tab(nullptr),
m_screen(nullptr), m_screen(nullptr),
m_launch(nullptr), m_launch(nullptr),
m_games(nullptr), m_games(nullptr)
m_log(nullptr)
{ {
setWindowTitle("Obliteration"); setWindowTitle("Obliteration");
@ -64,6 +62,14 @@ MainWindow::MainWindow() :
fileMenu->addSeparator(); fileMenu->addSeparator();
fileMenu->addAction(quit); 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. // Help menu.
auto helpMenu = menuBar()->addMenu("&Help"); auto helpMenu = menuBar()->addMenu("&Help");
auto reportIssue = new QAction("&Report Issue", this); auto reportIssue = new QAction("&Report Issue", this);
@ -110,25 +116,6 @@ MainWindow::MainWindow() :
m_tab->addTab(m_games, loadIcon(":/resources/view-comfy.svg"), "Games"); 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. // Show the window.
restoreGeometry(); restoreGeometry();
} }
@ -173,6 +160,9 @@ bool MainWindow::loadGames()
void MainWindow::closeEvent(QCloseEvent *event) void MainWindow::closeEvent(QCloseEvent *event)
{ {
// This will set to accept by QMainWindow::closeEvent.
event->ignore();
// Ask user to confirm. // Ask user to confirm.
if (m_kernel) { if (m_kernel) {
QMessageBox confirm(this); QMessageBox confirm(this);
@ -184,13 +174,17 @@ void MainWindow::closeEvent(QCloseEvent *event)
confirm.setIcon(QMessageBox::Warning); confirm.setIcon(QMessageBox::Warning);
if (confirm.exec() != QMessageBox::Yes) { if (confirm.exec() != QMessageBox::Yes) {
event->ignore();
return; return;
} }
m_kernel.free(); m_kernel.free();
} }
// Close child windows.
if (m_logs && !m_logs->close()) {
return;
}
// Save geometry. // Save geometry.
QSettings settings; QSettings settings;
@ -244,6 +238,22 @@ void MainWindow::openSystemFolder()
QDesktopServices::openUrl(QUrl::fromLocalFile(folderPath)); 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() void MainWindow::reportIssue()
{ {
if (!QDesktopServices::openUrl(QUrl("https://github.com/obhq/obliteration/issues"))) { if (!QDesktopServices::openUrl(QUrl("https://github.com/obhq/obliteration/issues"))) {
@ -308,10 +318,6 @@ void MainWindow::startKernel()
return; return;
} }
// Clear previous log and switch to screen tab.
m_log->reset();
m_tab->setCurrentIndex(0);
// Get full path to kernel binary. // Get full path to kernel binary.
std::string kernel; std::string kernel;

View File

@ -3,9 +3,10 @@
#include "core.hpp" #include "core.hpp"
#include <QMainWindow> #include <QMainWindow>
#include <QPointer>
class LaunchSettings; class LaunchSettings;
class LogFormatter; class LogsViewer;
class QStackedWidget; class QStackedWidget;
class QTableView; class QTableView;
@ -23,6 +24,7 @@ protected:
private slots: private slots:
void installPkg(); void installPkg();
void openSystemFolder(); void openSystemFolder();
void viewLogs();
void reportIssue(); void reportIssue();
void aboutObliteration(); void aboutObliteration();
void requestGamesContextMenu(const QPoint &pos); void requestGamesContextMenu(const QPoint &pos);
@ -38,6 +40,6 @@ private:
QStackedWidget *m_screen; QStackedWidget *m_screen;
LaunchSettings *m_launch; LaunchSettings *m_launch;
QTableView *m_games; QTableView *m_games;
LogFormatter *m_log; QPointer<LogsViewer> m_logs;
RustPtr<Vmm> m_kernel; RustPtr<Vmm> m_kernel;
}; };

View File

@ -2,7 +2,6 @@
<RCC version="1.0"> <RCC version="1.0">
<qresource> <qresource>
<file>resources/archive-arrow-down-outline.svg</file> <file>resources/archive-arrow-down-outline.svg</file>
<file>resources/card-text-outline.svg</file>
<file>resources/cog-outline.svg</file> <file>resources/cog-outline.svg</file>
<file>resources/fallbackicon0.png</file> <file>resources/fallbackicon0.png</file>
<file>resources/folder-open-outline.svg</file> <file>resources/folder-open-outline.svg</file>

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20,20H4A2,2 0 0,1 2,18V6A2,2 0 0,1 4,4H20A2,2 0 0,1 22,6V18A2,2 0 0,1 20,20M4,6V18H20V6H4M6,9H18V11H6V9M6,13H16V15H6V13Z" /></svg>

Before

Width:  |  Height:  |  Size: 200 B