2023-01-29 23:40:55 +00:00
|
|
|
// SPDX-FileCopyrightText: 2023 flowln <flowlnlnln@gmail.com>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
|
2022-12-30 17:06:07 +00:00
|
|
|
#include "ShaderPackPage.h"
|
|
|
|
#include "ui_ResourcePage.h"
|
|
|
|
|
|
|
|
#include "ShaderPackModel.h"
|
|
|
|
|
|
|
|
#include "ui/dialogs/ResourceDownloadDialog.h"
|
|
|
|
|
|
|
|
#include <QRegularExpression>
|
|
|
|
|
|
|
|
namespace ResourceDownload {
|
|
|
|
|
2023-06-02 22:04:06 +01:00
|
|
|
ShaderPackResourcePage::ShaderPackResourcePage(ShaderPackDownloadDialog* dialog, BaseInstance& instance) : ResourcePage(dialog, instance)
|
2022-12-30 17:06:07 +00:00
|
|
|
{
|
|
|
|
connect(m_ui->searchButton, &QPushButton::clicked, this, &ShaderPackResourcePage::triggerSearch);
|
|
|
|
connect(m_ui->packView, &QListView::doubleClicked, this, &ShaderPackResourcePage::onResourceSelected);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******** Callbacks to events in the UI (set up in the derived classes) ********/
|
|
|
|
|
|
|
|
void ShaderPackResourcePage::triggerSearch()
|
|
|
|
{
|
|
|
|
m_ui->packView->clearSelection();
|
|
|
|
m_ui->packDescription->clear();
|
|
|
|
m_ui->versionSelectionBox->clear();
|
|
|
|
|
|
|
|
updateSelectionButton();
|
|
|
|
|
|
|
|
static_cast<ShaderPackResourceModel*>(m_model)->searchWithTerm(getSearchTerm(), m_ui->sortByBox->currentData().toUInt());
|
|
|
|
m_fetch_progress.watch(m_model->activeSearchJob().get());
|
|
|
|
}
|
|
|
|
|
|
|
|
QMap<QString, QString> ShaderPackResourcePage::urlHandlers() const
|
|
|
|
{
|
|
|
|
QMap<QString, QString> map;
|
|
|
|
map.insert(QRegularExpression::anchoredPattern("(?:www\\.)?modrinth\\.com\\/shaders\\/([^\\/]+)\\/?"), "modrinth");
|
2023-06-02 22:04:06 +01:00
|
|
|
map.insert(QRegularExpression::anchoredPattern("(?:www\\.)?curseforge\\.com\\/minecraft\\/customization\\/([^\\/]+)\\/?"),
|
|
|
|
"curseforge");
|
2022-12-30 17:06:07 +00:00
|
|
|
map.insert(QRegularExpression::anchoredPattern("minecraft\\.curseforge\\.com\\/projects\\/([^\\/]+)\\/?"), "curseforge");
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
2023-06-02 22:04:06 +01:00
|
|
|
void ShaderPackResourcePage::addResourceToPage(ModPlatform::IndexedPack::Ptr pack,
|
|
|
|
ModPlatform::IndexedVersion& version,
|
|
|
|
const std::shared_ptr<ResourceFolderModel> base_model)
|
2022-12-30 17:06:07 +00:00
|
|
|
{
|
2023-06-02 22:04:06 +01:00
|
|
|
QString custom_target_folder;
|
2022-12-30 17:06:07 +00:00
|
|
|
if (version.loaders.contains(QStringLiteral("canvas")))
|
2023-06-02 22:04:06 +01:00
|
|
|
custom_target_folder = QStringLiteral("resourcepacks");
|
|
|
|
m_model->addPack(pack, version, base_model, false, custom_target_folder);
|
2022-12-30 17:06:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace ResourceDownload
|