2018-02-10 23:40:01 +00:00
|
|
|
/* Copyright 2013-2018 MultiMC Contributors
|
2013-02-01 19:07:36 +00:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2013-10-06 12:43:46 +00:00
|
|
|
*
|
2013-02-01 19:07:36 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2013-11-04 01:53:05 +00:00
|
|
|
#include "MultiMC.h"
|
|
|
|
#include "NewInstanceDialog.h"
|
|
|
|
#include "ui_NewInstanceDialog.h"
|
2013-02-01 19:07:36 +00:00
|
|
|
|
2015-02-09 00:51:14 +00:00
|
|
|
#include <BaseVersion.h>
|
|
|
|
#include <icons/IconList.h>
|
|
|
|
#include <tasks/Task.h>
|
|
|
|
#include <InstanceList.h>
|
2013-04-22 20:39:41 +00:00
|
|
|
|
2013-11-04 01:53:05 +00:00
|
|
|
#include "VersionSelectDialog.h"
|
2013-09-17 22:00:35 +00:00
|
|
|
#include "ProgressDialog.h"
|
2013-08-10 16:34:08 +00:00
|
|
|
#include "IconPickerDialog.h"
|
2013-04-22 20:39:41 +00:00
|
|
|
|
2013-02-01 19:07:36 +00:00
|
|
|
#include <QLayout>
|
2013-04-22 20:39:41 +00:00
|
|
|
#include <QPushButton>
|
2015-02-12 21:01:20 +00:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QValidator>
|
2018-03-19 01:36:12 +00:00
|
|
|
#include <QDialogButtonBox>
|
2015-02-12 21:01:20 +00:00
|
|
|
|
2018-03-19 01:36:12 +00:00
|
|
|
#include "widgets/PageContainer.h"
|
|
|
|
#include <pages/modplatform/VanillaPage.h>
|
|
|
|
#include <pages/modplatform/FTBPage.h>
|
|
|
|
#include <pages/modplatform/TwitchPage.h>
|
|
|
|
#include <pages/modplatform/ImportPage.h>
|
|
|
|
#include <pages/modplatform/TechnicPage.h>
|
2013-02-01 19:07:36 +00:00
|
|
|
|
2017-04-22 04:11:26 +00:00
|
|
|
NewInstanceDialog::NewInstanceDialog(const QString & initialGroup, const QString & url, QWidget *parent)
|
2013-10-06 12:43:46 +00:00
|
|
|
: QDialog(parent), ui(new Ui::NewInstanceDialog)
|
2013-02-01 19:07:36 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2015-02-12 21:01:20 +00:00
|
|
|
|
2018-03-19 01:36:12 +00:00
|
|
|
setWindowIcon(MMC->getThemedIcon("new"));
|
2017-03-19 23:44:49 +00:00
|
|
|
|
2015-05-31 23:19:12 +00:00
|
|
|
InstIconKey = "default";
|
2016-04-10 02:29:29 +00:00
|
|
|
ui->iconButton->setIcon(MMC->icons()->getIcon(InstIconKey));
|
2015-02-12 21:01:20 +00:00
|
|
|
|
2014-11-08 20:17:28 +00:00
|
|
|
auto groups = MMC->instances()->getGroups().toSet();
|
|
|
|
auto groupList = QStringList(groups.toList());
|
|
|
|
groupList.sort(Qt::CaseInsensitive);
|
|
|
|
groupList.removeOne("");
|
2016-04-10 23:30:50 +00:00
|
|
|
groupList.push_front(initialGroup);
|
2014-11-08 20:17:28 +00:00
|
|
|
groupList.push_front("");
|
|
|
|
ui->groupBox->addItems(groupList);
|
2016-04-10 23:30:50 +00:00
|
|
|
int index = groupList.indexOf(initialGroup);
|
2014-11-08 20:17:28 +00:00
|
|
|
if(index == -1)
|
|
|
|
{
|
|
|
|
index = 0;
|
|
|
|
}
|
|
|
|
ui->groupBox->setCurrentIndex(index);
|
|
|
|
ui->groupBox->lineEdit()->setPlaceholderText(tr("No group"));
|
2015-08-21 07:00:35 +00:00
|
|
|
|
2018-03-19 01:36:12 +00:00
|
|
|
m_buttons = new QDialogButtonBox(QDialogButtonBox::Help | QDialogButtonBox::Ok);
|
|
|
|
m_buttons->button(QDialogButtonBox::Ok)->setDefault(true);
|
2018-02-28 18:42:30 +00:00
|
|
|
|
2018-03-19 01:36:12 +00:00
|
|
|
connect(m_buttons->button(QDialogButtonBox::Ok), &QPushButton::clicked, this, &QDialog::accept);
|
|
|
|
connect(m_buttons->button(QDialogButtonBox::Help), &QPushButton::clicked, m_container, &PageContainer::help);
|
2018-02-28 18:42:30 +00:00
|
|
|
|
2018-03-19 01:36:12 +00:00
|
|
|
m_container = new PageContainer(this);
|
|
|
|
m_container->setSizePolicy(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Expanding);
|
|
|
|
ui->verticalLayout->insertWidget(2, m_container);
|
2018-02-28 18:42:30 +00:00
|
|
|
|
2018-03-19 01:36:12 +00:00
|
|
|
m_container->addButtons(m_buttons);
|
|
|
|
m_buttons->setFocus();
|
|
|
|
|
|
|
|
if(!url.isEmpty())
|
|
|
|
{
|
|
|
|
m_container->selectPage("import");
|
|
|
|
importPage->setUrl(url);
|
|
|
|
}
|
2018-02-28 18:42:30 +00:00
|
|
|
|
2015-08-21 07:00:35 +00:00
|
|
|
updateDialogState();
|
2018-03-19 01:36:12 +00:00
|
|
|
|
|
|
|
restoreGeometry(QByteArray::fromBase64(MMC->settings()->get("NewInstanceGeometry").toByteArray()));
|
2013-04-22 20:39:41 +00:00
|
|
|
}
|
|
|
|
|
2018-03-19 01:36:12 +00:00
|
|
|
QList<BasePage *> NewInstanceDialog::getPages()
|
2017-03-19 23:44:49 +00:00
|
|
|
{
|
2018-03-19 01:36:12 +00:00
|
|
|
importPage = new ImportPage(this);
|
|
|
|
return
|
2017-03-19 23:44:49 +00:00
|
|
|
{
|
2018-03-19 01:36:12 +00:00
|
|
|
new VanillaPage(this),
|
|
|
|
new FTBPage(this),
|
|
|
|
importPage,
|
|
|
|
new TwitchPage(this),
|
|
|
|
new TechnicPage(this)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
QString NewInstanceDialog::dialogTitle()
|
|
|
|
{
|
|
|
|
return tr("New Instance");
|
2017-03-19 23:44:49 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 19:41:37 +00:00
|
|
|
NewInstanceDialog::~NewInstanceDialog()
|
2013-04-22 20:39:41 +00:00
|
|
|
{
|
2013-05-03 19:41:37 +00:00
|
|
|
delete ui;
|
2013-04-22 20:39:41 +00:00
|
|
|
}
|
|
|
|
|
2018-03-19 01:36:12 +00:00
|
|
|
void NewInstanceDialog::setSuggestedPack(const QString& name, InstanceTask* task)
|
2013-04-22 20:39:41 +00:00
|
|
|
{
|
2018-03-19 01:36:12 +00:00
|
|
|
creationTask.reset(task);
|
|
|
|
ui->instNameTextBox->setPlaceholderText(name);
|
2018-02-28 18:42:30 +00:00
|
|
|
|
2018-03-19 01:36:12 +00:00
|
|
|
auto allowOK = task && !instName().isEmpty();
|
|
|
|
m_buttons->button(QDialogButtonBox::Ok)->setEnabled(allowOK);
|
2013-04-22 20:39:41 +00:00
|
|
|
}
|
|
|
|
|
2018-03-19 01:36:12 +00:00
|
|
|
InstanceTask * NewInstanceDialog::extractTask()
|
2013-04-22 20:39:41 +00:00
|
|
|
{
|
2018-03-19 01:36:12 +00:00
|
|
|
InstanceTask * extracted = creationTask.get();
|
|
|
|
creationTask.release();
|
|
|
|
extracted->setName(instName());
|
|
|
|
extracted->setGroup(instGroup());
|
|
|
|
extracted->setIcon(iconKey());
|
|
|
|
return extracted;
|
|
|
|
}
|
2013-10-06 12:43:46 +00:00
|
|
|
|
2018-03-19 01:36:12 +00:00
|
|
|
void NewInstanceDialog::updateDialogState()
|
|
|
|
{
|
|
|
|
auto allowOK = creationTask && !instName().isEmpty();
|
|
|
|
m_buttons->button(QDialogButtonBox::Ok)->setEnabled(allowOK);
|
2013-04-22 20:39:41 +00:00
|
|
|
}
|
|
|
|
|
2013-04-22 22:15:18 +00:00
|
|
|
QString NewInstanceDialog::instName() const
|
|
|
|
{
|
2015-08-21 07:00:35 +00:00
|
|
|
auto result = ui->instNameTextBox->text();
|
|
|
|
if(result.size())
|
|
|
|
{
|
2016-05-03 22:29:40 +00:00
|
|
|
return result.trimmed();
|
2015-08-21 07:00:35 +00:00
|
|
|
}
|
|
|
|
result = ui->instNameTextBox->placeholderText();
|
2018-03-19 01:36:12 +00:00
|
|
|
if(result.size())
|
2015-08-21 07:00:35 +00:00
|
|
|
{
|
2016-05-03 22:29:40 +00:00
|
|
|
return result.trimmed();
|
2015-08-21 07:00:35 +00:00
|
|
|
}
|
|
|
|
return QString();
|
2013-04-22 22:15:18 +00:00
|
|
|
}
|
2015-08-21 07:00:35 +00:00
|
|
|
|
2014-11-08 20:17:28 +00:00
|
|
|
QString NewInstanceDialog::instGroup() const
|
|
|
|
{
|
|
|
|
return ui->groupBox->currentText();
|
|
|
|
}
|
2013-04-22 22:15:18 +00:00
|
|
|
QString NewInstanceDialog::iconKey() const
|
|
|
|
{
|
2013-08-10 16:34:08 +00:00
|
|
|
return InstIconKey;
|
2013-04-22 22:15:18 +00:00
|
|
|
}
|
2013-05-07 02:28:28 +00:00
|
|
|
|
2013-08-10 16:34:08 +00:00
|
|
|
void NewInstanceDialog::on_iconButton_clicked()
|
|
|
|
{
|
2013-08-27 16:27:58 +00:00
|
|
|
IconPickerDialog dlg(this);
|
2015-09-26 02:04:09 +00:00
|
|
|
dlg.execWithSelection(InstIconKey);
|
2013-10-06 12:43:46 +00:00
|
|
|
|
|
|
|
if (dlg.result() == QDialog::Accepted)
|
2013-08-10 16:34:08 +00:00
|
|
|
{
|
|
|
|
InstIconKey = dlg.selectedIconKey;
|
2016-04-10 02:29:29 +00:00
|
|
|
ui->iconButton->setIcon(MMC->icons()->getIcon(InstIconKey));
|
2013-08-10 16:34:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-07 02:28:28 +00:00
|
|
|
void NewInstanceDialog::on_instNameTextBox_textChanged(const QString &arg1)
|
|
|
|
{
|
|
|
|
updateDialogState();
|
|
|
|
}
|
2014-11-08 20:17:28 +00:00
|
|
|
|
2018-03-19 01:36:12 +00:00
|
|
|
void NewInstanceDialog::closeEvent(QCloseEvent* event)
|
2015-02-12 21:01:20 +00:00
|
|
|
{
|
2018-03-19 01:36:12 +00:00
|
|
|
qDebug() << "New instance dialog close requested";
|
|
|
|
if (m_container->prepareToClose())
|
2015-02-12 21:01:20 +00:00
|
|
|
{
|
2018-03-19 01:36:12 +00:00
|
|
|
qDebug() << "New instance dialog close approved";
|
|
|
|
MMC->settings()->set("NewInstanceGeometry", saveGeometry().toBase64());
|
|
|
|
qDebug() << "New instance dialog geometry saved";
|
|
|
|
QDialog::closeEvent(event);
|
2018-02-28 18:42:30 +00:00
|
|
|
}
|
|
|
|
}
|