2023-01-23 14:03:55 +00:00
|
|
|
// SPDX-FileCopyrightText: 2023 flowln <flowlnlnln@gmail.com>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-only AND Apache-2.0
|
2022-06-12 12:50:58 +01:00
|
|
|
/*
|
2022-11-06 10:08:54 +00:00
|
|
|
* Prism Launcher - Minecraft Launcher
|
2022-06-12 12:50:58 +01:00
|
|
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
2022-11-01 16:58:22 +00:00
|
|
|
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
2022-06-12 12:50:58 +01:00
|
|
|
*
|
|
|
|
* 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 00:17:10 +00:00
|
|
|
#include "ModPage.h"
|
2022-11-25 12:23:46 +00:00
|
|
|
#include "ui_ResourcePage.h"
|
2022-03-03 00:17:10 +00:00
|
|
|
|
2022-11-01 16:58:22 +00:00
|
|
|
#include <QDesktopServices>
|
2022-03-03 00:17:10 +00:00
|
|
|
#include <QKeyEvent>
|
2022-11-10 11:14:58 +00:00
|
|
|
#include <QRegularExpression>
|
2022-11-25 12:23:46 +00:00
|
|
|
|
2022-04-02 22:33:50 +01:00
|
|
|
#include <memory>
|
2022-03-03 00:17:10 +00:00
|
|
|
|
2022-11-25 12:23:46 +00:00
|
|
|
#include "Application.h"
|
|
|
|
#include "ResourceDownloadTask.h"
|
|
|
|
|
2022-03-07 22:29:59 +00:00
|
|
|
#include "minecraft/MinecraftInstance.h"
|
|
|
|
#include "minecraft/PackProfile.h"
|
2022-07-15 02:23:41 +01:00
|
|
|
|
2022-12-17 00:44:21 +00:00
|
|
|
#include "ui/dialogs/ResourceDownloadDialog.h"
|
2022-11-01 16:58:22 +00:00
|
|
|
|
2022-12-16 22:03:52 +00:00
|
|
|
namespace ResourceDownload {
|
|
|
|
|
2023-06-02 22:04:06 +01:00
|
|
|
ModPage::ModPage(ModDownloadDialog* dialog, BaseInstance& instance) : ResourcePage(dialog, instance)
|
2022-03-03 00:17:10 +00:00
|
|
|
{
|
2022-11-25 12:23:46 +00:00
|
|
|
connect(m_ui->searchButton, &QPushButton::clicked, this, &ModPage::triggerSearch);
|
|
|
|
connect(m_ui->resourceFilterButton, &QPushButton::clicked, this, &ModPage::filterMods);
|
|
|
|
connect(m_ui->packView, &QListView::doubleClicked, this, &ModPage::onResourceSelected);
|
2022-03-03 00:17:10 +00:00
|
|
|
}
|
|
|
|
|
2022-08-21 14:50:10 +01:00
|
|
|
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);
|
|
|
|
|
2022-11-25 12:23:46 +00:00
|
|
|
m_ui->gridLayout_3->addWidget(m_filter_widget.get(), 0, 0, 1, m_ui->gridLayout_3->columnCount());
|
2022-08-21 14:50:10 +01:00
|
|
|
|
2022-11-25 12:23:46 +00:00
|
|
|
m_filter_widget->setInstance(&static_cast<MinecraftInstance&>(m_base_instance));
|
2022-08-21 14:50:10 +01:00
|
|
|
m_filter = m_filter_widget->getFilter();
|
|
|
|
|
2023-06-02 22:04:06 +01:00
|
|
|
connect(m_filter_widget.get(), &ModFilterWidget::filterChanged, this,
|
|
|
|
[&] { m_ui->searchButton->setStyleSheet("text-decoration: underline"); });
|
|
|
|
connect(m_filter_widget.get(), &ModFilterWidget::filterUnchanged, this,
|
|
|
|
[&] { m_ui->searchButton->setStyleSheet("text-decoration: none"); });
|
2022-08-21 14:50:10 +01:00
|
|
|
}
|
|
|
|
|
2022-03-07 22:29:59 +00:00
|
|
|
/******** Callbacks to events in the UI (set up in the derived classes) ********/
|
2022-03-03 00:17:10 +00:00
|
|
|
|
2022-04-02 22:33:50 +01:00
|
|
|
void ModPage::filterMods()
|
|
|
|
{
|
2022-08-21 14:50:10 +01:00
|
|
|
m_filter_widget->setHidden(!m_filter_widget->isHidden());
|
2022-04-02 22:33:50 +01:00
|
|
|
}
|
|
|
|
|
2022-03-03 00:17:10 +00:00
|
|
|
void ModPage::triggerSearch()
|
|
|
|
{
|
2022-08-21 14:50:10 +01:00
|
|
|
m_filter = m_filter_widget->getFilter();
|
2023-06-19 11:09:37 +01:00
|
|
|
m_ui->packView->clearSelection();
|
|
|
|
m_ui->packDescription->clear();
|
|
|
|
m_ui->versionSelectionBox->clear();
|
|
|
|
updateSelectionButton();
|
2022-11-01 16:58:22 +00:00
|
|
|
|
2023-06-19 11:09:37 +01:00
|
|
|
static_cast<ModModel*>(m_model)->searchWithTerm(getSearchTerm(), m_ui->sortByBox->currentData().toUInt(), m_filter_widget->changed());
|
2022-12-20 20:14:17 +00:00
|
|
|
m_fetch_progress.watch(m_model->activeSearchJob().get());
|
2022-03-03 00:17:10 +00:00
|
|
|
}
|
|
|
|
|
2022-11-25 12:23:46 +00:00
|
|
|
QMap<QString, QString> ModPage::urlHandlers() const
|
2022-03-03 00:17:10 +00:00
|
|
|
{
|
2022-11-25 12:23:46 +00:00
|
|
|
QMap<QString, QString> map;
|
|
|
|
map.insert(QRegularExpression::anchoredPattern("(?:www\\.)?modrinth\\.com\\/mod\\/([^\\/]+)\\/?"), "modrinth");
|
|
|
|
map.insert(QRegularExpression::anchoredPattern("(?:www\\.)?curseforge\\.com\\/minecraft\\/mc-mods\\/([^\\/]+)\\/?"), "curseforge");
|
|
|
|
map.insert(QRegularExpression::anchoredPattern("minecraft\\.curseforge\\.com\\/projects\\/([^\\/]+)\\/?"), "curseforge");
|
|
|
|
return map;
|
2022-11-01 16:58:22 +00:00
|
|
|
}
|
|
|
|
|
2022-03-07 22:29:59 +00:00
|
|
|
/******** Make changes to the UI ********/
|
|
|
|
|
2022-11-25 12:23:46 +00:00
|
|
|
void ModPage::updateVersionList()
|
2022-03-07 22:29:59 +00:00
|
|
|
{
|
2022-11-25 12:23:46 +00:00
|
|
|
m_ui->versionSelectionBox->clear();
|
|
|
|
auto packProfile = (dynamic_cast<MinecraftInstance&>(m_base_instance)).getPackProfile();
|
2022-03-07 22:29:59 +00:00
|
|
|
|
|
|
|
QString mcVersion = packProfile->getComponentVersion("net.minecraft");
|
2022-02-20 19:55:26 +00:00
|
|
|
|
2022-11-25 12:23:46 +00:00
|
|
|
auto current_pack = getCurrentPack();
|
2023-06-19 11:09:37 +01:00
|
|
|
if (!current_pack)
|
|
|
|
return;
|
2023-06-02 22:04:06 +01:00
|
|
|
for (int i = 0; i < current_pack->versions.size(); i++) {
|
|
|
|
auto version = current_pack->versions[i];
|
2022-04-02 22:33:50 +01:00
|
|
|
bool valid = false;
|
2023-06-02 22:04:06 +01:00
|
|
|
for (auto& mcVer : m_filter->versions) {
|
2023-08-23 10:52:51 +01:00
|
|
|
if (validateVersion(version, mcVer.toString(), packProfile->getSupportedModLoaders())) {
|
2022-04-02 22:33:50 +01:00
|
|
|
valid = true;
|
|
|
|
break;
|
|
|
|
}
|
2022-03-07 22:29:59 +00:00
|
|
|
}
|
2022-10-12 14:26:14 +01:00
|
|
|
|
|
|
|
// Only add the version if it's valid or using the 'Any' filter, but never if the version is opted out
|
2023-05-27 00:23:43 +01:00
|
|
|
if ((valid || m_filter->versions.empty()) && !optedOut(version)) {
|
2023-06-28 11:35:42 +01:00
|
|
|
auto release_type = version.version_type.isValid() ? QString(" [%1]").arg(version.version_type.toString()) : "";
|
2023-05-27 00:23:43 +01:00
|
|
|
m_ui->versionSelectionBox->addItem(QString("%1%2").arg(version.version, release_type), QVariant(i));
|
|
|
|
}
|
2022-03-07 22:29:59 +00:00
|
|
|
}
|
2022-11-25 12:23:46 +00:00
|
|
|
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 :("));
|
2022-04-03 14:21:48 +01:00
|
|
|
}
|
2022-03-07 22:29:59 +00:00
|
|
|
|
|
|
|
updateSelectionButton();
|
|
|
|
}
|
|
|
|
|
2023-06-02 22:04:06 +01:00
|
|
|
void ModPage::addResourceToPage(ModPlatform::IndexedPack::Ptr pack,
|
|
|
|
ModPlatform::IndexedVersion& version,
|
|
|
|
const std::shared_ptr<ResourceFolderModel> base_model)
|
2022-05-24 13:38:48 +01:00
|
|
|
{
|
2022-11-25 12:23:46 +00:00
|
|
|
bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
|
2023-06-02 22:04:06 +01:00
|
|
|
m_model->addPack(pack, version, base_model, is_indexed);
|
2022-05-24 13:38:48 +01:00
|
|
|
}
|
2022-12-16 22:03:52 +00:00
|
|
|
|
|
|
|
} // namespace ResourceDownload
|