From bbd523acb8bf846d27a7859d1d79f28ea92de245 Mon Sep 17 00:00:00 2001 From: Janrupf Date: Sun, 1 Apr 2018 20:24:28 +0200 Subject: [PATCH] NOISSUE Added FTB Pack logos to chooser and fixed some missing includes --- api/logic/CMakeLists.txt | 4 - api/logic/RWStorage.h | 2 + .../modplatform/ftb/FtbPackDownloader.cpp | 57 ------------ api/logic/modplatform/ftb/FtbPackDownloader.h | 39 -------- .../modplatform/ftb/FtbPackFetchTask.cpp | 63 ++++++++----- api/logic/modplatform/ftb/FtbPackFetchTask.h | 10 +- .../modplatform/ftb/FtbPackInstallTask.h | 2 +- api/logic/modplatform/ftb/PackHelpers.h | 15 ++- application/FtbListModel.cpp | 91 +++++++++++++++++-- application/FtbListModel.h | 23 ++++- application/MainWindow.h | 1 - application/pages/modplatform/FTBPage.cpp | 87 +++++++++++------- application/pages/modplatform/FTBPage.h | 24 +++-- application/pages/modplatform/FTBPage.ui | 79 +++++++++++++--- 14 files changed, 306 insertions(+), 191 deletions(-) delete mode 100644 api/logic/modplatform/ftb/FtbPackDownloader.cpp delete mode 100644 api/logic/modplatform/ftb/FtbPackDownloader.h diff --git a/api/logic/CMakeLists.txt b/api/logic/CMakeLists.txt index c6daef6f..d6b61d23 100644 --- a/api/logic/CMakeLists.txt +++ b/api/logic/CMakeLists.txt @@ -421,10 +421,6 @@ set(META_SOURCES ) set(FTB_SOURCES - # Modplatform sources - modplatform/ftb/FtbPackDownloader.h - modplatform/ftb/FtbPackDownloader.cpp - modplatform/ftb/FtbPackFetchTask.h modplatform/ftb/FtbPackFetchTask.cpp modplatform/ftb/FtbPackInstallTask.h diff --git a/api/logic/RWStorage.h b/api/logic/RWStorage.h index bbe8ac5a..4afbd96c 100644 --- a/api/logic/RWStorage.h +++ b/api/logic/RWStorage.h @@ -1,4 +1,6 @@ #pragma once +#include +#include template class RWStorage { diff --git a/api/logic/modplatform/ftb/FtbPackDownloader.cpp b/api/logic/modplatform/ftb/FtbPackDownloader.cpp deleted file mode 100644 index 3e274c9e..00000000 --- a/api/logic/modplatform/ftb/FtbPackDownloader.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "FtbPackDownloader.h" -#include "PackHelpers.h" -#include "FtbPackFetchTask.h" -#include "Env.h" - -FtbPackDownloader::FtbPackDownloader() -{ - done = false; - fetching = false; -} - -FtbPackDownloader::~FtbPackDownloader() -{ -} - -FtbModpackList FtbPackDownloader::getModpacks() -{ - return static_cast(fetchedPacks.values()); -} - -void FtbPackDownloader::fetchModpacks(bool force = false) -{ - if(fetching || (!force && done)) - { - qDebug() << "Skipping modpack refetch because done or already fetching [done =>" << done << "| fetching =>" << fetching << "]"; - return; - } - - fetching = true; - - fetchTask = new FtbPackFetchTask(); - connect(fetchTask, &FtbPackFetchTask::finished, this, &FtbPackDownloader::fetchSuccess); - connect(fetchTask, &FtbPackFetchTask::failed, this, &FtbPackDownloader::fetchFailed); - fetchTask->fetch(); -} - - -void FtbPackDownloader::fetchSuccess(FtbModpackList modpacks) -{ - for(int i = 0; i < modpacks.size(); i++) - { - fetchedPacks.insert(modpacks.at(i).name, modpacks.at(i)); - } - - fetching = false; - done = true; - emit ready(); - fetchTask->deleteLater(); -} - -void FtbPackDownloader::fetchFailed(QString reason) -{ - qWarning() << "Failed to fetch FtbData" << reason; - fetching = false; - emit packFetchFailed(); - fetchTask->deleteLater(); -} diff --git a/api/logic/modplatform/ftb/FtbPackDownloader.h b/api/logic/modplatform/ftb/FtbPackDownloader.h deleted file mode 100644 index cf7eb567..00000000 --- a/api/logic/modplatform/ftb/FtbPackDownloader.h +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include -#include -#include -#include "FtbPackFetchTask.h" -#include "tasks/Task.h" -#include "net/NetJob.h" - -#include "PackHelpers.h" -#include "Env.h" - -#pragma once - -class MULTIMC_LOGIC_EXPORT FtbPackDownloader : public QObject -{ - Q_OBJECT - -public: - FtbPackDownloader(); - virtual ~FtbPackDownloader(); - - void fetchModpacks(bool force); - FtbModpackList getModpacks(); - -signals: - void ready(); - void packFetchFailed(); - -private slots: - void fetchSuccess(FtbModpackList modlist); - void fetchFailed(QString reason); - -private: - QMap fetchedPacks; - bool fetching = false; - bool done = false; - - FtbPackFetchTask *fetchTask = 0; -}; diff --git a/api/logic/modplatform/ftb/FtbPackFetchTask.cpp b/api/logic/modplatform/ftb/FtbPackFetchTask.cpp index 30253bb9..5588a7fd 100644 --- a/api/logic/modplatform/ftb/FtbPackFetchTask.cpp +++ b/api/logic/modplatform/ftb/FtbPackFetchTask.cpp @@ -1,21 +1,25 @@ #include "FtbPackFetchTask.h" #include -FtbPackFetchTask::FtbPackFetchTask() { - +FtbPackFetchTask::FtbPackFetchTask() +{ } -FtbPackFetchTask::~FtbPackFetchTask() { - +FtbPackFetchTask::~FtbPackFetchTask() +{ } -void FtbPackFetchTask::fetch() { +void FtbPackFetchTask::fetch() +{ NetJob *netJob = new NetJob("FtbModpackFetch"); - QUrl url = QUrl("https://ftb.cursecdn.com/FTB2/static/modpacks.xml"); - qDebug() << "Downloading version info from " << url.toString(); + QUrl publicPacksUrl = QUrl("https://ftb.cursecdn.com/FTB2/static/modpacks.xml"); + qDebug() << "Downloading public version info from" << publicPacksUrl.toString(); + netJob->addNetAction(Net::Download::makeByteArray(publicPacksUrl, &publicModpacksXmlFileData)); - netJob->addNetAction(downloadPtr = Net::Download::makeByteArray(url, &modpacksXmlFileData)); + QUrl thirdPartyUrl = QUrl("https://ftb.cursecdn.com/FTB2/static/thirdparty.xml"); + qDebug() << "Downloading thirdparty version info from" << thirdPartyUrl.toString(); + netJob->addNetAction(Net::Download::makeByteArray(thirdPartyUrl, &thirdPartyModpacksXmlFileData)); QObject::connect(netJob, &NetJob::succeeded, this, &FtbPackFetchTask::fileDownloadFinished); QObject::connect(netJob, &NetJob::failed, this, &FtbPackFetchTask::fileDownloadFailed); @@ -24,28 +28,42 @@ void FtbPackFetchTask::fetch() { netJob->start(); } -void FtbPackFetchTask::fileDownloadFinished(){ - +void FtbPackFetchTask::fileDownloadFinished() +{ jobPtr.reset(); + QStringList failedLists; + + if(!parseAndAddPacks(publicModpacksXmlFileData, FtbPackType::Public, publicPacks)) { + failedLists.append(tr("Public Packs")); + } + + 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 { + emit finished(publicPacks, thirdPartyPacks); + } +} + +bool FtbPackFetchTask::parseAndAddPacks(QByteArray &data, FtbPackType packType, FtbModpackList &list) +{ QDomDocument doc; QString errorMsg = "Unknown error."; int errorLine = -1; int errorCol = -1; - if(!doc.setContent(modpacksXmlFileData, false, &errorMsg, &errorLine, &errorCol)){ + if(!doc.setContent(data, false, &errorMsg, &errorLine, &errorCol)){ auto fullErrMsg = QString("Failed to fetch modpack data: %s %d:%d!").arg(errorMsg, errorLine, errorCol); qWarning() << fullErrMsg; - emit failed(fullErrMsg); - modpacksXmlFileData.clear(); - return; + data.clear(); + return false; } - modpacksXmlFileData.clear(); - - FtbModpackList modpackList; - QDomNodeList nodes = doc.elementsByTagName("modpack"); for(int i = 0; i < nodes.length(); i++) { QDomElement element = nodes.at(i).toElement(); @@ -56,7 +74,7 @@ void FtbPackFetchTask::fileDownloadFinished(){ modpack.mcVersion = element.attribute("mcVersion"); modpack.description = element.attribute("description"); modpack.mods = element.attribute("mods"); - modpack.image = element.attribute("image"); + modpack.logo = element.attribute("logo"); modpack.oldVersions = element.attribute("oldVersions").split(";"); modpack.broken = false; modpack.bugged = false; @@ -85,11 +103,12 @@ void FtbPackFetchTask::fileDownloadFinished(){ modpack.dir = element.attribute("dir"); modpack.file = element.attribute("url"); - modpackList.append(modpack); + modpack.type = packType; + + list.append(modpack); } - - emit finished(modpackList); + return true; } void FtbPackFetchTask::fileDownloadFailed(QString reason){ diff --git a/api/logic/modplatform/ftb/FtbPackFetchTask.h b/api/logic/modplatform/ftb/FtbPackFetchTask.h index a2e4b5ab..b5635b12 100644 --- a/api/logic/modplatform/ftb/FtbPackFetchTask.h +++ b/api/logic/modplatform/ftb/FtbPackFetchTask.h @@ -18,16 +18,20 @@ public: private: NetJobPtr jobPtr; - Net::Download::Ptr downloadPtr; - QByteArray modpacksXmlFileData; + QByteArray publicModpacksXmlFileData; + QByteArray thirdPartyModpacksXmlFileData; + + bool parseAndAddPacks(QByteArray &data, FtbPackType packType, FtbModpackList &list); + FtbModpackList publicPacks; + FtbModpackList thirdPartyPacks; protected slots: void fileDownloadFinished(); void fileDownloadFailed(QString reason); signals: - void finished(FtbModpackList list); + void finished(FtbModpackList publicPacks, FtbModpackList thirdPartyPacks); void failed(QString reason); }; diff --git a/api/logic/modplatform/ftb/FtbPackInstallTask.h b/api/logic/modplatform/ftb/FtbPackInstallTask.h index 64f4809d..0bfba3d6 100644 --- a/api/logic/modplatform/ftb/FtbPackInstallTask.h +++ b/api/logic/modplatform/ftb/FtbPackInstallTask.h @@ -1,6 +1,5 @@ #pragma once #include "InstanceTask.h" -#include "modplatform/ftb/FtbPackDownloader.h" #include "BaseInstanceProvider.h" #include "net/NetJob.h" #include "quazip.h" @@ -8,6 +7,7 @@ #include "meta/Index.h" #include "meta/Version.h" #include "meta/VersionList.h" +#include "modplatform/ftb/PackHelpers.h" class MULTIMC_LOGIC_EXPORT FtbPackInstallTask : public InstanceTask { diff --git a/api/logic/modplatform/ftb/PackHelpers.h b/api/logic/modplatform/ftb/PackHelpers.h index b184ed33..350a5fa6 100644 --- a/api/logic/modplatform/ftb/PackHelpers.h +++ b/api/logic/modplatform/ftb/PackHelpers.h @@ -3,6 +3,12 @@ #include "qmetatype.h" //Header for structs etc... +enum FtbPackType { + Public, + ThirdParty, + Private +}; + struct FtbModpack { QString name; QString description; @@ -11,15 +17,18 @@ struct FtbModpack { QString currentVersion; QString mcVersion; QString mods; - QString image; + QString logo; //Technical data QString dir; QString file; //<- Url in the xml, but doesn't make much sense - bool bugged = true; - bool broken = true; + bool bugged = false; + bool broken = false; + + FtbPackType type; }; + //We need it for the proxy model Q_DECLARE_METATYPE(FtbModpack) diff --git a/application/FtbListModel.cpp b/application/FtbListModel.cpp index d79bcac0..d8c18ee5 100644 --- a/application/FtbListModel.cpp +++ b/application/FtbListModel.cpp @@ -5,12 +5,16 @@ #include #include +#include + +#include +#include FtbFilterModel::FtbFilterModel(QObject *parent) : QSortFilterProxyModel(parent) { currentSorting = Sorting::ByGameVersion; - sortings.insert("Sort by name", Sorting::ByName); - sortings.insert("Sort by game version", Sorting::ByGameVersion); + sortings.insert(tr("Sort by name"), Sorting::ByName); + sortings.insert(tr("Sort by game version"), Sorting::ByGameVersion); } bool FtbFilterModel::lessThan(const QModelIndex &left, const QModelIndex &right) const @@ -42,6 +46,11 @@ const QMap FtbFilterModel::getAvailableSorting return sortings; } +QString FtbFilterModel::translateCurrentSorting() +{ + return sortings.key(currentSorting); +} + void FtbFilterModel::setSorting(Sorting s) { currentSorting = s; @@ -55,6 +64,27 @@ FtbFilterModel::Sorting FtbFilterModel::getCurrentSorting() FtbListModel::FtbListModel(QObject *parent) : QAbstractListModel(parent) { + m_logoPool = new QThreadPool(this); + m_logoPool->setMaxThreadCount(4); +} + +FtbListModel::~FtbListModel() +{ + m_logoPool->waitForDone(500); + m_logoPool->deleteLater(); +} + +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"); + } } int FtbListModel::rowCount(const QModelIndex &parent) const @@ -70,14 +100,13 @@ int FtbListModel::columnCount(const QModelIndex &parent) const QVariant FtbListModel::data(const QModelIndex &index, int role) const { int pos = index.row(); - if(modpacks.size() <= pos || pos < 0) { + if(modpacks.size() <= pos || pos < 0 || !index.isValid()) { return QString("INVALID INDEX %1").arg(pos); } FtbModpack pack = modpacks.at(pos); - if(role == Qt::DisplayRole) { - return pack.name; + return pack.name + "\n" + translatePackType(pack.type); } else if (role == Qt::ToolTipRole) { if(pack.description.length() > 100) { //some magic to prevent to long tooltips and replace html linebreaks @@ -88,7 +117,12 @@ QVariant FtbListModel::data(const QModelIndex &index, int role) const } return pack.description; } else if(role == Qt::DecorationRole) { - //TODO: Add pack logos or something... but they have a weird size. This needs some design hacks + if(m_logoMap.contains(pack.logo)) { + return (m_logoMap.value(pack.logo)); + } + QPixmap pixmap = MMC->getThemedIcon("screenshot-placeholder").pixmap(QSize(42, 42)); + ((FtbListModel *)this)->requestLogo(pack.logo); + return pixmap; } else if(role == Qt::TextColorRole) { if(pack.broken) { //FIXME: Hardcoded color @@ -103,6 +137,7 @@ QVariant FtbListModel::data(const QModelIndex &index, int role) const v.setValue(pack); return v; } + return QVariant(); } @@ -117,3 +152,47 @@ FtbModpack FtbListModel::at(int row) { return modpacks.at(row); } + +void FtbListModel::logoLoaded(QString logo, QPixmap out) +{ + m_loadingLogos.removeAll(logo); + m_logoMap.insert(logo, out); + emit dataChanged(createIndex(0, 0), createIndex(modpacks.size(), 0)); +} + +void FtbListModel::logoFailed(QString logo) +{ + m_failedLogos.append(logo); + m_loadingLogos.removeAll(logo); +} + +void FtbListModel::requestLogo(QString file) +{ + if(m_loadingLogos.contains(file) || m_failedLogos.contains(file)) { + return; + } + + MetaEntryPtr entry = ENV.metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(file)); + NetJob *job = new NetJob(QString("FTB Icon Download for %1").arg(file)); + job->addNetAction(Net::Download::makeCached(QUrl(QString("https://ftb.cursecdn.com/FTB2/static/%1").arg(file)), entry)); + + QString *_file = new QString(file); + MetaEntry *_entry = entry.get(); + + QObject::connect(job, &NetJob::finished, this, [this, _file, _entry]{ + QPixmap pixmap; + pixmap.load(_entry->getFullPath()); + pixmap = pixmap.scaled(QSize(42, 42)); + emit logoLoaded(*_file, pixmap); + }); + + QObject::connect(job, &NetJob::failed, this, [this, _file]{ + emit logoFailed(*_file); + }); + + job->start(); + + m_loadingLogos.append(file); +} + +#include "FtbListModel.moc" diff --git a/application/FtbListModel.h b/application/FtbListModel.h index 41fc3ccd..747c65bd 100644 --- a/application/FtbListModel.h +++ b/application/FtbListModel.h @@ -3,6 +3,13 @@ #include #include #include +#include + +#include + +#include + +typedef QMap FtbLogoMap; class FtbFilterModel : public QSortFilterProxyModel { @@ -13,8 +20,9 @@ public: ByGameVersion }; const QMap getAvailableSortings(); - Sorting getCurrentSorting(); + QString translateCurrentSorting(); void setSorting(Sorting sorting); + Sorting getCurrentSorting(); protected: bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; @@ -31,9 +39,22 @@ class FtbListModel : public QAbstractListModel Q_OBJECT private: FtbModpackList modpacks; + QThreadPool *m_logoPool; + QStringList m_failedLogos; + QStringList m_loadingLogos; + FtbLogoMap m_logoMap; + + void requestLogo(QString file); + QString translatePackType(FtbPackType type) const; + + +private slots: + void logoFailed(QString logo); + void logoLoaded(QString logo, QPixmap out); public: FtbListModel(QObject *parent); + ~FtbListModel(); int rowCount(const QModelIndex &parent) const override; int columnCount(const QModelIndex &parent) const override; QVariant data(const QModelIndex &index, int role) const override; diff --git a/application/MainWindow.h b/application/MainWindow.h index 609df4ca..8f756412 100644 --- a/application/MainWindow.h +++ b/application/MainWindow.h @@ -25,7 +25,6 @@ #include "minecraft/auth/MojangAccount.h" #include "net/NetJob.h" #include "updater/GoUpdate.h" -#include class LaunchController; class NewsChecker; diff --git a/application/pages/modplatform/FTBPage.cpp b/application/pages/modplatform/FTBPage.cpp index 26b1e30b..3b808799 100644 --- a/application/pages/modplatform/FTBPage.cpp +++ b/application/pages/modplatform/FTBPage.cpp @@ -5,41 +5,53 @@ #include "FolderInstanceProvider.h" #include "dialogs/CustomMessageBox.h" #include "dialogs/NewInstanceDialog.h" -#include "modplatform/ftb/FtbPackDownloader.h" +#include "modplatform/ftb/FtbPackFetchTask.h" #include "modplatform/ftb/FtbPackInstallTask.h" #include FTBPage::FTBPage(NewInstanceDialog* dialog, QWidget *parent) : QWidget(parent), dialog(dialog), ui(new Ui::FTBPage) { + ftbFetchTask = new FtbPackFetchTask(); + ui->setupUi(this); ui->tabWidget->tabBar()->hide(); - ftbPackDownloader = new FtbPackDownloader(); - connect(ftbPackDownloader, &FtbPackDownloader::ready, this, &FTBPage::ftbPackDataDownloadSuccessfully); - connect(ftbPackDownloader, &FtbPackDownloader::packFetchFailed, this, &FTBPage::ftbPackDataDownloadFailed); - - filterModel = new FtbFilterModel(this); - listModel = new FtbListModel(this); - filterModel->setSourceModel(listModel); - - ui->packList->setModel(filterModel); - ui->packList->setSortingEnabled(true); - ui->packList->header()->hide(); - ui->packList->setIndentation(0); - - filterModel->setSorting(FtbFilterModel::Sorting::ByName); - - for(int i = 0; i < filterModel->getAvailableSortings().size(); i++) { - ui->sortByBox->addItem(filterModel->getAvailableSortings().keys().at(i)); + publicFilterModel = new FtbFilterModel(this); + publicListModel = new FtbListModel(this); + publicFilterModel->setSourceModel(publicListModel); + + ui->publicPackList->setModel(publicFilterModel); + ui->publicPackList->setSortingEnabled(true); + ui->publicPackList->header()->hide(); + ui->publicPackList->setIndentation(0); + + for(int i = 0; i < publicFilterModel->getAvailableSortings().size(); i++) + { + ui->sortByBox->addItem(publicFilterModel->getAvailableSortings().keys().at(i)); + } + + ui->sortByBox->setCurrentText(publicFilterModel->translateCurrentSorting()); } - ui->sortByBox->setCurrentText(filterModel->getAvailableSortings().key(filterModel->getCurrentSorting())); + { + thirdPartyFilterModel = new FtbFilterModel(this); + thirdPartyModel = new FtbListModel(this); + thirdPartyFilterModel->setSourceModel(thirdPartyModel); + + ui->thirdPartyPackList->setModel(thirdPartyFilterModel); + ui->thirdPartyPackList->setSortingEnabled(true); + ui->thirdPartyPackList->header()->hide(); + ui->thirdPartyPackList->setIndentation(0); + thirdPartyFilterModel->setSorting(publicFilterModel->getCurrentSorting()); + } connect(ui->sortByBox, &QComboBox::currentTextChanged, this, &FTBPage::onSortingSelectionChanged); connect(ui->packVersionSelection, &QComboBox::currentTextChanged, this, &FTBPage::onVersionSelectionItemChanged); - connect(ui->packList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onPackSelectionChanged); + + connect(ui->publicPackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onPublicPackSelectionChanged); + connect(ui->thirdPartyPackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onThirdPartyPackSelectionChanged); ui->modpackInfo->setOpenExternalLinks(true); } @@ -47,9 +59,8 @@ FTBPage::FTBPage(NewInstanceDialog* dialog, QWidget *parent) FTBPage::~FTBPage() { delete ui; - if(ftbPackDownloader) - { - ftbPackDownloader->deleteLater(); + if(ftbFetchTask) { + ftbFetchTask->deleteLater(); } } @@ -62,7 +73,9 @@ void FTBPage::openedImpl() { if(!initialized) { - ftbPackDownloader->fetchModpacks(false); + connect(ftbFetchTask, &FtbPackFetchTask::finished, this, &FTBPage::ftbPackDataDownloadSuccessfully); + connect(ftbFetchTask, &FtbPackFetchTask::failed, this, &FTBPage::ftbPackDataDownloadFailed); + ftbFetchTask->fetch(); initialized = true; } suggestCurrent(); @@ -83,25 +96,31 @@ void FTBPage::suggestCurrent() } } -FtbPackDownloader *FTBPage::getFtbPackDownloader() +void FTBPage::ftbPackDataDownloadSuccessfully(FtbModpackList publicPacks, FtbModpackList thirdPartyPacks) { - return ftbPackDownloader; + publicListModel->fill(publicPacks); + thirdPartyModel->fill(thirdPartyPacks); } -void FTBPage::ftbPackDataDownloadSuccessfully() +void FTBPage::ftbPackDataDownloadFailed(QString reason) { - listModel->fill(ftbPackDownloader->getModpacks()); + //TODO: Display the error } -void FTBPage::ftbPackDataDownloadFailed() +void FTBPage::onPublicPackSelectionChanged(QModelIndex first, QModelIndex second) { - qDebug() << "Stuff went missing while grabbing FTB pack list or something..."; + onPackSelectionChanged(first, second, publicFilterModel); } -void FTBPage::onPackSelectionChanged(QModelIndex now, QModelIndex prev) +void FTBPage::onThirdPartyPackSelectionChanged(QModelIndex first, QModelIndex second) +{ + onPackSelectionChanged(first, second, thirdPartyFilterModel); +} + +void FTBPage::onPackSelectionChanged(QModelIndex now, QModelIndex prev, FtbFilterModel *model) { ui->packVersionSelection->clear(); - FtbModpack selectedPack = filterModel->data(now, Qt::UserRole).value(); + FtbModpack selectedPack = model->data(now, Qt::UserRole).value(); ui->modpackInfo->setHtml("Pack by " + selectedPack.author + "" + "
Minecraft " + selectedPack.mcVersion + "
" "
" + selectedPack.description + "
  • " + selectedPack.mods.replace(";", "
  • ") + "
"); @@ -149,5 +168,7 @@ QString FTBPage::getSelectedVersion() void FTBPage::onSortingSelectionChanged(QString data) { - filterModel->setSorting(filterModel->getAvailableSortings().value(data)); + FtbFilterModel::Sorting toSet = publicFilterModel->getAvailableSortings().value(data); + publicFilterModel->setSorting(toSet); + thirdPartyFilterModel->setSorting(toSet); } diff --git a/application/pages/modplatform/FTBPage.h b/application/pages/modplatform/FTBPage.h index f7d6ca8b..ba8dd299 100644 --- a/application/pages/modplatform/FTBPage.h +++ b/application/pages/modplatform/FTBPage.h @@ -21,6 +21,7 @@ #include #include "tasks/Task.h" #include "modplatform/ftb/PackHelpers.h" +#include "modplatform/ftb/FtbPackFetchTask.h" namespace Ui { @@ -29,7 +30,6 @@ class FTBPage; class FtbListModel; class FtbFilterModel; -class FtbPackDownloader; class NewInstanceDialog; class FTBPage : public QWidget, public BasePage @@ -58,28 +58,36 @@ public: bool shouldDisplay() const override; void openedImpl() override; - FtbPackDownloader* getFtbPackDownloader(); FtbModpack getSelectedModpack(); QString getSelectedVersion(); private: void suggestCurrent(); + void onPackSelectionChanged(QModelIndex first, QModelIndex second, FtbFilterModel *model); private slots: - void ftbPackDataDownloadSuccessfully(); - void ftbPackDataDownloadFailed(); + void ftbPackDataDownloadSuccessfully(FtbModpackList publicPacks, FtbModpackList thirdPartyPacks); + void ftbPackDataDownloadFailed(QString reason); + void onSortingSelectionChanged(QString data); void onVersionSelectionItemChanged(QString data); - void onPackSelectionChanged(QModelIndex first, QModelIndex second); + + void onPublicPackSelectionChanged(QModelIndex first, QModelIndex second); + void onThirdPartyPackSelectionChanged(QModelIndex first, QModelIndex second); private: bool initialized = false; - FtbPackDownloader* ftbPackDownloader = nullptr; FtbModpack selectedPack; FtbModpack selected; QString selectedVersion; - FtbListModel* listModel = nullptr; - FtbFilterModel* filterModel = nullptr; + + FtbListModel* publicListModel = nullptr; + FtbFilterModel* publicFilterModel = nullptr; + + FtbListModel *thirdPartyModel = nullptr; + FtbFilterModel *thirdPartyFilterModel = nullptr; + + FtbPackFetchTask *ftbFetchTask; NewInstanceDialog* dialog = nullptr; Ui::FTBPage *ui = nullptr; diff --git a/application/pages/modplatform/FTBPage.ui b/application/pages/modplatform/FTBPage.ui index a64c9606..ee91f1f5 100644 --- a/application/pages/modplatform/FTBPage.ui +++ b/application/pages/modplatform/FTBPage.ui @@ -10,7 +10,7 @@ 602 - + 0 @@ -23,7 +23,7 @@ 0 - + 0 @@ -32,17 +32,15 @@ - - - + + + + + Qt::ScrollBarAsNeeded + + - - - - - - - + Version selected: @@ -52,9 +50,64 @@ - + + + + + + + + + 0 + 0 + + + + QTabWidget::Rounded + + + 0 + + + + Public Packs + + + + + 0 + 0 + 221 + 491 + + + + Qt::ScrollBarAlwaysOn + + + + + + 3rd Party Packs + + + + + 0 + 0 + 221 + 491 + + + + Qt::ScrollBarAlwaysOn + + + + +