mirror of
https://github.com/obhq/obliteration.git
synced 2024-11-23 11:19:56 +00:00
Moves logs viewer into a dedicated Window (#899)
This commit is contained in:
parent
fbf1a45cf6
commit
f873631e05
@ -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
|
||||
|
39
src/logs_viewer.cpp
Normal file
39
src/logs_viewer.cpp
Normal 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
13
src/logs_viewer.hpp
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class LogFormatter;
|
||||
|
||||
class LogsViewer final : public QWidget {
|
||||
public:
|
||||
LogsViewer();
|
||||
~LogsViewer() override;
|
||||
private:
|
||||
LogFormatter *m_formatter;
|
||||
};
|
@ -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 <QMenu>
|
||||
#include <QMenuBar>
|
||||
#include <QMessageBox>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QProgressDialog>
|
||||
#include <QResizeEvent>
|
||||
#include <QScrollBar>
|
||||
@ -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;
|
||||
|
||||
|
@ -3,9 +3,10 @@
|
||||
#include "core.hpp"
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QPointer>
|
||||
|
||||
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<LogsViewer> m_logs;
|
||||
RustPtr<Vmm> m_kernel;
|
||||
};
|
||||
|
@ -2,7 +2,6 @@
|
||||
<RCC version="1.0">
|
||||
<qresource>
|
||||
<file>resources/archive-arrow-down-outline.svg</file>
|
||||
<file>resources/card-text-outline.svg</file>
|
||||
<file>resources/cog-outline.svg</file>
|
||||
<file>resources/fallbackicon0.png</file>
|
||||
<file>resources/folder-open-outline.svg</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 |
Loading…
Reference in New Issue
Block a user