MultiMC5/application/pages/instance/LegacyUpgradePage.cpp

51 lines
1.4 KiB
C++
Raw Normal View History

#include "LegacyUpgradePage.h"
#include "ui_LegacyUpgradePage.h"
2018-07-23 23:24:06 +00:00
#include "InstanceList.h"
#include "minecraft/legacy/LegacyInstance.h"
#include "minecraft/legacy/LegacyUpgradeTask.h"
#include "MultiMC.h"
#include "dialogs/CustomMessageBox.h"
#include "dialogs/ProgressDialog.h"
LegacyUpgradePage::LegacyUpgradePage(InstancePtr inst, QWidget *parent)
2018-07-15 12:51:05 +00:00
: QWidget(parent), ui(new Ui::LegacyUpgradePage), m_inst(inst)
{
2018-07-15 12:51:05 +00:00
ui->setupUi(this);
}
LegacyUpgradePage::~LegacyUpgradePage()
{
2018-07-15 12:51:05 +00:00
delete ui;
}
void LegacyUpgradePage::runModalTask(Task *task)
{
2018-07-15 12:51:05 +00:00
connect(task, &Task::failed, [this](QString reason)
{
CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Warning)->show();
});
ProgressDialog loadDialog(this);
loadDialog.setSkipButton(true, tr("Abort"));
if(loadDialog.execWithTask(task) == QDialog::Accepted)
{
m_container->requestClose();
}
}
void LegacyUpgradePage::on_upgradeButton_clicked()
{
2018-07-15 12:51:05 +00:00
QString newName = tr("%1 (Migrated)").arg(m_inst->name());
auto upgradeTask = new LegacyUpgradeTask(m_inst);
upgradeTask->setName(newName);
upgradeTask->setGroup(MMC->instances()->getInstanceGroup(m_inst->id()));
2018-07-15 12:51:05 +00:00
upgradeTask->setIcon(m_inst->iconKey());
2018-07-23 23:24:06 +00:00
std::unique_ptr<Task> task(MMC->instances()->wrapInstanceTask(upgradeTask));
2018-07-15 12:51:05 +00:00
runModalTask(task.get());
}
bool LegacyUpgradePage::shouldDisplay() const
{
2018-07-15 12:51:05 +00:00
return !m_inst->isRunning();
}