From a53f8d506e212f862f54e5a758fb50666ec7c3ba Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Thu, 12 Feb 2015 22:01:20 +0100 Subject: GH-366: Plain and simple modpack export/import/download Also removed the in-source QuaZIP in favour of upstream version --- gui/dialogs/NewInstanceDialog.cpp | 75 ++++++++++++++++++-- gui/dialogs/NewInstanceDialog.h | 2 + gui/dialogs/NewInstanceDialog.ui | 141 +++++++++++++++++++++++++++++++------- 3 files changed, 189 insertions(+), 29 deletions(-) (limited to 'gui/dialogs') diff --git a/gui/dialogs/NewInstanceDialog.cpp b/gui/dialogs/NewInstanceDialog.cpp index e086cf6e..51060ad2 100644 --- a/gui/dialogs/NewInstanceDialog.cpp +++ b/gui/dialogs/NewInstanceDialog.cpp @@ -22,7 +22,7 @@ #include "logic/icons/IconList.h" #include "logic/minecraft/MinecraftVersionList.h" #include "logic/tasks/Task.h" -#include +#include "logic/InstanceList.h" #include "gui/Platform.h" #include "VersionSelectDialog.h" @@ -31,6 +31,31 @@ #include #include +#include +#include + +class UrlValidator : public QValidator +{ +public: + using QValidator::QValidator; + + State validate(QString &in, int &pos) const + { + const QUrl url(in); + if (url.isValid() && !url.isRelative() && !url.isEmpty()) + { + return Acceptable; + } + else if (QFile::exists(in)) + { + return Acceptable; + } + else + { + return Intermediate; + } + } +}; NewInstanceDialog::NewInstanceDialog(QWidget *parent) : QDialog(parent), ui(new Ui::NewInstanceDialog) @@ -39,9 +64,16 @@ NewInstanceDialog::NewInstanceDialog(QWidget *parent) ui->setupUi(this); resize(minimumSizeHint()); layout()->setSizeConstraint(QLayout::SetFixedSize); + setSelectedVersion(MMC->minecraftlist()->getLatestStable(), true); InstIconKey = "infinity"; ui->iconButton->setIcon(MMC->icons()->getIcon(InstIconKey)); + + ui->modpackEdit->setValidator(new UrlValidator(ui->modpackEdit)); + connect(ui->modpackEdit, &QLineEdit::textChanged, this, &NewInstanceDialog::updateDialogState); + connect(ui->modpackBox, &QRadioButton::clicked, this, &NewInstanceDialog::updateDialogState); + connect(ui->versionBox, &QRadioButton::clicked, this, &NewInstanceDialog::updateDialogState); + auto groups = MMC->instances()->getGroups().toSet(); auto groupList = QStringList(groups.toList()); groupList.sort(Qt::CaseInsensitive); @@ -67,7 +99,10 @@ NewInstanceDialog::~NewInstanceDialog() void NewInstanceDialog::updateDialogState() { ui->buttonBox->button(QDialogButtonBox::Ok) - ->setEnabled(!instName().isEmpty() && m_selectedVersion); + ->setEnabled(!instName().isEmpty() + && m_selectedVersion + && (!ui->modpackBox->isChecked() + || ui->modpackEdit->hasAcceptableInput())); } void NewInstanceDialog::setSelectedVersion(BaseVersionPtr version, bool initial) @@ -94,16 +129,33 @@ QString NewInstanceDialog::instName() const { return ui->instNameTextBox->text(); } - QString NewInstanceDialog::instGroup() const { return ui->groupBox->currentText(); } - QString NewInstanceDialog::iconKey() const { return InstIconKey; } +QUrl NewInstanceDialog::modpackUrl() const +{ + if (ui->modpackBox->isChecked()) + { + const QUrl url(ui->modpackEdit->text()); + if (url.isValid() && !url.isRelative() && !url.host().isEmpty()) + { + return url; + } + else + { + return QUrl::fromLocalFile(ui->modpackEdit->text()); + } + } + else + { + return QUrl(); + } +} BaseVersionPtr NewInstanceDialog::selectedVersion() const { @@ -140,3 +192,18 @@ void NewInstanceDialog::on_instNameTextBox_textChanged(const QString &arg1) updateDialogState(); } +void NewInstanceDialog::on_modpackBtn_clicked() +{ + const QUrl url = QFileDialog::getOpenFileUrl(this, tr("Choose modpack"), modpackUrl(), tr("Zip (*.zip)")); + if (url.isValid()) + { + if (url.isLocalFile()) + { + ui->modpackEdit->setText(url.toLocalFile()); + } + else + { + ui->modpackEdit->setText(url.toString()); + } + } +} diff --git a/gui/dialogs/NewInstanceDialog.h b/gui/dialogs/NewInstanceDialog.h index 39f83c89..1e1b0bea 100644 --- a/gui/dialogs/NewInstanceDialog.h +++ b/gui/dialogs/NewInstanceDialog.h @@ -41,12 +41,14 @@ public: QString instName() const; QString instGroup() const; QString iconKey() const; + QUrl modpackUrl() const; BaseVersionPtr selectedVersion() const; private slots: void on_btnChangeVersion_clicked(); void on_iconButton_clicked(); + void on_modpackBtn_clicked(); void on_instNameTextBox_textChanged(const QString &arg1); private: diff --git a/gui/dialogs/NewInstanceDialog.ui b/gui/dialogs/NewInstanceDialog.ui index be4642aa..adb7fa54 100644 --- a/gui/dialogs/NewInstanceDialog.ui +++ b/gui/dialogs/NewInstanceDialog.ui @@ -10,7 +10,7 @@ 0 0 345 - 261 + 343 @@ -84,41 +84,24 @@ - + ... - - - - true - - - - - - Version: - - - versionTextBox - - - - - Group: + &Group: groupBox - + @@ -131,6 +114,50 @@ + + + + false + + + http:// + + + + + + + false + + + ... + + + + + + + &Version: + + + true + + + + + + + Import &Modpack: + + + + + + + true + + + @@ -176,8 +203,8 @@ accept() - 248 - 254 + 257 + 333 157 @@ -192,8 +219,8 @@ reject() - 316 - 260 + 325 + 333 286 @@ -201,5 +228,69 @@ + + modpackBox + toggled(bool) + modpackEdit + setEnabled(bool) + + + 81 + 229 + + + 236 + 221 + + + + + modpackBox + toggled(bool) + modpackBtn + setEnabled(bool) + + + 129 + 225 + + + 328 + 229 + + + + + versionBox + toggled(bool) + versionTextBox + setEnabled(bool) + + + 93 + 195 + + + 213 + 191 + + + + + versionBox + toggled(bool) + btnChangeVersion + setEnabled(bool) + + + 104 + 198 + + + 322 + 192 + + + -- cgit v1.2.3