2023-01-23 19:33:55 +05:30
|
|
|
// SPDX-FileCopyrightText: 2023 flowln <flowlnlnln@gmail.com>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-only AND Apache-2.0
|
2022-06-12 17:20:58 +05:30
|
|
|
/*
|
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-11-25 17:53:46 +05:30
|
|
|
#include "ui_ResourcePage.h"
|
2022-03-03 05:47:10 +05:30
|
|
|
|
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-11-25 17:53:46 +05:30
|
|
|
|
2022-04-03 03:03:50 +05:30
|
|
|
#include <memory>
|
2022-03-03 05:47:10 +05:30
|
|
|
|
2022-11-25 17:53:46 +05:30
|
|
|
#include "Application.h"
|
|
|
|
#include "ResourceDownloadTask.h"
|
|
|
|
|
2022-03-08 03:59:59 +05:30
|
|
|
#include "minecraft/MinecraftInstance.h"
|
|
|
|
#include "minecraft/PackProfile.h"
|
2022-07-15 06:53:41 +05:30
|
|
|
|
2022-12-17 06:14:21 +05:30
|
|
|
#include "ui/dialogs/ResourceDownloadDialog.h"
|
2022-11-01 22:28:22 +05:30
|
|
|
|
2022-12-17 03:33:52 +05:30
|
|
|
namespace ResourceDownload {
|
|
|
|
|
2023-06-03 02:34:06 +05:30
|
|
|
ModPage::ModPage(ModDownloadDialog* dialog, BaseInstance& instance) : ResourcePage(dialog, instance)
|
2022-03-03 05:47:10 +05:30
|
|
|
{
|
2022-11-25 17:53:46 +05:30
|
|
|
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 05:47:10 +05:30
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2022-11-25 17:53:46 +05:30
|
|
|
m_ui->gridLayout_3->addWidget(m_filter_widget.get(), 0, 0, 1, m_ui->gridLayout_3->columnCount());
|
2022-08-21 19:20:10 +05:30
|
|
|
|
2022-11-25 17:53:46 +05:30
|
|
|
m_filter_widget->setInstance(&static_cast<MinecraftInstance&>(m_base_instance));
|
2022-08-21 19:20:10 +05:30
|
|
|
m_filter = m_filter_widget->getFilter();
|
|
|
|
|
2023-06-03 02:34:06 +05:30
|
|
|
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 19:20:10 +05:30
|
|
|
}
|
|
|
|
|
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-11-25 17:53:46 +05:30
|
|
|
m_ui->packView->clearSelection();
|
|
|
|
m_ui->packDescription->clear();
|
|
|
|
m_ui->versionSelectionBox->clear();
|
2022-04-14 18:57:03 +05:30
|
|
|
updateSelectionButton();
|
|
|
|
}
|
|
|
|
|
2022-12-20 20:45:17 +05:30
|
|
|
static_cast<ModModel*>(m_model)->searchWithTerm(getSearchTerm(), m_ui->sortByBox->currentData().toUInt(), changed);
|
2022-12-21 01:44:17 +05:30
|
|
|
m_fetch_progress.watch(m_model->activeSearchJob().get());
|
2022-03-03 05:47:10 +05:30
|
|
|
}
|
|
|
|
|
2022-11-25 17:53:46 +05:30
|
|
|
QMap<QString, QString> ModPage::urlHandlers() const
|
2022-03-03 05:47:10 +05:30
|
|
|
{
|
2022-11-25 17:53:46 +05:30
|
|
|
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 22:28:22 +05:30
|
|
|
}
|
|
|
|
|
2022-03-08 03:59:59 +05:30
|
|
|
/******** Make changes to the UI ********/
|
|
|
|
|
2022-11-25 17:53:46 +05:30
|
|
|
void ModPage::updateVersionList()
|
2022-03-08 03:59:59 +05:30
|
|
|
{
|
2022-11-25 17:53:46 +05:30
|
|
|
m_ui->versionSelectionBox->clear();
|
|
|
|
auto packProfile = (dynamic_cast<MinecraftInstance&>(m_base_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-11-25 17:53:46 +05:30
|
|
|
auto current_pack = getCurrentPack();
|
2023-06-03 02:34:06 +05:30
|
|
|
for (int i = 0; i < current_pack->versions.size(); i++) {
|
|
|
|
auto version = current_pack->versions[i];
|
2022-04-03 03:03:50 +05:30
|
|
|
bool valid = false;
|
2023-06-03 02:34:06 +05:30
|
|
|
for (auto& mcVer : m_filter->versions) {
|
|
|
|
// 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-11-25 17:53:46 +05:30
|
|
|
m_ui->versionSelectionBox->addItem(version.version, QVariant(i));
|
2022-03-08 03:59:59 +05:30
|
|
|
}
|
2022-11-25 17:53:46 +05:30
|
|
|
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 18:51:48 +05:30
|
|
|
}
|
2022-03-08 03:59:59 +05:30
|
|
|
|
|
|
|
updateSelectionButton();
|
|
|
|
}
|
|
|
|
|
2023-06-03 02:34:06 +05:30
|
|
|
void ModPage::addResourceToPage(ModPlatform::IndexedPack::Ptr pack,
|
|
|
|
ModPlatform::IndexedVersion& version,
|
|
|
|
const std::shared_ptr<ResourceFolderModel> base_model)
|
2022-05-24 18:08:48 +05:30
|
|
|
{
|
2022-11-25 17:53:46 +05:30
|
|
|
bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
|
2023-06-03 02:34:06 +05:30
|
|
|
m_model->addPack(pack, version, base_model, is_indexed);
|
2022-05-24 18:08:48 +05:30
|
|
|
}
|
2022-12-17 03:33:52 +05:30
|
|
|
|
|
|
|
} // namespace ResourceDownload
|