From 911ac19a56fa1a5f8dd4798385022813cd0b9d07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 18 May 2014 19:07:01 +0200 Subject: Screenshot upload dialog(s) now have the console window as parent. --- gui/ConsoleWindow.cpp | 40 ++++++++++++++++++++++++++++++---------- gui/ConsoleWindow.h | 7 ++++--- gui/MainWindow.cpp | 37 +++++++++---------------------------- gui/MainWindow.h | 2 -- logic/BaseInstance.h | 2 +- logic/LegacyInstance.cpp | 12 ++---------- logic/LegacyInstance.h | 2 +- logic/MinecraftProcess.cpp | 2 +- logic/MinecraftProcess.h | 19 ++++++++++++------- logic/OneSixInstance.cpp | 13 +++---------- logic/OneSixInstance.h | 2 +- 11 files changed, 64 insertions(+), 74 deletions(-) diff --git a/gui/ConsoleWindow.cpp b/gui/ConsoleWindow.cpp index 18a617e0..ac3752c5 100644 --- a/gui/ConsoleWindow.cpp +++ b/gui/ConsoleWindow.cpp @@ -24,9 +24,11 @@ #include #include #include +#include "dialogs/ScreenshotDialog.h" #include "logic/net/PasteUpload.h" #include "logic/icons/IconList.h" +#include 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); diff --git a/gui/ConsoleWindow.h b/gui/ConsoleWindow.h index e21da33c..17c64392 100644 --- a/gui/ConsoleWindow.h +++ b/gui/ConsoleWindow.h @@ -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) diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 725bf175..9661537a 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -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(); - } -} diff --git a/gui/MainWindow.h b/gui/MainWindow.h index 2c421b88..45ca520c 100644 --- a/gui/MainWindow.h +++ b/gui/MainWindow.h @@ -144,8 +144,6 @@ slots: void showInstanceContextMenu(const QPoint &); - void on_actionScreenshots_triggered(); - void updateToolsMenu(); void skinJobFinished(); diff --git a/logic/BaseInstance.h b/logic/BaseInstance.h index d38ae409..16791592 100644 --- a/logic/BaseInstance.h +++ b/logic/BaseInstance.h @@ -163,7 +163,7 @@ public: virtual std::shared_ptr doUpdate() = 0; /// returns a valid minecraft process, ready for launch with the given account. - virtual MinecraftProcess *prepareForLaunch(AuthSessionPtr account) = 0; + virtual bool prepareForLaunch(AuthSessionPtr account, QString & launchScript) = 0; /// do any necessary cleanups after the instance finishes. also runs before /// 'prepareForLaunch' diff --git a/logic/LegacyInstance.cpp b/logic/LegacyInstance.cpp index d06b8827..6648e059 100644 --- a/logic/LegacyInstance.cpp +++ b/logic/LegacyInstance.cpp @@ -50,16 +50,13 @@ std::shared_ptr LegacyInstance::doUpdate() return std::shared_ptr(new LegacyUpdate(this, this)); } -MinecraftProcess *LegacyInstance::prepareForLaunch(AuthSessionPtr account) +bool LegacyInstance::prepareForLaunch(AuthSessionPtr account, QString & launchScript) { - MinecraftProcess *proc = new MinecraftProcess(this); - QIcon icon = MMC->icons()->getIcon(iconKey()); auto pixmap = icon.pixmap(128, 128); pixmap.save(PathCombine(minecraftRoot(), "icon.png"), "PNG"); // create the launch script - QString launchScript; { // window size QString windowParams; @@ -79,12 +76,7 @@ MinecraftProcess *LegacyInstance::prepareForLaunch(AuthSessionPtr account) launchScript += "lwjgl " + lwjgl + "\n"; launchScript += "launcher legacy\n"; } - proc->setLaunchScript(launchScript); - - // set the process work path - proc->setWorkdir(minecraftRoot()); - - return proc; + return true; } void LegacyInstance::cleanupAfterRun() diff --git a/logic/LegacyInstance.h b/logic/LegacyInstance.h index badaf7e3..aa80968e 100644 --- a/logic/LegacyInstance.h +++ b/logic/LegacyInstance.h @@ -79,7 +79,7 @@ public: virtual void setShouldUpdate(bool val) override; virtual std::shared_ptr doUpdate() override; - virtual MinecraftProcess *prepareForLaunch(AuthSessionPtr account) override; + virtual bool prepareForLaunch(AuthSessionPtr account, QString & launchScript) override; virtual void cleanupAfterRun() override; virtual QDialog *createModEditDialog(QWidget *parent) override; diff --git a/logic/MinecraftProcess.cpp b/logic/MinecraftProcess.cpp index e43e5830..b268a4cc 100644 --- a/logic/MinecraftProcess.cpp +++ b/logic/MinecraftProcess.cpp @@ -34,7 +34,7 @@ #define IBUS "@im=ibus" // constructor -MinecraftProcess::MinecraftProcess(BaseInstance *inst) : m_instance(inst) +MinecraftProcess::MinecraftProcess(InstancePtr inst) : m_instance(inst) { connect(this, SIGNAL(finished(int, QProcess::ExitStatus)), SLOT(finish(int, QProcess::ExitStatus))); diff --git a/logic/MinecraftProcess.h b/logic/MinecraftProcess.h index d47a6cd2..b61ef380 100644 --- a/logic/MinecraftProcess.h +++ b/logic/MinecraftProcess.h @@ -52,8 +52,13 @@ public: * @brief MinecraftProcess constructor * @param inst the Instance pointer to launch */ - MinecraftProcess(BaseInstance *inst); + MinecraftProcess(InstancePtr inst); + virtual ~MinecraftProcess() + { + + }; + /** * @brief start the launcher part with the provided launch script */ @@ -69,7 +74,7 @@ public: */ void abort(); - BaseInstance *instance() + InstancePtr instance() { return m_instance; } @@ -97,22 +102,22 @@ signals: /** * @brief emitted when Minecraft immediately fails to run */ - void launch_failed(BaseInstance *); + void launch_failed(InstancePtr); /** * @brief emitted when the PreLaunchCommand fails */ - void prelaunch_failed(BaseInstance *, int code, QProcess::ExitStatus status); + void prelaunch_failed(InstancePtr, int code, QProcess::ExitStatus status); /** * @brief emitted when the PostLaunchCommand fails */ - void postlaunch_failed(BaseInstance *, int code, QProcess::ExitStatus status); + void postlaunch_failed(InstancePtr, int code, QProcess::ExitStatus status); /** * @brief emitted when mc has finished and the PostLaunchCommand was run */ - void ended(BaseInstance *, int code, QProcess::ExitStatus status); + void ended(InstancePtr, int code, QProcess::ExitStatus status); /** * @brief emitted when we want to log something @@ -122,7 +127,7 @@ signals: void log(QString text, MessageLevel::Enum level = MessageLevel::MultiMC); protected: - BaseInstance *m_instance = nullptr; + InstancePtr m_instance; QString m_err_leftover; QString m_out_leftover; QProcess m_prepostlaunchprocess; diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp index 24d54446..6f3018cb 100644 --- a/logic/OneSixInstance.cpp +++ b/logic/OneSixInstance.cpp @@ -189,7 +189,7 @@ QStringList OneSixInstance::processMinecraftArgs(AuthSessionPtr session) return parts; } -MinecraftProcess *OneSixInstance::prepareForLaunch(AuthSessionPtr session) +bool OneSixInstance::prepareForLaunch(AuthSessionPtr account, QString &launchScript) { I_D(OneSixInstance); @@ -200,7 +200,6 @@ MinecraftProcess *OneSixInstance::prepareForLaunch(AuthSessionPtr session) auto version = d->version; if (!version) return nullptr; - QString launchScript; { auto libs = version->getActiveNormalLibs(); for (auto lib : libs) @@ -212,7 +211,7 @@ MinecraftProcess *OneSixInstance::prepareForLaunch(AuthSessionPtr session) } launchScript += "mainClass " + version->mainClass + "\n"; - for (auto param : processMinecraftArgs(session)) + for (auto param : processMinecraftArgs(account)) { launchScript += "param " + param + "\n"; } @@ -240,13 +239,7 @@ MinecraftProcess *OneSixInstance::prepareForLaunch(AuthSessionPtr session) } launchScript += "natives " + natives_dir.absolutePath() + "\n"; launchScript += "launcher onesix\n"; - - // create the process and set its parameters - MinecraftProcess *proc = new MinecraftProcess(this); - proc->setWorkdir(minecraftRoot()); - proc->setLaunchScript(launchScript); - // proc->setNativeFolder(natives_dir.absolutePath()); - return proc; + return true; } void OneSixInstance::cleanupAfterRun() diff --git a/logic/OneSixInstance.h b/logic/OneSixInstance.h index 4e9d62a1..13a392c2 100644 --- a/logic/OneSixInstance.h +++ b/logic/OneSixInstance.h @@ -40,7 +40,7 @@ public: virtual QString instanceConfigFolder() const override; virtual std::shared_ptr doUpdate() override; - virtual MinecraftProcess *prepareForLaunch(AuthSessionPtr session) override; + virtual bool prepareForLaunch(AuthSessionPtr account, QString & launchScript) override; virtual void cleanupAfterRun() override; -- cgit v1.2.3