2018-03-19 01:36:12 +00:00
|
|
|
#include "TwitchPage.h"
|
|
|
|
#include "ui_TwitchPage.h"
|
|
|
|
|
|
|
|
#include "MultiMC.h"
|
|
|
|
#include "dialogs/NewInstanceDialog.h"
|
2019-06-30 09:03:59 +00:00
|
|
|
#include <InstanceImportTask.h>
|
2018-03-19 01:36:12 +00:00
|
|
|
|
|
|
|
TwitchPage::TwitchPage(NewInstanceDialog* dialog, QWidget *parent)
|
2018-07-15 12:51:05 +00:00
|
|
|
: QWidget(parent), ui(new Ui::TwitchPage), dialog(dialog)
|
2018-03-19 01:36:12 +00:00
|
|
|
{
|
2018-07-15 12:51:05 +00:00
|
|
|
ui->setupUi(this);
|
2019-06-27 01:20:11 +00:00
|
|
|
connect(ui->checkButton, &QPushButton::clicked, this, &TwitchPage::triggerCheck);
|
2019-10-14 00:31:53 +00:00
|
|
|
connect(ui->twitchLabel, &DropLabel::droppedURLs, [this](QList<QUrl> urls){
|
|
|
|
if(urls.size()) {
|
|
|
|
setUrl(urls[0].toString());
|
|
|
|
}
|
|
|
|
});
|
2018-03-19 01:36:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TwitchPage::~TwitchPage()
|
|
|
|
{
|
2018-07-15 12:51:05 +00:00
|
|
|
delete ui;
|
2018-03-19 01:36:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TwitchPage::shouldDisplay() const
|
|
|
|
{
|
2019-06-27 01:20:11 +00:00
|
|
|
return true;
|
2018-03-19 01:36:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchPage::openedImpl()
|
|
|
|
{
|
2018-07-15 12:51:05 +00:00
|
|
|
dialog->setSuggestedPack();
|
2018-03-19 01:36:12 +00:00
|
|
|
}
|
2019-06-27 01:20:11 +00:00
|
|
|
|
|
|
|
void TwitchPage::triggerCheck(bool)
|
|
|
|
{
|
|
|
|
if(m_modIdResolver) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto task = new Flame::UrlResolvingTask(ui->lineEdit->text());
|
|
|
|
connect(task, &Task::finished, this, &TwitchPage::checkDone);
|
|
|
|
m_modIdResolver.reset(task);
|
|
|
|
task->start();
|
|
|
|
}
|
|
|
|
|
2019-07-09 20:04:52 +00:00
|
|
|
void TwitchPage::setUrl(const QString& url)
|
|
|
|
{
|
|
|
|
ui->lineEdit->setText(url);
|
|
|
|
triggerCheck(true);
|
|
|
|
}
|
|
|
|
|
2019-06-27 01:20:11 +00:00
|
|
|
void TwitchPage::checkDone()
|
|
|
|
{
|
|
|
|
auto result = m_modIdResolver->getResults();
|
|
|
|
auto formatted = QString("Project %1, File %2").arg(result.projectId).arg(result.fileId);
|
2019-06-30 09:03:59 +00:00
|
|
|
if(result.resolved && result.type == Flame::File::Type::Modpack) {
|
|
|
|
ui->twitchLabel->setText(formatted);
|
|
|
|
QFileInfo fi(result.fileName);
|
|
|
|
dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(result.url));
|
|
|
|
} else {
|
|
|
|
ui->twitchLabel->setPixmap(QPixmap(QString::fromUtf8(":/assets/deadglitch")));
|
|
|
|
dialog->setSuggestedPack();
|
|
|
|
}
|
2019-06-27 01:20:11 +00:00
|
|
|
m_modIdResolver.reset();
|
|
|
|
}
|