2018-03-19 07:06:12 +05:30
|
|
|
#include "FTBPage.h"
|
|
|
|
#include "ui_FTBPage.h"
|
|
|
|
|
|
|
|
#include "MultiMC.h"
|
|
|
|
#include "FolderInstanceProvider.h"
|
|
|
|
#include "dialogs/CustomMessageBox.h"
|
|
|
|
#include "dialogs/NewInstanceDialog.h"
|
2018-04-01 23:54:28 +05:30
|
|
|
#include "modplatform/ftb/FtbPackFetchTask.h"
|
2018-03-19 07:06:12 +05:30
|
|
|
#include "modplatform/ftb/FtbPackInstallTask.h"
|
2018-04-07 00:34:34 +05:30
|
|
|
#include "FtbListModel.h"
|
2018-03-19 07:06:12 +05:30
|
|
|
|
|
|
|
FTBPage::FTBPage(NewInstanceDialog* dialog, QWidget *parent)
|
|
|
|
: QWidget(parent), dialog(dialog), ui(new Ui::FTBPage)
|
|
|
|
{
|
2018-04-01 23:54:28 +05:30
|
|
|
ftbFetchTask = new FtbPackFetchTask();
|
|
|
|
|
2018-03-19 07:06:12 +05:30
|
|
|
ui->setupUi(this);
|
2018-03-29 01:27:41 +05:30
|
|
|
ui->tabWidget->tabBar()->hide();
|
2018-03-19 07:06:12 +05:30
|
|
|
|
2018-04-01 23:54:28 +05:30
|
|
|
{
|
|
|
|
publicFilterModel = new FtbFilterModel(this);
|
|
|
|
publicListModel = new FtbListModel(this);
|
|
|
|
publicFilterModel->setSourceModel(publicListModel);
|
2018-03-19 07:06:12 +05:30
|
|
|
|
2018-04-01 23:54:28 +05:30
|
|
|
ui->publicPackList->setModel(publicFilterModel);
|
|
|
|
ui->publicPackList->setSortingEnabled(true);
|
|
|
|
ui->publicPackList->header()->hide();
|
|
|
|
ui->publicPackList->setIndentation(0);
|
2018-04-06 18:38:59 +05:30
|
|
|
ui->publicPackList->setIconSize(QSize(42, 42));
|
2018-03-19 07:06:12 +05:30
|
|
|
|
2018-04-01 23:54:28 +05:30
|
|
|
for(int i = 0; i < publicFilterModel->getAvailableSortings().size(); i++)
|
|
|
|
{
|
|
|
|
ui->sortByBox->addItem(publicFilterModel->getAvailableSortings().keys().at(i));
|
|
|
|
}
|
2018-03-19 07:06:12 +05:30
|
|
|
|
2018-04-01 23:54:28 +05:30
|
|
|
ui->sortByBox->setCurrentText(publicFilterModel->translateCurrentSorting());
|
|
|
|
}
|
2018-03-19 07:06:12 +05:30
|
|
|
|
|
|
|
{
|
2018-04-01 23:54:28 +05:30
|
|
|
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);
|
2018-04-06 18:38:59 +05:30
|
|
|
ui->thirdPartyPackList->setIconSize(QSize(42, 42));
|
|
|
|
|
2018-04-01 23:54:28 +05:30
|
|
|
thirdPartyFilterModel->setSorting(publicFilterModel->getCurrentSorting());
|
2018-03-19 07:06:12 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
connect(ui->sortByBox, &QComboBox::currentTextChanged, this, &FTBPage::onSortingSelectionChanged);
|
|
|
|
connect(ui->packVersionSelection, &QComboBox::currentTextChanged, this, &FTBPage::onVersionSelectionItemChanged);
|
2018-04-01 23:54:28 +05:30
|
|
|
|
|
|
|
connect(ui->publicPackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onPublicPackSelectionChanged);
|
|
|
|
connect(ui->thirdPartyPackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onThirdPartyPackSelectionChanged);
|
2018-03-19 07:06:12 +05:30
|
|
|
|
2018-04-05 23:03:31 +05:30
|
|
|
connect(ui->ftbTabWidget, &QTabWidget::currentChanged, this, &FTBPage::onTabChanged);
|
|
|
|
|
2018-03-19 07:06:12 +05:30
|
|
|
ui->modpackInfo->setOpenExternalLinks(true);
|
2018-04-05 23:03:31 +05:30
|
|
|
|
|
|
|
ui->publicPackList->selectionModel()->reset();
|
|
|
|
ui->thirdPartyPackList->selectionModel()->reset();
|
2018-03-19 07:06:12 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
FTBPage::~FTBPage()
|
|
|
|
{
|
|
|
|
delete ui;
|
2018-04-01 23:54:28 +05:30
|
|
|
if(ftbFetchTask) {
|
|
|
|
ftbFetchTask->deleteLater();
|
2018-03-19 07:06:12 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FTBPage::shouldDisplay() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FTBPage::openedImpl()
|
|
|
|
{
|
|
|
|
if(!initialized)
|
|
|
|
{
|
2018-04-01 23:54:28 +05:30
|
|
|
connect(ftbFetchTask, &FtbPackFetchTask::finished, this, &FTBPage::ftbPackDataDownloadSuccessfully);
|
|
|
|
connect(ftbFetchTask, &FtbPackFetchTask::failed, this, &FTBPage::ftbPackDataDownloadFailed);
|
|
|
|
ftbFetchTask->fetch();
|
2018-03-19 07:06:12 +05:30
|
|
|
initialized = true;
|
|
|
|
}
|
|
|
|
suggestCurrent();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FTBPage::suggestCurrent()
|
|
|
|
{
|
|
|
|
if(isOpened)
|
|
|
|
{
|
|
|
|
if(!selected.broken)
|
|
|
|
{
|
|
|
|
dialog->setSuggestedPack(selected.name, new FtbPackInstallTask(selected, selectedVersion));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dialog->setSuggestedPack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-01 23:54:28 +05:30
|
|
|
void FTBPage::ftbPackDataDownloadSuccessfully(FtbModpackList publicPacks, FtbModpackList thirdPartyPacks)
|
|
|
|
{
|
|
|
|
publicListModel->fill(publicPacks);
|
|
|
|
thirdPartyModel->fill(thirdPartyPacks);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FTBPage::ftbPackDataDownloadFailed(QString reason)
|
2018-03-19 07:06:12 +05:30
|
|
|
{
|
2018-04-01 23:54:28 +05:30
|
|
|
//TODO: Display the error
|
2018-03-19 07:06:12 +05:30
|
|
|
}
|
|
|
|
|
2018-04-07 01:29:04 +05:30
|
|
|
void FTBPage::onPublicPackSelectionChanged(QModelIndex now, QModelIndex prev)
|
2018-03-19 07:06:12 +05:30
|
|
|
{
|
2018-04-07 01:29:04 +05:30
|
|
|
if(!now.isValid())
|
|
|
|
{
|
|
|
|
onPackSelectionChanged();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
FtbModpack selectedPack = publicFilterModel->data(now, Qt::UserRole).value<FtbModpack>();
|
|
|
|
onPackSelectionChanged(&selectedPack);
|
2018-03-19 07:06:12 +05:30
|
|
|
}
|
|
|
|
|
2018-04-07 01:29:04 +05:30
|
|
|
void FTBPage::onThirdPartyPackSelectionChanged(QModelIndex now, QModelIndex prev)
|
2018-03-19 07:06:12 +05:30
|
|
|
{
|
2018-04-07 01:29:04 +05:30
|
|
|
if(!now.isValid())
|
|
|
|
{
|
|
|
|
onPackSelectionChanged();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
FtbModpack selectedPack = thirdPartyFilterModel->data(now, Qt::UserRole).value<FtbModpack>();
|
|
|
|
onPackSelectionChanged(&selectedPack);
|
2018-03-19 07:06:12 +05:30
|
|
|
}
|
|
|
|
|
2018-04-07 01:29:04 +05:30
|
|
|
void FTBPage::onPackSelectionChanged(FtbModpack* pack)
|
2018-03-19 07:06:12 +05:30
|
|
|
{
|
|
|
|
ui->packVersionSelection->clear();
|
2018-04-07 01:29:04 +05:30
|
|
|
if(pack)
|
2018-03-19 07:06:12 +05:30
|
|
|
{
|
2018-04-07 01:29:04 +05:30
|
|
|
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>");
|
|
|
|
bool currentAdded = false;
|
|
|
|
|
|
|
|
for(int i = 0; i < pack->oldVersions.size(); i++)
|
2018-03-19 07:06:12 +05:30
|
|
|
{
|
2018-04-07 01:29:04 +05:30
|
|
|
if(pack->currentVersion == pack->oldVersions.at(i))
|
|
|
|
{
|
|
|
|
currentAdded = true;
|
|
|
|
}
|
|
|
|
ui->packVersionSelection->addItem(pack->oldVersions.at(i));
|
2018-03-19 07:06:12 +05:30
|
|
|
}
|
|
|
|
|
2018-04-07 01:29:04 +05:30
|
|
|
if(!currentAdded)
|
|
|
|
{
|
|
|
|
ui->packVersionSelection->addItem(pack->currentVersion);
|
|
|
|
}
|
|
|
|
selected = *pack;
|
2018-03-19 07:06:12 +05:30
|
|
|
}
|
|
|
|
suggestCurrent();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FTBPage::onVersionSelectionItemChanged(QString data)
|
|
|
|
{
|
|
|
|
if(data.isNull() || data.isEmpty())
|
|
|
|
{
|
|
|
|
selectedVersion = "";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
selectedVersion = data;
|
2018-04-07 01:55:24 +05:30
|
|
|
suggestCurrent();
|
2018-03-19 07:06:12 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void FTBPage::onSortingSelectionChanged(QString data)
|
|
|
|
{
|
2018-04-01 23:54:28 +05:30
|
|
|
FtbFilterModel::Sorting toSet = publicFilterModel->getAvailableSortings().value(data);
|
|
|
|
publicFilterModel->setSorting(toSet);
|
|
|
|
thirdPartyFilterModel->setSorting(toSet);
|
2018-03-19 07:06:12 +05:30
|
|
|
}
|
2018-04-05 23:03:31 +05:30
|
|
|
|
|
|
|
void FTBPage::onTabChanged(int tab)
|
|
|
|
{
|
2018-04-07 01:29:04 +05:30
|
|
|
FtbFilterModel* currentModel = nullptr;
|
|
|
|
QTreeView* currentList = nullptr;
|
|
|
|
if (tab == 0)
|
|
|
|
{
|
|
|
|
currentModel = publicFilterModel;
|
|
|
|
currentList = ui->publicPackList;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
currentModel = thirdPartyFilterModel;
|
|
|
|
currentList = ui->thirdPartyPackList;
|
|
|
|
}
|
|
|
|
QModelIndex idx = currentList->currentIndex();
|
|
|
|
if(idx.isValid())
|
|
|
|
{
|
|
|
|
auto pack = currentModel->data(idx, Qt::UserRole).value<FtbModpack>();
|
|
|
|
onPackSelectionChanged(&pack);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
onPackSelectionChanged();
|
|
|
|
}
|
2018-04-05 23:03:31 +05:30
|
|
|
}
|