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 ++++++++++++++++++++++++++++++++++------ 1 file changed, 81 insertions(+), 12 deletions(-) (limited to 'logic/lists/ForgeVersionList.cpp') 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; -- cgit v1.2.3