From 4124faf474908e4d79d93b0f624bf8fd81bd9972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 23 Nov 2013 01:41:28 +0100 Subject: Fix console window (now not a QDialog) It now opens and coloses as expected, depending on user preferences and the status of the various processes involved. Console window geometry and state are remembered between runs. --- gui/ConsoleWindow.cpp | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'gui/ConsoleWindow.cpp') diff --git a/gui/ConsoleWindow.cpp b/gui/ConsoleWindow.cpp index 1a888330..d8a1b69d 100644 --- a/gui/ConsoleWindow.cpp +++ b/gui/ConsoleWindow.cpp @@ -15,6 +15,7 @@ #include "ConsoleWindow.h" #include "ui_ConsoleWindow.h" +#include "MultiMC.h" #include #include @@ -23,13 +24,26 @@ #include ConsoleWindow::ConsoleWindow(MinecraftProcess *mcproc, QWidget *parent) - : QDialog(parent), ui(new Ui::ConsoleWindow), m_mayclose(true), proc(mcproc) + : QMainWindow(parent), ui(new Ui::ConsoleWindow), proc(mcproc) { MultiMCPlatform::fixWM_CLASS(this); ui->setupUi(this); - this->setWindowFlags(Qt::Window); + connect(mcproc, SIGNAL(log(QString, MessageLevel::Enum)), this, + SLOT(write(QString, MessageLevel::Enum))); connect(mcproc, SIGNAL(ended(BaseInstance *, int, QProcess::ExitStatus)), this, SLOT(onEnded(BaseInstance *, int, QProcess::ExitStatus))); + connect(mcproc, SIGNAL(prelaunch_failed(BaseInstance*,int,QProcess::ExitStatus)), this, + SLOT(onEnded(BaseInstance *, int, QProcess::ExitStatus))); + connect(mcproc, SIGNAL(launch_failed(BaseInstance*)), this, + SLOT(onLaunchFailed(BaseInstance*))); + + restoreState(QByteArray::fromBase64(MMC->settings()->get("ConsoleWindowState").toByteArray())); + restoreGeometry(QByteArray::fromBase64(MMC->settings()->get("ConsoleWindowGeometry").toByteArray())); + + if (mcproc->instance()->settings().get("ShowConsole").toBool()) + { + show(); + } } ConsoleWindow::~ConsoleWindow() @@ -105,7 +119,13 @@ void ConsoleWindow::closeEvent(QCloseEvent *event) if (!m_mayclose) event->ignore(); else - QDialog::closeEvent(event); + { + MMC->settings()->set("ConsoleWindowState", saveState().toBase64()); + MMC->settings()->set("ConsoleWindowGeometry", saveGeometry().toBase64()); + + emit isClosing(); + QMainWindow::closeEvent(event); + } } void ConsoleWindow::on_btnKillMinecraft_clicked() @@ -131,6 +151,16 @@ void ConsoleWindow::onEnded(BaseInstance *instance, int code, QProcess::ExitStat if (code == 0 && status != QProcess::CrashExit) { this->close(); + return; } } + if(!isVisible()) + show(); +} + +void ConsoleWindow::onLaunchFailed(BaseInstance *instance) +{ + ui->btnKillMinecraft->setEnabled(false); + if(!isVisible()) + show(); } -- cgit v1.2.3