Made instace killing actually work

This commit is contained in:
Stiepen22 2013-09-06 22:40:50 +02:00
parent b44e70d58d
commit f897a200e2
7 changed files with 43 additions and 7 deletions

View File

@ -40,7 +40,8 @@ FORMS += gui/mainwindow.ui \
gui/settingsdialog.ui \
gui/modeditwindow.ui \
gui/instancesettings.ui \
gui/logindialog.ui
gui/logindialog.ui \
gui/consolewindow.ui
RESOURCES += \
multimc.qrc

View File

@ -2,11 +2,13 @@
#include "ui_consolewindow.h"
#include <QScrollBar>
#include <QMessageBox>
ConsoleWindow::ConsoleWindow(QWidget *parent) :
ConsoleWindow::ConsoleWindow(MinecraftProcess *mcproc, QWidget *parent) :
QDialog(parent),
ui(new Ui::ConsoleWindow),
m_mayclose(true)
m_mayclose(true),
proc(mcproc)
{
ui->setupUi(this);
}
@ -40,6 +42,9 @@ void ConsoleWindow::write(QString data, MessageLevel::Enum mode)
else if (mode == MessageLevel::Error)
while(iter.hasNext())
writeColor(iter.next(), "red");
else if (mode == MessageLevel::Warning)
while(iter.hasNext())
writeColor(iter.next(), "orange");
// TODO: implement other MessageLevels
else
while(iter.hasNext())
@ -72,3 +77,18 @@ void ConsoleWindow::closeEvent(QCloseEvent * event)
else
QDialog::closeEvent(event);
}
void ConsoleWindow::on_btnKillMinecraft_clicked()
{
ui->btnKillMinecraft->setEnabled(false);
QMessageBox r_u_sure;
r_u_sure.setText("Kill Minecraft?");
r_u_sure.setInformativeText("This can cause the instance to get corrupted and should only be used if Minecraft is frozen for some reason");
r_u_sure.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
r_u_sure.setDefaultButton(QMessageBox::Yes);
if (r_u_sure.exec() == QMessageBox::Yes)
proc->killMinecraft();
else
ui->btnKillMinecraft->setEnabled(true);
r_u_sure.close();
}

View File

@ -13,7 +13,7 @@ class ConsoleWindow : public QDialog
Q_OBJECT
public:
explicit ConsoleWindow(QWidget *parent = 0);
explicit ConsoleWindow(MinecraftProcess *proc, QWidget *parent = 0);
~ConsoleWindow();
/**
@ -48,12 +48,14 @@ public slots:
private slots:
void on_closeButton_clicked();
void on_btnKillMinecraft_clicked();
protected:
void closeEvent(QCloseEvent *);
private:
Ui::ConsoleWindow *ui;
MinecraftProcess *proc;
bool m_mayclose;
};

View File

@ -62,6 +62,13 @@
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnKillMinecraft">
<property name="text">
<string>Kill Minecraft</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="closeButton">
<property name="text">

View File

@ -538,7 +538,7 @@ void MainWindow::launchInstance(BaseInstance *instance, LoginResponse response)
if(!proc)
return;
console = new ConsoleWindow();
console = new ConsoleWindow(proc);
console->show();
connect(proc, SIGNAL(log(QString, MessageLevel::Enum)),
console, SLOT(write(QString, MessageLevel::Enum)));

View File

@ -120,7 +120,12 @@ void MinecraftProcess::finish(int code, ExitStatus status)
//TODO: error handling
}
// TODO: Localization
if (!killed)
emit log("Minecraft exited.");
else
emit log("Minecraft was killed by user.", MessageLevel::Error);
m_prepostlaunchprocess.processEnvironment().insert("INST_EXITCODE", QString(code));
@ -141,6 +146,7 @@ void MinecraftProcess::finish(int code, ExitStatus status)
void MinecraftProcess::killMinecraft()
{
killed = true;
kill();
}
void MinecraftProcess::launch()

View File

@ -71,7 +71,7 @@ private slots:
//FIXME: report error
return;
}
console = new ConsoleWindow();
console = new ConsoleWindow(proc);
console->show();
connect(proc, SIGNAL(ended()), SLOT(onTerminated()));