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