summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--MultiMC.cpp5
-rw-r--r--gui/ConsoleWindow.cpp36
-rw-r--r--gui/ConsoleWindow.h18
-rw-r--r--gui/ConsoleWindow.ui151
-rw-r--r--gui/MainWindow.cpp29
-rw-r--r--gui/MainWindow.h2
-rw-r--r--logic/InstanceLauncher.cpp7
-rw-r--r--logic/MinecraftProcess.cpp17
-rw-r--r--logic/MinecraftProcess.h20
9 files changed, 152 insertions, 133 deletions
diff --git a/MultiMC.cpp b/MultiMC.cpp
index 1c70fb54..0aaf31bf 100644
--- a/MultiMC.cpp
+++ b/MultiMC.cpp
@@ -321,8 +321,6 @@ void MultiMC::initGlobalSettings()
// The cat
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"));
@@ -338,6 +336,9 @@ void MultiMC::initGlobalSettings()
// Window state and geometry
m_settings->registerSetting(new Setting("MainWindowState", ""));
m_settings->registerSetting(new Setting("MainWindowGeometry", ""));
+
+ m_settings->registerSetting(new Setting("ConsoleWindowState", ""));
+ m_settings->registerSetting(new Setting("ConsoleWindowGeometry", ""));
}
void MultiMC::initHttpMetaCache()
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 <QScrollBar>
#include <QMessageBox>
@@ -23,13 +24,26 @@
#include <gui/dialogs/CustomMessageBox.h>
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 <QDialog>
+#include <QMainWindow>
#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 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConsoleWindow</class>
- <widget class="QDialog" name="ConsoleWindow">
+ <widget class="QMainWindow" name="ConsoleWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
- <width>610</width>
- <height>391</height>
+ <width>640</width>
+ <height>440</height>
</rect>
</property>
<property name="windowTitle">
<string>MultiMC Console</string>
</property>
- <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>
- <widget class="QPlainTextEdit" name="text">
- <property name="font">
- <font>
- <pointsize>10</pointsize>
- </font>
- </property>
- <property name="undoRedoEnabled">
- <bool>false</bool>
- </property>
- <property name="readOnly">
- <bool>true</bool>
- </property>
- <property name="plainText">
- <string notr="true"/>
- </property>
- <property name="textInteractionFlags">
- <set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
- </property>
- <property name="centerOnScroll">
- <bool>false</bool>
- </property>
- </widget>
- </item>
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout">
- <property name="leftMargin">
- <number>6</number>
- </property>
- <property name="rightMargin">
- <number>6</number>
- </property>
- <item>
- <spacer name="horizontalSpacer">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QPushButton" name="btnKillMinecraft">
- <property name="text">
- <string>&amp;Kill Minecraft</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="closeButton">
- <property name="text">
- <string>&amp;Close</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- </layout>
+ <widget class="QWidget" name="centralwidget">
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QPlainTextEdit" name="text">
+ <property name="font">
+ <font>
+ <pointsize>10</pointsize>
+ </font>
+ </property>
+ <property name="undoRedoEnabled">
+ <bool>false</bool>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ <property name="plainText">
+ <string notr="true"/>
+ </property>
+ <property name="textInteractionFlags">
+ <set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
+ </property>
+ <property name="centerOnScroll">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <property name="leftMargin">
+ <number>6</number>
+ </property>
+ <property name="rightMargin">
+ <number>6</number>
+ </property>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="btnKillMinecraft">
+ <property name="text">
+ <string>&amp;Kill Minecraft</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="closeButton">
+ <property name="text">
+ <string>&amp;Close</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
</widget>
- <tabstops>
- <tabstop>text</tabstop>
- <tabstop>closeButton</tabstop>
- <tabstop>btnKillMinecraft</tabstop>
- </tabstops>
<resources/>
<connections/>
</ui>
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();
diff --git a/logic/InstanceLauncher.cpp b/logic/InstanceLauncher.cpp
index f587e583..534d07d1 100644
--- a/logic/InstanceLauncher.cpp
+++ b/logic/InstanceLauncher.cpp
@@ -48,12 +48,9 @@ void InstanceLauncher::onLoginComplete()
return;
}
console = new ConsoleWindow(proc);
- console->show();
-
- connect(proc, SIGNAL(ended()), SLOT(onTerminated()));
- connect(proc, SIGNAL(log(QString, MessageLevel::Enum)), console,
- SLOT(write(QString, MessageLevel::Enum)));
+ connect(console, SIGNAL(isClosing()), this, SLOT(onTerminated()));
+ proc->setLogin(result.username, result.session_id);
proc->launch();
}
diff --git a/logic/MinecraftProcess.cpp b/logic/MinecraftProcess.cpp
index 6c86c73a..b3b587e8 100644
--- a/logic/MinecraftProcess.cpp
+++ b/logic/MinecraftProcess.cpp
@@ -101,7 +101,7 @@ void MinecraftProcess::on_stdOut()
for (int i = 0; i < lines.size() - 1; 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));
}
if (!complete)
@@ -139,7 +139,8 @@ void MinecraftProcess::finish(int code, ExitStatus status)
m_prepostlaunchprocess.waitForFinished();
if (m_prepostlaunchprocess.exitStatus() != NormalExit)
{
- // TODO: error handling
+ emit postlaunch_failed(m_instance, m_prepostlaunchprocess.exitCode(),
+ m_prepostlaunchprocess.exitStatus());
}
}
m_instance->cleanupAfterRun();
@@ -160,7 +161,9 @@ void MinecraftProcess::launch()
m_prepostlaunchprocess.waitForFinished();
if (m_prepostlaunchprocess.exitStatus() != NormalExit)
{
- // TODO: error handling
+ m_instance->cleanupAfterRun();
+ emit prelaunch_failed(m_instance, m_prepostlaunchprocess.exitCode(),
+ m_prepostlaunchprocess.exitStatus());
return;
}
}
@@ -171,15 +174,15 @@ void MinecraftProcess::launch()
QString JavaPath = m_instance->settings().get("JavaPath").toString();
emit log(QString("Java path: '%1'").arg(JavaPath));
emit log(QString("Arguments: '%1'").arg(
- m_args.join("' '") /*.replace(username, "<Username>").replace(sessionID, "<Session
-ID>")*/));
+ m_args.join("' '").replace(username, "<Username>").replace(sessionID, "<Session ID>")));
start(JavaPath, m_args);
if (!waitForStarted())
{
//: 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;
- // TODO: error handling
}
}
diff --git a/logic/MinecraftProcess.h b/logic/MinecraftProcess.h
index bba97692..6d4a1eb7 100644
--- a/logic/MinecraftProcess.h
+++ b/logic/MinecraftProcess.h
@@ -58,6 +58,11 @@ public:
*/
void launch();
+ BaseInstance *instance()
+ {
+ return m_instance;
+ }
+
void setMinecraftWorkdir(QString path);
void setMinecraftArguments(QStringList args);
@@ -72,6 +77,21 @@ public:
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
*/
void ended(BaseInstance *, int code, QProcess::ExitStatus status);