NOISSUE FTB pack code implementation, cleaned up
This commit is contained in:
parent
6cee50eac6
commit
6aada8adf7
@ -425,6 +425,9 @@ set(FTB_SOURCES
|
||||
modplatform/ftb/FtbPackInstallTask.h
|
||||
modplatform/ftb/FtbPackInstallTask.cpp
|
||||
|
||||
modplatform/ftb/FtbPrivatePackManager.h
|
||||
modplatform/ftb/FtbPrivatePackManager.cpp
|
||||
|
||||
modplatform/ftb/PackHelpers.h
|
||||
)
|
||||
|
||||
|
@ -1,16 +1,12 @@
|
||||
#include "FtbPackFetchTask.h"
|
||||
#include <QDomDocument>
|
||||
|
||||
FtbPackFetchTask::FtbPackFetchTask()
|
||||
{
|
||||
}
|
||||
|
||||
FtbPackFetchTask::~FtbPackFetchTask()
|
||||
{
|
||||
}
|
||||
#include "FtbPrivatePackManager.h"
|
||||
|
||||
void FtbPackFetchTask::fetch()
|
||||
{
|
||||
publicPacks.clear();
|
||||
thirdPartyPacks.clear();
|
||||
|
||||
NetJob *netJob = new NetJob("FtbModpackFetch");
|
||||
|
||||
QUrl publicPacksUrl = QUrl("https://ftb.cursecdn.com/FTB2/static/modpacks.xml");
|
||||
@ -28,23 +24,67 @@ void FtbPackFetchTask::fetch()
|
||||
netJob->start();
|
||||
}
|
||||
|
||||
void FtbPackFetchTask::fetchPrivate(const QStringList & toFetch)
|
||||
{
|
||||
QString privatePackBaseUrl = QString("https://ftb.cursecdn.com/FTB2/static/%1.xml");
|
||||
|
||||
for (auto &packCode: toFetch)
|
||||
{
|
||||
QByteArray *data = new QByteArray();
|
||||
NetJob *job = new NetJob("Fetching private pack");
|
||||
job->addNetAction(Net::Download::makeByteArray(privatePackBaseUrl.arg(packCode), data));
|
||||
|
||||
QObject::connect(job, &NetJob::succeeded, this, [this, job, data, packCode]
|
||||
{
|
||||
FtbModpackList packs;
|
||||
parseAndAddPacks(*data, FtbPackType::Private, packs);
|
||||
foreach(FtbModpack currentPack, packs)
|
||||
{
|
||||
currentPack.packCode = packCode;
|
||||
emit privateFileDownloadFinished(currentPack);
|
||||
}
|
||||
|
||||
job->deleteLater();
|
||||
|
||||
data->clear();
|
||||
delete data;
|
||||
});
|
||||
|
||||
QObject::connect(job, &NetJob::failed, this, [this, job, packCode, data](QString reason)
|
||||
{
|
||||
emit privateFileDownloadFailed(reason, packCode);
|
||||
job->deleteLater();
|
||||
|
||||
data->clear();
|
||||
delete data;
|
||||
});
|
||||
|
||||
job->start();
|
||||
}
|
||||
}
|
||||
|
||||
void FtbPackFetchTask::fileDownloadFinished()
|
||||
{
|
||||
jobPtr.reset();
|
||||
|
||||
QStringList failedLists;
|
||||
|
||||
if(!parseAndAddPacks(publicModpacksXmlFileData, FtbPackType::Public, publicPacks)) {
|
||||
if(!parseAndAddPacks(publicModpacksXmlFileData, FtbPackType::Public, publicPacks))
|
||||
{
|
||||
failedLists.append(tr("Public Packs"));
|
||||
}
|
||||
|
||||
if(!parseAndAddPacks(thirdPartyModpacksXmlFileData, FtbPackType::ThirdParty, thirdPartyPacks)) {
|
||||
if(!parseAndAddPacks(thirdPartyModpacksXmlFileData, FtbPackType::ThirdParty, thirdPartyPacks))
|
||||
{
|
||||
failedLists.append(tr("Third Party Packs"));
|
||||
}
|
||||
|
||||
if(failedLists.size() > 0) {
|
||||
emit failed(QString("Failed to download some pack lists:%1").arg(failedLists.join("\n- ")));
|
||||
} else {
|
||||
if(failedLists.size() > 0)
|
||||
{
|
||||
emit failed(tr("Failed to download some pack lists: %1").arg(failedLists.join("\n- ")));
|
||||
}
|
||||
else
|
||||
{
|
||||
emit finished(publicPacks, thirdPartyPacks);
|
||||
}
|
||||
}
|
||||
@ -57,15 +97,17 @@ bool FtbPackFetchTask::parseAndAddPacks(QByteArray &data, FtbPackType packType,
|
||||
int errorLine = -1;
|
||||
int errorCol = -1;
|
||||
|
||||
if(!doc.setContent(data, false, &errorMsg, &errorLine, &errorCol)){
|
||||
auto fullErrMsg = QString("Failed to fetch modpack data: %s %d:%d!").arg(errorMsg, errorLine, errorCol);
|
||||
if(!doc.setContent(data, false, &errorMsg, &errorLine, &errorCol))
|
||||
{
|
||||
auto fullErrMsg = QString("Failed to fetch modpack data: %1 %2:3d!").arg(errorMsg, errorLine, errorCol);
|
||||
qWarning() << fullErrMsg;
|
||||
data.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
QDomNodeList nodes = doc.elementsByTagName("modpack");
|
||||
for(int i = 0; i < nodes.length(); i++) {
|
||||
for(int i = 0; i < nodes.length(); i++)
|
||||
{
|
||||
QDomElement element = nodes.at(i).toElement();
|
||||
|
||||
FtbModpack modpack;
|
||||
@ -80,19 +122,25 @@ bool FtbPackFetchTask::parseAndAddPacks(QByteArray &data, FtbPackType packType,
|
||||
modpack.bugged = false;
|
||||
|
||||
//remove empty if the xml is bugged
|
||||
for(QString curr : modpack.oldVersions) {
|
||||
if(curr.isNull() || curr.isEmpty()) {
|
||||
for(QString curr : modpack.oldVersions)
|
||||
{
|
||||
if(curr.isNull() || curr.isEmpty())
|
||||
{
|
||||
modpack.oldVersions.removeAll(curr);
|
||||
modpack.bugged = true;
|
||||
qWarning() << "Removed some empty versions from" << modpack.name;
|
||||
}
|
||||
}
|
||||
|
||||
if(modpack.oldVersions.size() < 1) {
|
||||
if(!modpack.currentVersion.isNull() && !modpack.currentVersion.isEmpty()) {
|
||||
if(modpack.oldVersions.size() < 1)
|
||||
{
|
||||
if(!modpack.currentVersion.isNull() && !modpack.currentVersion.isEmpty())
|
||||
{
|
||||
modpack.oldVersions.append(modpack.currentVersion);
|
||||
qWarning() << "Added current version to oldVersions because oldVersions was empty! (" + modpack.name + ")";
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
modpack.broken = true;
|
||||
qWarning() << "Broken pack:" << modpack.name << " => No valid version!";
|
||||
}
|
||||
@ -111,7 +159,8 @@ bool FtbPackFetchTask::parseAndAddPacks(QByteArray &data, FtbPackType packType,
|
||||
return true;
|
||||
}
|
||||
|
||||
void FtbPackFetchTask::fileDownloadFailed(QString reason){
|
||||
qWarning() << "Fetching FtbPacks failed: " << reason;
|
||||
void FtbPackFetchTask::fileDownloadFailed(QString reason)
|
||||
{
|
||||
qWarning() << "Fetching FtbPacks failed:" << reason;
|
||||
emit failed(reason);
|
||||
}
|
||||
|
@ -11,10 +11,11 @@ class MULTIMC_LOGIC_EXPORT FtbPackFetchTask : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FtbPackFetchTask();
|
||||
virtual ~FtbPackFetchTask();
|
||||
FtbPackFetchTask() = default;
|
||||
virtual ~FtbPackFetchTask() = default;
|
||||
|
||||
void fetch();
|
||||
void fetchPrivate(const QStringList &toFetch);
|
||||
|
||||
private:
|
||||
NetJobPtr jobPtr;
|
||||
@ -34,4 +35,6 @@ signals:
|
||||
void finished(FtbModpackList publicPacks, FtbModpackList thirdPartyPacks);
|
||||
void failed(QString reason);
|
||||
|
||||
void privateFileDownloadFinished(FtbModpack modpack);
|
||||
void privateFileDownloadFailed(QString reason, QString packCode);
|
||||
};
|
||||
|
@ -29,7 +29,15 @@ void FtbPackInstallTask::downloadPack()
|
||||
NetJob *job = new NetJob("Download FTB Pack");
|
||||
|
||||
entry->setStale(true);
|
||||
QString url = QString("http://ftb.cursecdn.com/FTB2/modpacks/%1").arg(packoffset);
|
||||
QString url;
|
||||
if(m_pack.type == FtbPackType::Private)
|
||||
{
|
||||
url = QString("http://ftb.cursecdn.com/FTB2/privatepacks/%1").arg(packoffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
url = QString("http://ftb.cursecdn.com/FTB2/modpacks/%1").arg(packoffset);
|
||||
}
|
||||
job->addNetAction(Net::Download::makeCached(url, entry));
|
||||
archivePath = entry->getFullPath();
|
||||
|
||||
|
@ -8,8 +8,8 @@
|
||||
#include "meta/VersionList.h"
|
||||
#include "modplatform/ftb/PackHelpers.h"
|
||||
|
||||
class MULTIMC_LOGIC_EXPORT FtbPackInstallTask : public InstanceTask {
|
||||
|
||||
class MULTIMC_LOGIC_EXPORT FtbPackInstallTask : public InstanceTask
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
36
api/logic/modplatform/ftb/FtbPrivatePackManager.cpp
Normal file
36
api/logic/modplatform/ftb/FtbPrivatePackManager.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include "FtbPrivatePackManager.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include "FileSystem.h"
|
||||
|
||||
void FtbPrivatePackManager::load()
|
||||
{
|
||||
try
|
||||
{
|
||||
currentPacks = QString::fromUtf8(FS::read(m_filename)).split('\n', QString::SkipEmptyParts).toSet();
|
||||
dirty = false;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
currentPacks = {};
|
||||
qWarning() << "Failed to read third party FTB pack codes from" << m_filename;
|
||||
}
|
||||
}
|
||||
|
||||
void FtbPrivatePackManager::save() const
|
||||
{
|
||||
if(!dirty)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
FS::write(m_filename, currentPacks.toList().join('\n').toUtf8());
|
||||
dirty = false;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
qWarning() << "Failed to write third party FTB pack codes to" << m_filename;
|
||||
}
|
||||
}
|
40
api/logic/modplatform/ftb/FtbPrivatePackManager.h
Normal file
40
api/logic/modplatform/ftb/FtbPrivatePackManager.h
Normal file
@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include <QSet>
|
||||
#include <QString>
|
||||
#include <QFile>
|
||||
#include "multimc_logic_export.h"
|
||||
|
||||
class MULTIMC_LOGIC_EXPORT FtbPrivatePackManager
|
||||
{
|
||||
public:
|
||||
~FtbPrivatePackManager()
|
||||
{
|
||||
save();
|
||||
}
|
||||
void load();
|
||||
void save() const;
|
||||
bool empty() const
|
||||
{
|
||||
return currentPacks.empty();
|
||||
}
|
||||
const QSet<QString> &getCurrentPackCodes() const
|
||||
{
|
||||
return currentPacks;
|
||||
}
|
||||
void add(const QString &code)
|
||||
{
|
||||
currentPacks.insert(code);
|
||||
dirty = true;
|
||||
}
|
||||
void remove(const QString &code)
|
||||
{
|
||||
currentPacks.remove(code);
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
private:
|
||||
QSet<QString> currentPacks;
|
||||
QString m_filename = "private_packs.txt";
|
||||
mutable bool dirty = false;
|
||||
};
|
@ -6,13 +6,15 @@
|
||||
#include <QMetaType>
|
||||
|
||||
//Header for structs etc...
|
||||
enum FtbPackType {
|
||||
enum class FtbPackType
|
||||
{
|
||||
Public,
|
||||
ThirdParty,
|
||||
Private
|
||||
};
|
||||
|
||||
struct FtbModpack {
|
||||
struct FtbModpack
|
||||
{
|
||||
QString name;
|
||||
QString description;
|
||||
QString author;
|
||||
@ -30,6 +32,7 @@ struct FtbModpack {
|
||||
bool broken = false;
|
||||
|
||||
FtbPackType type;
|
||||
QString packCode;
|
||||
};
|
||||
|
||||
//We need it for the proxy model
|
||||
|
@ -144,6 +144,12 @@ void NewInstanceDialog::setSuggestedPack(const QString& name, InstanceTask* task
|
||||
creationTask.reset(task);
|
||||
ui->instNameTextBox->setPlaceholderText(name);
|
||||
|
||||
if(!task)
|
||||
{
|
||||
ui->iconButton->setIcon(MMC->icons()->getIcon("default"));
|
||||
importIcon = false;
|
||||
}
|
||||
|
||||
auto allowOK = task && !instName().isEmpty();
|
||||
m_buttons->button(QDialogButtonBox::Ok)->setEnabled(allowOK);
|
||||
}
|
||||
|
@ -1,20 +1,23 @@
|
||||
#include "FTBPage.h"
|
||||
#include "ui_FTBPage.h"
|
||||
|
||||
#include <QInputDialog>
|
||||
|
||||
#include "MultiMC.h"
|
||||
#include "dialogs/CustomMessageBox.h"
|
||||
#include "dialogs/NewInstanceDialog.h"
|
||||
#include "modplatform/ftb/FtbPackFetchTask.h"
|
||||
#include "modplatform/ftb/FtbPackInstallTask.h"
|
||||
#include "modplatform/ftb/FtbPrivatePackManager.h"
|
||||
#include "FtbListModel.h"
|
||||
|
||||
FTBPage::FTBPage(NewInstanceDialog* dialog, QWidget *parent)
|
||||
: QWidget(parent), dialog(dialog), ui(new Ui::FTBPage)
|
||||
{
|
||||
ftbFetchTask = new FtbPackFetchTask();
|
||||
ftbFetchTask.reset(new FtbPackFetchTask());
|
||||
ftbPrivatePacks.reset(new FtbPrivatePackManager());
|
||||
|
||||
ui->setupUi(this);
|
||||
ui->tabWidget->tabBar()->hide();
|
||||
|
||||
{
|
||||
publicFilterModel = new FtbFilterModel(this);
|
||||
@ -49,29 +52,47 @@ FTBPage::FTBPage(NewInstanceDialog* dialog, QWidget *parent)
|
||||
thirdPartyFilterModel->setSorting(publicFilterModel->getCurrentSorting());
|
||||
}
|
||||
|
||||
ui->packVersionSelection->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
ui->packVersionSelection->view()->parentWidget()->setMaximumHeight(300);
|
||||
{
|
||||
privateFilterModel = new FtbFilterModel(this);
|
||||
privateListModel = new FtbListModel(this);
|
||||
privateFilterModel->setSourceModel(privateListModel);
|
||||
|
||||
ui->privatePackList->setModel(privateFilterModel);
|
||||
ui->privatePackList->setSortingEnabled(true);
|
||||
ui->privatePackList->header()->hide();
|
||||
ui->privatePackList->setIndentation(0);
|
||||
ui->privatePackList->setIconSize(QSize(42, 42));
|
||||
|
||||
privateFilterModel->setSorting(publicFilterModel->getCurrentSorting());
|
||||
}
|
||||
|
||||
ui->versionSelectionBox->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
ui->versionSelectionBox->view()->parentWidget()->setMaximumHeight(300);
|
||||
|
||||
connect(ui->sortByBox, &QComboBox::currentTextChanged, this, &FTBPage::onSortingSelectionChanged);
|
||||
connect(ui->packVersionSelection, &QComboBox::currentTextChanged, this, &FTBPage::onVersionSelectionItemChanged);
|
||||
connect(ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &FTBPage::onVersionSelectionItemChanged);
|
||||
|
||||
connect(ui->publicPackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onPublicPackSelectionChanged);
|
||||
connect(ui->thirdPartyPackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onThirdPartyPackSelectionChanged);
|
||||
connect(ui->privatePackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onPrivatePackSelectionChanged);
|
||||
|
||||
connect(ui->ftbTabWidget, &QTabWidget::currentChanged, this, &FTBPage::onTabChanged);
|
||||
connect(ui->addPackBtn, &QPushButton::pressed, this, &FTBPage::onAddPackClicked);
|
||||
connect(ui->removePackBtn, &QPushButton::pressed, this, &FTBPage::onRemovePackClicked);
|
||||
|
||||
ui->modpackInfo->setOpenExternalLinks(true);
|
||||
connect(ui->tabWidget, &QTabWidget::currentChanged, this, &FTBPage::onTabChanged);
|
||||
|
||||
// ui->modpackInfo->setOpenExternalLinks(true);
|
||||
|
||||
ui->publicPackList->selectionModel()->reset();
|
||||
ui->thirdPartyPackList->selectionModel()->reset();
|
||||
ui->privatePackList->selectionModel()->reset();
|
||||
|
||||
onTabChanged(ui->tabWidget->currentIndex());
|
||||
}
|
||||
|
||||
FTBPage::~FTBPage()
|
||||
{
|
||||
delete ui;
|
||||
if(ftbFetchTask) {
|
||||
ftbFetchTask->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
bool FTBPage::shouldDisplay() const
|
||||
@ -83,9 +104,15 @@ void FTBPage::openedImpl()
|
||||
{
|
||||
if(!initialized)
|
||||
{
|
||||
connect(ftbFetchTask, &FtbPackFetchTask::finished, this, &FTBPage::ftbPackDataDownloadSuccessfully);
|
||||
connect(ftbFetchTask, &FtbPackFetchTask::failed, this, &FTBPage::ftbPackDataDownloadFailed);
|
||||
connect(ftbFetchTask.get(), &FtbPackFetchTask::finished, this, &FTBPage::ftbPackDataDownloadSuccessfully);
|
||||
connect(ftbFetchTask.get(), &FtbPackFetchTask::failed, this, &FTBPage::ftbPackDataDownloadFailed);
|
||||
|
||||
connect(ftbFetchTask.get(), &FtbPackFetchTask::privateFileDownloadFinished, this, &FTBPage::ftbPrivatePackDataDownloadSuccessfully);
|
||||
connect(ftbFetchTask.get(), &FtbPackFetchTask::privateFileDownloadFailed, this, &FTBPage::ftbPrivatePackDataDownloadFailed);
|
||||
|
||||
ftbFetchTask->fetch();
|
||||
ftbPrivatePacks->load();
|
||||
ftbFetchTask->fetchPrivate(ftbPrivatePacks->getCurrentPackCodes().toList());
|
||||
initialized = true;
|
||||
}
|
||||
suggestCurrent();
|
||||
@ -98,13 +125,37 @@ void FTBPage::suggestCurrent()
|
||||
if(!selected.broken)
|
||||
{
|
||||
dialog->setSuggestedPack(selected.name, new FtbPackInstallTask(selected, selectedVersion));
|
||||
if(selected.type == FtbPackType::Public) {
|
||||
publicListModel->getLogo(selected.logo, [this](QString logo){
|
||||
dialog->setSuggestedIconFromFile(logo, "ftb_" + selected.name);
|
||||
QString editedLogoName;
|
||||
if(selected.logo.toLower().startsWith("ftb"))
|
||||
{
|
||||
editedLogoName = selected.logo;
|
||||
}
|
||||
else
|
||||
{
|
||||
editedLogoName = "ftb_" + selected.logo;
|
||||
}
|
||||
|
||||
editedLogoName = editedLogoName.left(editedLogoName.lastIndexOf(".png"));
|
||||
|
||||
if(selected.type == FtbPackType::Public)
|
||||
{
|
||||
publicListModel->getLogo(selected.logo, [this, editedLogoName](QString logo)
|
||||
{
|
||||
dialog->setSuggestedIconFromFile(logo, editedLogoName);
|
||||
});
|
||||
} else if (selected.type == FtbPackType::ThirdParty) {
|
||||
thirdPartyModel->getLogo(selected.logo, [this](QString logo){
|
||||
dialog->setSuggestedIconFromFile(logo, "ftb_" + selected.name);
|
||||
}
|
||||
else if (selected.type == FtbPackType::ThirdParty)
|
||||
{
|
||||
thirdPartyModel->getLogo(selected.logo, [this, editedLogoName](QString logo)
|
||||
{
|
||||
dialog->setSuggestedIconFromFile(logo, editedLogoName);
|
||||
});
|
||||
}
|
||||
else if (selected.type == FtbPackType::Private)
|
||||
{
|
||||
privateListModel->getLogo(selected.logo, [this, editedLogoName](QString logo)
|
||||
{
|
||||
dialog->setSuggestedIconFromFile(logo, editedLogoName);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -126,6 +177,24 @@ void FTBPage::ftbPackDataDownloadFailed(QString reason)
|
||||
//TODO: Display the error
|
||||
}
|
||||
|
||||
void FTBPage::ftbPrivatePackDataDownloadSuccessfully(FtbModpack pack)
|
||||
{
|
||||
privateListModel->addPack(pack);
|
||||
}
|
||||
|
||||
void FTBPage::ftbPrivatePackDataDownloadFailed(QString reason, QString packCode)
|
||||
{
|
||||
auto reply = QMessageBox::question(
|
||||
this,
|
||||
tr("FTB private packs"),
|
||||
tr("Failed to download pack information for code %1.\nShould it be removed now?").arg(packCode)
|
||||
);
|
||||
if(reply == QMessageBox::Yes)
|
||||
{
|
||||
ftbPrivatePacks->remove(packCode);
|
||||
}
|
||||
}
|
||||
|
||||
void FTBPage::onPublicPackSelectionChanged(QModelIndex now, QModelIndex prev)
|
||||
{
|
||||
if(!now.isValid())
|
||||
@ -148,13 +217,25 @@ void FTBPage::onThirdPartyPackSelectionChanged(QModelIndex now, QModelIndex prev
|
||||
onPackSelectionChanged(&selectedPack);
|
||||
}
|
||||
|
||||
void FTBPage::onPrivatePackSelectionChanged(QModelIndex now, QModelIndex prev)
|
||||
{
|
||||
if(!now.isValid())
|
||||
{
|
||||
onPackSelectionChanged();
|
||||
return;
|
||||
}
|
||||
FtbModpack selectedPack = privateFilterModel->data(now, Qt::UserRole).value<FtbModpack>();
|
||||
onPackSelectionChanged(&selectedPack);
|
||||
}
|
||||
|
||||
void FTBPage::onPackSelectionChanged(FtbModpack* pack)
|
||||
{
|
||||
ui->packVersionSelection->clear();
|
||||
ui->versionSelectionBox->clear();
|
||||
if(pack)
|
||||
{
|
||||
ui->modpackInfo->setHtml("Pack by <b>" + pack->author + "</b>" + "<br>Minecraft " + pack->mcVersion + "<br>"
|
||||
"<br>" + pack->description + "<ul><li>" + pack->mods.replace(";", "</li><li>") + "</li></ul>");
|
||||
currentModpackInfo->setHtml("Pack by <b>" + pack->author + "</b>" +
|
||||
"<br>Minecraft " + pack->mcVersion + "<br>" + "<br>" + pack->description + "<ul><li>" + pack->mods.replace(";", "</li><li>")
|
||||
+ "</li></ul>");
|
||||
bool currentAdded = false;
|
||||
|
||||
for(int i = 0; i < pack->oldVersions.size(); i++)
|
||||
@ -163,15 +244,25 @@ void FTBPage::onPackSelectionChanged(FtbModpack* pack)
|
||||
{
|
||||
currentAdded = true;
|
||||
}
|
||||
ui->packVersionSelection->addItem(pack->oldVersions.at(i));
|
||||
ui->versionSelectionBox->addItem(pack->oldVersions.at(i));
|
||||
}
|
||||
|
||||
if(!currentAdded)
|
||||
{
|
||||
ui->packVersionSelection->addItem(pack->currentVersion);
|
||||
ui->versionSelectionBox->addItem(pack->currentVersion);
|
||||
}
|
||||
selected = *pack;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentModpackInfo->setHtml("");
|
||||
ui->versionSelectionBox->clear();
|
||||
if(isOpened)
|
||||
{
|
||||
dialog->setSuggestedPack();
|
||||
}
|
||||
return;
|
||||
}
|
||||
suggestCurrent();
|
||||
}
|
||||
|
||||
@ -192,22 +283,31 @@ void FTBPage::onSortingSelectionChanged(QString data)
|
||||
FtbFilterModel::Sorting toSet = publicFilterModel->getAvailableSortings().value(data);
|
||||
publicFilterModel->setSorting(toSet);
|
||||
thirdPartyFilterModel->setSorting(toSet);
|
||||
privateFilterModel->setSorting(toSet);
|
||||
}
|
||||
|
||||
void FTBPage::onTabChanged(int tab)
|
||||
{
|
||||
FtbFilterModel* currentModel = nullptr;
|
||||
QTreeView* currentList = nullptr;
|
||||
if (tab == 0)
|
||||
{
|
||||
currentModel = publicFilterModel;
|
||||
currentList = ui->publicPackList;
|
||||
}
|
||||
else
|
||||
if(tab == 1)
|
||||
{
|
||||
currentModel = thirdPartyFilterModel;
|
||||
currentList = ui->thirdPartyPackList;
|
||||
currentModpackInfo = ui->thirdPartyPackDescription;
|
||||
}
|
||||
else if(tab == 2)
|
||||
{
|
||||
currentModel = privateFilterModel;
|
||||
currentList = ui->privatePackList;
|
||||
currentModpackInfo = ui->privatePackDescription;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentModel = publicFilterModel;
|
||||
currentList = ui->publicPackList;
|
||||
currentModpackInfo = ui->publicPackDescription;
|
||||
}
|
||||
|
||||
currentList->selectionModel()->reset();
|
||||
QModelIndex idx = currentList->currentIndex();
|
||||
if(idx.isValid())
|
||||
{
|
||||
@ -219,3 +319,46 @@ void FTBPage::onTabChanged(int tab)
|
||||
onPackSelectionChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void FTBPage::onAddPackClicked()
|
||||
{
|
||||
bool ok;
|
||||
QString text = QInputDialog::getText(
|
||||
this,
|
||||
tr("Add FTB pack"),
|
||||
tr("Enter pack code:"),
|
||||
QLineEdit::Normal,
|
||||
QString(),
|
||||
&ok
|
||||
);
|
||||
if(ok && !text.isEmpty())
|
||||
{
|
||||
ftbPrivatePacks->add(text);
|
||||
ftbFetchTask->fetchPrivate({text});
|
||||
}
|
||||
}
|
||||
|
||||
void FTBPage::onRemovePackClicked()
|
||||
{
|
||||
auto index = ui->privatePackList->currentIndex();
|
||||
if(!index.isValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
auto row = index.row();
|
||||
FtbModpack pack = privateListModel->at(row);
|
||||
auto answer = QMessageBox::question(
|
||||
this,
|
||||
tr("Remove pack"),
|
||||
tr("Are you sure you want to remove pack %1?").arg(pack.name),
|
||||
QMessageBox::Yes | QMessageBox::No
|
||||
);
|
||||
if(answer != QMessageBox::Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ftbPrivatePacks->remove(pack.packCode);
|
||||
privateListModel->remove(row);
|
||||
onPackSelectionChanged();
|
||||
}
|
||||
|
@ -16,12 +16,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <QTreeView>
|
||||
#include <QTextBrowser>
|
||||
|
||||
#include "pages/BasePage.h"
|
||||
#include <MultiMC.h>
|
||||
#include "tasks/Task.h"
|
||||
#include "modplatform/ftb/PackHelpers.h"
|
||||
#include "modplatform/ftb/FtbPackFetchTask.h"
|
||||
#include "QObjectPtr.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
@ -31,6 +34,9 @@ class FTBPage;
|
||||
class FtbListModel;
|
||||
class FtbFilterModel;
|
||||
class NewInstanceDialog;
|
||||
class FtbPrivatePackListModel;
|
||||
class FtbPrivatePackFilterModel;
|
||||
class FtbPrivatePackManager;
|
||||
|
||||
class FTBPage : public QWidget, public BasePage
|
||||
{
|
||||
@ -66,15 +72,26 @@ private slots:
|
||||
void ftbPackDataDownloadSuccessfully(FtbModpackList publicPacks, FtbModpackList thirdPartyPacks);
|
||||
void ftbPackDataDownloadFailed(QString reason);
|
||||
|
||||
void ftbPrivatePackDataDownloadSuccessfully(FtbModpack pack);
|
||||
void ftbPrivatePackDataDownloadFailed(QString reason, QString packCode);
|
||||
|
||||
void onSortingSelectionChanged(QString data);
|
||||
void onVersionSelectionItemChanged(QString data);
|
||||
|
||||
void onPublicPackSelectionChanged(QModelIndex first, QModelIndex second);
|
||||
void onThirdPartyPackSelectionChanged(QModelIndex first, QModelIndex second);
|
||||
void onPrivatePackSelectionChanged(QModelIndex first, QModelIndex second);
|
||||
|
||||
void onTabChanged(int tab);
|
||||
|
||||
void onAddPackClicked();
|
||||
void onRemovePackClicked();
|
||||
|
||||
private:
|
||||
FtbFilterModel* currentModel = nullptr;
|
||||
QTreeView* currentList = nullptr;
|
||||
QTextBrowser* currentModpackInfo = nullptr;
|
||||
|
||||
bool initialized = false;
|
||||
FtbModpack selected;
|
||||
QString selectedVersion;
|
||||
@ -85,7 +102,12 @@ private:
|
||||
FtbListModel *thirdPartyModel = nullptr;
|
||||
FtbFilterModel *thirdPartyFilterModel = nullptr;
|
||||
|
||||
FtbPackFetchTask *ftbFetchTask = nullptr;
|
||||
FtbListModel *privateListModel = nullptr;
|
||||
FtbFilterModel *privateFilterModel = nullptr;
|
||||
|
||||
unique_qobject_ptr<FtbPackFetchTask> ftbFetchTask;
|
||||
std::unique_ptr<FtbPrivatePackManager> ftbPrivatePacks;
|
||||
|
||||
NewInstanceDialog* dialog = nullptr;
|
||||
|
||||
Ui::FTBPage *ui = nullptr;
|
||||
|
@ -11,18 +11,6 @@
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
@ -30,86 +18,107 @@
|
||||
</property>
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
<string notr="true"/>
|
||||
<string>Public</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout" columnstretch="0,0,0,0">
|
||||
<item row="1" column="2" colspan="2">
|
||||
<widget class="QTextBrowser" name="modpackInfo">
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAsNeeded</enum>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTreeView" name="publicPackList">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>250</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QLabel" name="selectedVersionLabel">
|
||||
<property name="text">
|
||||
<string>Version selected:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
<item row="0" column="1">
|
||||
<widget class="QTextBrowser" name="publicPackDescription"/>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<widget class="QComboBox" name="packVersionSelection"/>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<attribute name="title">
|
||||
<string>3rd Party</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="1">
|
||||
<widget class="QTextBrowser" name="thirdPartyPackDescription"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QComboBox" name="sortByBox"/>
|
||||
</item>
|
||||
<item row="0" column="0" rowspan="2">
|
||||
<widget class="QTabWidget" name="ftbTabWidget">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
<item row="0" column="0">
|
||||
<widget class="QTreeView" name="thirdPartyPackList">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>250</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="tabShape">
|
||||
<enum>QTabWidget::Rounded</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<attribute name="title">
|
||||
<string>Public Packs</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QTreeView" name="publicPackList">
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAsNeeded</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_3">
|
||||
<attribute name="title">
|
||||
<string>3rd Party Packs</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QTreeView" name="thirdPartyPackList">
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAsNeeded</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_3">
|
||||
<attribute name="title">
|
||||
<string>Private</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTreeView" name="privatePackList">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>250</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QPushButton" name="addPackBtn">
|
||||
<property name="text">
|
||||
<string>Add pack</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QPushButton" name="removePackBtn">
|
||||
<property name="text">
|
||||
<string>Remove selected pack</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" rowspan="3">
|
||||
<widget class="QTextBrowser" name="privatePackDescription"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Version selected:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QComboBox" name="versionSelectionBox"/>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QComboBox" name="sortByBox">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>265</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
@ -72,15 +72,17 @@ FtbListModel::~FtbListModel()
|
||||
|
||||
QString FtbListModel::translatePackType(FtbPackType type) const
|
||||
{
|
||||
if(type == FtbPackType::Public) {
|
||||
return tr("Public Modpack");
|
||||
} else if(type == FtbPackType::ThirdParty) {
|
||||
return tr("Third Party Modpack");
|
||||
} else if(type == FtbPackType::Private) {
|
||||
return tr("Private Modpack");
|
||||
} else {
|
||||
return tr("Unknown Type");
|
||||
switch(type)
|
||||
{
|
||||
case FtbPackType::Public:
|
||||
return tr("Public Modpack");
|
||||
case FtbPackType::ThirdParty:
|
||||
return tr("Third Party Modpack");
|
||||
case FtbPackType::Private:
|
||||
return tr("Private Modpack");
|
||||
}
|
||||
qWarning() << "Unknown FTB modpack type:" << int(type);
|
||||
return QString();
|
||||
}
|
||||
|
||||
int FtbListModel::rowCount(const QModelIndex &parent) const
|
||||
@ -96,15 +98,20 @@ int FtbListModel::columnCount(const QModelIndex &parent) const
|
||||
QVariant FtbListModel::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);
|
||||
}
|
||||
|
||||
FtbModpack pack = modpacks.at(pos);
|
||||
if(role == Qt::DisplayRole) {
|
||||
if(role == Qt::DisplayRole)
|
||||
{
|
||||
return pack.name + "\n" + translatePackType(pack.type);
|
||||
} else if (role == Qt::ToolTipRole) {
|
||||
if(pack.description.length() > 100) {
|
||||
}
|
||||
else if (role == Qt::ToolTipRole)
|
||||
{
|
||||
if(pack.description.length() > 100)
|
||||
{
|
||||
//some magic to prevent to long tooltips and replace html linebreaks
|
||||
QString edit = pack.description.left(97);
|
||||
edit = edit.left(edit.lastIndexOf("<br>")).left(edit.lastIndexOf(" ")).append("...");
|
||||
@ -112,23 +119,33 @@ QVariant FtbListModel::data(const QModelIndex &index, int role) const
|
||||
|
||||
}
|
||||
return pack.description;
|
||||
} else if(role == Qt::DecorationRole) {
|
||||
if(m_logoMap.contains(pack.logo)) {
|
||||
}
|
||||
else if(role == Qt::DecorationRole)
|
||||
{
|
||||
if(m_logoMap.contains(pack.logo))
|
||||
{
|
||||
return (m_logoMap.value(pack.logo));
|
||||
}
|
||||
QIcon icon = MMC->getThemedIcon("screenshot-placeholder");
|
||||
((FtbListModel *)this)->requestLogo(pack.logo);
|
||||
return icon;
|
||||
} else if(role == Qt::TextColorRole) {
|
||||
if(pack.broken) {
|
||||
}
|
||||
else if(role == Qt::TextColorRole)
|
||||
{
|
||||
if(pack.broken)
|
||||
{
|
||||
//FIXME: Hardcoded color
|
||||
return QColor(255, 0, 50);
|
||||
} else if(pack.bugged) {
|
||||
}
|
||||
else if(pack.bugged)
|
||||
{
|
||||
//FIXME: Hardcoded color
|
||||
//bugged pack, currently only indicates bugged xml
|
||||
return QColor(244, 229, 66);
|
||||
}
|
||||
} else if(role == Qt::UserRole) {
|
||||
}
|
||||
else if(role == Qt::UserRole)
|
||||
{
|
||||
QVariant v;
|
||||
v.setValue(pack);
|
||||
return v;
|
||||
@ -144,11 +161,37 @@ void FtbListModel::fill(FtbModpackList modpacks)
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void FtbListModel::addPack(FtbModpack modpack)
|
||||
{
|
||||
beginResetModel();
|
||||
this->modpacks.append(modpack);
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void FtbListModel::clear()
|
||||
{
|
||||
beginResetModel();
|
||||
modpacks.clear();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
FtbModpack FtbListModel::at(int row)
|
||||
{
|
||||
return modpacks.at(row);
|
||||
}
|
||||
|
||||
void FtbListModel::remove(int row)
|
||||
{
|
||||
if(row < 0 || row >= modpacks.size())
|
||||
{
|
||||
qWarning() << "Attempt to remove FTB modpacks with invalid row" << row;
|
||||
return;
|
||||
}
|
||||
beginRemoveRows(QModelIndex(), row, row);
|
||||
modpacks.removeAt(row);
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
void FtbListModel::logoLoaded(QString logo, QIcon out)
|
||||
{
|
||||
m_loadingLogos.removeAll(logo);
|
||||
@ -164,7 +207,8 @@ void FtbListModel::logoFailed(QString logo)
|
||||
|
||||
void FtbListModel::requestLogo(QString file)
|
||||
{
|
||||
if(m_loadingLogos.contains(file) || m_failedLogos.contains(file)) {
|
||||
if(m_loadingLogos.contains(file) || m_failedLogos.contains(file))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@ -173,14 +217,17 @@ void FtbListModel::requestLogo(QString file)
|
||||
job->addNetAction(Net::Download::makeCached(QUrl(QString("https://ftb.cursecdn.com/FTB2/static/%1").arg(file)), entry));
|
||||
|
||||
auto fullPath = entry->getFullPath();
|
||||
QObject::connect(job, &NetJob::finished, this, [this, file, fullPath]{
|
||||
QObject::connect(job, &NetJob::finished, this, [this, file, fullPath]
|
||||
{
|
||||
emit logoLoaded(file, QIcon(fullPath));
|
||||
if(waitingCallbacks.contains(file)) {
|
||||
if(waitingCallbacks.contains(file))
|
||||
{
|
||||
waitingCallbacks.value(file)(fullPath);
|
||||
}
|
||||
});
|
||||
|
||||
QObject::connect(job, &NetJob::failed, this, [this, file]{
|
||||
QObject::connect(job, &NetJob::failed, this, [this, file]
|
||||
{
|
||||
emit logoFailed(file);
|
||||
});
|
||||
|
||||
@ -191,9 +238,17 @@ void FtbListModel::requestLogo(QString file)
|
||||
|
||||
void FtbListModel::getLogo(const QString &logo, LogoCallback callback)
|
||||
{
|
||||
if(m_logoMap.contains(logo)) {
|
||||
if(m_logoMap.contains(logo))
|
||||
{
|
||||
callback(ENV.metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(logo.section(".", 0, 0)))->getFullPath());
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
requestLogo(logo);
|
||||
}
|
||||
}
|
||||
|
||||
Qt::ItemFlags FtbListModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
return QAbstractListModel::flags(index);
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QThreadPool>
|
||||
#include <QIcon>
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
#include <functional>
|
||||
|
||||
@ -60,8 +61,12 @@ public:
|
||||
int rowCount(const QModelIndex &parent) const override;
|
||||
int columnCount(const QModelIndex &parent) const override;
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
|
||||
void fill(FtbModpackList modpacks);
|
||||
void addPack(FtbModpack modpack);
|
||||
void clear();
|
||||
void remove(int row);
|
||||
|
||||
FtbModpack at(int row);
|
||||
void getLogo(const QString &logo, LogoCallback callback);
|
||||
|
Loading…
Reference in New Issue
Block a user