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