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