GH-328 overhaul all relevant version lists
This commit is contained in:
@ -50,63 +50,26 @@ QVariant BaseVersionList::data(const QModelIndex &index, int role) const
|
||||
|
||||
switch (role)
|
||||
{
|
||||
case Qt::DisplayRole:
|
||||
switch (index.column())
|
||||
{
|
||||
case NameColumn:
|
||||
return version->name();
|
||||
|
||||
case TypeColumn:
|
||||
return version->typeString();
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
case Qt::ToolTipRole:
|
||||
return version->descriptor();
|
||||
|
||||
case VersionPointerRole:
|
||||
return qVariantFromValue(version);
|
||||
|
||||
case VersionRole:
|
||||
return version->name();
|
||||
|
||||
case VersionIdRole:
|
||||
return version->descriptor();
|
||||
|
||||
case TypeRole:
|
||||
return version->typeString();
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
QVariant BaseVersionList::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
BaseVersionList::RoleList BaseVersionList::providesRoles()
|
||||
{
|
||||
switch (role)
|
||||
{
|
||||
case Qt::DisplayRole:
|
||||
switch (section)
|
||||
{
|
||||
case NameColumn:
|
||||
return tr("Name");
|
||||
|
||||
case TypeColumn:
|
||||
return tr("Type");
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
case Qt::ToolTipRole:
|
||||
switch (section)
|
||||
{
|
||||
case NameColumn:
|
||||
return tr("The name of the version.");
|
||||
|
||||
case TypeColumn:
|
||||
return tr("The version's type.");
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
return {VersionPointerRole, VersionRole, VersionIdRole, TypeRole};
|
||||
}
|
||||
|
||||
int BaseVersionList::rowCount(const QModelIndex &parent) const
|
||||
@ -117,5 +80,5 @@ int BaseVersionList::rowCount(const QModelIndex &parent) const
|
||||
|
||||
int BaseVersionList::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
return 2;
|
||||
return 1;
|
||||
}
|
||||
|
@ -41,20 +41,17 @@ class BaseVersionList : public QAbstractListModel
|
||||
public:
|
||||
enum ModelRoles
|
||||
{
|
||||
VersionPointerRole = 0x34B1CB48
|
||||
};
|
||||
|
||||
enum VListColumns
|
||||
{
|
||||
// First column - Name
|
||||
NameColumn = 0,
|
||||
|
||||
// Second column - Type
|
||||
TypeColumn,
|
||||
|
||||
// Third column - Timestamp
|
||||
TimeColumn
|
||||
VersionPointerRole = Qt::UserRole,
|
||||
VersionRole,
|
||||
VersionIdRole,
|
||||
ParentGameVersionRole,
|
||||
RecommendedRole,
|
||||
TypeRole,
|
||||
BranchRole,
|
||||
PathRole,
|
||||
ArchitectureRole
|
||||
};
|
||||
typedef QList<ModelRoles> RoleList;
|
||||
|
||||
explicit BaseVersionList(QObject *parent = 0);
|
||||
|
||||
@ -78,10 +75,12 @@ public:
|
||||
|
||||
//////// List Model Functions ////////
|
||||
virtual QVariant data(const QModelIndex &index, int role) const;
|
||||
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
||||
virtual int rowCount(const QModelIndex &parent) const;
|
||||
virtual int columnCount(const QModelIndex &parent) const;
|
||||
|
||||
//! which roles are provided by this version list?
|
||||
virtual RoleList providesRoles();
|
||||
|
||||
/*!
|
||||
* \brief Finds a version by its descriptor.
|
||||
* \param The descriptor of the version to find.
|
||||
|
@ -51,7 +51,7 @@ int ForgeVersionList::count() const
|
||||
|
||||
int ForgeVersionList::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
return 3;
|
||||
return 1;
|
||||
}
|
||||
|
||||
QVariant ForgeVersionList::data(const QModelIndex &index, int role) const
|
||||
@ -65,71 +65,32 @@ QVariant ForgeVersionList::data(const QModelIndex &index, int role) const
|
||||
auto version = std::dynamic_pointer_cast<ForgeVersion>(m_vlist[index.row()]);
|
||||
switch (role)
|
||||
{
|
||||
case Qt::DisplayRole:
|
||||
switch (index.column())
|
||||
{
|
||||
case 0:
|
||||
return version->name();
|
||||
|
||||
case 1:
|
||||
return version->mcver_sane;
|
||||
|
||||
case 2:
|
||||
return version->typeString();
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
case Qt::ToolTipRole:
|
||||
return version->descriptor();
|
||||
|
||||
case VersionPointerRole:
|
||||
return qVariantFromValue(m_vlist[index.row()]);
|
||||
|
||||
case VersionRole:
|
||||
return version->name();
|
||||
|
||||
case VersionIdRole:
|
||||
return version->descriptor();
|
||||
|
||||
case ParentGameVersionRole:
|
||||
return version->mcver_sane;
|
||||
|
||||
case RecommendedRole:
|
||||
return version->is_recommended;
|
||||
|
||||
case BranchRole:
|
||||
return version->branch;
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
QVariant ForgeVersionList::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
QList<BaseVersionList::ModelRoles> ForgeVersionList::providesRoles()
|
||||
{
|
||||
switch (role)
|
||||
{
|
||||
case Qt::DisplayRole:
|
||||
switch (section)
|
||||
{
|
||||
case 0:
|
||||
return tr("Version");
|
||||
|
||||
case 1:
|
||||
return tr("Minecraft");
|
||||
|
||||
case 2:
|
||||
return tr("Type");
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
case Qt::ToolTipRole:
|
||||
switch (section)
|
||||
{
|
||||
case 0:
|
||||
return tr("The name of the version.");
|
||||
|
||||
case 1:
|
||||
return tr("Minecraft version");
|
||||
|
||||
case 2:
|
||||
return tr("The version's type.");
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
return {VersionPointerRole, VersionRole, VersionIdRole, ParentGameVersionRole, RecommendedRole, BranchRole};
|
||||
}
|
||||
|
||||
BaseVersionPtr ForgeVersionList::getLatestStable() const
|
||||
@ -296,6 +257,7 @@ bool ForgeListLoadTask::parseForgeList(QList<BaseVersionPtr> &out)
|
||||
|
||||
bool ForgeListLoadTask::parseForgeGradleList(QList<BaseVersionPtr> &out)
|
||||
{
|
||||
QMap<int, std::shared_ptr<ForgeVersion>> lookup;
|
||||
QByteArray data;
|
||||
{
|
||||
auto dlJob = gradleListDownload;
|
||||
@ -402,6 +364,29 @@ bool ForgeListLoadTask::parseForgeGradleList(QList<BaseVersionPtr> &out)
|
||||
fVersion->installer_filename = installer_filename;
|
||||
fVersion->type = ForgeVersion::Gradle;
|
||||
out.append(fVersion);
|
||||
lookup[fVersion->m_buildnr] = fVersion;
|
||||
}
|
||||
QJsonObject promos = root.value("promos").toObject();
|
||||
for (auto it = promos.begin(); it != promos.end(); ++it)
|
||||
{
|
||||
QString key = it.key();
|
||||
int build = it.value().toInt();
|
||||
QRegularExpression regexp("^(?<mcversion>[0-9]+(.[0-9]+)*)-(?<label>[a-z]+)$");
|
||||
auto match = regexp.match(key);
|
||||
if(!match.hasMatch())
|
||||
{
|
||||
qDebug() << key << "doesn't match." << "build" << build;
|
||||
continue;
|
||||
}
|
||||
|
||||
QString label = match.captured("label");
|
||||
if(label != "recommended")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
QString mcversion = match.captured("mcversion");
|
||||
qDebug() << "Forge build" << build << "is the" << label << "for Minecraft" << mcversion << QString("<%1>").arg(key);
|
||||
lookup[build]->is_recommended = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -44,7 +44,8 @@ public:
|
||||
ForgeVersionPtr findVersionByVersionNr(QString version);
|
||||
|
||||
virtual QVariant data(const QModelIndex &index, int role) const;
|
||||
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
||||
virtual QList<ModelRoles> providesRoles() override;
|
||||
|
||||
virtual int columnCount(const QModelIndex &parent) const;
|
||||
|
||||
protected:
|
||||
|
@ -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()
|
||||
|
@ -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:
|
||||
|
@ -68,6 +68,42 @@ void LiteLoaderVersionList::sort()
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
QVariant LiteLoaderVersionList::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
if (index.row() > count())
|
||||
return QVariant();
|
||||
|
||||
auto version = std::dynamic_pointer_cast<LiteLoaderVersion>(m_vlist[index.row()]);
|
||||
switch (role)
|
||||
{
|
||||
case VersionPointerRole:
|
||||
return qVariantFromValue(m_vlist[index.row()]);
|
||||
|
||||
case VersionRole:
|
||||
return version->name();
|
||||
|
||||
case VersionIdRole:
|
||||
return version->descriptor();
|
||||
|
||||
case ParentGameVersionRole:
|
||||
return version->mcVersion;
|
||||
|
||||
case RecommendedRole:
|
||||
return version->isLatest;
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
QList<BaseVersionList::ModelRoles> LiteLoaderVersionList::providesRoles()
|
||||
{
|
||||
return {VersionPointerRole, VersionRole, VersionIdRole, ParentGameVersionRole, RecommendedRole};
|
||||
}
|
||||
|
||||
BaseVersionPtr LiteLoaderVersionList::getLatestStable() const
|
||||
{
|
||||
for (int i = 0; i < m_vlist.length(); i++)
|
||||
|
@ -78,6 +78,8 @@ public:
|
||||
virtual const BaseVersionPtr at(int i) const;
|
||||
virtual int count() const;
|
||||
virtual void sort();
|
||||
virtual QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const;
|
||||
virtual QList< ModelRoles > providesRoles();
|
||||
|
||||
virtual BaseVersionPtr getLatestStable() const;
|
||||
|
||||
|
@ -343,6 +343,42 @@ void MinecraftVersionList::sort()
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
QVariant MinecraftVersionList::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
if (index.row() > count())
|
||||
return QVariant();
|
||||
|
||||
auto version = std::dynamic_pointer_cast<MinecraftVersion>(m_vlist[index.row()]);
|
||||
switch (role)
|
||||
{
|
||||
case VersionPointerRole:
|
||||
return qVariantFromValue(m_vlist[index.row()]);
|
||||
|
||||
case VersionRole:
|
||||
return version->name();
|
||||
|
||||
case VersionIdRole:
|
||||
return version->descriptor();
|
||||
|
||||
case RecommendedRole:
|
||||
return version->descriptor() == "1.7.10";
|
||||
|
||||
case TypeRole:
|
||||
return version->typeString();
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
BaseVersionList::RoleList MinecraftVersionList::providesRoles()
|
||||
{
|
||||
return {VersionPointerRole, VersionRole, VersionIdRole, RecommendedRole, TypeRole};
|
||||
}
|
||||
|
||||
BaseVersionPtr MinecraftVersionList::getLatestStable() const
|
||||
{
|
||||
if(m_lookup.contains(m_latestReleaseID))
|
||||
@ -622,4 +658,4 @@ void MinecraftVersionList::finalizeUpdate(QString version)
|
||||
saveCachedList();
|
||||
}
|
||||
|
||||
#include "MinecraftVersionList.moc"
|
||||
#include "MinecraftVersionList.moc"
|
||||
|
@ -50,6 +50,8 @@ public:
|
||||
virtual const BaseVersionPtr at(int i) const;
|
||||
virtual int count() const;
|
||||
virtual void sort();
|
||||
virtual QVariant data(const QModelIndex & index, int role) const;
|
||||
virtual RoleList providesRoles();
|
||||
|
||||
virtual BaseVersionPtr getLatestStable() const;
|
||||
|
||||
|
Reference in New Issue
Block a user