aboutsummaryrefslogtreecommitdiff
path: root/gui/MainWindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gui/MainWindow.cpp')
-rw-r--r--gui/MainWindow.cpp317
1 files changed, 130 insertions, 187 deletions
diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp
index 9661537a..bee250c4 100644
--- a/gui/MainWindow.cpp
+++ b/gui/MainWindow.cpp
@@ -56,9 +56,7 @@
#include "gui/dialogs/VersionSelectDialog.h"
#include "gui/dialogs/CustomMessageBox.h"
#include "gui/dialogs/LwjglSelectDialog.h"
-#include "gui/dialogs/InstanceSettings.h"
#include "gui/dialogs/IconPickerDialog.h"
-#include "gui/dialogs/EditNotesDialog.h"
#include "gui/dialogs/CopyInstanceDialog.h"
#include "gui/dialogs/AccountListDialog.h"
#include "gui/dialogs/AccountSelectDialog.h"
@@ -67,12 +65,13 @@
#include "gui/dialogs/NotificationDialog.h"
#include "gui/ConsoleWindow.h"
+#include "pagedialog/PageDialog.h"
-#include "logic/lists/InstanceList.h"
-#include "logic/lists/MinecraftVersionList.h"
-#include "logic/lists/LwjglVersionList.h"
+#include "logic/InstanceList.h"
+#include "logic/minecraft/MinecraftVersionList.h"
+#include "logic/LwjglVersionList.h"
#include "logic/icons/IconList.h"
-#include "logic/lists/JavaVersionList.h"
+#include "logic/java/JavaVersionList.h"
#include "logic/auth/flows/AuthenticateTask.h"
#include "logic/auth/flows/RefreshTask.h"
@@ -90,7 +89,7 @@
#include "logic/InstanceFactory.h"
#include "logic/MinecraftProcess.h"
#include "logic/OneSixUpdate.h"
-#include "logic/JavaUtils.h"
+#include "logic/java/JavaUtils.h"
#include "logic/NagUtils.h"
#include "logic/SkinUtils.h"
@@ -109,7 +108,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
MultiMCPlatform::fixWM_CLASS(this);
ui->setupUi(this);
- QString winTitle = QString("MultiMC 5 - Version %1").arg(BuildConfig.printableVersionString());
+ QString winTitle =
+ QString("MultiMC 5 - Version %1").arg(BuildConfig.printableVersionString());
if (!BuildConfig.BUILD_PLATFORM.isEmpty())
winTitle += " on " + BuildConfig.BUILD_PLATFORM;
setWindowTitle(winTitle);
@@ -119,7 +119,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
// Global shortcuts
{
- //FIXME: This is kinda weird. and bad. We need some kind of managed shutdown.
+ // FIXME: This is kinda weird. and bad. We need some kind of managed shutdown.
auto q = new QShortcut(QKeySequence::Quit, this);
connect(q, SIGNAL(activated()), qApp, SLOT(quit()));
}
@@ -258,7 +258,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
auto accounts = MMC->accounts();
- QList<CacheDownloadPtr> skin_dls;
+ QList<CacheDownloadPtr> skin_dls;
for (int i = 0; i < accounts->count(); i++)
{
auto account = accounts->at(i);
@@ -269,21 +269,21 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
auto meta = MMC->metacache()->resolveEntry("skins", profile.name + ".png");
auto action = CacheDownload::make(
QUrl("http://" + URLConstants::SKINS_BASE + profile.name + ".png"), meta);
- skin_dls.append(action);
+ skin_dls.append(action);
meta->stale = true;
}
}
}
- if(!skin_dls.isEmpty())
- {
- auto job = new NetJob("Startup player skins download");
- connect(job, SIGNAL(succeeded()), SLOT(skinJobFinished()));
- connect(job, SIGNAL(failed()), SLOT(skinJobFinished()));
- for(auto action: skin_dls)
- job->addNetAction(action);
- skin_download_job.reset(job);
- job->start();
- }
+ if (!skin_dls.isEmpty())
+ {
+ auto job = new NetJob("Startup player skins download");
+ connect(job, SIGNAL(succeeded()), SLOT(skinJobFinished()));
+ connect(job, SIGNAL(failed()), SLOT(skinJobFinished()));
+ for (auto action : skin_dls)
+ job->addNetAction(action);
+ skin_download_job.reset(job);
+ job->start();
+ }
// run the things that load and download other things... FIXME: this is NOT the place
// FIXME: invisible actions in the background = NOPE.
@@ -334,11 +334,10 @@ MainWindow::~MainWindow()
void MainWindow::skinJobFinished()
{
- activeAccountChanged();
- skin_download_job.reset();
+ activeAccountChanged();
+ skin_download_job.reset();
}
-
void MainWindow::showInstanceContextMenu(const QPoint &pos)
{
QList<QAction *> actions;
@@ -360,9 +359,10 @@ void MainWindow::showInstanceContextMenu(const QPoint &pos)
QAction *actionCopyInstance = new QAction(tr("Copy instance"), this);
actionCopyInstance->setToolTip(ui->actionCopyInstance->toolTip());
-
- connect(actionRename, SIGNAL(triggered(bool)), SLOT(on_actionRenameInstance_triggered()));
- connect(actionCopyInstance, SIGNAL(triggered(bool)), SLOT(on_actionCopyInstance_triggered()));
+ connect(actionRename, SIGNAL(triggered(bool)),
+ SLOT(on_actionRenameInstance_triggered()));
+ connect(actionCopyInstance, SIGNAL(triggered(bool)),
+ SLOT(on_actionCopyInstance_triggered()));
actions.replace(1, actionRename);
actions.prepend(actionSep);
@@ -377,7 +377,8 @@ void MainWindow::showInstanceContextMenu(const QPoint &pos)
QAction *actionCreateInstance = new QAction(tr("Create instance"), this);
actionCreateInstance->setToolTip(ui->actionAddInstance->toolTip());
- connect(actionCreateInstance, SIGNAL(triggered(bool)), SLOT(on_actionAddInstance_triggered()));
+ connect(actionCreateInstance, SIGNAL(triggered(bool)),
+ SLOT(on_actionAddInstance_triggered()));
actions.prepend(actionSep);
actions.prepend(actionVoid);
@@ -385,7 +386,7 @@ void MainWindow::showInstanceContextMenu(const QPoint &pos)
}
QMenu myMenu;
myMenu.addActions(actions);
- if(onInstance)
+ if (onInstance)
myMenu.setEnabled(m_selectedInstance->canLaunch());
myMenu.exec(view->mapToGlobal(pos));
}
@@ -398,7 +399,8 @@ void MainWindow::updateToolsMenu()
}
QMenu *launchMenu = new QMenu(this);
QAction *normalLaunch = launchMenu->addAction(tr("Launch"));
- connect(normalLaunch, &QAction::triggered, [this](){doLaunch();});
+ connect(normalLaunch, &QAction::triggered, [this]()
+ { doLaunch(); });
launchMenu->addSeparator()->setText(tr("Profilers"));
for (auto profiler : MMC->profilers().values())
{
@@ -407,11 +409,13 @@ void MainWindow::updateToolsMenu()
if (!profiler->check(&error))
{
profilerAction->setDisabled(true);
- profilerAction->setToolTip(tr("Profiler not setup correctly. Go into settings, \"External Tools\"."));
+ profilerAction->setToolTip(
+ tr("Profiler not setup correctly. Go into settings, \"External Tools\"."));
}
else
{
- connect(profilerAction, &QAction::triggered, [this, profiler](){doLaunch(true, profiler.get());});
+ connect(profilerAction, &QAction::triggered, [this, profiler]()
+ { doLaunch(true, profiler.get()); });
}
}
launchMenu->addSeparator()->setText(tr("Tools"));
@@ -422,14 +426,13 @@ void MainWindow::updateToolsMenu()
if (!tool->check(&error))
{
toolAction->setDisabled(true);
- toolAction->setToolTip(tr("Tool not setup correctly. Go into settings, \"External Tools\"."));
+ 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();
- });
+ { tool->createDetachedTool(m_selectedInstance, this)->run(); });
}
}
ui->actionLaunchInstance->setMenu(launchMenu);
@@ -671,7 +674,7 @@ void MainWindow::downloadUpdates(QString repo, int versionId, bool installOnExit
if (updateDlg.exec(&updateTask))
{
UpdateFlags baseFlags = None;
- if(BuildConfig.UPDATER_DRY_RUN)
+ if (BuildConfig.UPDATER_DRY_RUN)
baseFlags |= DryRun;
if (installOnExit)
MMC->installUpdates(updateTask.updateFilesDir(), baseFlags | OnExit);
@@ -708,6 +711,11 @@ void MainWindow::setCatBackground(bool enabled)
void MainWindow::on_actionAddInstance_triggered()
{
+#ifdef TEST_SEGV
+ // For further testing stuff.
+ int v = *((int *)-1);
+#endif
+
if (!MMC->minecraftlist()->isLoaded() && m_versionLoadTask &&
m_versionLoadTask->isRunning())
{
@@ -864,17 +872,14 @@ void MainWindow::updateInstanceToolIcon(QString new_icon)
void MainWindow::setSelectedInstanceById(const QString &id)
{
- QModelIndex selectionIndex = proxymodel->index(0, 0);
- if (!id.isNull())
+ if (id.isNull())
+ return;
+ const QModelIndex index = MMC->instances()->getInstanceIndexById(id);
+ if (index.isValid())
{
- const QModelIndex index = MMC->instances()->getInstanceIndexById(id);
- if (index.isValid())
- {
- selectionIndex = proxymodel->mapFromSource(index);
- }
+ QModelIndex selectionIndex = proxymodel->mapFromSource(index);
+ view->selectionModel()->setCurrentIndex(selectionIndex, QItemSelectionModel::ClearAndSelect);
}
- view->selectionModel()->setCurrentIndex(selectionIndex,
- QItemSelectionModel::ClearAndSelect);
}
void MainWindow::on_actionChangeInstGroup_triggered()
@@ -938,6 +943,37 @@ void MainWindow::on_actionSettings_triggered()
updateToolsMenu();
}
+template <typename T>
+void ShowPageDialog(T raw_provider, QWidget * parent, QString open_page = QString())
+{
+ auto provider = std::dynamic_pointer_cast<BasePageProvider>(raw_provider);
+ if(!provider)
+ return;
+ PageDialog dlg(provider, open_page, parent);
+ dlg.exec();
+}
+
+void MainWindow::on_actionInstanceSettings_triggered()
+{
+ ShowPageDialog(m_selectedInstance, this, "settings");
+}
+
+void MainWindow::on_actionEditInstNotes_triggered()
+{
+ ShowPageDialog(m_selectedInstance, this, "notes");
+}
+
+void MainWindow::on_actionEditInstance_triggered()
+{
+ ShowPageDialog(m_selectedInstance, this);
+}
+
+void MainWindow::on_actionScreenshots_triggered()
+{
+ ShowPageDialog(m_selectedInstance, this, "screenshots");
+}
+
+
void MainWindow::on_actionManageAccounts_triggered()
{
AccountListDialog dialog(this);
@@ -1026,17 +1062,6 @@ void MainWindow::on_actionViewSelectedInstFolder_triggered()
}
}
-void MainWindow::on_actionEditInstMods_triggered()
-{
- if (m_selectedInstance)
- {
- auto dialog = m_selectedInstance->createModEditDialog(this);
- if (dialog)
- dialog->exec();
- dialog->deleteLater();
- }
-}
-
void MainWindow::closeEvent(QCloseEvent *event)
{
// Save the window state and geometry.
@@ -1062,10 +1087,10 @@ void MainWindow::instanceActivated(QModelIndex index)
{
if (!index.isValid())
return;
- QString id = index.data(InstanceList::InstanceIDRole).toString();
+ QString id = index.data(InstanceList::InstanceIDRole).toString();
InstancePtr inst = MMC->instances()->getInstanceById(id);
- if(!inst)
- return;
+ if (!inst)
+ return;
NagUtils::checkJVMArgs(inst->settings().get("JvmArgs").toString(), this);
@@ -1218,7 +1243,8 @@ void MainWindow::doLaunch(bool online, BaseProfilerFactory *profiler)
}
}
-void MainWindow::updateInstance(InstancePtr instance, AuthSessionPtr session, BaseProfilerFactory *profiler)
+void MainWindow::updateInstance(InstancePtr instance, AuthSessionPtr session,
+ BaseProfilerFactory *profiler)
{
auto updateTask = instance->doUpdate();
if (!updateTask)
@@ -1233,14 +1259,15 @@ void MainWindow::updateInstance(InstancePtr instance, AuthSessionPtr session, Ba
tDialog.exec(updateTask.get());
}
-void MainWindow::launchInstance(InstancePtr instance, AuthSessionPtr session, BaseProfilerFactory *profiler)
+void MainWindow::launchInstance(InstancePtr instance, AuthSessionPtr session,
+ BaseProfilerFactory *profiler)
{
Q_ASSERT_X(instance != NULL, "launchInstance", "instance is NULL");
Q_ASSERT_X(session.get() != nullptr, "launchInstance", "session is NULL");
QString launchScript;
- if(!instance->prepareForLaunch(session, launchScript))
+ if (!instance->prepareForLaunch(session, launchScript))
return;
MinecraftProcess *proc = new MinecraftProcess(instance);
@@ -1260,7 +1287,8 @@ void MainWindow::launchInstance(InstancePtr instance, AuthSessionPtr session, Ba
QString error;
if (!profiler->check(&error))
{
- QMessageBox::critical(this, tr("Error"), tr("Couldn't start profiler: %1").arg(error));
+ QMessageBox::critical(this, tr("Error"),
+ tr("Couldn't start profiler: %1").arg(error));
proc->abort();
return;
}
@@ -1270,9 +1298,11 @@ void MainWindow::launchInstance(InstancePtr instance, AuthSessionPtr session, Ba
dialog.setMaximum(0);
dialog.setValue(0);
dialog.setLabelText(tr("Waiting for profiler..."));
- connect(&dialog, &QProgressDialog::canceled, profilerInstance, &BaseProfiler::abortProfiling);
+ connect(&dialog, &QProgressDialog::canceled, profilerInstance,
+ &BaseProfiler::abortProfiling);
dialog.show();
- connect(profilerInstance, &BaseProfiler::readyToLaunch, [&dialog, this, proc](const QString &message)
+ connect(profilerInstance, &BaseProfiler::readyToLaunch,
+ [&dialog, this, proc](const QString & message)
{
dialog.accept();
QMessageBox msg;
@@ -1285,7 +1315,8 @@ void MainWindow::launchInstance(InstancePtr instance, AuthSessionPtr session, Ba
msg.exec();
proc->launch();
});
- connect(profilerInstance, &BaseProfiler::abortLaunch, [&dialog, this, proc](const QString &message)
+ connect(profilerInstance, &BaseProfiler::abortLaunch,
+ [&dialog, this, proc](const QString & message)
{
dialog.accept();
QMessageBox msg;
@@ -1333,119 +1364,26 @@ void MainWindow::startTask(Task *task)
task->start();
}
-// Create A Desktop Shortcut
-void MainWindow::on_actionMakeDesktopShortcut_triggered()
-{
- QString name("Test");
- name = QInputDialog::getText(this, tr("MultiMC Shortcut"), tr("Enter a Shortcut Name."),
- QLineEdit::Normal, name);
-
- Util::createShortCut(Util::getDesktopDir(), QApplication::instance()->applicationFilePath(),
- QStringList() << "-dl" << QDir::currentPath() << "test", name,
- "application-x-octet-stream");
-
- CustomMessageBox::selectable(
- this, tr("Not useful"),
- tr("A Dummy Shortcut was created. it will not do anything productive"),
- QMessageBox::Warning)->show();
-}
-
// BrowserDialog
void MainWindow::openWebPage(QUrl url)
{
QDesktopServices::openUrl(url);
}
-void MainWindow::on_actionChangeInstMCVersion_triggered()
+void MainWindow::instanceChanged(const QModelIndex &current, const QModelIndex &previous)
{
- if (view->selectionModel()->selectedIndexes().count() < 1)
- return;
-
- VersionSelectDialog vselect(m_selectedInstance->versionList().get(),
- tr("Change Minecraft version"), this);
- vselect.setFuzzyFilter(1, "*OneSix*");
- if (!vselect.exec() || !vselect.selectedVersion())
- return;
-
- if (!MMC->accounts()->anyAccountIsValid())
- {
- CustomMessageBox::selectable(
- this, tr("Error"),
- tr("MultiMC cannot download Minecraft or update instances unless you have at least "
- "one account added.\nPlease add your Mojang or Minecraft account."),
- QMessageBox::Warning)->show();
- return;
- }
-
- if (m_selectedInstance->versionIsCustom())
- {
- auto result = CustomMessageBox::selectable(
- this, tr("Are you sure?"),
- tr("This will remove any library/version customization you did previously. "
- "This includes things like Forge install and similar."),
- QMessageBox::Warning, QMessageBox::Ok | QMessageBox::Abort,
- QMessageBox::Abort)->exec();
-
- if (result != QMessageBox::Ok)
- return;
- }
- m_selectedInstance->setIntendedVersionId(vselect.selectedVersion()->descriptor());
-
- auto updateTask = m_selectedInstance->doUpdate();
- if (!updateTask)
+ if(!current.isValid())
{
+ MMC->settings()->set("SelectedInstance", QString());
+ selectionBad();
return;
}
- ProgressDialog tDialog(this);
- connect(updateTask.get(), SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString)));
- tDialog.exec(updateTask.get());
-}
-
-void MainWindow::on_actionChangeInstLWJGLVersion_triggered()
-{
- if (!m_selectedInstance)
- return;
-
- LWJGLSelectDialog lselect(this);
- lselect.exec();
- if (lselect.result() == QDialog::Accepted)
- {
- auto ptr = std::dynamic_pointer_cast<LegacyInstance>(m_selectedInstance);
- if(ptr)
- ptr->setLWJGLVersion(lselect.selectedVersion());
- }
-}
-
-void MainWindow::on_actionInstanceSettings_triggered()
-{
- if (view->selectionModel()->selectedIndexes().count() < 1)
- return;
-
- InstanceSettings settings(&m_selectedInstance->settings(), this);
- settings.setWindowTitle(tr("Instance settings"));
- settings.exec();
-}
-
-void MainWindow::instanceChanged(const QModelIndex &current, const QModelIndex &previous)
-{
- if(!current.isValid())
- {
- selectionBad();
- MMC->settings()->set("SelectedInstance", QString());
- return;
- }
- QString id = current.data(InstanceList::InstanceIDRole).toString();
- m_selectedInstance = MMC->instances()->getInstanceById(id);
+ QString id = current.data(InstanceList::InstanceIDRole).toString();
+ m_selectedInstance = MMC->instances()->getInstanceById(id);
if ( m_selectedInstance )
{
ui->instanceToolBar->setEnabled(m_selectedInstance->canLaunch());
renameButton->setText(m_selectedInstance->name());
- ui->actionChangeInstLWJGLVersion->setEnabled(
- m_selectedInstance->menuActionEnabled("actionChangeInstLWJGLVersion"));
- ui->actionEditInstMods->setEnabled(
- m_selectedInstance->menuActionEnabled("actionEditInstMods"));
- ui->actionChangeInstMCVersion->setEnabled(
- m_selectedInstance->menuActionEnabled("actionChangeInstMCVersion"));
m_statusLeft->setText(m_selectedInstance->getStatusbarDescription());
updateInstanceToolIcon(m_selectedInstance->iconKey());
@@ -1455,9 +1393,9 @@ void MainWindow::instanceChanged(const QModelIndex &current, const QModelIndex &
}
else
{
- selectionBad();
- MMC->settings()->set("SelectedInstance", QString());
- return;
+ MMC->settings()->set("SelectedInstance", QString());
+ selectionBad();
+ return;
}
}
@@ -1475,20 +1413,6 @@ void MainWindow::selectionBad()
setSelectedInstanceById(MMC->settings()->get("SelectedInstance").toString());
}
-void MainWindow::on_actionEditInstNotes_triggered()
-{
- if (!m_selectedInstance)
- return;
-
- EditNotesDialog noteedit(m_selectedInstance->notes(), m_selectedInstance->name(), this);
- noteedit.exec();
- if (noteedit.result() == QDialog::Accepted)
- {
-
- m_selectedInstance->setNotes(noteedit.getText());
- }
-}
-
void MainWindow::instanceEnded()
{
this->show();
@@ -1522,7 +1446,9 @@ void MainWindow::checkMigrateLegacyAssets()
void MainWindow::checkSetDefaultJava()
{
+ const QString javaHack = "IntelHack";
bool askForJava = false;
+ do
{
QString currentHostName = QHostInfo::localHostName();
QString oldHostName = MMC->settings()->get("LastHostname").toString();
@@ -1530,16 +1456,30 @@ void MainWindow::checkSetDefaultJava()
{
MMC->settings()->set("LastHostname", currentHostName);
askForJava = true;
+ break;
}
- }
-
- {
QString currentJavaPath = MMC->settings()->get("JavaPath").toString();
if (currentJavaPath.isEmpty())
{
askForJava = true;
+ break;
}
- }
+ #if defined Q_OS_WIN32
+ QString currentHack = MMC->settings()->get("JavaDetectionHack").toString();
+ if (currentHack != javaHack)
+ {
+ CustomMessageBox::selectable(
+ this, tr("Java detection forced"),
+ tr("Because of graphics performance issues caused by Intel drivers on Windows, "
+ "MultiMC java detection was forced. Please select a Java "
+ "version.<br/><br/>If you have custom java versions set for your instances, "
+ "make sure you use the 'javaw.exe' executable."),
+ QMessageBox::Warning)->exec();
+ askForJava = true;
+ break;
+ }
+ #endif
+ } while (0);
if (askForJava)
{
@@ -1567,7 +1507,10 @@ void MainWindow::checkSetDefaultJava()
java = ju.GetDefaultJava();
}
if (java)
+ {
MMC->settings()->set("JavaPath", java->path);
+ MMC->settings()->set("JavaDetectionHack", javaHack);
+ }
else
MMC->settings()->set("JavaPath", QString("java"));
}