Merge branch 'develop' into remove-updater

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
Sefa Eyeoglu
2023-01-24 14:37:40 +01:00
246 changed files with 7104 additions and 9153 deletions

View File

@ -39,12 +39,11 @@
#include <QIcon>
#include "Application.h"
#include "BuildConfig.h"
#include "Markdown.h"
#include <net/NetJob.h>
#include <qobject.h>
#include "HoeDown.h"
namespace {
QString getLink(QString link, QString name) {
return QString("&lt;<a href='%1'>%2</a>&gt;").arg(link).arg(name);
@ -114,10 +113,9 @@ QString getCreditsHtml()
QString getLicenseHtml()
{
HoeDown hoedown;
QFile dataFile(":/documents/COPYING.md");
dataFile.open(QIODevice::ReadOnly);
QString output = hoedown.process(dataFile.readAll());
QString output = markdownToHTML(dataFile.readAll());
return output;
}

View File

@ -234,7 +234,7 @@ void BlockedModsDialog::addHashTask(QString path)
/// @param path the path to the local file being hashed
void BlockedModsDialog::buildHashTask(QString path)
{
auto hash_task = Hashing::createBlockedModHasher(path, ModPlatform::Provider::FLAME, "sha1");
auto hash_task = Hashing::createBlockedModHasher(path, ModPlatform::ResourceProvider::FLAME, "sha1");
qDebug() << "[Blocked Mods Dialog] Creating Hash task for path: " << path;

View File

@ -67,9 +67,9 @@ void ChooseProviderDialog::confirmAll()
accept();
}
auto ChooseProviderDialog::getSelectedProvider() const -> ModPlatform::Provider
auto ChooseProviderDialog::getSelectedProvider() const -> ModPlatform::ResourceProvider
{
return ModPlatform::Provider(m_providers.checkedId());
return ModPlatform::ResourceProvider(m_providers.checkedId());
}
void ChooseProviderDialog::addProviders()
@ -77,7 +77,7 @@ void ChooseProviderDialog::addProviders()
int btn_index = 0;
QRadioButton* btn;
for (auto& provider : { ModPlatform::Provider::MODRINTH, ModPlatform::Provider::FLAME }) {
for (auto& provider : { ModPlatform::ResourceProvider::MODRINTH, ModPlatform::ResourceProvider::FLAME }) {
btn = new QRadioButton(ProviderCaps.readableName(provider), this);
m_providers.addButton(btn, btn_index++);
ui->providersLayout->addWidget(btn);

View File

@ -8,7 +8,7 @@ class ChooseProviderDialog;
}
namespace ModPlatform {
enum class Provider;
enum class ResourceProvider;
}
class Mod;
@ -24,7 +24,7 @@ class ChooseProviderDialog : public QDialog {
bool try_others = false;
ModPlatform::Provider chosen;
ModPlatform::ResourceProvider chosen;
};
public:
@ -45,7 +45,7 @@ class ChooseProviderDialog : public QDialog {
void addProviders();
void disableInput();
auto getSelectedProvider() const -> ModPlatform::Provider;
auto getSelectedProvider() const -> ModPlatform::ResourceProvider;
private:
Ui::ChooseProviderDialog* ui;

View File

@ -47,7 +47,6 @@ IconPickerDialog::IconPickerDialog(QWidget *parent)
contentsWidget->setUniformItemSizes(true);
contentsWidget->setTextElideMode(Qt::ElideRight);
contentsWidget->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
contentsWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
contentsWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
contentsWidget->setItemDelegate(new ListViewDelegate());

View File

@ -1,5 +1,5 @@
#include "ImportResourcePackDialog.h"
#include "ui_ImportResourcePackDialog.h"
#include "ImportResourceDialog.h"
#include "ui_ImportResourceDialog.h"
#include <QFileDialog>
#include <QPushButton>
@ -8,10 +8,11 @@
#include "InstanceList.h"
#include <InstanceList.h>
#include "ui/instanceview/InstanceProxyModel.h"
#include "ui/instanceview/InstanceDelegate.h"
#include "ui/instanceview/InstanceProxyModel.h"
ImportResourcePackDialog::ImportResourcePackDialog(QWidget* parent) : QDialog(parent), ui(new Ui::ImportResourcePackDialog)
ImportResourceDialog::ImportResourceDialog(QString file_path, PackedResourceType type, QWidget* parent)
: QDialog(parent), ui(new Ui::ImportResourceDialog), m_resource_type(type), m_file_path(file_path)
{
ui->setupUi(this);
setWindowModality(Qt::WindowModal);
@ -29,7 +30,6 @@ ImportResourcePackDialog::ImportResourcePackDialog(QWidget* parent) : QDialog(pa
// NOTE: We can't have uniform sizes because the text may wrap if it's too long. If we set this, it will cut off the wrapped text.
contentsWidget->setUniformItemSizes(false);
contentsWidget->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
contentsWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
contentsWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
contentsWidget->setItemDelegate(new ListViewDelegate());
@ -41,15 +41,19 @@ ImportResourcePackDialog::ImportResourcePackDialog(QWidget* parent) : QDialog(pa
connect(contentsWidget, SIGNAL(doubleClicked(QModelIndex)), SLOT(activated(QModelIndex)));
connect(contentsWidget->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
SLOT(selectionChanged(QItemSelection, QItemSelection)));
ui->label->setText(
tr("Choose the instance you would like to import this %1 to.").arg(ResourceUtils::getPackedTypeName(m_resource_type)));
ui->label_file_path->setText(tr("File: %1").arg(m_file_path));
}
void ImportResourcePackDialog::activated(QModelIndex index)
void ImportResourceDialog::activated(QModelIndex index)
{
selectedInstanceKey = index.data(InstanceList::InstanceIDRole).toString();
accept();
}
void ImportResourcePackDialog::selectionChanged(QItemSelection selected, QItemSelection deselected)
void ImportResourceDialog::selectionChanged(QItemSelection selected, QItemSelection deselected)
{
if (selected.empty())
return;
@ -60,7 +64,7 @@ void ImportResourcePackDialog::selectionChanged(QItemSelection selected, QItemSe
}
}
ImportResourcePackDialog::~ImportResourcePackDialog()
ImportResourceDialog::~ImportResourceDialog()
{
delete ui;
}

View File

@ -0,0 +1,30 @@
#pragma once
#include <QDialog>
#include <QItemSelection>
#include "minecraft/mod/tasks/LocalResourceParse.h"
#include "ui/instanceview/InstanceProxyModel.h"
namespace Ui {
class ImportResourceDialog;
}
class ImportResourceDialog : public QDialog {
Q_OBJECT
public:
explicit ImportResourceDialog(QString file_path, PackedResourceType type, QWidget* parent = nullptr);
~ImportResourceDialog() override;
QString selectedInstanceKey;
private:
Ui::ImportResourceDialog* ui;
PackedResourceType m_resource_type;
QString m_file_path;
InstanceProxyModel* proxyModel;
private slots:
void selectionChanged(QItemSelection, QItemSelection);
void activated(QModelIndex);
};

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ImportResourcePackDialog</class>
<widget class="QDialog" name="ImportResourcePackDialog">
<class>ImportResourceDialog</class>
<widget class="QDialog" name="ImportResourceDialog">
<property name="geometry">
<rect>
<x>0</x>
@ -11,7 +11,7 @@
</rect>
</property>
<property name="windowTitle">
<string>Choose instance to import</string>
<string>Choose instance to import to</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
@ -21,6 +21,13 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_file_path">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QListView" name="instanceView"/>
</item>
@ -41,7 +48,7 @@
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ImportResourcePackDialog</receiver>
<receiver>ImportResourceDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
@ -57,7 +64,7 @@
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ImportResourcePackDialog</receiver>
<receiver>ImportResourceDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">

View File

@ -1,27 +0,0 @@
#pragma once
#include <QDialog>
#include <QItemSelection>
#include "ui/instanceview/InstanceProxyModel.h"
namespace Ui {
class ImportResourcePackDialog;
}
class ImportResourcePackDialog : public QDialog {
Q_OBJECT
public:
explicit ImportResourcePackDialog(QWidget* parent = 0);
~ImportResourcePackDialog();
InstanceProxyModel* proxyModel;
QString selectedInstanceKey;
private:
Ui::ImportResourcePackDialog* ui;
private slots:
void selectionChanged(QItemSelection, QItemSelection);
void activated(QModelIndex);
};

View File

@ -1,202 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
*
* 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
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "ModDownloadDialog.h"
#include <BaseVersion.h>
#include <InstanceList.h>
#include <icons/IconList.h>
#include "Application.h"
#include "ReviewMessageBox.h"
#include <QDialogButtonBox>
#include <QLayout>
#include <QPushButton>
#include <QValidator>
#include "ModDownloadTask.h"
#include "ui/pages/modplatform/flame/FlameModPage.h"
#include "ui/pages/modplatform/modrinth/ModrinthModPage.h"
#include "ui/widgets/PageContainer.h"
ModDownloadDialog::ModDownloadDialog(const std::shared_ptr<ModFolderModel>& mods, QWidget* parent, BaseInstance* instance)
: QDialog(parent), mods(mods), m_verticalLayout(new QVBoxLayout(this)), m_instance(instance)
{
setObjectName(QStringLiteral("ModDownloadDialog"));
m_verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
resize(std::max(0.5 * parent->width(), 400.0), std::max(0.75 * parent->height(), 400.0));
setWindowIcon(APPLICATION->getThemedIcon("new"));
// NOTE: m_buttons must be initialized before PageContainer, because it indirectly accesses m_buttons through setSuggestedPack! Do not
// move this below.
m_buttons = new QDialogButtonBox(QDialogButtonBox::Help | QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
m_container = new PageContainer(this);
m_container->setSizePolicy(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Expanding);
m_container->layout()->setContentsMargins(0, 0, 0, 0);
m_verticalLayout->addWidget(m_container);
m_container->addButtons(m_buttons);
connect(m_container, &PageContainer::selectedPageChanged, this, &ModDownloadDialog::selectedPageChanged);
// Bonk Qt over its stupid head and make sure it understands which button is the default one...
// See: https://stackoverflow.com/questions/24556831/qbuttonbox-set-default-button
auto OkButton = m_buttons->button(QDialogButtonBox::Ok);
OkButton->setEnabled(false);
OkButton->setDefault(true);
OkButton->setAutoDefault(true);
OkButton->setText(tr("Review and confirm"));
OkButton->setShortcut(tr("Ctrl+Return"));
OkButton->setToolTip(tr("Opens a new popup to review your selected mods and confirm your selection. Shortcut: Ctrl+Return"));
connect(OkButton, &QPushButton::clicked, this, &ModDownloadDialog::confirm);
auto CancelButton = m_buttons->button(QDialogButtonBox::Cancel);
CancelButton->setDefault(false);
CancelButton->setAutoDefault(false);
connect(CancelButton, &QPushButton::clicked, this, &ModDownloadDialog::reject);
auto HelpButton = m_buttons->button(QDialogButtonBox::Help);
HelpButton->setDefault(false);
HelpButton->setAutoDefault(false);
connect(HelpButton, &QPushButton::clicked, m_container, &PageContainer::help);
QMetaObject::connectSlotsByName(this);
setWindowModality(Qt::WindowModal);
setWindowTitle(dialogTitle());
restoreGeometry(QByteArray::fromBase64(APPLICATION->settings()->get("ModDownloadGeometry").toByteArray()));
}
QString ModDownloadDialog::dialogTitle()
{
return tr("Download mods");
}
void ModDownloadDialog::reject()
{
APPLICATION->settings()->set("ModDownloadGeometry", saveGeometry().toBase64());
QDialog::reject();
}
void ModDownloadDialog::confirm()
{
auto keys = modTask.keys();
keys.sort(Qt::CaseInsensitive);
auto confirm_dialog = ReviewMessageBox::create(this, tr("Confirm mods to download"));
for (auto& task : keys) {
confirm_dialog->appendMod({ task, modTask.find(task).value()->getFilename() });
}
if (confirm_dialog->exec()) {
auto deselected = confirm_dialog->deselectedMods();
for (auto name : deselected) {
modTask.remove(name);
}
this->accept();
}
}
void ModDownloadDialog::accept()
{
APPLICATION->settings()->set("ModDownloadGeometry", saveGeometry().toBase64());
QDialog::accept();
}
QList<BasePage*> ModDownloadDialog::getPages()
{
QList<BasePage*> pages;
pages.append(ModrinthModPage::create(this, m_instance));
if (APPLICATION->capabilities() & Application::SupportsFlame)
pages.append(FlameModPage::create(this, m_instance));
m_selectedPage = dynamic_cast<ModPage*>(pages[0]);
return pages;
}
void ModDownloadDialog::addSelectedMod(QString name, ModDownloadTask* task)
{
removeSelectedMod(name);
modTask.insert(name, task);
m_buttons->button(QDialogButtonBox::Ok)->setEnabled(!modTask.isEmpty());
}
void ModDownloadDialog::removeSelectedMod(QString name)
{
if (modTask.contains(name))
delete modTask.find(name).value();
modTask.remove(name);
m_buttons->button(QDialogButtonBox::Ok)->setEnabled(!modTask.isEmpty());
}
bool ModDownloadDialog::isModSelected(QString name, QString filename) const
{
// FIXME: Is there a way to check for versions without checking the filename
// as a heuristic, other than adding such info to ModDownloadTask itself?
auto iter = modTask.find(name);
return iter != modTask.end() && (iter.value()->getFilename() == filename);
}
bool ModDownloadDialog::isModSelected(QString name) const
{
auto iter = modTask.find(name);
return iter != modTask.end();
}
const QList<ModDownloadTask*> ModDownloadDialog::getTasks()
{
return modTask.values();
}
void ModDownloadDialog::selectedPageChanged(BasePage* previous, BasePage* selected)
{
auto* prev_page = dynamic_cast<ModPage*>(previous);
if (!prev_page) {
qCritical() << "Page '" << previous->displayName() << "' in ModDownloadDialog is not a ModPage!";
return;
}
m_selectedPage = dynamic_cast<ModPage*>(selected);
if (!m_selectedPage) {
qCritical() << "Page '" << selected->displayName() << "' in ModDownloadDialog is not a ModPage!";
return;
}
// Same effect as having a global search bar
m_selectedPage->setSearchTerm(prev_page->getSearchTerm());
}
bool ModDownloadDialog::selectPage(QString pageId)
{
return m_container->selectPage(pageId);
}
ModPage* ModDownloadDialog::getSelectedPage()
{
return m_selectedPage;
}

View File

@ -1,78 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
*
* 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
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <QDialog>
#include <QVBoxLayout>
#include "ModDownloadTask.h"
#include "minecraft/mod/ModFolderModel.h"
#include "ui/pages/BasePageProvider.h"
namespace Ui
{
class ModDownloadDialog;
}
class PageContainer;
class QDialogButtonBox;
class ModPage;
class ModrinthModPage;
class ModDownloadDialog final : public QDialog, public BasePageProvider
{
Q_OBJECT
public:
explicit ModDownloadDialog(const std::shared_ptr<ModFolderModel>& mods, QWidget* parent, BaseInstance* instance);
~ModDownloadDialog() override = default;
QString dialogTitle() override;
QList<BasePage*> getPages() override;
void addSelectedMod(QString name = QString(), ModDownloadTask* task = nullptr);
void removeSelectedMod(QString name = QString());
bool isModSelected(QString name, QString filename) const;
bool isModSelected(QString name) const;
const QList<ModDownloadTask*> getTasks();
const std::shared_ptr<ModFolderModel>& mods;
bool selectPage(QString pageId);
ModPage* getSelectedPage();
public slots:
void confirm();
void accept() override;
void reject() override;
private slots:
void selectedPageChanged(BasePage* previous, BasePage* selected);
private:
Ui::ModDownloadDialog* ui = nullptr;
PageContainer* m_container = nullptr;
QDialogButtonBox* m_buttons = nullptr;
QVBoxLayout* m_verticalLayout = nullptr;
ModPage* m_selectedPage = nullptr;
QHash<QString, ModDownloadTask*> modTask;
BaseInstance* m_instance;
};

View File

@ -7,6 +7,7 @@
#include "FileSystem.h"
#include "Json.h"
#include "Markdown.h"
#include "tasks/ConcurrentTask.h"
@ -17,10 +18,11 @@
#include "modplatform/flame/FlameCheckUpdate.h"
#include "modplatform/modrinth/ModrinthCheckUpdate.h"
#include <HoeDown.h>
#include <QTextBrowser>
#include <QTreeWidgetItem>
#include <optional>
static ModPlatform::ProviderCapabilities ProviderCaps;
static std::list<Version> mcVersions(BaseInstance* inst)
@ -28,7 +30,7 @@ static std::list<Version> mcVersions(BaseInstance* inst)
return { static_cast<MinecraftInstance*>(inst)->getPackProfile()->getComponent("net.minecraft")->getVersion() };
}
static ModAPI::ModLoaderTypes mcLoaders(BaseInstance* inst)
static std::optional<ResourceAPI::ModLoaderTypes> mcLoaders(BaseInstance* inst)
{
return { static_cast<MinecraftInstance*>(inst)->getPackProfile()->getModLoaders() };
}
@ -212,14 +214,14 @@ auto ModUpdateDialog::ensureMetadata() -> bool
bool confirm_rest = false;
bool try_others_rest = false;
bool skip_rest = false;
ModPlatform::Provider provider_rest = ModPlatform::Provider::MODRINTH;
ModPlatform::ResourceProvider provider_rest = ModPlatform::ResourceProvider::MODRINTH;
auto addToTmp = [&](Mod* m, ModPlatform::Provider p) {
auto addToTmp = [&](Mod* m, ModPlatform::ResourceProvider p) {
switch (p) {
case ModPlatform::Provider::MODRINTH:
case ModPlatform::ResourceProvider::MODRINTH:
modrinth_tmp.push_back(m);
break;
case ModPlatform::Provider::FLAME:
case ModPlatform::ResourceProvider::FLAME:
flame_tmp.push_back(m);
break;
}
@ -264,10 +266,10 @@ auto ModUpdateDialog::ensureMetadata() -> bool
}
if (!modrinth_tmp.empty()) {
auto* modrinth_task = new EnsureMetadataTask(modrinth_tmp, index_dir, ModPlatform::Provider::MODRINTH);
auto* modrinth_task = new EnsureMetadataTask(modrinth_tmp, index_dir, ModPlatform::ResourceProvider::MODRINTH);
connect(modrinth_task, &EnsureMetadataTask::metadataReady, [this](Mod* candidate) { onMetadataEnsured(candidate); });
connect(modrinth_task, &EnsureMetadataTask::metadataFailed, [this, &should_try_others](Mod* candidate) {
onMetadataFailed(candidate, should_try_others.find(candidate->internal_id()).value(), ModPlatform::Provider::MODRINTH);
onMetadataFailed(candidate, should_try_others.find(candidate->internal_id()).value(), ModPlatform::ResourceProvider::MODRINTH);
});
if (modrinth_task->getHashingTask())
@ -277,10 +279,10 @@ auto ModUpdateDialog::ensureMetadata() -> bool
}
if (!flame_tmp.empty()) {
auto* flame_task = new EnsureMetadataTask(flame_tmp, index_dir, ModPlatform::Provider::FLAME);
auto* flame_task = new EnsureMetadataTask(flame_tmp, index_dir, ModPlatform::ResourceProvider::FLAME);
connect(flame_task, &EnsureMetadataTask::metadataReady, [this](Mod* candidate) { onMetadataEnsured(candidate); });
connect(flame_task, &EnsureMetadataTask::metadataFailed, [this, &should_try_others](Mod* candidate) {
onMetadataFailed(candidate, should_try_others.find(candidate->internal_id()).value(), ModPlatform::Provider::FLAME);
onMetadataFailed(candidate, should_try_others.find(candidate->internal_id()).value(), ModPlatform::ResourceProvider::FLAME);
});
if (flame_task->getHashingTask())
@ -306,28 +308,28 @@ void ModUpdateDialog::onMetadataEnsured(Mod* mod)
return;
switch (mod->metadata()->provider) {
case ModPlatform::Provider::MODRINTH:
case ModPlatform::ResourceProvider::MODRINTH:
m_modrinth_to_update.push_back(mod);
break;
case ModPlatform::Provider::FLAME:
case ModPlatform::ResourceProvider::FLAME:
m_flame_to_update.push_back(mod);
break;
}
}
ModPlatform::Provider next(ModPlatform::Provider p)
ModPlatform::ResourceProvider next(ModPlatform::ResourceProvider p)
{
switch (p) {
case ModPlatform::Provider::MODRINTH:
return ModPlatform::Provider::FLAME;
case ModPlatform::Provider::FLAME:
return ModPlatform::Provider::MODRINTH;
case ModPlatform::ResourceProvider::MODRINTH:
return ModPlatform::ResourceProvider::FLAME;
case ModPlatform::ResourceProvider::FLAME:
return ModPlatform::ResourceProvider::MODRINTH;
}
return ModPlatform::Provider::FLAME;
return ModPlatform::ResourceProvider::FLAME;
}
void ModUpdateDialog::onMetadataFailed(Mod* mod, bool try_others, ModPlatform::Provider first_choice)
void ModUpdateDialog::onMetadataFailed(Mod* mod, bool try_others, ModPlatform::ResourceProvider first_choice)
{
if (try_others) {
auto index_dir = indexDir();
@ -368,15 +370,8 @@ void ModUpdateDialog::appendMod(CheckUpdateTask::UpdatableMod const& info)
QString text = info.changelog;
switch (info.provider) {
case ModPlatform::Provider::MODRINTH: {
HoeDown h;
// HoeDown bug?: \n aren't converted to <br>
text = h.process(info.changelog.toUtf8());
// Don't convert if there's an HTML tag right after (Qt rendering weirdness)
text.remove(QRegularExpression("(\n+)(?=<)"));
text.replace('\n', "<br>");
case ModPlatform::ResourceProvider::MODRINTH: {
text = markdownToHTML(info.changelog.toUtf8());
break;
}
default:
@ -393,9 +388,9 @@ void ModUpdateDialog::appendMod(CheckUpdateTask::UpdatableMod const& info)
ui->modTreeWidget->addTopLevelItem(item_top);
}
auto ModUpdateDialog::getTasks() -> const QList<ModDownloadTask*>
auto ModUpdateDialog::getTasks() -> const QList<ResourceDownloadTask*>
{
QList<ModDownloadTask*> list;
QList<ResourceDownloadTask*> list;
auto* item = ui->modTreeWidget->topLevelItem(0);

View File

@ -1,7 +1,7 @@
#pragma once
#include "BaseInstance.h"
#include "ModDownloadTask.h"
#include "ResourceDownloadTask.h"
#include "ReviewMessageBox.h"
#include "minecraft/mod/ModFolderModel.h"
@ -25,7 +25,7 @@ class ModUpdateDialog final : public ReviewMessageBox {
void appendMod(const CheckUpdateTask::UpdatableMod& info);
const QList<ModDownloadTask*> getTasks();
const QList<ResourceDownloadTask*> getTasks();
auto indexDir() const -> QDir { return m_mod_model->indexDir(); }
auto noUpdates() const -> bool { return m_no_updates; };
@ -36,7 +36,7 @@ class ModUpdateDialog final : public ReviewMessageBox {
private slots:
void onMetadataEnsured(Mod*);
void onMetadataFailed(Mod*, bool try_others = false, ModPlatform::Provider first_choice = ModPlatform::Provider::MODRINTH);
void onMetadataFailed(Mod*, bool try_others = false, ModPlatform::ResourceProvider first_choice = ModPlatform::ResourceProvider::MODRINTH);
private:
QWidget* m_parent;
@ -54,7 +54,7 @@ class ModUpdateDialog final : public ReviewMessageBox {
QList<std::tuple<Mod*, QString>> m_failed_metadata;
QList<std::tuple<Mod*, QString, QUrl>> m_failed_check_update;
QHash<QString, ModDownloadTask*> m_tasks;
QHash<QString, ResourceDownloadTask*> m_tasks;
BaseInstance* m_instance;
bool m_no_updates = false;

View File

@ -0,0 +1,232 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
*
* 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
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "ResourceDownloadDialog.h"
#include <QPushButton>
#include "Application.h"
#include "ResourceDownloadTask.h"
#include "minecraft/mod/ModFolderModel.h"
#include "ui/dialogs/ReviewMessageBox.h"
#include "ui/pages/modplatform/ResourcePage.h"
#include "ui/pages/modplatform/flame/FlameResourcePages.h"
#include "ui/pages/modplatform/modrinth/ModrinthResourcePages.h"
#include "ui/widgets/PageContainer.h"
namespace ResourceDownload {
ResourceDownloadDialog::ResourceDownloadDialog(QWidget* parent, const std::shared_ptr<ResourceFolderModel> base_model)
: QDialog(parent), m_base_model(base_model), m_buttons(QDialogButtonBox::Help | QDialogButtonBox::Ok | QDialogButtonBox::Cancel), m_vertical_layout(this)
{
setObjectName(QStringLiteral("ResourceDownloadDialog"));
resize(std::max(0.5 * parent->width(), 400.0), std::max(0.75 * parent->height(), 400.0));
setWindowIcon(APPLICATION->getThemedIcon("new"));
// Bonk Qt over its stupid head and make sure it understands which button is the default one...
// See: https://stackoverflow.com/questions/24556831/qbuttonbox-set-default-button
auto OkButton = m_buttons.button(QDialogButtonBox::Ok);
OkButton->setEnabled(false);
OkButton->setDefault(true);
OkButton->setAutoDefault(true);
OkButton->setText(tr("Review and confirm"));
OkButton->setShortcut(tr("Ctrl+Return"));
auto CancelButton = m_buttons.button(QDialogButtonBox::Cancel);
CancelButton->setDefault(false);
CancelButton->setAutoDefault(false);
auto HelpButton = m_buttons.button(QDialogButtonBox::Help);
HelpButton->setDefault(false);
HelpButton->setAutoDefault(false);
setWindowModality(Qt::WindowModal);
}
void ResourceDownloadDialog::accept()
{
if (!geometrySaveKey().isEmpty())
APPLICATION->settings()->set(geometrySaveKey(), saveGeometry().toBase64());
QDialog::accept();
}
void ResourceDownloadDialog::reject()
{
if (!geometrySaveKey().isEmpty())
APPLICATION->settings()->set(geometrySaveKey(), saveGeometry().toBase64());
QDialog::reject();
}
// NOTE: We can't have this in the ctor because PageContainer calls a virtual function, and so
// won't work with subclasses if we put it in this ctor.
void ResourceDownloadDialog::initializeContainer()
{
m_container = new PageContainer(this);
m_container->setSizePolicy(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Expanding);
m_container->layout()->setContentsMargins(0, 0, 0, 0);
m_vertical_layout.addWidget(m_container);
m_container->addButtons(&m_buttons);
connect(m_container, &PageContainer::selectedPageChanged, this, &ResourceDownloadDialog::selectedPageChanged);
}
void ResourceDownloadDialog::connectButtons()
{
auto OkButton = m_buttons.button(QDialogButtonBox::Ok);
OkButton->setToolTip(tr("Opens a new popup to review your selected %1 and confirm your selection. Shortcut: Ctrl+Return").arg(resourcesString()));
connect(OkButton, &QPushButton::clicked, this, &ResourceDownloadDialog::confirm);
auto CancelButton = m_buttons.button(QDialogButtonBox::Cancel);
connect(CancelButton, &QPushButton::clicked, this, &ResourceDownloadDialog::reject);
auto HelpButton = m_buttons.button(QDialogButtonBox::Help);
connect(HelpButton, &QPushButton::clicked, m_container, &PageContainer::help);
}
void ResourceDownloadDialog::confirm()
{
auto keys = m_selected.keys();
keys.sort(Qt::CaseInsensitive);
auto confirm_dialog = ReviewMessageBox::create(this, tr("Confirm %1 to download").arg(resourcesString()));
confirm_dialog->retranslateUi(resourcesString());
for (auto& task : keys) {
auto selected = m_selected.constFind(task).value();
confirm_dialog->appendResource({ task, selected->getFilename(), selected->getCustomPath() });
}
if (confirm_dialog->exec()) {
auto deselected = confirm_dialog->deselectedResources();
for (auto name : deselected) {
m_selected.remove(name);
}
this->accept();
}
}
bool ResourceDownloadDialog::selectPage(QString pageId)
{
return m_container->selectPage(pageId);
}
ResourcePage* ResourceDownloadDialog::getSelectedPage()
{
return m_selectedPage;
}
void ResourceDownloadDialog::addResource(ModPlatform::IndexedPack& pack, ModPlatform::IndexedVersion& ver, bool is_indexed)
{
removeResource(pack, ver);
ver.is_currently_selected = true;
m_selected.insert(pack.name, new ResourceDownloadTask(pack, ver, getBaseModel(), is_indexed));
m_buttons.button(QDialogButtonBox::Ok)->setEnabled(!m_selected.isEmpty());
}
static ModPlatform::IndexedVersion& getVersionWithID(ModPlatform::IndexedPack& pack, QVariant id)
{
Q_ASSERT(pack.versionsLoaded);
auto it = std::find_if(pack.versions.begin(), pack.versions.end(), [id](auto const& v) { return v.fileId == id; });
Q_ASSERT(it != pack.versions.end());
return *it;
}
void ResourceDownloadDialog::removeResource(ModPlatform::IndexedPack& pack, ModPlatform::IndexedVersion& ver)
{
if (auto selected_task_it = m_selected.find(pack.name); selected_task_it != m_selected.end()) {
auto selected_task = *selected_task_it;
auto old_version_id = selected_task->getVersionID();
// If the new and old version IDs don't match, search for the old one and deselect it.
if (ver.fileId != old_version_id)
getVersionWithID(pack, old_version_id).is_currently_selected = false;
}
// Deselect the new version too, since all versions of that pack got removed.
ver.is_currently_selected = false;
m_selected.remove(pack.name);
m_buttons.button(QDialogButtonBox::Ok)->setEnabled(!m_selected.isEmpty());
}
const QList<ResourceDownloadDialog::DownloadTaskPtr> ResourceDownloadDialog::getTasks()
{
return m_selected.values();
}
void ResourceDownloadDialog::selectedPageChanged(BasePage* previous, BasePage* selected)
{
auto* prev_page = dynamic_cast<ResourcePage*>(previous);
if (!prev_page) {
qCritical() << "Page '" << previous->displayName() << "' in ResourceDownloadDialog is not a ResourcePage!";
return;
}
m_selectedPage = dynamic_cast<ResourcePage*>(selected);
if (!m_selectedPage) {
qCritical() << "Page '" << selected->displayName() << "' in ResourceDownloadDialog is not a ResourcePage!";
return;
}
// Same effect as having a global search bar
m_selectedPage->setSearchTerm(prev_page->getSearchTerm());
}
ModDownloadDialog::ModDownloadDialog(QWidget* parent, const std::shared_ptr<ModFolderModel>& mods, BaseInstance* instance)
: ResourceDownloadDialog(parent, mods), m_instance(instance)
{
setWindowTitle(dialogTitle());
initializeContainer();
connectButtons();
if (!geometrySaveKey().isEmpty())
restoreGeometry(QByteArray::fromBase64(APPLICATION->settings()->get(geometrySaveKey()).toByteArray()));
}
QList<BasePage*> ModDownloadDialog::getPages()
{
QList<BasePage*> pages;
pages.append(ModrinthModPage::create(this, *m_instance));
if (APPLICATION->capabilities() & Application::SupportsFlame)
pages.append(FlameModPage::create(this, *m_instance));
m_selectedPage = dynamic_cast<ModPage*>(pages[0]);
return pages;
}
} // namespace ResourceDownload

View File

@ -0,0 +1,111 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
*
* 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
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <QDialog>
#include <QDialogButtonBox>
#include <QHash>
#include <QLayout>
#include "QObjectPtr.h"
#include "modplatform/ModIndex.h"
#include "ui/pages/BasePageProvider.h"
class BaseInstance;
class ModFolderModel;
class PageContainer;
class QVBoxLayout;
class QDialogButtonBox;
class ResourceDownloadTask;
class ResourceFolderModel;
namespace ResourceDownload {
class ResourcePage;
class ResourceDownloadDialog : public QDialog, public BasePageProvider {
Q_OBJECT
public:
using DownloadTaskPtr = shared_qobject_ptr<ResourceDownloadTask>;
ResourceDownloadDialog(QWidget* parent, const std::shared_ptr<ResourceFolderModel> base_model);
void initializeContainer();
void connectButtons();
//: String that gets appended to the download dialog title ("Download " + resourcesString())
[[nodiscard]] virtual QString resourcesString() const { return tr("resources"); }
QString dialogTitle() override { return tr("Download %1").arg(resourcesString()); };
bool selectPage(QString pageId);
ResourcePage* getSelectedPage();
void addResource(ModPlatform::IndexedPack&, ModPlatform::IndexedVersion&, bool is_indexed = false);
void removeResource(ModPlatform::IndexedPack&, ModPlatform::IndexedVersion&);
const QList<DownloadTaskPtr> getTasks();
[[nodiscard]] const std::shared_ptr<ResourceFolderModel> getBaseModel() const { return m_base_model; }
public slots:
void accept() override;
void reject() override;
protected slots:
void selectedPageChanged(BasePage* previous, BasePage* selected);
virtual void confirm();
protected:
[[nodiscard]] virtual QString geometrySaveKey() const { return ""; }
protected:
const std::shared_ptr<ResourceFolderModel> m_base_model;
PageContainer* m_container = nullptr;
ResourcePage* m_selectedPage = nullptr;
QDialogButtonBox m_buttons;
QVBoxLayout m_vertical_layout;
QHash<QString, DownloadTaskPtr> m_selected;
};
class ModDownloadDialog final : public ResourceDownloadDialog {
Q_OBJECT
public:
explicit ModDownloadDialog(QWidget* parent, const std::shared_ptr<ModFolderModel>& mods, BaseInstance* instance);
~ModDownloadDialog() override = default;
//: String that gets appended to the mod download dialog title ("Download " + resourcesString())
[[nodiscard]] QString resourcesString() const override { return tr("mods"); }
[[nodiscard]] QString geometrySaveKey() const override { return "ModDownloadGeometry"; }
QList<BasePage*> getPages() override;
private:
BaseInstance* m_instance;
};
} // namespace ResourceDownload

View File

@ -1,6 +1,8 @@
#include "ReviewMessageBox.h"
#include "ui_ReviewMessageBox.h"
#include "Application.h"
#include <QPushButton>
ReviewMessageBox::ReviewMessageBox(QWidget* parent, QString const& title, QString const& icon)
@ -11,6 +13,10 @@ ReviewMessageBox::ReviewMessageBox(QWidget* parent, QString const& title, QStrin
auto back_button = ui->buttonBox->button(QDialogButtonBox::Cancel);
back_button->setText(tr("Back"));
ui->modTreeWidget->header()->setSectionResizeMode(0, QHeaderView::Stretch);
ui->modTreeWidget->header()->setStretchLastSection(false);
ui->modTreeWidget->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &ReviewMessageBox::accept);
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &ReviewMessageBox::reject);
}
@ -25,7 +31,7 @@ auto ReviewMessageBox::create(QWidget* parent, QString&& title, QString&& icon)
return new ReviewMessageBox(parent, title, icon);
}
void ReviewMessageBox::appendMod(ModInformation&& info)
void ReviewMessageBox::appendResource(ResourceInformation&& info)
{
auto itemTop = new QTreeWidgetItem(ui->modTreeWidget);
itemTop->setCheckState(0, Qt::CheckState::Checked);
@ -36,10 +42,20 @@ void ReviewMessageBox::appendMod(ModInformation&& info)
itemTop->insertChildren(0, { filenameItem });
if (!info.custom_file_path.isEmpty()) {
auto customPathItem = new QTreeWidgetItem(itemTop);
customPathItem->setText(0, tr("This download will be placed in: %1").arg(info.custom_file_path));
itemTop->insertChildren(1, { customPathItem });
itemTop->setIcon(1, QIcon(APPLICATION->getThemedIcon("status-yellow")));
itemTop->setToolTip(1, tr("This file will be downloaded to a folder location different from the default, possibly due to its loader requiring it."));
}
ui->modTreeWidget->addTopLevelItem(itemTop);
}
auto ReviewMessageBox::deselectedMods() -> QStringList
auto ReviewMessageBox::deselectedResources() -> QStringList
{
QStringList list;
@ -55,3 +71,11 @@ auto ReviewMessageBox::deselectedMods() -> QStringList
return list;
}
void ReviewMessageBox::retranslateUi(QString resources_name)
{
setWindowTitle(tr("Confirm %1 selection").arg(resources_name));
ui->explainLabel->setText(tr("You're about to download the following %1:").arg(resources_name));
ui->onlyCheckedLabel->setText(tr("Only %1 with a check will be downloaded!").arg(resources_name));
}

View File

@ -12,15 +12,18 @@ class ReviewMessageBox : public QDialog {
public:
static auto create(QWidget* parent, QString&& title, QString&& icon = "") -> ReviewMessageBox*;
using ModInformation = struct {
using ResourceInformation = struct res_info {
QString name;
QString filename;
QString custom_file_path {};
};
void appendMod(ModInformation&& info);
auto deselectedMods() -> QStringList;
void appendResource(ResourceInformation&& info);
auto deselectedResources() -> QStringList;
~ReviewMessageBox();
void retranslateUi(QString resources_name);
~ReviewMessageBox() override;
protected:
ReviewMessageBox(QWidget* parent, const QString& title, const QString& icon);

View File

@ -10,9 +10,6 @@
<height>350</height>
</rect>
</property>
<property name="windowTitle">
<string>Confirm mod selection</string>
</property>
<property name="sizeGripEnabled">
<bool>true</bool>
</property>
@ -39,22 +36,21 @@
<string/>
</property>
</column>
<column>
<property name="text">
<string/>
</property>
</column>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="explainLabel">
<property name="text">
<string>You're about to download the following mods:</string>
</property>
</widget>
</item>
<item row="5" column="0" rowspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="onlyCheckedLabel">
<property name="text">
<string>Only mods with a check will be downloaded!</string>
</property>
</widget>
</item>
<item>