diff options
| author | Rachel Powers <508861+Ryex@users.noreply.github.com> | 2023-07-31 22:26:20 -0700 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-31 22:26:20 -0700 | 
| commit | 2d1197f59f824a3093ad71b9ee3466bd5e2825c8 (patch) | |
| tree | 368a2ba5ab9a6ae9f3b3fd0841ea5ee1d0283add /launcher/ui/pages/instance | |
| parent | b47993b736ba40a75b5b63290f9d7b5911f8150e (diff) | |
| parent | 9137721e8e5b44f2338a36874a393435cbc6daa3 (diff) | |
| download | PrismLauncher-2d1197f59f824a3093ad71b9ee3466bd5e2825c8.tar.gz PrismLauncher-2d1197f59f824a3093ad71b9ee3466bd5e2825c8.tar.bz2 PrismLauncher-2d1197f59f824a3093ad71b9ee3466bd5e2825c8.zip | |
Merge branch 'develop' into refactor/net-split-headers-to-proxy-class
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
Diffstat (limited to 'launcher/ui/pages/instance')
17 files changed, 318 insertions, 355 deletions
| diff --git a/launcher/ui/pages/instance/ExternalResourcesPage.cpp b/launcher/ui/pages/instance/ExternalResourcesPage.cpp index 8e5226ef..12038f88 100644 --- a/launcher/ui/pages/instance/ExternalResourcesPage.cpp +++ b/launcher/ui/pages/instance/ExternalResourcesPage.cpp @@ -83,7 +83,7 @@ ExternalResourcesPage::ExternalResourcesPage(BaseInstance* instance, std::shared      connect(selection_model, &QItemSelectionModel::currentChanged, this, &ExternalResourcesPage::current);      auto updateExtra = [this]() {          if (updateExtraInfo) -            updateExtraInfo(extraHeaderInfoString()); +            updateExtraInfo(id(), extraHeaderInfoString());      };      connect(selection_model, &QItemSelectionModel::selectionChanged, this, updateExtra);      connect(model.get(), &ResourceFolderModel::updateFinished, this, updateExtra); @@ -151,9 +151,6 @@ void ExternalResourcesPage::retranslate()  void ExternalResourcesPage::itemActivated(const QModelIndex&)  { -    if (!m_controlsEnabled) -        return; -      auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection());  } @@ -197,9 +194,6 @@ bool ExternalResourcesPage::eventFilter(QObject* obj, QEvent* ev)  void ExternalResourcesPage::addItem()  { -    if (!m_controlsEnabled) -        return; -      auto list = GuiUtil::BrowseForFiles(          helpPage(), tr("Select %1", "Select whatever type of files the page contains. Example: 'Loader Mods'").arg(displayName()),          m_fileSelectionFilter.arg(displayName()), APPLICATION->settings()->get("CentralModsDir").toString(), this->parentWidget()); @@ -213,9 +207,6 @@ void ExternalResourcesPage::addItem()  void ExternalResourcesPage::removeItem()  { -    if (!m_controlsEnabled) -        return; -      auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection());      int count = 0; @@ -259,23 +250,37 @@ void ExternalResourcesPage::removeItem()  void ExternalResourcesPage::removeItems(const QItemSelection& selection)  { +    if (m_instance != nullptr && m_instance->isRunning()) { +        auto response = CustomMessageBox::selectable(this, "Confirm Delete", +                                                     "If you remove this resource while the game is running it may crash your game.\n" +                                                     "Are you sure you want to do this?", +                                                     QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No) +                            ->exec(); + +        if (response != QMessageBox::Yes) +            return; +    }      m_model->deleteResources(selection.indexes());  }  void ExternalResourcesPage::enableItem()  { -    if (!m_controlsEnabled) -        return; -      auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection());      m_model->setResourceEnabled(selection.indexes(), EnableAction::ENABLE);  }  void ExternalResourcesPage::disableItem()  { -    if (!m_controlsEnabled) -        return; +    if (m_instance != nullptr && m_instance->isRunning()) { +        auto response = CustomMessageBox::selectable(this, "Confirm disable", +                                                     "If you disable this resource while the game is running it may crash your game.\n" +                                                     "Are you sure you want to do this?", +                                                     QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No) +                            ->exec(); +        if (response != QMessageBox::Yes) +            return; +    }      auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection());      m_model->setResourceEnabled(selection.indexes(), EnableAction::DISABLE);  } diff --git a/launcher/ui/pages/instance/ExternalResourcesPage.h b/launcher/ui/pages/instance/ExternalResourcesPage.h index 6c0a12cb..97d922d8 100644 --- a/launcher/ui/pages/instance/ExternalResourcesPage.h +++ b/launcher/ui/pages/instance/ExternalResourcesPage.h @@ -73,7 +73,5 @@ class ExternalResourcesPage : public QMainWindow, public BasePage {      QString m_fileSelectionFilter;      QString m_viewFilter; -    bool m_controlsEnabled = true; -      std::shared_ptr<Setting> m_wide_bar_setting = nullptr;  }; diff --git a/launcher/ui/pages/instance/ExternalResourcesPage.ui b/launcher/ui/pages/instance/ExternalResourcesPage.ui index f676361c..3c836691 100644 --- a/launcher/ui/pages/instance/ExternalResourcesPage.ui +++ b/launcher/ui/pages/instance/ExternalResourcesPage.ui @@ -157,6 +157,17 @@      <string>Try to check or update all selected resources (all resources if none are selected)</string>     </property>    </action> +  <action name="actionVisitItemPage"> +   <property name="enabled"> +    <bool>false</bool> +   </property> +   <property name="text"> +    <string>Visit mod's page</string> +   </property> +   <property name="toolTip"> +    <string>Go to mods home page</string> +   </property> +  </action>   </widget>   <customwidgets>    <customwidget> diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.cpp b/launcher/ui/pages/instance/InstanceSettingsPage.cpp index 08977841..25cc1a0d 100644 --- a/launcher/ui/pages/instance/InstanceSettingsPage.cpp +++ b/launcher/ui/pages/instance/InstanceSettingsPage.cpp @@ -3,6 +3,7 @@   *  PolyMC - Minecraft Launcher   *  Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>   *  Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net> + *  Copyright (C) 2023 seth <getchoo at tuta dot io>   *   *  This program is free software: you can redistribute it and/or modify   *  it under the terms of the GNU General Public License as published by @@ -50,9 +51,9 @@  #include "Application.h"  #include "minecraft/auth/AccountList.h" +#include "FileSystem.h"  #include "java/JavaInstallList.h"  #include "java/JavaUtils.h" -#include "FileSystem.h"  InstanceSettingsPage::InstanceSettingsPage(BaseInstance *inst, QWidget *parent)      : QWidget(parent), ui(new Ui::InstanceSettingsPage), m_instance(inst) @@ -60,17 +61,13 @@ InstanceSettingsPage::InstanceSettingsPage(BaseInstance *inst, QWidget *parent)      m_settings = inst->settings();      ui->setupUi(this); -    // As the signal will (probably) not be triggered once we click edit, let's update it manually instead. -    updateRunningStatus(m_instance->isRunning()); - -    connect(m_instance, &BaseInstance::runningStatusChanged, this, &InstanceSettingsPage::updateRunningStatus);      connect(ui->openGlobalJavaSettingsButton, &QCommandLinkButton::clicked, this, &InstanceSettingsPage::globalSettingsButtonClicked);      connect(APPLICATION, &Application::globalSettingsAboutToOpen, this, &InstanceSettingsPage::applySettings);      connect(APPLICATION, &Application::globalSettingsClosed, this, &InstanceSettingsPage::loadSettings); -    connect(ui->instanceAccountSelector, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &InstanceSettingsPage::changeInstanceAccount); +    connect(ui->instanceAccountSelector, QOverload<int>::of(&QComboBox::currentIndexChanged), this, +            &InstanceSettingsPage::changeInstanceAccount);      loadSettings(); -      updateThresholds();  } @@ -85,12 +82,12 @@ void InstanceSettingsPage::globalSettingsButtonClicked(bool)          case 0:              APPLICATION->ShowGlobalSettings(this, "java-settings");              return; -        case 1: -            APPLICATION->ShowGlobalSettings(this, "minecraft-settings"); -            return;          case 2:              APPLICATION->ShowGlobalSettings(this, "custom-commands");              return; +        default: +            APPLICATION->ShowGlobalSettings(this, "minecraft-settings"); +            return;      }  } @@ -284,6 +281,14 @@ void InstanceSettingsPage::applySettings()          m_settings->reset("InstanceAccountId");      } +    bool overrideModLoaderSettings = ui->modLoaderSettingsGroupBox->isChecked(); +    m_settings->set("OverrideModLoaderSettings", overrideModLoaderSettings); +    if (overrideModLoaderSettings) { +        m_settings->set("DisableQuiltBeacon", ui->disableQuiltBeaconCheckBox->isChecked()); +    } else { +        m_settings->reset("DisableQuiltBeacon"); +    } +      // FIXME: This should probably be called by a signal instead      m_instance->updateRuntimeContext();  } @@ -384,6 +389,10 @@ void InstanceSettingsPage::loadSettings()      ui->instanceAccountGroupBox->setChecked(m_settings->get("UseAccountForInstance").toBool());      updateAccountsMenu(); + +    // Mod loader specific settings +    ui->modLoaderSettingsGroupBox->setChecked(m_settings->get("OverrideModLoaderSettings").toBool()); +    ui->disableQuiltBeaconCheckBox->setChecked(m_settings->get("DisableQuiltBeacon").toBool());  }  void InstanceSettingsPage::on_javaDetectBtn_clicked() @@ -523,8 +532,3 @@ void InstanceSettingsPage::updateThresholds()          ui->labelMaxMemIcon->setPixmap(pix);      }  } - -void InstanceSettingsPage::updateRunningStatus(bool running) -{ -    setEnabled(!running); -} diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.h b/launcher/ui/pages/instance/InstanceSettingsPage.h index 0438fe3b..036b4181 100644 --- a/launcher/ui/pages/instance/InstanceSettingsPage.h +++ b/launcher/ui/pages/instance/InstanceSettingsPage.h @@ -79,8 +79,7 @@ public:      void updateThresholds(); -private slots: -    void updateRunningStatus(bool running); +   private slots:      void on_javaDetectBtn_clicked();      void on_javaTestBtn_clicked();      void on_javaBrowseBtn_clicked(); diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.ui b/launcher/ui/pages/instance/InstanceSettingsPage.ui index 8427965d..245433fe 100644 --- a/launcher/ui/pages/instance/InstanceSettingsPage.ui +++ b/launcher/ui/pages/instance/InstanceSettingsPage.ui @@ -116,7 +116,7 @@            <item row="2" column="0">             <widget class="QLabel" name="labelPermGen">              <property name="text"> -             <string notr="true">PermGen:</string> +             <string>PermGen:</string>              </property>             </widget>            </item> @@ -542,6 +542,31 @@        </attribute>        <layout class="QVBoxLayout" name="verticalLayout_9">         <item> +        <widget class="QGroupBox" name="modLoaderSettingsGroupBox"> +         <property name="checkable"> +          <bool>true</bool> +         </property> +         <property name="checked"> +          <bool>false</bool> +         </property> +         <property name="title"> +          <string>Mod loader settings</string> +         </property> +         <layout class="QVBoxLayout" name="VerticalLayout_16"> +          <item> +           <widget class="QCheckBox" name="disableQuiltBeaconCheckBox"> +            <property name="text"> +             <string>Disable Quilt Loader Beacon</string> +            </property> +            <property name="toolTip"> +             <string>Disable Quilt loader's beacon for counting monthly active users</string> +            </property> +           </widget> +          </item> +         </layout> +        </widget> +       </item> +       <item>          <widget class="QGroupBox" name="gameTimeGroupBox">           <property name="enabled">            <bool>true</bool> diff --git a/launcher/ui/pages/instance/ManagedPackPage.cpp b/launcher/ui/pages/instance/ManagedPackPage.cpp index f6f7070a..82de9742 100644 --- a/launcher/ui/pages/instance/ManagedPackPage.cpp +++ b/launcher/ui/pages/instance/ManagedPackPage.cpp @@ -71,7 +71,6 @@ class NoBigComboBoxStyle : public QProxyStyle {     private:      NoBigComboBoxStyle(QStyle* style) : QProxyStyle(style) {} -  };  ManagedPackPage* ManagedPackPage::createPage(BaseInstance* inst, QString type, QWidget* parent) @@ -93,13 +92,13 @@ ManagedPackPage::ManagedPackPage(BaseInstance* inst, InstanceWindow* instance_wi      // NOTE: GTK2 themes crash with the proxy style.      // This seems like an upstream bug, so there's not much else that can be done. -    if (!QStyleFactory::keys().contains("gtk2")){ +    if (!QStyleFactory::keys().contains("gtk2")) {          auto comboStyle = NoBigComboBoxStyle::getInstance(ui->versionsComboBox->style());          ui->versionsComboBox->setStyle(comboStyle);      }      ui->reloadButton->setVisible(false); -    connect(ui->reloadButton, &QPushButton::clicked, this, [this](bool){ +    connect(ui->reloadButton, &QPushButton::clicked, this, [this](bool) {          ui->reloadButton->setVisible(false);          m_loaded = false; @@ -207,7 +206,7 @@ ModrinthManagedPackPage::ModrinthManagedPackPage(BaseInstance* inst, InstanceWin  {      Q_ASSERT(inst->isManagedPack());      connect(ui->versionsComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(suggestVersion())); -    connect(ui->updateButton, &QPushButton::pressed, this, &ModrinthManagedPackPage::update); +    connect(ui->updateButton, &QPushButton::clicked, this, &ModrinthManagedPackPage::update);  }  // MODRINTH @@ -228,7 +227,8 @@ void ModrinthManagedPackPage::parseManagedPack()      QString id = m_inst->getManagedPackID(); -    m_fetch_job->addNetAction(Net::ApiDownload::makeByteArray(QString("%1/project/%2/version").arg(BuildConfig.MODRINTH_PROD_URL, id), response)); +    m_fetch_job->addNetAction( +        Net::ApiDownload::makeByteArray(QString("%1/project/%2/version").arg(BuildConfig.MODRINTH_PROD_URL, id), response));      QObject::connect(m_fetch_job.get(), &NetJob::succeeded, this, [this, response, id] {          QJsonParseError parse_error{}; @@ -269,7 +269,6 @@ void ModrinthManagedPackPage::parseManagedPack()              if (version.version == m_inst->getManagedPackVersionName())                  name = tr("%1 (Current)").arg(name); -              ui->versionsComboBox->addItem(name, QVariant(version.id));          } @@ -293,6 +292,10 @@ QString ModrinthManagedPackPage::url() const  void ModrinthManagedPackPage::suggestVersion()  {      auto index = ui->versionsComboBox->currentIndex(); +    if (m_pack.versions.length() == 0) { +        setFailState(); +        return; +    }      auto version = m_pack.versions.at(index);      ui->changelogTextBrowser->setHtml(markdownToHTML(version.changelog.toUtf8())); @@ -303,6 +306,10 @@ void ModrinthManagedPackPage::suggestVersion()  void ModrinthManagedPackPage::update()  {      auto index = ui->versionsComboBox->currentIndex(); +    if (m_pack.versions.length() == 0) { +        setFailState(); +        return; +    }      auto version = m_pack.versions.at(index);      QMap<QString, QString> extra_info; @@ -334,7 +341,7 @@ FlameManagedPackPage::FlameManagedPackPage(BaseInstance* inst, InstanceWindow* i  {      Q_ASSERT(inst->isManagedPack());      connect(ui->versionsComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(suggestVersion())); -    connect(ui->updateButton, &QPushButton::pressed, this, &FlameManagedPackPage::update); +    connect(ui->updateButton, &QPushButton::clicked, this, &FlameManagedPackPage::update);  }  void FlameManagedPackPage::parseManagedPack() @@ -431,6 +438,10 @@ QString FlameManagedPackPage::url() const  void FlameManagedPackPage::suggestVersion()  {      auto index = ui->versionsComboBox->currentIndex(); +    if (m_pack.versions.length() == 0) { +        setFailState(); +        return; +    }      auto version = m_pack.versions.at(index);      ui->changelogTextBrowser->setHtml(m_api.getModFileChangelog(m_inst->getManagedPackID().toInt(), version.fileId)); @@ -441,6 +452,10 @@ void FlameManagedPackPage::suggestVersion()  void FlameManagedPackPage::update()  {      auto index = ui->versionsComboBox->currentIndex(); +    if (m_pack.versions.length() == 0) { +        setFailState(); +        return; +    }      auto version = m_pack.versions.at(index);      QMap<QString, QString> extra_info; diff --git a/launcher/ui/pages/instance/ModFolderPage.cpp b/launcher/ui/pages/instance/ModFolderPage.cpp index 90e7d0d6..cef292bd 100644 --- a/launcher/ui/pages/instance/ModFolderPage.cpp +++ b/launcher/ui/pages/instance/ModFolderPage.cpp @@ -45,6 +45,7 @@  #include <QMenu>  #include <QMessageBox>  #include <QSortFilterProxyModel> +#include <algorithm>  #include "Application.h" @@ -60,6 +61,7 @@  #include "minecraft/mod/Mod.h"  #include "minecraft/mod/ModFolderModel.h" +#include "modplatform/ModIndex.h"  #include "modplatform/ResourceAPI.h"  #include "Version.h" @@ -86,12 +88,28 @@ ModFolderPage::ModFolderPage(BaseInstance* inst, std::shared_ptr<ModFolderModel>          ui->actionsToolbar->insertActionAfter(ui->actionAddItem, ui->actionUpdateItem);          connect(ui->actionUpdateItem, &QAction::triggered, this, &ModFolderPage::updateMods); -        auto check_allow_update = [this] { -            return (!m_instance || !m_instance->isRunning()) && (ui->treeView->selectionModel()->hasSelection() || !m_model->empty()); -        }; +        ui->actionVisitItemPage->setToolTip(tr("Go to mod's home page")); +        ui->actionsToolbar->addAction(ui->actionVisitItemPage); +        connect(ui->actionVisitItemPage, &QAction::triggered, this, &ModFolderPage::visitModPages); -        connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, -                [this, check_allow_update] { ui->actionUpdateItem->setEnabled(check_allow_update()); }); +        auto check_allow_update = [this] { return ui->treeView->selectionModel()->hasSelection() || !m_model->empty(); }; + +        connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, [this, check_allow_update] { +            ui->actionUpdateItem->setEnabled(check_allow_update()); + +            auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection()).indexes(); +            auto mods_list = m_model->selectedMods(selection); +            auto selected = std::count_if(mods_list.cbegin(), mods_list.cend(), +                                          [](Mod* v) { return v->metadata() != nullptr || v->homeurl().size() != 0; }); +            if (selected <= 1) { +                ui->actionVisitItemPage->setText(tr("Visit mod's page")); +                ui->actionVisitItemPage->setToolTip(tr("Go to mod's home page")); +            } else { +                ui->actionVisitItemPage->setText(tr("Visit mods' pages")); +                ui->actionVisitItemPage->setToolTip(tr("Go to the pages of the selected mods")); +            } +            ui->actionVisitItemPage->setEnabled(selected != 0); +        });          connect(mods.get(), &ModFolderModel::rowsInserted, this,                  [this, check_allow_update] { ui->actionUpdateItem->setEnabled(check_allow_update()); }); @@ -101,22 +119,9 @@ ModFolderPage::ModFolderPage(BaseInstance* inst, std::shared_ptr<ModFolderModel>          connect(mods.get(), &ModFolderModel::updateFinished, this,                  [this, check_allow_update] { ui->actionUpdateItem->setEnabled(check_allow_update()); }); - -        connect(m_instance, &BaseInstance::runningStatusChanged, this, &ModFolderPage::runningStateChanged); -        ModFolderPage::runningStateChanged(m_instance && m_instance->isRunning());      }  } -void ModFolderPage::runningStateChanged(bool running) -{ -    ui->actionDownloadItem->setEnabled(!running); -    ui->actionUpdateItem->setEnabled(!running); -    ui->actionAddItem->setEnabled(!running); -    ui->actionEnableItem->setEnabled(!running); -    ui->actionDisableItem->setEnabled(!running); -    ui->actionRemoveItem->setEnabled(!running); -} -  bool ModFolderPage::shouldDisplay() const  {      return true; @@ -133,15 +138,23 @@ bool ModFolderPage::onSelectionChanged(const QModelIndex& current, const QModelI      return true;  } -void ModFolderPage::removeItems(const QItemSelection &selection) +void ModFolderPage::removeItems(const QItemSelection& selection)  { +    if (m_instance != nullptr && m_instance->isRunning()) { +        auto response = CustomMessageBox::selectable(this, "Confirm Delete", +                                                     "If you remove mods while the game is running it may crash your game.\n" +                                                     "Are you sure you want to do this?", +                                                     QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No) +                            ->exec(); + +        if (response != QMessageBox::Yes) +            return; +    }      m_model->deleteMods(selection.indexes());  }  void ModFolderPage::installMods()  { -    if (!m_controlsEnabled) -        return;      if (m_instance->typeName() != "Minecraft")          return;  // this is a null instance or a legacy instance @@ -207,8 +220,7 @@ void ModFolderPage::updateMods()                  message = tr("All selected mods are up-to-date! :)");              }          } -        CustomMessageBox::selectable(this, tr("Update checker"), message) -            ->exec(); +        CustomMessageBox::selectable(this, tr("Update checker"), message)->exec();          return;      } @@ -275,3 +287,13 @@ bool NilModFolderPage::shouldDisplay() const  {      return m_model->dir().exists();  } + +void ModFolderPage::visitModPages() +{ +    auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection()).indexes(); +    for (auto mod : m_model->selectedMods(selection)) { +        auto url = mod->metaurl(); +        if (!url.isEmpty()) +            DesktopServices::openUrl(url); +    } +} diff --git a/launcher/ui/pages/instance/ModFolderPage.h b/launcher/ui/pages/instance/ModFolderPage.h index 2fc7b574..a23dcae1 100644 --- a/launcher/ui/pages/instance/ModFolderPage.h +++ b/launcher/ui/pages/instance/ModFolderPage.h @@ -4,6 +4,7 @@   *  Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>   *  Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>   *  Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me> + *  Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>   *   *  This program is free software: you can redistribute it and/or modify   *  it under the terms of the GNU General Public License as published by @@ -59,11 +60,11 @@ class ModFolderPage : public ExternalResourcesPage {      bool onSelectionChanged(const QModelIndex& current, const QModelIndex& previous) override;     private slots: -    void runningStateChanged(bool running); -    void removeItems(const QItemSelection &selection) override; +    void removeItems(const QItemSelection& selection) override;      void installMods();      void updateMods(); +    void visitModPages();     protected:      std::shared_ptr<ModFolderModel> m_model; diff --git a/launcher/ui/pages/instance/ResourcePackPage.cpp b/launcher/ui/pages/instance/ResourcePackPage.cpp index 24bfb38d..12b371df 100644 --- a/launcher/ui/pages/instance/ResourcePackPage.cpp +++ b/launcher/ui/pages/instance/ResourcePackPage.cpp @@ -67,8 +67,6 @@ bool ResourcePackPage::onSelectionChanged(const QModelIndex& current, const QMod  void ResourcePackPage::downloadRPs()  { -    if (!m_controlsEnabled) -        return;      if (m_instance->typeName() != "Minecraft")          return;  // this is a null instance or a legacy instance diff --git a/launcher/ui/pages/instance/ScreenshotsPage.cpp b/launcher/ui/pages/instance/ScreenshotsPage.cpp index ca368d3b..bcce5f57 100644 --- a/launcher/ui/pages/instance/ScreenshotsPage.cpp +++ b/launcher/ui/pages/instance/ScreenshotsPage.cpp @@ -36,6 +36,7 @@   */  #include "ScreenshotsPage.h" +#include "BuildConfig.h"  #include "ui_ScreenshotsPage.h"  #include <QModelIndex> @@ -96,37 +97,30 @@ public:              return;          if ((info.suffix().compare("png", Qt::CaseInsensitive) != 0))              return; -        int tries = 5; -        while (tries) -        { -            if (!m_cache->stale(m_path)) -                return; -            QImage image(m_path); -            if (image.isNull()) -            { -                QThread::msleep(500); -                tries--; -                continue; -            } -            QImage small; -            if (image.width() > image.height()) -                small = image.scaledToWidth(512).scaledToWidth(256, Qt::SmoothTransformation); -            else -                small = image.scaledToHeight(512).scaledToHeight(256, Qt::SmoothTransformation); -            QPoint offset((256 - small.width()) / 2, (256 - small.height()) / 2); -            QImage square(QSize(256, 256), QImage::Format_ARGB32); -            square.fill(Qt::transparent); - -            QPainter painter(&square); -            painter.drawImage(offset, small); -            painter.end(); - -            QIcon icon(QPixmap::fromImage(square)); -            m_cache->add(m_path, icon); -            m_resultEmitter.emitResultsReady(m_path); +        if (!m_cache->stale(m_path)) +            return; +        QImage image(m_path); +        if (image.isNull()) { +            m_resultEmitter.emitResultsFailed(m_path); +            qDebug() << "Error loading screenshot: " + m_path + ". Perhaps too large?";              return;          } -        m_resultEmitter.emitResultsFailed(m_path); +        QImage small; +        if (image.width() > image.height()) +            small = image.scaledToWidth(512).scaledToWidth(256, Qt::SmoothTransformation); +        else +            small = image.scaledToHeight(512).scaledToHeight(256, Qt::SmoothTransformation); +        QPoint offset((256 - small.width()) / 2, (256 - small.height()) / 2); +        QImage square(QSize(256, 256), QImage::Format_ARGB32); +        square.fill(Qt::transparent); + +        QPainter painter(&square); +        painter.drawImage(offset, small); +        painter.end(); + +        QIcon icon(QPixmap::fromImage(square)); +        m_cache->add(m_path, icon); +        m_resultEmitter.emitResultsReady(m_path);      }      QString m_path;      SharedIconCachePtr m_cache; @@ -145,9 +139,12 @@ public:          m_thumbnailCache = std::make_shared<SharedIconCache>();          m_thumbnailCache->add("placeholder", APPLICATION->getThemedIcon("screenshot-placeholder"));          connect(&watcher, SIGNAL(fileChanged(QString)), SLOT(fileChanged(QString))); -        // FIXME: the watched file set is not updated when files are removed      } -    virtual ~FilterModel() { m_thumbnailingPool.waitForDone(500); } +    virtual ~FilterModel() { +        m_thumbnailingPool.clear(); +        if (!m_thumbnailingPool.waitForDone(500)) +            qDebug() << "Thumbnail pool took longer than 500ms to finish"; +    }      virtual QVariant data(const QModelIndex &proxyIndex, int role = Qt::DisplayRole) const      {          auto model = sourceModel(); @@ -214,10 +211,12 @@ private slots:      void fileChanged(QString filepath)      {          m_thumbnailCache->setStale(filepath); -        thumbnailImage(filepath);          // reinsert the path...          watcher.removePath(filepath); -        watcher.addPath(filepath); +        if (QFile::exists(filepath)) { +            watcher.addPath(filepath); +            thumbnailImage(filepath); +        }      }  private: @@ -380,16 +379,18 @@ void ScreenshotsPage::on_actionUpload_triggered()      if (selection.isEmpty())          return; -      QString text; +    QUrl baseUrl(BuildConfig.IMGUR_BASE_URL);      if (selection.size() > 1) -        text = tr("You are about to upload %1 screenshots.\n\n" +        text = tr("You are about to upload %1 screenshots to %2.\n" +                  "You should double-check for personal information.\n\n"                    "Are you sure?") -                   .arg(selection.size()); +                   .arg(QString::number(selection.size()), baseUrl.host());      else -        text = -            tr("You are about to upload the selected screenshot.\n\n" -               "Are you sure?"); +        text = tr("You are about to upload the selected screenshot to %1.\n" +                  "You should double-check for personal information.\n\n" +                  "Are you sure?") +                   .arg(baseUrl.host());      auto response = CustomMessageBox::selectable(this, "Confirm Upload", text, QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No,                                                   QMessageBox::No) diff --git a/launcher/ui/pages/instance/ShaderPackPage.cpp b/launcher/ui/pages/instance/ShaderPackPage.cpp index 2d0c10aa..dc8b0a05 100644 --- a/launcher/ui/pages/instance/ShaderPackPage.cpp +++ b/launcher/ui/pages/instance/ShaderPackPage.cpp @@ -46,7 +46,6 @@  #include "ui/dialogs/ProgressDialog.h"  #include "ui/dialogs/ResourceDownloadDialog.h" -  ShaderPackPage::ShaderPackPage(MinecraftInstance* instance, std::shared_ptr<ShaderPackFolderModel> model, QWidget* parent)      : ExternalResourcesPage(instance, model, parent)  { @@ -61,8 +60,6 @@ ShaderPackPage::ShaderPackPage(MinecraftInstance* instance, std::shared_ptr<Shad  void ShaderPackPage::downloadShaders()  { -    if (!m_controlsEnabled) -        return;      if (m_instance->typeName() != "Minecraft")          return;  // this is a null instance or a legacy instance diff --git a/launcher/ui/pages/instance/TexturePackPage.cpp b/launcher/ui/pages/instance/TexturePackPage.cpp index 427aba11..e477ceda 100644 --- a/launcher/ui/pages/instance/TexturePackPage.cpp +++ b/launcher/ui/pages/instance/TexturePackPage.cpp @@ -69,8 +69,6 @@ bool TexturePackPage::onSelectionChanged(const QModelIndex& current, const QMode  void TexturePackPage::downloadTPs()  { -    if (!m_controlsEnabled) -        return;      if (m_instance->typeName() != "Minecraft")          return;  // this is a null instance or a legacy instance diff --git a/launcher/ui/pages/instance/VersionPage.cpp b/launcher/ui/pages/instance/VersionPage.cpp index 74b7ec7c..a180c804 100644 --- a/launcher/ui/pages/instance/VersionPage.cpp +++ b/launcher/ui/pages/instance/VersionPage.cpp @@ -40,14 +40,13 @@  #include "Application.h" -#include <QMessageBox> -#include <QLabel> +#include <QAbstractItemModel>  #include <QEvent>  #include <QKeyEvent> +#include <QLabel> +#include <QListView>  #include <QMenu> -#include <QAbstractItemModel>  #include <QMessageBox> -#include <QListView>  #include <QString>  #include <QUrl> @@ -55,49 +54,42 @@  #include "ui_VersionPage.h"  #include "ui/dialogs/CustomMessageBox.h" -#include "ui/dialogs/VersionSelectDialog.h"  #include "ui/dialogs/NewComponentDialog.h"  #include "ui/dialogs/ProgressDialog.h" +#include "ui/dialogs/VersionSelectDialog.h"  #include "ui/GuiUtil.h" +#include "DesktopServices.h" +#include "Exception.h" +#include "Version.h" +#include "icons/IconList.h"  #include "minecraft/PackProfile.h"  #include "minecraft/auth/AccountList.h"  #include "minecraft/mod/Mod.h" -#include "icons/IconList.h" -#include "Exception.h" -#include "Version.h" -#include "DesktopServices.h"  #include "meta/Index.h"  #include "meta/VersionList.h" -class IconProxy : public QIdentityProxyModel -{ +class IconProxy : public QIdentityProxyModel {      Q_OBJECT -public: - -    IconProxy(QWidget *parentWidget) : QIdentityProxyModel(parentWidget) +   public: +    IconProxy(QWidget* parentWidget) : QIdentityProxyModel(parentWidget)      {          connect(parentWidget, &QObject::destroyed, this, &IconProxy::widgetGone);          m_parentWidget = parentWidget;      } -    virtual QVariant data(const QModelIndex &proxyIndex, int role = Qt::DisplayRole) const override +    virtual QVariant data(const QModelIndex& proxyIndex, int role = Qt::DisplayRole) const override      {          QVariant var = QIdentityProxyModel::data(proxyIndex, role);          int column = proxyIndex.column(); -        if(column == 0 && role == Qt::DecorationRole && m_parentWidget) -        { -            if(!var.isNull()) -            { +        if (column == 0 && role == Qt::DecorationRole && m_parentWidget) { +            if (!var.isNull()) {                  auto string = var.toString(); -                if(string == "warning") -                { +                if (string == "warning") {                      return APPLICATION->getThemedIcon("status-yellow"); -                } -                else if(string == "error") -                { +                } else if (string == "error") {                      return APPLICATION->getThemedIcon("status-bad");                  }              } @@ -105,14 +97,11 @@ public:          }          return var;      } -private slots: -    void widgetGone() -    { -        m_parentWidget = nullptr; -    } +   private slots: +    void widgetGone() { m_parentWidget = nullptr; } -private: -    QWidget *m_parentWidget = nullptr; +   private: +    QWidget* m_parentWidget = nullptr;  };  QIcon VersionPage::icon() const @@ -144,15 +133,14 @@ void VersionPage::closedImpl()      m_wide_bar_setting->set(ui->toolBar->getVisibilityState());  } -QMenu * VersionPage::createPopupMenu() +QMenu* VersionPage::createPopupMenu()  {      QMenu* filteredMenu = QMainWindow::createPopupMenu(); -    filteredMenu->removeAction( ui->toolBar->toggleViewAction() ); +    filteredMenu->removeAction(ui->toolBar->toggleViewAction());      return filteredMenu;  } -VersionPage::VersionPage(MinecraftInstance *inst, QWidget *parent) -    : QMainWindow(parent), ui(new Ui::VersionPage), m_inst(inst) +VersionPage::VersionPage(MinecraftInstance* inst, QWidget* parent) : QMainWindow(parent), ui(new Ui::VersionPage), m_inst(inst)  {      ui->setupUi(this); @@ -182,10 +170,8 @@ VersionPage::VersionPage(MinecraftInstance *inst, QWidget *parent)      connect(smodel, &QItemSelectionModel::currentChanged, this, &VersionPage::packageCurrent);      connect(m_profile.get(), &PackProfile::minecraftChanged, this, &VersionPage::updateVersionControls); -    controlsEnabled = !m_inst->isRunning();      updateVersionControls();      preselect(0); -    connect(m_inst, &BaseInstance::runningStatusChanged, this, &VersionPage::updateRunningStatus);      connect(ui->packageView, &ModListView::customContextMenuRequested, this, &VersionPage::showContextMenu);      connect(ui->filterEdit, &QLineEdit::textChanged, this, &VersionPage::onFilterTextChanged);  } @@ -202,18 +188,16 @@ void VersionPage::showContextMenu(const QPoint& pos)      delete menu;  } -void VersionPage::packageCurrent(const QModelIndex ¤t, const QModelIndex &previous) +void VersionPage::packageCurrent(const QModelIndex& current, const QModelIndex& previous)  { -    if (!current.isValid()) -    { +    if (!current.isValid()) {          ui->frame->clear();          return;      }      int row = current.row();      auto patch = m_profile->getComponent(row);      auto severity = patch->getProblemSeverity(); -    switch(severity) -    { +    switch (severity) {          case ProblemSeverity::Warning:              ui->frame->setName(tr("%1 possibly has issues.").arg(patch->getName()));              break; @@ -226,16 +210,12 @@ void VersionPage::packageCurrent(const QModelIndex ¤t, const QModelIndex &              return;      } -    auto &problems = patch->getProblems(); +    auto& problems = patch->getProblems();      QString problemOut; -    for (auto &problem: problems) -    { -        if(problem.m_severity == ProblemSeverity::Error) -        { +    for (auto& problem : problems) { +        if (problem.m_severity == ProblemSeverity::Error) {              problemOut += tr("Error: "); -        } -        else if(problem.m_severity == ProblemSeverity::Warning) -        { +        } else if (problem.m_severity == ProblemSeverity::Warning) {              problemOut += tr("Warning: ");          }          problemOut += problem.m_description; @@ -244,72 +224,47 @@ void VersionPage::packageCurrent(const QModelIndex ¤t, const QModelIndex &      ui->frame->setDescription(problemOut);  } -void VersionPage::updateRunningStatus(bool running) -{ -    if(controlsEnabled == running) { -        controlsEnabled = !running; -        updateVersionControls(); -    } -} -  void VersionPage::updateVersionControls()  {      // FIXME: this is a dirty hack      auto minecraftVersion = Version(m_profile->getComponentVersion("net.minecraft")); -    ui->actionInstall_Forge->setEnabled(controlsEnabled); -      bool supportsFabric = minecraftVersion >= Version("1.14"); -    ui->actionInstall_Fabric->setEnabled(controlsEnabled && supportsFabric); +    ui->actionInstall_Fabric->setEnabled(supportsFabric);      bool supportsQuilt = minecraftVersion >= Version("1.14"); -    ui->actionInstall_Quilt->setEnabled(controlsEnabled && supportsQuilt); +    ui->actionInstall_Quilt->setEnabled(supportsQuilt);      bool supportsLiteLoader = minecraftVersion <= Version("1.12.2"); -    ui->actionInstall_LiteLoader->setEnabled(controlsEnabled && supportsLiteLoader); +    ui->actionInstall_LiteLoader->setEnabled(supportsLiteLoader);      updateButtons();  }  void VersionPage::updateButtons(int row)  { -    if(row == -1) +    if (row == -1)          row = currentRow();      auto patch = m_profile->getComponent(row); -    ui->actionRemove->setEnabled(controlsEnabled && patch && patch->isRemovable()); -    ui->actionMove_down->setEnabled(controlsEnabled && patch && patch->isMoveable()); -    ui->actionMove_up->setEnabled(controlsEnabled && patch && patch->isMoveable()); -    ui->actionChange_version->setEnabled(controlsEnabled && patch && patch->isVersionChangeable()); -    ui->actionEdit->setEnabled(controlsEnabled && patch && patch->isCustom()); -    ui->actionCustomize->setEnabled(controlsEnabled && patch && patch->isCustomizable()); -    ui->actionRevert->setEnabled(controlsEnabled && patch && patch->isRevertible()); -    ui->actionDownload_All->setEnabled(controlsEnabled); -    ui->actionAdd_Empty->setEnabled(controlsEnabled); -    ui->actionImport_Components->setEnabled(controlsEnabled); -    ui->actionReload->setEnabled(controlsEnabled); -    ui->actionInstall_mods->setEnabled(controlsEnabled); -    ui->actionReplace_Minecraft_jar->setEnabled(controlsEnabled); -    ui->actionAdd_to_Minecraft_jar->setEnabled(controlsEnabled); -    ui->actionAdd_Agents->setEnabled(controlsEnabled); +    ui->actionRemove->setEnabled(patch && patch->isRemovable()); +    ui->actionMove_down->setEnabled(patch && patch->isMoveable()); +    ui->actionMove_up->setEnabled(patch && patch->isMoveable()); +    ui->actionChange_version->setEnabled(patch && patch->isVersionChangeable()); +    ui->actionEdit->setEnabled(patch && patch->isCustom()); +    ui->actionCustomize->setEnabled(patch && patch->isCustomizable()); +    ui->actionRevert->setEnabled(patch && patch->isRevertible());  }  bool VersionPage::reloadPackProfile()  { -    try -    { +    try {          m_profile->reload(Net::Mode::Online);          return true; -    } -    catch (const Exception &e) -    { +    } catch (const Exception& e) {          QMessageBox::critical(this, tr("Error"), e.cause());          return false; -    } -    catch (...) -    { -        QMessageBox::critical( -            this, tr("Error"), -            tr("Couldn't load the instance profile.")); +    } catch (...) { +        QMessageBox::critical(this, tr("Error"), tr("Couldn't load the instance profile."));          return false;      }  } @@ -322,14 +277,12 @@ void VersionPage::on_actionReload_triggered()  void VersionPage::on_actionRemove_triggered()  { -    if (!ui->packageView->currentIndex().isValid()) -    { +    if (!ui->packageView->currentIndex().isValid()) {          return;      }      int index = ui->packageView->currentIndex().row();      auto component = m_profile->getComponent(index); -    if (component->isCustom()) -    { +    if (component->isCustom()) {          auto response = CustomMessageBox::selectable(this, tr("Confirm Removal"),                                                       tr("You are about to remove \"%1\".\n"                                                          "This is permanent and will completely remove the custom component.\n\n" @@ -342,8 +295,7 @@ void VersionPage::on_actionRemove_triggered()              return;      }      // FIXME: use actual model, not reloading. -    if (!m_profile->remove(index)) -    { +    if (!m_profile->remove(index)) {          QMessageBox::critical(this, tr("Error"), tr("Couldn't remove file"));      }      updateButtons(); @@ -353,17 +305,16 @@ void VersionPage::on_actionRemove_triggered()  void VersionPage::on_actionInstall_mods_triggered()  { -    if(m_container) -    { +    if (m_container) {          m_container->selectPage("mods");      }  }  void VersionPage::on_actionAdd_to_Minecraft_jar_triggered()  { -    auto list = GuiUtil::BrowseForFiles("jarmod", tr("Select jar mods"), tr("Minecraft.jar mods (*.zip *.jar)"), APPLICATION->settings()->get("CentralModsDir").toString(), this->parentWidget()); -    if(!list.empty()) -    { +    auto list = GuiUtil::BrowseForFiles("jarmod", tr("Select jar mods"), tr("Minecraft.jar mods (*.zip *.jar)"), +                                        APPLICATION->settings()->get("CentralModsDir").toString(), this->parentWidget()); +    if (!list.empty()) {          m_profile->installJarMods(list);      }      updateButtons(); @@ -371,9 +322,9 @@ void VersionPage::on_actionAdd_to_Minecraft_jar_triggered()  void VersionPage::on_actionReplace_Minecraft_jar_triggered()  { -    auto jarPath = GuiUtil::BrowseForFile("jar", tr("Select jar"), tr("Minecraft.jar replacement (*.jar)"), APPLICATION->settings()->get("CentralModsDir").toString(), this->parentWidget()); -    if(!jarPath.isEmpty()) -    { +    auto jarPath = GuiUtil::BrowseForFile("jar", tr("Select jar"), tr("Minecraft.jar replacement (*.jar)"), +                                          APPLICATION->settings()->get("CentralModsDir").toString(), this->parentWidget()); +    if (!jarPath.isEmpty()) {          m_profile->installCustomJar(jarPath);      }      updateButtons(); @@ -407,12 +358,9 @@ void VersionPage::on_actionAdd_Agents_triggered()  void VersionPage::on_actionMove_up_triggered()  { -    try -    { +    try {          m_profile->move(currentRow(), PackProfile::MoveUp); -    } -    catch (const Exception &e) -    { +    } catch (const Exception& e) {          QMessageBox::critical(this, tr("Error"), e.cause());      }      updateButtons(); @@ -420,12 +368,9 @@ void VersionPage::on_actionMove_up_triggered()  void VersionPage::on_actionMove_down_triggered()  { -    try -    { +    try {          m_profile->move(currentRow(), PackProfile::MoveDown); -    } -    catch (const Exception &e) -    { +    } catch (const Exception& e) {          QMessageBox::critical(this, tr("Error"), e.cause());      }      updateButtons(); @@ -434,39 +379,32 @@ void VersionPage::on_actionMove_down_triggered()  void VersionPage::on_actionChange_version_triggered()  {      auto versionRow = currentRow(); -    if(versionRow == -1) -    { +    if (versionRow == -1) {          return;      }      auto patch = m_profile->getComponent(versionRow);      auto name = patch->getName();      auto list = patch->getVersionList(); -    if(!list) -    { +    if (!list) {          return;      }      auto uid = list->uid();      // FIXME: this is a horrible HACK. Get version filtering information from the actual metadata... -    if(uid == "net.minecraftforge") -    { +    if (uid == "net.minecraftforge") {          on_actionInstall_Forge_triggered();          return; -    } -    else if (uid == "com.mumfrey.liteloader") -    { +    } else if (uid == "com.mumfrey.liteloader") {          on_actionInstall_LiteLoader_triggered();          return;      }      VersionSelectDialog vselect(list.get(), tr("Change %1 version").arg(name), this); -    if (uid == "net.fabricmc.intermediary" || uid == "org.quiltmc.hashed") -    { +    if (uid == "net.fabricmc.intermediary" || uid == "org.quiltmc.hashed") {          vselect.setEmptyString(tr("No intermediary mappings versions are currently available."));          vselect.setEmptyErrorString(tr("Couldn't load or download the intermediary mappings version lists!"));          vselect.setExactFilter(BaseVersionList::ParentVersionRole, m_profile->getComponentVersion("net.minecraft"));      }      auto currentVersion = patch->getVersion(); -    if(!currentVersion.isEmpty()) -    { +    if (!currentVersion.isEmpty()) {          vselect.setCurrentVersion(currentVersion);      }      if (!vselect.exec() || !vselect.selectedVersion()) @@ -474,8 +412,7 @@ void VersionPage::on_actionChange_version_triggered()      qDebug() << "Change" << uid << "to" << vselect.selectedVersion()->descriptor();      bool important = false; -    if(uid == "net.minecraft") -    { +    if (uid == "net.minecraft") {          important = true;      }      m_profile->setComponentVersion(uid, vselect.selectedVersion()->descriptor(), important); @@ -485,19 +422,17 @@ void VersionPage::on_actionChange_version_triggered()  void VersionPage::on_actionDownload_All_triggered()  { -    if (!APPLICATION->accounts()->anyAccountIsValid()) -    { -        CustomMessageBox::selectable( -            this, tr("Error"), -            tr("Cannot download Minecraft or update instances unless you have at least " -               "one account added.\nPlease add your Mojang or Minecraft account."), -            QMessageBox::Warning)->show(); +    if (!APPLICATION->accounts()->anyAccountIsValid()) { +        CustomMessageBox::selectable(this, tr("Error"), +                                     tr("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;      }      auto updateTask = m_inst->createUpdateTask(Net::Mode::Online); -    if (!updateTask) -    { +    if (!updateTask) {          return;      }      ProgressDialog tDialog(this); @@ -511,28 +446,26 @@ void VersionPage::on_actionDownload_All_triggered()  void VersionPage::on_actionInstall_Forge_triggered()  {      auto vlist = APPLICATION->metadataIndex()->get("net.minecraftforge"); -    if(!vlist) -    { +    if (!vlist) {          return;      }      VersionSelectDialog vselect(vlist.get(), tr("Select Forge version"), this);      vselect.setExactFilter(BaseVersionList::ParentVersionRole, m_profile->getComponentVersion("net.minecraft")); -    vselect.setEmptyString(tr("No Forge versions are currently available for Minecraft ") + m_profile->getComponentVersion("net.minecraft")); +    vselect.setEmptyString(tr("No Forge versions are currently available for Minecraft ") + +                           m_profile->getComponentVersion("net.minecraft"));      vselect.setEmptyErrorString(tr("Couldn't load or download the Forge version lists!"));      auto currentVersion = m_profile->getComponentVersion("net.minecraftforge"); -    if(!currentVersion.isEmpty()) -    { +    if (!currentVersion.isEmpty()) {          vselect.setCurrentVersion(currentVersion);      } -    if (vselect.exec() && vselect.selectedVersion()) -    { +    if (vselect.exec() && vselect.selectedVersion()) {          auto vsn = vselect.selectedVersion();          m_profile->setComponentVersion("net.minecraftforge", vsn->descriptor());          m_profile->resolve(Net::Mode::Online);          // m_profile->installVersion(); -        preselect(m_profile->rowCount(QModelIndex())-1); +        preselect(m_profile->rowCount(QModelIndex()) - 1);          m_container->refreshContainer();      }  } @@ -540,8 +473,7 @@ void VersionPage::on_actionInstall_Forge_triggered()  void VersionPage::on_actionInstall_Fabric_triggered()  {      auto vlist = APPLICATION->metadataIndex()->get("net.fabricmc.fabric-loader"); -    if(!vlist) -    { +    if (!vlist) {          return;      }      VersionSelectDialog vselect(vlist.get(), tr("Select Fabric Loader version"), this); @@ -549,17 +481,15 @@ void VersionPage::on_actionInstall_Fabric_triggered()      vselect.setEmptyErrorString(tr("Couldn't load or download the Fabric Loader version lists!"));      auto currentVersion = m_profile->getComponentVersion("net.fabricmc.fabric-loader"); -    if(!currentVersion.isEmpty()) -    { +    if (!currentVersion.isEmpty()) {          vselect.setCurrentVersion(currentVersion);      } -    if (vselect.exec() && vselect.selectedVersion()) -    { +    if (vselect.exec() && vselect.selectedVersion()) {          auto vsn = vselect.selectedVersion();          m_profile->setComponentVersion("net.fabricmc.fabric-loader", vsn->descriptor());          m_profile->resolve(Net::Mode::Online); -        preselect(m_profile->rowCount(QModelIndex())-1); +        preselect(m_profile->rowCount(QModelIndex()) - 1);          m_container->refreshContainer();      }  } @@ -567,8 +497,7 @@ void VersionPage::on_actionInstall_Fabric_triggered()  void VersionPage::on_actionInstall_Quilt_triggered()  {      auto vlist = APPLICATION->metadataIndex()->get("org.quiltmc.quilt-loader"); -    if(!vlist) -    { +    if (!vlist) {          return;      }      VersionSelectDialog vselect(vlist.get(), tr("Select Quilt Loader version"), this); @@ -576,17 +505,15 @@ void VersionPage::on_actionInstall_Quilt_triggered()      vselect.setEmptyErrorString(tr("Couldn't load or download the Quilt Loader version lists!"));      auto currentVersion = m_profile->getComponentVersion("org.quiltmc.quilt-loader"); -    if(!currentVersion.isEmpty()) -    { +    if (!currentVersion.isEmpty()) {          vselect.setCurrentVersion(currentVersion);      } -    if (vselect.exec() && vselect.selectedVersion()) -    { +    if (vselect.exec() && vselect.selectedVersion()) {          auto vsn = vselect.selectedVersion();          m_profile->setComponentVersion("org.quiltmc.quilt-loader", vsn->descriptor());          m_profile->resolve(Net::Mode::Online); -        preselect(m_profile->rowCount(QModelIndex())-1); +        preselect(m_profile->rowCount(QModelIndex()) - 1);          m_container->refreshContainer();      }  } @@ -595,14 +522,12 @@ void VersionPage::on_actionAdd_Empty_triggered()  {      NewComponentDialog compdialog(QString(), QString(), this);      QStringList blacklist; -    for(int i = 0; i < m_profile->rowCount(); i++) -    { +    for (int i = 0; i < m_profile->rowCount(); i++) {          auto comp = m_profile->getComponent(i);          blacklist.push_back(comp->getID());      }      compdialog.setBlacklist(blacklist); -    if (compdialog.exec()) -    { +    if (compdialog.exec()) {          qDebug() << "name:" << compdialog.name();          qDebug() << "uid:" << compdialog.uid();          m_profile->installEmpty(compdialog.uid(), compdialog.name()); @@ -612,28 +537,26 @@ void VersionPage::on_actionAdd_Empty_triggered()  void VersionPage::on_actionInstall_LiteLoader_triggered()  {      auto vlist = APPLICATION->metadataIndex()->get("com.mumfrey.liteloader"); -    if(!vlist) -    { +    if (!vlist) {          return;      }      VersionSelectDialog vselect(vlist.get(), tr("Select LiteLoader version"), this);      vselect.setExactFilter(BaseVersionList::ParentVersionRole, m_profile->getComponentVersion("net.minecraft")); -    vselect.setEmptyString(tr("No LiteLoader versions are currently available for Minecraft ") + m_profile->getComponentVersion("net.minecraft")); +    vselect.setEmptyString(tr("No LiteLoader versions are currently available for Minecraft ") + +                           m_profile->getComponentVersion("net.minecraft"));      vselect.setEmptyErrorString(tr("Couldn't load or download the LiteLoader version lists!"));      auto currentVersion = m_profile->getComponentVersion("com.mumfrey.liteloader"); -    if(!currentVersion.isEmpty()) -    { +    if (!currentVersion.isEmpty()) {          vselect.setCurrentVersion(currentVersion);      } -    if (vselect.exec() && vselect.selectedVersion()) -    { +    if (vselect.exec() && vselect.selectedVersion()) {          auto vsn = vselect.selectedVersion();          m_profile->setComponentVersion("com.mumfrey.liteloader", vsn->descriptor());          m_profile->resolve(Net::Mode::Online);          // m_profile->installVersion(vselect.selectedVersion()); -        preselect(m_profile->rowCount(QModelIndex())-1); +        preselect(m_profile->rowCount(QModelIndex()) - 1);          m_container->refreshContainer();      }  } @@ -648,7 +571,7 @@ void VersionPage::on_actionMinecraftFolder_triggered()      DesktopServices::openDirectory(m_inst->gameRoot(), true);  } -void VersionPage::versionCurrent(const QModelIndex ¤t, const QModelIndex &previous) +void VersionPage::versionCurrent(const QModelIndex& current, const QModelIndex& previous)  {      currentIdx = current.row();      updateButtons(currentIdx); @@ -656,16 +579,13 @@ void VersionPage::versionCurrent(const QModelIndex ¤t, const QModelIndex &  void VersionPage::preselect(int row)  { -    if(row < 0) -    { +    if (row < 0) {          row = 0;      } -    if(row >= m_profile->rowCount(QModelIndex())) -    { +    if (row >= m_profile->rowCount(QModelIndex())) {          row = m_profile->rowCount(QModelIndex()) - 1;      } -    if(row < 0) -    { +    if (row < 0) {          return;      }      auto model_index = m_profile->index(row); @@ -681,8 +601,7 @@ void VersionPage::onGameUpdateError(QString error)  ComponentPtr VersionPage::current()  {      auto row = currentRow(); -    if(row < 0) -    { +    if (row < 0) {          return nullptr;      }      return m_profile->getComponent(row); @@ -690,8 +609,7 @@ ComponentPtr VersionPage::current()  int VersionPage::currentRow()  { -    if (ui->packageView->selectionModel()->selectedRows().isEmpty()) -    { +    if (ui->packageView->selectionModel()->selectedRows().isEmpty()) {          return -1;      }      return ui->packageView->selectionModel()->selectedRows().first().row(); @@ -700,18 +618,15 @@ int VersionPage::currentRow()  void VersionPage::on_actionCustomize_triggered()  {      auto version = currentRow(); -    if(version == -1) -    { +    if (version == -1) {          return;      }      auto patch = m_profile->getComponent(version); -    if(!patch->getVersionFile()) -    { +    if (!patch->getVersionFile()) {          // TODO: wait for the update task to finish here...          return;      } -    if(!m_profile->customize(version)) -    { +    if (!m_profile->customize(version)) {          // TODO: some error box here      }      updateButtons(); @@ -721,13 +636,11 @@ void VersionPage::on_actionCustomize_triggered()  void VersionPage::on_actionEdit_triggered()  {      auto version = current(); -    if(!version) -    { +    if (!version) {          return;      }      auto filename = version->getFilename(); -    if(!QFileInfo::exists(filename)) -    { +    if (!QFileInfo::exists(filename)) {          qWarning() << "file" << filename << "can't be opened for editing, doesn't exist!";          return;      } @@ -737,8 +650,7 @@ void VersionPage::on_actionEdit_triggered()  void VersionPage::on_actionRevert_triggered()  {      auto version = currentRow(); -    if(version == -1) -    { +    if (version == -1) {          return;      }      auto component = m_profile->getComponent(version); @@ -754,8 +666,7 @@ void VersionPage::on_actionRevert_triggered()      if (response != QMessageBox::Yes)          return; -    if(!m_profile->revertToBase(version)) -    { +    if (!m_profile->revertToBase(version)) {          // TODO: some error box here      }      updateButtons(); @@ -763,7 +674,7 @@ void VersionPage::on_actionRevert_triggered()      m_container->refreshContainer();  } -void VersionPage::onFilterTextChanged(const QString &newContents) +void VersionPage::onFilterTextChanged(const QString& newContents)  {      m_filterModel->setFilterFixedString(newContents);  } diff --git a/launcher/ui/pages/instance/VersionPage.h b/launcher/ui/pages/instance/VersionPage.h index d0087714..45d383f4 100644 --- a/launcher/ui/pages/instance/VersionPage.h +++ b/launcher/ui/pages/instance/VersionPage.h @@ -46,38 +46,27 @@  #include "minecraft/PackProfile.h"  #include "ui/pages/BasePage.h" -namespace Ui -{ +namespace Ui {  class VersionPage;  } -class VersionPage : public QMainWindow, public BasePage -{ +class VersionPage : public QMainWindow, public BasePage {      Q_OBJECT -public: -    explicit VersionPage(MinecraftInstance *inst, QWidget *parent = 0); +   public: +    explicit VersionPage(MinecraftInstance* inst, QWidget* parent = 0);      virtual ~VersionPage(); -    virtual QString displayName() const override -    { -        return tr("Version"); -    } +    virtual QString displayName() const override { return tr("Version"); }      virtual QIcon icon() const override; -    virtual QString id() const override -    { -        return "version"; -    } -    virtual QString helpPage() const override -    { -        return "Instance-Version"; -    } +    virtual QString id() const override { return "version"; } +    virtual QString helpPage() const override { return "Instance-Version"; }      virtual bool shouldDisplay() const override;      void retranslate() override;      void openedImpl() override;      void closedImpl() override; -private slots: +   private slots:      void on_actionChange_version_triggered();      void on_actionInstall_Forge_triggered();      void on_actionInstall_Fabric_triggered(); @@ -103,36 +92,34 @@ private slots:      void updateVersionControls(); -private: +   private:      ComponentPtr current();      int currentRow();      void updateButtons(int row = -1);      void preselect(int row = 0);      int doUpdate(); -protected: -    QMenu * createPopupMenu() override; +   protected: +    QMenu* createPopupMenu() override;      /// FIXME: this shouldn't be necessary!      bool reloadPackProfile(); -private: -    Ui::VersionPage *ui; -    QSortFilterProxyModel *m_filterModel; +   private: +    Ui::VersionPage* ui; +    QSortFilterProxyModel* m_filterModel;      std::shared_ptr<PackProfile> m_profile; -    MinecraftInstance *m_inst; +    MinecraftInstance* m_inst;      int currentIdx = 0; -    bool controlsEnabled = false;      std::shared_ptr<Setting> m_wide_bar_setting = nullptr; -public slots: -    void versionCurrent(const QModelIndex ¤t, const QModelIndex &previous); +   public slots: +    void versionCurrent(const QModelIndex& current, const QModelIndex& previous); -private slots: -    void updateRunningStatus(bool running); +   private slots:      void onGameUpdateError(QString error); -    void packageCurrent(const QModelIndex ¤t, const QModelIndex &previous); -    void showContextMenu(const QPoint &pos); -    void onFilterTextChanged(const QString & newContents); +    void packageCurrent(const QModelIndex& current, const QModelIndex& previous); +    void showContextMenu(const QPoint& pos); +    void onFilterTextChanged(const QString& newContents);  }; diff --git a/launcher/ui/pages/instance/VersionPage.ui b/launcher/ui/pages/instance/VersionPage.ui index 4777eafe..a73c42d6 100644 --- a/launcher/ui/pages/instance/VersionPage.ui +++ b/launcher/ui/pages/instance/VersionPage.ui @@ -102,7 +102,6 @@     <addaction name="actionInstall_Fabric"/>     <addaction name="actionInstall_Quilt"/>     <addaction name="actionInstall_LiteLoader"/> -   <addaction name="actionInstall_mods"/>     <addaction name="separator"/>     <addaction name="actionAdd_to_Minecraft_jar"/>     <addaction name="actionReplace_Minecraft_jar"/> @@ -112,7 +111,6 @@     <addaction name="separator"/>     <addaction name="actionMinecraftFolder"/>     <addaction name="actionLibrariesFolder"/> -   <addaction name="separator"/>     <addaction name="actionReload"/>     <addaction name="actionDownload_All"/>    </widget> @@ -204,14 +202,6 @@      <string>Install the LiteLoader package.</string>     </property>    </action> -  <action name="actionInstall_mods"> -   <property name="text"> -    <string>Install mods</string> -   </property> -   <property name="toolTip"> -    <string>Install normal mods.</string> -   </property> -  </action>    <action name="actionAdd_to_Minecraft_jar">     <property name="text">      <string>Add to Minecraft.jar</string> diff --git a/launcher/ui/pages/instance/WorldListPage.cpp b/launcher/ui/pages/instance/WorldListPage.cpp index b6ad159e..b2200b1a 100644 --- a/launcher/ui/pages/instance/WorldListPage.cpp +++ b/launcher/ui/pages/instance/WorldListPage.cpp @@ -339,6 +339,7 @@ void WorldListPage::mceditState(LoggedProcess::State state)          {              failed = true;          } +        /* fallthrough */          case LoggedProcess::Running:          case LoggedProcess::Finished:          { | 
