From aea51a08763d81ce82326b2b875ace8a0039fb1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 28 Apr 2015 09:01:37 +0200 Subject: GH-328 overhaul all relevant version lists --- logic/BaseVersionList.cpp | 57 +++--------- logic/BaseVersionList.h | 27 +++--- logic/forge/ForgeVersionList.cpp | 95 +++++++++----------- logic/forge/ForgeVersionList.h | 3 +- logic/java/JavaVersionList.cpp | 139 +++++++++++++---------------- logic/java/JavaVersionList.h | 26 +++--- logic/liteloader/LiteLoaderVersionList.cpp | 36 ++++++++ logic/liteloader/LiteLoaderVersionList.h | 2 + logic/minecraft/MinecraftVersionList.cpp | 38 +++++++- logic/minecraft/MinecraftVersionList.h | 2 + 10 files changed, 217 insertions(+), 208 deletions(-) (limited to 'logic') diff --git a/logic/BaseVersionList.cpp b/logic/BaseVersionList.cpp index 7752b14c..fe17a905 100644 --- a/logic/BaseVersionList.cpp +++ b/logic/BaseVersionList.cpp @@ -50,63 +50,26 @@ QVariant BaseVersionList::data(const QModelIndex &index, int role) const switch (role) { - case Qt::DisplayRole: - switch (index.column()) - { - case NameColumn: - return version->name(); - - case TypeColumn: - return version->typeString(); + case VersionPointerRole: + return qVariantFromValue(version); - default: - return QVariant(); - } + case VersionRole: + return version->name(); - case Qt::ToolTipRole: + case VersionIdRole: return version->descriptor(); - case VersionPointerRole: - return qVariantFromValue(version); + case TypeRole: + return version->typeString(); default: return QVariant(); } } -QVariant BaseVersionList::headerData(int section, Qt::Orientation orientation, int role) const +BaseVersionList::RoleList BaseVersionList::providesRoles() { - switch (role) - { - case Qt::DisplayRole: - switch (section) - { - case NameColumn: - return tr("Name"); - - case TypeColumn: - return tr("Type"); - - default: - return QVariant(); - } - - case Qt::ToolTipRole: - switch (section) - { - case NameColumn: - return tr("The name of the version."); - - case TypeColumn: - return tr("The version's type."); - - default: - return QVariant(); - } - - default: - return QVariant(); - } + return {VersionPointerRole, VersionRole, VersionIdRole, TypeRole}; } int BaseVersionList::rowCount(const QModelIndex &parent) const @@ -117,5 +80,5 @@ int BaseVersionList::rowCount(const QModelIndex &parent) const int BaseVersionList::columnCount(const QModelIndex &parent) const { - return 2; + return 1; } diff --git a/logic/BaseVersionList.h b/logic/BaseVersionList.h index 584d6ca7..6089c31c 100644 --- a/logic/BaseVersionList.h +++ b/logic/BaseVersionList.h @@ -41,20 +41,17 @@ class BaseVersionList : public QAbstractListModel public: enum ModelRoles { - VersionPointerRole = 0x34B1CB48 - }; - - enum VListColumns - { - // First column - Name - NameColumn = 0, - - // Second column - Type - TypeColumn, - - // Third column - Timestamp - TimeColumn + VersionPointerRole = Qt::UserRole, + VersionRole, + VersionIdRole, + ParentGameVersionRole, + RecommendedRole, + TypeRole, + BranchRole, + PathRole, + ArchitectureRole }; + typedef QList RoleList; explicit BaseVersionList(QObject *parent = 0); @@ -78,10 +75,12 @@ public: //////// List Model Functions //////// virtual QVariant data(const QModelIndex &index, int role) const; - virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; virtual int rowCount(const QModelIndex &parent) const; virtual int columnCount(const QModelIndex &parent) const; + //! which roles are provided by this version list? + virtual RoleList providesRoles(); + /*! * \brief Finds a version by its descriptor. * \param The descriptor of the version to find. 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(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 ForgeVersionList::providesRoles() +{ + return {VersionPointerRole, VersionRole, VersionIdRole, ParentGameVersionRole, RecommendedRole, BranchRole}; +} + BaseVersionPtr ForgeVersionList::getLatestStable() const { return BaseVersionPtr(); @@ -296,6 +257,7 @@ bool ForgeListLoadTask::parseForgeList(QList &out) bool ForgeListLoadTask::parseForgeGradleList(QList &out) { + QMap> lookup; QByteArray data; { auto dlJob = gradleListDownload; @@ -402,6 +364,29 @@ bool ForgeListLoadTask::parseForgeGradleList(QList &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("^(?[0-9]+(.[0-9]+)*)-(?