Merge remote-tracking branch 'upstream/develop' into resource-meta

Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
TheKodeToad
2024-10-08 17:15:42 +01:00
534 changed files with 14803 additions and 8430 deletions

View File

@ -5,6 +5,7 @@
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
* Copyright (C) 2023 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
@ -40,6 +41,7 @@
#include "modplatform/ModIndex.h"
#include "ui_ResourcePage.h"
#include <StringUtils.h>
#include <QDesktopServices>
#include <QKeyEvent>
@ -67,11 +69,13 @@ ResourcePage::ResourcePage(ResourceDownloadDialog* parent, BaseInstance& base_in
connect(&m_search_timer, &QTimer::timeout, this, &ResourcePage::triggerSearch);
// hide progress bar to prevent weird artifact
m_fetch_progress.hide();
m_fetch_progress.hideIfInactive(true);
m_fetch_progress.setFixedHeight(24);
m_fetch_progress.progressFormat("");
m_ui->gridLayout_3->addWidget(&m_fetch_progress, 0, 0, 1, m_ui->gridLayout_3->columnCount());
m_ui->verticalLayout->insertWidget(1, &m_fetch_progress);
m_ui->packView->setItemDelegate(new ProjectItemDelegate(this));
m_ui->packView->installEventFilter(this);
@ -93,8 +97,10 @@ void ResourcePage::retranslate()
void ResourcePage::openedImpl()
{
if (!supportsFiltering())
if (!supportsFiltering()) {
m_ui->resourceFilterButton->setVisible(false);
m_ui->filterWidget->hide();
}
//: String in the search bar of the mod downloading dialog
m_ui->searchEdit->setPlaceholderText(tr("Search for %1...").arg(resourcesString()));
@ -235,8 +241,8 @@ void ResourcePage::updateUi()
text += "<hr>";
m_ui->packDescription->setHtml(
text + (current_pack->extraData.body.isEmpty() ? current_pack->description : markdownToHTML(current_pack->extraData.body)));
m_ui->packDescription->setHtml(StringUtils::htmlListPatch(
text + (current_pack->extraData.body.isEmpty() ? current_pack->description : markdownToHTML(current_pack->extraData.body))));
m_ui->packDescription->flush();
}
@ -266,18 +272,21 @@ void ResourcePage::updateVersionList()
m_ui->versionSelectionBox->clear();
m_ui->versionSelectionBox->blockSignals(false);
if (current_pack)
if (current_pack) {
auto installedVersion = m_model->getInstalledPackVersion(current_pack);
for (int i = 0; i < current_pack->versions.size(); i++) {
auto& version = current_pack->versions[i];
if (optedOut(version))
if (!m_model->checkVersionFilters(version))
continue;
auto release_type = current_pack->versions[i].version_type.isValid()
? QString(" [%1]").arg(current_pack->versions[i].version_type.toString())
: "";
m_ui->versionSelectionBox->addItem(current_pack->versions[i].version, QVariant(i));
}
m_ui->versionSelectionBox->addItem(QString("%1%2").arg(version.version, release_type), QVariant(i));
}
}
if (m_ui->versionSelectionBox->count() == 0) {
m_ui->versionSelectionBox->addItem(tr("No valid version found."), QVariant(-1));
m_ui->resourceSelectionButton->setText(tr("Cannot select invalid version :("));
@ -313,14 +322,9 @@ void ResourcePage::onSelectionChanged(QModelIndex curr, [[maybe_unused]] QModelI
updateUi();
}
void ResourcePage::onVersionSelectionChanged(QString versionData)
void ResourcePage::onVersionSelectionChanged(int index)
{
if (versionData.isNull() || versionData.isEmpty()) {
m_selected_version_index = -1;
return;
}
m_selected_version_index = m_ui->versionSelectionBox->currentData().toInt();
m_selected_version_index = index;
updateSelectionButton();
}
@ -395,7 +399,7 @@ void ResourcePage::openUrl(const QUrl& url)
}
}
if (!page.isNull()) {
if (!page.isNull() && !m_do_not_jump_to_mod) {
const QString slug = match.captured(1);
// ensure the user isn't opening the same mod
@ -439,4 +443,52 @@ void ResourcePage::openUrl(const QUrl& url)
QDesktopServices::openUrl(url);
}
void ResourcePage::openProject(QVariant projectID)
{
m_ui->sortByBox->hide();
m_ui->searchEdit->hide();
m_ui->resourceFilterButton->hide();
m_ui->packView->hide();
m_ui->resourceSelectionButton->hide();
m_do_not_jump_to_mod = true;
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
auto okBtn = buttonBox->button(QDialogButtonBox::Ok);
okBtn->setDefault(true);
okBtn->setAutoDefault(true);
okBtn->setText(tr("Reinstall"));
okBtn->setShortcut(tr("Ctrl+Return"));
okBtn->setEnabled(false);
auto cancelBtn = buttonBox->button(QDialogButtonBox::Cancel);
cancelBtn->setDefault(false);
cancelBtn->setAutoDefault(false);
connect(okBtn, &QPushButton::clicked, this, [this] {
onResourceSelected();
m_parent_dialog->accept();
});
connect(cancelBtn, &QPushButton::clicked, m_parent_dialog, &ResourceDownloadDialog::reject);
m_ui->gridLayout_4->addWidget(buttonBox, 1, 2);
auto jump = [this, okBtn] {
for (int row = 0; row < m_model->rowCount({}); row++) {
const QModelIndex index = m_model->index(row);
m_ui->packView->setCurrentIndex(index);
okBtn->setEnabled(true);
return;
}
m_ui->packDescription->setText(tr("The resource was not found"));
};
m_ui->searchEdit->setText("#" + projectID.toString());
triggerSearch();
if (m_model->hasActiveSearchJob())
connect(m_model->activeSearchJob().get(), &Task::finished, jump);
else
jump();
}
} // namespace ResourceDownload