aboutsummaryrefslogtreecommitdiff
path: root/launcher/ui
diff options
context:
space:
mode:
authorkb1000 <kaeptmblaubaer1000@gmail.com>2022-01-31 15:25:36 +0100
committerSefa Eyeoglu <contact@scrumplex.net>2022-05-14 20:01:09 +0200
commitdb038463581400005f045a277a249ab07175ab2b (patch)
tree8c9a0dc54bd28d2a92c5d33c81964e872d3caa4d /launcher/ui
parentc6b3eccbdf2785b59ab33ed99fabf6f3f5d81d2a (diff)
downloadPrismLauncher-db038463581400005f045a277a249ab07175ab2b.tar.gz
PrismLauncher-db038463581400005f045a277a249ab07175ab2b.tar.bz2
PrismLauncher-db038463581400005f045a277a249ab07175ab2b.zip
Add support for importing Modrinth packs from files
Diffstat (limited to 'launcher/ui')
-rw-r--r--launcher/ui/dialogs/NewInstanceDialog.cpp2
-rw-r--r--launcher/ui/pages/modplatform/ImportPage.cpp4
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp55
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthPage.h62
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthPage.ui94
5 files changed, 216 insertions, 1 deletions
diff --git a/launcher/ui/dialogs/NewInstanceDialog.cpp b/launcher/ui/dialogs/NewInstanceDialog.cpp
index b402839c..05ea091d 100644
--- a/launcher/ui/dialogs/NewInstanceDialog.cpp
+++ b/launcher/ui/dialogs/NewInstanceDialog.cpp
@@ -39,6 +39,7 @@
#include "ui/pages/modplatform/legacy_ftb/Page.h"
#include "ui/pages/modplatform/flame/FlamePage.h"
#include "ui/pages/modplatform/ImportPage.h"
+#include "ui/pages/modplatform/modrinth/ModrinthPage.h"
#include "ui/pages/modplatform/technic/TechnicPage.h"
@@ -134,6 +135,7 @@ QList<BasePage *> NewInstanceDialog::getPages()
flamePage,
new FtbPage(this),
new LegacyFTB::Page(this),
+ new ModrinthPage(this),
technicPage
};
}
diff --git a/launcher/ui/pages/modplatform/ImportPage.cpp b/launcher/ui/pages/modplatform/ImportPage.cpp
index 1b53dd40..8ae38f8d 100644
--- a/launcher/ui/pages/modplatform/ImportPage.cpp
+++ b/launcher/ui/pages/modplatform/ImportPage.cpp
@@ -109,7 +109,8 @@ void ImportPage::updateState()
{
// FIXME: actually do some validation of what's inside here... this is fake AF
QFileInfo fi(input);
- if(fi.exists() && fi.suffix() == "zip")
+ // mrpack is a modrinth pack
+ if(fi.exists() && (fi.suffix() == "zip" || fi.suffix() == "mrpack"))
{
QFileInfo fi(url.fileName());
dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url));
@@ -143,6 +144,7 @@ void ImportPage::setUrl(const QString& url)
void ImportPage::on_modpackBtn_clicked()
{
+ // TODO: Add .mrpack filter
auto filter = QMimeDatabase().mimeTypeForName("application/zip").filterString();
const QUrl url = QFileDialog::getOpenFileUrl(this, tr("Choose modpack"), modpackUrl(), filter);
if (url.isValid())
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp
new file mode 100644
index 00000000..93b1ca02
--- /dev/null
+++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2013-2021 MultiMC Contributors
+ * Copyright 2021-2022 kb1000
+ *
+ * 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.
+ */
+
+#include "ModrinthPage.h"
+
+#include "ui_ModrinthPage.h"
+
+#include <QKeyEvent>
+
+ModrinthPage::ModrinthPage(NewInstanceDialog *dialog, QWidget *parent) : QWidget(parent), ui(new Ui::ModrinthPage), dialog(dialog)
+{
+ ui->setupUi(this);
+}
+
+ModrinthPage::~ModrinthPage()
+{
+ delete ui;
+}
+
+void ModrinthPage::openedImpl()
+{
+ BasePage::openedImpl();
+ triggerSearch();
+}
+
+bool ModrinthPage::eventFilter(QObject *watched, QEvent *event)
+{
+ if (watched == ui->searchEdit && event->type() == QEvent::KeyPress) {
+ auto *keyEvent = reinterpret_cast<QKeyEvent *>(event);
+ if (keyEvent->key() == Qt::Key_Return) {
+ this->triggerSearch();
+ keyEvent->accept();
+ return true;
+ }
+ }
+ return QObject::eventFilter(watched, event);
+}
+
+void ModrinthPage::triggerSearch() {
+
+}
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h
new file mode 100644
index 00000000..6c75b60d
--- /dev/null
+++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2013-2021 MultiMC Contributors
+ * Copyright 2021-2022 kb1000
+ *
+ * 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 "Application.h"
+#include "ui/dialogs/NewInstanceDialog.h"
+#include "ui/pages/BasePage.h"
+
+#include <QWidget>
+
+namespace Ui
+{
+ class ModrinthPage;
+}
+
+class ModrinthPage : public QWidget, public BasePage
+{
+ Q_OBJECT
+
+public:
+ explicit ModrinthPage(NewInstanceDialog *dialog, QWidget *parent = nullptr);
+ ~ModrinthPage() override;
+
+ QString displayName() const override
+ {
+ return tr("Modrinth");
+ }
+ QIcon icon() const override
+ {
+ return APPLICATION->getThemedIcon("modrinth");
+ }
+ QString id() const override
+ {
+ return "modrinth";
+ }
+
+ void openedImpl() override;
+
+ bool eventFilter(QObject *watched, QEvent *event) override;
+
+private slots:
+ void triggerSearch();
+
+private:
+ Ui::ModrinthPage *ui;
+ NewInstanceDialog *dialog;
+};
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.ui b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.ui
new file mode 100644
index 00000000..7ef099d3
--- /dev/null
+++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.ui
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ModrinthPage</class>
+ <widget class="QWidget" name="ModrinthPage">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>837</width>
+ <height>685</height>
+ </rect>
+ </property>
+ <layout class="QVBoxLayout">
+ <item>
+ <layout class="QHBoxLayout">
+ <item>
+ <widget class="QLineEdit" name="searchEdit">
+ <property name="placeholderText">
+ <string>Search and filter ...</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="searchButton">
+ <property name="text">
+ <string>Search</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout">
+ <item>
+ <widget class="QListView" name="packView">
+ <property name="horizontalScrollBarPolicy">
+ <enum>Qt::ScrollBarAlwaysOff</enum>
+ </property>
+ <property name="alternatingRowColors">
+ <bool>true</bool>
+ </property>
+ <property name="iconSize">
+ <size>
+ <width>48</width>
+ <height>48</height>
+ </size>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QTextBrowser" name="packDescription">
+ <property name="openExternalLinks">
+ <bool>true</bool>
+ </property>
+ <property name="openLinks">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout">
+ <item>
+ <widget class="QComboBox" name="sortByBox"/>
+ </item>
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Version selected:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QComboBox" name="versionSelectionBox"/>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <tabstops>
+ <tabstop>searchEdit</tabstop>
+ <tabstop>searchButton</tabstop>
+ <tabstop>packView</tabstop>
+ <tabstop>packDescription</tabstop>
+ <tabstop>sortByBox</tabstop>
+ <tabstop>versionSelectionBox</tabstop>
+ </tabstops>
+ <resources/>
+ <connections/>
+</ui>