feat: add a provider column to the mods page

Signed-off-by: leo78913 <leo3758@riseup.net>
This commit is contained in:
leo78913 2022-12-15 12:02:08 -03:00
parent aaef448959
commit 4ee29b388d
5 changed files with 26 additions and 3 deletions

View File

@ -44,6 +44,8 @@
#include "MetadataHandler.h" #include "MetadataHandler.h"
#include "Version.h" #include "Version.h"
static ModPlatform::ProviderCapabilities ProviderCaps;
Mod::Mod(const QFileInfo& file) : Resource(file), m_local_details() Mod::Mod(const QFileInfo& file) : Resource(file), m_local_details()
{ {
m_enabled = (file.suffix() != "disabled"); m_enabled = (file.suffix() != "disabled");
@ -91,6 +93,10 @@ std::pair<int, bool> Mod::compare(const Resource& other, SortType type) const
if (this_ver < other_ver) if (this_ver < other_ver)
return { -1, type == SortType::VERSION }; return { -1, type == SortType::VERSION };
} }
case SortType::PROVIDER:
auto compare_result = QString::compare(provider(), cast_other->provider(), Qt::CaseInsensitive);
if (compare_result != 0)
return { compare_result, type == SortType::PROVIDER };
} }
return { 0, false }; return { 0, false };
} }
@ -189,4 +195,12 @@ void Mod::finishResolvingWithDetails(ModDetails&& details)
m_local_details = std::move(details); m_local_details = std::move(details);
if (metadata) if (metadata)
setMetadata(std::move(metadata)); setMetadata(std::move(metadata));
};
auto Mod::provider() const -> QString
{
if (metadata()) {
return ProviderCaps.readableName(metadata()->provider);
}
return "Unknown";
} }

View File

@ -61,6 +61,7 @@ public:
auto description() const -> QString; auto description() const -> QString;
auto authors() const -> QStringList; auto authors() const -> QStringList;
auto status() const -> ModStatus; auto status() const -> ModStatus;
auto provider() const -> QString;
auto metadata() -> std::shared_ptr<Metadata::ModStruct>; auto metadata() -> std::shared_ptr<Metadata::ModStruct>;
auto metadata() const -> const std::shared_ptr<Metadata::ModStruct>; auto metadata() const -> const std::shared_ptr<Metadata::ModStruct>;

View File

@ -48,10 +48,11 @@
#include "minecraft/mod/tasks/LocalModParseTask.h" #include "minecraft/mod/tasks/LocalModParseTask.h"
#include "minecraft/mod/tasks/ModFolderLoadTask.h" #include "minecraft/mod/tasks/ModFolderLoadTask.h"
#include "modplatform/ModIndex.h"
ModFolderModel::ModFolderModel(const QString &dir, bool is_indexed) : ResourceFolderModel(QDir(dir)), m_is_indexed(is_indexed) ModFolderModel::ModFolderModel(const QString &dir, bool is_indexed) : ResourceFolderModel(QDir(dir)), m_is_indexed(is_indexed)
{ {
m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::VERSION, SortType::DATE }; m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::VERSION, SortType::DATE, SortType::PROVIDER };
} }
QVariant ModFolderModel::data(const QModelIndex &index, int role) const QVariant ModFolderModel::data(const QModelIndex &index, int role) const
@ -82,7 +83,8 @@ QVariant ModFolderModel::data(const QModelIndex &index, int role) const
} }
case DateColumn: case DateColumn:
return m_resources[row]->dateTimeChanged(); return m_resources[row]->dateTimeChanged();
case ProviderColumn:
return at(row)->provider();
default: default:
return QVariant(); return QVariant();
} }
@ -118,6 +120,8 @@ QVariant ModFolderModel::headerData(int section, Qt::Orientation orientation, in
return tr("Version"); return tr("Version");
case DateColumn: case DateColumn:
return tr("Last changed"); return tr("Last changed");
case ProviderColumn:
return tr("Provider");
default: default:
return QVariant(); return QVariant();
} }
@ -133,6 +137,8 @@ QVariant ModFolderModel::headerData(int section, Qt::Orientation orientation, in
return tr("The version of the mod."); return tr("The version of the mod.");
case DateColumn: case DateColumn:
return tr("The date and time this mod was last changed (or added)."); return tr("The date and time this mod was last changed (or added).");
case ProviderColumn:
return tr("Where the mod was downloaded from.");
default: default:
return QVariant(); return QVariant();
} }

View File

@ -67,6 +67,7 @@ public:
NameColumn, NameColumn,
VersionColumn, VersionColumn,
DateColumn, DateColumn,
ProviderColumn,
NUM_COLUMNS NUM_COLUMNS
}; };
enum ModStatusAction { enum ModStatusAction {

View File

@ -20,7 +20,8 @@ enum class SortType {
DATE, DATE,
VERSION, VERSION,
ENABLED, ENABLED,
PACK_FORMAT PACK_FORMAT,
PROVIDER
}; };
enum class EnableAction { enum class EnableAction {