summaryrefslogtreecommitdiffstats
path: root/gui/MainWindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gui/MainWindow.cpp')
-rw-r--r--gui/MainWindow.cpp118
1 files changed, 109 insertions, 9 deletions
diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp
index a4c04d89..121c2a73 100644
--- a/gui/MainWindow.cpp
+++ b/gui/MainWindow.cpp
@@ -33,6 +33,7 @@
#include <QLabel>
#include <QToolButton>
#include <QWidgetAction>
+#include <QProgressDialog>
#include "osutils.h"
#include "userutils.h"
@@ -97,6 +98,8 @@
#include <logic/updater/NotificationChecker.h>
#include <logic/tasks/ThreadTask.h>
+#include "logic/tools/BaseProfiler.h"
+
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
MultiMCPlatform::fixWM_CLASS(this);
@@ -358,6 +361,51 @@ void MainWindow::showInstanceContextMenu(const QPoint &pos)
myMenu.exec(view->mapToGlobal(pos));
}
+void MainWindow::updateToolsMenu()
+{
+ if (ui->actionLaunchInstance->menu())
+ {
+ ui->actionLaunchInstance->menu()->deleteLater();
+ }
+ QMenu *launchMenu = new QMenu(this);
+ QAction *normalLaunch = launchMenu->addAction(tr("Launch"));
+ connect(normalLaunch, &QAction::triggered, [this](){doLaunch();});
+ launchMenu->addSeparator()->setText(tr("Profilers"));
+ for (auto profiler : MMC->profilers().values())
+ {
+ QAction *profilerAction = launchMenu->addAction(profiler->name());
+ QString error;
+ if (!profiler->check(&error))
+ {
+ profilerAction->setDisabled(true);
+ profilerAction->setToolTip(tr("Profiler not setup correctly. Go into settings, \"External Tools\"."));
+ }
+ else
+ {
+ connect(profilerAction, &QAction::triggered, [this, profiler](){doLaunch(true, profiler.get());});
+ }
+ }
+ launchMenu->addSeparator()->setText(tr("Tools"));
+ for (auto tool : MMC->tools().values())
+ {
+ QAction *toolAction = launchMenu->addAction(tool->name());
+ QString error;
+ if (!tool->check(&error))
+ {
+ toolAction->setDisabled(true);
+ toolAction->setToolTip(tr("Tool not setup correctly. Go into settings, \"External Tools\"."));
+ }
+ else
+ {
+ connect(toolAction, &QAction::triggered, [this, tool]()
+ {
+ tool->createDetachedTool(m_selectedInstance, this)->run();
+ });
+ }
+ }
+ ui->actionLaunchInstance->setMenu(launchMenu);
+}
+
void MainWindow::repopulateAccountsMenu()
{
accountMenu->clear();
@@ -931,6 +979,7 @@ void MainWindow::on_actionSettings_triggered()
// FIXME: quick HACK to make this work. improve, optimize.
proxymodel->invalidate();
proxymodel->sort(0);
+ updateToolsMenu();
}
void MainWindow::on_actionManageAccounts_triggered()
@@ -1079,7 +1128,7 @@ void MainWindow::on_actionLaunchInstanceOffline_triggered()
}
}
-void MainWindow::doLaunch(bool online)
+void MainWindow::doLaunch(bool online, BaseProfilerFactory *profiler)
{
if (!m_selectedInstance)
return;
@@ -1195,11 +1244,11 @@ void MainWindow::doLaunch(bool online)
// update first if the server actually responded
if (session->auth_server_online)
{
- updateInstance(m_selectedInstance, session);
+ updateInstance(m_selectedInstance, session, profiler);
}
else
{
- launchInstance(m_selectedInstance, session);
+ launchInstance(m_selectedInstance, session, profiler);
}
tryagain = false;
}
@@ -1207,22 +1256,22 @@ void MainWindow::doLaunch(bool online)
}
}
-void MainWindow::updateInstance(BaseInstance *instance, AuthSessionPtr session)
+void MainWindow::updateInstance(BaseInstance *instance, AuthSessionPtr session, BaseProfilerFactory *profiler)
{
auto updateTask = instance->doUpdate();
if (!updateTask)
{
- launchInstance(instance, session);
+ launchInstance(instance, session, profiler);
return;
}
ProgressDialog tDialog(this);
- connect(updateTask.get(), &Task::succeeded, [this, instance, session]
- { launchInstance(instance, session); });
+ connect(updateTask.get(), &Task::succeeded, [this, instance, session, profiler]
+ { launchInstance(instance, session, profiler); });
connect(updateTask.get(), SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString)));
tDialog.exec(updateTask.get());
}
-void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session)
+void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session, BaseProfilerFactory *profiler)
{
Q_ASSERT_X(instance != NULL, "launchInstance", "instance is NULL");
Q_ASSERT_X(session.get() != nullptr, "launchInstance", "session is NULL");
@@ -1237,7 +1286,56 @@ void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session)
connect(console, SIGNAL(isClosing()), this, SLOT(instanceEnded()));
proc->setLogin(session);
- proc->launch();
+ proc->arm();
+
+ if (profiler)
+ {
+ QString error;
+ if (!profiler->check(&error))
+ {
+ QMessageBox::critical(this, tr("Error"), tr("Couldn't start profiler: %1").arg(error));
+ proc->abort();
+ return;
+ }
+ BaseProfiler *profilerInstance = profiler->createProfiler(instance, this);
+ QProgressDialog dialog;
+ dialog.setMinimum(0);
+ dialog.setMaximum(0);
+ dialog.setValue(0);
+ dialog.setLabelText(tr("Waiting for profiler..."));
+ connect(&dialog, &QProgressDialog::canceled, profilerInstance, &BaseProfiler::abortProfiling);
+ dialog.show();
+ connect(profilerInstance, &BaseProfiler::readyToLaunch, [&dialog, this](const QString &message)
+ {
+ dialog.accept();
+ QMessageBox msg;
+ msg.setText(tr("The launch of Minecraft itself is delayed until you press the "
+ "button. This is the right time to setup the profiler, as the "
+ "profiler server is running now.\n\n%1").arg(message));
+ msg.setWindowTitle(tr("Waiting"));
+ msg.setIcon(QMessageBox::Information);
+ msg.addButton(tr("Launch"), QMessageBox::AcceptRole);
+ msg.exec();
+ proc->launch();
+ });
+ connect(profilerInstance, &BaseProfiler::abortLaunch, [&dialog, this](const QString &message)
+ {
+ dialog.accept();
+ QMessageBox msg;
+ msg.setText(tr("Couldn't start the profiler: %1").arg(message));
+ msg.setWindowTitle(tr("Error"));
+ msg.setIcon(QMessageBox::Critical);
+ msg.addButton(QMessageBox::Ok);
+ msg.exec();
+ proc->abort();
+ });
+ profilerInstance->beginProfiling(proc);
+ dialog.exec();
+ }
+ else
+ {
+ proc->launch();
+ }
}
void MainWindow::onGameUpdateError(QString error)
@@ -1378,6 +1476,8 @@ void MainWindow::instanceChanged(const QModelIndex &current, const QModelIndex &
m_statusLeft->setText(m_selectedInstance->getStatusbarDescription());
updateInstanceToolIcon(m_selectedInstance->iconKey());
+ updateToolsMenu();
+
MMC->settings()->set("SelectedInstance", m_selectedInstance->id());
}
else