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.
This commit is contained in:
parent
7f5eb5d61a
commit
4124faf474
@ -321,8 +321,6 @@ void MultiMC::initGlobalSettings()
|
|||||||
// The cat
|
// The cat
|
||||||
m_settings->registerSetting(new Setting("TheCat", false));
|
m_settings->registerSetting(new Setting("TheCat", false));
|
||||||
|
|
||||||
// Shall the main window hide on instance launch
|
|
||||||
m_settings->registerSetting(new Setting("NoHide", false));
|
|
||||||
|
|
||||||
m_settings->registerSetting(new Setting("InstSortMode", "Name"));
|
m_settings->registerSetting(new Setting("InstSortMode", "Name"));
|
||||||
|
|
||||||
@ -338,6 +336,9 @@ void MultiMC::initGlobalSettings()
|
|||||||
// Window state and geometry
|
// Window state and geometry
|
||||||
m_settings->registerSetting(new Setting("MainWindowState", ""));
|
m_settings->registerSetting(new Setting("MainWindowState", ""));
|
||||||
m_settings->registerSetting(new Setting("MainWindowGeometry", ""));
|
m_settings->registerSetting(new Setting("MainWindowGeometry", ""));
|
||||||
|
|
||||||
|
m_settings->registerSetting(new Setting("ConsoleWindowState", ""));
|
||||||
|
m_settings->registerSetting(new Setting("ConsoleWindowGeometry", ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiMC::initHttpMetaCache()
|
void MultiMC::initHttpMetaCache()
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
#include "ConsoleWindow.h"
|
#include "ConsoleWindow.h"
|
||||||
#include "ui_ConsoleWindow.h"
|
#include "ui_ConsoleWindow.h"
|
||||||
|
#include "MultiMC.h"
|
||||||
|
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
@ -23,13 +24,26 @@
|
|||||||
#include <gui/dialogs/CustomMessageBox.h>
|
#include <gui/dialogs/CustomMessageBox.h>
|
||||||
|
|
||||||
ConsoleWindow::ConsoleWindow(MinecraftProcess *mcproc, QWidget *parent)
|
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);
|
MultiMCPlatform::fixWM_CLASS(this);
|
||||||
ui->setupUi(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,
|
connect(mcproc, SIGNAL(ended(BaseInstance *, int, QProcess::ExitStatus)), this,
|
||||||
SLOT(onEnded(BaseInstance *, int, QProcess::ExitStatus)));
|
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()
|
ConsoleWindow::~ConsoleWindow()
|
||||||
@ -105,7 +119,13 @@ void ConsoleWindow::closeEvent(QCloseEvent *event)
|
|||||||
if (!m_mayclose)
|
if (!m_mayclose)
|
||||||
event->ignore();
|
event->ignore();
|
||||||
else
|
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()
|
void ConsoleWindow::on_btnKillMinecraft_clicked()
|
||||||
@ -131,6 +151,16 @@ void ConsoleWindow::onEnded(BaseInstance *instance, int code, QProcess::ExitStat
|
|||||||
if (code == 0 && status != QProcess::CrashExit)
|
if (code == 0 && status != QProcess::CrashExit)
|
||||||
{
|
{
|
||||||
this->close();
|
this->close();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(!isVisible())
|
||||||
|
show();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleWindow::onLaunchFailed(BaseInstance *instance)
|
||||||
|
{
|
||||||
|
ui->btnKillMinecraft->setEnabled(false);
|
||||||
|
if(!isVisible())
|
||||||
|
show();
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QMainWindow>
|
||||||
#include "logic/MinecraftProcess.h"
|
#include "logic/MinecraftProcess.h"
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
@ -23,7 +23,7 @@ namespace Ui
|
|||||||
class ConsoleWindow;
|
class ConsoleWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConsoleWindow : public QDialog
|
class ConsoleWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@ -38,6 +38,9 @@ public:
|
|||||||
*/
|
*/
|
||||||
void setMayClose(bool mayclose);
|
void setMayClose(bool mayclose);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void isClosing();
|
||||||
|
|
||||||
public
|
public
|
||||||
slots:
|
slots:
|
||||||
/**
|
/**
|
||||||
@ -67,13 +70,16 @@ slots:
|
|||||||
void on_closeButton_clicked();
|
void on_closeButton_clicked();
|
||||||
void on_btnKillMinecraft_clicked();
|
void on_btnKillMinecraft_clicked();
|
||||||
void onEnded(BaseInstance *instance, int code, QProcess::ExitStatus status);
|
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:
|
protected:
|
||||||
void closeEvent(QCloseEvent *);
|
void closeEvent(QCloseEvent *);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ConsoleWindow *ui;
|
Ui::ConsoleWindow *ui = nullptr;
|
||||||
MinecraftProcess *proc;
|
MinecraftProcess *proc = nullptr;
|
||||||
bool m_mayclose;
|
bool m_mayclose = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,31 +1,20 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<ui version="4.0">
|
<ui version="4.0">
|
||||||
<class>ConsoleWindow</class>
|
<class>ConsoleWindow</class>
|
||||||
<widget class="QDialog" name="ConsoleWindow">
|
<widget class="QMainWindow" name="ConsoleWindow">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>610</width>
|
<width>640</width>
|
||||||
<height>391</height>
|
<height>440</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>MultiMC Console</string>
|
<string>MultiMC Console</string>
|
||||||
</property>
|
</property>
|
||||||
|
<widget class="QWidget" name="centralwidget">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<property name="leftMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="topMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="rightMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="bottomMargin">
|
|
||||||
<number>6</number>
|
|
||||||
</property>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPlainTextEdit" name="text">
|
<widget class="QPlainTextEdit" name="text">
|
||||||
<property name="font">
|
<property name="font">
|
||||||
@ -89,11 +78,7 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<tabstops>
|
</widget>
|
||||||
<tabstop>text</tabstop>
|
|
||||||
<tabstop>closeButton</tabstop>
|
|
||||||
<tabstop>btnKillMinecraft</tabstop>
|
|
||||||
</tabstops>
|
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
@ -712,27 +712,10 @@ void MainWindow::launchInstance(BaseInstance *instance, LoginResponse response)
|
|||||||
if (!proc)
|
if (!proc)
|
||||||
return;
|
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);
|
console = new ConsoleWindow(proc);
|
||||||
|
connect(console, SIGNAL(isClosing()), this, SLOT(instanceEnded()));
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
proc->setLogin(response.username, response.session_id);
|
proc->setLogin(response.username, response.session_id);
|
||||||
proc->launch();
|
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();
|
this->show();
|
||||||
ui->actionLaunchInstance->setEnabled(m_selectedInstance);
|
|
||||||
|
|
||||||
if (instance->settings().get("AutoCloseConsole").toBool())
|
|
||||||
{
|
|
||||||
console->close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::checkSetDefaultJava()
|
void MainWindow::checkSetDefaultJava()
|
||||||
|
@ -116,7 +116,7 @@ slots:
|
|||||||
|
|
||||||
void on_actionChangeInstLWJGLVersion_triggered();
|
void on_actionChangeInstLWJGLVersion_triggered();
|
||||||
|
|
||||||
void instanceEnded(BaseInstance *instance, int code, QProcess::ExitStatus status);
|
void instanceEnded();
|
||||||
|
|
||||||
void on_actionInstanceSettings_triggered();
|
void on_actionInstanceSettings_triggered();
|
||||||
|
|
||||||
|
@ -48,12 +48,9 @@ void InstanceLauncher::onLoginComplete()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console = new ConsoleWindow(proc);
|
console = new ConsoleWindow(proc);
|
||||||
console->show();
|
connect(console, SIGNAL(isClosing()), this, SLOT(onTerminated()));
|
||||||
|
|
||||||
connect(proc, SIGNAL(ended()), SLOT(onTerminated()));
|
|
||||||
connect(proc, SIGNAL(log(QString, MessageLevel::Enum)), console,
|
|
||||||
SLOT(write(QString, MessageLevel::Enum)));
|
|
||||||
|
|
||||||
|
proc->setLogin(result.username, result.session_id);
|
||||||
proc->launch();
|
proc->launch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ void MinecraftProcess::on_stdOut()
|
|||||||
for (int i = 0; i < lines.size() - 1; i++)
|
for (int i = 0; i < lines.size() - 1; i++)
|
||||||
{
|
{
|
||||||
QString &line = lines[i];
|
QString &line = lines[i];
|
||||||
emit log(line /*.replace(username, "<Username>").replace(sessionID, "<Session ID>")*/,
|
emit log(line.replace(username, "<Username>").replace(sessionID, "<Session ID>"),
|
||||||
getLevel(line, MessageLevel::Message));
|
getLevel(line, MessageLevel::Message));
|
||||||
}
|
}
|
||||||
if (!complete)
|
if (!complete)
|
||||||
@ -139,7 +139,8 @@ void MinecraftProcess::finish(int code, ExitStatus status)
|
|||||||
m_prepostlaunchprocess.waitForFinished();
|
m_prepostlaunchprocess.waitForFinished();
|
||||||
if (m_prepostlaunchprocess.exitStatus() != NormalExit)
|
if (m_prepostlaunchprocess.exitStatus() != NormalExit)
|
||||||
{
|
{
|
||||||
// TODO: error handling
|
emit postlaunch_failed(m_instance, m_prepostlaunchprocess.exitCode(),
|
||||||
|
m_prepostlaunchprocess.exitStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_instance->cleanupAfterRun();
|
m_instance->cleanupAfterRun();
|
||||||
@ -160,7 +161,9 @@ void MinecraftProcess::launch()
|
|||||||
m_prepostlaunchprocess.waitForFinished();
|
m_prepostlaunchprocess.waitForFinished();
|
||||||
if (m_prepostlaunchprocess.exitStatus() != NormalExit)
|
if (m_prepostlaunchprocess.exitStatus() != NormalExit)
|
||||||
{
|
{
|
||||||
// TODO: error handling
|
m_instance->cleanupAfterRun();
|
||||||
|
emit prelaunch_failed(m_instance, m_prepostlaunchprocess.exitCode(),
|
||||||
|
m_prepostlaunchprocess.exitStatus());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -171,15 +174,15 @@ void MinecraftProcess::launch()
|
|||||||
QString JavaPath = m_instance->settings().get("JavaPath").toString();
|
QString JavaPath = m_instance->settings().get("JavaPath").toString();
|
||||||
emit log(QString("Java path: '%1'").arg(JavaPath));
|
emit log(QString("Java path: '%1'").arg(JavaPath));
|
||||||
emit log(QString("Arguments: '%1'").arg(
|
emit log(QString("Arguments: '%1'").arg(
|
||||||
m_args.join("' '") /*.replace(username, "<Username>").replace(sessionID, "<Session
|
m_args.join("' '").replace(username, "<Username>").replace(sessionID, "<Session ID>")));
|
||||||
ID>")*/));
|
|
||||||
start(JavaPath, m_args);
|
start(JavaPath, m_args);
|
||||||
if (!waitForStarted())
|
if (!waitForStarted())
|
||||||
{
|
{
|
||||||
//: Error message displayed if instace can't start
|
//: Error message displayed if instace can't start
|
||||||
emit log(tr("Could not launch minecraft!"));
|
emit log(tr("Could not launch minecraft!"), MessageLevel::Error);
|
||||||
|
m_instance->cleanupAfterRun();
|
||||||
|
emit launch_failed(m_instance);
|
||||||
return;
|
return;
|
||||||
// TODO: error handling
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,6 +58,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
void launch();
|
void launch();
|
||||||
|
|
||||||
|
BaseInstance *instance()
|
||||||
|
{
|
||||||
|
return m_instance;
|
||||||
|
}
|
||||||
|
|
||||||
void setMinecraftWorkdir(QString path);
|
void setMinecraftWorkdir(QString path);
|
||||||
|
|
||||||
void setMinecraftArguments(QStringList args);
|
void setMinecraftArguments(QStringList args);
|
||||||
@ -71,6 +76,21 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
/**
|
||||||
|
* @brief emitted when Minecraft immediately fails to run
|
||||||
|
*/
|
||||||
|
void launch_failed(BaseInstance *);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief emitted when the PreLaunchCommand fails
|
||||||
|
*/
|
||||||
|
void prelaunch_failed(BaseInstance *, int code, QProcess::ExitStatus status);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief emitted when the PostLaunchCommand fails
|
||||||
|
*/
|
||||||
|
void postlaunch_failed(BaseInstance *, int code, QProcess::ExitStatus status);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief emitted when mc has finished and the PostLaunchCommand was run
|
* @brief emitted when mc has finished and the PostLaunchCommand was run
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user