diff options
author | Petr Mrázek <peterix@gmail.com> | 2017-04-06 23:30:18 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2017-04-07 00:20:02 +0200 |
commit | 643d74f66c2b22660264a393d5c3fa38f68a5d59 (patch) | |
tree | acd7387bdd6599aa1ecb8eb71f8d0d9a03c694c7 | |
parent | f565798650b453ed8c94422096d9b37ba81ebf3e (diff) | |
download | MultiMC-643d74f66c2b22660264a393d5c3fa38f68a5d59.tar MultiMC-643d74f66c2b22660264a393d5c3fa38f68a5d59.tar.gz MultiMC-643d74f66c2b22660264a393d5c3fa38f68a5d59.tar.lz MultiMC-643d74f66c2b22660264a393d5c3fa38f68a5d59.tar.xz MultiMC-643d74f66c2b22660264a393d5c3fa38f68a5d59.zip |
NOISSUE implement recommended versions using the new JSON format
-rw-r--r-- | api/logic/BaseVersionList.cpp | 7 | ||||
-rw-r--r-- | api/logic/BaseVersionList.h | 5 | ||||
-rw-r--r-- | api/logic/meta/JsonFormat.cpp | 5 | ||||
-rw-r--r-- | api/logic/meta/Version.cpp | 16 | ||||
-rw-r--r-- | api/logic/meta/Version.h | 8 | ||||
-rw-r--r-- | api/logic/meta/VersionList.cpp | 15 | ||||
-rw-r--r-- | api/logic/meta/VersionList.h | 2 |
7 files changed, 32 insertions, 26 deletions
diff --git a/api/logic/BaseVersionList.cpp b/api/logic/BaseVersionList.cpp index dae604a2..8b424c11 100644 --- a/api/logic/BaseVersionList.cpp +++ b/api/logic/BaseVersionList.cpp @@ -30,7 +30,7 @@ BaseVersionPtr BaseVersionList::findVersion(const QString &descriptor) return BaseVersionPtr(); } -BaseVersionPtr BaseVersionList::getLatestStable() const +BaseVersionPtr BaseVersionList::getRecommended() const { if (count() <= 0) return BaseVersionPtr(); @@ -38,11 +38,6 @@ BaseVersionPtr BaseVersionList::getLatestStable() const return at(0); } -BaseVersionPtr BaseVersionList::getRecommended() const -{ - return getLatestStable(); -} - QVariant BaseVersionList::data(const QModelIndex &index, int role) const { if (!index.isValid()) diff --git a/api/logic/BaseVersionList.h b/api/logic/BaseVersionList.h index eb3b622a..655bbd43 100644 --- a/api/logic/BaseVersionList.h +++ b/api/logic/BaseVersionList.h @@ -94,11 +94,6 @@ public: virtual BaseVersionPtr findVersion(const QString &descriptor); /*! - * \brief Gets the latest stable version from this list - */ - virtual BaseVersionPtr getLatestStable() const; - - /*! * \brief Gets the recommended version from this list * If the list doesn't support recommended versions, this works exactly as getLatestStable */ diff --git a/api/logic/meta/JsonFormat.cpp b/api/logic/meta/JsonFormat.cpp index 8a063f48..1638105a 100644 --- a/api/logic/meta/JsonFormat.cpp +++ b/api/logic/meta/JsonFormat.cpp @@ -52,6 +52,7 @@ static VersionPtr parseCommonVersion(const QString &uid, const QJsonObject &obj) version->setTime(QDateTime::fromString(requireString(obj, "releaseTime"), Qt::ISODate).toMSecsSinceEpoch() / 1000); version->setType(ensureString(obj, "type", QString())); version->setParentUid(ensureString(obj, "parentUid", QString())); + version->setRecommended(ensureBoolean(obj, "recommended", false)); if(obj.contains("requires")) { QHash<QString, QString> requires; @@ -87,7 +88,9 @@ static BaseEntity::Ptr parseVersionListInternal(const QJsonObject &obj) versions.reserve(versionsRaw.size()); std::transform(versionsRaw.begin(), versionsRaw.end(), std::back_inserter(versions), [uid](const QJsonObject &vObj) { - return parseCommonVersion(uid, vObj); + auto version = parseCommonVersion(uid, vObj); + version->setProvidesRecommendations(); + return version; }); VersionListPtr list = std::make_shared<VersionList>(uid); diff --git a/api/logic/meta/Version.cpp b/api/logic/meta/Version.cpp index 2a8e1780..338e180b 100644 --- a/api/logic/meta/Version.cpp +++ b/api/logic/meta/Version.cpp @@ -53,6 +53,13 @@ void Meta::Version::parse(const QJsonObject& obj) void Meta::Version::merge(const std::shared_ptr<BaseEntity> &other) { VersionPtr version = std::dynamic_pointer_cast<Version>(other); + if(version->m_providesRecommendations) + { + if(m_recommended != version->m_recommended) + { + setRecommended(version->m_recommended); + } + } if (m_type != version->m_type) { setType(version->m_type); @@ -107,3 +114,12 @@ void Meta::Version::setData(const VersionFilePtr &data) m_data = data; } +void Meta::Version::setProvidesRecommendations() +{ + m_providesRecommendations = true; +} + +void Meta::Version::setRecommended(bool recommended) +{ + m_recommended = recommended; +} diff --git a/api/logic/meta/Version.h b/api/logic/meta/Version.h index 8aac8ea1..f132b861 100644 --- a/api/logic/meta/Version.h +++ b/api/logic/meta/Version.h @@ -72,6 +72,10 @@ public: /* con/des */ { return m_data; } + bool isRecommended() const + { + return m_recommended; + } void merge(const std::shared_ptr<BaseEntity> &other) override; void parse(const QJsonObject &obj) override; @@ -83,6 +87,8 @@ public: // for usage by format parsers only void setType(const QString &type); void setTime(const qint64 time); void setRequires(const QHash<QString, QString> &requires); + void setRecommended(bool recommended); + void setProvidesRecommendations(); void setData(const VersionFilePtr &data); signals: @@ -91,6 +97,8 @@ signals: void requiresChanged(); private: + bool m_providesRecommendations = false; + bool m_recommended = false; QString m_name; QString m_uid; QString m_parentUid; diff --git a/api/logic/meta/VersionList.cpp b/api/logic/meta/VersionList.cpp index 41ed1352..0f1404ba 100644 --- a/api/logic/meta/VersionList.cpp +++ b/api/logic/meta/VersionList.cpp @@ -94,8 +94,9 @@ QVariant VersionList::data(const QModelIndex &index, int role) const case RequiresRole: return QVariant::fromValue(version->requires()); case SortRole: return version->rawTime(); case VersionPtrRole: return QVariant::fromValue(version); - case RecommendedRole: return version == getRecommended(); - case LatestRole: return version == getLatestStable(); + case RecommendedRole: return version->isRecommended(); + // FIXME: this should be determined in whatever view/proxy is used... + // case LatestRole: return version == getLatestStable(); default: return QVariant(); } } @@ -158,7 +159,6 @@ void VersionList::setVersions(const QVector<VersionPtr> &versions) setupAddedVersion(i, m_versions.at(i)); } - m_latest = m_versions.isEmpty() ? nullptr : m_versions.first(); auto recommendedIt = std::find_if(m_versions.constBegin(), m_versions.constEnd(), [](const VersionPtr &ptr) { return ptr->type() == "release"; }); m_recommended = recommendedIt == m_versions.constEnd() ? nullptr : *recommendedIt; endResetModel(); @@ -202,11 +202,6 @@ void VersionList::merge(const BaseEntity::Ptr &other) m_lookup.insert(version->uid(), version); endInsertRows(); - if (!m_latest || version->rawTime() > m_latest->rawTime()) - { - m_latest = version; - emit dataChanged(index(0), index(m_versions.size() - 1), QVector<int>() << LatestRole); - } if (!m_recommended || (version->type() == "release" && version->rawTime() > m_recommended->rawTime())) { m_recommended = version; @@ -224,10 +219,6 @@ void VersionList::setupAddedVersion(const int row, const VersionPtr &version) connect(version.get(), &Version::typeChanged, this, [this, row]() { emit dataChanged(index(row), index(row), QVector<int>() << TypeRole); }); } -BaseVersionPtr VersionList::getLatestStable() const -{ - return m_latest; -} BaseVersionPtr VersionList::getRecommended() const { return m_recommended; diff --git a/api/logic/meta/VersionList.h b/api/logic/meta/VersionList.h index faacdbf8..e8016314 100644 --- a/api/logic/meta/VersionList.h +++ b/api/logic/meta/VersionList.h @@ -47,7 +47,6 @@ public: int count() const override; void sortVersions() override; - BaseVersionPtr getLatestStable() const override; BaseVersionPtr getRecommended() const override; QVariant data(const QModelIndex &index, int role) const override; @@ -100,7 +99,6 @@ private: QString m_name; VersionPtr m_recommended; - VersionPtr m_latest; void setupAddedVersion(const int row, const VersionPtr &version); }; |