2021-03-23 23:59:43 +00:00
|
|
|
#include "FlamePage.h"
|
|
|
|
#include "ui_FlamePage.h"
|
2020-03-31 01:13:19 +00:00
|
|
|
|
|
|
|
#include "MultiMC.h"
|
|
|
|
#include "dialogs/NewInstanceDialog.h"
|
|
|
|
#include <InstanceImportTask.h>
|
2021-03-23 23:59:43 +00:00
|
|
|
#include "FlameModel.h"
|
2020-03-31 01:13:19 +00:00
|
|
|
#include <QKeyEvent>
|
|
|
|
|
2021-03-23 23:59:43 +00:00
|
|
|
FlamePage::FlamePage(NewInstanceDialog* dialog, QWidget *parent)
|
|
|
|
: QWidget(parent), ui(new Ui::FlamePage), dialog(dialog)
|
2020-03-31 01:13:19 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2021-03-23 23:59:43 +00:00
|
|
|
connect(ui->searchButton, &QPushButton::clicked, this, &FlamePage::triggerSearch);
|
2020-03-31 01:13:19 +00:00
|
|
|
ui->searchEdit->installEventFilter(this);
|
2021-03-23 23:59:43 +00:00
|
|
|
model = new Flame::ListModel(this);
|
2020-03-31 01:13:19 +00:00
|
|
|
ui->packView->setModel(model);
|
2021-03-23 23:59:43 +00:00
|
|
|
connect(ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &FlamePage::onSelectionChanged);
|
2020-03-31 01:13:19 +00:00
|
|
|
}
|
|
|
|
|
2021-03-23 23:59:43 +00:00
|
|
|
FlamePage::~FlamePage()
|
2020-03-31 01:13:19 +00:00
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2021-03-23 23:59:43 +00:00
|
|
|
bool FlamePage::eventFilter(QObject* watched, QEvent* event)
|
2020-03-31 01:13:19 +00:00
|
|
|
{
|
|
|
|
if (watched == ui->searchEdit && event->type() == QEvent::KeyPress) {
|
|
|
|
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
|
|
|
|
if (keyEvent->key() == Qt::Key_Return) {
|
|
|
|
triggerSearch();
|
|
|
|
keyEvent->accept();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QWidget::eventFilter(watched, event);
|
|
|
|
}
|
|
|
|
|
2021-03-23 23:59:43 +00:00
|
|
|
bool FlamePage::shouldDisplay() const
|
2020-03-31 01:13:19 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-03-23 23:59:43 +00:00
|
|
|
void FlamePage::openedImpl()
|
2020-03-31 01:13:19 +00:00
|
|
|
{
|
|
|
|
suggestCurrent();
|
|
|
|
}
|
|
|
|
|
2021-03-23 23:59:43 +00:00
|
|
|
void FlamePage::triggerSearch()
|
2020-03-31 01:13:19 +00:00
|
|
|
{
|
|
|
|
model->searchWithTerm(ui->searchEdit->text());
|
|
|
|
}
|
|
|
|
|
2021-03-23 23:59:43 +00:00
|
|
|
void FlamePage::onSelectionChanged(QModelIndex first, QModelIndex second)
|
2020-03-31 01:13:19 +00:00
|
|
|
{
|
|
|
|
if(!first.isValid())
|
|
|
|
{
|
|
|
|
if(isOpened)
|
|
|
|
{
|
|
|
|
dialog->setSuggestedPack();
|
|
|
|
}
|
2020-04-29 19:17:51 +00:00
|
|
|
ui->frame->clear();
|
2020-03-31 01:13:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-04-29 19:17:51 +00:00
|
|
|
|
2021-03-23 23:59:43 +00:00
|
|
|
current = model->data(first, Qt::UserRole).value<Flame::Modpack>();
|
2020-04-29 19:17:51 +00:00
|
|
|
QString text = "";
|
|
|
|
QString name = current.name;
|
|
|
|
|
|
|
|
if (current.websiteUrl.isEmpty())
|
|
|
|
text = name;
|
|
|
|
else
|
|
|
|
text = "<a href=\"" + current.websiteUrl + "\">" + name + "</a>";
|
|
|
|
if (!current.authors.empty()) {
|
2021-03-23 23:59:43 +00:00
|
|
|
auto authorToStr = [](Flame::ModpackAuthor & author) {
|
2020-04-29 19:17:51 +00:00
|
|
|
if(author.url.isEmpty()) {
|
|
|
|
return author.name;
|
|
|
|
}
|
|
|
|
return QString("<a href=\"%1\">%2</a>").arg(author.url, author.name);
|
|
|
|
};
|
|
|
|
QStringList authorStrs;
|
|
|
|
for(auto & author: current.authors) {
|
|
|
|
authorStrs.push_back(authorToStr(author));
|
|
|
|
}
|
|
|
|
text += tr(" by ") + authorStrs.join(", ");
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->frame->setModText(text);
|
|
|
|
ui->frame->setModDescription(current.description);
|
2020-03-31 01:13:19 +00:00
|
|
|
suggestCurrent();
|
|
|
|
}
|
|
|
|
|
2021-03-23 23:59:43 +00:00
|
|
|
void FlamePage::suggestCurrent()
|
2020-03-31 01:13:19 +00:00
|
|
|
{
|
|
|
|
if(!isOpened)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(current.broken)
|
|
|
|
{
|
|
|
|
dialog->setSuggestedPack();
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog->setSuggestedPack(current.name, new InstanceImportTask(current.latestFile.downloadUrl));
|
|
|
|
QString editedLogoName;
|
2021-03-23 23:59:43 +00:00
|
|
|
editedLogoName = "curseforge_" + current.logoName.section(".", 0, 0);
|
2020-03-31 01:13:19 +00:00
|
|
|
model->getLogo(current.logoName, current.logoUrl, [this, editedLogoName](QString logo)
|
|
|
|
{
|
|
|
|
dialog->setSuggestedIconFromFile(logo, editedLogoName);
|
|
|
|
});
|
|
|
|
}
|