2022-06-12 17:20:58 +05:30
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
/*
|
2022-11-06 15:38:54 +05:30
|
|
|
* Prism Launcher - Minecraft Launcher
|
2022-06-12 17:20:58 +05:30
|
|
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
2022-11-01 22:28:22 +05:30
|
|
|
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
2022-06-12 17:20:58 +05:30
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following copyright and
|
|
|
|
* permission notice:
|
|
|
|
*
|
|
|
|
* Copyright 2013-2021 MultiMC Contributors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-03-03 05:47:10 +05:30
|
|
|
#include "ModPage.h"
|
2022-06-04 19:00:34 +05:30
|
|
|
#include "Application.h"
|
2022-03-03 05:47:10 +05:30
|
|
|
#include "ui_ModPage.h"
|
|
|
|
|
2022-11-01 22:28:22 +05:30
|
|
|
#include <QDesktopServices>
|
2022-03-03 05:47:10 +05:30
|
|
|
#include <QKeyEvent>
|
2022-11-10 16:44:58 +05:30
|
|
|
#include <QRegularExpression>
|
2022-04-03 03:03:50 +05:30
|
|
|
#include <memory>
|
2022-03-03 05:47:10 +05:30
|
|
|
|
2022-03-08 03:59:59 +05:30
|
|
|
#include "minecraft/MinecraftInstance.h"
|
|
|
|
#include "minecraft/PackProfile.h"
|
2022-03-03 05:47:10 +05:30
|
|
|
#include "ui/dialogs/ModDownloadDialog.h"
|
2022-07-15 06:53:41 +05:30
|
|
|
#include "ui/widgets/ProjectItem.h"
|
2023-01-07 01:56:26 +05:30
|
|
|
#include "Markdown.h"
|
2022-08-21 19:20:10 +05:30
|
|
|
|
2022-03-06 22:24:05 +05:30
|
|
|
ModPage::ModPage(ModDownloadDialog* dialog, BaseInstance* instance, ModAPI* api)
|
2022-04-03 03:03:50 +05:30
|
|
|
: QWidget(dialog)
|
|
|
|
, m_instance(instance)
|
|
|
|
, ui(new Ui::ModPage)
|
|
|
|
, dialog(dialog)
|
2022-07-15 21:48:12 +05:30
|
|
|
, m_fetch_progress(this, false)
|
2022-04-03 03:03:50 +05:30
|
|
|
, api(api)
|
2022-03-03 05:47:10 +05:30
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2022-07-15 20:27:27 +05:30
|
|
|
|
2022-03-03 05:47:10 +05:30
|
|
|
connect(ui->searchButton, &QPushButton::clicked, this, &ModPage::triggerSearch);
|
2022-04-03 03:03:50 +05:30
|
|
|
connect(ui->modFilterButton, &QPushButton::clicked, this, &ModPage::filterMods);
|
2022-09-25 02:07:51 +05:30
|
|
|
connect(ui->packView, &QListView::doubleClicked, this, &ModPage::onModSelected);
|
2022-07-15 20:27:27 +05:30
|
|
|
|
|
|
|
m_search_timer.setTimerType(Qt::TimerType::CoarseTimer);
|
|
|
|
m_search_timer.setSingleShot(true);
|
|
|
|
|
|
|
|
connect(&m_search_timer, &QTimer::timeout, this, &ModPage::triggerSearch);
|
|
|
|
|
2022-03-03 05:47:10 +05:30
|
|
|
ui->searchEdit->installEventFilter(this);
|
|
|
|
|
|
|
|
ui->versionSelectionBox->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
|
|
|
ui->versionSelectionBox->view()->parentWidget()->setMaximumHeight(300);
|
|
|
|
|
2022-07-15 21:48:12 +05:30
|
|
|
m_fetch_progress.hideIfInactive(true);
|
|
|
|
m_fetch_progress.setFixedHeight(24);
|
|
|
|
m_fetch_progress.progressFormat("");
|
|
|
|
|
|
|
|
ui->gridLayout_3->addWidget(&m_fetch_progress, 0, 0, 1, ui->gridLayout_3->columnCount());
|
2022-07-15 06:53:41 +05:30
|
|
|
|
|
|
|
ui->packView->setItemDelegate(new ProjectItemDelegate(this));
|
2022-07-15 18:04:11 +05:30
|
|
|
ui->packView->installEventFilter(this);
|
2022-11-01 22:28:22 +05:30
|
|
|
|
|
|
|
connect(ui->packDescription, &QTextBrowser::anchorClicked, this, &ModPage::openUrl);
|
2022-03-03 05:47:10 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
ModPage::~ModPage()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2022-08-21 19:20:10 +05:30
|
|
|
void ModPage::setFilterWidget(unique_qobject_ptr<ModFilterWidget>& widget)
|
|
|
|
{
|
|
|
|
if (m_filter_widget)
|
|
|
|
disconnect(m_filter_widget.get(), nullptr, nullptr, nullptr);
|
|
|
|
|
|
|
|
m_filter_widget.swap(widget);
|
|
|
|
|
|
|
|
ui->gridLayout_3->addWidget(m_filter_widget.get(), 0, 0, 1, ui->gridLayout_3->columnCount());
|
|
|
|
|
|
|
|
m_filter_widget->setInstance(static_cast<MinecraftInstance*>(m_instance));
|
|
|
|
m_filter = m_filter_widget->getFilter();
|
|
|
|
|
|
|
|
connect(m_filter_widget.get(), &ModFilterWidget::filterChanged, this, [&]{
|
|
|
|
ui->searchButton->setStyleSheet("text-decoration: underline");
|
|
|
|
});
|
|
|
|
connect(m_filter_widget.get(), &ModFilterWidget::filterUnchanged, this, [&]{
|
|
|
|
ui->searchButton->setStyleSheet("text-decoration: none");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-03-08 03:59:59 +05:30
|
|
|
|
|
|
|
/******** Qt things ********/
|
|
|
|
|
2022-03-03 05:47:10 +05:30
|
|
|
void ModPage::openedImpl()
|
|
|
|
{
|
|
|
|
updateSelectionButton();
|
|
|
|
triggerSearch();
|
|
|
|
}
|
|
|
|
|
2022-03-08 19:42:35 +05:30
|
|
|
auto ModPage::eventFilter(QObject* watched, QEvent* event) -> bool
|
2022-03-03 05:47:10 +05:30
|
|
|
{
|
|
|
|
if (watched == ui->searchEdit && event->type() == QEvent::KeyPress) {
|
2022-03-08 19:42:35 +05:30
|
|
|
auto* keyEvent = dynamic_cast<QKeyEvent*>(event);
|
2022-03-03 05:47:10 +05:30
|
|
|
if (keyEvent->key() == Qt::Key_Return) {
|
|
|
|
triggerSearch();
|
2022-07-15 18:04:11 +05:30
|
|
|
keyEvent->accept();
|
|
|
|
return true;
|
2022-07-15 20:27:27 +05:30
|
|
|
} else {
|
|
|
|
if (m_search_timer.isActive())
|
|
|
|
m_search_timer.stop();
|
|
|
|
|
|
|
|
m_search_timer.start(350);
|
2022-07-15 18:04:11 +05:30
|
|
|
}
|
|
|
|
} else if (watched == ui->packView && event->type() == QEvent::KeyPress) {
|
|
|
|
auto* keyEvent = dynamic_cast<QKeyEvent*>(event);
|
|
|
|
if (keyEvent->key() == Qt::Key_Return) {
|
|
|
|
onModSelected();
|
|
|
|
|
|
|
|
// To have the 'select mod' button outlined instead of the 'review and confirm' one
|
|
|
|
ui->modSelectionButton->setFocus(Qt::FocusReason::ShortcutFocusReason);
|
|
|
|
ui->packView->setFocus(Qt::FocusReason::NoFocusReason);
|
|
|
|
|
2022-03-03 05:47:10 +05:30
|
|
|
keyEvent->accept();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QWidget::eventFilter(watched, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-08 03:59:59 +05:30
|
|
|
/******** Callbacks to events in the UI (set up in the derived classes) ********/
|
2022-03-03 05:47:10 +05:30
|
|
|
|
2022-04-03 03:03:50 +05:30
|
|
|
void ModPage::filterMods()
|
|
|
|
{
|
2022-08-21 19:20:10 +05:30
|
|
|
m_filter_widget->setHidden(!m_filter_widget->isHidden());
|
2022-04-03 03:03:50 +05:30
|
|
|
}
|
|
|
|
|
2022-03-03 05:47:10 +05:30
|
|
|
void ModPage::triggerSearch()
|
|
|
|
{
|
2022-08-21 19:20:10 +05:30
|
|
|
auto changed = m_filter_widget->changed();
|
|
|
|
m_filter = m_filter_widget->getFilter();
|
2022-11-01 22:28:22 +05:30
|
|
|
|
|
|
|
if (changed) {
|
2022-04-14 18:57:03 +05:30
|
|
|
ui->packView->clearSelection();
|
|
|
|
ui->packDescription->clear();
|
|
|
|
ui->versionSelectionBox->clear();
|
|
|
|
updateSelectionButton();
|
|
|
|
}
|
|
|
|
|
2022-07-15 19:50:08 +05:30
|
|
|
listModel->searchWithTerm(getSearchTerm(), ui->sortByBox->currentIndex(), changed);
|
2022-07-15 21:48:12 +05:30
|
|
|
m_fetch_progress.watch(listModel->activeJob());
|
2022-07-15 19:50:08 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
QString ModPage::getSearchTerm() const
|
|
|
|
{
|
|
|
|
return ui->searchEdit->text();
|
|
|
|
}
|
|
|
|
void ModPage::setSearchTerm(QString term)
|
|
|
|
{
|
|
|
|
ui->searchEdit->setText(term);
|
2022-03-03 05:47:10 +05:30
|
|
|
}
|
|
|
|
|
2022-07-19 03:47:44 +05:30
|
|
|
void ModPage::onSelectionChanged(QModelIndex curr, QModelIndex prev)
|
2022-03-03 05:47:10 +05:30
|
|
|
{
|
|
|
|
ui->versionSelectionBox->clear();
|
|
|
|
|
2022-07-19 03:47:44 +05:30
|
|
|
if (!curr.isValid()) { return; }
|
2022-03-03 05:47:10 +05:30
|
|
|
|
2022-07-19 03:47:44 +05:30
|
|
|
current = listModel->data(curr, Qt::UserRole).value<ModPlatform::IndexedPack>();
|
2022-03-03 05:47:10 +05:30
|
|
|
|
|
|
|
if (!current.versionsLoaded) {
|
|
|
|
qDebug() << QString("Loading %1 mod versions").arg(debugName());
|
|
|
|
|
|
|
|
ui->modSelectionButton->setText(tr("Loading versions..."));
|
|
|
|
ui->modSelectionButton->setEnabled(false);
|
|
|
|
|
2022-07-19 03:58:46 +05:30
|
|
|
listModel->requestModVersions(current, curr);
|
2022-03-03 05:47:10 +05:30
|
|
|
} else {
|
|
|
|
for (int i = 0; i < current.versions.size(); i++) {
|
|
|
|
ui->versionSelectionBox->addItem(current.versions[i].version, QVariant(i));
|
|
|
|
}
|
2022-03-25 02:54:51 +05:30
|
|
|
if (ui->versionSelectionBox->count() == 0) { ui->versionSelectionBox->addItem(tr("No valid version found."), QVariant(-1)); }
|
2022-03-03 05:47:10 +05:30
|
|
|
|
|
|
|
updateSelectionButton();
|
|
|
|
}
|
2022-05-24 18:08:48 +05:30
|
|
|
|
|
|
|
if(!current.extraDataLoaded){
|
|
|
|
qDebug() << QString("Loading %1 mod info").arg(debugName());
|
2022-07-19 03:47:44 +05:30
|
|
|
|
|
|
|
listModel->requestModInfo(current, curr);
|
2022-05-24 18:08:48 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
updateUi();
|
2022-03-03 05:47:10 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void ModPage::onVersionSelectionChanged(QString data)
|
|
|
|
{
|
|
|
|
if (data.isNull() || data.isEmpty()) {
|
|
|
|
selectedVersion = -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
selectedVersion = ui->versionSelectionBox->currentData().toInt();
|
|
|
|
updateSelectionButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModPage::onModSelected()
|
|
|
|
{
|
2022-07-15 18:04:11 +05:30
|
|
|
if (selectedVersion < 0)
|
|
|
|
return;
|
|
|
|
|
2022-03-03 05:47:10 +05:30
|
|
|
auto& version = current.versions[selectedVersion];
|
|
|
|
if (dialog->isModSelected(current.name, version.fileName)) {
|
|
|
|
dialog->removeSelectedMod(current.name);
|
|
|
|
} else {
|
2022-06-04 19:00:34 +05:30
|
|
|
bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
|
|
|
|
dialog->addSelectedMod(current.name, new ModDownloadTask(current, version, dialog->mods, is_indexed));
|
2022-03-03 05:47:10 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
updateSelectionButton();
|
2022-08-01 00:31:47 +05:30
|
|
|
|
|
|
|
/* Force redraw on the mods list when the selection changes */
|
|
|
|
ui->packView->adjustSize();
|
2022-03-03 05:47:10 +05:30
|
|
|
}
|
2022-03-08 03:59:59 +05:30
|
|
|
|
2022-11-10 16:44:58 +05:30
|
|
|
static const QRegularExpression modrinth(QRegularExpression::anchoredPattern("(?:www\\.)?modrinth\\.com\\/mod\\/([^\\/]+)\\/?"));
|
|
|
|
static const QRegularExpression curseForge(QRegularExpression::anchoredPattern("(?:www\\.)?curseforge\\.com\\/minecraft\\/mc-mods\\/([^\\/]+)\\/?"));
|
|
|
|
static const QRegularExpression curseForgeOld(QRegularExpression::anchoredPattern("minecraft\\.curseforge\\.com\\/projects\\/([^\\/]+)\\/?"));
|
|
|
|
|
2022-11-01 22:28:22 +05:30
|
|
|
void ModPage::openUrl(const QUrl& url)
|
|
|
|
{
|
|
|
|
// do not allow other url schemes for security reasons
|
|
|
|
if (!(url.scheme() == "http" || url.scheme() == "https")) {
|
|
|
|
qWarning() << "Unsupported scheme" << url.scheme();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// detect mod URLs and search instead
|
2022-11-06 15:38:54 +05:30
|
|
|
|
|
|
|
const QString address = url.host() + url.path();
|
|
|
|
QRegularExpressionMatch match;
|
2022-11-15 01:50:38 +05:30
|
|
|
QString page;
|
2022-11-01 22:28:22 +05:30
|
|
|
|
2022-11-10 16:44:58 +05:30
|
|
|
match = modrinth.match(address);
|
|
|
|
if (match.hasMatch())
|
2022-11-01 22:28:22 +05:30
|
|
|
page = "modrinth";
|
2022-11-10 16:44:58 +05:30
|
|
|
else if (APPLICATION->capabilities() & Application::SupportsFlame) {
|
|
|
|
match = curseForge.match(address);
|
|
|
|
if (!match.hasMatch())
|
|
|
|
match = curseForgeOld.match(address);
|
|
|
|
|
|
|
|
if (match.hasMatch())
|
|
|
|
page = "curseforge";
|
|
|
|
}
|
2022-11-01 22:28:22 +05:30
|
|
|
|
2022-11-15 01:50:38 +05:30
|
|
|
if (!page.isNull()) {
|
2022-11-06 15:38:54 +05:30
|
|
|
const QString slug = match.captured(1);
|
2022-11-01 22:28:22 +05:30
|
|
|
|
2022-11-06 15:38:54 +05:30
|
|
|
// ensure the user isn't opening the same mod
|
|
|
|
if (slug != current.slug) {
|
2022-11-01 22:28:22 +05:30
|
|
|
dialog->selectPage(page);
|
2022-11-01 22:49:54 +05:30
|
|
|
|
2022-11-01 23:42:27 +05:30
|
|
|
ModPage* newPage = dialog->getSelectedPage();
|
2022-11-02 15:29:52 +05:30
|
|
|
|
2022-11-02 15:01:39 +05:30
|
|
|
QLineEdit* searchEdit = newPage->ui->searchEdit;
|
2022-11-02 15:29:52 +05:30
|
|
|
ModPlatform::ListModel* model = newPage->listModel;
|
|
|
|
QListView* view = newPage->ui->packView;
|
|
|
|
|
|
|
|
auto jump = [url, slug, model, view] {
|
|
|
|
for (int row = 0; row < model->rowCount({}); row++) {
|
2022-11-06 15:38:54 +05:30
|
|
|
const QModelIndex index = model->index(row);
|
|
|
|
const auto pack = model->data(index, Qt::UserRole).value<ModPlatform::IndexedPack>();
|
2022-11-02 15:01:39 +05:30
|
|
|
|
2022-11-02 15:29:52 +05:30
|
|
|
if (pack.slug == slug) {
|
|
|
|
view->setCurrentIndex(index);
|
|
|
|
return;
|
2022-11-01 23:55:54 +05:30
|
|
|
}
|
2022-11-02 15:29:52 +05:30
|
|
|
}
|
2022-11-02 00:10:12 +05:30
|
|
|
|
2022-11-02 15:29:52 +05:30
|
|
|
// The final fallback.
|
|
|
|
QDesktopServices::openUrl(url);
|
|
|
|
};
|
2022-11-01 22:49:54 +05:30
|
|
|
|
2022-11-02 15:29:52 +05:30
|
|
|
searchEdit->setText(slug);
|
|
|
|
newPage->triggerSearch();
|
|
|
|
|
2022-11-06 15:38:54 +05:30
|
|
|
if (model->activeJob())
|
2022-11-02 15:29:52 +05:30
|
|
|
connect(model->activeJob(), &Task::finished, jump);
|
2022-11-06 15:38:54 +05:30
|
|
|
else
|
|
|
|
jump();
|
2022-11-02 15:29:52 +05:30
|
|
|
|
|
|
|
return;
|
2022-11-01 22:28:22 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// open in the user's web browser
|
|
|
|
QDesktopServices::openUrl(url);
|
|
|
|
}
|
|
|
|
|
2022-03-08 03:59:59 +05:30
|
|
|
/******** Make changes to the UI ********/
|
|
|
|
|
2022-03-25 02:54:51 +05:30
|
|
|
void ModPage::retranslate()
|
|
|
|
{
|
2022-04-15 01:25:03 +05:30
|
|
|
ui->retranslateUi(this);
|
2022-03-25 02:54:51 +05:30
|
|
|
}
|
|
|
|
|
2022-04-03 18:51:48 +05:30
|
|
|
void ModPage::updateModVersions(int prev_count)
|
2022-03-08 03:59:59 +05:30
|
|
|
{
|
2022-03-08 19:42:35 +05:30
|
|
|
auto packProfile = (dynamic_cast<MinecraftInstance*>(m_instance))->getPackProfile();
|
2022-03-08 03:59:59 +05:30
|
|
|
|
|
|
|
QString mcVersion = packProfile->getComponentVersion("net.minecraft");
|
2022-02-21 01:25:26 +05:30
|
|
|
|
2022-03-08 03:59:59 +05:30
|
|
|
for (int i = 0; i < current.versions.size(); i++) {
|
|
|
|
auto version = current.versions[i];
|
2022-04-03 03:03:50 +05:30
|
|
|
bool valid = false;
|
|
|
|
for(auto& mcVer : m_filter->versions){
|
2022-04-18 16:42:42 +05:30
|
|
|
//NOTE: Flame doesn't care about loader, so passing it changes nothing.
|
2022-05-19 12:10:28 +05:30
|
|
|
if (validateVersion(version, mcVer.toString(), packProfile->getModLoaders())) {
|
2022-04-03 03:03:50 +05:30
|
|
|
valid = true;
|
|
|
|
break;
|
|
|
|
}
|
2022-03-08 03:59:59 +05:30
|
|
|
}
|
2022-10-12 18:56:14 +05:30
|
|
|
|
|
|
|
// Only add the version if it's valid or using the 'Any' filter, but never if the version is opted out
|
|
|
|
if ((valid || m_filter->versions.empty()) && !optedOut(version))
|
2022-04-03 03:03:50 +05:30
|
|
|
ui->versionSelectionBox->addItem(version.version, QVariant(i));
|
2022-03-08 03:59:59 +05:30
|
|
|
}
|
2022-11-01 22:28:22 +05:30
|
|
|
if (ui->versionSelectionBox->count() == 0 && prev_count != 0) {
|
|
|
|
ui->versionSelectionBox->addItem(tr("No valid version found!"), QVariant(-1));
|
2022-04-03 18:51:48 +05:30
|
|
|
ui->modSelectionButton->setText(tr("Cannot select invalid version :("));
|
|
|
|
}
|
2022-03-08 03:59:59 +05:30
|
|
|
|
|
|
|
updateSelectionButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ModPage::updateSelectionButton()
|
|
|
|
{
|
|
|
|
if (!isOpened || selectedVersion < 0) {
|
|
|
|
ui->modSelectionButton->setEnabled(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->modSelectionButton->setEnabled(true);
|
|
|
|
auto& version = current.versions[selectedVersion];
|
|
|
|
if (!dialog->isModSelected(current.name, version.fileName)) {
|
|
|
|
ui->modSelectionButton->setText(tr("Select mod for download"));
|
|
|
|
} else {
|
|
|
|
ui->modSelectionButton->setText(tr("Deselect mod for download"));
|
|
|
|
}
|
|
|
|
}
|
2022-05-24 18:08:48 +05:30
|
|
|
|
|
|
|
void ModPage::updateUi()
|
|
|
|
{
|
|
|
|
QString text = "";
|
|
|
|
QString name = current.name;
|
|
|
|
|
|
|
|
if (current.websiteUrl.isEmpty())
|
|
|
|
text = name;
|
|
|
|
else
|
|
|
|
text = "<a href=\"" + current.websiteUrl + "\">" + name + "</a>";
|
|
|
|
|
|
|
|
if (!current.authors.empty()) {
|
|
|
|
auto authorToStr = [](ModPlatform::ModpackAuthor& author) -> QString {
|
|
|
|
if (author.url.isEmpty()) { return author.name; }
|
|
|
|
return QString("<a href=\"%1\">%2</a>").arg(author.url, author.name);
|
|
|
|
};
|
|
|
|
QStringList authorStrs;
|
|
|
|
for (auto& author : current.authors) {
|
|
|
|
authorStrs.push_back(authorToStr(author));
|
|
|
|
}
|
|
|
|
text += "<br>" + tr(" by ") + authorStrs.join(", ");
|
|
|
|
}
|
|
|
|
|
2022-11-01 22:28:22 +05:30
|
|
|
if (current.extraDataLoaded) {
|
2022-05-24 20:28:11 +05:30
|
|
|
if (!current.extraData.donate.isEmpty()) {
|
|
|
|
text += "<br><br>" + tr("Donate information: ");
|
|
|
|
auto donateToStr = [](ModPlatform::DonationData& donate) -> QString {
|
|
|
|
return QString("<a href=\"%1\">%2</a>").arg(donate.url, donate.platform);
|
|
|
|
};
|
|
|
|
QStringList donates;
|
|
|
|
for (auto& donate : current.extraData.donate) {
|
|
|
|
donates.append(donateToStr(donate));
|
|
|
|
}
|
|
|
|
text += donates.join(", ");
|
2022-05-24 18:08:48 +05:30
|
|
|
}
|
2022-05-24 20:28:11 +05:30
|
|
|
|
|
|
|
if (!current.extraData.issuesUrl.isEmpty()
|
|
|
|
|| !current.extraData.sourceUrl.isEmpty()
|
|
|
|
|| !current.extraData.wikiUrl.isEmpty()
|
|
|
|
|| !current.extraData.discordUrl.isEmpty()) {
|
|
|
|
text += "<br><br>" + tr("External links:") + "<br>";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!current.extraData.issuesUrl.isEmpty())
|
|
|
|
text += "- " + tr("Issues: <a href=%1>%1</a>").arg(current.extraData.issuesUrl) + "<br>";
|
|
|
|
if (!current.extraData.wikiUrl.isEmpty())
|
|
|
|
text += "- " + tr("Wiki: <a href=%1>%1</a>").arg(current.extraData.wikiUrl) + "<br>";
|
|
|
|
if (!current.extraData.sourceUrl.isEmpty())
|
|
|
|
text += "- " + tr("Source code: <a href=%1>%1</a>").arg(current.extraData.sourceUrl) + "<br>";
|
|
|
|
if (!current.extraData.discordUrl.isEmpty())
|
|
|
|
text += "- " + tr("Discord: <a href=%1>%1</a>").arg(current.extraData.discordUrl) + "<br>";
|
2022-05-24 18:08:48 +05:30
|
|
|
}
|
|
|
|
|
2022-05-24 20:28:11 +05:30
|
|
|
text += "<hr>";
|
2022-05-24 18:08:48 +05:30
|
|
|
|
2023-01-07 01:56:26 +05:30
|
|
|
ui->packDescription->setHtml(text + (current.extraData.body.isEmpty() ? current.description : markdownToHTML(current.extraData.body)));
|
2022-10-11 22:49:29 +05:30
|
|
|
ui->packDescription->flush();
|
2022-05-24 18:08:48 +05:30
|
|
|
}
|