diff options
author | Petr Mrázek <peterix@gmail.com> | 2015-04-28 09:01:37 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2015-05-01 20:50:24 +0200 |
commit | aea51a08763d81ce82326b2b875ace8a0039fb1a (patch) | |
tree | 7d92d2ed9500f7cd205257b79e49dd03bc84f001 /logic | |
parent | 75dfbc61fcc451239254049a362b227e72d94d90 (diff) | |
download | MultiMC-aea51a08763d81ce82326b2b875ace8a0039fb1a.tar MultiMC-aea51a08763d81ce82326b2b875ace8a0039fb1a.tar.gz MultiMC-aea51a08763d81ce82326b2b875ace8a0039fb1a.tar.lz MultiMC-aea51a08763d81ce82326b2b875ace8a0039fb1a.tar.xz MultiMC-aea51a08763d81ce82326b2b875ace8a0039fb1a.zip |
GH-328 overhaul all relevant version lists
Diffstat (limited to 'logic')
-rw-r--r-- | logic/BaseVersionList.cpp | 57 | ||||
-rw-r--r-- | logic/BaseVersionList.h | 27 | ||||
-rw-r--r-- | logic/forge/ForgeVersionList.cpp | 95 | ||||
-rw-r--r-- | logic/forge/ForgeVersionList.h | 3 | ||||
-rw-r--r-- | logic/java/JavaVersionList.cpp | 139 | ||||
-rw-r--r-- | logic/java/JavaVersionList.h | 26 | ||||
-rw-r--r-- | logic/liteloader/LiteLoaderVersionList.cpp | 36 | ||||
-rw-r--r-- | logic/liteloader/LiteLoaderVersionList.h | 2 | ||||
-rw-r--r-- | logic/minecraft/MinecraftVersionList.cpp | 38 | ||||
-rw-r--r-- | logic/minecraft/MinecraftVersionList.h | 2 |
10 files changed, 217 insertions, 208 deletions
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<ModelRoles> 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<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; } diff --git a/logic/forge/ForgeVersionList.h b/logic/forge/ForgeVersionList.h index 75e1dd78..baae570d 100644 --- a/logic/forge/ForgeVersionList.h +++ b/logic/forge/ForgeVersionList.h @@ -44,7 +44,8 @@ public: ForgeVersionPtr findVersionByVersionNr(QString version); virtual QVariant data(const QModelIndex &index, int role) const; - virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; + virtual QList<ModelRoles> providesRoles() override; + virtual int columnCount(const QModelIndex &parent) const; protected: diff --git a/logic/java/JavaVersionList.cpp b/logic/java/JavaVersionList.cpp index 72fa6dc8..d607ae72 100644 --- a/logic/java/JavaVersionList.cpp +++ b/logic/java/JavaVersionList.cpp @@ -22,6 +22,7 @@ #include "java/JavaVersionList.h" #include "java/JavaCheckerJob.h" #include "java/JavaUtils.h" +#include "MMCStrings.h" JavaVersionList::JavaVersionList(QObject *parent) : BaseVersionList(parent) { @@ -47,11 +48,6 @@ int JavaVersionList::count() const return m_vlist.count(); } -int JavaVersionList::columnCount(const QModelIndex &parent) const -{ - return 3; -} - QVariant JavaVersionList::data(const QModelIndex &index, int role) const { if (!index.isValid()) @@ -63,100 +59,87 @@ QVariant JavaVersionList::data(const QModelIndex &index, int role) const auto version = std::dynamic_pointer_cast<JavaVersion>(m_vlist[index.row()]); switch (role) { - case Qt::DisplayRole: - switch (index.column()) - { - case 0: + case VersionPointerRole: + return qVariantFromValue(m_vlist[index.row()]); + case VersionIdRole: + return version->descriptor(); + case VersionRole: return version->id; - - case 1: - return version->arch; - - case 2: + case RecommendedRole: + return version->recommended; + case PathRole: return version->path; - + case ArchitectureRole: + return version->arch; default: return QVariant(); - } - - case Qt::ToolTipRole: - return version->descriptor(); - - case VersionPointerRole: - return qVariantFromValue(m_vlist[index.row()]); - - default: - return QVariant(); } } -QVariant JavaVersionList::headerData(int section, Qt::Orientation orientation, int role) const +BaseVersionList::RoleList JavaVersionList::providesRoles() { - switch (role) - { - case Qt::DisplayRole: - switch (section) - { - case 0: - return tr("Version"); - - case 1: - return tr("Arch"); - - case 2: - return tr("Path"); - - default: - return QVariant(); - } - - case Qt::ToolTipRole: - switch (section) - { - case 0: - return tr("The name of the version."); - - case 1: - return tr("The architecture this version is for."); - - case 2: - return tr("Path to this Java version."); - - default: - return QVariant(); - } - - default: - return QVariant(); - } + return {VersionPointerRole, VersionIdRole, VersionRole, RecommendedRole, PathRole, ArchitectureRole}; } -BaseVersionPtr JavaVersionList::getTopRecommended() const -{ - auto first = m_vlist.first(); - if(first != nullptr) - { - return first; - } - else - { - return BaseVersionPtr(); - } -} void JavaVersionList::updateListData(QList<BaseVersionPtr> versions) { beginResetModel(); m_vlist = versions; m_loaded = true; + // manual testing fakery + /* + m_vlist.push_back(std::make_shared<JavaVersion>("1.6.0_33", "64", "/foo/bar/baz")); + m_vlist.push_back(std::make_shared<JavaVersion>("1.6.0_44", "64", "/foo/bar/baz")); + m_vlist.push_back(std::make_shared<JavaVersion>("1.6.0_55", "64", "/foo/bar/baz")); + m_vlist.push_back(std::make_shared<JavaVersion>("1.7.0_44", "64", "/foo/bar/baz")); + m_vlist.push_back(std::make_shared<JavaVersion>("1.8.0_44", "64", "/foo/bar/baz")); + m_vlist.push_back(std::make_shared<JavaVersion>("1.6.0_33", "32", "/foo/bar/baz")); + m_vlist.push_back(std::make_shared<JavaVersion>("1.6.0_44", "32", "/foo/bar/baz")); + m_vlist.push_back(std::make_shared<JavaVersion>("1.6.0_55", "32", "/foo/bar/baz")); + m_vlist.push_back(std::make_shared<JavaVersion>("1.7.0_44", "32", "/foo/bar/baz")); + m_vlist.push_back(std::make_shared<JavaVersion>("1.8.0_44", "32", "/foo/bar/baz")); + m_vlist.push_back(std::make_shared<JavaVersion>("1.9.0_1231", "32", "/foo/bar/baz")); + m_vlist.push_back(std::make_shared<JavaVersion>("1.9.0_1", "32", "/foo/bar/baz")); + m_vlist.push_back(std::make_shared<JavaVersion>("1.9.0_1", "64", "/foo/bar/baz")); + */ + sort(); + if(m_vlist.size()) + { + auto best = std::dynamic_pointer_cast<JavaVersion>(m_vlist[0]); + best->recommended = true; + } endResetModel(); - // NOW SORT!! - // sort(); +} + +bool sortJavas(BaseVersionPtr left, BaseVersionPtr right) +{ + auto rleft = std::dynamic_pointer_cast<JavaVersion>(left); + auto rright = std::dynamic_pointer_cast<JavaVersion>(right); + // prefer higher arch + auto archCompare = Strings::naturalCompare(rleft->arch, rright->arch, Qt::CaseInsensitive); + if(archCompare != 0) + return archCompare > 0; + // dirty hack - 1.9 and above is too new + auto labove19 = Strings::naturalCompare(rleft->name(), "1.9.0", Qt::CaseInsensitive) >= 0; + auto rabove19 = Strings::naturalCompare(rright->name(), "1.9.0", Qt::CaseInsensitive) >= 0; + if(labove19 == rabove19) + { + // prefer higher versions in general + auto nameCompare = Strings::naturalCompare(rleft->name(), rright->name(), Qt::CaseInsensitive); + if(nameCompare != 0) + return nameCompare > 0; + // if all else is equal, sort by path + return Strings::naturalCompare(rleft->path, rright->path, Qt::CaseInsensitive) < 0; + } + return labove19 < rabove19; } void JavaVersionList::sort() { - // NO-OP for now + beginResetModel(); + std::sort(m_vlist.begin(), m_vlist.end(), sortJavas); + endResetModel(); } JavaListLoadTask::JavaListLoadTask(JavaVersionList *vlist) : Task() diff --git a/logic/java/JavaVersionList.h b/logic/java/JavaVersionList.h index 0117ea76..f0176673 100644 --- a/logic/java/JavaVersionList.h +++ b/logic/java/JavaVersionList.h @@ -26,6 +26,11 @@ class JavaListLoadTask; struct JavaVersion : public BaseVersion { + JavaVersion(){} + JavaVersion(QString id, QString arch, QString path) + : id(id), arch(arch), path(path) + { + } virtual QString descriptor() { return id; @@ -44,6 +49,7 @@ struct JavaVersion : public BaseVersion QString id; QString arch; QString path; + bool recommended = false; }; typedef std::shared_ptr<JavaVersion> JavaVersionPtr; @@ -54,20 +60,16 @@ class JavaVersionList : public BaseVersionList public: explicit JavaVersionList(QObject *parent = 0); - virtual Task *getLoadTask(); - virtual bool isLoaded(); - virtual const BaseVersionPtr at(int i) const; - virtual int count() const; - virtual void sort(); + virtual Task *getLoadTask() override; + virtual bool isLoaded() override; + virtual const BaseVersionPtr at(int i) const override; + virtual int count() const override; + virtual void sort() override; - virtual BaseVersionPtr getTopRecommended() const; + virtual QVariant data(const QModelIndex &index, int role) const override; + virtual RoleList providesRoles() override; - virtual QVariant data(const QModelIndex &index, int role) const; - virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; - virtual int columnCount(const QModelIndex &parent) const; - -public -slots: +public slots: virtual void updateListData(QList<BaseVersionPtr> versions); protected: diff --git a/logic/liteloader/LiteLoaderVersionList.cpp b/logic/liteloader/LiteLoaderVersionList.cpp index 2e54afdf..8b3c13e0 100644 --- a/logic/liteloader/LiteLoaderVersionList.cpp +++ b/logic/liteloader/LiteLoaderVersionList.cpp @@ -68,6 +68,42 @@ void LiteLoaderVersionList::sort() endResetModel(); } +QVariant LiteLoaderVersionList::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (index.row() > count()) + return QVariant(); + + auto version = std::dynamic_pointer_cast<LiteLoaderVersion>(m_vlist[index.row()]); + switch (role) + { + case VersionPointerRole: + return qVariantFromValue(m_vlist[index.row()]); + + case VersionRole: + return version->name(); + + case VersionIdRole: + return version->descriptor(); + + case ParentGameVersionRole: + return version->mcVersion; + + case RecommendedRole: + return version->isLatest; + + default: + return QVariant(); + } +} + +QList<BaseVersionList::ModelRoles> LiteLoaderVersionList::providesRoles() +{ + return {VersionPointerRole, VersionRole, VersionIdRole, ParentGameVersionRole, RecommendedRole}; +} + BaseVersionPtr LiteLoaderVersionList::getLatestStable() const { for (int i = 0; i < m_vlist.length(); i++) diff --git a/logic/liteloader/LiteLoaderVersionList.h b/logic/liteloader/LiteLoaderVersionList.h index fd20fcfa..f3f78349 100644 --- a/logic/liteloader/LiteLoaderVersionList.h +++ b/logic/liteloader/LiteLoaderVersionList.h @@ -78,6 +78,8 @@ public: virtual const BaseVersionPtr at(int i) const; virtual int count() const; virtual void sort(); + virtual QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const; + virtual QList< ModelRoles > providesRoles(); virtual BaseVersionPtr getLatestStable() const; diff --git a/logic/minecraft/MinecraftVersionList.cpp b/logic/minecraft/MinecraftVersionList.cpp index 7b3325e0..f57478e3 100644 --- a/logic/minecraft/MinecraftVersionList.cpp +++ b/logic/minecraft/MinecraftVersionList.cpp @@ -343,6 +343,42 @@ void MinecraftVersionList::sort() endResetModel(); } +QVariant MinecraftVersionList::data(const QModelIndex& index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (index.row() > count()) + return QVariant(); + + auto version = std::dynamic_pointer_cast<MinecraftVersion>(m_vlist[index.row()]); + switch (role) + { + case VersionPointerRole: + return qVariantFromValue(m_vlist[index.row()]); + + case VersionRole: + return version->name(); + + case VersionIdRole: + return version->descriptor(); + + case RecommendedRole: + return version->descriptor() == "1.7.10"; + + case TypeRole: + return version->typeString(); + + default: + return QVariant(); + } +} + +BaseVersionList::RoleList MinecraftVersionList::providesRoles() +{ + return {VersionPointerRole, VersionRole, VersionIdRole, RecommendedRole, TypeRole}; +} + BaseVersionPtr MinecraftVersionList::getLatestStable() const { if(m_lookup.contains(m_latestReleaseID)) @@ -622,4 +658,4 @@ void MinecraftVersionList::finalizeUpdate(QString version) saveCachedList(); } -#include "MinecraftVersionList.moc"
\ No newline at end of file +#include "MinecraftVersionList.moc" diff --git a/logic/minecraft/MinecraftVersionList.h b/logic/minecraft/MinecraftVersionList.h index 3266fc2d..7244d453 100644 --- a/logic/minecraft/MinecraftVersionList.h +++ b/logic/minecraft/MinecraftVersionList.h @@ -50,6 +50,8 @@ public: virtual const BaseVersionPtr at(int i) const; virtual int count() const; virtual void sort(); + virtual QVariant data(const QModelIndex & index, int role) const; + virtual RoleList providesRoles(); virtual BaseVersionPtr getLatestStable() const; |