summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/logic/CMakeLists.txt4
-rw-r--r--api/logic/RWStorage.h2
-rw-r--r--api/logic/modplatform/ftb/FtbPackDownloader.cpp57
-rw-r--r--api/logic/modplatform/ftb/FtbPackDownloader.h39
-rw-r--r--api/logic/modplatform/ftb/FtbPackFetchTask.cpp63
-rw-r--r--api/logic/modplatform/ftb/FtbPackFetchTask.h10
-rw-r--r--api/logic/modplatform/ftb/FtbPackInstallTask.h2
-rw-r--r--api/logic/modplatform/ftb/PackHelpers.h15
-rw-r--r--application/FtbListModel.cpp91
-rw-r--r--application/FtbListModel.h23
-rw-r--r--application/MainWindow.h1
-rw-r--r--application/pages/modplatform/FTBPage.cpp81
-rw-r--r--application/pages/modplatform/FTBPage.h24
-rw-r--r--application/pages/modplatform/FTBPage.ui79
14 files changed, 303 insertions, 188 deletions
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 <QWriteLocker>
+#include <QReadLocker>
template <typename K, typename V>
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<FtbModpackList>(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 <QString>
-#include <QUrl>
-#include <QList>
-#include <QObject>
-#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<QString, FtbModpack> 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 <QDomDocument>
-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 <Version.h>
#include <QtMath>
+#include <QLabel>
+
+#include <RWStorage.h>
+#include <Env.h>
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<QString, FtbFilterModel::Sorting> 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 <QAbstractListModel>
#include <QSortFilterProxyModel>
#include <modplatform/ftb/PackHelpers.h>
+#include <QThreadPool>
+
+#include <RWStorage.h>
+
+#include <QPixmap>
+
+typedef QMap<QString, QPixmap> FtbLogoMap;
class FtbFilterModel : public QSortFilterProxyModel
{
@@ -13,8 +20,9 @@ public:
ByGameVersion
};
const QMap<QString, Sorting> 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 <modplatform/ftb/FtbPackDownloader.h>
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 <FtbListModel.h>
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);
+ {
+ publicFilterModel = new FtbFilterModel(this);
+ publicListModel = new FtbListModel(this);
+ publicFilterModel->setSourceModel(publicListModel);
- filterModel = new FtbFilterModel(this);
- listModel = new FtbListModel(this);
- filterModel->setSourceModel(listModel);
+ ui->publicPackList->setModel(publicFilterModel);
+ ui->publicPackList->setSortingEnabled(true);
+ ui->publicPackList->header()->hide();
+ ui->publicPackList->setIndentation(0);
- ui->packList->setModel(filterModel);
- ui->packList->setSortingEnabled(true);
- ui->packList->header()->hide();
- ui->packList->setIndentation(0);
+ for(int i = 0; i < publicFilterModel->getAvailableSortings().size(); i++)
+ {
+ ui->sortByBox->addItem(publicFilterModel->getAvailableSortings().keys().at(i));
+ }
- filterModel->setSorting(FtbFilterModel::Sorting::ByName);
+ ui->sortByBox->setCurrentText(publicFilterModel->translateCurrentSorting());
+ }
- for(int i = 0; i < filterModel->getAvailableSortings().size(); i++)
{
- ui->sortByBox->addItem(filterModel->getAvailableSortings().keys().at(i));
+ 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());
}
- ui->sortByBox->setCurrentText(filterModel->getAvailableSortings().key(filterModel->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)
+{
+ publicListModel->fill(publicPacks);
+ thirdPartyModel->fill(thirdPartyPacks);
+}
+
+void FTBPage::ftbPackDataDownloadFailed(QString reason)
{
- return ftbPackDownloader;
+ //TODO: Display the error
}
-void FTBPage::ftbPackDataDownloadSuccessfully()
+void FTBPage::onPublicPackSelectionChanged(QModelIndex first, QModelIndex second)
{
- listModel->fill(ftbPackDownloader->getModpacks());
+ onPackSelectionChanged(first, second, publicFilterModel);
}
-void FTBPage::ftbPackDataDownloadFailed()
+void FTBPage::onThirdPartyPackSelectionChanged(QModelIndex first, QModelIndex second)
{
- qDebug() << "Stuff went missing while grabbing FTB pack list or something...";
+ onPackSelectionChanged(first, second, thirdPartyFilterModel);
}
-void FTBPage::onPackSelectionChanged(QModelIndex now, QModelIndex prev)
+void FTBPage::onPackSelectionChanged(QModelIndex now, QModelIndex prev, FtbFilterModel *model)
{
ui->packVersionSelection->clear();
- FtbModpack selectedPack = filterModel->data(now, Qt::UserRole).value<FtbModpack>();
+ FtbModpack selectedPack = model->data(now, Qt::UserRole).value<FtbModpack>();
ui->modpackInfo->setHtml("Pack by <b>" + selectedPack.author + "</b>" + "<br>Minecraft " + selectedPack.mcVersion + "<br>"
"<br>" + selectedPack.description + "<ul><li>" + selectedPack.mods.replace(";", "</li><li>") + "</li></ul>");
@@ -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 <MultiMC.h>
#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 @@
<height>602</height>
</rect>
</property>
- <layout class="QVBoxLayout" name="verticalLayout">
+ <layout class="QGridLayout" name="gridLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
@@ -23,7 +23,7 @@
<property name="bottomMargin">
<number>0</number>
</property>
- <item>
+ <item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
@@ -32,17 +32,15 @@
<attribute name="title">
<string notr="true"/>
</attribute>
- <layout class="QGridLayout" name="gridLayout" columnstretch="0,0,4,4">
- <item row="0" column="0" colspan="2">
- <widget class="QTreeView" name="packList"/>
- </item>
- <item row="0" column="2" colspan="2">
- <widget class="QTextBrowser" name="modpackInfo"/>
- </item>
- <item row="1" column="3">
- <widget class="QComboBox" name="packVersionSelection"/>
+ <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>
+ </property>
+ </widget>
</item>
- <item row="1" column="2">
+ <item row="2" column="2">
<widget class="QLabel" name="selectedVersionLabel">
<property name="text">
<string>Version selected:</string>
@@ -52,9 +50,64 @@
</property>
</widget>
</item>
- <item row="1" column="0" colspan="2">
+ <item row="2" column="3">
+ <widget class="QComboBox" name="packVersionSelection"/>
+ </item>
+ <item row="2" column="0">
<widget class="QComboBox" name="sortByBox"/>
</item>
+ <item row="0" column="0" rowspan="2">
+ <widget class="QTabWidget" name="tabWidget_2">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </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>
+ <widget class="QTreeView" name="publicPackList">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>221</width>
+ <height>491</height>
+ </rect>
+ </property>
+ <property name="verticalScrollBarPolicy">
+ <enum>Qt::ScrollBarAlwaysOn</enum>
+ </property>
+ </widget>
+ </widget>
+ <widget class="QWidget" name="tab_3">
+ <attribute name="title">
+ <string>3rd Party Packs</string>
+ </attribute>
+ <widget class="QTreeView" name="thirdPartyPackList">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>221</width>
+ <height>491</height>
+ </rect>
+ </property>
+ <property name="verticalScrollBarPolicy">
+ <enum>Qt::ScrollBarAlwaysOn</enum>
+ </property>
+ </widget>
+ </widget>
+ </widget>
+ </item>
</layout>
</widget>
</widget>