From aade36860c373268857ca821c14a13f38c880b1a Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Wed, 23 Apr 2014 02:27:40 +0200 Subject: Begin the transformation! Nuke all the things. --- CMakeLists.txt | 53 ++- MultiMC.cpp | 5 +- gui/MainWindow.cpp | 97 +---- gui/MainWindow.h | 10 +- gui/MainWindow.ui | 83 +--- gui/dialogs/InstanceEditDialog.cpp | 623 +++++++++++++++++++++++++++++ gui/dialogs/InstanceEditDialog.h | 97 +++++ gui/dialogs/InstanceEditDialog.ui | 404 +++++++++++++++++++ gui/dialogs/LegacyModEditDialog.cpp | 393 ------------------ gui/dialogs/LegacyModEditDialog.h | 78 ---- gui/dialogs/LegacyModEditDialog.ui | 321 --------------- gui/dialogs/ModEditDialogCommon.cpp | 57 --- gui/dialogs/ModEditDialogCommon.h | 22 - gui/dialogs/OneSixModEditDialog.cpp | 399 ------------------ gui/dialogs/OneSixModEditDialog.h | 75 ---- gui/dialogs/OneSixModEditDialog.ui | 310 -------------- logic/BaseInstaller.h | 2 +- logic/BaseVersion.h | 4 +- logic/ForgeInstaller.cpp | 328 --------------- logic/ForgeInstaller.h | 45 --- logic/InstanceFactory.cpp | 52 +-- logic/LegacyForge.cpp | 56 --- logic/LegacyForge.h | 25 -- logic/LegacyInstance.cpp | 11 +- logic/LegacyUpdate.cpp | 65 +-- logic/LegacyUpdate.h | 9 +- logic/LiteLoaderInstaller.cpp | 150 ------- logic/LiteLoaderInstaller.h | 41 -- logic/MinecraftVersion.h | 45 +-- logic/NostalgiaInstance.cpp | 36 -- logic/NostalgiaInstance.h | 29 -- logic/OneSixFTBInstance.cpp | 4 +- logic/OneSixInstance.cpp | 64 ++- logic/OneSixInstance.h | 11 +- logic/OneSixInstance_p.h | 3 +- logic/OneSixLibrary.h | 2 +- logic/OneSixUpdate.cpp | 2 +- logic/OneSixVersionBuilder.cpp | 10 +- logic/OneSixVersionBuilder.h | 5 +- logic/VersionFile.cpp | 84 +++- logic/VersionFile.h | 19 +- logic/VersionFinal.cpp | 75 ++-- logic/VersionFinal.h | 32 +- logic/forge/ForgeData.cpp | 62 +++ logic/forge/ForgeData.h | 21 + logic/forge/ForgeInstaller.cpp | 380 ++++++++++++++++++ logic/forge/ForgeInstaller.h | 51 +++ logic/forge/ForgeMirror.h | 10 + logic/forge/ForgeMirrors.cpp | 118 ++++++ logic/forge/ForgeMirrors.h | 58 +++ logic/forge/ForgeVersion.cpp | 55 +++ logic/forge/ForgeVersion.h | 31 ++ logic/forge/ForgeVersionList.cpp | 435 ++++++++++++++++++++ logic/forge/ForgeVersionList.h | 83 ++++ logic/forge/ForgeXzDownload.cpp | 389 ++++++++++++++++++ logic/forge/ForgeXzDownload.h | 66 +++ logic/forge/LegacyForge.cpp | 56 +++ logic/forge/LegacyForge.h | 25 ++ logic/lists/ForgeVersionList.cpp | 439 -------------------- logic/lists/ForgeVersionList.h | 128 ------ logic/lists/LiteLoaderVersionList.cpp | 223 ----------- logic/lists/LiteLoaderVersionList.h | 112 ------ logic/lists/MinecraftVersionList.cpp | 16 +- logic/liteloader/LiteLoaderInstaller.cpp | 150 +++++++ logic/liteloader/LiteLoaderInstaller.h | 40 ++ logic/liteloader/LiteLoaderVersionList.cpp | 223 +++++++++++ logic/liteloader/LiteLoaderVersionList.h | 112 ++++++ logic/net/ForgeMirror.h | 10 - logic/net/ForgeMirrors.cpp | 118 ------ logic/net/ForgeMirrors.h | 58 --- logic/net/ForgeXzDownload.cpp | 389 ------------------ logic/net/ForgeXzDownload.h | 66 --- logic/net/NetJob.h | 2 +- 73 files changed, 3819 insertions(+), 4343 deletions(-) create mode 100644 gui/dialogs/InstanceEditDialog.cpp create mode 100644 gui/dialogs/InstanceEditDialog.h create mode 100644 gui/dialogs/InstanceEditDialog.ui delete mode 100644 gui/dialogs/LegacyModEditDialog.cpp delete mode 100644 gui/dialogs/LegacyModEditDialog.h delete mode 100644 gui/dialogs/LegacyModEditDialog.ui delete mode 100644 gui/dialogs/ModEditDialogCommon.cpp delete mode 100644 gui/dialogs/ModEditDialogCommon.h delete mode 100644 gui/dialogs/OneSixModEditDialog.cpp delete mode 100644 gui/dialogs/OneSixModEditDialog.h delete mode 100644 gui/dialogs/OneSixModEditDialog.ui delete mode 100644 logic/ForgeInstaller.cpp delete mode 100644 logic/ForgeInstaller.h delete mode 100644 logic/LegacyForge.cpp delete mode 100644 logic/LegacyForge.h delete mode 100644 logic/LiteLoaderInstaller.cpp delete mode 100644 logic/LiteLoaderInstaller.h delete mode 100644 logic/NostalgiaInstance.cpp delete mode 100644 logic/NostalgiaInstance.h create mode 100644 logic/forge/ForgeData.cpp create mode 100644 logic/forge/ForgeData.h create mode 100644 logic/forge/ForgeInstaller.cpp create mode 100644 logic/forge/ForgeInstaller.h create mode 100644 logic/forge/ForgeMirror.h create mode 100644 logic/forge/ForgeMirrors.cpp create mode 100644 logic/forge/ForgeMirrors.h create mode 100644 logic/forge/ForgeVersion.cpp create mode 100644 logic/forge/ForgeVersion.h create mode 100644 logic/forge/ForgeVersionList.cpp create mode 100644 logic/forge/ForgeVersionList.h create mode 100644 logic/forge/ForgeXzDownload.cpp create mode 100644 logic/forge/ForgeXzDownload.h create mode 100644 logic/forge/LegacyForge.cpp create mode 100644 logic/forge/LegacyForge.h delete mode 100644 logic/lists/ForgeVersionList.cpp delete mode 100644 logic/lists/ForgeVersionList.h delete mode 100644 logic/lists/LiteLoaderVersionList.cpp delete mode 100644 logic/lists/LiteLoaderVersionList.h create mode 100644 logic/liteloader/LiteLoaderInstaller.cpp create mode 100644 logic/liteloader/LiteLoaderInstaller.h create mode 100644 logic/liteloader/LiteLoaderVersionList.cpp create mode 100644 logic/liteloader/LiteLoaderVersionList.h delete mode 100644 logic/net/ForgeMirror.h delete mode 100644 logic/net/ForgeMirrors.cpp delete mode 100644 logic/net/ForgeMirrors.h delete mode 100644 logic/net/ForgeXzDownload.cpp delete mode 100644 logic/net/ForgeXzDownload.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 345bb366..4617020a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -309,12 +309,8 @@ SET(MULTIMC_SOURCES gui/dialogs/InstanceSettings.cpp gui/dialogs/IconPickerDialog.h gui/dialogs/IconPickerDialog.cpp - gui/dialogs/LegacyModEditDialog.h - gui/dialogs/LegacyModEditDialog.cpp - gui/dialogs/OneSixModEditDialog.h - gui/dialogs/OneSixModEditDialog.cpp - gui/dialogs/ModEditDialogCommon.h - gui/dialogs/ModEditDialogCommon.cpp + gui/dialogs/InstanceEditDialog.h + gui/dialogs/InstanceEditDialog.cpp gui/dialogs/EditNotesDialog.h gui/dialogs/EditNotesDialog.cpp gui/dialogs/CustomMessageBox.h @@ -395,10 +391,6 @@ SET(MULTIMC_SOURCES logic/net/ByteArrayDownload.cpp logic/net/CacheDownload.h logic/net/CacheDownload.cpp - logic/net/ForgeMirrors.h - logic/net/ForgeMirrors.cpp - logic/net/ForgeXzDownload.h - logic/net/ForgeXzDownload.cpp logic/net/NetJob.h logic/net/NetJob.cpp logic/net/HttpMetaCache.h @@ -449,9 +441,6 @@ SET(MULTIMC_SOURCES logic/LegacyUpdate.h logic/LegacyUpdate.cpp - logic/LegacyForge.h - logic/LegacyForge.cpp - # OneSix instances logic/OneSixUpdate.h logic/OneSixUpdate.cpp @@ -476,14 +465,6 @@ SET(MULTIMC_SOURCES # Mod installers logic/BaseInstaller.h logic/BaseInstaller.cpp - logic/ForgeInstaller.h - logic/ForgeInstaller.cpp - logic/LiteLoaderInstaller.h - logic/LiteLoaderInstaller.cpp - - # Nostalgia - logic/NostalgiaInstance.h - logic/NostalgiaInstance.cpp # FTB logic/OneSixFTBInstance.h @@ -500,12 +481,8 @@ SET(MULTIMC_SOURCES logic/lists/MinecraftVersionList.cpp logic/lists/LwjglVersionList.h logic/lists/LwjglVersionList.cpp - logic/lists/ForgeVersionList.h - logic/lists/ForgeVersionList.cpp logic/lists/JavaVersionList.h logic/lists/JavaVersionList.cpp - logic/lists/LiteLoaderVersionList.h - logic/lists/LiteLoaderVersionList.cpp # the screenshots feature logic/screenshots/Screenshot.h @@ -566,6 +543,29 @@ SET(MULTIMC_SOURCES logic/tools/JProfiler.cpp logic/tools/JVisualVM.h logic/tools/JVisualVM.cpp + + # Forge and all things forge related + logic/forge/ForgeData.h + logic/forge/ForgeData.cpp + logic/forge/ForgeVersion.h + logic/forge/ForgeVersion.cpp + logic/forge/ForgeVersionList.h + logic/forge/ForgeVersionList.cpp + logic/forge/ForgeMirror.h + logic/forge/ForgeMirrors.h + logic/forge/ForgeMirrors.cpp + logic/forge/ForgeXzDownload.h + logic/forge/ForgeXzDownload.cpp + logic/forge/LegacyForge.h + logic/forge/LegacyForge.cpp + logic/forge/ForgeInstaller.h + logic/forge/ForgeInstaller.cpp + + # Liteloader and related things + logic/liteloader/LiteLoaderInstaller.h + logic/liteloader/LiteLoaderInstaller.cpp + logic/liteloader/LiteLoaderVersionList.h + logic/liteloader/LiteLoaderVersionList.cpp ) @@ -585,8 +585,7 @@ SET(MULTIMC_UIS gui/dialogs/InstanceSettings.ui gui/dialogs/ProgressDialog.ui gui/dialogs/IconPickerDialog.ui - gui/dialogs/LegacyModEditDialog.ui - gui/dialogs/OneSixModEditDialog.ui + gui/dialogs/InstanceEditDialog.ui gui/dialogs/EditNotesDialog.ui gui/dialogs/AccountListDialog.ui gui/dialogs/AccountSelectDialog.ui diff --git a/MultiMC.cpp b/MultiMC.cpp index c1fc089c..28fe8e26 100644 --- a/MultiMC.cpp +++ b/MultiMC.cpp @@ -17,8 +17,9 @@ #include "logic/icons/IconList.h" #include "logic/lists/LwjglVersionList.h" #include "logic/lists/MinecraftVersionList.h" -#include "logic/lists/ForgeVersionList.h" -#include "logic/lists/LiteLoaderVersionList.h" +#include "logic/liteloader/LiteLoaderVersionList.h" + +#include "logic/forge/ForgeVersionList.h" #include "logic/news/NewsChecker.h" diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 5ba05b2a..95f2ac4c 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -1032,7 +1032,7 @@ void MainWindow::on_actionViewSelectedInstFolder_triggered() } } -void MainWindow::on_actionEditInstMods_triggered() +void MainWindow::on_actionEditInstance_triggered() { if (m_selectedInstance) { @@ -1339,99 +1339,12 @@ 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() -{ - 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) - { - 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(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 ¤t, const QModelIndex &previous) { if(!current.isValid()) @@ -1446,12 +1359,8 @@ void MainWindow::instanceChanged(const QModelIndex ¤t, const QModelIndex & { 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")); + ui->actionEditInstance->setEnabled( + m_selectedInstance->menuActionEnabled("actionEditInstance")); m_statusLeft->setText(m_selectedInstance->getStatusbarDescription()); updateInstanceToolIcon(m_selectedInstance->iconKey()); diff --git a/gui/MainWindow.h b/gui/MainWindow.h index 69cf11b0..0cd2e84b 100644 --- a/gui/MainWindow.h +++ b/gui/MainWindow.h @@ -103,11 +103,7 @@ slots: void on_actionRenameInstance_triggered(); - void on_actionMakeDesktopShortcut_triggered(); - - void on_actionChangeInstMCVersion_triggered(); - - void on_actionEditInstMods_triggered(); + void on_actionEditInstance_triggered(); void on_actionEditInstNotes_triggered(); @@ -135,12 +131,8 @@ slots: void taskStart(); void taskEnd(); - void on_actionChangeInstLWJGLVersion_triggered(); - void instanceEnded(); - void on_actionInstanceSettings_triggered(); - // called when an icon is changed in the icon model. void iconUpdated(QString); diff --git a/gui/MainWindow.ui b/gui/MainWindow.ui index 1d7fbec9..8ee196fd 100644 --- a/gui/MainWindow.ui +++ b/gui/MainWindow.ui @@ -74,7 +74,7 @@ - + @@ -115,10 +115,7 @@ - - - - + @@ -284,7 +281,7 @@ Open the MultiMC Patreon page. - + @@ -388,82 +385,18 @@ Edit the notes for the selected instance. - - - true - - - Settings - - - Change settings for the selected instance. - - - Change settings for the selected instance. - - - - - false - - - Make Shortcut - - - Make a shortcut on the desktop for the selected instance. - - - Make a shortcut on the desktop for the selected instance. - - - - - false - - - Manage Saves - - - Manage saves for the selected instance. - - - Manage saves for the selected instance. - - - + Edit Mods - - Edit the mods for the selected instance. - - - Edit the mods for the selected instance. - - - - - Change Version - - - Change the selected instance's Minecraft version. - - - Change the selected instance's Minecraft version. - - - - - false - - - Change LWJGL + + Edit Instance - Change the version of LWJGL for the selected instance to use. + Change the instance settings, mods and versions. - Change the version of LWJGL for the selected instance to use. + Change the instance settings, mods and versions. diff --git a/gui/dialogs/InstanceEditDialog.cpp b/gui/dialogs/InstanceEditDialog.cpp new file mode 100644 index 00000000..fe2d1b03 --- /dev/null +++ b/gui/dialogs/InstanceEditDialog.cpp @@ -0,0 +1,623 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "MultiMC.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "InstanceEditDialog.h" +#include "ui_InstanceEditDialog.h" + +#include "gui/Platform.h" +#include "gui/dialogs/CustomMessageBox.h" +#include "gui/dialogs/VersionSelectDialog.h" + +#include "gui/dialogs/ProgressDialog.h" +#include "InstanceSettings.h" + +#include "logic/ModList.h" +#include "logic/VersionFinal.h" +#include "logic/EnabledItemFilter.h" +#include "logic/forge/ForgeVersionList.h" +#include "logic/forge/ForgeInstaller.h" +#include "logic/liteloader/LiteLoaderVersionList.h" +#include "logic/liteloader/LiteLoaderInstaller.h" +#include "logic/OneSixVersionBuilder.h" +#include "logic/auth/MojangAccountList.h" + +#include +#include + +#include "CustomMessageBox.h" +#include +#include +#include +#include + +bool lastfirst(QModelIndexList &list, int &first, int &last) +{ + if (!list.size()) + return false; + first = last = list[0].row(); + for (auto item : list) + { + int row = item.row(); + if (row < first) + first = row; + if (row > last) + last = row; + } + return true; +} + +void showWebsiteForMod(QWidget *parentDlg, Mod &m) +{ + QString url = m.homeurl(); + if (url.size()) + { + // catch the cases where the protocol is missing + if (!url.startsWith("http")) + { + url = "http://" + url; + } + QDesktopServices::openUrl(url); + } + else + { + CustomMessageBox::selectable( + parentDlg, QObject::tr("How sad!"), + QObject::tr("The mod author didn't provide a website link for this mod."), + QMessageBox::Warning); + } +} + +InstanceEditDialog::InstanceEditDialog(OneSixInstance *inst, QWidget *parent) + : QDialog(parent), ui(new Ui::InstanceEditDialog), m_inst(inst) +{ + MultiMCPlatform::fixWM_CLASS(this); + ui->setupUi(this); + // libraries! + + m_version = m_inst->getFullVersion(); + if (m_version) + { + main_model = new EnabledItemFilter(this); + main_model->setActive(true); + main_model->setSourceModel(m_version.get()); + ui->libraryTreeView->setModel(main_model); + ui->libraryTreeView->installEventFilter(this); + connect(ui->libraryTreeView->selectionModel(), &QItemSelectionModel::currentChanged, + this, &InstanceEditDialog::versionCurrent); + updateVersionControls(); + } + else + { + disableVersionControls(); + } + // Loader mods + { + ensureFolderPathExists(m_inst->loaderModsDir()); + m_mods = m_inst->loaderModList(); + ui->loaderModTreeView->setModel(m_mods.get()); + ui->loaderModTreeView->installEventFilter(this); + m_mods->startWatching(); + auto smodel = ui->loaderModTreeView->selectionModel(); + connect(smodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), + SLOT(loaderCurrent(QModelIndex, QModelIndex))); + } + // Core mods + { + ensureFolderPathExists(m_inst->coreModsDir()); + m_coremods = m_inst->coreModList(); + ui->coreModsTreeView->setModel(m_coremods.get()); + ui->coreModsTreeView->installEventFilter(this); + m_coremods->startWatching(); + auto smodel = ui->coreModsTreeView->selectionModel(); + connect(smodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), + SLOT(coreCurrent(QModelIndex, QModelIndex))); + } + // resource packs + { + ensureFolderPathExists(m_inst->resourcePacksDir()); + m_resourcepacks = m_inst->resourcePackList(); + ui->resPackTreeView->setModel(m_resourcepacks.get()); + ui->resPackTreeView->installEventFilter(this); + m_resourcepacks->startWatching(); + } + + connect(m_inst, &OneSixInstance::versionReloaded, this, + &InstanceEditDialog::updateVersionControls); +} + +InstanceEditDialog::~InstanceEditDialog() +{ + m_mods->stopWatching(); + m_resourcepacks->stopWatching(); + m_coremods->stopWatching(); + delete ui; +} + +void InstanceEditDialog::updateVersionControls() +{ + ui->forgeBtn->setEnabled(true); + ui->liteloaderBtn->setEnabled(true); +} + +void InstanceEditDialog::disableVersionControls() +{ + ui->forgeBtn->setEnabled(false); + ui->liteloaderBtn->setEnabled(false); + ui->reloadLibrariesBtn->setEnabled(false); + ui->removeLibraryBtn->setEnabled(false); +} + +bool InstanceEditDialog::reloadInstanceVersion() +{ + try + { + m_inst->reloadVersion(); + return true; + } + catch (MMCError &e) + { + QMessageBox::critical(this, tr("Error"), e.cause()); + return false; + } + catch (...) + { + QMessageBox::critical( + this, tr("Error"), + tr("Failed to load the version description file for reasons unknown.")); + return false; + } +} + +void InstanceEditDialog::on_settingsBtn_clicked() +{ + InstanceSettings settings(&m_inst->settings(), this); + settings.setWindowTitle(tr("Instance settings")); + settings.exec(); +} + +void InstanceEditDialog::on_reloadLibrariesBtn_clicked() +{ + reloadInstanceVersion(); +} + +void InstanceEditDialog::on_removeLibraryBtn_clicked() +{ + if (ui->libraryTreeView->currentIndex().isValid()) + { + // FIXME: use actual model, not reloading. + if (!m_version->remove(ui->libraryTreeView->currentIndex().row())) + { + QMessageBox::critical(this, tr("Error"), tr("Couldn't remove file")); + } + } +} + +void InstanceEditDialog::on_resetLibraryOrderBtn_clicked() +{ + try + { + m_version->resetOrder(); + } + catch (MMCError &e) + { + QMessageBox::critical(this, tr("Error"), e.cause()); + } +} + +void InstanceEditDialog::on_moveLibraryUpBtn_clicked() +{ + if (ui->libraryTreeView->selectionModel()->selectedRows().isEmpty()) + { + return; + } + try + { + const int row = ui->libraryTreeView->selectionModel()->selectedRows().first().row(); + const int newRow = 0;m_version->move(row, VersionFinal::MoveUp); + //ui->libraryTreeView->selectionModel()->setCurrentIndex(m_version->index(newRow), QItemSelectionModel::ClearAndSelect); + } + catch (MMCError &e) + { + QMessageBox::critical(this, tr("Error"), e.cause()); + } +} + +void InstanceEditDialog::on_moveLibraryDownBtn_clicked() +{ + if (ui->libraryTreeView->selectionModel()->selectedRows().isEmpty()) + { + return; + } + try + { + const int row = ui->libraryTreeView->selectionModel()->selectedRows().first().row(); + const int newRow = 0;m_version->move(row, VersionFinal::MoveDown); + //ui->libraryTreeView->selectionModel()->setCurrentIndex(m_version->index(newRow), QItemSelectionModel::ClearAndSelect); + } + catch (MMCError &e) + { + QMessageBox::critical(this, tr("Error"), e.cause()); + } +} + +// FIXME: use this for legacy forge... or abstract away. +/* +void LegacyModEditDialog::on_addForgeBtn_clicked() +{ + VersionSelectDialog vselect(MMC->forgelist().get(), tr("Select Forge version"), this); + vselect.setFilter(1, m_inst->intendedVersionId()); + if (vselect.exec() && vselect.selectedVersion()) + { + ForgeVersionPtr forge = + std::dynamic_pointer_cast(vselect.selectedVersion()); + if (!forge) + return; + auto entry = MMC->metacache()->resolveEntry("minecraftforge", forge->filename); + if (entry->stale) + { + NetJob *fjob = new NetJob("Forge download"); + fjob->addNetAction(CacheDownload::make(forge->universal_url, entry)); + ProgressDialog dlg(this); + dlg.exec(fjob); + if (dlg.result() == QDialog::Accepted) + { + m_jarmods->stopWatching(); + m_jarmods->installMod(QFileInfo(entry->getFullPath())); + m_jarmods->startWatching(); + } + else + { + // failed to download forge :/ + } + } + else + { + m_jarmods->stopWatching(); + m_jarmods->installMod(QFileInfo(entry->getFullPath())); + m_jarmods->startWatching(); + } + } +}*/ + +void InstanceEditDialog::on_changeMCVersionBtn_clicked() +{ + VersionSelectDialog vselect(m_inst->versionList().get(), tr("Change Minecraft version"), this); + 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_inst->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_version->revertToVanilla(); + reloadInstanceVersion(); + } + m_inst->setIntendedVersionId(vselect.selectedVersion()->descriptor()); + + auto updateTask = m_inst->doUpdate(); + if (!updateTask) + { + 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(m_selectedInstance); + if(ptr) + ptr->setLWJGLVersion(lselect.selectedVersion()); + } +} +*/ + + +void InstanceEditDialog::on_forgeBtn_clicked() +{ + // FIXME: use actual model, not reloading. Move logic to model. + if (m_version->hasFtbPack()) + { + if (QMessageBox::question(this, tr("Revert?"), + tr("This action will remove the FTB pack version patch. Continue?")) != + QMessageBox::Yes) + { + return; + } + m_version->removeFtbPack(); + reloadInstanceVersion(); + } + if (m_version->usesLegacyCustomJson()) + { + if (QMessageBox::question(this, tr("Revert?"), + tr("This action will remove your custom.json. Continue?")) != + QMessageBox::Yes) + { + return; + } + m_version->revertToVanilla(); + reloadInstanceVersion(); + } + VersionSelectDialog vselect(MMC->forgelist().get(), tr("Select Forge version"), this); + vselect.setExactFilter(1, m_inst->currentVersionId()); + vselect.setEmptyString(tr("No Forge versions are currently available for Minecraft ") + + m_inst->currentVersionId()); + if (vselect.exec() && vselect.selectedVersion()) + { + ProgressDialog dialog(this); + dialog.exec(ForgeInstaller().createInstallTask(m_inst, vselect.selectedVersion(), this)); + } +} + +void InstanceEditDialog::on_liteloaderBtn_clicked() +{ + if (m_version->hasFtbPack()) + { + if (QMessageBox::question(this, tr("Revert?"), + tr("This action will remove the FTB pack version patch. Continue?")) != + QMessageBox::Yes) + { + return; + } + m_version->removeFtbPack(); + reloadInstanceVersion(); + } + if (m_version->usesLegacyCustomJson()) + { + if (QMessageBox::question(this, tr("Revert?"), + tr("This action will remove your custom.json. Continue?")) != + QMessageBox::Yes) + { + return; + } + m_version->revertToVanilla(); + reloadInstanceVersion(); + } + VersionSelectDialog vselect(MMC->liteloaderlist().get(), tr("Select LiteLoader version"), + this); + vselect.setExactFilter(1, m_inst->currentVersionId()); + vselect.setEmptyString(tr("No LiteLoader versions are currently available for Minecraft ") + + m_inst->currentVersionId()); + if (vselect.exec() && vselect.selectedVersion()) + { + ProgressDialog dialog(this); + dialog.exec(LiteLoaderInstaller().createInstallTask(m_inst, vselect.selectedVersion(), this)); + } +} + +bool InstanceEditDialog::loaderListFilter(QKeyEvent *keyEvent) +{ + switch (keyEvent->key()) + { + case Qt::Key_Delete: + on_rmModBtn_clicked(); + return true; + case Qt::Key_Plus: + on_addModBtn_clicked(); + return true; + default: + break; + } + return QDialog::eventFilter(ui->loaderModTreeView, keyEvent); +} + +bool InstanceEditDialog::coreListFilter(QKeyEvent *keyEvent) +{ + switch (keyEvent->key()) + { + case Qt::Key_Delete: + on_rmCoreBtn_clicked(); + return true; + case Qt::Key_Plus: + on_addCoreBtn_clicked(); + return true; + default: + break; + } + return QDialog::eventFilter(ui->coreModsTreeView, keyEvent); +} + +bool InstanceEditDialog::resourcePackListFilter(QKeyEvent *keyEvent) +{ + switch (keyEvent->key()) + { + case Qt::Key_Delete: + on_rmResPackBtn_clicked(); + return true; + case Qt::Key_Plus: + on_addResPackBtn_clicked(); + return true; + default: + break; + } + return QDialog::eventFilter(ui->resPackTreeView, keyEvent); +} + +bool InstanceEditDialog::eventFilter(QObject *obj, QEvent *ev) +{ + if (ev->type() != QEvent::KeyPress) + { + return QDialog::eventFilter(obj, ev); + } + QKeyEvent *keyEvent = static_cast(ev); + if (obj == ui->loaderModTreeView) + return loaderListFilter(keyEvent); + if (obj == ui->coreModsTreeView) + return coreListFilter(keyEvent); + if (obj == ui->resPackTreeView) + return resourcePackListFilter(keyEvent); + return QDialog::eventFilter(obj, ev); +} + +void InstanceEditDialog::on_buttonBox_rejected() +{ + close(); +} + +void InstanceEditDialog::on_addModBtn_clicked() +{ + QStringList fileNames = QFileDialog::getOpenFileNames( + this, QApplication::translate("InstanceEditDialog", "Select Loader Mods")); + for (auto filename : fileNames) + { + m_mods->stopWatching(); + m_mods->installMod(QFileInfo(filename)); + m_mods->startWatching(); + } +} +void InstanceEditDialog::on_rmModBtn_clicked() +{ + int first, last; + auto list = ui->loaderModTreeView->selectionModel()->selectedRows(); + + if (!lastfirst(list, first, last)) + return; + m_mods->stopWatching(); + m_mods->deleteMods(first, last); + m_mods->startWatching(); +} +void InstanceEditDialog::on_viewModBtn_clicked() +{ + openDirInDefaultProgram(m_inst->loaderModsDir(), true); +} + +void InstanceEditDialog::on_addCoreBtn_clicked() +{ + //: Title of core mod selection dialog + QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select Core Mods")); + for (auto filename : fileNames) + { + m_coremods->stopWatching(); + m_coremods->installMod(QFileInfo(filename)); + m_coremods->startWatching(); + } +} + +void InstanceEditDialog::on_rmCoreBtn_clicked() +{ + int first, last; + auto list = ui->coreModsTreeView->selectionModel()->selectedRows(); + + if (!lastfirst(list, first, last)) + return; + m_coremods->stopWatching(); + m_coremods->deleteMods(first, last); + m_coremods->startWatching(); +} + +void InstanceEditDialog::on_viewCoreBtn_clicked() +{ + openDirInDefaultProgram(m_inst->coreModsDir(), true); +} + +void InstanceEditDialog::on_addResPackBtn_clicked() +{ + QStringList fileNames = QFileDialog::getOpenFileNames( + this, QApplication::translate("InstanceEditDialog", "Select Resource Packs")); + for (auto filename : fileNames) + { + m_resourcepacks->stopWatching(); + m_resourcepacks->installMod(QFileInfo(filename)); + m_resourcepacks->startWatching(); + } +} +void InstanceEditDialog::on_rmResPackBtn_clicked() +{ + int first, last; + auto list = ui->resPackTreeView->selectionModel()->selectedRows(); + + if (!lastfirst(list, first, last)) + return; + m_resourcepacks->stopWatching(); + m_resourcepacks->deleteMods(first, last); + m_resourcepacks->startWatching(); +} +void InstanceEditDialog::on_viewResPackBtn_clicked() +{ + openDirInDefaultProgram(m_inst->resourcePacksDir(), true); +} + +void InstanceEditDialog::loaderCurrent(QModelIndex current, QModelIndex previous) +{ + if (!current.isValid()) + { + ui->frame->clear(); + return; + } + int row = current.row(); + Mod &m = m_mods->operator[](row); + ui->frame->updateWithMod(m); +} + +void InstanceEditDialog::versionCurrent(const QModelIndex ¤t, + const QModelIndex &previous) +{ + if (!current.isValid()) + { + ui->removeLibraryBtn->setDisabled(true); + } + else + { + ui->removeLibraryBtn->setEnabled(m_version->canRemove(current.row())); + } +} + +void InstanceEditDialog::coreCurrent(QModelIndex current, QModelIndex previous) +{ + if (!current.isValid()) + { + ui->coreMIFrame->clear(); + return; + } + int row = current.row(); + Mod &m = m_coremods->operator[](row); + ui->coreMIFrame->updateWithMod(m); +} diff --git a/gui/dialogs/InstanceEditDialog.h b/gui/dialogs/InstanceEditDialog.h new file mode 100644 index 00000000..ea2c6496 --- /dev/null +++ b/gui/dialogs/InstanceEditDialog.h @@ -0,0 +1,97 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include + +#include +#include + +class EnabledItemFilter; +namespace Ui +{ +class InstanceEditDialog; +} + +class InstanceEditDialog : public QDialog +{ + Q_OBJECT + +public: + explicit InstanceEditDialog(OneSixInstance *inst, QWidget *parent = 0); + virtual ~InstanceEditDialog(); + +private +slots: + + // version tab + void on_forgeBtn_clicked(); + void on_liteloaderBtn_clicked(); + void on_reloadLibrariesBtn_clicked(); + void on_removeLibraryBtn_clicked(); + void on_resetLibraryOrderBtn_clicked(); + void on_settingsBtn_clicked(); + void on_moveLibraryUpBtn_clicked(); + void on_moveLibraryDownBtn_clicked(); + + // loader mod tab + void on_addModBtn_clicked(); + void on_rmModBtn_clicked(); + void on_viewModBtn_clicked(); + + // core mod tab + void on_addCoreBtn_clicked(); + void on_rmCoreBtn_clicked(); + void on_viewCoreBtn_clicked(); + + // resource pack tab + void on_addResPackBtn_clicked(); + void on_rmResPackBtn_clicked(); + void on_viewResPackBtn_clicked(); + + + // Questionable: SettingsDialog doesn't need this for some reason? + void on_buttonBox_rejected(); + + void updateVersionControls(); + void disableVersionControls(); + void on_changeMCVersionBtn_clicked(); + +protected: + bool eventFilter(QObject *obj, QEvent *ev); + bool jarListFilter(QKeyEvent *ev); + bool loaderListFilter(QKeyEvent *ev); + bool coreListFilter(QKeyEvent *ev); + bool resourcePackListFilter(QKeyEvent *ev); + /// FIXME: this shouldn't be necessary! + bool reloadInstanceVersion(); + +private: + Ui::InstanceEditDialog *ui; + std::shared_ptr m_version; + std::shared_ptr m_mods; + std::shared_ptr m_coremods; + std::shared_ptr m_jarmods; + std::shared_ptr m_resourcepacks; + EnabledItemFilter *main_model; + OneSixInstance *m_inst; + NetJobPtr forgeJob; + +public +slots: + void loaderCurrent(QModelIndex current, QModelIndex previous); + void versionCurrent(const QModelIndex ¤t, const QModelIndex &previous); + void coreCurrent(QModelIndex current, QModelIndex previous); +}; diff --git a/gui/dialogs/InstanceEditDialog.ui b/gui/dialogs/InstanceEditDialog.ui new file mode 100644 index 00000000..0ad79833 --- /dev/null +++ b/gui/dialogs/InstanceEditDialog.ui @@ -0,0 +1,404 @@ + + + InstanceEditDialog + + + + 0 + 0 + 593 + 568 + + + + Edit Instance + + + + + + false + + + QDialogButtonBox::Close + + + + + + + true + + + + 0 + 0 + + + + 0 + + + + Version + + + + + + + + Qt::ScrollBarAlwaysOn + + + Qt::ScrollBarAlwaysOff + + + false + + + + + + + + + + + Change version + + + + + + + Replace any current custom version with Minecraft Forge + + + Install Forge + + + + + + + Install LiteLoader + + + + + + + Add jar mod + + + + + + + Qt::Horizontal + + + + + + + Reload + + + + + + + Remove + + + + + + + Qt::Horizontal + + + + + + + This isn't implemented yet. + + + Move up + + + + + + + This isn't implemented yet. + + + Move down + + + + + + + This isn't implemented yet. + + + Reset order + + + + + + + Qt::Horizontal + + + + + + + Settings + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Core Mods + + + + + + + + QAbstractItemView::DropOnly + + + + + + + + + &Add + + + + + + + &Remove + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + &View Folder + + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + Loader Mods + + + + + + + + + + + 0 + 0 + + + + true + + + QAbstractItemView::DropOnly + + + + + + + + + + + &Add + + + + + + + &Remove + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + &View Folder + + + + + + + + + + + + 0 + 0 + + + + + + + + + Resource Packs + + + + + + true + + + QAbstractItemView::DropOnly + + + + + + + + + &Add + + + + + + + &Remove + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + &View Folder + + + + + + + + + + + + + + ModListView + QTreeView +
gui/widgets/ModListView.h
+
+ + MCModInfoFrame + QFrame +
gui/widgets/MCModInfoFrame.h
+ 1 +
+
+ + +
diff --git a/gui/dialogs/LegacyModEditDialog.cpp b/gui/dialogs/LegacyModEditDialog.cpp deleted file mode 100644 index e5039c02..00000000 --- a/gui/dialogs/LegacyModEditDialog.cpp +++ /dev/null @@ -1,393 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "MultiMC.h" -#include "LegacyModEditDialog.h" -#include "ModEditDialogCommon.h" -#include "VersionSelectDialog.h" -#include "ProgressDialog.h" -#include "ui_LegacyModEditDialog.h" -#include "logic/ModList.h" -#include "logic/lists/ForgeVersionList.h" -#include "gui/Platform.h" - -#include -#include -//#include -#include -#include -#include - -LegacyModEditDialog::LegacyModEditDialog(LegacyInstance *inst, QWidget *parent) - : QDialog(parent), ui(new Ui::LegacyModEditDialog), m_inst(inst) -{ - MultiMCPlatform::fixWM_CLASS(this); - ui->setupUi(this); - - // Jar mods - { - ensureFolderPathExists(m_inst->jarModsDir()); - m_jarmods = m_inst->jarModList(); - ui->jarModsTreeView->setModel(m_jarmods.get()); -#ifndef Q_OS_LINUX - // FIXME: internal DnD causes segfaults later - ui->jarModsTreeView->setDragDropMode(QAbstractItemView::DragDrop); - // FIXME: DnD is glitched with contiguous (we move only first item in selection) - ui->jarModsTreeView->setSelectionMode(QAbstractItemView::SingleSelection); -#endif - ui->jarModsTreeView->installEventFilter(this); - m_jarmods->startWatching(); - auto smodel = ui->jarModsTreeView->selectionModel(); - connect(smodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), - SLOT(jarCurrent(QModelIndex, QModelIndex))); - } - // Core mods - { - ensureFolderPathExists(m_inst->coreModsDir()); - m_coremods = m_inst->coreModList(); - ui->coreModsTreeView->setModel(m_coremods.get()); - ui->coreModsTreeView->installEventFilter(this); - m_coremods->startWatching(); - auto smodel = ui->coreModsTreeView->selectionModel(); - connect(smodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), - SLOT(coreCurrent(QModelIndex, QModelIndex))); - } - // Loader mods - { - ensureFolderPathExists(m_inst->loaderModsDir()); - m_mods = m_inst->loaderModList(); - ui->loaderModTreeView->setModel(m_mods.get()); - ui->loaderModTreeView->installEventFilter(this); - m_mods->startWatching(); - auto smodel = ui->loaderModTreeView->selectionModel(); - connect(smodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), - SLOT(loaderCurrent(QModelIndex, QModelIndex))); - } - // texture packs - { - ensureFolderPathExists(m_inst->texturePacksDir()); - m_texturepacks = m_inst->texturePackList(); - ui->texPackTreeView->setModel(m_texturepacks.get()); - ui->texPackTreeView->installEventFilter(this); - m_texturepacks->startWatching(); - } -} - -LegacyModEditDialog::~LegacyModEditDialog() -{ - m_mods->stopWatching(); - m_coremods->stopWatching(); - m_jarmods->stopWatching(); - m_texturepacks->stopWatching(); - delete ui; -} - -bool LegacyModEditDialog::coreListFilter(QKeyEvent *keyEvent) -{ - switch (keyEvent->key()) - { - case Qt::Key_Delete: - on_rmCoreBtn_clicked(); - return true; - case Qt::Key_Plus: - on_addCoreBtn_clicked(); - return true; - default: - break; - } - return QDialog::eventFilter(ui->coreModsTreeView, keyEvent); -} - -bool LegacyModEditDialog::jarListFilter(QKeyEvent *keyEvent) -{ - switch (keyEvent->key()) - { - case Qt::Key_Up: - { - if (keyEvent->modifiers() & Qt::ControlModifier) - { - on_moveJarUpBtn_clicked(); - return true; - } - break; - } - case Qt::Key_Down: - { - if (keyEvent->modifiers() & Qt::ControlModifier) - { - on_moveJarDownBtn_clicked(); - return true; - } - break; - } - case Qt::Key_Delete: - on_rmJarBtn_clicked(); - return true; - case Qt::Key_Plus: - on_addJarBtn_clicked(); - return true; - default: - break; - } - return QDialog::eventFilter(ui->jarModsTreeView, keyEvent); -} - -bool LegacyModEditDialog::loaderListFilter(QKeyEvent *keyEvent) -{ - switch (keyEvent->key()) - { - case Qt::Key_Delete: - on_rmModBtn_clicked(); - return true; - case Qt::Key_Plus: - on_addModBtn_clicked(); - return true; - default: - break; - } - return QDialog::eventFilter(ui->loaderModTreeView, keyEvent); -} - -bool LegacyModEditDialog::texturePackListFilter(QKeyEvent *keyEvent) -{ - switch (keyEvent->key()) - { - case Qt::Key_Delete: - on_rmTexPackBtn_clicked(); - return true; - case Qt::Key_Plus: - on_addTexPackBtn_clicked(); - return true; - default: - break; - } - return QDialog::eventFilter(ui->texPackTreeView, keyEvent); -} - -bool LegacyModEditDialog::eventFilter(QObject *obj, QEvent *ev) -{ - if (ev->type() != QEvent::KeyPress) - { - return QDialog::eventFilter(obj, ev); - } - QKeyEvent *keyEvent = static_cast(ev); - if (obj == ui->jarModsTreeView) - return jarListFilter(keyEvent); - if (obj == ui->coreModsTreeView) - return coreListFilter(keyEvent); - if (obj == ui->loaderModTreeView) - return loaderListFilter(keyEvent); - if (obj == ui->texPackTreeView) - return texturePackListFilter(keyEvent); - return QDialog::eventFilter(obj, ev); -} - -void LegacyModEditDialog::on_addCoreBtn_clicked() -{ - //: Title of core mod selection dialog - QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select Core Mods")); - for (auto filename : fileNames) - { - m_coremods->stopWatching(); - m_coremods->installMod(QFileInfo(filename)); - m_coremods->startWatching(); - } -} -void LegacyModEditDialog::on_addForgeBtn_clicked() -{ - VersionSelectDialog vselect(MMC->forgelist().get(), tr("Select Forge version"), this); - vselect.setExactFilter(1, m_inst->intendedVersionId()); - if (vselect.exec() && vselect.selectedVersion()) - { - ForgeVersionPtr forge = - std::dynamic_pointer_cast(vselect.selectedVersion()); - if (!forge) - return; - auto entry = MMC->metacache()->resolveEntry("minecraftforge", forge->filename); - if (entry->stale) - { - NetJob *fjob = new NetJob("Forge download"); - fjob->addNetAction(CacheDownload::make(forge->universal_url, entry)); - ProgressDialog dlg(this); - dlg.exec(fjob); - if (dlg.result() == QDialog::Accepted) - { - m_jarmods->stopWatching(); - m_jarmods->installMod(QFileInfo(entry->getFullPath())); - m_jarmods->startWatching(); - } - else - { - // failed to download forge :/ - } - } - else - { - m_jarmods->stopWatching(); - m_jarmods->installMod(QFileInfo(entry->getFullPath())); - m_jarmods->startWatching(); - } - } -} -void LegacyModEditDialog::on_addJarBtn_clicked() -{ - //: Title of jar mod selection dialog - QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select Jar Mods")); - for (auto filename : fileNames) - { - m_jarmods->stopWatching(); - m_jarmods->installMod(QFileInfo(filename)); - m_jarmods->startWatching(); - } -} -void LegacyModEditDialog::on_addModBtn_clicked() -{ - //: Title of regular mod selection dialog - QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select Loader Mods")); - for (auto filename : fileNames) - { - m_mods->stopWatching(); - m_mods->installMod(QFileInfo(filename)); - m_mods->startWatching(); - } -} -void LegacyModEditDialog::on_addTexPackBtn_clicked() -{ - //: Title of texture pack selection dialog - QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select Texture Packs")); - for (auto filename : fileNames) - { - m_texturepacks->stopWatching(); - m_texturepacks->installMod(QFileInfo(filename)); - m_texturepacks->startWatching(); - } -} - -void LegacyModEditDialog::on_moveJarDownBtn_clicked() -{ - int first, last; - auto list = ui->jarModsTreeView->selectionModel()->selectedRows(); - - if (!lastfirst(list, first, last)) - return; - - m_jarmods->moveModsDown(first, last); -} -void LegacyModEditDialog::on_moveJarUpBtn_clicked() -{ - int first, last; - auto list = ui->jarModsTreeView->selectionModel()->selectedRows(); - - if (!lastfirst(list, first, last)) - return; - m_jarmods->moveModsUp(first, last); -} -void LegacyModEditDialog::on_rmCoreBtn_clicked() -{ - int first, last; - auto list = ui->coreModsTreeView->selectionModel()->selectedRows(); - - if (!lastfirst(list, first, last)) - return; - m_coremods->stopWatching(); - m_coremods->deleteMods(first, last); - m_coremods->startWatching(); -} -void LegacyModEditDialog::on_rmJarBtn_clicked() -{ - int first, last; - auto list = ui->jarModsTreeView->selectionModel()->selectedRows(); - - if (!lastfirst(list, first, last)) - return; - m_jarmods->stopWatching(); - m_jarmods->deleteMods(first, last); - m_jarmods->startWatching(); -} -void LegacyModEditDialog::on_rmModBtn_clicked() -{ - int first, last; - auto list = ui->loaderModTreeView->selectionModel()->selectedRows(); - - if (!lastfirst(list, first, last)) - return; - m_mods->stopWatching(); - m_mods->deleteMods(first, last); - m_mods->startWatching(); -} -void LegacyModEditDialog::on_rmTexPackBtn_clicked() -{ - int first, last; - auto list = ui->texPackTreeView->selectionModel()->selectedRows(); - - if (!lastfirst(list, first, last)) - return; - m_texturepacks->stopWatching(); - m_texturepacks->deleteMods(first, last); - m_texturepacks->startWatching(); -} -void LegacyModEditDialog::on_viewCoreBtn_clicked() -{ - openDirInDefaultProgram(m_inst->coreModsDir(), true); -} -void LegacyModEditDialog::on_viewModBtn_clicked() -{ - openDirInDefaultProgram(m_inst->loaderModsDir(), true); -} -void LegacyModEditDialog::on_viewTexPackBtn_clicked() -{ - openDirInDefaultProgram(m_inst->texturePacksDir(), true); -} - -void LegacyModEditDialog::on_buttonBox_rejected() -{ - close(); -} - -void LegacyModEditDialog::jarCurrent(QModelIndex current, QModelIndex previous) -{ - if (!current.isValid()) - { - ui->jarMIFrame->clear(); - return; - } - int row = current.row(); - Mod &m = m_jarmods->operator[](row); - ui->jarMIFrame->updateWithMod(m); -} - -void LegacyModEditDialog::coreCurrent(QModelIndex current, QModelIndex previous) -{ - if (!current.isValid()) - { - ui->coreMIFrame->clear(); - return; - } - int row = current.row(); - Mod &m = m_coremods->operator[](row); - ui->coreMIFrame->updateWithMod(m); -} - -void LegacyModEditDialog::loaderCurrent(QModelIndex current, QModelIndex previous) -{ - if (!current.isValid()) - { - ui->loaderMIFrame->clear(); - return; - } - int row = current.row(); - Mod &m = m_mods->operator[](row); - ui->loaderMIFrame->updateWithMod(m); -} diff --git a/gui/dialogs/LegacyModEditDialog.h b/gui/dialogs/LegacyModEditDialog.h deleted file mode 100644 index d5582aef..00000000 --- a/gui/dialogs/LegacyModEditDialog.h +++ /dev/null @@ -1,78 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include "logic/LegacyInstance.h" -#include - -namespace Ui -{ -class LegacyModEditDialog; -} - -class LegacyModEditDialog : public QDialog -{ - Q_OBJECT - -public: - explicit LegacyModEditDialog(LegacyInstance *inst, QWidget *parent = 0); - ~LegacyModEditDialog(); - -private -slots: - - void on_addJarBtn_clicked(); - void on_rmJarBtn_clicked(); - void on_addForgeBtn_clicked(); - void on_moveJarUpBtn_clicked(); - void on_moveJarDownBtn_clicked(); - - void on_addCoreBtn_clicked(); - void on_rmCoreBtn_clicked(); - void on_viewCoreBtn_clicked(); - - void on_addModBtn_clicked(); - void on_rmModBtn_clicked(); - void on_viewModBtn_clicked(); - - void on_addTexPackBtn_clicked(); - void on_rmTexPackBtn_clicked(); - void on_viewTexPackBtn_clicked(); - - // Questionable: SettingsDialog doesn't need this for some reason? - void on_buttonBox_rejected(); - - void jarCurrent(QModelIndex current, QModelIndex previous); - void coreCurrent(QModelIndex current, QModelIndex previous); - void loaderCurrent(QModelIndex current, QModelIndex previous); - -protected: - bool eventFilter(QObject *obj, QEvent *ev); - bool jarListFilter(QKeyEvent *ev); - bool coreListFilter(QKeyEvent *ev); - bool loaderListFilter(QKeyEvent *ev); - bool texturePackLis