diff options
author | Andrew <forkk@forkk.net> | 2013-05-03 20:14:38 -0500 |
---|---|---|
committer | Andrew <forkk@forkk.net> | 2013-05-03 20:14:38 -0500 |
commit | 857a4e4dbed88b647619c213d731dc460d034820 (patch) | |
tree | ddff2ab3d6af3fb049b1931cd8b27cbedd7b6ee3 /libmultimc/src/minecraftversionlist.cpp | |
parent | 055198303c7bf15f456687838c37650871596946 (diff) | |
download | MultiMC-857a4e4dbed88b647619c213d731dc460d034820.tar MultiMC-857a4e4dbed88b647619c213d731dc460d034820.tar.gz MultiMC-857a4e4dbed88b647619c213d731dc460d034820.tar.lz MultiMC-857a4e4dbed88b647619c213d731dc460d034820.tar.xz MultiMC-857a4e4dbed88b647619c213d731dc460d034820.zip |
Implemented version list sorting.
Resolves MMC-8:
https://jira.forkk.net/browse/MMC-8
Diffstat (limited to 'libmultimc/src/minecraftversionlist.cpp')
-rw-r--r-- | libmultimc/src/minecraftversionlist.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/libmultimc/src/minecraftversionlist.cpp b/libmultimc/src/minecraftversionlist.cpp index ce02a769..abbae991 100644 --- a/libmultimc/src/minecraftversionlist.cpp +++ b/libmultimc/src/minecraftversionlist.cpp @@ -25,6 +25,8 @@ #include <QJsonValue> #include <QJsonParseError> +#include <QtAlgorithms> + #include <QtNetwork> #define MCVLIST_URLBASE "http://s3.amazonaws.com/Minecraft.Download/versions/" @@ -78,6 +80,18 @@ void MinecraftVersionList::printToStdOut() const } } +bool cmpVersions(const InstVersion *first, const InstVersion *second) +{ + return !first->isLessThan(*second); +} + +void MinecraftVersionList::sort() +{ + beginResetModel(); + qSort(m_vlist.begin(), m_vlist.end(), cmpVersions); + endResetModel(); +} + MinecraftVersionList &MinecraftVersionList::getMainList() { return mcVList; @@ -108,6 +122,9 @@ void MinecraftVersionList::updateListData(QList<InstVersion *> versions) // tempList (and vice-versa). Now we just free the memory. while (!tempList.isEmpty()) delete tempList.takeFirst(); + + // NOW SORT!! + sort(); } inline QDomElement getDomElementByTagName(QDomElement parent, QString tagname) @@ -125,6 +142,22 @@ inline QDateTime timeFromS3Time(QString str) return QDateTime::fromString(str, fmt); } +inline QDateTime timeFromMCVListTime(QString str) +{ + int operatorPos = str.indexOf("+", str.indexOf("T")); + if (operatorPos == -1) + operatorPos = str.indexOf("-", str.indexOf("T")); + if (operatorPos) + operatorPos = str.length(); + + const QString fmt("yyyy-MM-dd'T'HH:mm:ss'+02:00'"); + + // It's a dark templar! + QDateTime dt = QDateTime::fromString(str.left(operatorPos), fmt); + return dt; + +} + inline void waitForNetRequest(QNetworkReply *netReply) { QEventLoop loop; @@ -234,7 +267,11 @@ bool MCVListLoadTask::loadFromVList() // Now, process that info and add the version to the list. // Parse the timestamp. - QDateTime versionTime = timeFromS3Time(versionTimeStr); + QDateTime versionTime = timeFromMCVListTime(versionTimeStr); + + Q_ASSERT_X(versionTime.isValid(), "loadFromVList", + QString("in versions array, index %1's timestamp failed to parse"). + arg(i).toUtf8()); // Parse the type. MinecraftVersion::VersionType versionType; |