diff options
Diffstat (limited to 'launcher/ui/pages')
26 files changed, 1072 insertions, 92 deletions
diff --git a/launcher/ui/pages/BasePageContainer.h b/launcher/ui/pages/BasePageContainer.h index f8c7adeb..b41fe12a 100644 --- a/launcher/ui/pages/BasePageContainer.h +++ b/launcher/ui/pages/BasePageContainer.h @@ -1,10 +1,13 @@ #pragma once +class BasePage; + class BasePageContainer { public: virtual ~BasePageContainer(){}; virtual bool selectPage(QString pageId) = 0; + virtual BasePage* getPage(QString pageId) { return nullptr; }; virtual void refreshContainer() = 0; virtual bool requestClose() = 0; }; diff --git a/launcher/ui/pages/global/JavaPage.cpp b/launcher/ui/pages/global/JavaPage.cpp index 2cee15bf..81dd4cc1 100644 --- a/launcher/ui/pages/global/JavaPage.cpp +++ b/launcher/ui/pages/global/JavaPage.cpp @@ -58,9 +58,8 @@ JavaPage::JavaPage(QWidget *parent) : QWidget(parent), ui(new Ui::JavaPage) ui->setupUi(this); ui->tabWidget->tabBar()->hide(); - auto sysMiB = Sys::getSystemRam() / Sys::mebibyte; - ui->maxMemSpinBox->setMaximum(sysMiB); loadSettings(); + updateThresholds(); } JavaPage::~JavaPage() @@ -177,6 +176,11 @@ void JavaPage::on_javaTestBtn_clicked() checker->run(); } +void JavaPage::on_maxMemSpinBox_valueChanged(int i) +{ + updateThresholds(); +} + void JavaPage::checkerFinished() { checker.reset(); @@ -186,3 +190,29 @@ void JavaPage::retranslate() { ui->retranslateUi(this); } + +void JavaPage::updateThresholds() +{ + auto sysMiB = Sys::getSystemRam() / Sys::mebibyte; + unsigned int maxMem = ui->maxMemSpinBox->value(); + + QString iconName; + + if (maxMem >= sysMiB) { + iconName = "status-bad"; + ui->labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation exceeds your system memory capacity.")); + } else if (maxMem > (sysMiB * 0.9)) { + iconName = "status-yellow"; + ui->labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation approaches your system memory capacity.")); + } else { + iconName = "status-good"; + ui->labelMaxMemIcon->setToolTip(""); + } + + { + auto height = ui->labelMaxMemIcon->fontInfo().pixelSize(); + QIcon icon = APPLICATION->getThemedIcon(iconName); + QPixmap pix = icon.pixmap(height, height); + ui->labelMaxMemIcon->setPixmap(pix); + } +} diff --git a/launcher/ui/pages/global/JavaPage.h b/launcher/ui/pages/global/JavaPage.h index 64d4098e..2ef6d749 100644 --- a/launcher/ui/pages/global/JavaPage.h +++ b/launcher/ui/pages/global/JavaPage.h @@ -76,6 +76,8 @@ public: bool apply() override; void retranslate() override; + void updateThresholds(); + private: void applySettings(); void loadSettings(); @@ -85,6 +87,7 @@ slots: void on_javaDetectBtn_clicked(); void on_javaTestBtn_clicked(); void on_javaBrowseBtn_clicked(); + void on_maxMemSpinBox_valueChanged(int i); void checkerFinished(); private: diff --git a/launcher/ui/pages/global/JavaPage.ui b/launcher/ui/pages/global/JavaPage.ui index 6ccffed4..6749cbe4 100644 --- a/launcher/ui/pages/global/JavaPage.ui +++ b/launcher/ui/pages/global/JavaPage.ui @@ -44,50 +44,38 @@ <property name="title"> <string>Memory</string> </property> - <layout class="QGridLayout" name="gridLayout_2"> - <item row="1" column="1"> - <widget class="QSpinBox" name="maxMemSpinBox"> - <property name="toolTip"> - <string>The maximum amount of memory Minecraft is allowed to use.</string> - </property> - <property name="suffix"> - <string notr="true"> MiB</string> - </property> - <property name="minimum"> - <number>128</number> - </property> - <property name="maximum"> - <number>65536</number> - </property> - <property name="singleStep"> - <number>128</number> + <layout class="QGridLayout" name="gridLayout_2" columnstretch="1,0,0,0"> + <item row="1" column="0"> + <widget class="QLabel" name="labelMaxMem"> + <property name="text"> + <string>Ma&ximum memory allocation:</string> </property> - <property name="value"> - <number>1024</number> + <property name="buddy"> + <cstring>maxMemSpinBox</cstring> </property> </widget> </item> - <item row="0" column="0"> - <widget class="QLabel" name="labelMinMem"> + <item row="2" column="0"> + <widget class="QLabel" name="labelPermGen"> <property name="text"> - <string>&Minimum memory allocation:</string> + <string notr="true">&PermGen:</string> </property> <property name="buddy"> - <cstring>minMemSpinBox</cstring> + <cstring>permGenSpinBox</cstring> </property> </widget> </item> - <item row="1" column="0"> - <widget class="QLabel" name="labelMaxMem"> + <item row="0" column="0"> + <widget class="QLabel" name="labelMinMem"> <property name="text"> - <string>Ma&ximum memory allocation:</string> + <string>&Minimum memory allocation:</string> </property> <property name="buddy"> - <cstring>maxMemSpinBox</cstring> + <cstring>minMemSpinBox</cstring> </property> </widget> </item> - <item row="0" column="1"> + <item row="0" column="2"> <widget class="QSpinBox" name="minMemSpinBox"> <property name="toolTip"> <string>The amount of memory Minecraft is started with.</string> @@ -99,7 +87,7 @@ <number>128</number> </property> <property name="maximum"> - <number>65536</number> + <number>1048576</number> </property> <property name="singleStep"> <number>128</number> @@ -109,17 +97,29 @@ </property> </widget> </item> - <item row="2" column="0"> - <widget class="QLabel" name="labelPermGen"> - <property name="text"> - <string notr="true">&PermGen:</string> + <item row="1" column="2"> + <widget class="QSpinBox" name="maxMemSpinBox"> + <property name="toolTip"> + <string>The maximum amount of memory Minecraft is allowed to use.</string> </property> - <property name="buddy"> - <cstring>permGenSpinBox</cstring> + <property name="suffix"> + <string notr="true"> MiB</string> + </property> + <property name="minimum"> + <number>128</number> + </property> + <property name="maximum"> + <number>1048576</number> + </property> + <property name="singleStep"> + <number>128</number> + </property> + <property name="value"> + <number>1024</number> </property> </widget> </item> - <item row="2" column="1"> + <item row="2" column="2"> <widget class="QSpinBox" name="permGenSpinBox"> <property name="toolTip"> <string>The amount of memory available to store loaded Java classes.</string> @@ -141,6 +141,16 @@ </property> </widget> </item> + <item row="1" column="3"> + <widget class="QLabel" name="labelMaxMemIcon"> + <property name="text"> + <string/> + </property> + <property name="buddy"> + <cstring>maxMemSpinBox</cstring> + </property> + </widget> + </item> </layout> </widget> </item> diff --git a/launcher/ui/pages/instance/ExternalResourcesPage.cpp b/launcher/ui/pages/instance/ExternalResourcesPage.cpp index b6c873cc..c66d1368 100644 --- a/launcher/ui/pages/instance/ExternalResourcesPage.cpp +++ b/launcher/ui/pages/instance/ExternalResourcesPage.cpp @@ -14,8 +14,6 @@ ExternalResourcesPage::ExternalResourcesPage(BaseInstance* instance, std::shared { ui->setupUi(this); - ExternalResourcesPage::runningStateChanged(m_instance && m_instance->isRunning()); - ui->actionsToolbar->insertSpacer(ui->actionViewConfigs); m_filterModel = model->createFilterProxyModel(this); @@ -45,7 +43,6 @@ ExternalResourcesPage::ExternalResourcesPage(BaseInstance* instance, std::shared auto selection_model = ui->treeView->selectionModel(); connect(selection_model, &QItemSelectionModel::currentChanged, this, &ExternalResourcesPage::current); connect(ui->filterEdit, &QLineEdit::textChanged, this, &ExternalResourcesPage::filterTextChanged); - connect(m_instance, &BaseInstance::runningStatusChanged, this, &ExternalResourcesPage::runningStateChanged); } ExternalResourcesPage::~ExternalResourcesPage() @@ -70,11 +67,21 @@ void ExternalResourcesPage::ShowContextMenu(const QPoint& pos) void ExternalResourcesPage::openedImpl() { m_model->startWatching(); + + auto const setting_name = QString("WideBarVisibility_%1").arg(id()); + if (!APPLICATION->settings()->contains(setting_name)) + m_wide_bar_setting = APPLICATION->settings()->registerSetting(setting_name); + else + m_wide_bar_setting = APPLICATION->settings()->getSetting(setting_name); + + ui->actionsToolbar->setVisibilityState(m_wide_bar_setting->get().toByteArray()); } void ExternalResourcesPage::closedImpl() { m_model->stopWatching(); + + m_wide_bar_setting->set(ui->actionsToolbar->getVisibilityState()); } void ExternalResourcesPage::retranslate() @@ -97,14 +104,6 @@ void ExternalResourcesPage::filterTextChanged(const QString& newContents) m_filterModel->setFilterRegularExpression(m_viewFilter); } -void ExternalResourcesPage::runningStateChanged(bool running) -{ - if (m_controlsEnabled == !running) - return; - - m_controlsEnabled = !running; -} - bool ExternalResourcesPage::shouldDisplay() const { return true; diff --git a/launcher/ui/pages/instance/ExternalResourcesPage.h b/launcher/ui/pages/instance/ExternalResourcesPage.h index 8e352cef..2d1a5b51 100644 --- a/launcher/ui/pages/instance/ExternalResourcesPage.h +++ b/launcher/ui/pages/instance/ExternalResourcesPage.h @@ -4,6 +4,7 @@ #include <QSortFilterProxyModel> #include "Application.h" +#include "settings/Setting.h" #include "minecraft/MinecraftInstance.h" #include "ui/pages/BasePage.h" @@ -47,7 +48,6 @@ class ExternalResourcesPage : public QMainWindow, public BasePage { protected slots: void itemActivated(const QModelIndex& index); void filterTextChanged(const QString& newContents); - virtual void runningStateChanged(bool running); virtual void addItem(); virtual void removeItem(); @@ -71,4 +71,6 @@ class ExternalResourcesPage : public QMainWindow, public BasePage { QString m_viewFilter; bool m_controlsEnabled = true; + + std::shared_ptr<Setting> m_wide_bar_setting = nullptr; }; diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.cpp b/launcher/ui/pages/instance/InstanceSettingsPage.cpp index 5da7f19f..af2ba7c8 100644 --- a/launcher/ui/pages/instance/InstanceSettingsPage.cpp +++ b/launcher/ui/pages/instance/InstanceSettingsPage.cpp @@ -59,12 +59,12 @@ InstanceSettingsPage::InstanceSettingsPage(BaseInstance *inst, QWidget *parent) { m_settings = inst->settings(); ui->setupUi(this); - auto sysMB = Sys::getSystemRam() / Sys::mebibyte; - ui->maxMemSpinBox->setMaximum(sysMB); + connect(ui->openGlobalJavaSettingsButton, &QCommandLinkButton::clicked, this, &InstanceSettingsPage::globalSettingsButtonClicked); connect(APPLICATION, &Application::globalSettingsAboutToOpen, this, &InstanceSettingsPage::applySettings); connect(APPLICATION, &Application::globalSettingsClosed, this, &InstanceSettingsPage::loadSettings); loadSettings(); + updateThresholds(); } bool InstanceSettingsPage::shouldDisplay() const @@ -437,6 +437,11 @@ void InstanceSettingsPage::on_javaTestBtn_clicked() checker->run(); } +void InstanceSettingsPage::on_maxMemSpinBox_valueChanged(int i) +{ + updateThresholds(); +} + void InstanceSettingsPage::checkerFinished() { checker.reset(); @@ -447,3 +452,29 @@ void InstanceSettingsPage::retranslate() ui->retranslateUi(this); ui->customCommands->retranslate(); // TODO: why is this seperate from the others? } + +void InstanceSettingsPage::updateThresholds() +{ + auto sysMiB = Sys::getSystemRam() / Sys::mebibyte; + unsigned int maxMem = ui->maxMemSpinBox->value(); + + QString iconName; + + if (maxMem >= sysMiB) { + iconName = "status-bad"; + ui->labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation exceeds your system memory capacity.")); + } else if (maxMem > (sysMiB * 0.9)) { + iconName = "status-yellow"; + ui->labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation approaches your system memory capacity.")); + } else { + iconName = "status-good"; + ui->labelMaxMemIcon->setToolTip(""); + } + + { + auto height = ui->labelMaxMemIcon->fontInfo().pixelSize(); + QIcon icon = APPLICATION->getThemedIcon(iconName); + QPixmap pix = icon.pixmap(height, height); + ui->labelMaxMemIcon->setPixmap(pix); + } +} diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.h b/launcher/ui/pages/instance/InstanceSettingsPage.h index 97d1296f..7450188d 100644 --- a/launcher/ui/pages/instance/InstanceSettingsPage.h +++ b/launcher/ui/pages/instance/InstanceSettingsPage.h @@ -77,10 +77,13 @@ public: virtual bool shouldDisplay() const override; void retranslate() override; + void updateThresholds(); + private slots: void on_javaDetectBtn_clicked(); void on_javaTestBtn_clicked(); void on_javaBrowseBtn_clicked(); + void on_maxMemSpinBox_valueChanged(int i); void applySettings(); void loadSettings(); diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.ui b/launcher/ui/pages/instance/InstanceSettingsPage.ui index 8b3c3370..b064367d 100644 --- a/launcher/ui/pages/instance/InstanceSettingsPage.ui +++ b/launcher/ui/pages/instance/InstanceSettingsPage.ui @@ -112,7 +112,14 @@ <property name="checked"> <bool>false</bool> </property> - <layout class="QGridLayout" name="gridLayout_2"> + <layout class="QGridLayout" name="gridLayout_2" columnstretch="1,0,0,0"> + <item row="2" column="0"> + <widget class="QLabel" name="labelPermGen"> + <property name="text"> + <string notr="true">PermGen:</string> + </property> + </widget> + </item> <item row="0" column="0"> <widget class="QLabel" name="labelMinMem"> <property name="text"> @@ -120,10 +127,24 @@ </property> </widget> </item> - <item row="1" column="1"> - <widget class="QSpinBox" name="maxMemSpinBox"> + <item row="1" column="0"> + <widget class="QLabel" name="labelMaxMem"> + <property name="text"> + <string>Maximum memory allocation:</string> + </property> + </widget> + </item> + <item row="3" column="0" colspan="3"> + <widget class="QLabel" name="labelPermgenNote"> + <property name="text"> + <string>Note: Permgen is set automatically by Java 8 and later</string> + </property> + </widget> + </item> + <item row="0" column="2"> + <widget class="QSpinBox" name="minMemSpinBox"> <property name="toolTip"> - <string>The maximum amount of memory Minecraft is allowed to use.</string> + <string>The amount of memory Minecraft is started with.</string> </property> <property name="suffix"> <string notr="true"> MiB</string> @@ -132,20 +153,20 @@ <number>128</number> </property> <property name="maximum"> - <number>65536</number> + <number>1048576</number> </property> <property name="singleStep"> <number>128</number> </property> <property name="value"> - <number>1024</number> + <number>256</number> </property> </widget> </item> - <item row="0" column="1"> - <widget class="QSpinBox" name="minMemSpinBox"> + <item row="1" column="2"> + <widget class="QSpinBox" name="maxMemSpinBox"> <property name="toolTip"> - <string>The amount of memory Minecraft is started with.</string> + <string>The maximum amount of memory Minecraft is allowed to use.</string> </property> <property name="suffix"> <string notr="true"> MiB</string> @@ -154,17 +175,17 @@ <number>128</number> </property> <property name="maximum"> - <number>65536</number> + <number>1048576</number> </property> <property name="singleStep"> <number>128</number> </property> <property name="value"> - <number>256</number> + <number>1024</number> </property> </widget> </item> - <item row="2" column="1"> + <item row="2" column="2"> <widget class="QSpinBox" name="permGenSpinBox"> <property name="toolTip"> <string>The amount of memory available to store loaded Java classes.</string> @@ -186,24 +207,16 @@ </property> </widget> </item> - <item row="2" column="0"> - <widget class="QLabel" name="labelPermGen"> + <item row="1" column="3"> + <widget class="QLabel" name="labelMaxMemIcon"> <property name="text"> - <string notr="true">PermGen:</string> + <string notr="true"/> </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="labelMaxMem"> - <property name="text"> - <string>Maximum memory allocation:</string> + <property name="alignment"> + <set>Qt::AlignCenter</set> </property> - </widget> - </item> - <item row="3" column="0" colspan="2"> - <widget class="QLabel" name="labelPermgenNote"> - <property name="text"> - <string>Note: Permgen is set automatically by Java 8 and later</string> + <property name="buddy"> + <cstring>maxMemSpinBox</cstring> </property> </widget> </item> diff --git a/launcher/ui/pages/instance/ManagedPackPage.cpp b/launcher/ui/pages/instance/ManagedPackPage.cpp new file mode 100644 index 00000000..4de80468 --- /dev/null +++ b/launcher/ui/pages/instance/ManagedPackPage.cpp @@ -0,0 +1,433 @@ +// SPDX-FileCopyrightText: 2022 flow <flowlnlnln@gmail.com> +// +// SPDX-License-Identifier: GPL-3.0-only + +#include "ManagedPackPage.h" +#include "ui_ManagedPackPage.h" + +#include <QListView> +#include <QProxyStyle> +#include <QStyleFactory> + +#include <HoeDown.h> + +#include "Application.h" +#include "BuildConfig.h" +#include "InstanceImportTask.h" +#include "InstanceList.h" +#include "InstanceTask.h" +#include "Json.h" + +#include "modplatform/modrinth/ModrinthPackManifest.h" + +#include "ui/InstanceWindow.h" +#include "ui/dialogs/CustomMessageBox.h" +#include "ui/dialogs/ProgressDialog.h" + +/** This is just to override the combo box popup behavior so that the combo box doesn't take the whole screen. + * ... thanks Qt. + */ +class NoBigComboBoxStyle : public QProxyStyle { + Q_OBJECT + + public: + NoBigComboBoxStyle(QStyle* style) : QProxyStyle(style) {} + + // clang-format off + int styleHint(QStyle::StyleHint hint, const QStyleOption* option = nullptr, const QWidget* widget = nullptr, QStyleHintReturn* returnData = nullptr) const override + { + if (hint == QStyle::SH_ComboBox_Popup) + return false; + + return QProxyStyle::styleHint(hint, option, widget, returnData); + } + // clang-format on +}; + +ManagedPackPage* ManagedPackPage::createPage(BaseInstance* inst, QString type, QWidget* parent) +{ + if (type == "modrinth") + return new ModrinthManagedPackPage(inst, nullptr, parent); + if (type == "flame" && (APPLICATION->capabilities() & Application::SupportsFlame)) + return new FlameManagedPackPage(inst, nullptr, parent); + + return new GenericManagedPackPage(inst, nullptr, parent); +} + +ManagedPackPage::ManagedPackPage(BaseInstance* inst, InstanceWindow* instance_window, QWidget* parent) + : QWidget(parent), m_instance_window(instance_window), ui(new Ui::ManagedPackPage), m_inst(inst) +{ + Q_ASSERT(inst); + + ui->setupUi(this); + + // 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")) + ui->versionsComboBox->setStyle(new NoBigComboBoxStyle(ui->versionsComboBox->style())); + + ui->reloadButton->setVisible(false); + connect(ui->reloadButton, &QPushButton::clicked, this, [this](bool){ + ui->reloadButton->setVisible(false); + + m_loaded = false; + // Pretend we're opening the page again + openedImpl(); + }); +} + +ManagedPackPage::~ManagedPackPage() +{ + delete ui; +} + +void ManagedPackPage::openedImpl() +{ + ui->packName->setText(m_inst->getManagedPackName()); + ui->packVersion->setText(m_inst->getManagedPackVersionName()); + ui->packOrigin->setText(tr("Website: <a href=%1>%2</a> | Pack ID: %3 | Version ID: %4") + .arg(url(), displayName(), m_inst->getManagedPackID(), m_inst->getManagedPackVersionID())); + + parseManagedPack(); +} + +QString ManagedPackPage::displayName() const +{ + auto type = m_inst->getManagedPackType(); + if (type.isEmpty()) + return {}; + if (type == "flame") + type = "CurseForge"; + return type.replace(0, 1, type[0].toUpper()); +} + +QIcon ManagedPackPage::icon() const +{ + return APPLICATION->getThemedIcon(m_inst->getManagedPackType()); +} + +QString ManagedPackPage::helpPage() const +{ + return {}; +} + +void ManagedPackPage::retranslate() +{ + ui->retranslateUi(this); +} + +bool ManagedPackPage::shouldDisplay() const +{ + return m_inst->isManagedPack(); +} + +bool ManagedPackPage::runUpdateTask(InstanceTask* task) +{ + Q_ASSERT(task); + + unique_qobject_ptr<Task> wrapped_task(APPLICATION->instances()->wrapInstanceTask(task)); + + connect(task, &Task::failed, + [this](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show(); }); + connect(task, &Task::succeeded, [this, task]() { + QStringList warnings = task->warnings(); + if (warnings.count()) + CustomMessageBox::selectable(this, tr("Warnings"), warnings.join('\n'), QMessageBox::Warning)->show(); + }); + connect(task, &Task::aborted, [this] { + CustomMessageBox::selectable(this, tr("Task aborted"), tr("The task has been aborted by the user."), QMessageBox::Information) + ->show(); + }); + + ProgressDialog loadDialog(this); + loadDialog.setSkipButton(true, tr("Abort")); + loadDialog.execWithTask(task); + + return task->wasSuccessful(); +} + +void ManagedPackPage::suggestVersion() +{ + ui->updateButton->setText(tr("Update pack")); + ui->updateButton->setDisabled(false); +} + +void ManagedPackPage::setFailState() +{ + qDebug() << "Setting fail state!"; + + // We block signals here so that suggestVersion() doesn't get called, causing an assertion fail. + ui->versionsComboBox->blockSignals(true); + ui->versionsComboBox->clear(); + ui->versionsComboBox->addItem(tr("Failed to search for available versions."), {}); + ui->versionsComboBox->blockSignals(false); + + ui->changelogTextBrowser->setText(tr("Failed to request changelog data for this modpack.")); + + ui->updateButton->setText(tr("Cannot update!")); + ui->updateButton->setDisabled(true); + + ui->reloadButton->setVisible(true); +} + +ModrinthManagedPackPage::ModrinthManagedPackPage(BaseInstance* inst, InstanceWindow* instance_window, QWidget* parent) + : ManagedPackPage(inst, instance_window, parent) +{ + Q_ASSERT(inst->isManagedPack()); + connect(ui->versionsComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(suggestVersion())); + connect(ui->updateButton, &QPushButton::pressed, this, &ModrinthManagedPackPage::update); +} + +// MODRINTH + +void ModrinthManagedPackPage::parseManagedPack() +{ + qDebug() << "Parsing Modrinth pack"; + + // No need for the extra work because we already have everything we need. + if (m_loaded) + return; + + if (m_fetch_job && m_fetch_job->isRunning()) + m_fetch_job->abort(); + + m_fetch_job.reset(new NetJob(QString("Modrinth::PackVersions(%1)").arg(m_inst->getManagedPackName()), APPLICATION->network())); + auto response = std::make_shared<QByteArray>(); + + QString id = m_inst->getManagedPackID(); + + m_fetch_job->addNetAction(Net::Download::makeByteArray(QString("%1/project/%2/version").arg(BuildConfig.MODRINTH_PROD_URL, id), response.get())); + + QObject::connect(m_fetch_job.get(), &NetJob::succeeded, this, [this, response, id] { + QJsonParseError parse_error{}; + QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error); + if (parse_error.error != QJsonParseError::NoError) { + qWarning() << "Error while parsing JSON response from Modrinth at " << parse_error.offset + << " reason: " << parse_error.errorString(); + qWarning() << *response; + + setFailState(); + + return; + } + + try { + Modrinth::loadIndexedVersions(m_pack, doc); + } catch (const JSONValidationError& e) { + qDebug() << *response; + qWarning() << "Error while reading modrinth modpack version: " << e.cause(); + + setFailState(); + return; + } + + // We block signals here so that suggestVersion() doesn't get called, causing an assertion fail. + ui->versionsComboBox->blockSignals(true); + ui->versionsComboBox->clear(); + ui->versionsComboBox->blockSignals(false); + + for (auto version : m_pack.versions) { + QString name = version.version; + + if (!version.name.contains(version.version)) + name = QString("%1 — %2").arg(version.nam |
