75116364c6
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
82 lines
2.3 KiB
C++
82 lines
2.3 KiB
C++
// SPDX-FileCopyrightText: 2023 flowln <flowlnlnln@gmail.com>
|
|
//
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "ModModel.h"
|
|
|
|
#include "minecraft/MinecraftInstance.h"
|
|
#include "minecraft/PackProfile.h"
|
|
#include "minecraft/mod/ModFolderModel.h"
|
|
#include "modplatform/ModIndex.h"
|
|
|
|
#include <QMessageBox>
|
|
|
|
namespace ResourceDownload {
|
|
|
|
ModModel::ModModel(BaseInstance const& base_inst, ResourceAPI* api) : ResourceModel(api), m_base_instance(base_inst)
|
|
{
|
|
auto folder = static_cast<MinecraftInstance const&>(m_base_instance).loaderModList();
|
|
for (auto mod : folder->allMods()) {
|
|
auto meta = mod->metadata();
|
|
ModPlatform::IndexedPack pack{ meta->project_id, meta->provider, meta->name, meta->slug };
|
|
pack.loadedFileId = meta->file_id;
|
|
addPack(pack);
|
|
}
|
|
}
|
|
|
|
/******** Make data requests ********/
|
|
|
|
ResourceAPI::SearchArgs ModModel::createSearchArguments()
|
|
{
|
|
auto profile = static_cast<MinecraftInstance const&>(m_base_instance).getPackProfile();
|
|
|
|
Q_ASSERT(profile);
|
|
Q_ASSERT(m_filter);
|
|
|
|
std::optional<std::list<Version>> versions{};
|
|
|
|
{ // Version filter
|
|
if (!m_filter->versions.empty())
|
|
versions = m_filter->versions;
|
|
}
|
|
|
|
auto sort = getCurrentSortingMethodByIndex();
|
|
|
|
return { ModPlatform::ResourceType::MOD, m_next_search_offset, m_search_term, sort, profile->getModLoaders(), versions };
|
|
}
|
|
|
|
ResourceAPI::VersionSearchArgs ModModel::createVersionsArguments(QModelIndex& entry)
|
|
{
|
|
auto& pack = m_packs[entry.row()];
|
|
auto profile = static_cast<MinecraftInstance const&>(m_base_instance).getPackProfile();
|
|
|
|
Q_ASSERT(profile);
|
|
Q_ASSERT(m_filter);
|
|
|
|
std::optional<std::list<Version>> versions{};
|
|
if (!m_filter->versions.empty())
|
|
versions = m_filter->versions;
|
|
|
|
return { pack, versions, profile->getModLoaders() };
|
|
}
|
|
|
|
ResourceAPI::ProjectInfoArgs ModModel::createInfoArguments(QModelIndex& entry)
|
|
{
|
|
auto& pack = m_packs[entry.row()];
|
|
return { pack };
|
|
}
|
|
|
|
void ModModel::searchWithTerm(const QString& term, unsigned int sort, bool filter_changed)
|
|
{
|
|
if (m_search_term == term && m_search_term.isNull() == term.isNull() && m_current_sort_index == sort && !filter_changed) {
|
|
return;
|
|
}
|
|
|
|
setSearchTerm(term);
|
|
m_current_sort_index = sort;
|
|
|
|
refresh();
|
|
}
|
|
|
|
} // namespace ResourceDownload
|