mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2026-07-04 12:26:58 +03:00
remove extra encapsulations
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
323c25d83b
commit
e0b8d6e0fc
28 changed files with 517 additions and 925 deletions
|
|
@ -40,38 +40,75 @@
|
|||
#include "ModPage.h"
|
||||
#include "ui_ResourcePage.h"
|
||||
|
||||
#include <QDesktopServices>
|
||||
#include <QKeyEvent>
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "Application.h"
|
||||
#include "ResourceDownloadTask.h"
|
||||
|
||||
#include "minecraft/MinecraftInstance.h"
|
||||
|
||||
#include "ui/dialogs/ResourceDownloadDialog.h"
|
||||
|
||||
namespace ResourceDownload {
|
||||
|
||||
ModPage::ModPage(ModDownloadDialog* dialog, BaseInstance& instance) : ResourcePage(dialog, instance)
|
||||
namespace {
|
||||
ResourceDownload::ResourceDescriptor prepareModDescriptor()
|
||||
{
|
||||
QMap<QString, QString> urlHandlers;
|
||||
urlHandlers.insert(QRegularExpression::anchoredPattern(R"((?:www\.)?modrinth\.com\/mod\/([^\/]+)\/?)"), "modrinth");
|
||||
urlHandlers.insert(QRegularExpression::anchoredPattern(R"((?:www\.)?curseforge\.com\/minecraft\/mc-mods\/([^\/]+)\/?)"), "curseforge");
|
||||
urlHandlers.insert(QRegularExpression::anchoredPattern(R"(minecraft\.curseforge\.com\/projects\/([^\/]+)\/?)"), "curseforge");
|
||||
return {
|
||||
.helpPage = "Mod-platform",
|
||||
//: The singular version of 'mods'
|
||||
.resourceString = QObject::tr("mod"),
|
||||
//: The plural version of 'mod'
|
||||
.resourcesString = QObject::tr("mods"),
|
||||
.supportsFiltering = true,
|
||||
.isIndexed = true,
|
||||
.urlHandlers = urlHandlers,
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace ResourceDownload {
|
||||
ModPage::ModPage(ModDownloadDialog* dialog, BaseInstance& instance, ResourceProviderData p, ResourceAPI* api, ModFilterWidget* filterWidget)
|
||||
: ResourcePage(dialog, instance, prepareModDescriptor(), std::move(p)), m_api(api)
|
||||
{
|
||||
auto* model = new ModModel(instance, api, debugName(), metaEntryBase());
|
||||
m_model = model;
|
||||
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...
|
||||
setFilterWidget(filterWidget);
|
||||
model->setFilter(getFilter());
|
||||
|
||||
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, &ModPage::triggerSearch);
|
||||
connect(m_ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &ModPage::onSelectionChanged);
|
||||
connect(m_ui->versionSelectionBox, &QComboBox::currentIndexChanged, this, &ModPage::onVersionSelectionChanged);
|
||||
connect(m_ui->resourceSelectionButton, &QPushButton::clicked, this, &ModPage::onResourceSelected);
|
||||
|
||||
m_ui->packDescription->setMetaEntry(metaEntryBase());
|
||||
connect(m_ui->resourceFilterButton, &QPushButton::clicked, this, &ModPage::filterMods);
|
||||
}
|
||||
|
||||
void ModPage::setFilterWidget(std::unique_ptr<ModFilterWidget>& widget)
|
||||
void ModPage::setFilterWidget(ModFilterWidget* widget)
|
||||
{
|
||||
if (m_filter_widget) {
|
||||
disconnect(m_filter_widget.get(), nullptr, nullptr, nullptr);
|
||||
}
|
||||
|
||||
auto* old = m_ui->splitter->replaceWidget(0, widget.get());
|
||||
auto* old = m_ui->splitter->replaceWidget(0, widget);
|
||||
// because we replaced the widget we also need to delete it
|
||||
if (old) {
|
||||
old->deleteLater();
|
||||
}
|
||||
|
||||
delete old;
|
||||
|
||||
m_filter_widget.swap(widget);
|
||||
m_filter_widget.reset(widget);
|
||||
|
||||
m_filter = m_filter_widget->getFilter();
|
||||
|
||||
|
|
@ -100,24 +137,14 @@ void ModPage::triggerSearch()
|
|||
m_fetchProgress.watch(m_model->activeSearchJob().get());
|
||||
}
|
||||
|
||||
QMap<QString, QString> ModPage::urlHandlers() const
|
||||
void ModPage::prepareProviderCategories()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
/******** Make changes to the UI ********/
|
||||
|
||||
void ModPage::addResourceToPage(ModPlatform::IndexedPack::Ptr pack,
|
||||
ModPlatform::IndexedVersion& version,
|
||||
ResourceFolderModel* baseModel,
|
||||
QString downloadReason)
|
||||
{
|
||||
bool isIndexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
|
||||
m_model->addPack(pack, version, baseModel, isIndexed, downloadReason);
|
||||
}
|
||||
|
||||
auto [task, response] = m_api->getModCategories();
|
||||
m_categoriesTask = task;
|
||||
connect(m_categoriesTask.get(), &Task::succeeded, [this, response]() {
|
||||
auto categories = m_api->loadModCategories(*response);
|
||||
m_filter_widget->setCategories(categories);
|
||||
});
|
||||
m_categoriesTask->start();
|
||||
};
|
||||
} // namespace ResourceDownload
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue