summaryrefslogtreecommitdiffstats
path: root/logic/forge/ForgeVersionList.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'logic/forge/ForgeVersionList.cpp')
-rw-r--r--logic/forge/ForgeVersionList.cpp95
1 files changed, 40 insertions, 55 deletions
diff --git a/logic/forge/ForgeVersionList.cpp b/logic/forge/ForgeVersionList.cpp
index 56ffad11..b2320a6d 100644
--- a/logic/forge/ForgeVersionList.cpp
+++ b/logic/forge/ForgeVersionList.cpp
@@ -51,7 +51,7 @@ int ForgeVersionList::count() const
int ForgeVersionList::columnCount(const QModelIndex &parent) const
{
- return 3;
+ return 1;
}
QVariant ForgeVersionList::data(const QModelIndex &index, int role) const
@@ -65,73 +65,34 @@ QVariant ForgeVersionList::data(const QModelIndex &index, int role) const
auto version = std::dynamic_pointer_cast<ForgeVersion>(m_vlist[index.row()]);
switch (role)
{
- case Qt::DisplayRole:
- switch (index.column())
- {
- case 0:
- return version->name();
-
- case 1:
- return version->mcver_sane;
-
- case 2:
- return version->typeString();
- default:
- return QVariant();
- }
-
- case Qt::ToolTipRole:
- return version->descriptor();
-
case VersionPointerRole:
return qVariantFromValue(m_vlist[index.row()]);
- default:
- return QVariant();
- }
-}
-
-QVariant ForgeVersionList::headerData(int section, Qt::Orientation orientation, int role) const
-{
- switch (role)
- {
- case Qt::DisplayRole:
- switch (section)
- {
- case 0:
- return tr("Version");
-
- case 1:
- return tr("Minecraft");
-
- case 2:
- return tr("Type");
+ case VersionRole:
+ return version->name();
- default:
- return QVariant();
- }
-
- case Qt::ToolTipRole:
- switch (section)
- {
- case 0:
- return tr("The name of the version.");
+ case VersionIdRole:
+ return version->descriptor();
- case 1:
- return tr("Minecraft version");
+ case ParentGameVersionRole:
+ return version->mcver_sane;
- case 2:
- return tr("The version's type.");
+ case RecommendedRole:
+ return version->is_recommended;
- default:
- return QVariant();
- }
+ case BranchRole:
+ return version->branch;
default:
return QVariant();
}
}
+QList<BaseVersionList::ModelRoles> ForgeVersionList::providesRoles()
+{
+ return {VersionPointerRole, VersionRole, VersionIdRole, ParentGameVersionRole, RecommendedRole, BranchRole};
+}
+
BaseVersionPtr ForgeVersionList::getLatestStable() const
{
return BaseVersionPtr();
@@ -296,6 +257,7 @@ bool ForgeListLoadTask::parseForgeList(QList<BaseVersionPtr> &out)
bool ForgeListLoadTask::parseForgeGradleList(QList<BaseVersionPtr> &out)
{
+ QMap<int, std::shared_ptr<ForgeVersion>> lookup;
QByteArray data;
{
auto dlJob = gradleListDownload;
@@ -402,6 +364,29 @@ bool ForgeListLoadTask::parseForgeGradleList(QList<BaseVersionPtr> &out)
fVersion->installer_filename = installer_filename;
fVersion->type = ForgeVersion::Gradle;
out.append(fVersion);
+ lookup[fVersion->m_buildnr] = fVersion;
+ }
+ QJsonObject promos = root.value("promos").toObject();
+ for (auto it = promos.begin(); it != promos.end(); ++it)
+ {
+ QString key = it.key();
+ int build = it.value().toInt();
+ QRegularExpression regexp("^(?<mcversion>[0-9]+(.[0-9]+)*)-(?<label>[a-z]+)$");
+ auto match = regexp.match(key);
+ if(!match.hasMatch())
+ {
+ qDebug() << key << "doesn't match." << "build" << build;
+ continue;
+ }
+
+ QString label = match.captured("label");
+ if(label != "recommended")
+ {
+ continue;
+ }
+ QString mcversion = match.captured("mcversion");
+ qDebug() << "Forge build" << build << "is the" << label << "for Minecraft" << mcversion << QString("<%1>").arg(key);
+ lookup[build]->is_recommended = true;
}
return true;
}