2018-03-19 07:06:12 +05:30
|
|
|
#include "FTBPage.h"
|
|
|
|
#include "ui_FTBPage.h"
|
|
|
|
|
2018-08-02 04:22:31 +05:30
|
|
|
#include <QInputDialog>
|
|
|
|
|
2018-03-19 07:06:12 +05:30
|
|
|
#include "MultiMC.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-08-02 04:22:31 +05:30
|
|
|
#include "modplatform/ftb/FtbPrivatePackManager.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)
|
2018-07-15 18:21:05 +05:30
|
|
|
: QWidget(parent), dialog(dialog), ui(new Ui::FTBPage)
|
2018-03-19 07:06:12 +05:30
|
|
|
{
|
2018-08-02 04:22:31 +05:30
|
|
|
ftbFetchTask.reset(new FtbPackFetchTask());
|
|
|
|
ftbPrivatePacks.reset(new FtbPrivatePackManager());
|
2018-04-01 23:54:28 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
ui->setupUi(this);
|
2018-03-19 07:06:12 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
{
|
|
|
|
publicFilterModel = new FtbFilterModel(this);
|
|
|
|
publicListModel = new FtbListModel(this);
|
|
|
|
publicFilterModel->setSourceModel(publicListModel);
|
2018-03-19 07:06:12 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
ui->publicPackList->setModel(publicFilterModel);
|
|
|
|
ui->publicPackList->setSortingEnabled(true);
|
|
|
|
ui->publicPackList->header()->hide();
|
|
|
|
ui->publicPackList->setIndentation(0);
|
|
|
|
ui->publicPackList->setIconSize(QSize(42, 42));
|
2018-03-19 07:06:12 +05:30
|
|
|
|
2018-07-15 18:21:05 +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-07-15 18:21:05 +05:30
|
|
|
ui->sortByBox->setCurrentText(publicFilterModel->translateCurrentSorting());
|
|
|
|
}
|
2018-03-19 07:06:12 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
{
|
|
|
|
thirdPartyFilterModel = new FtbFilterModel(this);
|
|
|
|
thirdPartyModel = new FtbListModel(this);
|
|
|
|
thirdPartyFilterModel->setSourceModel(thirdPartyModel);
|
2018-04-01 23:54:28 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
ui->thirdPartyPackList->setModel(thirdPartyFilterModel);
|
|
|
|
ui->thirdPartyPackList->setSortingEnabled(true);
|
|
|
|
ui->thirdPartyPackList->header()->hide();
|
|
|
|
ui->thirdPartyPackList->setIndentation(0);
|
|
|
|
ui->thirdPartyPackList->setIconSize(QSize(42, 42));
|
2018-04-06 18:38:59 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
thirdPartyFilterModel->setSorting(publicFilterModel->getCurrentSorting());
|
|
|
|
}
|
2018-03-19 07:06:12 +05:30
|
|
|
|
2018-08-02 04:22:31 +05:30
|
|
|
{
|
|
|
|
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);
|
2018-04-07 19:45:58 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
connect(ui->sortByBox, &QComboBox::currentTextChanged, this, &FTBPage::onSortingSelectionChanged);
|
2018-08-02 04:22:31 +05:30
|
|
|
connect(ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &FTBPage::onVersionSelectionItemChanged);
|
2018-04-01 23:54:28 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
connect(ui->publicPackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onPublicPackSelectionChanged);
|
|
|
|
connect(ui->thirdPartyPackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onThirdPartyPackSelectionChanged);
|
2018-08-02 04:22:31 +05:30
|
|
|
connect(ui->privatePackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onPrivatePackSelectionChanged);
|
|
|
|
|
|
|
|
connect(ui->addPackBtn, &QPushButton::pressed, this, &FTBPage::onAddPackClicked);
|
|
|
|
connect(ui->removePackBtn, &QPushButton::pressed, this, &FTBPage::onRemovePackClicked);
|
2018-03-19 07:06:12 +05:30
|
|
|
|
2018-08-02 04:22:31 +05:30
|
|
|
connect(ui->tabWidget, &QTabWidget::currentChanged, this, &FTBPage::onTabChanged);
|
2018-04-05 23:03:31 +05:30
|
|
|
|
2018-08-02 04:22:31 +05:30
|
|
|
// ui->modpackInfo->setOpenExternalLinks(true);
|
2018-04-05 23:03:31 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
ui->publicPackList->selectionModel()->reset();
|
|
|
|
ui->thirdPartyPackList->selectionModel()->reset();
|
2018-08-02 04:22:31 +05:30
|
|
|
ui->privatePackList->selectionModel()->reset();
|
|
|
|
|
|
|
|
onTabChanged(ui->tabWidget->currentIndex());
|
2018-03-19 07:06:12 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
FTBPage::~FTBPage()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
delete ui;
|
2018-03-19 07:06:12 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
bool FTBPage::shouldDisplay() const
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
return true;
|
2018-03-19 07:06:12 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void FTBPage::openedImpl()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
if(!initialized)
|
|
|
|
{
|
2018-08-02 04:22:31 +05:30
|
|
|
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);
|
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
ftbFetchTask->fetch();
|
2018-08-02 04:22:31 +05:30
|
|
|
ftbPrivatePacks->load();
|
|
|
|
ftbFetchTask->fetchPrivate(ftbPrivatePacks->getCurrentPackCodes().toList());
|
2018-07-15 18:21:05 +05:30
|
|
|
initialized = true;
|
|
|
|
}
|
|
|
|
suggestCurrent();
|
2018-03-19 07:06:12 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void FTBPage::suggestCurrent()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
if(isOpened)
|
|
|
|
{
|
|
|
|
if(!selected.broken)
|
|
|
|
{
|
|
|
|
dialog->setSuggestedPack(selected.name, new FtbPackInstallTask(selected, selectedVersion));
|
2018-08-02 04:22:31 +05:30
|
|
|
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);
|
2018-07-15 18:21:05 +05:30
|
|
|
});
|
2018-08-02 04:22:31 +05:30
|
|
|
}
|
|
|
|
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);
|
2018-07-15 18:21:05 +05:30
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dialog->setSuggestedPack();
|
|
|
|
}
|
|
|
|
}
|
2018-03-19 07:06:12 +05:30
|
|
|
}
|
|
|
|
|
2018-04-01 23:54:28 +05:30
|
|
|
void FTBPage::ftbPackDataDownloadSuccessfully(FtbModpackList publicPacks, FtbModpackList thirdPartyPacks)
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
publicListModel->fill(publicPacks);
|
|
|
|
thirdPartyModel->fill(thirdPartyPacks);
|
2018-04-01 23:54:28 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void FTBPage::ftbPackDataDownloadFailed(QString reason)
|
2018-03-19 07:06:12 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
//TODO: Display the error
|
2018-03-19 07:06:12 +05:30
|
|
|
}
|
|
|
|
|
2018-08-02 04:22:31 +05:30
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-07 01:29:04 +05:30
|
|
|
void FTBPage::onPublicPackSelectionChanged(QModelIndex now, QModelIndex prev)
|
2018-03-19 07:06:12 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +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-07-15 18:21:05 +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-08-02 04:22:31 +05:30
|
|
|
void FTBPage::onPrivatePackSelectionChanged(QModelIndex now, QModelIndex prev)
|
|
|
|
{
|
|
|
|
if(!now.isValid())
|
|
|
|
{
|
|
|
|
onPackSelectionChanged();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
FtbModpack selectedPack = privateFilterModel->data(now, Qt::UserRole).value<FtbModpack>();
|
|
|
|
onPackSelectionChanged(&selectedPack);
|
|
|
|
}
|
|
|
|
|
2018-04-07 01:29:04 +05:30
|
|
|
void FTBPage::onPackSelectionChanged(FtbModpack* pack)
|
2018-03-19 07:06:12 +05:30
|
|
|
{
|
2018-08-02 04:22:31 +05:30
|
|
|
ui->versionSelectionBox->clear();
|
2018-07-15 18:21:05 +05:30
|
|
|
if(pack)
|
|
|
|
{
|
2018-08-02 04:22:31 +05:30
|
|
|
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>");
|
2018-07-15 18:21:05 +05:30
|
|
|
bool currentAdded = false;
|
|
|
|
|
|
|
|
for(int i = 0; i < pack->oldVersions.size(); i++)
|
|
|
|
{
|
|
|
|
if(pack->currentVersion == pack->oldVersions.at(i))
|
|
|
|
{
|
|
|
|
currentAdded = true;
|
|
|
|
}
|
2018-08-02 04:22:31 +05:30
|
|
|
ui->versionSelectionBox->addItem(pack->oldVersions.at(i));
|
2018-07-15 18:21:05 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
if(!currentAdded)
|
|
|
|
{
|
2018-08-02 04:22:31 +05:30
|
|
|
ui->versionSelectionBox->addItem(pack->currentVersion);
|
2018-07-15 18:21:05 +05:30
|
|
|
}
|
|
|
|
selected = *pack;
|
|
|
|
}
|
2018-08-02 04:22:31 +05:30
|
|
|
else
|
|
|
|
{
|
|
|
|
currentModpackInfo->setHtml("");
|
|
|
|
ui->versionSelectionBox->clear();
|
|
|
|
if(isOpened)
|
|
|
|
{
|
|
|
|
dialog->setSuggestedPack();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2018-07-15 18:21:05 +05:30
|
|
|
suggestCurrent();
|
2018-03-19 07:06:12 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void FTBPage::onVersionSelectionItemChanged(QString data)
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
if(data.isNull() || data.isEmpty())
|
|
|
|
{
|
|
|
|
selectedVersion = "";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
selectedVersion = data;
|
|
|
|
suggestCurrent();
|
2018-03-19 07:06:12 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void FTBPage::onSortingSelectionChanged(QString data)
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
FtbFilterModel::Sorting toSet = publicFilterModel->getAvailableSortings().value(data);
|
|
|
|
publicFilterModel->setSorting(toSet);
|
|
|
|
thirdPartyFilterModel->setSorting(toSet);
|
2018-08-02 04:22:31 +05:30
|
|
|
privateFilterModel->setSorting(toSet);
|
2018-03-19 07:06:12 +05:30
|
|
|
}
|
2018-04-05 23:03:31 +05:30
|
|
|
|
|
|
|
void FTBPage::onTabChanged(int tab)
|
|
|
|
{
|
2018-08-02 04:22:31 +05:30
|
|
|
if(tab == 1)
|
2018-07-15 18:21:05 +05:30
|
|
|
{
|
2018-08-02 04:22:31 +05:30
|
|
|
currentModel = thirdPartyFilterModel;
|
|
|
|
currentList = ui->thirdPartyPackList;
|
|
|
|
currentModpackInfo = ui->thirdPartyPackDescription;
|
|
|
|
}
|
|
|
|
else if(tab == 2)
|
|
|
|
{
|
|
|
|
currentModel = privateFilterModel;
|
|
|
|
currentList = ui->privatePackList;
|
|
|
|
currentModpackInfo = ui->privatePackDescription;
|
2018-07-15 18:21:05 +05:30
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-02 04:22:31 +05:30
|
|
|
currentModel = publicFilterModel;
|
|
|
|
currentList = ui->publicPackList;
|
|
|
|
currentModpackInfo = ui->publicPackDescription;
|
2018-07-15 18:21:05 +05:30
|
|
|
}
|
2018-08-02 04:22:31 +05:30
|
|
|
|
|
|
|
currentList->selectionModel()->reset();
|
2018-07-15 18:21:05 +05:30
|
|
|
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
|
|
|
}
|
2018-08-02 04:22:31 +05:30
|
|
|
|
|
|
|
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();
|
|
|
|
}
|