pre-commit run --all-files
This commit is contained in:
parent
513361df25
commit
4f9fdcc293
@ -98,4 +98,4 @@ private:
|
|||||||
QWidget* m_parent;
|
QWidget* m_parent;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace ModpacksCH
|
||||||
|
@ -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);
|
||||||
@ -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);
|
||||||
|
@ -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,8 +143,7 @@ struct Version
|
|||||||
QVector<VersionFile> files;
|
QVector<VersionFile> files;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VersionChangelog
|
struct VersionChangelog {
|
||||||
{
|
|
||||||
QString content;
|
QString content;
|
||||||
int64_t updated;
|
int64_t updated;
|
||||||
};
|
};
|
||||||
@ -163,6 +151,6 @@ struct VersionChangelog
|
|||||||
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,12 +19,11 @@
|
|||||||
#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);
|
||||||
@ -37,7 +36,6 @@ class FetchFlameAPIKey : public Task
|
|||||||
protected:
|
protected:
|
||||||
virtual void executeTask();
|
virtual void executeTask();
|
||||||
|
|
||||||
|
|
||||||
std::shared_ptr<QNetworkReply> m_reply;
|
std::shared_ptr<QNetworkReply> m_reply;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
@ -77,11 +77,9 @@ bool FilterModel::lessThan(const QModelIndex &left, const QModelIndex &right) co
|
|||||||
|
|
||||||
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,8 +20,7 @@
|
|||||||
|
|
||||||
namespace Ftb {
|
namespace Ftb {
|
||||||
|
|
||||||
class FilterModel : public QSortFilterProxyModel
|
class FilterModel : public QSortFilterProxyModel {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -45,7 +44,6 @@ private:
|
|||||||
QMap<QString, Sorting> sortings;
|
QMap<QString, Sorting> sortings;
|
||||||
Sorting currentSorting;
|
Sorting currentSorting;
|
||||||
QString searchTerm{ "" };
|
QString searchTerm{ "" };
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace Ftb
|
||||||
|
@ -16,21 +16,17 @@
|
|||||||
|
|
||||||
#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
|
||||||
{
|
{
|
||||||
@ -45,22 +41,16 @@ int ListModel::columnCount(const QModelIndex &parent) const
|
|||||||
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);
|
||||||
@ -78,9 +68,7 @@ QVariant ListModel::data(const QModelIndex &index, int role) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
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;
|
||||||
@ -91,12 +79,10 @@ QVariant ListModel::data(const QModelIndex &index, int role) const
|
|||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,7 +119,8 @@ void ListModel::requestFinished()
|
|||||||
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;
|
||||||
}
|
}
|
||||||
@ -180,7 +167,8 @@ void ListModel::packRequestFinished()
|
|||||||
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,12 +186,9 @@ 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();
|
||||||
@ -234,16 +216,14 @@ void ListModel::logoLoaded(QString logo, bool stale)
|
|||||||
|
|
||||||
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);
|
||||||
@ -285,15 +265,9 @@ 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;
|
||||||
@ -301,4 +275,4 @@ void ListModel::requestLogo(QString logo, QString url)
|
|||||||
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 {
|
||||||
|
|
||||||
@ -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,13 +121,11 @@ 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;
|
||||||
}
|
}
|
||||||
@ -141,10 +136,8 @@ void FtbPage::suggestCurrent()
|
|||||||
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,39 +41,25 @@
|
|||||||
#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;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user