From f74e3db804f2fb3d73cbf7ab5fbdb12ecea0f259 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sat, 29 Jun 2019 01:13:39 +0200 Subject: NOISSUE Import page is now a MultiMC pack page --- application/pages/modplatform/ImportPage.cpp | 128 -------------------------- application/pages/modplatform/ImportPage.h | 70 -------------- application/pages/modplatform/ImportPage.ui | 52 ----------- application/pages/modplatform/MultiMCPage.cpp | 123 +++++++++++++++++++++++++ application/pages/modplatform/MultiMCPage.h | 70 ++++++++++++++ application/pages/modplatform/MultiMCPage.ui | 52 +++++++++++ 6 files changed, 245 insertions(+), 250 deletions(-) delete mode 100644 application/pages/modplatform/ImportPage.cpp delete mode 100644 application/pages/modplatform/ImportPage.h delete mode 100644 application/pages/modplatform/ImportPage.ui create mode 100644 application/pages/modplatform/MultiMCPage.cpp create mode 100644 application/pages/modplatform/MultiMCPage.h create mode 100644 application/pages/modplatform/MultiMCPage.ui (limited to 'application/pages/modplatform') diff --git a/application/pages/modplatform/ImportPage.cpp b/application/pages/modplatform/ImportPage.cpp deleted file mode 100644 index 3910dfda..00000000 --- a/application/pages/modplatform/ImportPage.cpp +++ /dev/null @@ -1,128 +0,0 @@ -#include "ImportPage.h" -#include "ui_ImportPage.h" - -#include "MultiMC.h" -#include "dialogs/NewInstanceDialog.h" -#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; - } - } -}; - -ImportPage::ImportPage(NewInstanceDialog* dialog, QWidget *parent) - : QWidget(parent), ui(new Ui::ImportPage), dialog(dialog) -{ - ui->setupUi(this); - ui->modpackEdit->setValidator(new UrlValidator(ui->modpackEdit)); - connect(ui->modpackEdit, &QLineEdit::textChanged, this, &ImportPage::updateState); -} - -ImportPage::~ImportPage() -{ - delete ui; -} - -bool ImportPage::shouldDisplay() const -{ - return true; -} - -void ImportPage::openedImpl() -{ - updateState(); -} - -void ImportPage::updateState() -{ - if(!isOpened) - { - return; - } - if(ui->modpackEdit->hasAcceptableInput()) - { - QString input = ui->modpackEdit->text(); - auto url = QUrl::fromUserInput(input); - if(url.isLocalFile()) - { - // FIXME: actually do some validation of what's inside here... this is fake AF - QFileInfo fi(input); - if(fi.exists() && fi.suffix() == "zip") - { - QFileInfo fi(url.fileName()); - dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url)); - } - } - else - { - if(input.endsWith("?client=y")) { - input.chop(9); - input.append("/file"); - url = QUrl::fromUserInput(input); - } - // hook, line and sinker. - QFileInfo fi(url.fileName()); - dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url)); - } - } - else - { - dialog->setSuggestedPack(); - } -} - -void ImportPage::setUrl(const QString& url) -{ - ui->modpackEdit->setText(url); - updateState(); -} - -void ImportPage::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()); - } - } -} - - -QUrl ImportPage::modpackUrl() const -{ - const QUrl url(ui->modpackEdit->text()); - if (url.isValid() && !url.isRelative() && !url.host().isEmpty()) - { - return url; - } - else - { - return QUrl::fromLocalFile(ui->modpackEdit->text()); - } -} diff --git a/application/pages/modplatform/ImportPage.h b/application/pages/modplatform/ImportPage.h deleted file mode 100644 index 3afb0045..00000000 --- a/application/pages/modplatform/ImportPage.h +++ /dev/null @@ -1,70 +0,0 @@ -/* Copyright 2013-2019 MultiMC Contributors - * - * 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 - * - * 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. - */ - -#pragma once - -#include - -#include "pages/BasePage.h" -#include -#include "tasks/Task.h" - -namespace Ui -{ -class ImportPage; -} - -class NewInstanceDialog; - -class ImportPage : public QWidget, public BasePage -{ - Q_OBJECT - -public: - explicit ImportPage(NewInstanceDialog* dialog, QWidget *parent = 0); - virtual ~ImportPage(); - virtual QString displayName() const override - { - return tr("Import from zip"); - } - virtual QIcon icon() const override - { - return MMC->getThemedIcon("viewfolder"); - } - virtual QString id() const override - { - return "import"; - } - virtual QString helpPage() const override - { - return "Zip-import"; - } - virtual bool shouldDisplay() const override; - - void setUrl(const QString & url); - void openedImpl() override; - -private slots: - void on_modpackBtn_clicked(); - void updateState(); - -private: - QUrl modpackUrl() const; - -private: - Ui::ImportPage *ui = nullptr; - NewInstanceDialog* dialog = nullptr; -}; - diff --git a/application/pages/modplatform/ImportPage.ui b/application/pages/modplatform/ImportPage.ui deleted file mode 100644 index eb63cbe9..00000000 --- a/application/pages/modplatform/ImportPage.ui +++ /dev/null @@ -1,52 +0,0 @@ - - - ImportPage - - - - 0 - 0 - 546 - 405 - - - - - - - Browse - - - - - - - http:// - - - - - - - Local file or link to a direct download: - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - diff --git a/application/pages/modplatform/MultiMCPage.cpp b/application/pages/modplatform/MultiMCPage.cpp new file mode 100644 index 00000000..c98596c2 --- /dev/null +++ b/application/pages/modplatform/MultiMCPage.cpp @@ -0,0 +1,123 @@ +#include "MultiMCPage.h" +#include "ui_MultiMCPage.h" + +#include "MultiMC.h" +#include "dialogs/NewInstanceDialog.h" +#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; + } + } +}; + +MultiMCPage::MultiMCPage(NewInstanceDialog* dialog, QWidget *parent) + : QWidget(parent), ui(new Ui::MultiMCPage), dialog(dialog) +{ + ui->setupUi(this); + ui->modpackEdit->setValidator(new UrlValidator(ui->modpackEdit)); + connect(ui->modpackEdit, &QLineEdit::textChanged, this, &MultiMCPage::updateState); +} + +MultiMCPage::~MultiMCPage() +{ + delete ui; +} + +bool MultiMCPage::shouldDisplay() const +{ + return true; +} + +void MultiMCPage::openedImpl() +{ + updateState(); +} + +void MultiMCPage::updateState() +{ + if(!isOpened) + { + return; + } + if(ui->modpackEdit->hasAcceptableInput()) + { + QString input = ui->modpackEdit->text(); + auto url = QUrl::fromUserInput(input); + if(url.isLocalFile()) + { + // FIXME: actually do some validation of what's inside here... this is fake AF + QFileInfo fi(input); + if(fi.exists() && fi.suffix() == "zip") + { + QFileInfo fi(url.fileName()); + dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url)); + } + } + else + { + // hook, line and sinker. + QFileInfo fi(url.fileName()); + dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url)); + } + } + else + { + dialog->setSuggestedPack(); + } +} + +void MultiMCPage::setUrl(const QString& url) +{ + ui->modpackEdit->setText(url); + updateState(); +} + +void MultiMCPage::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()); + } + } +} + + +QUrl MultiMCPage::modpackUrl() const +{ + const QUrl url(ui->modpackEdit->text()); + if (url.isValid() && !url.isRelative() && !url.host().isEmpty()) + { + return url; + } + else + { + return QUrl::fromLocalFile(ui->modpackEdit->text()); + } +} diff --git a/application/pages/modplatform/MultiMCPage.h b/application/pages/modplatform/MultiMCPage.h new file mode 100644 index 00000000..1d9b7744 --- /dev/null +++ b/application/pages/modplatform/MultiMCPage.h @@ -0,0 +1,70 @@ +/* Copyright 2013-2019 MultiMC Contributors + * + * 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 + * + * 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. + */ + +#pragma once + +#include + +#include "pages/BasePage.h" +#include +#include "tasks/Task.h" + +namespace Ui +{ +class MultiMCPage; +} + +class NewInstanceDialog; + +class MultiMCPage : public QWidget, public BasePage +{ + Q_OBJECT + +public: + explicit MultiMCPage(NewInstanceDialog* dialog, QWidget *parent = 0); + virtual ~MultiMCPage(); + virtual QString displayName() const override + { + return tr("MultiMC"); + } + virtual QIcon icon() const override + { + return MMC->getThemedIcon("multimc"); + } + virtual QString id() const override + { + return "multimc"; + } + virtual QString helpPage() const override + { + return "MultiMC-packs"; + } + virtual bool shouldDisplay() const override; + + void setUrl(const QString & url); + void openedImpl() override; + +private slots: + void on_modpackBtn_clicked(); + void updateState(); + +private: + QUrl modpackUrl() const; + +private: + Ui::MultiMCPage *ui = nullptr; + NewInstanceDialog* dialog = nullptr; +}; + diff --git a/application/pages/modplatform/MultiMCPage.ui b/application/pages/modplatform/MultiMCPage.ui new file mode 100644 index 00000000..dc329c4c --- /dev/null +++ b/application/pages/modplatform/MultiMCPage.ui @@ -0,0 +1,52 @@ + + + MultiMCPage + + + + 0 + 0 + 546 + 405 + + + + + + + Browse + + + + + + + http:// + + + + + + + Local file or link to a direct download: + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + -- cgit