diff options
Diffstat (limited to 'gui/consolewindow.cpp')
-rw-r--r-- | gui/consolewindow.cpp | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/gui/consolewindow.cpp b/gui/consolewindow.cpp index 811900a2..deeedd65 100644 --- a/gui/consolewindow.cpp +++ b/gui/consolewindow.cpp @@ -2,13 +2,19 @@ #include "ui_consolewindow.h" #include <QScrollBar> +#include <QMessageBox> -ConsoleWindow::ConsoleWindow(QWidget *parent) : +#include <gui/platform.h> + +ConsoleWindow::ConsoleWindow(MinecraftProcess *mcproc, QWidget *parent) : QDialog(parent), ui(new Ui::ConsoleWindow), - m_mayclose(true) + m_mayclose(true), + proc(mcproc) { + MultiMCPlatform::fixWM_CLASS(this); ui->setupUi(this); + connect(mcproc, SIGNAL(ended()), this, SLOT(onEnded())); } ConsoleWindow::~ConsoleWindow() @@ -20,7 +26,7 @@ void ConsoleWindow::writeColor(QString text, const char *color) { // append a paragraph if (color != nullptr) - ui->text->appendHtml(QString("<font color=%1>%2</font>").arg(color).arg(text)); + ui->text->appendHtml(QString("<font color=\"%1\">%2</font>").arg(color).arg(text)); else ui->text->appendPlainText(text); // scroll down @@ -33,6 +39,11 @@ void ConsoleWindow::write(QString data, MessageLevel::Enum mode) if (data.endsWith('\n')) data = data.left(data.length()-1); QStringList paragraphs = data.split('\n'); + for(QString ¶graph : paragraphs) + { + paragraph = paragraph.trimmed(); + } + QListIterator<QString> iter(paragraphs); if (mode == MessageLevel::MultiMC) while(iter.hasNext()) @@ -40,6 +51,15 @@ 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"); + else if (mode == MessageLevel::Fatal) + while(iter.hasNext()) + writeColor(iter.next(), "pink"); + else if (mode == MessageLevel::Debug) + while(iter.hasNext()) + writeColor(iter.next(), "green"); // TODO: implement other MessageLevels else while(iter.hasNext()) @@ -72,3 +92,26 @@ void ConsoleWindow::closeEvent(QCloseEvent * event) else QDialog::closeEvent(event); } + +void ConsoleWindow::on_btnKillMinecraft_clicked() +{ + ui->btnKillMinecraft->setEnabled(false); + QMessageBox r_u_sure; + //: Main question of the kill confirmation dialog + r_u_sure.setText(tr("Kill Minecraft?")); + r_u_sure.setInformativeText(tr("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(); +} + +void ConsoleWindow::onEnded() +{ + ui->btnKillMinecraft->setEnabled(false); + // TODO: Check why this doesn't work + if (!proc->exitCode()) this->close(); +} |