2020-11-14 23:36:27 +05:30
|
|
|
#include "FtbListModel.h"
|
GH-3095 New FTB platform support
Models are based on the models from my go-modpacksch library.
License:
========
The MIT License (MIT)
Copyright (c) Jamie Mansfield <https://www.jamiemansfield.me/>
Copyright (c) contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
2020-06-07 20:44:47 +05:30
|
|
|
|
|
|
|
#include "BuildConfig.h"
|
2021-11-20 20:52:22 +05:30
|
|
|
#include "Application.h"
|
GH-3095 New FTB platform support
Models are based on the models from my go-modpacksch library.
License:
========
The MIT License (MIT)
Copyright (c) Jamie Mansfield <https://www.jamiemansfield.me/>
Copyright (c) contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
2020-06-07 20:44:47 +05:30
|
|
|
#include "Json.h"
|
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
|
|
|
namespace Ftb {
|
|
|
|
|
|
|
|
ListModel::ListModel(QObject *parent) : QAbstractListModel(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ListModel::~ListModel()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int ListModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
return modpacks.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
int ListModel::columnCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant ListModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
int pos = index.row();
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
return pack.name;
|
|
|
|
}
|
|
|
|
else if (role == Qt::ToolTipRole)
|
|
|
|
{
|
|
|
|
return pack.synopsis;
|
|
|
|
}
|
|
|
|
else if(role == Qt::DecorationRole)
|
|
|
|
{
|
2021-11-20 20:52:22 +05:30
|
|
|
QIcon placeholder = APPLICATION->getThemedIcon("screenshot-placeholder");
|
GH-3095 New FTB platform support
Models are based on the models from my go-modpacksch library.
License:
========
The MIT License (MIT)
Copyright (c) Jamie Mansfield <https://www.jamiemansfield.me/>
Copyright (c) contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
2020-06-07 20:44:47 +05:30
|
|
|
|
|
|
|
auto iter = m_logoMap.find(pack.name);
|
|
|
|
if (iter != m_logoMap.end()) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return placeholder;
|
|
|
|
}
|
|
|
|
else if(role == Qt::UserRole)
|
|
|
|
{
|
|
|
|
QVariant v;
|
|
|
|
v.setValue(pack);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ListModel::getLogo(const QString &logo, const QString &logoUrl, LogoCallback callback)
|
|
|
|
{
|
|
|
|
if(m_logoMap.contains(logo))
|
|
|
|
{
|
2021-11-22 03:51:12 +05:30
|
|
|
callback(APPLICATION->metacache()->resolveEntry("ModpacksCHPacks", QString("logos/%1").arg(logo.section(".", 0, 0)))->getFullPath());
|
GH-3095 New FTB platform support
Models are based on the models from my go-modpacksch library.
License:
========
The MIT License (MIT)
Copyright (c) Jamie Mansfield <https://www.jamiemansfield.me/>
Copyright (c) contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
2020-06-07 20:44:47 +05:30
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
requestLogo(logo, logoUrl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-17 04:01:27 +05:30
|
|
|
void ListModel::request()
|
GH-3095 New FTB platform support
Models are based on the models from my go-modpacksch library.
License:
========
The MIT License (MIT)
Copyright (c) Jamie Mansfield <https://www.jamiemansfield.me/>
Copyright (c) contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
2020-06-07 20:44:47 +05:30
|
|
|
{
|
2021-03-27 01:33:57 +05:30
|
|
|
beginResetModel();
|
|
|
|
modpacks.clear();
|
|
|
|
endResetModel();
|
|
|
|
|
2021-10-17 04:01:27 +05:30
|
|
|
auto *netJob = new NetJob("Ftb::Request");
|
|
|
|
auto url = QString(BuildConfig.MODPACKSCH_API_BASE_URL + "public/modpack/all");
|
|
|
|
netJob->addNetAction(Net::Download::makeByteArray(QUrl(url), &response));
|
|
|
|
jobPtr = netJob;
|
2021-11-22 03:51:12 +05:30
|
|
|
jobPtr->start(APPLICATION->network());
|
2021-10-17 04:01:27 +05:30
|
|
|
|
|
|
|
QObject::connect(netJob, &NetJob::succeeded, this, &ListModel::requestFinished);
|
|
|
|
QObject::connect(netJob, &NetJob::failed, this, &ListModel::requestFailed);
|
GH-3095 New FTB platform support
Models are based on the models from my go-modpacksch library.
License:
========
The MIT License (MIT)
Copyright (c) Jamie Mansfield <https://www.jamiemansfield.me/>
Copyright (c) contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
2020-06-07 20:44:47 +05:30
|
|
|
}
|
|
|
|
|
2021-10-17 04:01:27 +05:30
|
|
|
void ListModel::requestFinished()
|
GH-3095 New FTB platform support
Models are based on the models from my go-modpacksch library.
License:
========
The MIT License (MIT)
Copyright (c) Jamie Mansfield <https://www.jamiemansfield.me/>
Copyright (c) contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
2020-06-07 20:44:47 +05:30
|
|
|
{
|
|
|
|
jobPtr.reset();
|
|
|
|
remainingPacks.clear();
|
|
|
|
|
|
|
|
QJsonParseError parse_error;
|
|
|
|
QJsonDocument doc = QJsonDocument::fromJson(response, &parse_error);
|
|
|
|
if(parse_error.error != QJsonParseError::NoError) {
|
|
|
|
qWarning() << "Error while parsing JSON response from FTB at " << parse_error.offset << " reason: " << parse_error.errorString();
|
|
|
|
qWarning() << response;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto packs = doc.object().value("packs").toArray();
|
|
|
|
for(auto pack : packs) {
|
|
|
|
auto packId = pack.toInt();
|
|
|
|
remainingPacks.append(packId);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!remainingPacks.isEmpty()) {
|
|
|
|
currentPack = remainingPacks.at(0);
|
|
|
|
requestPack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-17 04:01:27 +05:30
|
|
|
void ListModel::requestFailed(QString reason)
|
GH-3095 New FTB platform support
Models are based on the models from my go-modpacksch library.
License:
========
The MIT License (MIT)
Copyright (c) Jamie Mansfield <https://www.jamiemansfield.me/>
Copyright (c) contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
2020-06-07 20:44:47 +05:30
|
|
|
{
|
|
|
|
jobPtr.reset();
|
|
|
|
remainingPacks.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ListModel::requestPack()
|
|
|
|
{
|
|
|
|
auto *netJob = new NetJob("Ftb::Search");
|
|
|
|
auto searchUrl = QString(BuildConfig.MODPACKSCH_API_BASE_URL + "public/modpack/%1")
|
|
|
|
.arg(currentPack);
|
|
|
|
netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), &response));
|
|
|
|
jobPtr = netJob;
|
2021-11-22 03:51:12 +05:30
|
|
|
jobPtr->start(APPLICATION->network());
|
GH-3095 New FTB platform support
Models are based on the models from my go-modpacksch library.
License:
========
The MIT License (MIT)
Copyright (c) Jamie Mansfield <https://www.jamiemansfield.me/>
Copyright (c) contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
2020-06-07 20:44:47 +05:30
|
|
|
|
|
|
|
QObject::connect(netJob, &NetJob::succeeded, this, &ListModel::packRequestFinished);
|
|
|
|
QObject::connect(netJob, &NetJob::failed, this, &ListModel::packRequestFailed);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ListModel::packRequestFinished()
|
|
|
|
{
|
|
|
|
jobPtr.reset();
|
|
|
|
remainingPacks.removeOne(currentPack);
|
|
|
|
|
|
|
|
QJsonParseError parse_error;
|
|
|
|
QJsonDocument doc = QJsonDocument::fromJson(response, &parse_error);
|
|
|
|
|
|
|
|
if(parse_error.error != QJsonParseError::NoError) {
|
|
|
|
qWarning() << "Error while parsing JSON response from FTB at " << parse_error.offset << " reason: " << parse_error.errorString();
|
|
|
|
qWarning() << response;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto obj = doc.object();
|
|
|
|
|
|
|
|
ModpacksCH::Modpack pack;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
ModpacksCH::loadModpack(pack, obj);
|
|
|
|
}
|
|
|
|
catch (const JSONValidationError &e)
|
|
|
|
{
|
|
|
|
qDebug() << QString::fromUtf8(response);
|
|
|
|
qWarning() << "Error while reading pack manifest from FTB: " << e.cause();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-29 03:43:53 +05:30
|
|
|
// Since there is no guarantee that packs have a version, this will just
|
|
|
|
// ignore those "dud" packs.
|
|
|
|
if (pack.versions.empty())
|
|
|
|
{
|
|
|
|
qWarning() << "FTB Pack " << pack.id << " ignored. reason: lacking any versions";
|
|
|
|
}
|
2020-11-29 19:28:20 +05:30
|
|
|
else
|
|
|
|
{
|
|
|
|
beginInsertRows(QModelIndex(), modpacks.size(), modpacks.size());
|
|
|
|
modpacks.append(pack);
|
|
|
|
endInsertRows();
|
|
|
|
}
|
GH-3095 New FTB platform support
Models are based on the models from my go-modpacksch library.
License:
========
The MIT License (MIT)
Copyright (c) Jamie Mansfield <https://www.jamiemansfield.me/>
Copyright (c) contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
2020-06-07 20:44:47 +05:30
|
|
|
|
|
|
|
if(!remainingPacks.isEmpty()) {
|
|
|
|
currentPack = remainingPacks.at(0);
|
|
|
|
requestPack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ListModel::packRequestFailed(QString reason)
|
|
|
|
{
|
|
|
|
jobPtr.reset();
|
|
|
|
remainingPacks.removeOne(currentPack);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ListModel::logoLoaded(QString logo, bool stale)
|
|
|
|
{
|
|
|
|
auto & logoObj = m_logoMap[logo];
|
|
|
|
logoObj.downloadJob.reset();
|
|
|
|
QString smallPath = logoObj.fullpath + ".small";
|
|
|
|
|
|
|
|
QFileInfo smallInfo(smallPath);
|
|
|
|
|
|
|
|
if(stale || !smallInfo.exists()) {
|
|
|
|
QImage image(logoObj.fullpath);
|
|
|
|
if (image.isNull())
|
|
|
|
{
|
|
|
|
logoObj.failed = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QImage small;
|
|
|
|
if (image.width() > image.height()) {
|
|
|
|
small = image.scaledToWidth(512).scaledToWidth(256, Qt::SmoothTransformation);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
small = image.scaledToHeight(512).scaledToHeight(256, Qt::SmoothTransformation);
|
|
|
|
}
|
|
|
|
QPoint offset((256 - small.width()) / 2, (256 - small.height()) / 2);
|
|
|
|
QImage square(QSize(256, 256), QImage::Format_ARGB32);
|
|
|
|
square.fill(Qt::transparent);
|
|
|
|
|
|
|
|
QPainter painter(&square);
|
|
|
|
painter.drawImage(offset, small);
|
|
|
|
painter.end();
|
|
|
|
|
|
|
|
square.save(logoObj.fullpath + ".small", "PNG");
|
|
|
|
}
|
|
|
|
|
|
|
|
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});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ListModel::logoFailed(QString logo)
|
|
|
|
{
|
|
|
|
m_logoMap[logo].failed = true;
|
|
|
|
m_logoMap[logo].downloadJob.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ListModel::requestLogo(QString logo, QString url)
|
|
|
|
{
|
|
|
|
if(m_logoMap.contains(logo)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-22 03:51:12 +05:30
|
|
|
MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("ModpacksCHPacks", QString("logos/%1").arg(logo.section(".", 0, 0)));
|
GH-3095 New FTB platform support
Models are based on the models from my go-modpacksch library.
License:
========
The MIT License (MIT)
Copyright (c) Jamie Mansfield <https://www.jamiemansfield.me/>
Copyright (c) contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
2020-06-07 20:44:47 +05:30
|
|
|
|
|
|
|
bool stale = entry->isStale();
|
|
|
|
|
|
|
|
NetJob *job = new NetJob(QString("FTB Icon Download %1").arg(logo));
|
|
|
|
job->addNetAction(Net::Download::makeCached(QUrl(url), entry));
|
|
|
|
|
|
|
|
auto fullPath = entry->getFullPath();
|
|
|
|
QObject::connect(job, &NetJob::finished, this, [this, logo, fullPath, stale]
|
|
|
|
{
|
|
|
|
logoLoaded(logo, stale);
|
|
|
|
});
|
|
|
|
|
|
|
|
QObject::connect(job, &NetJob::failed, this, [this, logo]
|
|
|
|
{
|
|
|
|
logoFailed(logo);
|
|
|
|
});
|
|
|
|
|
|
|
|
auto &newLogoEntry = m_logoMap[logo];
|
|
|
|
newLogoEntry.downloadJob = job;
|
|
|
|
newLogoEntry.fullpath = fullPath;
|
2021-11-22 03:51:12 +05:30
|
|
|
job->start(APPLICATION->network());
|
GH-3095 New FTB platform support
Models are based on the models from my go-modpacksch library.
License:
========
The MIT License (MIT)
Copyright (c) Jamie Mansfield <https://www.jamiemansfield.me/>
Copyright (c) contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
2020-06-07 20:44:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|