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/java | |
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/java')
-rw-r--r-- | logic/java/JavaVersionList.cpp | 139 | ||||
-rw-r--r-- | logic/java/JavaVersionList.h | 26 |
2 files changed, 75 insertions, 90 deletions
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: |