@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <modplatform/legacy_ftb/PackHelpers.h>
|
||||
#include <RWStorage.h>
|
||||
#include <modplatform/legacy_ftb/PackHelpers.h>
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QThreadPool>
|
||||
#include <QIcon>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QThreadPool>
|
||||
|
||||
#include <functional>
|
||||
|
||||
@ -16,34 +16,28 @@ namespace LegacyFTB {
|
||||
typedef QMap<QString, QIcon> FTBLogoMap;
|
||||
typedef std::function<void(QString)> LogoCallback;
|
||||
|
||||
class FilterModel : public QSortFilterProxyModel
|
||||
{
|
||||
class FilterModel : public QSortFilterProxyModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
public:
|
||||
FilterModel(QObject* parent = Q_NULLPTR);
|
||||
enum Sorting {
|
||||
ByName,
|
||||
ByGameVersion
|
||||
};
|
||||
enum Sorting { ByName, ByGameVersion };
|
||||
const QMap<QString, Sorting> getAvailableSortings();
|
||||
QString translateCurrentSorting();
|
||||
void setSorting(Sorting sorting);
|
||||
Sorting getCurrentSorting();
|
||||
|
||||
protected:
|
||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
|
||||
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
|
||||
protected:
|
||||
bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override;
|
||||
bool lessThan(const QModelIndex& left, const QModelIndex& right) const override;
|
||||
|
||||
private:
|
||||
private:
|
||||
QMap<QString, Sorting> sortings;
|
||||
Sorting currentSorting;
|
||||
|
||||
};
|
||||
|
||||
class ListModel : public QAbstractListModel
|
||||
{
|
||||
class ListModel : public QAbstractListModel {
|
||||
Q_OBJECT
|
||||
private:
|
||||
private:
|
||||
ModpackList modpacks;
|
||||
QStringList m_failedLogos;
|
||||
QStringList m_loadingLogos;
|
||||
@ -53,18 +47,17 @@ private:
|
||||
void requestLogo(QString file);
|
||||
QString translatePackType(PackType type) const;
|
||||
|
||||
|
||||
private slots:
|
||||
private slots:
|
||||
void logoFailed(QString logo);
|
||||
void logoLoaded(QString logo, QIcon out);
|
||||
|
||||
public:
|
||||
ListModel(QObject *parent);
|
||||
public:
|
||||
ListModel(QObject* parent);
|
||||
~ListModel();
|
||||
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;
|
||||
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(ModpackList modpacks);
|
||||
void addPack(Modpack modpack);
|
||||
@ -72,7 +65,7 @@ public:
|
||||
void remove(int row);
|
||||
|
||||
Modpack at(int row);
|
||||
void getLogo(const QString &logo, LogoCallback callback);
|
||||
void getLogo(const QString& logo, LogoCallback callback);
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LegacyFTB
|
||||
|
@ -44,15 +44,14 @@
|
||||
#include "ui/dialogs/CustomMessageBox.h"
|
||||
#include "ui/dialogs/NewInstanceDialog.h"
|
||||
|
||||
#include "ListModel.h"
|
||||
#include "modplatform/legacy_ftb/PackFetchTask.h"
|
||||
#include "modplatform/legacy_ftb/PackInstallTask.h"
|
||||
#include "modplatform/legacy_ftb/PrivatePackManager.h"
|
||||
#include "ListModel.h"
|
||||
|
||||
namespace LegacyFTB {
|
||||
|
||||
Page::Page(NewInstanceDialog* dialog, QWidget *parent)
|
||||
: QWidget(parent), dialog(dialog), ui(new Ui::Page)
|
||||
Page::Page(NewInstanceDialog* dialog, QWidget* parent) : QWidget(parent), dialog(dialog), ui(new Ui::Page)
|
||||
{
|
||||
ftbFetchTask.reset(new PackFetchTask(APPLICATION->network()));
|
||||
ftbPrivatePacks.reset(new PrivatePackManager());
|
||||
@ -70,8 +69,7 @@ Page::Page(NewInstanceDialog* dialog, QWidget *parent)
|
||||
ui->publicPackList->setIndentation(0);
|
||||
ui->publicPackList->setIconSize(QSize(42, 42));
|
||||
|
||||
for(int i = 0; i < publicFilterModel->getAvailableSortings().size(); i++)
|
||||
{
|
||||
for (int i = 0; i < publicFilterModel->getAvailableSortings().size(); i++) {
|
||||
ui->sortByBox->addItem(publicFilterModel->getAvailableSortings().keys().at(i));
|
||||
}
|
||||
|
||||
@ -142,8 +140,7 @@ bool Page::shouldDisplay() const
|
||||
|
||||
void Page::openedImpl()
|
||||
{
|
||||
if(!initialized)
|
||||
{
|
||||
if (!initialized) {
|
||||
connect(ftbFetchTask.get(), &PackFetchTask::finished, this, &Page::ftbPackDataDownloadSuccessfully);
|
||||
connect(ftbFetchTask.get(), &PackFetchTask::failed, this, &Page::ftbPackDataDownloadFailed);
|
||||
connect(ftbFetchTask.get(), &PackFetchTask::aborted, this, &Page::ftbPackDataDownloadAborted);
|
||||
@ -166,50 +163,34 @@ void Page::retranslate()
|
||||
|
||||
void Page::suggestCurrent()
|
||||
{
|
||||
if(!isOpened)
|
||||
{
|
||||
if (!isOpened) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(selected.broken || selectedVersion.isEmpty())
|
||||
{
|
||||
if (selected.broken || selectedVersion.isEmpty()) {
|
||||
dialog->setSuggestedPack();
|
||||
return;
|
||||
}
|
||||
|
||||
dialog->setSuggestedPack(selected.name, selectedVersion, new PackInstallTask(APPLICATION->network(), selected, selectedVersion));
|
||||
QString editedLogoName;
|
||||
if(selected.logo.toLower().startsWith("ftb"))
|
||||
{
|
||||
if (selected.logo.toLower().startsWith("ftb")) {
|
||||
editedLogoName = selected.logo;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
editedLogoName = "ftb_" + selected.logo;
|
||||
}
|
||||
|
||||
editedLogoName = editedLogoName.left(editedLogoName.lastIndexOf(".png"));
|
||||
|
||||
if(selected.type == PackType::Public)
|
||||
{
|
||||
publicListModel->getLogo(selected.logo, [this, editedLogoName](QString logo)
|
||||
{
|
||||
dialog->setSuggestedIconFromFile(logo, editedLogoName);
|
||||
});
|
||||
}
|
||||
else if (selected.type == PackType::ThirdParty)
|
||||
{
|
||||
thirdPartyModel->getLogo(selected.logo, [this, editedLogoName](QString logo)
|
||||
{
|
||||
dialog->setSuggestedIconFromFile(logo, editedLogoName);
|
||||
});
|
||||
}
|
||||
else if (selected.type == PackType::Private)
|
||||
{
|
||||
privateListModel->getLogo(selected.logo, [this, editedLogoName](QString logo)
|
||||
{
|
||||
dialog->setSuggestedIconFromFile(logo, editedLogoName);
|
||||
});
|
||||
if (selected.type == PackType::Public) {
|
||||
publicListModel->getLogo(selected.logo,
|
||||
[this, editedLogoName](QString logo) { dialog->setSuggestedIconFromFile(logo, editedLogoName); });
|
||||
} else if (selected.type == PackType::ThirdParty) {
|
||||
thirdPartyModel->getLogo(selected.logo,
|
||||
[this, editedLogoName](QString logo) { dialog->setSuggestedIconFromFile(logo, editedLogoName); });
|
||||
} else if (selected.type == PackType::Private) {
|
||||
privateListModel->getLogo(selected.logo,
|
||||
[this, editedLogoName](QString logo) { dialog->setSuggestedIconFromFile(logo, editedLogoName); });
|
||||
}
|
||||
}
|
||||
|
||||
@ -236,21 +217,16 @@ void Page::ftbPrivatePackDataDownloadSuccessfully(Modpack pack)
|
||||
|
||||
void Page::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)
|
||||
{
|
||||
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 Page::onPublicPackSelectionChanged(QModelIndex now, QModelIndex prev)
|
||||
{
|
||||
if(!now.isValid())
|
||||
{
|
||||
if (!now.isValid()) {
|
||||
onPackSelectionChanged();
|
||||
return;
|
||||
}
|
||||
@ -260,8 +236,7 @@ void Page::onPublicPackSelectionChanged(QModelIndex now, QModelIndex prev)
|
||||
|
||||
void Page::onThirdPartyPackSelectionChanged(QModelIndex now, QModelIndex prev)
|
||||
{
|
||||
if(!now.isValid())
|
||||
{
|
||||
if (!now.isValid()) {
|
||||
onPackSelectionChanged();
|
||||
return;
|
||||
}
|
||||
@ -271,8 +246,7 @@ void Page::onThirdPartyPackSelectionChanged(QModelIndex now, QModelIndex prev)
|
||||
|
||||
void Page::onPrivatePackSelectionChanged(QModelIndex now, QModelIndex prev)
|
||||
{
|
||||
if(!now.isValid())
|
||||
{
|
||||
if (!now.isValid()) {
|
||||
onPackSelectionChanged();
|
||||
return;
|
||||
}
|
||||
@ -283,34 +257,26 @@ void Page::onPrivatePackSelectionChanged(QModelIndex now, QModelIndex prev)
|
||||
void Page::onPackSelectionChanged(Modpack* pack)
|
||||
{
|
||||
ui->versionSelectionBox->clear();
|
||||
if(pack)
|
||||
{
|
||||
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>");
|
||||
if (pack) {
|
||||
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++)
|
||||
{
|
||||
if(pack->currentVersion == pack->oldVersions.at(i))
|
||||
{
|
||||
for (int i = 0; i < pack->oldVersions.size(); i++) {
|
||||
if (pack->currentVersion == pack->oldVersions.at(i)) {
|
||||
currentAdded = true;
|
||||
}
|
||||
ui->versionSelectionBox->addItem(pack->oldVersions.at(i));
|
||||
}
|
||||
|
||||
if(!currentAdded)
|
||||
{
|
||||
if (!currentAdded) {
|
||||
ui->versionSelectionBox->addItem(pack->currentVersion);
|
||||
}
|
||||
selected = *pack;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
currentModpackInfo->setHtml("");
|
||||
ui->versionSelectionBox->clear();
|
||||
if(isOpened)
|
||||
{
|
||||
if (isOpened) {
|
||||
dialog->setSuggestedPack();
|
||||
}
|
||||
return;
|
||||
@ -320,8 +286,7 @@ void Page::onPackSelectionChanged(Modpack* pack)
|
||||
|
||||
void Page::onVersionSelectionItemChanged(QString data)
|
||||
{
|
||||
if(data.isNull() || data.isEmpty())
|
||||
{
|
||||
if (data.isNull() || data.isEmpty()) {
|
||||
selectedVersion = "";
|
||||
return;
|
||||
}
|
||||
@ -340,20 +305,15 @@ void Page::onSortingSelectionChanged(QString data)
|
||||
|
||||
void Page::onTabChanged(int tab)
|
||||
{
|
||||
if(tab == 1)
|
||||
{
|
||||
if (tab == 1) {
|
||||
currentModel = thirdPartyFilterModel;
|
||||
currentList = ui->thirdPartyPackList;
|
||||
currentModpackInfo = ui->thirdPartyPackDescription;
|
||||
}
|
||||
else if(tab == 2)
|
||||
{
|
||||
} else if (tab == 2) {
|
||||
currentModel = privateFilterModel;
|
||||
currentList = ui->privatePackList;
|
||||
currentModpackInfo = ui->privatePackDescription;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
currentModel = publicFilterModel;
|
||||
currentList = ui->publicPackList;
|
||||
currentModpackInfo = ui->publicPackDescription;
|
||||
@ -361,13 +321,10 @@ void Page::onTabChanged(int tab)
|
||||
|
||||
currentList->selectionModel()->reset();
|
||||
QModelIndex idx = currentList->currentIndex();
|
||||
if(idx.isValid())
|
||||
{
|
||||
if (idx.isValid()) {
|
||||
auto pack = currentModel->data(idx, Qt::UserRole).value<Modpack>();
|
||||
onPackSelectionChanged(&pack);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
onPackSelectionChanged();
|
||||
}
|
||||
}
|
||||
@ -375,38 +332,24 @@ void Page::onTabChanged(int tab)
|
||||
void Page::onAddPackClicked()
|
||||
{
|
||||
bool ok;
|
||||
QString text = QInputDialog::getText(
|
||||
this,
|
||||
tr("Add FTB pack"),
|
||||
tr("Enter pack code:"),
|
||||
QLineEdit::Normal,
|
||||
QString(),
|
||||
&ok
|
||||
);
|
||||
if(ok && !text.isEmpty())
|
||||
{
|
||||
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});
|
||||
ftbFetchTask->fetchPrivate({ text });
|
||||
}
|
||||
}
|
||||
|
||||
void Page::onRemovePackClicked()
|
||||
{
|
||||
auto index = ui->privatePackList->currentIndex();
|
||||
if(!index.isValid())
|
||||
{
|
||||
if (!index.isValid()) {
|
||||
return;
|
||||
}
|
||||
auto row = index.row();
|
||||
Modpack 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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@ -415,4 +358,4 @@ void Page::onRemovePackClicked()
|
||||
onPackSelectionChanged();
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LegacyFTB
|
||||
|
@ -35,23 +35,22 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <QTreeView>
|
||||
#include <QTextBrowser>
|
||||
#include <QTreeView>
|
||||
#include <QWidget>
|
||||
|
||||
#include "ui/pages/BasePage.h"
|
||||
#include <Application.h>
|
||||
#include "tasks/Task.h"
|
||||
#include "modplatform/legacy_ftb/PackHelpers.h"
|
||||
#include "modplatform/legacy_ftb/PackFetchTask.h"
|
||||
#include "QObjectPtr.h"
|
||||
#include "modplatform/legacy_ftb/PackFetchTask.h"
|
||||
#include "modplatform/legacy_ftb/PackHelpers.h"
|
||||
#include "tasks/Task.h"
|
||||
#include "ui/pages/BasePage.h"
|
||||
|
||||
class NewInstanceDialog;
|
||||
|
||||
namespace LegacyFTB {
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
namespace Ui {
|
||||
class Page;
|
||||
}
|
||||
|
||||
@ -61,38 +60,25 @@ class PrivatePackListModel;
|
||||
class PrivatePackFilterModel;
|
||||
class PrivatePackManager;
|
||||
|
||||
class Page : public QWidget, public BasePage
|
||||
{
|
||||
class Page : public QWidget, public BasePage {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Page(NewInstanceDialog * dialog, QWidget *parent = 0);
|
||||
public:
|
||||
explicit Page(NewInstanceDialog* dialog, QWidget* parent = 0);
|
||||
virtual ~Page();
|
||||
QString displayName() const override
|
||||
{
|
||||
return "FTB Legacy";
|
||||
}
|
||||
QIcon icon() const override
|
||||
{
|
||||
return APPLICATION->getThemedIcon("ftb_logo");
|
||||
}
|
||||
QString id() const override
|
||||
{
|
||||
return "legacy_ftb";
|
||||
}
|
||||
QString helpPage() const override
|
||||
{
|
||||
return "FTB-platform";
|
||||
}
|
||||
QString displayName() const override { return "FTB Legacy"; }
|
||||
QIcon icon() const override { return APPLICATION->getThemedIcon("ftb_logo"); }
|
||||
QString id() const override { return "legacy_ftb"; }
|
||||
QString helpPage() const override { return "FTB-platform"; }
|
||||
bool shouldDisplay() const override;
|
||||
void openedImpl() override;
|
||||
void retranslate() override;
|
||||
|
||||
private:
|
||||
private:
|
||||
void suggestCurrent();
|
||||
void onPackSelectionChanged(Modpack *pack = nullptr);
|
||||
void onPackSelectionChanged(Modpack* pack = nullptr);
|
||||
|
||||
private slots:
|
||||
private slots:
|
||||
void ftbPackDataDownloadSuccessfully(ModpackList publicPacks, ModpackList thirdPartyPacks);
|
||||
void ftbPackDataDownloadFailed(QString reason);
|
||||
void ftbPackDataDownloadAborted();
|
||||
@ -112,7 +98,7 @@ private slots:
|
||||
void onAddPackClicked();
|
||||
void onRemovePackClicked();
|
||||
|
||||
private:
|
||||
private:
|
||||
FilterModel* currentModel = nullptr;
|
||||
QTreeView* currentList = nullptr;
|
||||
QTextBrowser* currentModpackInfo = nullptr;
|
||||
@ -124,18 +110,18 @@ private:
|
||||
ListModel* publicListModel = nullptr;
|
||||
FilterModel* publicFilterModel = nullptr;
|
||||
|
||||
ListModel *thirdPartyModel = nullptr;
|
||||
FilterModel *thirdPartyFilterModel = nullptr;
|
||||
ListModel* thirdPartyModel = nullptr;
|
||||
FilterModel* thirdPartyFilterModel = nullptr;
|
||||
|
||||
ListModel *privateListModel = nullptr;
|
||||
FilterModel *privateFilterModel = nullptr;
|
||||
ListModel* privateListModel = nullptr;
|
||||
FilterModel* privateFilterModel = nullptr;
|
||||
|
||||
unique_qobject_ptr<PackFetchTask> ftbFetchTask;
|
||||
std::unique_ptr<PrivatePackManager> ftbPrivatePacks;
|
||||
|
||||
NewInstanceDialog* dialog = nullptr;
|
||||
|
||||
Ui::Page *ui = nullptr;
|
||||
Ui::Page* ui = nullptr;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LegacyFTB
|
||||
|
Reference in New Issue
Block a user