pre-commit run --all-files
This commit is contained in:
parent
513361df25
commit
4f9fdcc293
@ -53,16 +53,16 @@ namespace ModpacksCH {
|
|||||||
class PackInstallTask final : public InstanceTask {
|
class PackInstallTask final : public InstanceTask {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit PackInstallTask(Modpack pack, QString version, QWidget* parent = nullptr);
|
explicit PackInstallTask(Modpack pack, QString version, QWidget* parent = nullptr);
|
||||||
~PackInstallTask() override = default;
|
~PackInstallTask() override = default;
|
||||||
|
|
||||||
bool abort() override;
|
bool abort() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void executeTask() override;
|
void executeTask() override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onManifestDownloadSucceeded();
|
void onManifestDownloadSucceeded();
|
||||||
void onResolveModsSucceeded();
|
void onResolveModsSucceeded();
|
||||||
void onCreateInstanceSucceeded();
|
void onCreateInstanceSucceeded();
|
||||||
@ -73,13 +73,13 @@ private slots:
|
|||||||
void onCreateInstanceFailed(QString reason);
|
void onCreateInstanceFailed(QString reason);
|
||||||
void onModDownloadFailed(QString reason);
|
void onModDownloadFailed(QString reason);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void resolveMods();
|
void resolveMods();
|
||||||
void createInstance();
|
void createInstance();
|
||||||
void downloadPack();
|
void downloadPack();
|
||||||
void copyBlockedMods();
|
void copyBlockedMods();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NetJob::Ptr m_net_job = nullptr;
|
NetJob::Ptr m_net_job = nullptr;
|
||||||
shared_qobject_ptr<Flame::FileResolvingTask> m_mod_id_resolver_task = nullptr;
|
shared_qobject_ptr<Flame::FileResolvingTask> m_mod_id_resolver_task = nullptr;
|
||||||
|
|
||||||
@ -94,8 +94,8 @@ private:
|
|||||||
QMap<QString, QString> m_files_to_copy;
|
QMap<QString, QString> m_files_to_copy;
|
||||||
QList<BlockedMod> m_blocked_mods;
|
QList<BlockedMod> m_blocked_mods;
|
||||||
|
|
||||||
//FIXME: nuke
|
// FIXME: nuke
|
||||||
QWidget* m_parent;
|
QWidget* m_parent;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace ModpacksCH
|
||||||
|
@ -38,20 +38,20 @@
|
|||||||
|
|
||||||
#include "Json.h"
|
#include "Json.h"
|
||||||
|
|
||||||
static void loadSpecs(ModpacksCH::Specs & s, QJsonObject & obj)
|
static void loadSpecs(ModpacksCH::Specs& s, QJsonObject& obj)
|
||||||
{
|
{
|
||||||
s.id = Json::requireInteger(obj, "id");
|
s.id = Json::requireInteger(obj, "id");
|
||||||
s.minimum = Json::requireInteger(obj, "minimum");
|
s.minimum = Json::requireInteger(obj, "minimum");
|
||||||
s.recommended = Json::requireInteger(obj, "recommended");
|
s.recommended = Json::requireInteger(obj, "recommended");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loadTag(ModpacksCH::Tag & t, QJsonObject & obj)
|
static void loadTag(ModpacksCH::Tag& t, QJsonObject& obj)
|
||||||
{
|
{
|
||||||
t.id = Json::requireInteger(obj, "id");
|
t.id = Json::requireInteger(obj, "id");
|
||||||
t.name = Json::requireString(obj, "name");
|
t.name = Json::requireString(obj, "name");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loadArt(ModpacksCH::Art & a, QJsonObject & obj)
|
static void loadArt(ModpacksCH::Art& a, QJsonObject& obj)
|
||||||
{
|
{
|
||||||
a.id = Json::requireInteger(obj, "id");
|
a.id = Json::requireInteger(obj, "id");
|
||||||
a.url = Json::requireString(obj, "url");
|
a.url = Json::requireString(obj, "url");
|
||||||
@ -64,7 +64,7 @@ static void loadArt(ModpacksCH::Art & a, QJsonObject & obj)
|
|||||||
a.updated = Json::requireInteger(obj, "updated");
|
a.updated = Json::requireInteger(obj, "updated");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loadAuthor(ModpacksCH::Author & a, QJsonObject & obj)
|
static void loadAuthor(ModpacksCH::Author& a, QJsonObject& obj)
|
||||||
{
|
{
|
||||||
a.id = Json::requireInteger(obj, "id");
|
a.id = Json::requireInteger(obj, "id");
|
||||||
a.name = Json::requireString(obj, "name");
|
a.name = Json::requireString(obj, "name");
|
||||||
@ -73,7 +73,7 @@ static void loadAuthor(ModpacksCH::Author & a, QJsonObject & obj)
|
|||||||
a.updated = Json::requireInteger(obj, "updated");
|
a.updated = Json::requireInteger(obj, "updated");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loadVersionInfo(ModpacksCH::VersionInfo & v, QJsonObject & obj)
|
static void loadVersionInfo(ModpacksCH::VersionInfo& v, QJsonObject& obj)
|
||||||
{
|
{
|
||||||
v.id = Json::requireInteger(obj, "id");
|
v.id = Json::requireInteger(obj, "id");
|
||||||
v.name = Json::requireString(obj, "name");
|
v.name = Json::requireString(obj, "name");
|
||||||
@ -83,7 +83,7 @@ static void loadVersionInfo(ModpacksCH::VersionInfo & v, QJsonObject & obj)
|
|||||||
loadSpecs(v.specs, specs);
|
loadSpecs(v.specs, specs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModpacksCH::loadModpack(ModpacksCH::Modpack & m, QJsonObject & obj)
|
void ModpacksCH::loadModpack(ModpacksCH::Modpack& m, QJsonObject& obj)
|
||||||
{
|
{
|
||||||
m.id = Json::requireInteger(obj, "id");
|
m.id = Json::requireInteger(obj, "id");
|
||||||
m.name = Json::requireString(obj, "name");
|
m.name = Json::requireString(obj, "name");
|
||||||
@ -96,32 +96,28 @@ void ModpacksCH::loadModpack(ModpacksCH::Modpack & m, QJsonObject & obj)
|
|||||||
m.updated = Json::requireInteger(obj, "updated");
|
m.updated = Json::requireInteger(obj, "updated");
|
||||||
m.refreshed = Json::requireInteger(obj, "refreshed");
|
m.refreshed = Json::requireInteger(obj, "refreshed");
|
||||||
auto artArr = Json::requireArray(obj, "art");
|
auto artArr = Json::requireArray(obj, "art");
|
||||||
for (QJsonValueRef artRaw : artArr)
|
for (QJsonValueRef artRaw : artArr) {
|
||||||
{
|
|
||||||
auto artObj = Json::requireObject(artRaw);
|
auto artObj = Json::requireObject(artRaw);
|
||||||
ModpacksCH::Art art;
|
ModpacksCH::Art art;
|
||||||
loadArt(art, artObj);
|
loadArt(art, artObj);
|
||||||
m.art.append(art);
|
m.art.append(art);
|
||||||
}
|
}
|
||||||
auto authorArr = Json::requireArray(obj, "authors");
|
auto authorArr = Json::requireArray(obj, "authors");
|
||||||
for (QJsonValueRef authorRaw : authorArr)
|
for (QJsonValueRef authorRaw : authorArr) {
|
||||||
{
|
|
||||||
auto authorObj = Json::requireObject(authorRaw);
|
auto authorObj = Json::requireObject(authorRaw);
|
||||||
ModpacksCH::Author author;
|
ModpacksCH::Author author;
|
||||||
loadAuthor(author, authorObj);
|
loadAuthor(author, authorObj);
|
||||||
m.authors.append(author);
|
m.authors.append(author);
|
||||||
}
|
}
|
||||||
auto versionArr = Json::requireArray(obj, "versions");
|
auto versionArr = Json::requireArray(obj, "versions");
|
||||||
for (QJsonValueRef versionRaw : versionArr)
|
for (QJsonValueRef versionRaw : versionArr) {
|
||||||
{
|
|
||||||
auto versionObj = Json::requireObject(versionRaw);
|
auto versionObj = Json::requireObject(versionRaw);
|
||||||
ModpacksCH::VersionInfo version;
|
ModpacksCH::VersionInfo version;
|
||||||
loadVersionInfo(version, versionObj);
|
loadVersionInfo(version, versionObj);
|
||||||
m.versions.append(version);
|
m.versions.append(version);
|
||||||
}
|
}
|
||||||
auto tagArr = Json::requireArray(obj, "tags");
|
auto tagArr = Json::requireArray(obj, "tags");
|
||||||
for (QJsonValueRef tagRaw : tagArr)
|
for (QJsonValueRef tagRaw : tagArr) {
|
||||||
{
|
|
||||||
auto tagObj = Json::requireObject(tagRaw);
|
auto tagObj = Json::requireObject(tagRaw);
|
||||||
ModpacksCH::Tag tag;
|
ModpacksCH::Tag tag;
|
||||||
loadTag(tag, tagObj);
|
loadTag(tag, tagObj);
|
||||||
@ -130,7 +126,7 @@ void ModpacksCH::loadModpack(ModpacksCH::Modpack & m, QJsonObject & obj)
|
|||||||
m.updated = Json::requireInteger(obj, "updated");
|
m.updated = Json::requireInteger(obj, "updated");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loadVersionTarget(ModpacksCH::VersionTarget & a, QJsonObject & obj)
|
static void loadVersionTarget(ModpacksCH::VersionTarget& a, QJsonObject& obj)
|
||||||
{
|
{
|
||||||
a.id = Json::requireInteger(obj, "id");
|
a.id = Json::requireInteger(obj, "id");
|
||||||
a.name = Json::requireString(obj, "name");
|
a.name = Json::requireString(obj, "name");
|
||||||
@ -139,7 +135,7 @@ static void loadVersionTarget(ModpacksCH::VersionTarget & a, QJsonObject & obj)
|
|||||||
a.updated = Json::requireInteger(obj, "updated");
|
a.updated = Json::requireInteger(obj, "updated");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loadVersionFile(ModpacksCH::VersionFile & a, QJsonObject & obj)
|
static void loadVersionFile(ModpacksCH::VersionFile& a, QJsonObject& obj)
|
||||||
{
|
{
|
||||||
a.id = Json::requireInteger(obj, "id");
|
a.id = Json::requireInteger(obj, "id");
|
||||||
a.type = Json::requireString(obj, "type");
|
a.type = Json::requireString(obj, "type");
|
||||||
@ -158,7 +154,7 @@ static void loadVersionFile(ModpacksCH::VersionFile & a, QJsonObject & obj)
|
|||||||
a.curseforge.file_id = Json::ensureInteger(curseforgeObj, "file");
|
a.curseforge.file_id = Json::ensureInteger(curseforgeObj, "file");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModpacksCH::loadVersion(ModpacksCH::Version & m, QJsonObject & obj)
|
void ModpacksCH::loadVersion(ModpacksCH::Version& m, QJsonObject& obj)
|
||||||
{
|
{
|
||||||
m.id = Json::requireInteger(obj, "id");
|
m.id = Json::requireInteger(obj, "id");
|
||||||
m.parent = Json::requireInteger(obj, "parent");
|
m.parent = Json::requireInteger(obj, "parent");
|
||||||
@ -171,16 +167,14 @@ void ModpacksCH::loadVersion(ModpacksCH::Version & m, QJsonObject & obj)
|
|||||||
auto specs = Json::requireObject(obj, "specs");
|
auto specs = Json::requireObject(obj, "specs");
|
||||||
loadSpecs(m.specs, specs);
|
loadSpecs(m.specs, specs);
|
||||||
auto targetArr = Json::requireArray(obj, "targets");
|
auto targetArr = Json::requireArray(obj, "targets");
|
||||||
for (QJsonValueRef targetRaw : targetArr)
|
for (QJsonValueRef targetRaw : targetArr) {
|
||||||
{
|
|
||||||
auto versionObj = Json::requireObject(targetRaw);
|
auto versionObj = Json::requireObject(targetRaw);
|
||||||
ModpacksCH::VersionTarget target;
|
ModpacksCH::VersionTarget target;
|
||||||
loadVersionTarget(target, versionObj);
|
loadVersionTarget(target, versionObj);
|
||||||
m.targets.append(target);
|
m.targets.append(target);
|
||||||
}
|
}
|
||||||
auto fileArr = Json::requireArray(obj, "files");
|
auto fileArr = Json::requireArray(obj, "files");
|
||||||
for (QJsonValueRef fileRaw : fileArr)
|
for (QJsonValueRef fileRaw : fileArr) {
|
||||||
{
|
|
||||||
auto fileObj = Json::requireObject(fileRaw);
|
auto fileObj = Json::requireObject(fileRaw);
|
||||||
ModpacksCH::VersionFile file;
|
ModpacksCH::VersionFile file;
|
||||||
loadVersionFile(file, fileObj);
|
loadVersionFile(file, fileObj);
|
||||||
@ -188,8 +182,8 @@ void ModpacksCH::loadVersion(ModpacksCH::Version & m, QJsonObject & obj)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//static void loadVersionChangelog(ModpacksCH::VersionChangelog & m, QJsonObject & obj)
|
// static void loadVersionChangelog(ModpacksCH::VersionChangelog & m, QJsonObject & obj)
|
||||||
//{
|
//{
|
||||||
// m.content = Json::requireString(obj, "content");
|
// m.content = Json::requireString(obj, "content");
|
||||||
// m.updated = Json::requireInteger(obj, "updated");
|
// m.updated = Json::requireInteger(obj, "updated");
|
||||||
//}
|
// }
|
||||||
|
@ -36,30 +36,26 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QString>
|
|
||||||
#include <QVector>
|
|
||||||
#include <QUrl>
|
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
|
#include <QString>
|
||||||
|
#include <QUrl>
|
||||||
|
#include <QVector>
|
||||||
|
|
||||||
namespace ModpacksCH
|
namespace ModpacksCH {
|
||||||
{
|
|
||||||
|
|
||||||
struct Specs
|
struct Specs {
|
||||||
{
|
|
||||||
int id;
|
int id;
|
||||||
int minimum;
|
int minimum;
|
||||||
int recommended;
|
int recommended;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Tag
|
struct Tag {
|
||||||
{
|
|
||||||
int id;
|
int id;
|
||||||
QString name;
|
QString name;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Art
|
struct Art {
|
||||||
{
|
|
||||||
int id;
|
int id;
|
||||||
QString url;
|
QString url;
|
||||||
QString type;
|
QString type;
|
||||||
@ -71,8 +67,7 @@ struct Art
|
|||||||
int64_t updated;
|
int64_t updated;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Author
|
struct Author {
|
||||||
{
|
|
||||||
int id;
|
int id;
|
||||||
QString name;
|
QString name;
|
||||||
QString type;
|
QString type;
|
||||||
@ -80,8 +75,7 @@ struct Author
|
|||||||
int64_t updated;
|
int64_t updated;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VersionInfo
|
struct VersionInfo {
|
||||||
{
|
|
||||||
int id;
|
int id;
|
||||||
QString name;
|
QString name;
|
||||||
QString type;
|
QString type;
|
||||||
@ -89,8 +83,7 @@ struct VersionInfo
|
|||||||
Specs specs;
|
Specs specs;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Modpack
|
struct Modpack {
|
||||||
{
|
|
||||||
int id;
|
int id;
|
||||||
QString name;
|
QString name;
|
||||||
QString synopsis;
|
QString synopsis;
|
||||||
@ -107,8 +100,7 @@ struct Modpack
|
|||||||
QVector<Tag> tags;
|
QVector<Tag> tags;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VersionTarget
|
struct VersionTarget {
|
||||||
{
|
|
||||||
int id;
|
int id;
|
||||||
QString type;
|
QString type;
|
||||||
QString name;
|
QString name;
|
||||||
@ -116,14 +108,12 @@ struct VersionTarget
|
|||||||
int64_t updated;
|
int64_t updated;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VersionFileCurseForge
|
struct VersionFileCurseForge {
|
||||||
{
|
|
||||||
int project_id;
|
int project_id;
|
||||||
int file_id;
|
int file_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VersionFile
|
struct VersionFile {
|
||||||
{
|
|
||||||
int id;
|
int id;
|
||||||
QString type;
|
QString type;
|
||||||
QString path;
|
QString path;
|
||||||
@ -139,8 +129,7 @@ struct VersionFile
|
|||||||
VersionFileCurseForge curseforge;
|
VersionFileCurseForge curseforge;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Version
|
struct Version {
|
||||||
{
|
|
||||||
int id;
|
int id;
|
||||||
int parent;
|
int parent;
|
||||||
QString name;
|
QString name;
|
||||||
@ -154,15 +143,14 @@ struct Version
|
|||||||
QVector<VersionFile> files;
|
QVector<VersionFile> files;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VersionChangelog
|
struct VersionChangelog {
|
||||||
{
|
|
||||||
QString content;
|
QString content;
|
||||||
int64_t updated;
|
int64_t updated;
|
||||||
};
|
};
|
||||||
|
|
||||||
void loadModpack(Modpack & m, QJsonObject & obj);
|
void loadModpack(Modpack& m, QJsonObject& obj);
|
||||||
|
|
||||||
void loadVersion(Version & m, QJsonObject & obj);
|
void loadVersion(Version& m, QJsonObject& obj);
|
||||||
}
|
} // namespace ModpacksCH
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(ModpacksCH::Modpack)
|
Q_DECLARE_METATYPE(ModpacksCH::Modpack)
|
||||||
|
@ -17,18 +17,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "FetchFlameAPIKey.h"
|
#include "FetchFlameAPIKey.h"
|
||||||
#include "Application.h"
|
|
||||||
#include <BuildConfig.h>
|
#include <BuildConfig.h>
|
||||||
#include <Json.h>
|
#include <Json.h>
|
||||||
|
#include "Application.h"
|
||||||
|
|
||||||
#include <ui/dialogs/ProgressDialog.h>
|
|
||||||
#include <ui/dialogs/CustomMessageBox.h>
|
#include <ui/dialogs/CustomMessageBox.h>
|
||||||
|
#include <ui/dialogs/ProgressDialog.h>
|
||||||
|
|
||||||
FetchFlameAPIKey::FetchFlameAPIKey(QObject *parent)
|
FetchFlameAPIKey::FetchFlameAPIKey(QObject* parent) : Task{ parent } {}
|
||||||
: Task{parent}
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void FetchFlameAPIKey::executeTask()
|
void FetchFlameAPIKey::executeTask()
|
||||||
{
|
{
|
||||||
@ -42,8 +38,7 @@ void FetchFlameAPIKey::executeTask()
|
|||||||
#else
|
#else
|
||||||
qOverload<QNetworkReply::NetworkError>(&QNetworkReply::error),
|
qOverload<QNetworkReply::NetworkError>(&QNetworkReply::error),
|
||||||
#endif
|
#endif
|
||||||
this,
|
this, [this](QNetworkReply::NetworkError error) {
|
||||||
[this] (QNetworkReply::NetworkError error) {
|
|
||||||
qCritical() << "Network error: " << error;
|
qCritical() << "Network error: " << error;
|
||||||
emitFailed(m_reply->errorString());
|
emitFailed(m_reply->errorString());
|
||||||
});
|
});
|
||||||
@ -63,18 +58,13 @@ void FetchFlameAPIKey::downloadFinished()
|
|||||||
|
|
||||||
auto success = Json::requireBoolean(obj, "ok");
|
auto success = Json::requireBoolean(obj, "ok");
|
||||||
|
|
||||||
if (success)
|
if (success) {
|
||||||
{
|
|
||||||
m_result = Json::requireString(obj, "token");
|
m_result = Json::requireString(obj, "token");
|
||||||
emitSucceeded();
|
emitSucceeded();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
emitFailed("The API returned an output indicating failure.");
|
emitFailed("The API returned an output indicating failure.");
|
||||||
}
|
}
|
||||||
}
|
} catch (Json::JsonException&) {
|
||||||
catch (Json::JsonException&)
|
|
||||||
{
|
|
||||||
qCritical() << "Output: " << res;
|
qCritical() << "Output: " << res;
|
||||||
emitFailed("The API returned an unexpected JSON output.");
|
emitFailed("The API returned an unexpected JSON output.");
|
||||||
}
|
}
|
||||||
|
@ -19,15 +19,14 @@
|
|||||||
#ifndef FETCHFLAMEAPIKEY_H
|
#ifndef FETCHFLAMEAPIKEY_H
|
||||||
#define FETCHFLAMEAPIKEY_H
|
#define FETCHFLAMEAPIKEY_H
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QNetworkReply>
|
|
||||||
#include <tasks/Task.h>
|
#include <tasks/Task.h>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
class FetchFlameAPIKey : public Task
|
class FetchFlameAPIKey : public Task {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit FetchFlameAPIKey(QObject *parent = nullptr);
|
explicit FetchFlameAPIKey(QObject* parent = nullptr);
|
||||||
|
|
||||||
QString m_result;
|
QString m_result;
|
||||||
|
|
||||||
@ -37,8 +36,7 @@ class FetchFlameAPIKey : public Task
|
|||||||
protected:
|
protected:
|
||||||
virtual void executeTask();
|
virtual void executeTask();
|
||||||
|
|
||||||
|
|
||||||
std::shared_ptr<QNetworkReply> m_reply;
|
std::shared_ptr<QNetworkReply> m_reply;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FETCHFLAMEAPIKEY_H
|
#endif // FETCHFLAMEAPIKEY_H
|
||||||
|
@ -52,7 +52,7 @@
|
|||||||
#include <settings/SettingsObject.h>
|
#include <settings/SettingsObject.h>
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
|
|
||||||
QString GuiUtil::fetchFlameKey(QWidget *parentWidget)
|
QString GuiUtil::fetchFlameKey(QWidget* parentWidget)
|
||||||
{
|
{
|
||||||
if (BuildConfig.FLAME_API_KEY_API_URL.isEmpty())
|
if (BuildConfig.FLAME_API_KEY_API_URL.isEmpty())
|
||||||
return "";
|
return "";
|
||||||
@ -61,17 +61,16 @@ QString GuiUtil::fetchFlameKey(QWidget *parentWidget)
|
|||||||
auto flameKeyTask = std::make_unique<FetchFlameAPIKey>();
|
auto flameKeyTask = std::make_unique<FetchFlameAPIKey>();
|
||||||
prog.execWithTask(flameKeyTask.get());
|
prog.execWithTask(flameKeyTask.get());
|
||||||
|
|
||||||
if (!flameKeyTask->wasSuccessful())
|
if (!flameKeyTask->wasSuccessful()) {
|
||||||
{
|
|
||||||
auto message = QObject::tr("Fetching the Curseforge API key failed. Reason: %1").arg(flameKeyTask->failReason());
|
auto message = QObject::tr("Fetching the Curseforge API key failed. Reason: %1").arg(flameKeyTask->failReason());
|
||||||
if (!(APPLICATION->capabilities() & Application::SupportsFlame))
|
if (!(APPLICATION->capabilities() & Application::SupportsFlame)) {
|
||||||
{
|
message += "\n\n" + QObject::tr(
|
||||||
message += "\n\n" + QObject::tr("Downloading Curseforge modpacks will not work unless you manually set a valid Curseforge Core API key in the settings.");
|
"Downloading Curseforge modpacks will not work unless you manually set a valid Curseforge Core API key "
|
||||||
|
"in the settings.");
|
||||||
}
|
}
|
||||||
|
|
||||||
CustomMessageBox::selectable(parentWidget,
|
CustomMessageBox::selectable(parentWidget, QObject::tr("Failed to fetch Curseforge API key."), message, QMessageBox::Critical)
|
||||||
QObject::tr("Failed to fetch Curseforge API key."),
|
->exec();
|
||||||
message, QMessageBox::Critical)->exec();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return flameKeyTask->m_result;
|
return flameKeyTask->m_result;
|
||||||
|
@ -206,7 +206,7 @@ QString InstanceWindow::instanceId()
|
|||||||
return m_instance->id();
|
return m_instance->id();
|
||||||
}
|
}
|
||||||
|
|
||||||
BasePage * InstanceWindow::getPage(QString pageId)
|
BasePage* InstanceWindow::getPage(QString pageId)
|
||||||
{
|
{
|
||||||
return m_container->getPage(pageId);
|
return m_container->getPage(pageId);
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ class InstanceWindow : public QMainWindow, public BasePageContainer {
|
|||||||
explicit InstanceWindow(InstancePtr proc, QWidget* parent = 0);
|
explicit InstanceWindow(InstancePtr proc, QWidget* parent = 0);
|
||||||
virtual ~InstanceWindow() = default;
|
virtual ~InstanceWindow() = default;
|
||||||
|
|
||||||
BasePage * getPage(QString pageId) override;
|
BasePage* getPage(QString pageId) override;
|
||||||
bool selectPage(QString pageId) override;
|
bool selectPage(QString pageId) override;
|
||||||
BasePage* selectedPage() const override;
|
BasePage* selectedPage() const override;
|
||||||
void refreshContainer() override;
|
void refreshContainer() override;
|
||||||
|
@ -128,7 +128,8 @@ void SkinUploadDialog::on_skinBrowseBtn_clicked()
|
|||||||
ui->skinPathTextBox->setText(cooked_path);
|
ui->skinPathTextBox->setText(cooked_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
SkinUploadDialog::SkinUploadDialog(MinecraftAccountPtr account, QWidget* parent) : QDialog(parent), m_account(account), ui(new Ui::SkinUploadDialog)
|
SkinUploadDialog::SkinUploadDialog(MinecraftAccountPtr account, QWidget* parent)
|
||||||
|
: QDialog(parent), m_account(account), ui(new Ui::SkinUploadDialog)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
namespace Ftb {
|
namespace Ftb {
|
||||||
|
|
||||||
FilterModel::FilterModel(QObject *parent) : QSortFilterProxyModel(parent)
|
FilterModel::FilterModel(QObject* parent) : QSortFilterProxyModel(parent)
|
||||||
{
|
{
|
||||||
currentSorting = Sorting::ByPlays;
|
currentSorting = Sorting::ByPlays;
|
||||||
sortings.insert(tr("Sort by Plays"), Sorting::ByPlays);
|
sortings.insert(tr("Sort by Plays"), Sorting::ByPlays);
|
||||||
@ -59,7 +59,7 @@ void FilterModel::setSearchTerm(const QString& term)
|
|||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
bool FilterModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const
|
||||||
{
|
{
|
||||||
if (searchTerm.isEmpty()) {
|
if (searchTerm.isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
@ -70,18 +70,16 @@ bool FilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParen
|
|||||||
return pack.name.contains(searchTerm, Qt::CaseInsensitive);
|
return pack.name.contains(searchTerm, Qt::CaseInsensitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FilterModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
bool FilterModel::lessThan(const QModelIndex& left, const QModelIndex& right) const
|
||||||
{
|
{
|
||||||
ModpacksCH::Modpack leftPack = sourceModel()->data(left, Qt::UserRole).value<ModpacksCH::Modpack>();
|
ModpacksCH::Modpack leftPack = sourceModel()->data(left, Qt::UserRole).value<ModpacksCH::Modpack>();
|
||||||
ModpacksCH::Modpack rightPack = sourceModel()->data(right, Qt::UserRole).value<ModpacksCH::Modpack>();
|
ModpacksCH::Modpack rightPack = sourceModel()->data(right, Qt::UserRole).value<ModpacksCH::Modpack>();
|
||||||
|
|
||||||
if (currentSorting == ByPlays) {
|
if (currentSorting == ByPlays) {
|
||||||
return leftPack.plays < rightPack.plays;
|
return leftPack.plays < rightPack.plays;
|
||||||
}
|
} else if (currentSorting == ByInstalls) {
|
||||||
else if (currentSorting == ByInstalls) {
|
|
||||||
return leftPack.installs < rightPack.installs;
|
return leftPack.installs < rightPack.installs;
|
||||||
}
|
} else if (currentSorting == ByName) {
|
||||||
else if (currentSorting == ByName) {
|
|
||||||
return StringUtils::naturalCompare(leftPack.name, rightPack.name, Qt::CaseSensitive) >= 0;
|
return StringUtils::naturalCompare(leftPack.name, rightPack.name, Qt::CaseSensitive) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,4 +88,4 @@ bool FilterModel::lessThan(const QModelIndex &left, const QModelIndex &right) co
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace Ftb
|
||||||
|
@ -20,11 +20,10 @@
|
|||||||
|
|
||||||
namespace Ftb {
|
namespace Ftb {
|
||||||
|
|
||||||
class FilterModel : public QSortFilterProxyModel
|
class FilterModel : public QSortFilterProxyModel {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FilterModel(QObject* parent = Q_NULLPTR);
|
FilterModel(QObject* parent = Q_NULLPTR);
|
||||||
enum Sorting {
|
enum Sorting {
|
||||||
ByPlays,
|
ByPlays,
|
||||||
@ -37,15 +36,14 @@ public:
|
|||||||
Sorting getCurrentSorting();
|
Sorting getCurrentSorting();
|
||||||
void setSearchTerm(const QString& term);
|
void setSearchTerm(const QString& term);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
|
bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override;
|
||||||
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
|
bool lessThan(const QModelIndex& left, const QModelIndex& right) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMap<QString, Sorting> sortings;
|
QMap<QString, Sorting> sortings;
|
||||||
Sorting currentSorting;
|
Sorting currentSorting;
|
||||||
QString searchTerm { "" };
|
QString searchTerm{ "" };
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace Ftb
|
||||||
|
@ -16,71 +16,59 @@
|
|||||||
|
|
||||||
#include "FtbListModel.h"
|
#include "FtbListModel.h"
|
||||||
|
|
||||||
#include "BuildConfig.h"
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
|
#include "BuildConfig.h"
|
||||||
#include "Json.h"
|
#include "Json.h"
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
namespace Ftb {
|
namespace Ftb {
|
||||||
|
|
||||||
ListModel::ListModel(QObject *parent) : QAbstractListModel(parent)
|
ListModel::ListModel(QObject* parent) : QAbstractListModel(parent) {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ListModel::~ListModel()
|
ListModel::~ListModel() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int ListModel::rowCount(const QModelIndex &parent) const
|
int ListModel::rowCount(const QModelIndex& parent) const
|
||||||
{
|
{
|
||||||
return parent.isValid() ? 0 : modpacks.size();
|
return parent.isValid() ? 0 : modpacks.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
int ListModel::columnCount(const QModelIndex &parent) const
|
int ListModel::columnCount(const QModelIndex& parent) const
|
||||||
{
|
{
|
||||||
return parent.isValid() ? 0 : 1;
|
return parent.isValid() ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant ListModel::data(const QModelIndex &index, int role) const
|
QVariant ListModel::data(const QModelIndex& index, int role) const
|
||||||
{
|
{
|
||||||
int pos = index.row();
|
int pos = index.row();
|
||||||
if(pos >= modpacks.size() || pos < 0 || !index.isValid())
|
if (pos >= modpacks.size() || pos < 0 || !index.isValid()) {
|
||||||
{
|
|
||||||
return QString("INVALID INDEX %1").arg(pos);
|
return QString("INVALID INDEX %1").arg(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
ModpacksCH::Modpack pack = modpacks.at(pos);
|
ModpacksCH::Modpack pack = modpacks.at(pos);
|
||||||
if(role == Qt::DisplayRole)
|
if (role == Qt::DisplayRole) {
|
||||||
{
|
|
||||||
return pack.name;
|
return pack.name;
|
||||||
}
|
} else if (role == Qt::ToolTipRole) {
|
||||||
else if (role == Qt::ToolTipRole)
|
|
||||||
{
|
|
||||||
return pack.synopsis;
|
return pack.synopsis;
|
||||||
}
|
} else if (role == Qt::DecorationRole) {
|
||||||
else if(role == Qt::DecorationRole)
|
|
||||||
{
|
|
||||||
QIcon placeholder = APPLICATION->getThemedIcon("screenshot-placeholder");
|
QIcon placeholder = APPLICATION->getThemedIcon("screenshot-placeholder");
|
||||||
|
|
||||||
auto iter = m_logoMap.find(pack.name);
|
auto iter = m_logoMap.find(pack.name);
|
||||||
if (iter != m_logoMap.end()) {
|
if (iter != m_logoMap.end()) {
|
||||||
auto & logo = *iter;
|
auto& logo = *iter;
|
||||||
if(!logo.result.isNull()) {
|
if (!logo.result.isNull()) {
|
||||||
return logo.result;
|
return logo.result;
|
||||||
}
|
}
|
||||||
return placeholder;
|
return placeholder;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(auto art : pack.art) {
|
for (auto art : pack.art) {
|
||||||
if(art.type == "square") {
|
if (art.type == "square") {
|
||||||
((ListModel *)this)->requestLogo(pack.name, art.url);
|
((ListModel*)this)->requestLogo(pack.name, art.url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return placeholder;
|
return placeholder;
|
||||||
}
|
} else if (role == Qt::UserRole) {
|
||||||
else if(role == Qt::UserRole)
|
|
||||||
{
|
|
||||||
QVariant v;
|
QVariant v;
|
||||||
v.setValue(pack);
|
v.setValue(pack);
|
||||||
return v;
|
return v;
|
||||||
@ -89,14 +77,12 @@ QVariant ListModel::data(const QModelIndex &index, int role) const
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ListModel::getLogo(const QString &logo, const QString &logoUrl, LogoCallback callback)
|
void ListModel::getLogo(const QString& logo, const QString& logoUrl, LogoCallback callback)
|
||||||
{
|
{
|
||||||
if(m_logoMap.contains(logo))
|
if (m_logoMap.contains(logo)) {
|
||||||
{
|
callback(
|
||||||
callback(APPLICATION->metacache()->resolveEntry("ModpacksCHPacks", QString("logos/%1").arg(logo.section(".", 0, 0)))->getFullPath());
|
APPLICATION->metacache()->resolveEntry("ModpacksCHPacks", QString("logos/%1").arg(logo.section(".", 0, 0)))->getFullPath());
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
requestLogo(logo, logoUrl);
|
requestLogo(logo, logoUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -130,21 +116,22 @@ void ListModel::requestFinished()
|
|||||||
jobPtr.reset();
|
jobPtr.reset();
|
||||||
remainingPacks.clear();
|
remainingPacks.clear();
|
||||||
|
|
||||||
QJsonParseError parse_error {};
|
QJsonParseError parse_error{};
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
|
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
|
||||||
if(parse_error.error != QJsonParseError::NoError) {
|
if (parse_error.error != QJsonParseError::NoError) {
|
||||||
qWarning() << "Error while parsing JSON response from ModpacksCH at " << parse_error.offset << " reason: " << parse_error.errorString();
|
qWarning() << "Error while parsing JSON response from ModpacksCH at " << parse_error.offset
|
||||||
|
<< " reason: " << parse_error.errorString();
|
||||||
qWarning() << *response;
|
qWarning() << *response;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto packs = doc.object().value("packs").toArray();
|
auto packs = doc.object().value("packs").toArray();
|
||||||
for(auto pack : packs) {
|
for (auto pack : packs) {
|
||||||
auto packId = pack.toInt();
|
auto packId = pack.toInt();
|
||||||
remainingPacks.append(packId);
|
remainingPacks.append(packId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!remainingPacks.isEmpty()) {
|
if (!remainingPacks.isEmpty()) {
|
||||||
currentPack = remainingPacks.at(0);
|
currentPack = remainingPacks.at(0);
|
||||||
requestPack();
|
requestPack();
|
||||||
}
|
}
|
||||||
@ -179,8 +166,9 @@ void ListModel::packRequestFinished()
|
|||||||
QJsonParseError parse_error;
|
QJsonParseError parse_error;
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
|
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
|
||||||
|
|
||||||
if(parse_error.error != QJsonParseError::NoError) {
|
if (parse_error.error != QJsonParseError::NoError) {
|
||||||
qWarning() << "Error while parsing JSON response from ModpacksCH at " << parse_error.offset << " reason: " << parse_error.errorString();
|
qWarning() << "Error while parsing JSON response from ModpacksCH at " << parse_error.offset
|
||||||
|
<< " reason: " << parse_error.errorString();
|
||||||
qWarning() << *response;
|
qWarning() << *response;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -188,12 +176,9 @@ void ListModel::packRequestFinished()
|
|||||||
auto obj = doc.object();
|
auto obj = doc.object();
|
||||||
|
|
||||||
ModpacksCH::Modpack pack;
|
ModpacksCH::Modpack pack;
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
ModpacksCH::loadModpack(pack, obj);
|
ModpacksCH::loadModpack(pack, obj);
|
||||||
}
|
} catch (const JSONValidationError& e) {
|
||||||
catch (const JSONValidationError &e)
|
|
||||||
{
|
|
||||||
qDebug() << QString::fromUtf8(*response);
|
qDebug() << QString::fromUtf8(*response);
|
||||||
qWarning() << "Error while reading pack manifest from ModpacksCH: " << e.cause();
|
qWarning() << "Error while reading pack manifest from ModpacksCH: " << e.cause();
|
||||||
return;
|
return;
|
||||||
@ -201,18 +186,15 @@ void ListModel::packRequestFinished()
|
|||||||
|
|
||||||
// Since there is no guarantee that packs have a version, this will just
|
// Since there is no guarantee that packs have a version, this will just
|
||||||
// ignore those "dud" packs.
|
// ignore those "dud" packs.
|
||||||
if (pack.versions.empty())
|
if (pack.versions.empty()) {
|
||||||
{
|
|
||||||
qWarning() << "ModpacksCH Pack " << pack.id << " ignored. reason: lacking any versions";
|
qWarning() << "ModpacksCH Pack " << pack.id << " ignored. reason: lacking any versions";
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
beginInsertRows(QModelIndex(), modpacks.size(), modpacks.size());
|
beginInsertRows(QModelIndex(), modpacks.size(), modpacks.size());
|
||||||
modpacks.append(pack);
|
modpacks.append(pack);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!remainingPacks.isEmpty()) {
|
if (!remainingPacks.isEmpty()) {
|
||||||
currentPack = remainingPacks.at(0);
|
currentPack = remainingPacks.at(0);
|
||||||
requestPack();
|
requestPack();
|
||||||
}
|
}
|
||||||
@ -226,24 +208,22 @@ void ListModel::packRequestFailed(QString reason)
|
|||||||
|
|
||||||
void ListModel::logoLoaded(QString logo, bool stale)
|
void ListModel::logoLoaded(QString logo, bool stale)
|
||||||
{
|
{
|
||||||
auto & logoObj = m_logoMap[logo];
|
auto& logoObj = m_logoMap[logo];
|
||||||
logoObj.downloadJob.reset();
|
logoObj.downloadJob.reset();
|
||||||
QString smallPath = logoObj.fullpath + ".small";
|
QString smallPath = logoObj.fullpath + ".small";
|
||||||
|
|
||||||
QFileInfo smallInfo(smallPath);
|
QFileInfo smallInfo(smallPath);
|
||||||
|
|
||||||
if(stale || !smallInfo.exists()) {
|
if (stale || !smallInfo.exists()) {
|
||||||
QImage image(logoObj.fullpath);
|
QImage image(logoObj.fullpath);
|
||||||
if (image.isNull())
|
if (image.isNull()) {
|
||||||
{
|
|
||||||
logoObj.failed = true;
|
logoObj.failed = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QImage small;
|
QImage small;
|
||||||
if (image.width() > image.height()) {
|
if (image.width() > image.height()) {
|
||||||
small = image.scaledToWidth(512).scaledToWidth(256, Qt::SmoothTransformation);
|
small = image.scaledToWidth(512).scaledToWidth(256, Qt::SmoothTransformation);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
small = image.scaledToHeight(512).scaledToHeight(256, Qt::SmoothTransformation);
|
small = image.scaledToHeight(512).scaledToHeight(256, Qt::SmoothTransformation);
|
||||||
}
|
}
|
||||||
QPoint offset((256 - small.width()) / 2, (256 - small.height()) / 2);
|
QPoint offset((256 - small.width()) / 2, (256 - small.height()) / 2);
|
||||||
@ -258,9 +238,9 @@ void ListModel::logoLoaded(QString logo, bool stale)
|
|||||||
}
|
}
|
||||||
|
|
||||||
logoObj.result = QIcon(logoObj.fullpath + ".small");
|
logoObj.result = QIcon(logoObj.fullpath + ".small");
|
||||||
for(int i = 0; i < modpacks.size(); i++) {
|
for (int i = 0; i < modpacks.size(); i++) {
|
||||||
if(modpacks[i].name == logo) {
|
if (modpacks[i].name == logo) {
|
||||||
emit dataChanged(createIndex(i, 0), createIndex(i, 0), {Qt::DecorationRole});
|
emit dataChanged(createIndex(i, 0), createIndex(i, 0), { Qt::DecorationRole });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -273,7 +253,7 @@ void ListModel::logoFailed(QString logo)
|
|||||||
|
|
||||||
void ListModel::requestLogo(QString logo, QString url)
|
void ListModel::requestLogo(QString logo, QString url)
|
||||||
{
|
{
|
||||||
if(m_logoMap.contains(logo)) {
|
if (m_logoMap.contains(logo)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -285,20 +265,14 @@ void ListModel::requestLogo(QString logo, QString url)
|
|||||||
job->addNetAction(Net::Download::makeCached(QUrl(url), entry));
|
job->addNetAction(Net::Download::makeCached(QUrl(url), entry));
|
||||||
|
|
||||||
auto fullPath = entry->getFullPath();
|
auto fullPath = entry->getFullPath();
|
||||||
QObject::connect(job.get(), &NetJob::finished, this, [this, logo, fullPath, stale]
|
QObject::connect(job.get(), &NetJob::finished, this, [this, logo, fullPath, stale] { logoLoaded(logo, stale); });
|
||||||
{
|
|
||||||
logoLoaded(logo, stale);
|
|
||||||
});
|
|
||||||
|
|
||||||
QObject::connect(job.get(), &NetJob::failed, this, [this, logo]
|
QObject::connect(job.get(), &NetJob::failed, this, [this, logo] { logoFailed(logo); });
|
||||||
{
|
|
||||||
logoFailed(logo);
|
|
||||||
});
|
|
||||||
|
|
||||||
auto &newLogoEntry = m_logoMap[logo];
|
auto& newLogoEntry = m_logoMap[logo];
|
||||||
newLogoEntry.downloadJob = job;
|
newLogoEntry.downloadJob = job;
|
||||||
newLogoEntry.fullpath = fullPath;
|
newLogoEntry.fullpath = fullPath;
|
||||||
job->start();
|
job->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace Ftb
|
||||||
|
@ -18,10 +18,10 @@
|
|||||||
|
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
#include "modplatform/modpacksch/FTBPackManifest.h"
|
|
||||||
#include "net/NetJob.h"
|
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include "modplatform/modpacksch/FTBPackManifest.h"
|
||||||
|
#include "net/NetJob.h"
|
||||||
|
|
||||||
namespace Ftb {
|
namespace Ftb {
|
||||||
|
|
||||||
@ -38,23 +38,23 @@ typedef std::function<void(QString)> LogoCallback;
|
|||||||
class ListModel : public QAbstractListModel {
|
class ListModel : public QAbstractListModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ListModel(QObject *parent);
|
ListModel(QObject* parent);
|
||||||
virtual ~ListModel();
|
virtual ~ListModel();
|
||||||
|
|
||||||
int rowCount(const QModelIndex &parent) const override;
|
int rowCount(const QModelIndex& parent) const override;
|
||||||
int columnCount(const QModelIndex &parent) const override;
|
int columnCount(const QModelIndex& parent) const override;
|
||||||
QVariant data(const QModelIndex &index, int role) const override;
|
QVariant data(const QModelIndex& index, int role) const override;
|
||||||
|
|
||||||
void request();
|
void request();
|
||||||
void abortRequest();
|
void abortRequest();
|
||||||
|
|
||||||
void getLogo(const QString &logo, const QString &logoUrl, LogoCallback callback);
|
void getLogo(const QString& logo, const QString& logoUrl, LogoCallback callback);
|
||||||
|
|
||||||
[[nodiscard]] bool isMakingRequest() const { return jobPtr.get(); }
|
[[nodiscard]] bool isMakingRequest() const { return jobPtr.get(); }
|
||||||
[[nodiscard]] bool wasAborted() const { return m_aborted; }
|
[[nodiscard]] bool wasAborted() const { return m_aborted; }
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void requestFinished();
|
void requestFinished();
|
||||||
void requestFailed(QString reason);
|
void requestFailed(QString reason);
|
||||||
|
|
||||||
@ -65,10 +65,10 @@ private slots:
|
|||||||
void logoFailed(QString logo);
|
void logoFailed(QString logo);
|
||||||
void logoLoaded(QString logo, bool stale);
|
void logoLoaded(QString logo, bool stale);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void requestLogo(QString file, QString url);
|
void requestLogo(QString file, QString url);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_aborted = false;
|
bool m_aborted = false;
|
||||||
|
|
||||||
QList<ModpacksCH::Modpack> modpacks;
|
QList<ModpacksCH::Modpack> modpacks;
|
||||||
@ -80,4 +80,4 @@ private:
|
|||||||
std::shared_ptr<QByteArray> response = std::make_shared<QByteArray>();
|
std::shared_ptr<QByteArray> response = std::make_shared<QByteArray>();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace Ftb
|
||||||
|
@ -40,13 +40,12 @@
|
|||||||
|
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
|
|
||||||
#include "ui/dialogs/NewInstanceDialog.h"
|
|
||||||
#include "modplatform/modpacksch/FTBPackInstallTask.h"
|
#include "modplatform/modpacksch/FTBPackInstallTask.h"
|
||||||
|
#include "ui/dialogs/NewInstanceDialog.h"
|
||||||
|
|
||||||
#include "Markdown.h"
|
#include "Markdown.h"
|
||||||
|
|
||||||
FtbPage::FtbPage(NewInstanceDialog* dialog, QWidget *parent)
|
FtbPage::FtbPage(NewInstanceDialog* dialog, QWidget* parent) : QWidget(parent), ui(new Ui::FtbPage), dialog(dialog)
|
||||||
: QWidget(parent), ui(new Ui::FtbPage), dialog(dialog)
|
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
@ -63,8 +62,7 @@ FtbPage::FtbPage(NewInstanceDialog* dialog, QWidget *parent)
|
|||||||
ui->versionSelectionBox->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
ui->versionSelectionBox->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||||
ui->versionSelectionBox->view()->parentWidget()->setMaximumHeight(300);
|
ui->versionSelectionBox->view()->parentWidget()->setMaximumHeight(300);
|
||||||
|
|
||||||
for(int i = 0; i < filterModel->getAvailableSortings().size(); i++)
|
for (int i = 0; i < filterModel->getAvailableSortings().size(); i++) {
|
||||||
{
|
|
||||||
ui->sortByBox->addItem(filterModel->getAvailableSortings().keys().at(i));
|
ui->sortByBox->addItem(filterModel->getAvailableSortings().keys().at(i));
|
||||||
}
|
}
|
||||||
ui->sortByBox->setCurrentText(filterModel->translateCurrentSorting());
|
ui->sortByBox->setCurrentText(filterModel->translateCurrentSorting());
|
||||||
@ -107,8 +105,7 @@ void FtbPage::retranslate()
|
|||||||
|
|
||||||
void FtbPage::openedImpl()
|
void FtbPage::openedImpl()
|
||||||
{
|
{
|
||||||
if(!initialised || listModel->wasAborted())
|
if (!initialised || listModel->wasAborted()) {
|
||||||
{
|
|
||||||
listModel->request();
|
listModel->request();
|
||||||
initialised = true;
|
initialised = true;
|
||||||
}
|
}
|
||||||
@ -124,27 +121,23 @@ void FtbPage::closedImpl()
|
|||||||
|
|
||||||
void FtbPage::suggestCurrent()
|
void FtbPage::suggestCurrent()
|
||||||
{
|
{
|
||||||
if(!isOpened)
|
if (!isOpened) {
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedVersion.isEmpty())
|
if (selectedVersion.isEmpty()) {
|
||||||
{
|
|
||||||
dialog->setSuggestedPack();
|
dialog->setSuggestedPack();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dialog->setSuggestedPack(selected.name, selectedVersion, new ModpacksCH::PackInstallTask(selected, selectedVersion, this));
|
dialog->setSuggestedPack(selected.name, selectedVersion, new ModpacksCH::PackInstallTask(selected, selectedVersion, this));
|
||||||
for(auto art : selected.art) {
|
for (auto art : selected.art) {
|
||||||
if(art.type == "square") {
|
if (art.type == "square") {
|
||||||
QString editedLogoName;
|
QString editedLogoName;
|
||||||
editedLogoName = selected.name;
|
editedLogoName = selected.name;
|
||||||
|
|
||||||
listModel->getLogo(selected.name, art.url, [this, editedLogoName](QString logo)
|
listModel->getLogo(selected.name, art.url,
|
||||||
{
|
[this, editedLogoName](QString logo) { dialog->setSuggestedIconFromFile(logo + ".small", editedLogoName); });
|
||||||
dialog->setSuggestedIconFromFile(logo + ".small", editedLogoName);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -164,10 +157,8 @@ void FtbPage::onSelectionChanged(QModelIndex first, QModelIndex second)
|
|||||||
{
|
{
|
||||||
ui->versionSelectionBox->clear();
|
ui->versionSelectionBox->clear();
|
||||||
|
|
||||||
if(!first.isValid())
|
if (!first.isValid()) {
|
||||||
{
|
if (isOpened) {
|
||||||
if(isOpened)
|
|
||||||
{
|
|
||||||
dialog->setSuggestedPack();
|
dialog->setSuggestedPack();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -188,8 +179,7 @@ void FtbPage::onSelectionChanged(QModelIndex first, QModelIndex second)
|
|||||||
|
|
||||||
void FtbPage::onVersionSelectionChanged(QString data)
|
void FtbPage::onVersionSelectionChanged(QString data)
|
||||||
{
|
{
|
||||||
if(data.isNull() || data.isEmpty())
|
if (data.isNull() || data.isEmpty()) {
|
||||||
{
|
|
||||||
selectedVersion = "";
|
selectedVersion = "";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -41,59 +41,45 @@
|
|||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "ui/pages/BasePage.h"
|
|
||||||
#include "tasks/Task.h"
|
#include "tasks/Task.h"
|
||||||
|
#include "ui/pages/BasePage.h"
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui {
|
||||||
{
|
class FtbPage;
|
||||||
class FtbPage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class NewInstanceDialog;
|
class NewInstanceDialog;
|
||||||
|
|
||||||
class FtbPage : public QWidget, public BasePage
|
class FtbPage : public QWidget, public BasePage {
|
||||||
{
|
Q_OBJECT
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit FtbPage(NewInstanceDialog* dialog, QWidget *parent = 0);
|
explicit FtbPage(NewInstanceDialog* dialog, QWidget* parent = 0);
|
||||||
virtual ~FtbPage();
|
virtual ~FtbPage();
|
||||||
virtual QString displayName() const override
|
virtual QString displayName() const override { return "FTB"; }
|
||||||
{
|
virtual QIcon icon() const override { return APPLICATION->getThemedIcon("ftb_logo"); }
|
||||||
return "FTB";
|
virtual QString id() const override { return "ftb"; }
|
||||||
}
|
virtual QString helpPage() const override { return "FTB-platform"; }
|
||||||
virtual QIcon icon() const override
|
|
||||||
{
|
|
||||||
return APPLICATION->getThemedIcon("ftb_logo");
|
|
||||||
}
|
|
||||||
virtual QString id() const override
|
|
||||||
{
|
|
||||||
return "ftb";
|
|
||||||
}
|
|
||||||
virtual QString helpPage() const override
|
|
||||||
{
|
|
||||||
return "FTB-platform";
|
|
||||||
}
|
|
||||||
virtual bool shouldDisplay() const override;
|
virtual bool shouldDisplay() const override;
|
||||||
void retranslate() override;
|
void retranslate() override;
|
||||||
|
|
||||||
void openedImpl() override;
|
void openedImpl() override;
|
||||||
void closedImpl() override;
|
void closedImpl() override;
|
||||||
|
|
||||||
bool eventFilter(QObject * watched, QEvent * event) override;
|
bool eventFilter(QObject* watched, QEvent* event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void suggestCurrent();
|
void suggestCurrent();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void triggerSearch();
|
void triggerSearch();
|
||||||
|
|
||||||
void onSortingSelectionChanged(QString data);
|
void onSortingSelectionChanged(QString data);
|
||||||
void onSelectionChanged(QModelIndex first, QModelIndex second);
|
void onSelectionChanged(QModelIndex first, QModelIndex second);
|
||||||
void onVersionSelectionChanged(QString data);
|
void onVersionSelectionChanged(QString data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::FtbPage *ui = nullptr;
|
Ui::FtbPage* ui = nullptr;
|
||||||
NewInstanceDialog* dialog = nullptr;
|
NewInstanceDialog* dialog = nullptr;
|
||||||
Ftb::ListModel* listModel = nullptr;
|
Ftb::ListModel* listModel = nullptr;
|
||||||
Ftb::FilterModel* filterModel = nullptr;
|
Ftb::FilterModel* filterModel = nullptr;
|
||||||
@ -101,5 +87,5 @@ private:
|
|||||||
ModpacksCH::Modpack selected;
|
ModpacksCH::Modpack selected;
|
||||||
QString selectedVersion;
|
QString selectedVersion;
|
||||||
|
|
||||||
bool initialised { false };
|
bool initialised{ false };
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user