diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.h b/launcher/modplatform/modpacksch/FTBPackInstallTask.h index a80f020e4..7ace74414 100644 --- a/launcher/modplatform/modpacksch/FTBPackInstallTask.h +++ b/launcher/modplatform/modpacksch/FTBPackInstallTask.h @@ -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 m_mod_id_resolver_task = nullptr; @@ -94,8 +94,8 @@ private: QMap m_files_to_copy; QList m_blocked_mods; - //FIXME: nuke + // FIXME: nuke QWidget* m_parent; }; -} +} // namespace ModpacksCH diff --git a/launcher/modplatform/modpacksch/FTBPackManifest.cpp b/launcher/modplatform/modpacksch/FTBPackManifest.cpp index 421527aef..90142a125 100644 --- a/launcher/modplatform/modpacksch/FTBPackManifest.cpp +++ b/launcher/modplatform/modpacksch/FTBPackManifest.cpp @@ -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"); +// } diff --git a/launcher/modplatform/modpacksch/FTBPackManifest.h b/launcher/modplatform/modpacksch/FTBPackManifest.h index a8b6f35ec..48a7531c3 100644 --- a/launcher/modplatform/modpacksch/FTBPackManifest.h +++ b/launcher/modplatform/modpacksch/FTBPackManifest.h @@ -36,30 +36,26 @@ #pragma once -#include -#include -#include #include #include +#include +#include +#include -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 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 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) diff --git a/launcher/net/FetchFlameAPIKey.cpp b/launcher/net/FetchFlameAPIKey.cpp index 4433f9e96..a5e0c3fca 100644 --- a/launcher/net/FetchFlameAPIKey.cpp +++ b/launcher/net/FetchFlameAPIKey.cpp @@ -17,18 +17,14 @@ */ #include "FetchFlameAPIKey.h" -#include "Application.h" #include #include +#include "Application.h" -#include #include +#include -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::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."); } diff --git a/launcher/net/FetchFlameAPIKey.h b/launcher/net/FetchFlameAPIKey.h index 6434281a5..cf171a7c4 100644 --- a/launcher/net/FetchFlameAPIKey.h +++ b/launcher/net/FetchFlameAPIKey.h @@ -19,15 +19,14 @@ #ifndef FETCHFLAMEAPIKEY_H #define FETCHFLAMEAPIKEY_H -#include -#include #include +#include +#include -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 m_reply; }; -#endif // FETCHFLAMEAPIKEY_H +#endif // FETCHFLAMEAPIKEY_H diff --git a/launcher/ui/GuiUtil.cpp b/launcher/ui/GuiUtil.cpp index aed984c39..620ec5d94 100644 --- a/launcher/ui/GuiUtil.cpp +++ b/launcher/ui/GuiUtil.cpp @@ -52,7 +52,7 @@ #include #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(); 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; diff --git a/launcher/ui/InstanceWindow.cpp b/launcher/ui/InstanceWindow.cpp index 22263087d..843111b88 100644 --- a/launcher/ui/InstanceWindow.cpp +++ b/launcher/ui/InstanceWindow.cpp @@ -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); } diff --git a/launcher/ui/InstanceWindow.h b/launcher/ui/InstanceWindow.h index c07ac7dde..343513961 100644 --- a/launcher/ui/InstanceWindow.h +++ b/launcher/ui/InstanceWindow.h @@ -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; diff --git a/launcher/ui/dialogs/SkinUploadDialog.cpp b/launcher/ui/dialogs/SkinUploadDialog.cpp index 438323de5..52fc302ac 100644 --- a/launcher/ui/dialogs/SkinUploadDialog.cpp +++ b/launcher/ui/dialogs/SkinUploadDialog.cpp @@ -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); diff --git a/launcher/ui/pages/modplatform/ftb/FtbFilterModel.cpp b/launcher/ui/pages/modplatform/ftb/FtbFilterModel.cpp index e2b548f2d..b8c3af0a0 100644 --- a/launcher/ui/pages/modplatform/ftb/FtbFilterModel.cpp +++ b/launcher/ui/pages/modplatform/ftb/FtbFilterModel.cpp @@ -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 rightPack = sourceModel()->data(right, Qt::UserRole).value(); 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 diff --git a/launcher/ui/pages/modplatform/ftb/FtbFilterModel.h b/launcher/ui/pages/modplatform/ftb/FtbFilterModel.h index 1be28e995..47fc1d8c6 100644 --- a/launcher/ui/pages/modplatform/ftb/FtbFilterModel.h +++ b/launcher/ui/pages/modplatform/ftb/FtbFilterModel.h @@ -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 sortings; Sorting currentSorting; - QString searchTerm { "" }; - + QString searchTerm{ "" }; }; -} +} // namespace Ftb diff --git a/launcher/ui/pages/modplatform/ftb/FtbListModel.cpp b/launcher/ui/pages/modplatform/ftb/FtbListModel.cpp index 62819e0c3..c8b60a839 100644 --- a/launcher/ui/pages/modplatform/ftb/FtbListModel.cpp +++ b/launcher/ui/pages/modplatform/ftb/FtbListModel.cpp @@ -16,71 +16,59 @@ #include "FtbListModel.h" -#include "BuildConfig.h" #include "Application.h" +#include "BuildConfig.h" #include "Json.h" #include 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 diff --git a/launcher/ui/pages/modplatform/ftb/FtbListModel.h b/launcher/ui/pages/modplatform/ftb/FtbListModel.h index 8712a80db..1d303b52c 100644 --- a/launcher/ui/pages/modplatform/ftb/FtbListModel.h +++ b/launcher/ui/pages/modplatform/ftb/FtbListModel.h @@ -18,10 +18,10 @@ #include -#include "modplatform/modpacksch/FTBPackManifest.h" -#include "net/NetJob.h" #include #include +#include "modplatform/modpacksch/FTBPackManifest.h" +#include "net/NetJob.h" namespace Ftb { @@ -38,23 +38,23 @@ typedef std::function 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 modpacks; @@ -80,4 +80,4 @@ private: std::shared_ptr response = std::make_shared(); }; -} +} // namespace Ftb diff --git a/launcher/ui/pages/modplatform/ftb/FtbPage.cpp b/launcher/ui/pages/modplatform/ftb/FtbPage.cpp index 7d59a6ae7..c1ed11a1a 100644 --- a/launcher/ui/pages/modplatform/ftb/FtbPage.cpp +++ b/launcher/ui/pages/modplatform/ftb/FtbPage.cpp @@ -40,13 +40,12 @@ #include -#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; } diff --git a/launcher/ui/pages/modplatform/ftb/FtbPage.h b/launcher/ui/pages/modplatform/ftb/FtbPage.h index 631ae7f56..0283e90d3 100644 --- a/launcher/ui/pages/modplatform/ftb/FtbPage.h +++ b/launcher/ui/pages/modplatform/ftb/FtbPage.h @@ -41,59 +41,45 @@ #include #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 }; };