pre-commit run --all-files

This commit is contained in:
Evan Goode 2024-05-23 16:49:09 -04:00
parent 513361df25
commit 4f9fdcc293
15 changed files with 171 additions and 255 deletions

View File

@ -98,4 +98,4 @@ private:
QWidget* m_parent;
};
}
} // namespace ModpacksCH

View File

@ -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);
@ -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);

View File

@ -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,8 +143,7 @@ struct Version
QVector<VersionFile> files;
};
struct VersionChangelog
{
struct VersionChangelog {
QString content;
int64_t updated;
};
@ -163,6 +151,6 @@ struct VersionChangelog
void loadModpack(Modpack& m, QJsonObject& obj);
void loadVersion(Version& m, QJsonObject& obj);
}
} // namespace ModpacksCH
Q_DECLARE_METATYPE(ModpacksCH::Modpack)

View File

@ -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.");
}

View File

@ -19,12 +19,11 @@
#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);
@ -37,7 +36,6 @@ class FetchFlameAPIKey : public Task
protected:
virtual void executeTask();
std::shared_ptr<QNetworkReply> m_reply;
};

View File

@ -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;

View File

@ -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);

View File

@ -77,11 +77,9 @@ bool FilterModel::lessThan(const QModelIndex &left, const QModelIndex &right) co
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

View File

@ -20,8 +20,7 @@
namespace Ftb {
class FilterModel : public QSortFilterProxyModel
{
class FilterModel : public QSortFilterProxyModel {
Q_OBJECT
public:
@ -45,7 +44,6 @@ private:
QMap<QString, Sorting> sortings;
Sorting currentSorting;
QString searchTerm{ "" };
};
}
} // namespace Ftb

View File

@ -16,21 +16,17 @@
#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
{
@ -45,22 +41,16 @@ int ListModel::columnCount(const QModelIndex &parent) 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);
@ -78,9 +68,7 @@ QVariant ListModel::data(const QModelIndex &index, int role) const
}
}
return placeholder;
}
else if(role == Qt::UserRole)
{
} else if (role == Qt::UserRole) {
QVariant v;
v.setValue(pack);
return v;
@ -91,12 +79,10 @@ QVariant ListModel::data(const QModelIndex &index, int role) const
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);
}
}
@ -133,7 +119,8 @@ void ListModel::requestFinished()
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();
qWarning() << "Error while parsing JSON response from ModpacksCH at " << parse_error.offset
<< " reason: " << parse_error.errorString();
qWarning() << *response;
return;
}
@ -180,7 +167,8 @@ void ListModel::packRequestFinished()
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();
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,12 +186,9 @@ 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();
@ -234,16 +216,14 @@ void ListModel::logoLoaded(QString logo, bool stale)
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);
@ -285,15 +265,9 @@ 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];
newLogoEntry.downloadJob = job;
@ -301,4 +275,4 @@ void ListModel::requestLogo(QString logo, QString url)
job->start();
}
}
} // namespace Ftb

View File

@ -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 {
@ -80,4 +80,4 @@ private:
std::shared_ptr<QByteArray> response = std::make_shared<QByteArray>();
};
}
} // namespace Ftb

View File

@ -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,13 +121,11 @@ void FtbPage::closedImpl()
void FtbPage::suggestCurrent()
{
if(!isOpened)
{
if (!isOpened) {
return;
}
if (selectedVersion.isEmpty())
{
if (selectedVersion.isEmpty()) {
dialog->setSuggestedPack();
return;
}
@ -141,10 +136,8 @@ void FtbPage::suggestCurrent()
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;
}

View File

@ -41,39 +41,25 @@
#include <QWidget>
#include "Application.h"
#include "ui/pages/BasePage.h"
#include "tasks/Task.h"
#include "ui/pages/BasePage.h"
namespace Ui
{
namespace Ui {
class FtbPage;
}
class NewInstanceDialog;
class FtbPage : public QWidget, public BasePage
{
class FtbPage : public QWidget, public BasePage {
Q_OBJECT
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;