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 +++++++++++- gui/ConsoleWindow.h | 18 ++++-- gui/ConsoleWindow.ui | 151 +++++++++++++++++++++++--------------------------- gui/MainWindow.cpp | 29 +--------- gui/MainWindow.h | 2 +- 5 files changed, 117 insertions(+), 119 deletions(-) (limited to 'gui') 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(); } diff --git a/gui/ConsoleWindow.h b/gui/ConsoleWindow.h index 65786c7e..e0a47bc6 100644 --- a/gui/ConsoleWindow.h +++ b/gui/ConsoleWindow.h @@ -15,7 +15,7 @@ #pragma once -#include +#include #include "logic/MinecraftProcess.h" namespace Ui @@ -23,7 +23,7 @@ namespace Ui class ConsoleWindow; } -class ConsoleWindow : public QDialog +class ConsoleWindow : public QMainWindow { Q_OBJECT @@ -38,6 +38,9 @@ public: */ void setMayClose(bool mayclose); +signals: + void isClosing(); + public slots: /** @@ -67,13 +70,16 @@ slots: void on_closeButton_clicked(); void on_btnKillMinecraft_clicked(); void onEnded(BaseInstance *instance, int code, QProcess::ExitStatus status); + void onLaunchFailed(BaseInstance *instance); + + // FIXME: add handlers for the other MinecraftProcess signals (pre/post launch command + // failures) protected: void closeEvent(QCloseEvent *); private: - Ui::ConsoleWindow *ui; - MinecraftProcess *proc; - bool m_mayclose; + Ui::ConsoleWindow *ui = nullptr; + MinecraftProcess *proc = nullptr; + bool m_mayclose = true; }; - diff --git a/gui/ConsoleWindow.ui b/gui/ConsoleWindow.ui index 472c7c8d..ed1b627b 100644 --- a/gui/ConsoleWindow.ui +++ b/gui/ConsoleWindow.ui @@ -1,99 +1,84 @@ ConsoleWindow - + 0 0 - 610 - 391 + 640 + 440 MultiMC Console - - - 0 - - - 0 - - - 0 - - - 6 - - - - - - 10 - - - - false - - - true - - - - - - Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - false - - - - - - - 6 - - - 6 - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - &Kill Minecraft - - - - - - - &Close - - - - - - + + + + + + + 10 + + + + false + + + true + + + + + + Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + false + + + + + + + 6 + + + 6 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + &Kill Minecraft + + + + + + + &Close + + + + + + + - - text - closeButton - btnKillMinecraft - diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 842014d3..fc1b631c 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -712,27 +712,10 @@ void MainWindow::launchInstance(BaseInstance *instance, LoginResponse response) if (!proc) return; - // Prepare GUI: If it shall stay open disable the required parts - if (MMC->settings()->get("NoHide").toBool()) - { - ui->actionLaunchInstance->setEnabled(false); - } - else - { - this->hide(); - } + this->hide(); console = new ConsoleWindow(proc); - - connect(proc, SIGNAL(log(QString, MessageLevel::Enum)), console, - SLOT(write(QString, MessageLevel::Enum))); - connect(proc, SIGNAL(ended(BaseInstance*,int,QProcess::ExitStatus)), this, - SLOT(instanceEnded(BaseInstance*,int,QProcess::ExitStatus))); - - if (instance->settings().get("ShowConsole").toBool()) - { - console->show(); - } + connect(console, SIGNAL(isClosing()), this, SLOT(instanceEnded())); proc->setLogin(response.username, response.session_id); proc->launch(); @@ -884,15 +867,9 @@ void MainWindow::on_actionEditInstNotes_triggered() } } -void MainWindow::instanceEnded(BaseInstance *instance, int code, QProcess::ExitStatus status) +void MainWindow::instanceEnded() { this->show(); - ui->actionLaunchInstance->setEnabled(m_selectedInstance); - - if (instance->settings().get("AutoCloseConsole").toBool()) - { - console->close(); - } } void MainWindow::checkSetDefaultJava() diff --git a/gui/MainWindow.h b/gui/MainWindow.h index 798df0f9..b1678f76 100644 --- a/gui/MainWindow.h +++ b/gui/MainWindow.h @@ -116,7 +116,7 @@ slots: void on_actionChangeInstLWJGLVersion_triggered(); - void instanceEnded(BaseInstance *instance, int code, QProcess::ExitStatus status); + void instanceEnded(); void on_actionInstanceSettings_triggered(); -- cgit v1.2.3