Screenshot upload dialog(s) now have the console window as parent.

This commit is contained in:
Petr Mrázek
2014-05-18 19:07:01 +02:00
parent 7f2a16917e
commit 911ac19a56
11 changed files with 64 additions and 74 deletions

View File

@ -24,9 +24,11 @@
#include <gui/Platform.h>
#include <gui/dialogs/CustomMessageBox.h>
#include <gui/dialogs/ProgressDialog.h>
#include "dialogs/ScreenshotDialog.h"
#include "logic/net/PasteUpload.h"
#include "logic/icons/IconList.h"
#include <logic/screenshots/ScreenshotList.h>
ConsoleWindow::ConsoleWindow(MinecraftProcess *mcproc, QWidget *parent)
: QMainWindow(parent), ui(new Ui::ConsoleWindow), proc(mcproc)
@ -35,14 +37,12 @@ ConsoleWindow::ConsoleWindow(MinecraftProcess *mcproc, QWidget *parent)
ui->setupUi(this);
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 *)));
connect(ui->btnScreenshots, &QPushButton::clicked, this, &ConsoleWindow::uploadScreenshots);
connect(mcproc, SIGNAL(ended(InstancePtr, int, QProcess::ExitStatus)), this,
SLOT(onEnded(InstancePtr, int, QProcess::ExitStatus)));
connect(mcproc, SIGNAL(prelaunch_failed(InstancePtr, int, QProcess::ExitStatus)), this,
SLOT(onEnded(InstancePtr, int, QProcess::ExitStatus)));
connect(mcproc, SIGNAL(launch_failed(InstancePtr)), this,
SLOT(onLaunchFailed(InstancePtr)));
restoreState(
QByteArray::fromBase64(MMC->settings()->get("ConsoleWindowState").toByteArray()));
@ -172,6 +172,26 @@ void ConsoleWindow::on_closeButton_clicked()
close();
}
void ConsoleWindow::on_btnScreenshots_clicked()
{
ScreenshotList *list = new ScreenshotList(proc->instance());
Task *task = list->load();
ProgressDialog prog(this);
prog.exec(task);
if (!task->successful())
{
CustomMessageBox::selectable(this, tr("Failed to load screenshots!"),
task->failReason(), QMessageBox::Warning)->exec();
return;
}
ScreenshotDialog dialog(list, this);
if (dialog.exec() == ScreenshotDialog::Accepted)
{
CustomMessageBox::selectable(this, tr("Done uploading!"), dialog.message(),
QMessageBox::Information)->exec();
}
}
void ConsoleWindow::setMayClose(bool mayclose)
{
if(mayclose)
@ -242,7 +262,7 @@ void ConsoleWindow::on_btnKillMinecraft_clicked()
ui->btnKillMinecraft->setEnabled(true);
}
void ConsoleWindow::onEnded(BaseInstance *instance, int code, QProcess::ExitStatus status)
void ConsoleWindow::onEnded(InstancePtr instance, int code, QProcess::ExitStatus status)
{
bool peacefulExit = code == 0 && status != QProcess::CrashExit;
ui->btnKillMinecraft->setEnabled(false);
@ -274,7 +294,7 @@ void ConsoleWindow::onEnded(BaseInstance *instance, int code, QProcess::ExitStat
}
}
void ConsoleWindow::onLaunchFailed(BaseInstance *instance)
void ConsoleWindow::onLaunchFailed(InstancePtr instance)
{
ui->btnKillMinecraft->setEnabled(false);

View File

@ -51,7 +51,6 @@ private:
signals:
void isClosing();
void uploadScreenshots();
public
slots:
@ -71,9 +70,11 @@ slots:
private
slots:
void on_closeButton_clicked();
void on_btnScreenshots_clicked();
void on_btnKillMinecraft_clicked();
void onEnded(BaseInstance *instance, int code, QProcess::ExitStatus status);
void onLaunchFailed(BaseInstance *instance);
void onEnded(InstancePtr instance, int code, QProcess::ExitStatus status);
void onLaunchFailed(InstancePtr instance);
// FIXME: add handlers for the other MinecraftProcess signals (pre/post launch command
// failures)

View File

@ -64,7 +64,6 @@
#include "gui/dialogs/AccountSelectDialog.h"
#include "gui/dialogs/UpdateDialog.h"
#include "gui/dialogs/EditAccountDialog.h"
#include "gui/dialogs/ScreenshotDialog.h"
#include "gui/dialogs/NotificationDialog.h"
#include "gui/ConsoleWindow.h"
@ -1239,15 +1238,19 @@ void MainWindow::launchInstance(InstancePtr instance, AuthSessionPtr session, Ba
Q_ASSERT_X(instance != NULL, "launchInstance", "instance is NULL");
Q_ASSERT_X(session.get() != nullptr, "launchInstance", "session is NULL");
proc = instance->prepareForLaunch(session);
if (!proc)
QString launchScript;
if(!instance->prepareForLaunch(session, launchScript))
return;
MinecraftProcess *proc = new MinecraftProcess(instance);
proc->setLaunchScript(launchScript);
proc->setWorkdir(instance->minecraftRoot());
this->hide();
console = new ConsoleWindow(proc);
connect(console, SIGNAL(isClosing()), this, SLOT(instanceEnded()));
connect(console, &ConsoleWindow::uploadScreenshots, this, &MainWindow::on_actionScreenshots_triggered);
proc->setLogin(session);
proc->arm();
@ -1269,7 +1272,7 @@ void MainWindow::launchInstance(InstancePtr instance, AuthSessionPtr session, Ba
dialog.setLabelText(tr("Waiting for profiler..."));
connect(&dialog, &QProgressDialog::canceled, profilerInstance, &BaseProfiler::abortProfiling);
dialog.show();
connect(profilerInstance, &BaseProfiler::readyToLaunch, [&dialog, this](const QString &message)
connect(profilerInstance, &BaseProfiler::readyToLaunch, [&dialog, this, proc](const QString &message)
{
dialog.accept();
QMessageBox msg;
@ -1282,7 +1285,7 @@ void MainWindow::launchInstance(InstancePtr instance, AuthSessionPtr session, Ba
msg.exec();
proc->launch();
});
connect(profilerInstance, &BaseProfiler::abortLaunch, [&dialog, this](const QString &message)
connect(profilerInstance, &BaseProfiler::abortLaunch, [&dialog, this, proc](const QString &message)
{
dialog.accept();
QMessageBox msg;
@ -1569,25 +1572,3 @@ void MainWindow::checkSetDefaultJava()
MMC->settings()->set("JavaPath", QString("java"));
}
}
void MainWindow::on_actionScreenshots_triggered()
{
if (!m_selectedInstance)
return;
ScreenshotList *list = new ScreenshotList(m_selectedInstance);
Task *task = list->load();
ProgressDialog prog(this);
prog.exec(task);
if (!task->successful())
{
CustomMessageBox::selectable(this, tr("Failed to load screenshots!"),
task->failReason(), QMessageBox::Warning)->exec();
return;
}
ScreenshotDialog dialog(list, this);
if (dialog.exec() == ScreenshotDialog::Accepted)
{
CustomMessageBox::selectable(this, tr("Done uploading!"), dialog.message(),
QMessageBox::Information)->exec();
}
}

View File

@ -144,8 +144,6 @@ slots:
void showInstanceContextMenu(const QPoint &);
void on_actionScreenshots_triggered();
void updateToolsMenu();
void skinJobFinished();