aboutsummaryrefslogtreecommitdiff
path: root/launcher
diff options
context:
space:
mode:
authorflow <flowlnlnln@gmail.com>2022-12-30 11:39:03 -0300
committerGitHub <noreply@github.com>2022-12-30 11:39:03 -0300
commitd55f47077aed0e2066f4b5d8f1bd208ffffd550e (patch)
treed4fd5898b35ea44b04c2515326ca54d64065d530 /launcher
parent67ac3da8a0eac959343fe86ca143b97f0f76543c (diff)
parent141e94369ed88e7099b46b45a0ed3683cada6329 (diff)
downloadPrismLauncher-d55f47077aed0e2066f4b5d8f1bd208ffffd550e.tar.gz
PrismLauncher-d55f47077aed0e2066f4b5d8f1bd208ffffd550e.tar.bz2
PrismLauncher-d55f47077aed0e2066f4b5d8f1bd208ffffd550e.zip
Merge pull request #626 from leo78913/mods-provider-column
closes https://github.com/PrismLauncher/PrismLauncher/issues/402
Diffstat (limited to 'launcher')
-rw-r--r--launcher/minecraft/mod/Mod.cpp14
-rw-r--r--launcher/minecraft/mod/Mod.h3
-rw-r--r--launcher/minecraft/mod/ModFolderModel.cpp15
-rw-r--r--launcher/minecraft/mod/ModFolderModel.h1
-rw-r--r--launcher/minecraft/mod/Resource.h3
-rw-r--r--launcher/ui/widgets/ModListView.cpp16
6 files changed, 50 insertions, 2 deletions
diff --git a/launcher/minecraft/mod/Mod.cpp b/launcher/minecraft/mod/Mod.cpp
index 39023f69..9cd0056c 100644
--- a/launcher/minecraft/mod/Mod.cpp
+++ b/launcher/minecraft/mod/Mod.cpp
@@ -44,6 +44,8 @@
#include "MetadataHandler.h"
#include "Version.h"
+static ModPlatform::ProviderCapabilities ProviderCaps;
+
Mod::Mod(const QFileInfo& file) : Resource(file), m_local_details()
{
m_enabled = (file.suffix() != "disabled");
@@ -91,6 +93,11 @@ std::pair<int, bool> Mod::compare(const Resource& other, SortType type) const
if (this_ver < other_ver)
return { -1, type == SortType::VERSION };
}
+ case SortType::PROVIDER: {
+ auto compare_result = QString::compare(provider().value_or("Unknown"), cast_other->provider().value_or("Unknown"), Qt::CaseInsensitive);
+ if (compare_result != 0)
+ return { compare_result, type == SortType::PROVIDER };
+ }
}
return { 0, false };
}
@@ -189,4 +196,11 @@ void Mod::finishResolvingWithDetails(ModDetails&& details)
m_local_details = std::move(details);
if (metadata)
setMetadata(std::move(metadata));
+};
+
+auto Mod::provider() const -> std::optional<QString>
+{
+ if (metadata())
+ return ProviderCaps.readableName(metadata()->provider);
+ return {};
}
diff --git a/launcher/minecraft/mod/Mod.h b/launcher/minecraft/mod/Mod.h
index f336bec4..8185c8fc 100644
--- a/launcher/minecraft/mod/Mod.h
+++ b/launcher/minecraft/mod/Mod.h
@@ -39,6 +39,8 @@
#include <QFileInfo>
#include <QList>
+#include <optional>
+
#include "Resource.h"
#include "ModDetails.h"
@@ -61,6 +63,7 @@ public:
auto description() const -> QString;
auto authors() const -> QStringList;
auto status() const -> ModStatus;
+ auto provider() const -> std::optional<QString>;
auto metadata() -> std::shared_ptr<Metadata::ModStruct>;
auto metadata() const -> const std::shared_ptr<Metadata::ModStruct>;
diff --git a/launcher/minecraft/mod/ModFolderModel.cpp b/launcher/minecraft/mod/ModFolderModel.cpp
index 4ccc5d4d..f258ad69 100644
--- a/launcher/minecraft/mod/ModFolderModel.cpp
+++ b/launcher/minecraft/mod/ModFolderModel.cpp
@@ -48,10 +48,11 @@
#include "minecraft/mod/tasks/LocalModParseTask.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)
{
- 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
@@ -82,7 +83,15 @@ QVariant ModFolderModel::data(const QModelIndex &index, int role) const
}
case DateColumn:
return m_resources[row]->dateTimeChanged();
+ case ProviderColumn: {
+ auto provider = at(row)->provider();
+ if (!provider.has_value()) {
+ //: Unknown mod provider (i.e. not Modrinth, CurseForge, etc...)
+ return tr("Unknown");
+ }
+ return provider.value();
+ }
default:
return QVariant();
}
@@ -118,6 +127,8 @@ QVariant ModFolderModel::headerData(int section, Qt::Orientation orientation, in
return tr("Version");
case DateColumn:
return tr("Last changed");
+ case ProviderColumn:
+ return tr("Provider");
default:
return QVariant();
}
@@ -133,6 +144,8 @@ QVariant ModFolderModel::headerData(int section, Qt::Orientation orientation, in
return tr("The version of the mod.");
case DateColumn:
return tr("The date and time this mod was last changed (or added).");
+ case ProviderColumn:
+ return tr("Where the mod was downloaded from.");
default:
return QVariant();
}
diff --git a/launcher/minecraft/mod/ModFolderModel.h b/launcher/minecraft/mod/ModFolderModel.h
index 93980319..6898f6eb 100644
--- a/launcher/minecraft/mod/ModFolderModel.h
+++ b/launcher/minecraft/mod/ModFolderModel.h
@@ -67,6 +67,7 @@ public:
NameColumn,
VersionColumn,
DateColumn,
+ ProviderColumn,
NUM_COLUMNS
};
enum ModStatusAction {
diff --git a/launcher/minecraft/mod/Resource.h b/launcher/minecraft/mod/Resource.h
index f9bd811e..0c37f3a3 100644
--- a/launcher/minecraft/mod/Resource.h
+++ b/launcher/minecraft/mod/Resource.h
@@ -20,7 +20,8 @@ enum class SortType {
DATE,
VERSION,
ENABLED,
- PACK_FORMAT
+ PACK_FORMAT,
+ PROVIDER
};
enum class EnableAction {
diff --git a/launcher/ui/widgets/ModListView.cpp b/launcher/ui/widgets/ModListView.cpp
index d1860f57..09b03a76 100644
--- a/launcher/ui/widgets/ModListView.cpp
+++ b/launcher/ui/widgets/ModListView.cpp
@@ -14,6 +14,9 @@
*/
#include "ModListView.h"
+
+#include "minecraft/mod/ModFolderModel.h"
+
#include <QHeaderView>
#include <QMouseEvent>
#include <QPainter>
@@ -62,4 +65,17 @@ void ModListView::setModel ( QAbstractItemModel* model )
for(int i = 1; i < head->count(); i++)
head->setSectionResizeMode(i, QHeaderView::ResizeToContents);
}
+
+ auto real_model = model;
+ if (auto proxy_model = dynamic_cast<QSortFilterProxyModel*>(model); proxy_model)
+ real_model = proxy_model->sourceModel();
+
+ if (auto mod_model = dynamic_cast<ModFolderModel*>(real_model); mod_model) {
+ connect(mod_model, &ModFolderModel::updateFinished, this, [this, mod_model]{
+ auto mods = mod_model->allMods();
+ // Hide the 'Provider' column if no mod has a defined provider!
+ setColumnHidden(ModFolderModel::Columns::ProviderColumn,
+ std::none_of(mods.constBegin(), mods.constEnd(), [](auto const mod){ return mod->provider().has_value(); }));
+ });
+ }
}