From b979d0ce5da515793a02802a6421ef607a498323 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 18 Sep 2013 00:00:35 +0200 Subject: Implement legacy forge button! Many refactors of the task system. Progress dialog now accepts generic ProgressProvider objects --- logic/lists/ForgeVersionList.cpp | 93 +++++++++++++++++++++++++++++++++----- logic/lists/ForgeVersionList.h | 10 ++-- logic/lists/MinecraftVersionList.h | 2 +- 3 files changed, 89 insertions(+), 16 deletions(-) (limited to 'logic/lists') diff --git a/logic/lists/ForgeVersionList.cpp b/logic/lists/ForgeVersionList.cpp index f45b8b6b..412c04fe 100644 --- a/logic/lists/ForgeVersionList.cpp +++ b/logic/lists/ForgeVersionList.cpp @@ -50,21 +50,90 @@ int ForgeVersionList::count() const { return m_vlist.count(); } -/* -bool cmpVersions(BaseVersionPtr first, BaseVersionPtr second) + +int ForgeVersionList::columnCount(const QModelIndex& parent) const { - const BaseVersion & left = *first; - const BaseVersion & right = *second; - return left > right; + return 3; } -void MinecraftVersionList::sort() +QVariant ForgeVersionList::data(const QModelIndex &index, int role) const { - beginResetModel(); - qSort(m_vlist.begin(), m_vlist.end(), cmpVersions); - endResetModel(); + if (!index.isValid()) + return QVariant(); + + if (index.row() > count()) + return QVariant(); + + auto version = m_vlist[index.row()].dynamicCast(); + switch (role) + { + case Qt::DisplayRole: + switch (index.column()) + { + case 0: + return version->name(); + + case 1: + return version->mcver; + + 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 "Version"; + + case 1: + return "Minecraft"; + + case 2: + return "Type"; + + default: + return QVariant(); + } + + case Qt::ToolTipRole: + switch (section) + { + case 0: + return "The name of the version."; + + case 1: + return "Minecraft version"; + + case 2: + return "The version's type."; + + default: + return QVariant(); + } + + default: + return QVariant(); + } +} + BaseVersionPtr ForgeVersionList::getLatestStable() const { return BaseVersionPtr(); @@ -99,7 +168,7 @@ void ForgeListLoadTask::executeTask() listJob.reset(job); connect(listJob.data(), SIGNAL(succeeded()), SLOT(list_downloaded())); connect(listJob.data(), SIGNAL(failed()), SLOT(versionFileFailed())); - connect(listJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64))); + connect(listJob.data(), SIGNAL(progress(qint64,qint64)), SIGNAL(progress(qint64,qint64))); listJob->start(); } @@ -148,7 +217,7 @@ void ForgeListLoadTask::list_downloaded() int build_nr = obj.value("build").toDouble(0); if(!build_nr) continue; - QJsonArray files = root.value("files").toArray(); + QJsonArray files = obj.value("files").toArray(); QString url, jobbuildver, mcver, buildtype, filename; QString changelog_url, installer_url; bool valid = false; diff --git a/logic/lists/ForgeVersionList.h b/logic/lists/ForgeVersionList.h index 8d4a2d46..ca6b27bc 100644 --- a/logic/lists/ForgeVersionList.h +++ b/logic/lists/ForgeVersionList.h @@ -26,7 +26,7 @@ #include "logic/net/DownloadJob.h" class ForgeVersion; -typedef QSharedPointer PtrForgeVersion; +typedef QSharedPointer ForgeVersionPtr; struct ForgeVersion : public BaseVersion { @@ -36,7 +36,7 @@ struct ForgeVersion : public BaseVersion }; virtual QString name() { - return "Forge " + jobbuildver + " (" + mcver + ")"; + return "Forge " + jobbuildver; }; virtual QString typeString() const { @@ -71,8 +71,12 @@ public: virtual BaseVersionPtr getLatestStable() const; + 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; + protected: - QList m_vlist; + QList m_vlist; bool m_loaded; diff --git a/logic/lists/MinecraftVersionList.h b/logic/lists/MinecraftVersionList.h index 8937ba7b..fb28ddfe 100644 --- a/logic/lists/MinecraftVersionList.h +++ b/logic/lists/MinecraftVersionList.h @@ -49,7 +49,7 @@ protected: bool m_loaded; protected slots: - virtual void updateListData(QList versions); + virtual void updateListData(QList versions); }; class MCVListLoadTask : public Task -- cgit v1.2.3