remove extra encapsulations

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2026-02-06 23:17:16 +02:00
parent 323c25d83b
commit e0b8d6e0fc
No known key found for this signature in database
GPG key ID: 55EF5DA53DB36318
28 changed files with 517 additions and 925 deletions

View file

@ -14,12 +14,52 @@
namespace ResourceDownload {
DataPackResourcePage::DataPackResourcePage(DataPackDownloadDialog* dialog, BaseInstance& instance) : ResourcePage(dialog, instance) {}
static ResourceDescriptor prepareDataPackDescriptor()
{
QMap<QString, QString> urlHandlers;
urlHandlers.insert(QRegularExpression::anchoredPattern("(?:www\\.)?modrinth\\.com\\/resourcepack\\/([^\\/]+)\\/?"), "modrinth");
urlHandlers.insert(QRegularExpression::anchoredPattern("(?:www\\.)?curseforge\\.com\\/minecraft\\/texture-packs\\/([^\\/]+)\\/?"),
"curseforge");
urlHandlers.insert(QRegularExpression::anchoredPattern("minecraft\\.curseforge\\.com\\/projects\\/([^\\/]+)\\/?"), "curseforge");
return {
.helpPage = {},
//: The singular version of 'data packs'
.resourceString = QObject::tr("data pack"),
//: The plural version of 'data pack'
.resourcesString = QObject::tr("data packs"),
.supportsFiltering = false,
.isIndexed = true,
.urlHandlers = urlHandlers,
};
}
DataPackResourcePage::DataPackResourcePage(DataPackDownloadDialog* dialog, BaseInstance& instance, ResourceProviderData p, ResourceAPI* api)
: ResourcePage(dialog, instance, prepareDataPackDescriptor(), p)
{
m_model = new DataPackResourceModel(instance, api, debugName(), metaEntryBase());
m_ui->packView->setModel(m_model);
addSortings();
// sometimes Qt just ignores virtual slots and doesn't work as intended it seems,
// so it's best not to connect them in the parent's constructor...
connect(m_model, &ResourceModel::versionListUpdated, this, &ResourcePage::versionListUpdated);
connect(m_model, &ResourceModel::projectInfoUpdated, this, &ResourcePage::updateUi);
connect(m_model, &QAbstractListModel::modelReset, this, &ResourcePage::modelReset);
connect(m_ui->sortByBox, &QComboBox::currentIndexChanged, this, &DataPackResourcePage::triggerSearch);
connect(m_ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &DataPackResourcePage::onSelectionChanged);
connect(m_ui->versionSelectionBox, &QComboBox::currentIndexChanged, this, &DataPackResourcePage::onVersionSelectionChanged);
connect(m_ui->resourceSelectionButton, &QPushButton::clicked, this, &DataPackResourcePage::onResourceSelected);
m_ui->packDescription->setMetaEntry(metaEntryBase());
}
/******** Callbacks to events in the UI (set up in the derived classes) ********/
void DataPackResourcePage::triggerSearch()
{
m_ui->packView->selectionModel()->setCurrentIndex({}, QItemSelectionModel::SelectionFlag::ClearAndSelect);
m_ui->packView->clearSelection();
m_ui->packDescription->clear();
m_ui->versionSelectionBox->clear();
@ -30,14 +70,4 @@ void DataPackResourcePage::triggerSearch()
m_fetchProgress.watch(m_model->activeSearchJob().get());
}
QMap<QString, QString> DataPackResourcePage::urlHandlers() const
{
QMap<QString, QString> map;
map.insert(QRegularExpression::anchoredPattern("(?:www\\.)?modrinth\\.com\\/resourcepack\\/([^\\/]+)\\/?"), "modrinth");
map.insert(QRegularExpression::anchoredPattern("(?:www\\.)?curseforge\\.com\\/minecraft\\/texture-packs\\/([^\\/]+)\\/?"),
"curseforge");
map.insert(QRegularExpression::anchoredPattern("minecraft\\.curseforge\\.com\\/projects\\/([^\\/]+)\\/?"), "curseforge");
return map;
}
} // namespace ResourceDownload