2018-03-19 07:06:12 +05:30
|
|
|
#include "TwitchPage.h"
|
|
|
|
#include "ui_TwitchPage.h"
|
|
|
|
|
|
|
|
#include "MultiMC.h"
|
|
|
|
#include "dialogs/NewInstanceDialog.h"
|
2019-06-30 14:33:59 +05:30
|
|
|
#include <InstanceImportTask.h>
|
2018-03-19 07:06:12 +05:30
|
|
|
|
|
|
|
TwitchPage::TwitchPage(NewInstanceDialog* dialog, QWidget *parent)
|
2018-07-15 18:21:05 +05:30
|
|
|
: QWidget(parent), ui(new Ui::TwitchPage), dialog(dialog)
|
2018-03-19 07:06:12 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
ui->setupUi(this);
|
2019-06-27 06:50:11 +05:30
|
|
|
connect(ui->checkButton, &QPushButton::clicked, this, &TwitchPage::triggerCheck);
|
2018-03-19 07:06:12 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
TwitchPage::~TwitchPage()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
delete ui;
|
2018-03-19 07:06:12 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
bool TwitchPage::shouldDisplay() const
|
|
|
|
{
|
2019-06-27 06:50:11 +05:30
|
|
|
return true;
|
2018-03-19 07:06:12 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchPage::openedImpl()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
dialog->setSuggestedPack();
|
2018-03-19 07:06:12 +05:30
|
|
|
}
|
2019-06-27 06:50:11 +05:30
|
|
|
|
|
|
|
void TwitchPage::triggerCheck(bool)
|
|
|
|
{
|
|
|
|
if(m_modIdResolver) {
|
|
|
|
qDebug() << "Click!";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto task = new Flame::UrlResolvingTask(ui->lineEdit->text());
|
|
|
|
connect(task, &Task::finished, this, &TwitchPage::checkDone);
|
|
|
|
m_modIdResolver.reset(task);
|
|
|
|
task->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchPage::checkDone()
|
|
|
|
{
|
|
|
|
auto result = m_modIdResolver->getResults();
|
|
|
|
auto formatted = QString("Project %1, File %2").arg(result.projectId).arg(result.fileId);
|
2019-06-30 14:33:59 +05:30
|
|
|
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 06:50:11 +05:30
|
|
|
m_modIdResolver.reset();
|
|
|
|
}
|