2023-01-23 14:03:55 +00:00
|
|
|
// SPDX-FileCopyrightText: 2023 flowln <flowlnlnln@gmail.com>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
|
2022-03-03 00:17:10 +00:00
|
|
|
#include "ModModel.h"
|
|
|
|
|
2022-03-03 02:01:23 +00:00
|
|
|
#include "minecraft/MinecraftInstance.h"
|
|
|
|
#include "minecraft/PackProfile.h"
|
2022-07-15 02:23:41 +01:00
|
|
|
|
2022-03-03 00:17:10 +00:00
|
|
|
#include <QMessageBox>
|
|
|
|
|
2022-12-16 22:03:52 +00:00
|
|
|
namespace ResourceDownload {
|
2022-03-03 00:17:10 +00:00
|
|
|
|
2023-01-03 15:48:22 +00:00
|
|
|
ModModel::ModModel(BaseInstance const& base_inst, ResourceAPI* api) : ResourceModel(api), m_base_instance(base_inst) {}
|
2022-03-07 22:29:59 +00:00
|
|
|
|
|
|
|
/******** Make data requests ********/
|
|
|
|
|
2022-12-16 22:03:52 +00:00
|
|
|
ResourceAPI::SearchArgs ModModel::createSearchArguments()
|
2022-03-07 22:29:59 +00:00
|
|
|
{
|
2022-12-18 18:41:46 +00:00
|
|
|
auto profile = static_cast<MinecraftInstance const&>(m_base_instance).getPackProfile();
|
|
|
|
|
|
|
|
Q_ASSERT(profile);
|
|
|
|
Q_ASSERT(m_filter);
|
|
|
|
|
2022-12-20 15:15:17 +00:00
|
|
|
std::optional<std::list<Version>> versions{};
|
|
|
|
|
2023-04-20 20:35:10 +01:00
|
|
|
{ // Version filter
|
2022-12-20 15:15:17 +00:00
|
|
|
if (!m_filter->versions.empty())
|
|
|
|
versions = m_filter->versions;
|
|
|
|
}
|
2022-12-18 18:41:46 +00:00
|
|
|
|
2022-12-23 20:28:42 +00:00
|
|
|
auto sort = getCurrentSortingMethodByIndex();
|
2022-12-20 15:15:17 +00:00
|
|
|
|
|
|
|
return { ModPlatform::ResourceType::MOD, m_next_search_offset, m_search_term, sort, profile->getModLoaders(), versions };
|
2022-03-07 22:29:59 +00:00
|
|
|
}
|
2022-03-03 00:17:10 +00:00
|
|
|
|
2022-12-16 22:03:52 +00:00
|
|
|
ResourceAPI::VersionSearchArgs ModModel::createVersionsArguments(QModelIndex& entry)
|
2022-07-18 23:17:44 +01:00
|
|
|
{
|
2022-12-18 18:41:46 +00:00
|
|
|
auto& pack = m_packs[entry.row()];
|
|
|
|
auto profile = static_cast<MinecraftInstance const&>(m_base_instance).getPackProfile();
|
|
|
|
|
|
|
|
Q_ASSERT(profile);
|
|
|
|
Q_ASSERT(m_filter);
|
2022-07-18 23:17:44 +01:00
|
|
|
|
2022-12-20 15:15:17 +00:00
|
|
|
std::optional<std::list<Version>> versions{};
|
|
|
|
if (!m_filter->versions.empty())
|
2022-12-18 18:41:46 +00:00
|
|
|
versions = m_filter->versions;
|
|
|
|
|
|
|
|
return { pack, versions, profile->getModLoaders() };
|
2022-07-18 23:17:44 +01:00
|
|
|
}
|
2022-03-03 02:01:23 +00:00
|
|
|
|
2022-12-16 22:03:52 +00:00
|
|
|
ResourceAPI::ProjectInfoArgs ModModel::createInfoArguments(QModelIndex& entry)
|
2022-05-24 13:38:48 +01:00
|
|
|
{
|
2022-11-25 12:23:46 +00:00
|
|
|
auto& pack = m_packs[entry.row()];
|
|
|
|
return { pack };
|
2022-05-24 13:38:48 +01:00
|
|
|
}
|
2022-03-03 00:17:10 +00:00
|
|
|
|
2022-12-20 15:15:17 +00:00
|
|
|
void ModModel::searchWithTerm(const QString& term, unsigned int sort, bool filter_changed)
|
2022-04-02 23:21:02 +01:00
|
|
|
{
|
2022-12-20 15:15:17 +00:00
|
|
|
if (m_search_term == term && m_search_term.isNull() == term.isNull() && m_current_sort_index == sort && !filter_changed) {
|
2022-05-08 08:22:50 +01:00
|
|
|
return;
|
|
|
|
}
|
2022-04-14 14:27:03 +01:00
|
|
|
|
2022-11-25 12:23:46 +00:00
|
|
|
setSearchTerm(term);
|
2022-12-20 15:15:17 +00:00
|
|
|
m_current_sort_index = sort;
|
2022-04-02 23:21:02 +01:00
|
|
|
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
2022-12-16 22:03:52 +00:00
|
|
|
} // namespace ResourceDownload
|