2022-06-12 12:50:58 +01:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
/*
|
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 {
|
|
|
|
|
2022-11-25 12:23:46 +00: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();
|
|
|
|
|
|
|
|
connect(m_filter_widget.get(), &ModFilterWidget::filterChanged, this, [&]{
|
2022-11-25 12:23:46 +00:00
|
|
|
m_ui->searchButton->setStyleSheet("text-decoration: underline");
|
2022-08-21 14:50:10 +01:00
|
|
|
});
|
|
|
|
connect(m_filter_widget.get(), &ModFilterWidget::filterUnchanged, this, [&]{
|
2022-11-25 12:23:46 +00:00
|
|
|
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
|
|
|
auto changed = m_filter_widget->changed();
|
|
|
|
m_filter = m_filter_widget->getFilter();
|
2022-11-01 16:58:22 +00:00
|
|
|
|
|
|
|
if (changed) {
|
2022-11-25 12:23:46 +00:00
|
|
|
m_ui->packView->clearSelection();
|
|
|
|
m_ui->packDescription->clear();
|
|
|
|
m_ui->versionSelectionBox->clear();
|
2022-04-14 14:27:03 +01:00
|
|
|
updateSelectionButton();
|
|
|
|
}
|
|
|
|
|
2022-12-16 22:03:52 +00:00
|
|
|
static_cast<ModModel*>(m_model)->searchWithTerm(getSearchTerm(), m_ui->sortByBox->currentIndex(), changed);
|
2022-11-25 12:23:46 +00:00
|
|
|
m_fetch_progress.watch(&m_model->activeJob());
|
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();
|
|
|
|
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;
|
|
|
|
for(auto& mcVer : m_filter->versions){
|
2022-04-18 12:12:42 +01:00
|
|
|
//NOTE: Flame doesn't care about loader, so passing it changes nothing.
|
2022-05-19 07:40:28 +01:00
|
|
|
if (validateVersion(version, mcVer.toString(), packProfile->getModLoaders())) {
|
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
|
|
|
|
if ((valid || m_filter->versions.empty()) && !optedOut(version))
|
2022-11-25 12:23:46 +00:00
|
|
|
m_ui->versionSelectionBox->addItem(version.version, 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();
|
|
|
|
}
|
|
|
|
|
2022-11-25 12:23:46 +00:00
|
|
|
void ModPage::addResourceToDialog(ModPlatform::IndexedPack& pack, ModPlatform::IndexedVersion& version)
|
2022-05-24 13:38:48 +01:00
|
|
|
{
|
2022-11-25 12:23:46 +00:00
|
|
|
bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
|
2022-12-18 18:41:46 +00:00
|
|
|
m_parent_dialog->addResource(pack, version, is_indexed);
|
2022-05-24 13:38:48 +01:00
|
|
|
}
|
2022-12-16 22:03:52 +00:00
|
|
|
|
|
|
|
} // namespace ResourceDownload
|