aboutsummaryrefslogtreecommitdiff
path: root/launcher/ui
diff options
context:
space:
mode:
Diffstat (limited to 'launcher/ui')
-rw-r--r--launcher/ui/InstanceWindow.cpp115
-rw-r--r--launcher/ui/InstanceWindow.h15
-rw-r--r--launcher/ui/MainWindow.cpp296
-rw-r--r--launcher/ui/MainWindow.h24
-rw-r--r--launcher/ui/MainWindow.ui73
-rw-r--r--launcher/ui/dialogs/CopyInstanceDialog.cpp2
-rw-r--r--launcher/ui/dialogs/ExportInstanceDialog.cpp8
-rw-r--r--launcher/ui/dialogs/ExportPackDialog.cpp81
-rw-r--r--launcher/ui/dialogs/ExportPackDialog.ui86
-rw-r--r--launcher/ui/dialogs/InstallLoaderDialog.cpp166
-rw-r--r--launcher/ui/dialogs/InstallLoaderDialog.h45
-rw-r--r--launcher/ui/dialogs/ModUpdateDialog.cpp10
-rw-r--r--launcher/ui/dialogs/NewInstanceDialog.cpp11
-rw-r--r--launcher/ui/dialogs/NewInstanceDialog.h5
-rw-r--r--launcher/ui/dialogs/ProfileSetupDialog.cpp16
-rw-r--r--launcher/ui/dialogs/ProgressDialog.cpp20
-rw-r--r--launcher/ui/dialogs/ProgressDialog.h2
-rw-r--r--launcher/ui/dialogs/ResourceDownloadDialog.cpp34
-rw-r--r--launcher/ui/dialogs/ResourceDownloadDialog.h5
-rw-r--r--launcher/ui/dialogs/ReviewMessageBox.cpp2
-rw-r--r--launcher/ui/dialogs/SkinUploadDialog.cpp6
-rw-r--r--launcher/ui/dialogs/SkinUploadDialog.ui8
-rw-r--r--launcher/ui/dialogs/VersionSelectDialog.cpp13
-rw-r--r--launcher/ui/dialogs/VersionSelectDialog.h1
-rw-r--r--launcher/ui/instanceview/InstanceDelegate.cpp22
-rw-r--r--launcher/ui/instanceview/InstanceView.cpp86
-rw-r--r--launcher/ui/pages/BasePageContainer.h1
-rw-r--r--launcher/ui/pages/global/AccountListPage.cpp7
-rw-r--r--launcher/ui/pages/global/ExternalToolsPage.ui8
-rw-r--r--launcher/ui/pages/global/JavaPage.cpp6
-rw-r--r--launcher/ui/pages/global/JavaPage.ui150
-rw-r--r--launcher/ui/pages/global/LauncherPage.ui8
-rw-r--r--launcher/ui/pages/global/MinecraftPage.cpp43
-rw-r--r--launcher/ui/pages/global/MinecraftPage.h3
-rw-r--r--launcher/ui/pages/global/MinecraftPage.ui66
-rw-r--r--launcher/ui/pages/global/ProxyPage.cpp2
-rw-r--r--launcher/ui/pages/instance/ExternalResourcesPage.cpp3
-rw-r--r--launcher/ui/pages/instance/ExternalResourcesPage.ui11
-rw-r--r--launcher/ui/pages/instance/InstanceSettingsPage.cpp54
-rw-r--r--launcher/ui/pages/instance/InstanceSettingsPage.h3
-rw-r--r--launcher/ui/pages/instance/InstanceSettingsPage.ui131
-rw-r--r--launcher/ui/pages/instance/ManagedPackPage.cpp6
-rw-r--r--launcher/ui/pages/instance/ModFolderPage.cpp32
-rw-r--r--launcher/ui/pages/instance/ModFolderPage.h1
-rw-r--r--launcher/ui/pages/instance/OtherLogsPage.cpp22
-rw-r--r--launcher/ui/pages/instance/ResourcePackPage.cpp2
-rw-r--r--launcher/ui/pages/instance/ServersPage.cpp28
-rw-r--r--launcher/ui/pages/instance/TexturePackPage.cpp2
-rw-r--r--launcher/ui/pages/instance/VersionPage.cpp143
-rw-r--r--launcher/ui/pages/instance/VersionPage.h5
-rw-r--r--launcher/ui/pages/instance/VersionPage.ui62
-rw-r--r--launcher/ui/pages/instance/WorldListPage.cpp2
-rw-r--r--launcher/ui/pages/modplatform/CustomPage.cpp3
-rw-r--r--launcher/ui/pages/modplatform/CustomPage.ui10
-rw-r--r--launcher/ui/pages/modplatform/ImportPage.cpp74
-rw-r--r--launcher/ui/pages/modplatform/ImportPage.h3
-rw-r--r--launcher/ui/pages/modplatform/ImportPage.ui2
-rw-r--r--launcher/ui/pages/modplatform/ModModel.cpp4
-rw-r--r--launcher/ui/pages/modplatform/ModPage.cpp3
-rw-r--r--launcher/ui/pages/modplatform/ModPage.h2
-rw-r--r--launcher/ui/pages/modplatform/ResourceModel.cpp66
-rw-r--r--launcher/ui/pages/modplatform/ResourceModel.h6
-rw-r--r--launcher/ui/pages/modplatform/ResourcePackModel.cpp3
-rw-r--r--launcher/ui/pages/modplatform/ResourcePage.cpp13
-rw-r--r--launcher/ui/pages/modplatform/ResourcePage.h6
-rw-r--r--launcher/ui/pages/modplatform/ShaderPackModel.cpp3
-rw-r--r--launcher/ui/pages/modplatform/ShaderPackPage.cpp3
-rw-r--r--launcher/ui/pages/modplatform/atlauncher/AtlFilterModel.cpp3
-rw-r--r--launcher/ui/pages/modplatform/atlauncher/AtlListModel.cpp67
-rw-r--r--launcher/ui/pages/modplatform/atlauncher/AtlOptionalModDialog.cpp20
-rw-r--r--launcher/ui/pages/modplatform/atlauncher/AtlOptionalModDialog.h2
-rw-r--r--launcher/ui/pages/modplatform/atlauncher/AtlPage.cpp16
-rw-r--r--launcher/ui/pages/modplatform/atlauncher/AtlPage.ui89
-rw-r--r--launcher/ui/pages/modplatform/flame/FlameModel.cpp65
-rw-r--r--launcher/ui/pages/modplatform/flame/FlameModel.h6
-rw-r--r--launcher/ui/pages/modplatform/flame/FlamePage.cpp33
-rw-r--r--launcher/ui/pages/modplatform/flame/FlamePage.h8
-rw-r--r--launcher/ui/pages/modplatform/flame/FlamePage.ui4
-rw-r--r--launcher/ui/pages/modplatform/flame/FlameResourceModels.cpp27
-rw-r--r--launcher/ui/pages/modplatform/flame/FlameResourceModels.h17
-rw-r--r--launcher/ui/pages/modplatform/flame/FlameResourcePages.cpp49
-rw-r--r--launcher/ui/pages/modplatform/flame/FlameResourcePages.h30
-rw-r--r--launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.cpp29
-rw-r--r--launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.h3
-rw-r--r--launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.ui52
-rw-r--r--launcher/ui/pages/modplatform/import_ftb/ListModel.cpp105
-rw-r--r--launcher/ui/pages/modplatform/import_ftb/ListModel.h22
-rw-r--r--launcher/ui/pages/modplatform/legacy_ftb/ListModel.cpp103
-rw-r--r--launcher/ui/pages/modplatform/legacy_ftb/ListModel.h2
-rw-r--r--launcher/ui/pages/modplatform/legacy_ftb/Page.cpp31
-rw-r--r--launcher/ui/pages/modplatform/legacy_ftb/Page.h5
-rw-r--r--launcher/ui/pages/modplatform/legacy_ftb/Page.ui49
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp75
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthModel.h6
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp32
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthPage.h7
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthPage.ui10
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthResourceModels.cpp12
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthResourcePages.cpp16
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthResourcePages.h2
-rw-r--r--launcher/ui/pages/modplatform/technic/TechnicModel.cpp82
-rw-r--r--launcher/ui/pages/modplatform/technic/TechnicModel.h3
-rw-r--r--launcher/ui/pages/modplatform/technic/TechnicPage.cpp39
-rw-r--r--launcher/ui/pages/modplatform/technic/TechnicPage.h8
-rw-r--r--launcher/ui/pages/modplatform/technic/TechnicPage.ui4
-rw-r--r--launcher/ui/setupwizard/ThemeWizardPage.cpp2
-rw-r--r--launcher/ui/themes/CatPack.cpp10
-rw-r--r--launcher/ui/themes/CatPack.h9
-rw-r--r--launcher/ui/themes/CustomTheme.cpp2
-rw-r--r--launcher/ui/themes/IconTheme.cpp53
-rw-r--r--launcher/ui/themes/IconTheme.h37
-rw-r--r--launcher/ui/themes/ThemeManager.cpp192
-rw-r--r--launcher/ui/themes/ThemeManager.h23
-rw-r--r--launcher/ui/widgets/InfoFrame.cpp10
-rw-r--r--launcher/ui/widgets/JavaSettingsWidget.cpp30
-rw-r--r--launcher/ui/widgets/PageContainer.cpp8
-rw-r--r--launcher/ui/widgets/PageContainer.h6
-rw-r--r--launcher/ui/widgets/PageContainer_p.h2
-rw-r--r--launcher/ui/widgets/ProjectItem.cpp2
-rw-r--r--launcher/ui/widgets/SubTaskProgressBar.cpp2
-rw-r--r--launcher/ui/widgets/ThemeCustomizationWidget.cpp40
-rw-r--r--launcher/ui/widgets/ThemeCustomizationWidget.h16
-rw-r--r--launcher/ui/widgets/ThemeCustomizationWidget.ui98
-rw-r--r--launcher/ui/widgets/VariableSizedImageObject.cpp3
-rw-r--r--launcher/ui/widgets/VersionSelectWidget.cpp26
-rw-r--r--launcher/ui/widgets/VersionSelectWidget.h6
-rw-r--r--launcher/ui/widgets/WideBar.cpp4
127 files changed, 2567 insertions, 1301 deletions
diff --git a/launcher/ui/InstanceWindow.cpp b/launcher/ui/InstanceWindow.cpp
index 9c7886fa..bf83a56c 100644
--- a/launcher/ui/InstanceWindow.cpp
+++ b/launcher/ui/InstanceWindow.cpp
@@ -2,6 +2,7 @@
/*
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
+ * Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -43,8 +44,6 @@
#include <QPushButton>
#include <QScrollBar>
-#include "ui/dialogs/CustomMessageBox.h"
-#include "ui/dialogs/ProgressDialog.h"
#include "ui/widgets/PageContainer.h"
#include "InstancePageProvider.h"
@@ -75,40 +74,44 @@ InstanceWindow::InstanceWindow(InstancePtr instance, QWidget* parent) : QMainWin
// Add custom buttons to the page container layout.
{
- auto horizontalLayout = new QHBoxLayout();
+ auto horizontalLayout = new QHBoxLayout(this);
horizontalLayout->setObjectName(QStringLiteral("horizontalLayout"));
horizontalLayout->setContentsMargins(6, -1, 6, -1);
- auto btnHelp = new QPushButton();
+ auto btnHelp = new QPushButton(this);
btnHelp->setText(tr("Help"));
horizontalLayout->addWidget(btnHelp);
- connect(btnHelp, SIGNAL(clicked(bool)), m_container, SLOT(help()));
+ connect(btnHelp, &QPushButton::clicked, m_container, &PageContainer::help);
auto spacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout->addSpacerItem(spacer);
- m_killButton = new QPushButton();
- horizontalLayout->addWidget(m_killButton);
- connect(m_killButton, SIGNAL(clicked(bool)), SLOT(on_btnKillMinecraft_clicked()));
-
- m_launchOfflineButton = new QPushButton();
- horizontalLayout->addWidget(m_launchOfflineButton);
- m_launchOfflineButton->setText(tr("Launch Offline"));
+ m_launchButton = new QToolButton(this);
+ m_launchButton->setText(tr("&Launch"));
+ m_launchButton->setToolTip(tr("Launch the instance"));
+ m_launchButton->setPopupMode(QToolButton::MenuButtonPopup);
+ m_launchButton->setMinimumWidth(80); // HACK!!
+ horizontalLayout->addWidget(m_launchButton);
+ connect(m_launchButton, &QPushButton::clicked, this, [this] { APPLICATION->launch(m_instance); });
- m_launchDemoButton = new QPushButton();
- horizontalLayout->addWidget(m_launchDemoButton);
- m_launchDemoButton->setText(tr("Launch Demo"));
+ m_killButton = new QPushButton(this);
+ m_killButton->setText(tr("&Kill"));
+ m_killButton->setToolTip(tr("Kill the running instance"));
+ m_killButton->setShortcut(QKeySequence(tr("Ctrl+K")));
+ horizontalLayout->addWidget(m_killButton);
+ connect(m_killButton, &QPushButton::clicked, this, [this] { APPLICATION->kill(m_instance); });
- updateLaunchButtons();
- connect(m_launchOfflineButton, SIGNAL(clicked(bool)), SLOT(on_btnLaunchMinecraftOffline_clicked()));
- connect(m_launchDemoButton, SIGNAL(clicked(bool)), SLOT(on_btnLaunchMinecraftDemo_clicked()));
+ updateButtons();
- m_closeButton = new QPushButton();
+ m_closeButton = new QPushButton(this);
m_closeButton->setText(tr("Close"));
horizontalLayout->addWidget(m_closeButton);
- connect(m_closeButton, SIGNAL(clicked(bool)), SLOT(on_closeButton_clicked()));
+ connect(m_closeButton, &QPushButton::clicked, this, &QMainWindow::close);
m_container->addButtons(horizontalLayout);
+
+ connect(m_instance.get(), &BaseInstance::profilerChanged, this, &InstanceWindow::updateButtons);
+ connect(APPLICATION, &Application::globalSettingsClosed, this, &InstanceWindow::updateButtons);
}
// restore window state
@@ -148,47 +151,18 @@ void InstanceWindow::on_instanceStatusChanged(BaseInstance::Status, BaseInstance
}
}
-void InstanceWindow::updateLaunchButtons()
-{
- if (m_instance->isRunning()) {
- m_launchOfflineButton->setEnabled(false);
- m_launchDemoButton->setEnabled(false);
- m_killButton->setText(tr("Kill"));
- m_killButton->setObjectName("killButton");
- m_killButton->setToolTip(tr("Kill the running instance"));
- } else if (!m_instance->canLaunch()) {
- m_launchOfflineButton->setEnabled(false);
- m_launchDemoButton->setEnabled(false);
- m_killButton->setText(tr("Launch"));
- m_killButton->setObjectName("launchButton");
- m_killButton->setToolTip(tr("Launch the instance"));
- m_killButton->setEnabled(false);
- } else {
- m_launchOfflineButton->setEnabled(true);
-
- // Disable demo-mode if not available.
- auto instance = dynamic_cast<MinecraftInstance*>(m_instance.get());
- if (instance) {
- m_launchDemoButton->setEnabled(instance->supportsDemo());
- }
-
- m_killButton->setText(tr("Launch"));
- m_killButton->setObjectName("launchButton");
- m_killButton->setToolTip(tr("Launch the instance"));
- }
- // NOTE: this is a hack to force the button to recalculate its style
- m_killButton->setStyleSheet("/* */");
- m_killButton->setStyleSheet(QString());
-}
-
-void InstanceWindow::on_btnLaunchMinecraftOffline_clicked()
-{
- APPLICATION->launch(m_instance, false, false, nullptr);
-}
-
-void InstanceWindow::on_btnLaunchMinecraftDemo_clicked()
+void InstanceWindow::updateButtons()
{
- APPLICATION->launch(m_instance, false, true, nullptr);
+ m_launchButton->setEnabled(m_instance->canLaunch());
+ m_killButton->setEnabled(m_instance->isRunning());
+
+ QMenu* launchMenu = m_launchButton->menu();
+ if (launchMenu)
+ launchMenu->clear();
+ else
+ launchMenu = new QMenu(this);
+ m_instance->populateLaunchMenu(launchMenu);
+ m_launchButton->setMenu(launchMenu);
}
void InstanceWindow::instanceLaunchTaskChanged(shared_qobject_ptr<LaunchTask> proc)
@@ -198,18 +172,13 @@ void InstanceWindow::instanceLaunchTaskChanged(shared_qobject_ptr<LaunchTask> pr
void InstanceWindow::runningStateChanged(bool running)
{
- updateLaunchButtons();
+ updateButtons();
m_container->refreshContainer();
if (running) {
selectPage("log");
}
}
-void InstanceWindow::on_closeButton_clicked()
-{
- close();
-}
-
void InstanceWindow::closeEvent(QCloseEvent* event)
{
bool proceed = true;
@@ -232,15 +201,6 @@ bool InstanceWindow::saveAll()
return m_container->saveAll();
}
-void InstanceWindow::on_btnKillMinecraft_clicked()
-{
- if (m_instance->isRunning()) {
- APPLICATION->kill(m_instance);
- } else {
- APPLICATION->launch(m_instance, true, false, nullptr);
- }
-}
-
QString InstanceWindow::instanceId()
{
return m_instance->id();
@@ -256,7 +216,10 @@ void InstanceWindow::refreshContainer()
m_container->refreshContainer();
}
-InstanceWindow::~InstanceWindow() {}
+BasePage* InstanceWindow::selectedPage() const
+{
+ return m_container->selectedPage();
+}
bool InstanceWindow::requestClose()
{
diff --git a/launcher/ui/InstanceWindow.h b/launcher/ui/InstanceWindow.h
index 508bcaa1..e5bc24d4 100644
--- a/launcher/ui/InstanceWindow.h
+++ b/launcher/ui/InstanceWindow.h
@@ -2,6 +2,7 @@
/*
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
+ * Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -37,6 +38,7 @@
#include <QMainWindow>
#include <QSystemTrayIcon>
+#include <QToolButton>
#include "LaunchController.h"
#include "launch/LaunchTask.h"
@@ -52,9 +54,10 @@ class InstanceWindow : public QMainWindow, public BasePageContainer {
public:
explicit InstanceWindow(InstancePtr proc, QWidget* parent = 0);
- virtual ~InstanceWindow();
+ virtual ~InstanceWindow() = default;
bool selectPage(QString pageId) override;
+ BasePage* selectedPage() const override;
void refreshContainer() override;
QString instanceId();
@@ -69,11 +72,6 @@ class InstanceWindow : public QMainWindow, public BasePageContainer {
void isClosing();
private slots:
- void on_closeButton_clicked();
- void on_btnKillMinecraft_clicked();
- void on_btnLaunchMinecraftOffline_clicked();
- void on_btnLaunchMinecraftDemo_clicked();
-
void instanceLaunchTaskChanged(shared_qobject_ptr<LaunchTask> proc);
void runningStateChanged(bool running);
void on_instanceStatusChanged(BaseInstance::Status, BaseInstance::Status newStatus);
@@ -82,7 +80,7 @@ class InstanceWindow : public QMainWindow, public BasePageContainer {
void closeEvent(QCloseEvent*) override;
private:
- void updateLaunchButtons();
+ void updateButtons();
private:
shared_qobject_ptr<LaunchTask> m_proc;
@@ -90,7 +88,6 @@ class InstanceWindow : public QMainWindow, public BasePageContainer {
bool m_doNotSave = false;
PageContainer* m_container = nullptr;
QPushButton* m_closeButton = nullptr;
+ QToolButton* m_launchButton = nullptr;
QPushButton* m_killButton = nullptr;
- QPushButton* m_launchOfflineButton = nullptr;
- QPushButton* m_launchDemoButton = nullptr;
};
diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp
index e342e833..5e55a5ab 100644
--- a/launcher/ui/MainWindow.cpp
+++ b/launcher/ui/MainWindow.cpp
@@ -43,7 +43,6 @@
#include "FileSystem.h"
#include "MainWindow.h"
-#include "ui/dialogs/ExportToModListDialog.h"
#include "ui_MainWindow.h"
#include <QDir>
@@ -85,22 +84,19 @@
#include <launch/LaunchTask.h>
#include <minecraft/MinecraftInstance.h>
#include <minecraft/auth/AccountList.h>
-#include <net/Download.h>
+#include <net/ApiDownload.h>
#include <net/NetJob.h>
#include <news/NewsChecker.h>
#include <tools/BaseProfiler.h>
#include <updater/ExternalUpdater.h>
-#include "InstancePageProvider.h"
#include "InstanceWindow.h"
-#include "JavaCommon.h"
-#include "LaunchController.h"
#include "ui/dialogs/AboutDialog.h"
#include "ui/dialogs/CopyInstanceDialog.h"
#include "ui/dialogs/CustomMessageBox.h"
-#include "ui/dialogs/EditAccountDialog.h"
#include "ui/dialogs/ExportInstanceDialog.h"
#include "ui/dialogs/ExportPackDialog.h"
+#include "ui/dialogs/ExportToModListDialog.h"
#include "ui/dialogs/IconPickerDialog.h"
#include "ui/dialogs/ImportResourceDialog.h"
#include "ui/dialogs/NewInstanceDialog.h"
@@ -113,15 +109,24 @@
#include "ui/themes/ThemeManager.h"
#include "ui/widgets/LabeledToolButton.h"
+#include "minecraft/PackProfile.h"
+#include "minecraft/VersionFile.h"
#include "minecraft/WorldList.h"
#include "minecraft/mod/ModFolderModel.h"
+#include "minecraft/mod/ResourcePackFolderModel.h"
#include "minecraft/mod/ShaderPackFolderModel.h"
+#include "minecraft/mod/TexturePackFolderModel.h"
#include "minecraft/mod/tasks/LocalResourceParse.h"
+#include "modplatform/ModIndex.h"
+#include "modplatform/flame/FlameAPI.h"
+#include "modplatform/flame/FlameModIndex.h"
+
#include "KonamiCode.h"
#include "InstanceCopyTask.h"
-#include "InstanceImportTask.h"
+
+#include "Json.h"
#include "MMCTime.h"
@@ -515,9 +520,9 @@ void MainWindow::showInstanceContextMenu(const QPoint& pos)
QAction* actionCreateInstance = new QAction(tr("Create instance"), this);
actionCreateInstance->setToolTip(ui->actionAddInstance->toolTip());
if (!group.isNull()) {
- QVariantMap data;
- data["group"] = group;
- actionCreateInstance->setData(data);
+ QVariantMap instance_action_data;
+ instance_action_data["group"] = group;
+ actionCreateInstance->setData(instance_action_data);
}
connect(actionCreateInstance, SIGNAL(triggered(bool)), SLOT(on_actionAddInstance_triggered()));
@@ -527,9 +532,9 @@ void MainWindow::showInstanceContextMenu(const QPoint& pos)
actions.append(actionCreateInstance);
if (!group.isNull()) {
QAction* actionDeleteGroup = new QAction(tr("Delete group '%1'").arg(group), this);
- QVariantMap data;
- data["group"] = group;
- actionDeleteGroup->setData(data);
+ QVariantMap delete_group_action_data;
+ delete_group_action_data["group"] = group;
+ actionDeleteGroup->setData(delete_group_action_data);
connect(actionDeleteGroup, SIGNAL(triggered(bool)), SLOT(deleteGroup()));
actions.append(actionDeleteGroup);
}
@@ -549,71 +554,15 @@ void MainWindow::updateMainToolBar()
ui->mainToolBar->setVisible(ui->menuBar->isNativeMenuBar() || !APPLICATION->settings()->get("MenuBarInsteadOfToolBar").toBool());
}
-void MainWindow::updateToolsMenu()
+void MainWindow::updateLaunchButton()
{
- bool currentInstanceRunning = m_selectedInstance && m_selectedInstance->isRunning();
-
- ui->actionLaunchInstance->setDisabled(!m_selectedInstance || currentInstanceRunning);
- ui->actionLaunchInstanceOffline->setDisabled(!m_selectedInstance || currentInstanceRunning);
- ui->actionLaunchInstanceDemo->setDisabled(!m_selectedInstance || currentInstanceRunning);
-
QMenu* launchMenu = ui->actionLaunchInstance->menu();
- if (launchMenu) {
+ if (launchMenu)
launchMenu->clear();
- } else {
+ else
launchMenu = new QMenu(this);
- }
- QAction* normalLaunch = launchMenu->addAction(tr("Launch"));
- normalLaunch->setShortcut(QKeySequence::Open);
- QAction* normalLaunchOffline = launchMenu->addAction(tr("Launch Offline"));
- normalLaunchOffline->setShortcut(QKeySequence(tr("Ctrl+Shift+O")));
- QAction* normalLaunchDemo = launchMenu->addAction(tr("Launch Demo"));
- normalLaunchDemo->setShortcut(QKeySequence(tr("Ctrl+Alt+O")));
- if (m_selectedInstance) {
- normalLaunch->setEnabled(m_selectedInstance->canLaunch());
- normalLaunchOffline->setEnabled(m_selectedInstance->canLaunch());
- normalLaunchDemo->setEnabled(m_selectedInstance->canLaunch());
-
- connect(normalLaunch, &QAction::triggered, [this]() { APPLICATION->launch(m_selectedInstance, true, false); });
- connect(normalLaunchOffline, &QAction::triggered, [this]() { APPLICATION->launch(m_selectedInstance, false, false); });
- connect(normalLaunchDemo, &QAction::triggered, [this]() { APPLICATION->launch(m_selectedInstance, false, true); });
- } else {
- normalLaunch->setDisabled(true);
- normalLaunchOffline->setDisabled(true);
- normalLaunchDemo->setDisabled(true);
- }
-
- // Disable demo-mode if not available.
- auto instance = dynamic_cast<MinecraftInstance*>(m_selectedInstance.get());
- if (instance) {
- normalLaunchDemo->setEnabled(instance->supportsDemo());
- }
-
- QString profilersTitle = tr("Profilers");
- launchMenu->addSeparator()->setText(profilersTitle);
- for (auto profiler : APPLICATION->profilers().values()) {
- QAction* profilerAction = launchMenu->addAction(profiler->name());
- QAction* profilerOfflineAction = launchMenu->addAction(tr("%1 Offline").arg(profiler->name()));
- QString error;
- if (!profiler->check(&error)) {
- profilerAction->setDisabled(true);
- profilerOfflineAction->setDisabled(true);
- QString profilerToolTip = tr("Profiler not setup correctly. Go into settings, \"External Tools\".");
- profilerAction->setToolTip(profilerToolTip);
- profilerOfflineAction->setToolTip(profilerToolTip);
- } else if (m_selectedInstance) {
- profilerAction->setEnabled(m_selectedInstance->canLaunch());
- profilerOfflineAction->setEnabled(m_selectedInstance->canLaunch());
-
- connect(profilerAction, &QAction::triggered,
- [this, profiler]() { APPLICATION->launch(m_selectedInstance, true, false, profiler.get()); });
- connect(profilerOfflineAction, &QAction::triggered,
- [this, profiler]() { APPLICATION->launch(m_selectedInstance, false, false, profiler.get()); });
- } else {
- profilerAction->setDisabled(true);
- profilerOfflineAction->setDisabled(true);
- }
- }
+ if (m_selectedInstance)
+ m_selectedInstance->populateLaunchMenu(launchMenu);
ui->actionLaunchInstance->setMenu(launchMenu);
}
@@ -627,7 +576,7 @@ void MainWindow::updateThemeMenu()
themeMenu = new QMenu(this);
}
- auto themes = APPLICATION->getValidApplicationThemes();
+ auto themes = APPLICATION->themeManager()->getValidApplicationThemes();
QActionGroup* themesGroup = new QActionGroup(this);
@@ -641,7 +590,7 @@ void MainWindow::updateThemeMenu()
themeAction->setActionGroup(themesGroup);
connect(themeAction, &QAction::triggered, [theme]() {
- APPLICATION->setApplicationTheme(theme->id());
+ APPLICATION->themeManager()->setApplicationTheme(theme->id());
APPLICATION->settings()->set("ApplicationTheme", theme->id());
});
}
@@ -744,9 +693,9 @@ void MainWindow::changeActiveAccount()
if (sAction->data().type() != QVariant::Type::Int)
return;
- QVariant data = sAction->data();
+ QVariant action_data = sAction->data();
bool valid = false;
- int index = data.toInt(&valid);
+ int index = action_data.toInt(&valid);
if (!valid) {
index = -1;
}
@@ -923,13 +872,13 @@ void MainWindow::finalizeInstance(InstancePtr inst)
} else {
CustomMessageBox::selectable(this, tr("Error"),
tr("The launcher cannot download Minecraft or update instances unless you have at least "
- "one account added.\nPlease add your Mojang or Minecraft account."),
+ "one account added.\nPlease add your Microsoft or Mojang account."),
QMessageBox::Warning)
->show();
}
}
-void MainWindow::addInstance(QString url)
+void MainWindow::addInstance(const QString& url, const QMap<QString, QString>& extra_info)
{
QString groupName;
do {
@@ -949,7 +898,7 @@ void MainWindow::addInstance(QString url)
groupName = APPLICATION->settings()->get("LastUsedGroupForNewInstance").toString();
}
- NewInstanceDialog newInstDlg(groupName, url, this);
+ NewInstanceDialog newInstDlg(groupName, url, extra_info, this);
if (!newInstDlg.exec())
return;
@@ -976,18 +925,105 @@ void MainWindow::processURLs(QList<QUrl> urls)
if (url.scheme().isEmpty())
url.setScheme("file");
- if (!url.isLocalFile()) { // probably instance/modpack
- addInstance(url.toString());
- break;
+ ModPlatform::IndexedVersion version;
+ QMap<QString, QString> extra_info;
+ QUrl local_url;
+ if (!url.isLocalFile()) { // download the remote resource and identify
+ QUrl dl_url;
+ if (url.scheme() == "curseforge") {
+ // need to find the download link for the modpack / resource
+ // format of url curseforge://install?addonId=IDHERE&fileId=IDHERE
+ QUrlQuery query(url);
+
+ if (query.allQueryItemValues("addonId").isEmpty() || query.allQueryItemValues("fileId").isEmpty()) {
+ qDebug() << "Invalid curseforge link:" << url;
+ continue;
+ }
+
+ auto addonId = query.allQueryItemValues("addonId")[0];
+ auto fileId = query.allQueryItemValues("fileId")[0];
+
+ extra_info.insert("pack_id", addonId);
+ extra_info.insert("pack_version_id", fileId);
+
+ auto array = std::make_shared<QByteArray>();
+
+ auto api = FlameAPI();
+ auto job = api.getFile(addonId, fileId, array);
+
+ connect(job.get(), &Task::failed, this,
+ [this](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show(); });
+ connect(job.get(), &Task::succeeded, this, [this, array, addonId, fileId, &dl_url, &version] {
+ qDebug() << "Returned CFURL Json:\n" << array->toStdString().c_str();
+ auto doc = Json::requireDocument(*array);
+ auto data = Json::ensureObject(Json::ensureObject(doc.object()), "data");
+ // No way to find out if it's a mod or a modpack before here
+ // And also we need to check if it ends with .zip, instead of any better way
+ version = FlameMod::loadIndexedPackVersion(data);
+ auto fileName = version.fileName;
+
+ // Have to use ensureString then use QUrl to get proper url encoding
+ dl_url = QUrl(version.downloadUrl);
+ if (!dl_url.isValid()) {
+ CustomMessageBox::selectable(
+ this, tr("Error"),
+ tr("The modpack, mod, or resource %1 is blocked for third-parties! Please download it manually.").arg(fileName),
+ QMessageBox::Critical)
+ ->show();
+ return;
+ }
+
+ QFileInfo dl_file(dl_url.fileName());
+ });
+
+ { // drop stack
+ ProgressDialog dlUrlDialod(this);
+ dlUrlDialod.setSkipButton(true, tr("Abort"));
+ dlUrlDialod.execWithTask(job.get());
+ }
+
+ } else {
+ dl_url = url;
+ }
+
+ if (!dl_url.isValid()) {
+ continue; // no valid url to download this resource
+ }
+
+ const QString path = dl_url.host() + '/' + dl_url.path();
+ auto entry = APPLICATION->metacache()->resolveEntry("general", path);
+ entry->setStale(true);
+ auto dl_job = unique_qobject_ptr<NetJob>(new NetJob(tr("Modpack download"), APPLICATION->network()));
+ dl_job->addNetAction(Net::ApiDownload::makeCached(dl_url, entry));
+ auto archivePath = entry->getFullPath();
+
+ bool dl_success = false;
+ connect(dl_job.get(), &Task::failed, this,
+ [this](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show(); });
+ connect(dl_job.get(), &Task::succeeded, this, [&dl_success] { dl_success = true; });
+
+ { // drop stack
+ ProgressDialog dlUrlDialod(this);
+ dlUrlDialod.setSkipButton(true, tr("Abort"));
+ dlUrlDialod.execWithTask(dl_job.get());
+ }
+
+ if (!dl_success) {
+ continue; // no local file to identify
+ }
+ local_url = QUrl::fromLocalFile(archivePath);
+
+ } else {
+ local_url = url;
}
- auto localFileName = QDir::toNativeSeparators(url.toLocalFile());
+ auto localFileName = QDir::toNativeSeparators(local_url.toLocalFile());
QFileInfo localFileInfo(localFileName);
auto type = ResourceUtils::identify(localFileInfo);
if (ResourceUtils::ValidResourceTypes.count(type) == 0) { // probably instance/modpack
- addInstance(localFileName);
+ addInstance(localFileName, extra_info);
continue;
}
@@ -1012,7 +1048,7 @@ void MainWindow::processURLs(QList<QUrl> urls)
qWarning() << "Importing of Data Packs not supported at this time. Ignoring" << localFileName;
break;
case PackedResourceType::Mod:
- minecraftInst->loaderModList()->installMod(localFileName);
+ minecraftInst->loaderModList()->installMod(localFileName, version);
break;
case PackedResourceType::ShaderPack:
minecraftInst->shaderPackList()->installResource(localFileName);
@@ -1061,9 +1097,9 @@ void MainWindow::on_actionChangeInstIcon_triggered()
void MainWindow::iconUpdated(QString icon)
{
if (icon == m_currentInstIcon) {
- auto icon = APPLICATION->icons()->getIcon(m_currentInstIcon);
- ui->actionChangeInstIcon->setIcon(icon);
- changeIconButton->setIcon(icon);
+ auto new_icon = APPLICATION->icons()->getIcon(m_currentInstIcon);
+ ui->actionChangeInstIcon->setIcon(new_icon);
+ changeIconButton->setIcon(new_icon);
}
}
@@ -1134,26 +1170,40 @@ void MainWindow::undoTrashInstance()
ui->actionUndoTrashInstance->setEnabled(APPLICATION->instances()->trashedSomething());
}
+void MainWindow::on_actionViewLauncherRootFolder_triggered()
+{
+ DesktopServices::openDirectory(".");
+}
+
void MainWindow::on_actionViewInstanceFolder_triggered()
{
QString str = APPLICATION->settings()->get("InstanceDir").toString();
DesktopServices::openDirectory(str);
}
-void MainWindow::on_actionViewLauncherRootFolder_triggered()
+void MainWindow::on_actionViewCentralModsFolder_triggered()
{
- const QString dataPath = QDir::currentPath();
- DesktopServices::openDirectory(dataPath);
+ DesktopServices::openDirectory(APPLICATION->settings()->get("CentralModsDir").toString(), true);
}
-void MainWindow::refreshInstances()
+void MainWindow::on_actionViewIconThemeFolder_triggered()
{
- APPLICATION->instances()->loadList();
+ DesktopServices::openDirectory(APPLICATION->themeManager()->getIconThemesFolder().path());
}
-void MainWindow::on_actionViewCentralModsFolder_triggered()
+void MainWindow::on_actionViewWidgetThemeFolder_triggered()
{
- DesktopServices::openDirectory(APPLICATION->settings()->get("CentralModsDir").toString(), true);
+ DesktopServices::openDirectory(APPLICATION->themeManager()->getApplicationThemesFolder().path());
+}
+
+void MainWindow::on_actionViewCatPackFolder_triggered()
+{
+ DesktopServices::openDirectory(APPLICATION->themeManager()->getCatPacksFolder().path());
+}
+
+void MainWindow::refreshInstances()
+{
+ APPLICATION->instances()->loadList();
}
void MainWindow::checkForUpdates()
@@ -1177,7 +1227,7 @@ void MainWindow::globalSettingsClosed()
proxymodel->invalidate();
proxymodel->sort(0);
updateMainToolBar();
- updateToolsMenu();
+ updateLaunchButton();
updateThemeMenu();
updateStatusCenter();
// This needs to be done to prevent UI elements disappearing in the event the config is changed
@@ -1307,10 +1357,11 @@ void MainWindow::on_actionDeleteInstance_triggered()
if (APPLICATION->instances()->trashInstance(id)) {
ui->actionUndoTrashInstance->setEnabled(APPLICATION->instances()->trashedSomething());
- return;
+ } else {
+ APPLICATION->instances()->deleteInstance(id);
}
-
- APPLICATION->instances()->deleteInstance(id);
+ APPLICATION->settings()->set("SelectedInstance", QString());
+ selectionBad();
}
void MainWindow::on_actionExportInstanceZip_triggered()
@@ -1412,20 +1463,6 @@ void MainWindow::activateInstance(InstancePtr instance)
APPLICATION->launch(instance);
}
-void MainWindow::on_actionLaunchInstanceOffline_triggered()
-{
- if (m_selectedInstance) {
- APPLICATION->launch(m_selectedInstance, false);
- }
-}
-
-void MainWindow::on_actionLaunchInstanceDemo_triggered()
-{
- if (m_selectedInstance) {
- APPLICATION->launch(m_selectedInstance, false, true);
- }
-}
-
void MainWindow::on_actionKillInstance_triggered()
{
if (m_selectedInstance && m_selectedInstance->isRunning()) {
@@ -1590,7 +1627,7 @@ void MainWindow::startTask(Task* task)
task->start();
}
-void MainWindow::instanceChanged(const QModelIndex& current, const QModelIndex& previous)
+void MainWindow::instanceChanged(const QModelIndex& current, [[maybe_unused]] const QModelIndex& previous)
{
if (!current.isValid()) {
APPLICATION->settings()->set("SelectedInstance", QString());
@@ -1599,6 +1636,7 @@ void MainWindow::instanceChanged(const QModelIndex& current, const QModelIndex&
}
if (m_selectedInstance) {
disconnect(m_selectedInstance.get(), &BaseInstance::runningStatusChanged, this, &MainWindow::refreshCurrentInstance);
+ disconnect(m_selectedInstance.get(), &BaseInstance::profilerChanged, this, &MainWindow::refreshCurrentInstance);
}
QString id = current.data(InstanceList::InstanceIDRole).toString();
m_selectedInstance = APPLICATION->instances()->getInstanceById(id);
@@ -1606,14 +1644,6 @@ void MainWindow::instanceChanged(const QModelIndex& current, const QModelIndex&
ui->instanceToolBar->setEnabled(true);
setInstanceActionsEnabled(true);
ui->actionLaunchInstance->setEnabled(m_selectedInstance->canLaunch());
- ui->actionLaunchInstanceOffline->setEnabled(m_selectedInstance->canLaunch());
- ui->actionLaunchInstanceDemo->setEnabled(m_selectedInstance->canLaunch());
-
- // Disable demo-mode if not available.
- auto instance = dynamic_cast<MinecraftInstance*>(m_selectedInstance.get());
- if (instance) {
- ui->actionLaunchInstanceDemo->setEnabled(instance->supportsDemo());
- }
ui->actionKillInstance->setEnabled(m_selectedInstance->isRunning());
ui->actionExportInstance->setEnabled(m_selectedInstance->canExport());
@@ -1622,18 +1652,13 @@ void MainWindow::instanceChanged(const QModelIndex& current, const QModelIndex&
updateStatusCenter();
updateInstanceToolIcon(m_selectedInstance->iconKey());
- updateToolsMenu();
+ updateLaunchButton();
APPLICATION->settings()->set("SelectedInstance", m_selectedInstance->id());
connect(m_selectedInstance.get(), &BaseInstance::runningStatusChanged, this, &MainWindow::refreshCurrentInstance);
+ connect(m_selectedInstance.get(), &BaseInstance::profilerChanged, this, &MainWindow::refreshCurrentInstance);
} else {
- ui->instanceToolBar->setEnabled(false);
- setInstanceActionsEnabled(false);
- ui->actionLaunchInstance->setEnabled(false);
- ui->actionLaunchInstanceOffline->setEnabled(false);
- ui->actionLaunchInstanceDemo->setEnabled(false);
- ui->actionKillInstance->setEnabled(false);
APPLICATION->settings()->set("SelectedInstance", QString());
selectionBad();
return;
@@ -1658,11 +1683,12 @@ void MainWindow::selectionBad()
{
// start by reseting everything...
m_selectedInstance = nullptr;
+ m_statusLeft->setText(tr("No instance selected"));
statusBar()->clearMessage();
ui->instanceToolBar->setEnabled(false);
setInstanceActionsEnabled(false);
- updateToolsMenu();
+ updateLaunchButton();
renameButton->setText(tr("Rename Instance"));
updateInstanceToolIcon("grass");
@@ -1709,7 +1735,9 @@ void MainWindow::updateStatusCenter()
int timePlayed = APPLICATION->instances()->getTotalPlayTime();
if (timePlayed > 0) {
- m_statusCenter->setText(tr("Total playtime: %1").arg(Time::prettifyDuration(timePlayed)));
+ m_statusCenter->setText(
+ tr("Total playtime: %1")
+ .arg(Time::prettifyDuration(timePlayed, APPLICATION->settings()->get("ShowGameTimeWithoutDays").toBool())));
}
}
// "Instance actions" are actions that require an instance to be selected (i.e. "new instance" is not here)
@@ -1725,7 +1753,7 @@ void MainWindow::setInstanceActionsEnabled(bool enabled)
ui->actionCreateInstanceShortcut->setEnabled(enabled);
}
-void MainWindow::refreshCurrentInstance(bool running)
+void MainWindow::refreshCurrentInstance()
{
auto current = view->selectionModel()->currentIndex();
instanceChanged(current, current);
diff --git a/launcher/ui/MainWindow.h b/launcher/ui/MainWindow.h
index e6434dae..0b614452 100644
--- a/launcher/ui/MainWindow.h
+++ b/launcher/ui/MainWindow.h
@@ -109,16 +109,19 @@ class MainWindow : public QMainWindow {
void on_actionChangeInstIcon_triggered();
+ void on_actionViewLauncherRootFolder_triggered();
+
void on_actionViewInstanceFolder_triggered();
+ void on_actionViewCentralModsFolder_triggered();
- void on_actionViewLauncherRootFolder_triggered();
+ void on_actionViewIconThemeFolder_triggered();
+ void on_actionViewWidgetThemeFolder_triggered();
+ void on_actionViewCatPackFolder_triggered();
void on_actionViewSelectedInstFolder_triggered();
void refreshInstances();
- void on_actionViewCentralModsFolder_triggered();
-
void checkForUpdates();
void on_actionSettings_triggered();
@@ -141,10 +144,6 @@ class MainWindow : public QMainWindow {
void on_actionLaunchInstance_triggered();
- void on_actionLaunchInstanceOffline_triggered();
-
- void on_actionLaunchInstanceDemo_triggered();
-
void on_actionKillInstance_triggered();
void on_actionDeleteInstance_triggered();
@@ -152,10 +151,7 @@ class MainWindow : public QMainWindow {
void deleteGroup();
void undoTrashInstance();
- inline void on_actionExportInstance_triggered()
- {
- on_actionExportInstanceZip_triggered();
- }
+ inline void on_actionExportInstance_triggered() { on_actionExportInstanceZip_triggered(); }
void on_actionExportInstanceZip_triggered();
void on_actionExportInstanceMrPack_triggered();
void on_actionExportInstanceFlamePack_triggered();
@@ -178,7 +174,7 @@ class MainWindow : public QMainWindow {
void updateMainToolBar();
- void updateToolsMenu();
+ void updateLaunchButton();
void updateThemeMenu();
@@ -212,12 +208,12 @@ class MainWindow : public QMainWindow {
void keyReleaseEvent(QKeyEvent* event) override;
#endif
- void refreshCurrentInstance(bool running);
+ void refreshCurrentInstance();
private:
void retranslateUi();
- void addInstance(QString url = QString());
+ void addInstance(const QString& url = QString(), const QMap<QString, QString>& extra_info = {});
void activateInstance(InstancePtr instance);
void setCatBackground(bool enabled);
void updateInstanceToolIcon(QString new_icon);
diff --git a/launcher/ui/MainWindow.ui b/launcher/ui/MainWindow.ui
index e4421d40..91b2c270 100644
--- a/launcher/ui/MainWindow.ui
+++ b/launcher/ui/MainWindow.ui
@@ -186,9 +186,14 @@
<property name="toolTipsVisible">
<bool>true</bool>
</property>
- <addaction name="actionViewInstanceFolder"/>
<addaction name="actionViewLauncherRootFolder"/>
+ <addaction name="separator"/>
+ <addaction name="actionViewInstanceFolder"/>
<addaction name="actionViewCentralModsFolder"/>
+ <addaction name="separator"/>
+ <addaction name="actionViewIconThemeFolder"/>
+ <addaction name="actionViewWidgetThemeFolder"/>
+ <addaction name="actionViewCatPackFolder"/>
</widget>
<widget class="QMenu" name="accountsMenu">
<property name="title">
@@ -435,22 +440,6 @@
<string>Ctrl+D</string>
</property>
</action>
- <action name="actionLaunchInstanceOffline">
- <property name="text">
- <string>Launch &amp;Offline</string>
- </property>
- <property name="toolTip">
- <string>Launch the selected instance in offline mode.</string>
- </property>
- </action>
- <action name="actionLaunchInstanceDemo">
- <property name="text">
- <string>Launch &amp;Demo</string>
- </property>
- <property name="toolTip">
- <string>Launch the selected instance in demo mode.</string>
- </property>
- </action>
<action name="actionExportInstance">
<property name="icon">
<iconset theme="export">
@@ -465,7 +454,8 @@
</action>
<action name="actionExportInstanceZip">
<property name="icon">
- <iconset theme="launcher"/>
+ <iconset theme="launcher">
+ <normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>Prism Launcher (zip)</string>
@@ -473,7 +463,8 @@
</action>
<action name="actionExportInstanceMrPack">
<property name="icon">
- <iconset theme="modrinth"/>
+ <iconset theme="modrinth">
+ <normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>Modrinth (mrpack)</string>
@@ -481,15 +472,17 @@
</action>
<action name="actionExportInstanceFlamePack">
<property name="icon">
- <iconset theme="flame"/>
+ <iconset theme="flame">
+ <normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
- <string>CurseForge (zip)</string>
+ <string>CurseForge (zip)</string>
</property>
</action>
<action name="actionExportInstanceToModList">
<property name="icon">
- <iconset theme="new"/>
+ <iconset theme="new">
+ <normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>Mod List</string>
@@ -552,7 +545,7 @@
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
- <string>&amp;View Instance Folder</string>
+ <string>View &amp;Instance Folder</string>
</property>
<property name="toolTip">
<string>Open the instance folder in a file browser.</string>
@@ -564,7 +557,7 @@
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
- <string>&amp;View Launcher Root Folder</string>
+ <string>View Launcher &amp;Root Folder</string>
</property>
<property name="toolTip">
<string>Open the launcher's root folder in a file browser.</string>
@@ -719,6 +712,38 @@
<string>Open the %1 wiki</string>
</property>
</action>
+ <action name="actionViewWidgetThemeFolder">
+ <property name="icon">
+ <iconset theme="viewfolder">
+ <normaloff>.</normaloff>.</iconset>
+ </property>
+ <property name="text">
+ <string>View &amp;Widget Themes Folder</string>
+ </property>
+ <property name="toolTip">
+ <string>View Widget Theme Folder</string>
+ </property>
+ </action>
+ <action name="actionViewIconThemeFolder">
+ <property name="icon">
+ <iconset theme="viewfolder">
+ <normaloff>.</normaloff>.</iconset>
+ </property>
+ <property name="text">
+ <string>View I&amp;con Theme Folder</string>
+ </property>
+ <property name="toolTip">
+ <string>View Icon Theme Folder</string>
+ </property>
+ </action>
+ <action name="actionViewCatPackFolder">
+ <property name="icon">
+ <iconset theme="viewfolder"/>
+ </property>
+ <property name="text">
+ <string>View Cat Packs Folder</string>
+ </property>
+ </action>
</widget>
<customwidgets>
<customwidget>
diff --git a/launcher/ui/dialogs/CopyInstanceDialog.cpp b/launcher/ui/dialogs/CopyInstanceDialog.cpp
index 0e410027..8b2f5bb8 100644
--- a/launcher/ui/dialogs/CopyInstanceDialog.cpp
+++ b/launcher/ui/dialogs/CopyInstanceDialog.cpp
@@ -220,7 +220,7 @@ void CopyInstanceDialog::on_iconButton_clicked()
}
}
-void CopyInstanceDialog::on_instNameTextBox_textChanged(const QString& arg1)
+void CopyInstanceDialog::on_instNameTextBox_textChanged([[maybe_unused]] const QString& arg1)
{
updateDialogState();
}
diff --git a/launcher/ui/dialogs/ExportInstanceDialog.cpp b/launcher/ui/dialogs/ExportInstanceDialog.cpp
index d6a503cc..703736d6 100644
--- a/launcher/ui/dialogs/ExportInstanceDialog.cpp
+++ b/launcher/ui/dialogs/ExportInstanceDialog.cpp
@@ -195,8 +195,8 @@ void ExportInstanceDialog::loadPackIgnore()
if (!ignoreFile.open(QIODevice::ReadOnly)) {
return;
}
- auto data = ignoreFile.readAll();
- auto string = QString::fromUtf8(data);
+ auto ignoreData = ignoreFile.readAll();
+ auto string = QString::fromUtf8(ignoreData);
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
proxyModel->setBlockedPaths(string.split('\n', Qt::SkipEmptyParts));
#else
@@ -206,10 +206,10 @@ void ExportInstanceDialog::loadPackIgnore()
void ExportInstanceDialog::savePackIgnore()
{
- auto data = proxyModel->blockedPaths().toStringList().join('\n').toUtf8();
+ auto ignoreData = proxyModel->blockedPaths().toStringList().join('\n').toUtf8();
auto filename = ignoreFileName();
try {
- FS::write(filename, data);
+ FS::write(filename, ignoreData);
} catch (const Exception& e) {
qWarning() << e.cause();
}
diff --git a/launcher/ui/dialogs/ExportPackDialog.cpp b/launcher/ui/dialogs/ExportPackDialog.cpp
index ad8db5ff..5af24b1b 100644
--- a/launcher/ui/dialogs/ExportPackDialog.cpp
+++ b/launcher/ui/dialogs/ExportPackDialog.cpp
@@ -37,15 +37,21 @@
ExportPackDialog::ExportPackDialog(InstancePtr instance, QWidget* parent, ModPlatform::ResourceProvider provider)
: QDialog(parent), instance(instance), ui(new Ui::ExportPackDialog), m_provider(provider)
{
+ Q_ASSERT(m_provider == ModPlatform::ResourceProvider::MODRINTH || m_provider == ModPlatform::ResourceProvider::FLAME);
+
ui->setupUi(this);
- ui->name->setText(instance->name());
+ ui->name->setPlaceholderText(instance->name());
+ ui->name->setText(instance->settings()->get("ExportName").toString());
+ ui->version->setText(instance->settings()->get("ExportVersion").toString());
+ ui->optionalFiles->setChecked(instance->settings()->get("ExportOptionalFiles").toBool());
+
if (m_provider == ModPlatform::ResourceProvider::MODRINTH) {
- ui->summary->setText(instance->notes().split(QRegularExpression("\\r?\\n"))[0]);
- setWindowTitle("Export Modrinth Pack");
+ setWindowTitle(tr("Export Modrinth Pack"));
+ ui->summary->setText(instance->settings()->get("ExportSummary").toString());
} else {
- setWindowTitle("Export CurseForge Pack");
- ui->version->setText("");
- ui->summaryLabel->setText("Author");
+ setWindowTitle(tr("Export CurseForge Pack"));
+ ui->summaryLabel->setText(tr("&Author"));
+ ui->summary->setText(instance->settings()->get("ExportAuthor").toString());
}
// ensure a valid pack is generated
@@ -75,20 +81,19 @@ ExportPackDialog::ExportPackDialog(InstancePtr instance, QWidget* parent, ModPla
MinecraftInstance* mcInstance = dynamic_cast<MinecraftInstance*>(instance.get());
if (mcInstance) {
- mcInstance->loaderModList()->update();
const QDir index = mcInstance->loaderModList()->indexDir();
if (index.exists())
- proxy->blockedPaths().insert(root.relativeFilePath(index.absolutePath()));
+ proxy->ignoreFilesWithPath().insert(root.relativeFilePath(index.absolutePath()));
}
- ui->treeView->setModel(proxy);
- ui->treeView->setRootIndex(proxy->mapFromSource(model->index(instance->gameRoot())));
- ui->treeView->sortByColumn(0, Qt::AscendingOrder);
+ ui->files->setModel(proxy);
+ ui->files->setRootIndex(proxy->mapFromSource(model->index(instance->gameRoot())));
+ ui->files->sortByColumn(0, Qt::AscendingOrder);
model->setFilter(filter);
model->setRootPath(instance->gameRoot());
- QHeaderView* headerView = ui->treeView->header();
+ QHeaderView* headerView = ui->files->header();
headerView->setSectionResizeMode(QHeaderView::ResizeToContents);
headerView->setSectionResizeMode(0, QHeaderView::Stretch);
}
@@ -100,26 +105,41 @@ ExportPackDialog::~ExportPackDialog()
void ExportPackDialog::done(int result)
{
+ auto settings = instance->settings();
+ settings->set("ExportName", ui->name->text());
+ settings->set("ExportVersion", ui->version->text());
+ settings->set(m_provider == ModPlatform::ResourceProvider::FLAME ? "ExportAuthor" : "ExportSummary", ui->summary->text());
+ settings->set("ExportOptionalFiles", ui->optionalFiles->isChecked());
+
if (result == Accepted) {
- const QString filename = FS::RemoveInvalidFilenameChars(ui->name->text());
+ const QString name = ui->name->text().isEmpty() ? instance->name() : ui->name->text();
+ const QString filename = FS::RemoveInvalidFilenameChars(name);
+
QString output;
- if (m_provider == ModPlatform::ResourceProvider::MODRINTH)
- output = QFileDialog::getSaveFileName(this, tr("Export %1").arg(ui->name->text()),
- FS::PathCombine(QDir::homePath(), filename + ".mrpack"), "Modrinth pack (*.mrpack *.zip)",
- nullptr);
- else
- output = QFileDialog::getSaveFileName(this, tr("Export %1").arg(ui->name->text()),
- FS::PathCombine(QDir::homePath(), filename + ".zip"), "CurseForge pack (*.zip)", nullptr);
-
- if (output.isEmpty())
- return;
+ if (m_provider == ModPlatform::ResourceProvider::MODRINTH) {
+ output = QFileDialog::getSaveFileName(this, tr("Export %1").arg(name), FS::PathCombine(QDir::homePath(), filename + ".mrpack"),
+ "Modrinth pack (*.mrpack *.zip)", nullptr);
+ if (output.isEmpty())
+ return;
+ if (!(output.endsWith(".zip") || output.endsWith(".mrpack")))
+ output.append(".mrpack");
+ } else {
+ output = QFileDialog::getSaveFileName(this, tr("Export %1").arg(name), FS::PathCombine(QDir::homePath(), filename + ".zip"),
+ "CurseForge pack (*.zip)", nullptr);
+ if (output.isEmpty())
+ return;
+ if (!output.endsWith(".zip"))
+ output.append(".zip");
+ }
+
Task* task;
- if (m_provider == ModPlatform::ResourceProvider::MODRINTH)
- task = new ModrinthPackExportTask(ui->name->text(), ui->version->text(), ui->summary->text(), instance, output,
- std::bind(&FileIgnoreProxy::filterFile, proxy, std::placeholders::_1));
- else
- task = new FlamePackExportTask(ui->name->text(), ui->version->text(), ui->summary->text(), instance, output,
+ if (m_provider == ModPlatform::ResourceProvider::MODRINTH) {
+ task = new ModrinthPackExportTask(name, ui->version->text(), ui->summary->text(), ui->optionalFiles->isChecked(), instance,
+ output, std::bind(&FileIgnoreProxy::filterFile, proxy, std::placeholders::_1));
+ } else {
+ task = new FlamePackExportTask(name, ui->version->text(), ui->summary->text(), ui->optionalFiles->isChecked(), instance, output,
std::bind(&FileIgnoreProxy::filterFile, proxy, std::placeholders::_1));
+ }
connect(task, &Task::failed,
[this](const QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show(); });
@@ -140,7 +160,6 @@ void ExportPackDialog::done(int result)
void ExportPackDialog::validate()
{
- const bool invalid =
- ui->name->text().isEmpty() || ((m_provider == ModPlatform::ResourceProvider::MODRINTH) && ui->version->text().isEmpty());
- ui->buttonBox->button(QDialogButtonBox::Ok)->setDisabled(invalid);
+ ui->buttonBox->button(QDialogButtonBox::Ok)
+ ->setDisabled(m_provider == ModPlatform::ResourceProvider::MODRINTH && ui->version->text().isEmpty());
}
diff --git a/launcher/ui/dialogs/ExportPackDialog.ui b/launcher/ui/dialogs/ExportPackDialog.ui
index 3976e28f..09dea72a 100644
--- a/launcher/ui/dialogs/ExportPackDialog.ui
+++ b/launcher/ui/dialogs/ExportPackDialog.ui
@@ -7,12 +7,9 @@
<x>0</x>
<y>0</y>
<width>650</width>
- <height>413</height>
+ <height>510</height>
</rect>
</property>
- <property name="windowTitle">
- <string>Export Pack</string>
- </property>
<property name="sizeGripEnabled">
<bool>true</bool>
</property>
@@ -20,13 +17,16 @@
<item>
<widget class="QGroupBox" name="information">
<property name="title">
- <string>Information</string>
+ <string>&amp;Description</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="0">
<widget class="QLabel" name="summaryLabel">
<property name="text">
- <string>Summary</string>
+ <string>&amp;Summary</string>
+ </property>
+ <property name="buddy">
+ <cstring>summary</cstring>
</property>
</widget>
</item>
@@ -36,14 +36,20 @@
<item row="0" column="0">
<widget class="QLabel" name="nameLabel">
<property name="text">
- <string>Name</string>
+ <string>&amp;Name</string>
+ </property>
+ <property name="buddy">
+ <cstring>name</cstring>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="versionLabel">
<property name="text">
- <string>Version</string>
+ <string>&amp;Version</string>
+ </property>
+ <property name="buddy">
+ <cstring>version</cstring>
</property>
</widget>
</item>
@@ -57,31 +63,52 @@
</property>
</widget>
</item>
-
</layout>
</widget>
</item>
<item>
- <widget class="QLabel" name="filesLabel">
- <property name="text">
- <string>Files</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QTreeView" name="treeView">
- <property name="alternatingRowColors">
- <bool>true</bool>
- </property>
- <property name="selectionMode">
- <enum>QAbstractItemView::ExtendedSelection</enum>
- </property>
- <property name="sortingEnabled">
- <bool>true</bool>
+ <widget class="QGroupBox" name="options">
+ <property name="title">
+ <string>&amp;Options</string>
</property>
- <attribute name="headerStretchLastSection">
- <bool>false</bool>
- </attribute>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QLabel" name="filesLabel">
+ <property name="text">
+ <string>&amp;Files</string>
+ </property>
+ <property name="buddy">
+ <cstring>files</cstring>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QTreeView" name="files">
+ <property name="alternatingRowColors">
+ <bool>true</bool>
+ </property>
+ <property name="selectionMode">
+ <enum>QAbstractItemView::ExtendedSelection</enum>
+ </property>
+ <property name="sortingEnabled">
+ <bool>true</bool>
+ </property>
+ <attribute name="headerStretchLastSection">
+ <bool>false</bool>
+ </attribute>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="optionalFiles">
+ <property name="text">
+ <string>&amp;Mark disabled files as optional</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
</widget>
</item>
<item>
@@ -97,7 +124,8 @@
<tabstop>name</tabstop>
<tabstop>version</tabstop>
<tabstop>summary</tabstop>
- <tabstop>treeView</tabstop>
+ <tabstop>files</tabstop>
+ <tabstop>optionalFiles</tabstop>
</tabstops>
<resources/>
<connections>
diff --git a/launcher/ui/dialogs/InstallLoaderDialog.cpp b/launcher/ui/dialogs/InstallLoaderDialog.cpp
new file mode 100644
index 00000000..541119d1
--- /dev/null
+++ b/launcher/ui/dialogs/InstallLoaderDialog.cpp
@@ -0,0 +1,166 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include "InstallLoaderDialog.h"
+
+#include <QDialogButtonBox>
+#include <QPushButton>
+#include <QVBoxLayout>
+#include "Application.h"
+#include "BuildConfig.h"
+#include "DesktopServices.h"
+#include "meta/Index.h"
+#include "minecraft/MinecraftInstance.h"
+#include "minecraft/PackProfile.h"
+#include "ui/widgets/PageContainer.h"
+#include "ui/widgets/VersionSelectWidget.h"
+
+class InstallLoaderPage : public VersionSelectWidget, public BasePage {
+ public:
+ InstallLoaderPage(const QString& id,
+ const QString& iconName,
+ const QString& name,
+ const Version& oldestVersion,
+ const std::shared_ptr<PackProfile> profile)
+ : VersionSelectWidget(nullptr), uid(id), iconName(iconName), name(name)
+ {
+ const QString minecraftVersion = profile->getComponentVersion("net.minecraft");
+ setEmptyString(tr("No versions are currently available for Minecraft %1").arg(minecraftVersion));
+ setExactIfPresentFilter(BaseVersionList::ParentVersionRole, minecraftVersion);
+
+ if (oldestVersion != Version() && Version(minecraftVersion) < oldestVersion)
+ setExactFilter(BaseVersionList::ParentVersionRole, "AAA");
+
+ if (const QString currentVersion = profile->getComponentVersion(id); !currentVersion.isNull())
+ setCurrentVersion(currentVersion);
+ }
+
+ QString id() const override { return uid; }
+ QString displayName() const override { return name; }
+ QIcon icon() const override { return APPLICATION->getThemedIcon(iconName); }
+
+ void openedImpl() override
+ {
+ if (loaded)
+ return;
+
+ const auto versions = APPLICATION->metadataIndex()->get(uid);
+ if (!versions)
+ return;
+
+ initialize(versions.get());
+ loaded = true;
+ }
+
+ void setParentContainer(BasePageContainer* container) override
+ {
+ auto dialog = dynamic_cast<QDialog*>(dynamic_cast<PageContainer*>(container)->parent());
+ connect(view(), &QAbstractItemView::doubleClicked, dialog, &QDialog::accept);
+ }
+
+ private:
+ const QString uid;
+ const QString iconName;
+ const QString name;
+ bool loaded = false;
+};
+
+static InstallLoaderPage* pageCast(BasePage* page)
+{
+ auto result = dynamic_cast<InstallLoaderPage*>(page);
+ Q_ASSERT(result != nullptr);
+ return result;
+}
+
+InstallLoaderDialog::InstallLoaderDialog(std::shared_ptr<PackProfile> profile, const QString& uid, QWidget* parent)
+ : QDialog(parent), profile(std::move(profile)), container(new PageContainer(this, QString(), this)), buttons(new QDialogButtonBox(this))
+{
+ auto layout = new QVBoxLayout(this);
+
+ container->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
+ layout->addWidget(container);
+
+ auto buttonLayout = new QHBoxLayout(this);
+
+ auto refreshButton = new QPushButton(tr("&Refresh"), this);
+ connect(refreshButton, &QPushButton::clicked, this, [this] { pageCast(container->selectedPage())->loadList(); });
+ buttonLayout->addWidget(refreshButton);
+
+ buttons->setOrientation(Qt::Horizontal);
+ buttons->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
+ connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
+ connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
+ buttonLayout->addWidget(buttons);
+
+ layout->addLayout(buttonLayout);
+
+ setWindowTitle(dialogTitle());
+ setWindowModality(Qt::WindowModal);
+ resize(520, 347);
+
+ for (BasePage* page : container->getPages()) {
+ if (page->id() == uid)
+ container->selectPage(page->id());
+
+ connect(pageCast(page), &VersionSelectWidget::selectedVersionChanged, this, [this, page] {
+ if (page->id() == container->selectedPage()->id())
+ validate(container->selectedPage());
+ });
+ }
+ connect(container, &PageContainer::selectedPageChanged, this, [this](BasePage* previous, BasePage* current) { validate(current); });
+ pageCast(container->selectedPage())->selectSearch();
+ validate(container->selectedPage());
+}
+
+QList<BasePage*> InstallLoaderDialog::getPages()
+{
+ return { // NeoForge
+ new InstallLoaderPage("net.neoforged", "neoforged", tr("NeoForge"), {}, profile),
+ // Forge
+ new InstallLoaderPage("net.minecraftforge", "forge", tr("Forge"), {}, profile),
+ // Fabric
+ new InstallLoaderPage("net.fabricmc.fabric-loader", "fabricmc", tr("Fabric"), Version("1.14"), profile),
+ // Quilt
+ new InstallLoaderPage("org.quiltmc.quilt-loader", "quiltmc", tr("Quilt"), Version("1.14"), profile),
+ // LiteLoader
+ new InstallLoaderPage("com.mumfrey.liteloader", "liteloader", tr("LiteLoader"), {}, profile)
+ };
+}
+
+QString InstallLoaderDialog::dialogTitle()
+{
+ return tr("Install Loader");
+}
+
+void InstallLoaderDialog::validate(BasePage* page)
+{
+ buttons->button(QDialogButtonBox::Ok)->setEnabled(pageCast(page)->selectedVersion() != nullptr);
+}
+
+void InstallLoaderDialog::done(int result)
+{
+ if (result == Accepted) {
+ auto* page = pageCast(container->selectedPage());
+ if (page->selectedVersion()) {
+ profile->setComponentVersion(page->id(), page->selectedVersion()->descriptor());
+ profile->resolve(Net::Mode::Online);
+ }
+ }
+
+ QDialog::done(result);
+}
diff --git a/launcher/ui/dialogs/InstallLoaderDialog.h b/launcher/ui/dialogs/InstallLoaderDialog.h
new file mode 100644
index 00000000..86cb3bdd
--- /dev/null
+++ b/launcher/ui/dialogs/InstallLoaderDialog.h
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <QDialog>
+#include "ui/pages/BasePageProvider.h"
+
+class MinecraftInstance;
+class PageContainer;
+class PackProfile;
+class QDialogButtonBox;
+
+class InstallLoaderDialog final : public QDialog, protected BasePageProvider {
+ Q_OBJECT
+
+ public:
+ explicit InstallLoaderDialog(std::shared_ptr<PackProfile> instance, const QString& uid = QString(), QWidget* parent = nullptr);
+
+ QList<BasePage*> getPages() override;
+ QString dialogTitle() override;
+
+ void validate(BasePage* page);
+ void done(int result) override;
+
+ private:
+ std::shared_ptr<PackProfile> profile;
+ PageContainer* container;
+ QDialogButtonBox* buttons;
+};
diff --git a/launcher/ui/dialogs/ModUpdateDialog.cpp b/launcher/ui/dialogs/ModUpdateDialog.cpp
index 79622ff7..0e11ff1a 100644
--- a/launcher/ui/dialogs/ModUpdateDialog.cpp
+++ b/launcher/ui/dialogs/ModUpdateDialog.cpp
@@ -5,8 +5,6 @@
#include "ScrollMessageBox.h"
#include "ui_ReviewMessageBox.h"
-#include "FileSystem.h"
-#include "Json.h"
#include "Markdown.h"
#include "tasks/ConcurrentTask.h"
@@ -30,9 +28,9 @@ static std::list<Version> mcVersions(BaseInstance* inst)
return { static_cast<MinecraftInstance*>(inst)->getPackProfile()->getComponent("net.minecraft")->getVersion() };
}
-static std::optional<ResourceAPI::ModLoaderTypes> mcLoaders(BaseInstance* inst)
+static std::optional<ModPlatform::ModLoaderTypes> mcLoaders(BaseInstance* inst)
{
- return { static_cast<MinecraftInstance*>(inst)->getPackProfile()->getModLoaders() };
+ return { static_cast<MinecraftInstance*>(inst)->getPackProfile()->getSupportedModLoaders() };
}
ModUpdateDialog::ModUpdateDialog(QWidget* parent,
@@ -238,6 +236,10 @@ auto ModUpdateDialog::ensureMetadata() -> bool
if (skip_rest)
continue;
+ if (candidate->type() == ResourceType::FOLDER) {
+ continue;
+ }
+
if (confirm_rest) {
addToTmp(candidate, provider_rest);
should_try_others.insert(candidate->internal_id(), try_others_rest);
diff --git a/launcher/ui/dialogs/NewInstanceDialog.cpp b/launcher/ui/dialogs/NewInstanceDialog.cpp
index 6e5a41ef..9613c6b0 100644
--- a/launcher/ui/dialogs/NewInstanceDialog.cpp
+++ b/launcher/ui/dialogs/NewInstanceDialog.cpp
@@ -62,8 +62,10 @@
#include "ui/pages/modplatform/modrinth/ModrinthPage.h"
#include "ui/pages/modplatform/technic/TechnicPage.h"
#include "ui/widgets/PageContainer.h"
-
-NewInstanceDialog::NewInstanceDialog(const QString& initialGroup, const QString& url, QWidget* parent)
+NewInstanceDialog::NewInstanceDialog(const QString& initialGroup,
+ const QString& url,
+ const QMap<QString, QString>& extra_info,
+ QWidget* parent)
: QDialog(parent), ui(new Ui::NewInstanceDialog)
{
ui->setupUi(this);
@@ -125,6 +127,7 @@ NewInstanceDialog::NewInstanceDialog(const QString& initialGroup, const QString&
QUrl actualUrl(url);
m_container->selectPage("import");
importPage->setUrl(url);
+ importPage->setExtraInfo(extra_info);
}
updateDialogState();
@@ -290,7 +293,7 @@ void NewInstanceDialog::on_iconButton_clicked()
}
}
-void NewInstanceDialog::on_instNameTextBox_textChanged(const QString& arg1)
+void NewInstanceDialog::on_instNameTextBox_textChanged([[maybe_unused]] const QString& arg1)
{
updateDialogState();
}
@@ -299,7 +302,7 @@ void NewInstanceDialog::importIconNow()
{
if (importIcon) {
APPLICATION->icons()->installIcon(importIconPath, importIconName);
- InstIconKey = importIconName;
+ InstIconKey = importIconName.mid(0, importIconName.lastIndexOf('.'));
importIcon = false;
}
APPLICATION->settings()->set("NewInstanceGeometry", saveGeometry().toBase64());
diff --git a/launcher/ui/dialogs/NewInstanceDialog.h b/launcher/ui/dialogs/NewInstanceDialog.h
index b348649f..92357956 100644
--- a/launcher/ui/dialogs/NewInstanceDialog.h
+++ b/launcher/ui/dialogs/NewInstanceDialog.h
@@ -53,7 +53,10 @@ class NewInstanceDialog : public QDialog, public BasePageProvider {
Q_OBJECT
public:
- explicit NewInstanceDialog(const QString& initialGroup, const QString& url = QString(), QWidget* parent = 0);
+ explicit NewInstanceDialog(const QString& initialGroup,
+ const QString& url = QString(),
+ const QMap<QString, QString>& extra_info = {},
+ QWidget* parent = 0);
~NewInstanceDialog();
void updateDialogState();
diff --git a/launcher/ui/dialogs/ProfileSetupDialog.cpp b/launcher/ui/dialogs/ProfileSetupDialog.cpp
index d7758d6d..4b0c5b76 100644
--- a/launcher/ui/dialogs/ProfileSetupDialog.cpp
+++ b/launcher/ui/dialogs/ProfileSetupDialog.cpp
@@ -163,13 +163,15 @@ void ProfileSetupDialog::checkName(const QString& name)
requestor->get(request);
}
-void ProfileSetupDialog::checkFinished(QNetworkReply::NetworkError error, QByteArray data, QList<QNetworkReply::RawHeaderPair> headers)
+void ProfileSetupDialog::checkFinished(QNetworkReply::NetworkError error,
+ QByteArray profileData,
+ [[maybe_unused]] QList<QNetworkReply::RawHeaderPair> headers)
{
auto requestor = qobject_cast<AuthRequest*>(QObject::sender());
requestor->deleteLater();
if (error == QNetworkReply::NoError) {
- auto doc = QJsonDocument::fromJson(data);
+ auto doc = QJsonDocument::fromJson(profileData);
auto root = doc.object();
auto statusValue = root.value("status").toString("INVALID");
if (statusValue == "AVAILABLE") {
@@ -202,11 +204,11 @@ void ProfileSetupDialog::setupProfile(const QString& profileName)
request.setRawHeader("Authorization", QString("Bearer %1").arg(token).toUtf8());
QString payloadTemplate("{\"profileName\":\"%1\"}");
- auto data = payloadTemplate.arg(profileName).toUtf8();
+ auto profileData = payloadTemplate.arg(profileName).toUtf8();
AuthRequest* requestor = new AuthRequest(this);
connect(requestor, &AuthRequest::finished, this, &ProfileSetupDialog::setupProfileFinished);
- requestor->post(request, data);
+ requestor->post(request, profileData);
isWorking = true;
auto button = ui->buttonBox->button(QDialogButtonBox::Cancel);
@@ -243,8 +245,8 @@ struct MojangError {
} // namespace
void ProfileSetupDialog::setupProfileFinished(QNetworkReply::NetworkError error,
- QByteArray data,
- QList<QNetworkReply::RawHeaderPair> headers)
+ QByteArray errorData,
+ [[maybe_unused]] QList<QNetworkReply::RawHeaderPair> headers)
{
auto requestor = qobject_cast<AuthRequest*>(QObject::sender());
requestor->deleteLater();
@@ -257,7 +259,7 @@ void ProfileSetupDialog::setupProfileFinished(QNetworkReply::NetworkError error,
*/
accept();
} else {
- auto parsedError = MojangError::fromJSON(data);
+ auto parsedError = MojangError::fromJSON(errorData);
ui->errorLabel->setVisible(true);
ui->errorLabel->setText(tr("The server returned the following error:") + "\n\n" + parsedError.errorMessage);
qDebug() << parsedError.rawError;
diff --git a/launcher/ui/dialogs/ProgressDialog.cpp b/launcher/ui/dialogs/ProgressDialog.cpp
index ba22e334..0ca3a1bd 100644
--- a/launcher/ui/dialogs/ProgressDialog.cpp
+++ b/launcher/ui/dialogs/ProgressDialog.cpp
@@ -85,7 +85,7 @@ void ProgressDialog::on_skipButton_clicked(bool checked)
{
Q_UNUSED(checked);
if (ui->skipButton->isEnabled()) // prevent other triggers from aborting
- task->abort();
+ m_task->abort();
}
ProgressDialog::~ProgressDialog()
@@ -127,7 +127,7 @@ void ProgressDialog::updateSize(bool recenterParent)
int ProgressDialog::execWithTask(Task* task)
{
- this->task = task;
+ this->m_task = task;
if (!task) {
qDebug() << "Programmer error: Progress dialog created with null task.";
@@ -179,8 +179,8 @@ int ProgressDialog::execWithTask(std::unique_ptr<Task>& task)
bool ProgressDialog::handleImmediateResult(QDialog::DialogCode& result)
{
- if (task->isFinished()) {
- if (task->wasSuccessful()) {
+ if (m_task->isFinished()) {
+ if (m_task->wasSuccessful()) {
result = QDialog::Accepted;
} else {
result = QDialog::Rejected;
@@ -192,12 +192,12 @@ bool ProgressDialog::handleImmediateResult(QDialog::DialogCode& result)
Task* ProgressDialog::getTask()
{
- return task;
+ return m_task;
}
void ProgressDialog::onTaskStarted() {}
-void ProgressDialog::onTaskFailed(QString failure)
+void ProgressDialog::onTaskFailed([[maybe_unused]] QString failure)
{
reject();
hide();
@@ -209,11 +209,11 @@ void ProgressDialog::onTaskSucceeded()
hide();
}
-void ProgressDialog::changeStatus(const QString& status)
+void ProgressDialog::changeStatus([[maybe_unused]] const QString& status)
{
- ui->globalStatusLabel->setText(task->getStatus());
+ ui->globalStatusLabel->setText(m_task->getStatus());
ui->globalStatusLabel->adjustSize();
- ui->globalStatusDetailsLabel->setText(task->getDetails());
+ ui->globalStatusDetailsLabel->setText(m_task->getDetails());
ui->globalStatusDetailsLabel->adjustSize();
updateSize();
@@ -279,7 +279,7 @@ void ProgressDialog::keyPressEvent(QKeyEvent* e)
void ProgressDialog::closeEvent(QCloseEvent* e)
{
- if (task && task->isRunning()) {
+ if (m_task && m_task->isRunning()) {
e->ignore();
} else {
QDialog::closeEvent(e);
diff --git a/launcher/ui/dialogs/ProgressDialog.h b/launcher/ui/dialogs/ProgressDialog.h
index 82067271..15eadf4e 100644
--- a/launcher/ui/dialogs/ProgressDialog.h
+++ b/launcher/ui/dialogs/ProgressDialog.h
@@ -92,7 +92,7 @@ class ProgressDialog : public QDialog {
private:
Ui::ProgressDialog* ui;
- Task* task;
+ Task* m_task;
bool m_is_multi_step = false;
QHash<QUuid, SubTaskProgressBar*> taskProgress;
diff --git a/launcher/ui/dialogs/ResourceDownloadDialog.cpp b/launcher/ui/dialogs/ResourceDownloadDialog.cpp
index 16bdc9b0..cfd292f4 100644
--- a/launcher/ui/dialogs/ResourceDownloadDialog.cpp
+++ b/launcher/ui/dialogs/ResourceDownloadDialog.cpp
@@ -2,7 +2,7 @@
/*
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
- * Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
+ * Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -210,15 +210,17 @@ bool ResourceDownloadDialog::selectPage(QString pageId)
return m_container->selectPage(pageId);
}
-ResourcePage* ResourceDownloadDialog::getSelectedPage()
+ResourcePage* ResourceDownloadDialog::selectedPage()
{
- return m_selectedPage;
+ ResourcePage* result = dynamic_cast<ResourcePage*>(m_container->selectedPage());
+ Q_ASSERT(result != nullptr);
+ return result;
}
void ResourceDownloadDialog::addResource(ModPlatform::IndexedPack::Ptr pack, ModPlatform::IndexedVersion& ver)
{
removeResource(pack->name);
- m_selectedPage->addResourceToPage(pack, ver, getBaseModel());
+ selectedPage()->addResourceToPage(pack, ver, getBaseModel());
setButtonStatus();
}
@@ -258,14 +260,8 @@ void ResourceDownloadDialog::selectedPageChanged(BasePage* previous, BasePage* s
return;
}
- m_selectedPage = dynamic_cast<ResourcePage*>(selected);
- if (!m_selectedPage) {
- qCritical() << "Page '" << selected->displayName() << "' in ResourceDownloadDialog is not a ResourcePage!";
- return;
- }
-
// Same effect as having a global search bar
- m_selectedPage->setSearchTerm(prev_page->getSearchTerm());
+ selectedPage()->setSearchTerm(prev_page->getSearchTerm());
}
ModDownloadDialog::ModDownloadDialog(QWidget* parent, const std::shared_ptr<ModFolderModel>& mods, BaseInstance* instance)
@@ -284,15 +280,13 @@ QList<BasePage*> ModDownloadDialog::getPages()
{
QList<BasePage*> pages;
- auto loaders = static_cast<MinecraftInstance*>(m_instance)->getPackProfile()->getModLoaders().value();
+ auto loaders = static_cast<MinecraftInstance*>(m_instance)->getPackProfile()->getSupportedModLoaders().value();
if (ModrinthAPI::validateModLoaders(loaders))
pages.append(ModrinthModPage::create(this, *m_instance));
if (APPLICATION->capabilities() & Application::SupportsFlame && FlameAPI::validateModLoaders(loaders))
pages.append(FlameModPage::create(this, *m_instance));
- m_selectedPage = dynamic_cast<ModPage*>(pages[0]);
-
return pages;
}
@@ -307,7 +301,7 @@ GetModDependenciesTask::Ptr ModDownloadDialog::getModDependenciesTask()
return makeShared<GetModDependenciesTask>(this, m_instance, model, selectedVers);
}
return nullptr;
-};
+}
ResourcePackDownloadDialog::ResourcePackDownloadDialog(QWidget* parent,
const std::shared_ptr<ResourcePackFolderModel>& resource_packs,
@@ -331,8 +325,6 @@ QList<BasePage*> ResourcePackDownloadDialog::getPages()
if (APPLICATION->capabilities() & Application::SupportsFlame)
pages.append(FlameResourcePackPage::create(this, *m_instance));
- m_selectedPage = dynamic_cast<ResourcePackResourcePage*>(pages[0]);
-
return pages;
}
@@ -358,8 +350,6 @@ QList<BasePage*> TexturePackDownloadDialog::getPages()
if (APPLICATION->capabilities() & Application::SupportsFlame)
pages.append(FlameTexturePackPage::create(this, *m_instance));
- m_selectedPage = dynamic_cast<TexturePackResourcePage*>(pages[0]);
-
return pages;
}
@@ -380,11 +370,9 @@ ShaderPackDownloadDialog::ShaderPackDownloadDialog(QWidget* parent,
QList<BasePage*> ShaderPackDownloadDialog::getPages()
{
QList<BasePage*> pages;
-
pages.append(ModrinthShaderPackPage::create(this, *m_instance));
-
- m_selectedPage = dynamic_cast<ShaderPackResourcePage*>(pages[0]);
-
+ if (APPLICATION->capabilities() & Application::SupportsFlame)
+ pages.append(FlameShaderPackPage::create(this, *m_instance));
return pages;
}
diff --git a/launcher/ui/dialogs/ResourceDownloadDialog.h b/launcher/ui/dialogs/ResourceDownloadDialog.h
index f65daaa3..e9d2cfbe 100644
--- a/launcher/ui/dialogs/ResourceDownloadDialog.h
+++ b/launcher/ui/dialogs/ResourceDownloadDialog.h
@@ -2,7 +2,7 @@
/*
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
- * Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
+ * Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -61,7 +61,7 @@ class ResourceDownloadDialog : public QDialog, public BasePageProvider {
QString dialogTitle() override { return tr("Download %1").arg(resourcesString()); };
bool selectPage(QString pageId);
- ResourcePage* getSelectedPage();
+ ResourcePage* selectedPage();
void addResource(ModPlatform::IndexedPack::Ptr, ModPlatform::IndexedVersion&);
void removeResource(const QString&);
@@ -88,7 +88,6 @@ class ResourceDownloadDialog : public QDialog, public BasePageProvider {
const std::shared_ptr<ResourceFolderModel> m_base_model;
PageContainer* m_container = nullptr;
- ResourcePage* m_selectedPage = nullptr;
QDialogButtonBox m_buttons;
QVBoxLayout m_vertical_layout;
diff --git a/launcher/ui/dialogs/ReviewMessageBox.cpp b/launcher/ui/dialogs/ReviewMessageBox.cpp
index d1b7bd15..aa668f8c 100644
--- a/launcher/ui/dialogs/ReviewMessageBox.cpp
+++ b/launcher/ui/dialogs/ReviewMessageBox.cpp
@@ -5,7 +5,7 @@
#include <QPushButton>
-ReviewMessageBox::ReviewMessageBox(QWidget* parent, QString const& title, QString const& icon)
+ReviewMessageBox::ReviewMessageBox(QWidget* parent, [[maybe_unused]] QString const& title, [[maybe_unused]] QString const& icon)
: QDialog(parent), ui(new Ui::ReviewMessageBox)
{
ui->setupUi(this);
diff --git a/launcher/ui/dialogs/SkinUploadDialog.cpp b/launcher/ui/dialogs/SkinUploadDialog.cpp
index 8f0c8fa4..5b3ebfa2 100644
--- a/launcher/ui/dialogs/SkinUploadDialog.cpp
+++ b/launcher/ui/dialogs/SkinUploadDialog.cpp
@@ -133,15 +133,15 @@ SkinUploadDialog::SkinUploadDialog(MinecraftAccountPtr acct, QWidget* parent) :
ui->setupUi(this);
// FIXME: add a model for this, download/refresh the capes on demand
- auto& data = *acct->accountData();
+ auto& accountData = *acct->accountData();
int index = 0;
ui->capeCombo->addItem(tr("No Cape"), QVariant());
- auto currentCape = data.minecraftProfile.currentCape;
+ auto currentCape = accountData.minecraftProfile.currentCape;
if (currentCape.isEmpty()) {
ui->capeCombo->setCurrentIndex(index);
}
- for (auto& cape : data.minecraftProfile.capes) {
+ for (auto& cape : accountData.minecraftProfile.capes) {
index++;
if (cape.data.size()) {
QPixmap capeImage;
diff --git a/launcher/ui/dialogs/SkinUploadDialog.ui b/launcher/ui/dialogs/SkinUploadDialog.ui
index c7b16645..c6df92df 100644
--- a/launcher/ui/dialogs/SkinUploadDialog.ui
+++ b/launcher/ui/dialogs/SkinUploadDialog.ui
@@ -35,14 +35,8 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
- <property name="maximumSize">
- <size>
- <width>28</width>
- <height>16777215</height>
- </size>
- </property>
<property name="text">
- <string notr="true">...</string>
+ <string>Browse</string>
</property>
</widget>
</item>
diff --git a/launcher/ui/dialogs/VersionSelectDialog.cpp b/launcher/ui/dialogs/VersionSelectDialog.cpp
index 61254c46..c61d1057 100644
--- a/launcher/ui/dialogs/VersionSelectDialog.cpp
+++ b/launcher/ui/dialogs/VersionSelectDialog.cpp
@@ -54,7 +54,7 @@ VersionSelectDialog::VersionSelectDialog(BaseVersionList* vlist, QString title,
m_verticalLayout = new QVBoxLayout(this);
m_verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
- m_versionWidget = new VersionSelectWidget(true, parent);
+ m_versionWidget = new VersionSelectWidget(parent);
m_verticalLayout->addWidget(m_versionWidget);
m_horizontalLayout = new QHBoxLayout();
@@ -74,8 +74,9 @@ VersionSelectDialog::VersionSelectDialog(BaseVersionList* vlist, QString title,
retranslate();
- QObject::connect(m_buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
- QObject::connect(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+ connect(m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
+ connect(m_versionWidget->view(), &QAbstractItemView::doubleClicked, this, &QDialog::accept);
+ connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
QMetaObject::connectSlotsByName(this);
setWindowModality(Qt::WindowModal);
@@ -121,6 +122,7 @@ int VersionSelectDialog::exec()
{
QDialog::open();
m_versionWidget->initialize(m_vlist);
+ m_versionWidget->selectSearch();
if (resizeOnColumn != -1) {
m_versionWidget->setResizeOn(resizeOnColumn);
}
@@ -147,6 +149,11 @@ void VersionSelectDialog::setExactFilter(BaseVersionList::ModelRoles role, QStri
m_versionWidget->setExactFilter(role, filter);
}
+void VersionSelectDialog::setExactIfPresentFilter(BaseVersionList::ModelRoles role, QString filter)
+{
+ m_versionWidget->setExactIfPresentFilter(role, filter);
+}
+
void VersionSelectDialog::setFuzzyFilter(BaseVersionList::ModelRoles role, QString filter)
{
m_versionWidget->setFuzzyFilter(role, filter);
diff --git a/launcher/ui/dialogs/VersionSelectDialog.h b/launcher/ui/dialogs/VersionSelectDialog.h
index 701020fa..0ccd45e7 100644
--- a/launcher/ui/dialogs/VersionSelectDialog.h
+++ b/launcher/ui/dialogs/VersionSelectDialog.h
@@ -46,6 +46,7 @@ class VersionSelectDialog : public QDialog {
void setCurrentVersion(const QString& version);
void setFuzzyFilter(BaseVersionList::ModelRoles role, QString filter);
void setExactFilter(BaseVersionList::ModelRoles role, QString filter);
+ void setExactIfPresentFilter(BaseVersionList::ModelRoles role, QString filter);
void setEmptyString(QString emptyString);
void setEmptyErrorString(QString emptyErrorString);
void setResizeOn(int column);
diff --git a/launcher/ui/instanceview/InstanceDelegate.cpp b/launcher/ui/instanceview/InstanceDelegate.cpp
index 915b41d8..d947163b 100644
--- a/launcher/ui/instanceview/InstanceDelegate.cpp
+++ b/launcher/ui/instanceview/InstanceDelegate.cpp
@@ -367,7 +367,9 @@ class NoReturnTextEdit : public QTextEdit {
void editingDone();
};
-void ListViewDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const
+void ListViewDelegate::updateEditorGeometry(QWidget* editor,
+ const QStyleOptionViewItem& option,
+ [[maybe_unused]] const QModelIndex& index) const
{
const int iconSize = 48;
QRect textRect = option.rect;
@@ -379,17 +381,17 @@ void ListViewDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionV
void ListViewDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
{
auto text = index.data(Qt::EditRole).toString();
- QTextEdit* realeditor = qobject_cast<NoReturnTextEdit*>(editor);
- realeditor->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
- realeditor->append(text);
- realeditor->selectAll();
- realeditor->document()->clearUndoRedoStacks();
+ QTextEdit* realEditor = qobject_cast<NoReturnTextEdit*>(editor);
+ realEditor->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
+ realEditor->append(text);
+ realEditor->selectAll();
+ realEditor->document()->clearUndoRedoStacks();
}
void ListViewDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
{
- QTextEdit* realeditor = qobject_cast<NoReturnTextEdit*>(editor);
- QString text = realeditor->toPlainText();
+ QTextEdit* realEditor = qobject_cast<NoReturnTextEdit*>(editor);
+ QString text = realEditor->toPlainText();
text.replace(QChar('\n'), QChar(' '));
text = text.trimmed();
// Prevent instance names longer than 128 chars
@@ -399,7 +401,9 @@ void ListViewDelegate::setModelData(QWidget* editor, QAbstractItemModel* model,
}
}
-QWidget* ListViewDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
+QWidget* ListViewDelegate::createEditor(QWidget* parent,
+ [[maybe_unused]] const QStyleOptionViewItem& option,
+ [[maybe_unused]] const QModelIndex& index) const
{
auto editor = new NoReturnTextEdit(parent);
connect(editor, &NoReturnTextEdit::editingDone, this, &ListViewDelegate::editingDone);
diff --git a/launcher/ui/instanceview/InstanceView.cpp b/launcher/ui/instanceview/InstanceView.cpp
index a9442546..690dc917 100644
--- a/launcher/ui/instanceview/InstanceView.cpp
+++ b/launcher/ui/instanceview/InstanceView.cpp
@@ -47,8 +47,8 @@
#include <QScrollBar>
#include <QtMath>
-#include <QDebug>
#include "VisualGroup.h"
+#include "ui/themes/ThemeManager.h"
#include <Application.h>
#include <InstanceList.h>
@@ -86,16 +86,18 @@ void InstanceView::setModel(QAbstractItemModel* model)
connect(model, &QAbstractItemModel::rowsRemoved, this, &InstanceView::rowsRemoved);
}
-void InstanceView::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles)
+void InstanceView::dataChanged([[maybe_unused]] const QModelIndex& topLeft,
+ [[maybe_unused]] const QModelIndex& bottomRight,
+ [[maybe_unused]] const QVector<int>& roles)
{
scheduleDelayedItemsLayout();
}
-void InstanceView::rowsInserted(const QModelIndex& parent, int start, int end)
+void InstanceView::rowsInserted([[maybe_unused]] const QModelIndex& parent, [[maybe_unused]] int start, [[maybe_unused]] int end)
{
scheduleDelayedItemsLayout();
}
-void InstanceView::rowsAboutToBeRemoved(const QModelIndex& parent, int start, int end)
+void InstanceView::rowsAboutToBeRemoved([[maybe_unused]] const QModelIndex& parent, [[maybe_unused]] int start, [[maybe_unused]] int end)
{
scheduleDelayedItemsLayout();
}
@@ -239,9 +241,9 @@ QString InstanceView::groupNameAt(const QPoint& point)
{
executeDelayedItemsLayout();
- VisualGroup::HitResults hitresult;
- auto group = categoryAt(point + offset(), hitresult);
- if (group && (hitresult & (VisualGroup::HeaderHit | VisualGroup::BodyHit))) {
+ VisualGroup::HitResults hitResult;
+ auto group = categoryAt(point + offset(), hitResult);
+ if (group && (hitResult & (VisualGroup::HeaderHit | VisualGroup::BodyHit))) {
return group->text;
}
return QString();
@@ -275,9 +277,9 @@ void InstanceView::mousePressEvent(QMouseEvent* event)
m_pressedAlreadySelected = selectionModel()->isSelected(m_pressedIndex);
m_pressedPosition = geometryPos;
- VisualGroup::HitResults hitresult;
- m_pressedCategory = categoryAt(geometryPos, hitresult);
- if (m_pressedCategory && hitresult & VisualGroup::CheckboxHit) {
+ VisualGroup::HitResults hitResult;
+ m_pressedCategory = categoryAt(geometryPos, hitResult);
+ if (m_pressedCategory && hitResult & VisualGroup::CheckboxHit) {
setState(m_pressedCategory->collapsed ? ExpandingState : CollapsingState);
event->accept();
return;
@@ -361,10 +363,10 @@ void InstanceView::mouseReleaseEvent(QMouseEvent* event)
QPoint geometryPos = event->pos() + offset();
QPersistentModelIndex index = indexAt(visualPos);
- VisualGroup::HitResults hitresult;
+ VisualGroup::HitResults hitResult;
bool click =
- (index == m_pressedIndex && index.isValid()) || (m_pressedCategory && m_pressedCategory == categoryAt(geometryPos, hitresult));
+ (index == m_pressedIndex && index.isValid()) || (m_pressedCategory && m_pressedCategory == categoryAt(geometryPos, hitResult));
if (click && m_pressedCategory) {
if (state() == ExpandingState) {
@@ -444,12 +446,12 @@ void InstanceView::setPaintCat(bool visible)
{
m_catVisible = visible;
if (visible)
- m_catPixmap.load(APPLICATION->getCatPack());
+ m_catPixmap.load(APPLICATION->themeManager()->getCatPack());
else
m_catPixmap = QPixmap();
}
-void InstanceView::paintEvent(QPaintEvent* event)
+void InstanceView::paintEvent([[maybe_unused]] QPaintEvent* event)
{
executeDelayedItemsLayout();
@@ -545,7 +547,7 @@ void InstanceView::paintEvent(QPaintEvent* event)
#endif
}
-void InstanceView::resizeEvent(QResizeEvent* event)
+void InstanceView::resizeEvent([[maybe_unused]] QResizeEvent* event)
{
int newItemsPerRow = calculateItemsPerRow();
if (newItemsPerRow != m_currentItemsPerRow) {
@@ -581,7 +583,7 @@ void InstanceView::dragMoveEvent(QDragMoveEvent* event)
event->accept();
}
-void InstanceView::dragLeaveEvent(QDragLeaveEvent* event)
+void InstanceView::dragLeaveEvent([[maybe_unused]] QDragLeaveEvent* event)
{
executeDelayedItemsLayout();
@@ -604,9 +606,9 @@ void InstanceView::dropEvent(QDropEvent* event)
if (event->possibleActions() & Qt::MoveAction) {
std::pair<VisualGroup*, VisualGroup::HitResults> dropPos = rowDropPos(event->pos());
const VisualGroup* group = dropPos.first;
- auto hitresult = dropPos.second;
+ auto hitResult = dropPos.second;
- if (hitresult == VisualGroup::HitResult::NoHit) {
+ if (hitResult == VisualGroup::HitResult::NoHit) {
viewport()->update();
return;
}
@@ -643,15 +645,15 @@ void InstanceView::startDrag(Qt::DropActions supportedActions)
if (indexes.count() == 0)
return;
- QMimeData* data = model()->mimeData(indexes);
- if (!data) {
+ QMimeData* mimeData = model()->mimeData(indexes);
+ if (!mimeData) {
return;
}
QRect rect;
QPixmap pixmap = renderToPixmap(indexes, &rect);
QDrag* drag = new QDrag(this);
drag->setPixmap(pixmap);
- drag->setMimeData(data);
+ drag->setMimeData(mimeData);
drag->setHotSpot(m_pressedPosition - rect.topLeft());
Qt::DropAction defaultDropAction = Qt::IgnoreAction;
if (this->defaultDropAction() != Qt::IgnoreAction && (supportedActions & this->defaultDropAction())) {
@@ -767,16 +769,16 @@ QList<std::pair<QRect, QModelIndex>> InstanceView::draggablePaintPairs(const QMo
return ret;
}
-bool InstanceView::isDragEventAccepted(QDropEvent* event)
+bool InstanceView::isDragEventAccepted([[maybe_unused]] QDropEvent* event)
{
return true;
}
std::pair<VisualGroup*, VisualGroup::HitResults> InstanceView::rowDropPos(const QPoint& pos)
{
- VisualGroup::HitResults hitresult;
- auto group = categoryAt(pos + offset(), hitresult);
- return std::make_pair(group, hitresult);
+ VisualGroup::HitResults hitResult;
+ auto group = categoryAt(pos + offset(), hitResult);
+ return std::make_pair(group, hitResult);
}
QPoint InstanceView::offset() const
@@ -802,7 +804,7 @@ QRegion InstanceView::visualRegionForSelection(const QItemSelection& selection)
return region;
}
-QModelIndex InstanceView::moveCursor(QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
+QModelIndex InstanceView::moveCursor(QAbstractItemView::CursorAction cursorAction, [[maybe_unused]] Qt::KeyboardModifiers modifiers)
{
auto current = currentIndex();
if (!current.isValid()) {
@@ -822,20 +824,20 @@ QModelIndex InstanceView::moveCursor(QAbstractItemView::CursorAction cursorActio
switch (cursorAction) {
case MoveUp: {
if (row == 0) {
- int prevgroupindex = group_index - 1;
- while (prevgroupindex >= 0) {
- auto prevgroup = m_groups[prevgroupindex];
- if (prevgroup->collapsed) {
- prevgroupindex--;
+ int prevGroupIndex = group_index - 1;
+ while (prevGroupIndex >= 0) {
+ auto prevGroup = m_groups[prevGroupIndex];
+ if (prevGroup->collapsed) {
+ prevGroupIndex--;
continue;
}
- int newRow = prevgroup->numRows() - 1;
- int newRowSize = prevgroup->rows[newRow].size();
+ int newRow = prevGroup->numRows() - 1;
+ int newRowSize = prevGroup->rows[newRow].size();
int newColumn = m_currentCursorColumn;
if (m_currentCursorColumn >= newRowSize) {
newColumn = newRowSize - 1;
}
- return prevgroup->rows[newRow][newColumn];
+ return prevGroup->rows[newRow][newColumn];
}
} else {
int newRow = row - 1;
@@ -850,19 +852,19 @@ QModelIndex InstanceView::moveCursor(QAbstractItemView::CursorAction cursorActio
}
case MoveDown: {
if (row == cat->rows.size() - 1) {
- int nextgroupindex = group_index + 1;
- while (nextgroupindex < m_groups.size()) {
- auto nextgroup = m_groups[nextgroupindex];
- if (nextgroup->collapsed) {
- nextgroupindex++;
+ int nextGroupIndex = group_index + 1;
+ while (nextGroupIndex < m_groups.size()) {
+ auto nextGroup = m_groups[nextGroupIndex];
+ if (nextGroup->collapsed) {
+ nextGroupIndex++;
continue;
}
- int newRowSize = nextgroup->rows[0].size();
+ int newRowSize = nextGroup->rows[0].size();
int newColumn = m_currentCursorColumn;
if (m_currentCursorColumn >= newRowSize) {
newColumn = newRowSize - 1;
}
- return nextgroup->rows[0][newColumn];
+ return nextGroup->rows[0][newColumn];
}
} else {
int newRow = row + 1;
@@ -936,7 +938,7 @@ void InstanceView::scrollTo(const QModelIndex& index, ScrollHint hint)
verticalScrollBar()->setValue(verticalScrollToValue(index, rect, hint));
}
-int InstanceView::verticalScrollToValue(const QModelIndex& index, const QRect& rect, QListView::ScrollHint hint) const
+int InstanceView::verticalScrollToValue([[maybe_unused]] const QModelIndex& index, const QRect& rect, QListView::ScrollHint hint) const
{
const QRect area = viewport()->rect();
const bool above = (hint == QListView::EnsureVisible && rect.top() < area.top());
diff --git a/launcher/ui/pages/BasePageContainer.h b/launcher/ui/pages/BasePageContainer.h
index b750e827..a497ef7b 100644
--- a/launcher/ui/pages/BasePageContainer.h
+++ b/launcher/ui/pages/BasePageContainer.h
@@ -6,6 +6,7 @@ class BasePageContainer {
public:
virtual ~BasePageContainer(){};
virtual bool selectPage(QString pageId) = 0;
+ virtual BasePage* selectedPage() const = 0;
virtual BasePage* getPage(QString pageId) { return nullptr; };
virtual void refreshContainer() = 0;
virtual bool requestClose() = 0;
diff --git a/launcher/ui/pages/global/AccountListPage.cpp b/launcher/ui/pages/global/AccountListPage.cpp
index 1d5ecb8d..c95bfabd 100644
--- a/launcher/ui/pages/global/AccountListPage.cpp
+++ b/launcher/ui/pages/global/AccountListPage.cpp
@@ -64,7 +64,8 @@ AccountListPage::AccountListPage(QWidget* parent) : QMainWindow(parent), ui(new
ui->setupUi(this);
ui->listView->setEmptyString(
tr("Welcome!\n"
- "If you're new here, you can click the \"Add\" button to add your Mojang or Minecraft account."));
+ "If you're new here, you can select the \"Add Microsoft\" or \"Add Mojang\" buttons to link your Microsoft and/or Mojang "
+ "accounts."));
ui->listView->setEmptyMode(VersionListView::String);
ui->listView->setContextMenuPolicy(Qt::CustomContextMenu);
@@ -83,8 +84,10 @@ AccountListPage::AccountListPage(QWidget* parent) : QMainWindow(parent), ui(new
QItemSelectionModel* selectionModel = ui->listView->selectionModel();
connect(selectionModel, &QItemSelectionModel::selectionChanged,
- [this](const QItemSelection& sel, const QItemSelection& dsel) { updateButtonStates(); });
+ [this]([[maybe_unused]] const QItemSelection& sel, [[maybe_unused]] const QItemSelection& dsel) { updateButtonStates(); });
connect(ui->listView, &VersionListView::customContextMenuRequested, this, &AccountListPage::ShowContextMenu);
+ connect(ui->listView, &VersionListView::activated, this,
+ [this](const QModelIndex& index) { m_accounts->setDefaultAccount(m_accounts->at(index.row())); });
connect(m_accounts.get(), &AccountList::listChanged, this, &AccountListPage::listChanged);
connect(m_accounts.get(), &AccountList::listActivityChanged, this, &AccountListPage::listChanged);
diff --git a/launcher/ui/pages/global/ExternalToolsPage.ui b/launcher/ui/pages/global/ExternalToolsPage.ui
index 3643094d..47c77842 100644
--- a/launcher/ui/pages/global/ExternalToolsPage.ui
+++ b/launcher/ui/pages/global/ExternalToolsPage.ui
@@ -47,7 +47,7 @@
<item>
<widget class="QPushButton" name="jprofilerPathBtn">
<property name="text">
- <string notr="true">...</string>
+ <string>Browse</string>
</property>
</widget>
</item>
@@ -84,7 +84,7 @@
<item>
<widget class="QPushButton" name="jvisualvmPathBtn">
<property name="text">
- <string notr="true">...</string>
+ <string>Browse</string>
</property>
</widget>
</item>
@@ -121,7 +121,7 @@
<item>
<widget class="QPushButton" name="mceditPathBtn">
<property name="text">
- <string notr="true">...</string>
+ <string>Browse</string>
</property>
</widget>
</item>
@@ -166,7 +166,7 @@
<item row="0" column="2">
<widget class="QToolButton" name="jsonEditorBrowseBtn">
<property name="text">
- <string notr="true">...</string>
+ <string>Browse</string>
</property>
</widget>
</item>
diff --git a/launcher/ui/pages/global/JavaPage.cpp b/launcher/ui/pages/global/JavaPage.cpp
index a9ede8ed..ac50319e 100644
--- a/launcher/ui/pages/global/JavaPage.cpp
+++ b/launcher/ui/pages/global/JavaPage.cpp
@@ -166,7 +166,7 @@ void JavaPage::on_javaTestBtn_clicked()
checker->run();
}
-void JavaPage::on_maxMemSpinBox_valueChanged(int i)
+void JavaPage::on_maxMemSpinBox_valueChanged([[maybe_unused]] int i)
{
updateThresholds();
}
@@ -185,6 +185,7 @@ void JavaPage::updateThresholds()
{
auto sysMiB = Sys::getSystemRam() / Sys::mebibyte;
unsigned int maxMem = ui->maxMemSpinBox->value();
+ unsigned int minMem = ui->minMemSpinBox->value();
QString iconName;
@@ -194,6 +195,9 @@ void JavaPage::updateThresholds()
} else if (maxMem > (sysMiB * 0.9)) {
iconName = "status-yellow";
ui->labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation approaches your system memory capacity."));
+ } else if (maxMem < minMem) {
+ iconName = "status-yellow";
+ ui->labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation is smaller than the minimum value"));
} else {
iconName = "status-good";
ui->labelMaxMemIcon->setToolTip("");
diff --git a/launcher/ui/pages/global/JavaPage.ui b/launcher/ui/pages/global/JavaPage.ui
index 561cf79b..5a547637 100644
--- a/launcher/ui/pages/global/JavaPage.ui
+++ b/launcher/ui/pages/global/JavaPage.ui
@@ -160,37 +160,73 @@
<string>Java Runtime</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
- <item row="3" column="1">
- <widget class="QPushButton" name="javaDetectBtn">
+ <item row="7" column="0" colspan="3">
+ <widget class="QPlainTextEdit" name="jvmArgsTextBox">
+ <property name="enabled">
+ <bool>true</bool>
+ </property>
<property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
- <property name="text">
- <string>&amp;Auto-detect...</string>
+ <property name="maximumSize">
+ <size>
+ <width>16777215</width>
+ <height>100</height>
+ </size>
</property>
</widget>
</item>
- <item row="2" column="0">
- <widget class="QLabel" name="labelJVMArgs">
+ <item row="4" column="0">
+ <widget class="QCheckBox" name="skipCompatibilityCheckbox">
<property name="sizePolicy">
- <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
- <property name="text">
- <string>JVM arguments:</string>
+ <property name="toolTip">
+ <string>If enabled, the launcher will not check if an instance is compatible with the selected Java version.</string>
</property>
- <property name="alignment">
- <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
+ <property name="text">
+ <string>&amp;Skip Java compatibility checks</string>
</property>
</widget>
</item>
- <item row="0" column="0">
- <widget class="QLabel" name="labelJavaPath">
+ <item row="2" column="0" colspan="3">
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="QPushButton" name="javaDetectBtn">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>&amp;Auto-detect...</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="javaTestBtn">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>&amp;Test</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="6" column="0">
+ <widget class="QLabel" name="labelJVMArgs">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
@@ -198,69 +234,50 @@
</sizepolicy>
</property>
<property name="text">
- <string>&amp;Java path:</string>
- </property>
- <property name="buddy">
- <cstring>javaPathTextBox</cstring>
- </property>
- </widget>
- </item>
- <item row="3" column="2">
- <widget class="QPushButton" name="javaTestBtn">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
+ <string>JVM arguments:</string>
</property>
- <property name="text">
- <string>&amp;Test</string>
+ <property name="alignment">
+ <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
- <item row="0" column="1" colspan="2">
+ <item row="1" column="0" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
+ <widget class="QLabel" name="labelJavaPath">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>&amp;Java path:</string>
+ </property>
+ <property name="buddy">
+ <cstring>javaPathTextBox</cstring>
+ </property>
+ </widget>
+ </item>
+ <item>
<widget class="QLineEdit" name="javaPathTextBox"/>
</item>
<item>
<widget class="QPushButton" name="javaBrowseBtn">
<property name="sizePolicy">
- <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
- <property name="maximumSize">
- <size>
- <width>28</width>
- <height>16777215</height>
- </size>
- </property>
<property name="text">
- <string notr="true">...</string>
+ <string>Browse</string>
</property>
</widget>
</item>
</layout>
</item>
- <item row="4" column="1">
- <widget class="QCheckBox" name="skipCompatibilityCheckbox">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="toolTip">
- <string>If enabled, the launcher will not check if an instance is compatible with the selected Java version.</string>
- </property>
- <property name="text">
- <string>&amp;Skip Java compatibility checks</string>
- </property>
- </widget>
- </item>
- <item row="5" column="1">
+ <item row="5" column="0">
<widget class="QCheckBox" name="skipJavaWizardCheckbox">
<property name="toolTip">
<string>If enabled, the launcher will not prompt you to choose a Java version if one isn't found.</string>
@@ -270,25 +287,6 @@
</property>
</widget>
</item>
- <item row="2" column="1" colspan="2">
- <widget class="QPlainTextEdit" name="jvmArgsTextBox">
- <property name="enabled">
- <bool>true</bool>
- </property>
- <property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="maximumSize">
- <size>
- <width>16777215</width>
- <height>100</height>
- </size>
- </property>
- </widget>
- </item>
</layout>
</widget>
</item>
@@ -317,8 +315,6 @@
<tabstop>permGenSpinBox</tabstop>
<tabstop>javaBrowseBtn</tabstop>
<tabstop>javaPathTextBox</tabstop>
- <tabstop>javaDetectBtn</tabstop>
- <tabstop>javaTestBtn</tabstop>
<tabstop>tabWidget</tabstop>
</tabstops>
<resources/>
diff --git a/launcher/ui/pages/global/LauncherPage.ui b/launcher/ui/pages/global/LauncherPage.ui
index 26408f44..bc259a9b 100644
--- a/launcher/ui/pages/global/LauncherPage.ui
+++ b/launcher/ui/pages/global/LauncherPage.ui
@@ -99,7 +99,7 @@
<item row="3" column="2">
<widget class="QToolButton" name="downloadsDirBrowseBtn">
<property name="text">
- <string notr="true">...</string>
+ <string>Browse</string>
</property>
</widget>
</item>
@@ -109,7 +109,7 @@
<item row="1" column="2">
<widget class="QToolButton" name="modsDirBrowseBtn">
<property name="text">
- <string notr="true">...</string>
+ <string>Browse</string>
</property>
</widget>
</item>
@@ -126,14 +126,14 @@
<item row="0" column="2">
<widget class="QToolButton" name="instDirBrowseBtn">
<property name="text">
- <string notr="true">...</string>
+ <string>Browse</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QToolButton" name="iconsDirBrowseBtn">
<property name="text">
- <string notr="true">...</string>
+ <string>Browse</string>
</property>
</widget>
</item>
diff --git a/launcher/ui/pages/global/MinecraftPage.cpp b/launcher/ui/pages/global/MinecraftPage.cpp
index 866a4121..553cefd8 100644
--- a/launcher/ui/pages/global/MinecraftPage.cpp
+++ b/launcher/ui/pages/global/MinecraftPage.cpp
@@ -2,7 +2,6 @@
/*
* Prism Launcher - Minecraft Launcher
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
- * Copyright (C) 2023 seth <getchoo at tuta dot io>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -35,6 +34,7 @@
*/
#include "MinecraftPage.h"
+#include "BuildConfig.h"
#include "ui_MinecraftPage.h"
#include <QDir>
@@ -44,9 +44,15 @@
#include "Application.h"
#include "settings/SettingsObject.h"
+#ifdef Q_OS_LINUX
+#include "MangoHud.h"
+#endif
+
MinecraftPage::MinecraftPage(QWidget* parent) : QWidget(parent), ui(new Ui::MinecraftPage)
{
ui->setupUi(this);
+ connect(ui->useNativeGLFWCheck, &QAbstractButton::toggled, this, &MinecraftPage::onUseNativeGLFWChanged);
+ connect(ui->useNativeOpenALCheck, &QAbstractButton::toggled, this, &MinecraftPage::onUseNativeOpenALChanged);
loadSettings();
updateCheckboxStuff();
}
@@ -74,6 +80,16 @@ void MinecraftPage::on_maximizedCheckBox_clicked(bool checked)
updateCheckboxStuff();
}
+void MinecraftPage::onUseNativeGLFWChanged(bool checked)
+{
+ ui->lineEditGLFWPath->setEnabled(checked);
+}
+
+void MinecraftPage::onUseNativeOpenALChanged(bool checked)
+{
+ ui->lineEditOpenALPath->setEnabled(checked);
+}
+
void MinecraftPage::applySettings()
{
auto s = APPLICATION->settings();
@@ -84,8 +100,10 @@ void MinecraftPage::applySettings()
s->set("MinecraftWinHeight", ui->windowHeightSpinBox->value());
// Native library workarounds
- s->set("UseNativeOpenAL", ui->useNativeOpenALCheck->isChecked());
s->set("UseNativeGLFW", ui->useNativeGLFWCheck->isChecked());
+ s->set("CustomGLFWPath", ui->lineEditGLFWPath->text());
+ s->set("UseNativeOpenAL", ui->useNativeOpenALCheck->isChecked());
+ s->set("CustomOpenALPath", ui->lineEditOpenALPath->text());
// Peformance related options
s->set("EnableFeralGamemode", ui->enableFeralGamemodeCheck->isChecked());
@@ -96,13 +114,11 @@ void MinecraftPage::applySettings()
s->set("ShowGameTime", ui->showGameTime->isChecked());
s->set("ShowGlobalGameTime", ui->showGlobalGameTime->isChecked());
s->set("RecordGameTime", ui->recordGameTime->isChecked());
+ s->set("ShowGameTimeWithoutDays", ui->showGameTimeWithoutDays->isChecked());
// Miscellaneous
s->set("CloseAfterLaunch", ui->closeAfterLaunchCheck->isChecked());
s->set("QuitAfterGameStop", ui->quitAfterGameStopCheck->isChecked());
-
- // Mod loader settings
- s->set("DisableQuiltBeacon", ui->disableQuiltBeaconCheckBox->isChecked());
}
void MinecraftPage::loadSettings()
@@ -114,8 +130,20 @@ void MinecraftPage::loadSettings()
ui->windowWidthSpinBox->setValue(s->get("MinecraftWinWidth").toInt());
ui->windowHeightSpinBox->setValue(s->get("MinecraftWinHeight").toInt());
- ui->useNativeOpenALCheck->setChecked(s->get("UseNativeOpenAL").toBool());
ui->useNativeGLFWCheck->setChecked(s->get("UseNativeGLFW").toBool());
+ ui->lineEditGLFWPath->setText(s->get("CustomGLFWPath").toString());
+ ui->lineEditGLFWPath->setPlaceholderText(tr("Path to %1 library file").arg(BuildConfig.GLFW_LIBRARY_NAME));
+#ifdef Q_OS_LINUX
+ if (!APPLICATION->m_detectedGLFWPath.isEmpty())
+ ui->lineEditGLFWPath->setPlaceholderText(tr("Auto detected path: %1").arg(APPLICATION->m_detectedGLFWPath));
+#endif
+ ui->useNativeOpenALCheck->setChecked(s->get("UseNativeOpenAL").toBool());
+ ui->lineEditOpenALPath->setText(s->get("CustomOpenALPath").toString());
+ ui->lineEditOpenALPath->setPlaceholderText(tr("Path to %1 library file").arg(BuildConfig.OPENAL_LIBRARY_NAME));
+#ifdef Q_OS_LINUX
+ if (!APPLICATION->m_detectedOpenALPath.isEmpty())
+ ui->lineEditOpenALPath->setPlaceholderText(tr("Auto detected path: %1").arg(APPLICATION->m_detectedOpenALPath));
+#endif
ui->enableFeralGamemodeCheck->setChecked(s->get("EnableFeralGamemode").toBool());
ui->enableMangoHud->setChecked(s->get("EnableMangoHud").toBool());
@@ -138,11 +166,10 @@ void MinecraftPage::loadSettings()
ui->showGameTime->setChecked(s->get("ShowGameTime").toBool());
ui->showGlobalGameTime->setChecked(s->get("ShowGlobalGameTime").toBool());
ui->recordGameTime->setChecked(s->get("RecordGameTime").toBool());
+ ui->showGameTimeWithoutDays->setChecked(s->get("ShowGameTimeWithoutDays").toBool());
ui->closeAfterLaunchCheck->setChecked(s->get("CloseAfterLaunch").toBool());
ui->quitAfterGameStopCheck->setChecked(s->get("QuitAfterGameStop").toBool());
-
- ui->disableQuiltBeaconCheckBox->setChecked(s->get("DisableQuiltBeacon").toBool());
}
void MinecraftPage::retranslate()
diff --git a/launcher/ui/pages/global/MinecraftPage.h b/launcher/ui/pages/global/MinecraftPage.h
index 28c31b5d..5facfbb3 100644
--- a/launcher/ui/pages/global/MinecraftPage.h
+++ b/launcher/ui/pages/global/MinecraftPage.h
@@ -70,6 +70,9 @@ class MinecraftPage : public QWidget, public BasePage {
private slots:
void on_maximizedCheckBox_clicked(bool checked);
+ void onUseNativeGLFWChanged(bool checked);
+ void onUseNativeOpenALChanged(bool checked);
+
private:
Ui::MinecraftPage* ui;
};
diff --git a/launcher/ui/pages/global/MinecraftPage.ui b/launcher/ui/pages/global/MinecraftPage.ui
index 393b0f35..b5cfa659 100644
--- a/launcher/ui/pages/global/MinecraftPage.ui
+++ b/launcher/ui/pages/global/MinecraftPage.ui
@@ -138,6 +138,13 @@
</property>
</widget>
</item>
+ <item>
+ <widget class="QCheckBox" name="showGameTimeWithoutDays">
+ <property name="text">
+ <string>Show time spent playing in hours</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
</item>
@@ -191,44 +198,59 @@
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_12">
<item>
- <widget class="QGroupBox" name="modLoaderSettingsGroupBox">
- <property name="title">
- <string>Mod loader settings</string>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout_13">
- <item>
- <widget class="QCheckBox" name="disableQuiltBeaconCheckBox">
- <property name="text">
- <string>Disable Quilt Loader Beacon</string>
- </property>
- <property name="toolTip">
- <string>Disable Quilt loader's beacon for counting monthly active users</string>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- </item>
- <item>
<widget class="QGroupBox" name="nativeLibWorkaroundGroupBox">
<property name="title">
<string>Native library workarounds</string>
</property>
- <layout class="QVBoxLayout" name="verticalLayout_11">
- <item>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
<widget class="QCheckBox" name="useNativeGLFWCheck">
<property name="text">
<string>Use system installation of &amp;GLFW</string>
</property>
</widget>
</item>
- <item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="labelGLFWPath">
+ <property name="text">
+ <string>&amp;GLFW library path</string>
+ </property>
+ <property name="buddy">
+ <cstring>lineEditGLFWPath</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
<widget class="QCheckBox" name="useNativeOpenALCheck">
<property name="text">
<string>Use system installation of &amp;OpenAL</string>
</property>
</widget>
</item>
+ <item row="3" column="0">
+ <widget class="QLabel" name="labelOpenALPath">
+ <property name="text">
+ <string>&amp;OpenAL library path</string>
+ </property>
+ <property name="buddy">
+ <cstring>lineEditOpenALPath</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QLineEdit" name="lineEditGLFWPath">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QLineEdit" name="lineEditOpenALPath">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
</item>
diff --git a/launcher/ui/pages/global/ProxyPage.cpp b/launcher/ui/pages/global/ProxyPage.cpp
index 19b2bcea..9caffcb3 100644
--- a/launcher/ui/pages/global/ProxyPage.cpp
+++ b/launcher/ui/pages/global/ProxyPage.cpp
@@ -71,7 +71,7 @@ void ProxyPage::updateCheckboxStuff()
ui->proxyAuthBox->setEnabled(enableEditing);
}
-void ProxyPage::proxyGroupChanged(QAbstractButton* button)
+void ProxyPage::proxyGroupChanged([[maybe_unused]] QAbstractButton* button)
{
updateCheckboxStuff();
}
diff --git a/launcher/ui/pages/instance/ExternalResourcesPage.cpp b/launcher/ui/pages/instance/ExternalResourcesPage.cpp
index 12038f88..1a8fafa9 100644
--- a/launcher/ui/pages/instance/ExternalResourcesPage.cpp
+++ b/launcher/ui/pages/instance/ExternalResourcesPage.cpp
@@ -152,6 +152,7 @@ void ExternalResourcesPage::retranslate()
void ExternalResourcesPage::itemActivated(const QModelIndex&)
{
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection());
+ m_model->setResourceEnabled(selection.indexes(), EnableAction::TOGGLE);
}
void ExternalResourcesPage::filterTextChanged(const QString& newContents)
@@ -305,7 +306,7 @@ bool ExternalResourcesPage::current(const QModelIndex& current, const QModelInde
return onSelectionChanged(current, previous);
}
-bool ExternalResourcesPage::onSelectionChanged(const QModelIndex& current, const QModelIndex& previous)
+bool ExternalResourcesPage::onSelectionChanged(const QModelIndex& current, [[maybe_unused]] const QModelIndex& previous)
{
auto sourceCurrent = m_filterModel->mapToSource(current);
int row = sourceCurrent.row();
diff --git a/launcher/ui/pages/instance/ExternalResourcesPage.ui b/launcher/ui/pages/instance/ExternalResourcesPage.ui
index 3c836691..ba703f77 100644
--- a/launcher/ui/pages/instance/ExternalResourcesPage.ui
+++ b/launcher/ui/pages/instance/ExternalResourcesPage.ui
@@ -168,6 +168,17 @@
<string>Go to mods home page</string>
</property>
</action>
+ <action name="actionRemoveItemMetadata">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Remove metadata</string>
+ </property>
+ <property name="toolTip">
+ <string>Remove mod's metadata</string>
+ </property>
+ </action>
</widget>
<customwidgets>
<customwidget>
diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.cpp b/launcher/ui/pages/instance/InstanceSettingsPage.cpp
index 687b82d7..7aa6bd32 100644
--- a/launcher/ui/pages/instance/InstanceSettingsPage.cpp
+++ b/launcher/ui/pages/instance/InstanceSettingsPage.cpp
@@ -3,7 +3,6 @@
* Prism Launcher - Minecraft Launcher
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
- * Copyright (C) 2023 seth <getchoo at tuta dot io>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -48,6 +47,7 @@
#include "ui/widgets/CustomCommands.h"
#include "Application.h"
+#include "BuildConfig.h"
#include "JavaCommon.h"
#include "minecraft/auth/AccountList.h"
@@ -66,6 +66,10 @@ InstanceSettingsPage::InstanceSettingsPage(BaseInstance* inst, QWidget* parent)
connect(APPLICATION, &Application::globalSettingsClosed, this, &InstanceSettingsPage::loadSettings);
connect(ui->instanceAccountSelector, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&InstanceSettingsPage::changeInstanceAccount);
+
+ connect(ui->useNativeGLFWCheck, &QAbstractButton::toggled, this, &InstanceSettingsPage::onUseNativeGLFWChanged);
+ connect(ui->useNativeOpenALCheck, &QAbstractButton::toggled, this, &InstanceSettingsPage::onUseNativeOpenALChanged);
+
loadSettings();
updateThresholds();
@@ -198,11 +202,15 @@ void InstanceSettingsPage::applySettings()
bool workarounds = ui->nativeWorkaroundsGroupBox->isChecked();
m_settings->set("OverrideNativeWorkarounds", workarounds);
if (workarounds) {
- m_settings->set("UseNativeOpenAL", ui->useNativeOpenALCheck->isChecked());
m_settings->set("UseNativeGLFW", ui->useNativeGLFWCheck->isChecked());
+ m_settings->set("CustomGLFWPath", ui->lineEditGLFWPath->text());
+ m_settings->set("UseNativeOpenAL", ui->useNativeOpenALCheck->isChecked());
+ m_settings->set("CustomOpenALPath", ui->lineEditOpenALPath->text());
} else {
- m_settings->reset("UseNativeOpenAL");
m_settings->reset("UseNativeGLFW");
+ m_settings->reset("CustomGLFWPath");
+ m_settings->reset("UseNativeOpenAL");
+ m_settings->reset("CustomOpenALPath");
}
// Performance
@@ -245,14 +253,6 @@ void InstanceSettingsPage::applySettings()
m_settings->reset("InstanceAccountId");
}
- bool overrideModLoaderSettings = ui->modLoaderSettingsGroupBox->isChecked();
- m_settings->set("OverrideModLoaderSettings", overrideModLoaderSettings);
- if (overrideModLoaderSettings) {
- m_settings->set("DisableQuiltBeacon", ui->disableQuiltBeaconCheckBox->isChecked());
- } else {
- m_settings->reset("DisableQuiltBeacon");
- }
-
// FIXME: This should probably be called by a signal instead
m_instance->updateRuntimeContext();
}
@@ -312,7 +312,19 @@ void InstanceSettingsPage::loadSettings()
// Workarounds
ui->nativeWorkaroundsGroupBox->setChecked(m_settings->get("OverrideNativeWorkarounds").toBool());
ui->useNativeGLFWCheck->setChecked(m_settings->get("UseNativeGLFW").toBool());
+ ui->lineEditGLFWPath->setText(m_settings->get("CustomGLFWPath").toString());
+#ifdef Q_OS_LINUX
+ ui->lineEditGLFWPath->setPlaceholderText(APPLICATION->m_detectedGLFWPath);
+#else
+ ui->lineEditGLFWPath->setPlaceholderText(tr("Path to %1 library file").arg(BuildConfig.GLFW_LIBRARY_NAME));
+#endif
ui->useNativeOpenALCheck->setChecked(m_settings->get("UseNativeOpenAL").toBool());
+ ui->lineEditOpenALPath->setText(m_settings->get("CustomOpenALPath").toString());
+#ifdef Q_OS_LINUX
+ ui->lineEditOpenALPath->setPlaceholderText(APPLICATION->m_detectedOpenALPath);
+#else
+ ui->lineEditGLFWPath->setPlaceholderText(tr("Path to %1 library file").arg(BuildConfig.OPENAL_LIBRARY_NAME));
+#endif
// Performance
ui->perfomanceGroupBox->setChecked(m_settings->get("OverridePerformance").toBool());
@@ -344,10 +356,6 @@ void InstanceSettingsPage::loadSettings()
ui->instanceAccountGroupBox->setChecked(m_settings->get("UseAccountForInstance").toBool());
updateAccountsMenu();
-
- // Mod loader specific settings
- ui->modLoaderSettingsGroupBox->setChecked(m_settings->get("OverrideModLoaderSettings").toBool());
- ui->disableQuiltBeaconCheckBox->setChecked(m_settings->get("DisableQuiltBeacon").toBool());
}
void InstanceSettingsPage::on_javaDetectBtn_clicked()
@@ -408,6 +416,16 @@ void InstanceSettingsPage::on_javaTestBtn_clicked()
checker->run();
}
+void InstanceSettingsPage::onUseNativeGLFWChanged(bool checked)
+{
+ ui->lineEditGLFWPath->setEnabled(checked);
+}
+
+void InstanceSettingsPage::onUseNativeOpenALChanged(bool checked)
+{
+ ui->lineEditOpenALPath->setEnabled(checked);
+}
+
void InstanceSettingsPage::updateAccountsMenu()
{
ui->instanceAccountSelector->clear();
@@ -440,7 +458,7 @@ void InstanceSettingsPage::changeInstanceAccount(int index)
}
}
-void InstanceSettingsPage::on_maxMemSpinBox_valueChanged(int i)
+void InstanceSettingsPage::on_maxMemSpinBox_valueChanged([[maybe_unused]] int i)
{
updateThresholds();
}
@@ -460,6 +478,7 @@ void InstanceSettingsPage::updateThresholds()
{
auto sysMiB = Sys::getSystemRam() / Sys::mebibyte;
unsigned int maxMem = ui->maxMemSpinBox->value();
+ unsigned int minMem = ui->minMemSpinBox->value();
QString iconName;
@@ -469,6 +488,9 @@ void InstanceSettingsPage::updateThresholds()
} else if (maxMem > (sysMiB * 0.9)) {
iconName = "status-yellow";
ui->labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation approaches your system memory capacity."));
+ } else if (maxMem < minMem) {
+ iconName = "status-yellow";
+ ui->labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation is smaller than the minimum value"));
} else {
iconName = "status-good";
ui->labelMaxMemIcon->setToolTip("");
diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.h b/launcher/ui/pages/instance/InstanceSettingsPage.h
index 21ecbaf8..8b78dcb7 100644
--- a/launcher/ui/pages/instance/InstanceSettingsPage.h
+++ b/launcher/ui/pages/instance/InstanceSettingsPage.h
@@ -71,6 +71,9 @@ class InstanceSettingsPage : public QWidget, public BasePage {
void on_javaBrowseBtn_clicked();
void on_maxMemSpinBox_valueChanged(int i);
+ void onUseNativeGLFWChanged(bool checked);
+ void onUseNativeOpenALChanged(bool checked);
+
void applySettings();
void loadSettings();
diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.ui b/launcher/ui/pages/instance/InstanceSettingsPage.ui
index 245433fe..81cf7093 100644
--- a/launcher/ui/pages/instance/InstanceSettingsPage.ui
+++ b/launcher/ui/pages/instance/InstanceSettingsPage.ui
@@ -61,31 +61,7 @@
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
- <item row="0" column="0" colspan="3">
- <widget class="QLineEdit" name="javaPathTextBox"/>
- </item>
- <item row="1" column="0">
- <widget class="QPushButton" name="javaDetectBtn">
- <property name="text">
- <string>Auto-detect...</string>
- </property>
- </widget>
- </item>
- <item row="1" column="1">
- <widget class="QPushButton" name="javaBrowseBtn">
- <property name="text">
- <string>Browse...</string>
- </property>
- </widget>
- </item>
- <item row="1" column="2">
- <widget class="QPushButton" name="javaTestBtn">
- <property name="text">
- <string>Test</string>
- </property>
- </widget>
- </item>
- <item row="2" column="0">
+ <item row="4" column="0">
<widget class="QCheckBox" name="skipCompatibilityCheckbox">
<property name="toolTip">
<string>If enabled, the launcher will not check if an instance is compatible with the selected Java version.</string>
@@ -95,6 +71,38 @@
</property>
</widget>
</item>
+ <item row="1" column="0">
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QLineEdit" name="javaPathTextBox"/>
+ </item>
+ <item>
+ <widget class="QPushButton" name="javaBrowseBtn">
+ <property name="text">
+ <string>Browse</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="2" column="0">
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="QPushButton" name="javaDetectBtn">
+ <property name="text">
+ <string>Auto-detect...</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="javaTestBtn">
+ <property name="text">
+ <string>Test</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
</layout>
</widget>
</item>
@@ -435,18 +443,52 @@
<property name="checked">
<bool>false</bool>
</property>
- <layout class="QVBoxLayout" name="verticalLayout_7">
- <item>
+ <layout class="QGridLayout" name="gridLayout_3">
+ <item row="2" column="0">
+ <widget class="QCheckBox" name="useNativeOpenALCheck">
+ <property name="text">
+ <string>Use system installation of OpenAL</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="labelGLFWPath">
+ <property name="text">
+ <string>&amp;GLFW library path</string>
+ </property>
+ <property name="buddy">
+ <cstring>lineEditGLFWPath</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0">
<widget class="QCheckBox" name="useNativeGLFWCheck">
<property name="text">
<string>Use system installation of GLFW</string>
</property>
</widget>
</item>
- <item>
- <widget class="QCheckBox" name="useNativeOpenALCheck">
+ <item row="1" column="1">
+ <widget class="QLineEdit" name="lineEditGLFWPath">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0">
+ <widget class="QLabel" name="labelOpenALPath">
<property name="text">
- <string>Use system installation of OpenAL</string>
+ <string>&amp;OpenAL library path</string>
+ </property>
+ <property name="buddy">
+ <cstring>lineEditOpenALPath</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QLineEdit" name="lineEditOpenALPath">
+ <property name="enabled">
+ <bool>false</bool>
</property>
</widget>
</item>
@@ -542,31 +584,6 @@
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_9">
<item>
- <widget class="QGroupBox" name="modLoaderSettingsGroupBox">
- <property name="checkable">
- <bool>true</bool>
- </property>
- <property name="checked">
- <bool>false</bool>
- </property>
- <property name="title">
- <string>Mod loader settings</string>
- </property>
- <layout class="QVBoxLayout" name="VerticalLayout_16">
- <item>
- <widget class="QCheckBox" name="disableQuiltBeaconCheckBox">
- <property name="text">
- <string>Disable Quilt Loader Beacon</string>
- </property>
- <property name="toolTip">
- <string>Disable Quilt loader's beacon for counting monthly active users</string>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- </item>
- <item>
<widget class="QGroupBox" name="gameTimeGroupBox">
<property name="enabled">
<bool>true</bool>
@@ -699,10 +716,6 @@
<tabstop>openGlobalJavaSettingsButton</tabstop>
<tabstop>settingsTabs</tabstop>
<tabstop>javaSettingsGroupBox</tabstop>
- <tabstop>javaPathTextBox</tabstop>
- <tabstop>javaDetectBtn</tabstop>
- <tabstop>javaBrowseBtn</tabstop>
- <tabstop>javaTestBtn</tabstop>
<tabstop>memoryGroupBox</tabstop>
<tabstop>minMemSpinBox</tabstop>
<tabstop>maxMemSpinBox</tabstop>
diff --git a/launcher/ui/pages/instance/ManagedPackPage.cpp b/launcher/ui/pages/instance/ManagedPackPage.cpp
index 0443baf1..8fdaf065 100644
--- a/launcher/ui/pages/instance/ManagedPackPage.cpp
+++ b/launcher/ui/pages/instance/ManagedPackPage.cpp
@@ -26,6 +26,8 @@
#include "ui/dialogs/CustomMessageBox.h"
#include "ui/dialogs/ProgressDialog.h"
+#include "net/ApiDownload.h"
+
/** This is just to override the combo box popup behavior so that the combo box doesn't take the whole screen.
* ... thanks Qt.
*/
@@ -242,7 +244,7 @@ void ModrinthManagedPackPage::parseManagedPack()
QString id = m_inst->getManagedPackID();
m_fetch_job->addNetAction(
- Net::Download::makeByteArray(QString("%1/project/%2/version").arg(BuildConfig.MODRINTH_PROD_URL, id), response));
+ Net::ApiDownload::makeByteArray(QString("%1/project/%2/version").arg(BuildConfig.MODRINTH_PROD_URL, id), response));
QObject::connect(m_fetch_job.get(), &NetJob::succeeded, this, [this, response, id] {
QJsonParseError parse_error{};
@@ -392,7 +394,7 @@ void FlameManagedPackPage::parseManagedPack()
QString id = m_inst->getManagedPackID();
- m_fetch_job->addNetAction(Net::Download::makeByteArray(QString("%1/mods/%2/files").arg(BuildConfig.FLAME_BASE_URL, id), response));
+ m_fetch_job->addNetAction(Net::ApiDownload::makeByteArray(QString("%1/mods/%2/files").arg(BuildConfig.FLAME_BASE_URL, id), response));
QObject::connect(m_fetch_job.get(), &NetJob::succeeded, this, [this, response, id] {
QJsonParseError parse_error{};
diff --git a/launcher/ui/pages/instance/ModFolderPage.cpp b/launcher/ui/pages/instance/ModFolderPage.cpp
index cef292bd..b42bbf46 100644
--- a/launcher/ui/pages/instance/ModFolderPage.cpp
+++ b/launcher/ui/pages/instance/ModFolderPage.cpp
@@ -92,6 +92,10 @@ ModFolderPage::ModFolderPage(BaseInstance* inst, std::shared_ptr<ModFolderModel>
ui->actionsToolbar->addAction(ui->actionVisitItemPage);
connect(ui->actionVisitItemPage, &QAction::triggered, this, &ModFolderPage::visitModPages);
+ ui->actionRemoveItemMetadata->setToolTip(tr("Remove mod's metadata"));
+ ui->actionsToolbar->insertActionAfter(ui->actionRemoveItem, ui->actionRemoveItemMetadata);
+ connect(ui->actionRemoveItemMetadata, &QAction::triggered, this, &ModFolderPage::deleteModMetadata);
+
auto check_allow_update = [this] { return ui->treeView->selectionModel()->hasSelection() || !m_model->empty(); };
connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, [this, check_allow_update] {
@@ -104,11 +108,16 @@ ModFolderPage::ModFolderPage(BaseInstance* inst, std::shared_ptr<ModFolderModel>
if (selected <= 1) {
ui->actionVisitItemPage->setText(tr("Visit mod's page"));
ui->actionVisitItemPage->setToolTip(tr("Go to mod's home page"));
+
+ ui->actionRemoveItemMetadata->setToolTip(tr("Remove mod's metadata"));
} else {
ui->actionVisitItemPage->setText(tr("Visit mods' pages"));
ui->actionVisitItemPage->setToolTip(tr("Go to the pages of the selected mods"));
+
+ ui->actionRemoveItemMetadata->setToolTip(tr("Remove mods' metadata"));
}
ui->actionVisitItemPage->setEnabled(selected != 0);
+ ui->actionRemoveItemMetadata->setEnabled(selected != 0);
});
connect(mods.get(), &ModFolderModel::rowsInserted, this,
@@ -127,7 +136,7 @@ bool ModFolderPage::shouldDisplay() const
return true;
}
-bool ModFolderPage::onSelectionChanged(const QModelIndex& current, const QModelIndex& previous)
+bool ModFolderPage::onSelectionChanged(const QModelIndex& current, [[maybe_unused]] const QModelIndex& previous)
{
auto sourceCurrent = m_filterModel->mapToSource(current);
int row = sourceCurrent.row();
@@ -297,3 +306,24 @@ void ModFolderPage::visitModPages()
DesktopServices::openUrl(url);
}
}
+
+void ModFolderPage::deleteModMetadata()
+{
+ auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection()).indexes();
+ auto selectionCount = m_model->selectedMods(selection).length();
+ if (selectionCount == 0)
+ return;
+ if (selectionCount > 1) {
+ auto response = CustomMessageBox::selectable(this, tr("Confirm Removal"),
+ tr("You are about to remove the metadata for %1 mods.\n"
+ "Are you sure?")
+ .arg(selectionCount),
+ QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
+ ->exec();
+
+ if (response != QMessageBox::Yes)
+ return;
+ }
+
+ m_model->deleteModsMetadata(selection);
+}
diff --git a/launcher/ui/pages/instance/ModFolderPage.h b/launcher/ui/pages/instance/ModFolderPage.h
index a23dcae1..0c654d0d 100644
--- a/launcher/ui/pages/instance/ModFolderPage.h
+++ b/launcher/ui/pages/instance/ModFolderPage.h
@@ -61,6 +61,7 @@ class ModFolderPage : public ExternalResourcesPage {
private slots:
void removeItems(const QItemSelection& selection) override;
+ void deleteModMetadata();
void installMods();
void updateMods();
diff --git a/launcher/ui/pages/instance/OtherLogsPage.cpp b/launcher/ui/pages/instance/OtherLogsPage.cpp
index b80c08e1..ab5d9828 100644
--- a/launcher/ui/pages/instance/OtherLogsPage.cpp
+++ b/launcher/ui/pages/instance/OtherLogsPage.cpp
@@ -246,20 +246,20 @@ void OtherLogsPage::on_btnClean_clicked()
}
}
if (!failed.empty()) {
- QMessageBox* messageBox = new QMessageBox(this);
- messageBox->setWindowTitle(tr("Error"));
+ QMessageBox* messageBoxFailure = new QMessageBox(this);
+ messageBoxFailure->setWindowTitle(tr("Error"));
if (failed.size() > 5) {
- messageBox->setText(tr("Couldn't delete some files!"));
- messageBox->setDetailedText(failed.join('\n'));
+ messageBoxFailure->setText(tr("Couldn't delete some files!"));
+ messageBoxFailure->setDetailedText(failed.join('\n'));
} else {
- messageBox->setText(tr("Couldn't delete some files:\n%1").arg(failed.join('\n')));
+ messageBoxFailure->setText(tr("Couldn't delete some files:\n%1").arg(failed.join('\n')));
}
- messageBox->setStandardButtons(QMessageBox::Ok);
- messageBox->setDefaultButton(QMessageBox::Ok);
- messageBox->setTextInteractionFlags(Qt::TextSelectableByMouse);
- messageBox->setIcon(QMessageBox::Critical);
- messageBox->setTextInteractionFlags(Qt::TextBrowserInteraction);
- messageBox->exec();
+ messageBoxFailure->setStandardButtons(QMessageBox::Ok);
+ messageBoxFailure->setDefaultButton(QMessageBox::Ok);
+ messageBoxFailure->setTextInteractionFlags(Qt::TextSelectableByMouse);
+ messageBoxFailure->setIcon(QMessageBox::Critical);
+ messageBoxFailure->setTextInteractionFlags(Qt::TextBrowserInteraction);
+ messageBoxFailure->exec();
}
}
diff --git a/launcher/ui/pages/instance/ResourcePackPage.cpp b/launcher/ui/pages/instance/ResourcePackPage.cpp
index 12b371df..26c14ca4 100644
--- a/launcher/ui/pages/instance/ResourcePackPage.cpp
+++ b/launcher/ui/pages/instance/ResourcePackPage.cpp
@@ -55,7 +55,7 @@ ResourcePackPage::ResourcePackPage(MinecraftInstance* instance, std::shared_ptr<
ui->actionViewConfigs->setVisible(false);
}
-bool ResourcePackPage::onSelectionChanged(const QModelIndex& current, const QModelIndex& previous)
+bool ResourcePackPage::onSelectionChanged(const QModelIndex& current, [[maybe_unused]] const QModelIndex& previous)
{
auto sourceCurrent = m_filterModel->mapToSource(current);
int row = sourceCurrent.row();
diff --git a/launcher/ui/pages/instance/ServersPage.cpp b/launcher/ui/pages/instance/ServersPage.cpp
index 07daca21..2142e6c9 100644
--- a/launcher/ui/pages/instance/ServersPage.cpp
+++ b/launcher/ui/pages/instance/ServersPage.cpp
@@ -3,7 +3,7 @@
* Prism Launcher - Minecraft Launcher
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
- * Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
+ * Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -354,14 +354,8 @@ class ServersModel : public QAbstractListModel {
}
}
- virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override
- {
- return parent.isValid() ? 0 : m_servers.size();
- }
- int columnCount(const QModelIndex& parent) const override
- {
- return parent.isValid() ? 0 : COLUMN_COUNT;
- }
+ virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override { return parent.isValid() ? 0 : m_servers.size(); }
+ int columnCount(const QModelIndex& parent) const override { return parent.isValid() ? 0 : COLUMN_COUNT; }
Server* at(int index)
{
@@ -445,10 +439,7 @@ class ServersModel : public QAbstractListModel {
qDebug() << "Changed:" << path;
load();
}
- void fileChanged(const QString& path)
- {
- qDebug() << "Changed:" << path;
- }
+ void fileChanged(const QString& path) { qDebug() << "Changed:" << path; }
private slots:
void save_internal()
@@ -492,10 +483,7 @@ class ServersModel : public QAbstractListModel {
m_saveTimer.stop();
}
- bool saveIsScheduled() const
- {
- return m_dirty;
- }
+ bool saveIsScheduled() const { return m_dirty; }
void updateFSObserver()
{
@@ -607,7 +595,7 @@ void ServersPage::runningStateChanged(bool running)
updateState();
}
-void ServersPage::currentChanged(const QModelIndex& current, const QModelIndex& previous)
+void ServersPage::currentChanged(const QModelIndex& current, [[maybe_unused]] const QModelIndex& previous)
{
int nextServer = -1;
if (!current.isValid()) {
@@ -620,7 +608,7 @@ void ServersPage::currentChanged(const QModelIndex& current, const QModelIndex&
}
// WARNING: this is here because currentChanged is not accurate when removing rows. the current item needs to be fixed up after removal.
-void ServersPage::rowsRemoved(const QModelIndex& parent, int first, int last)
+void ServersPage::rowsRemoved([[maybe_unused]] const QModelIndex& parent, int first, int last)
{
if (currentServer < first) {
// current was before the removal
@@ -743,7 +731,7 @@ void ServersPage::on_actionMove_Down_triggered()
void ServersPage::on_actionJoin_triggered()
{
const auto& address = m_model->at(currentServer)->m_address;
- APPLICATION->launch(m_inst, true, false, nullptr, std::make_shared<MinecraftServerTarget>(MinecraftServerTarget::parse(address)));
+ APPLICATION->launch(m_inst, true, false, std::make_shared<MinecraftServerTarget>(MinecraftServerTarget::parse(address)));
}
#include "ServersPage.moc"
diff --git a/launcher/ui/pages/instance/TexturePackPage.cpp b/launcher/ui/pages/instance/TexturePackPage.cpp
index e477ceda..fa478a9a 100644
--- a/launcher/ui/pages/instance/TexturePackPage.cpp
+++ b/launcher/ui/pages/instance/TexturePackPage.cpp
@@ -57,7 +57,7 @@ TexturePackPage::TexturePackPage(MinecraftInstance* instance, std::shared_ptr<Te
ui->actionViewConfigs->setVisible(false);
}
-bool TexturePackPage::onSelectionChanged(const QModelIndex& current, const QModelIndex& previous)
+bool TexturePackPage::onSelectionChanged(const QModelIndex& current, [[maybe_unused]] const QModelIndex& previous)
{
auto sourceCurrent = m_filterModel->mapToSource(current);
int row = sourceCurrent.row();
diff --git a/launcher/ui/pages/instance/VersionPage.cpp b/launcher/ui/pages/instance/VersionPage.cpp
index a180c804..e22c764c 100644
--- a/launcher/ui/pages/instance/VersionPage.cpp
+++ b/launcher/ui/pages/instance/VersionPage.cpp
@@ -6,7 +6,7 @@
* Prism Launcher - Minecraft Launcher
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
* Copyright (C) 2022-2023 Sefa Eyeoglu <contact@scrumplex.net>
- * Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
+ * Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -51,6 +51,7 @@
#include <QUrl>
#include "VersionPage.h"
+#include "ui/dialogs/InstallLoaderDialog.h"
#include "ui_VersionPage.h"
#include "ui/dialogs/CustomMessageBox.h"
@@ -165,14 +166,17 @@ VersionPage::VersionPage(MinecraftInstance* inst, QWidget* parent) : QMainWindow
ui->packageView->setSelectionMode(QAbstractItemView::SingleSelection);
ui->packageView->setContextMenuPolicy(Qt::CustomContextMenu);
- connect(ui->packageView->selectionModel(), &QItemSelectionModel::currentChanged, this, &VersionPage::versionCurrent);
auto smodel = ui->packageView->selectionModel();
+ connect(smodel, &QItemSelectionModel::currentChanged, this, &VersionPage::versionCurrent);
connect(smodel, &QItemSelectionModel::currentChanged, this, &VersionPage::packageCurrent);
-
connect(m_profile.get(), &PackProfile::minecraftChanged, this, &VersionPage::updateVersionControls);
updateVersionControls();
preselect(0);
connect(ui->packageView, &ModListView::customContextMenuRequested, this, &VersionPage::showContextMenu);
+ connect(ui->packageView, &QAbstractItemView::activated, this, [this](const QModelIndex& index) {
+ auto component = m_profile->getComponent(index.row());
+ component->setEnabled(!component->isEnabled());
+ });
connect(ui->filterEdit, &QLineEdit::textChanged, this, &VersionPage::onFilterTextChanged);
}
@@ -188,7 +192,7 @@ void VersionPage::showContextMenu(const QPoint& pos)
delete menu;
}
-void VersionPage::packageCurrent(const QModelIndex& current, const QModelIndex& previous)
+void VersionPage::packageCurrent(const QModelIndex& current, [[maybe_unused]] const QModelIndex& previous)
{
if (!current.isValid()) {
ui->frame->clear();
@@ -226,18 +230,6 @@ void VersionPage::packageCurrent(const QModelIndex& current, const QModelIndex&
void VersionPage::updateVersionControls()
{
- // FIXME: this is a dirty hack
- auto minecraftVersion = Version(m_profile->getComponentVersion("net.minecraft"));
-
- bool supportsFabric = minecraftVersion >= Version("1.14");
- ui->actionInstall_Fabric->setEnabled(supportsFabric);
-
- bool supportsQuilt = minecraftVersion >= Version("1.14");
- ui->actionInstall_Quilt->setEnabled(supportsQuilt);
-
- bool supportsLiteLoader = minecraftVersion <= Version("1.12.2");
- ui->actionInstall_LiteLoader->setEnabled(supportsLiteLoader);
-
updateButtons();
}
@@ -389,20 +381,14 @@ void VersionPage::on_actionChange_version_triggered()
return;
}
auto uid = list->uid();
- // FIXME: this is a horrible HACK. Get version filtering information from the actual metadata...
- if (uid == "net.minecraftforge") {
- on_actionInstall_Forge_triggered();
- return;
- } else if (uid == "com.mumfrey.liteloader") {
- on_actionInstall_LiteLoader_triggered();
- return;
- }
+
VersionSelectDialog vselect(list.get(), tr("Change %1 version").arg(name), this);
if (uid == "net.fabricmc.intermediary" || uid == "org.quiltmc.hashed") {
vselect.setEmptyString(tr("No intermediary mappings versions are currently available."));
vselect.setEmptyErrorString(tr("Couldn't load or download the intermediary mappings version lists!"));
- vselect.setExactFilter(BaseVersionList::ParentVersionRole, m_profile->getComponentVersion("net.minecraft"));
}
+ vselect.setExactIfPresentFilter(BaseVersionList::ParentVersionRole, m_profile->getComponentVersion("net.minecraft"));
+
auto currentVersion = patch->getVersion();
if (!currentVersion.isEmpty()) {
vselect.setCurrentVersion(currentVersion);
@@ -425,7 +411,7 @@ void VersionPage::on_actionDownload_All_triggered()
if (!APPLICATION->accounts()->anyAccountIsValid()) {
CustomMessageBox::selectable(this, tr("Error"),
tr("Cannot download Minecraft or update instances unless you have at least "
- "one account added.\nPlease add your Mojang or Minecraft account."),
+ "one account added.\nPlease add your Microsoft or Mojang account."),
QMessageBox::Warning)
->show();
return;
@@ -443,79 +429,11 @@ void VersionPage::on_actionDownload_All_triggered()
m_container->refreshContainer();
}
-void VersionPage::on_actionInstall_Forge_triggered()
-{
- auto vlist = APPLICATION->metadataIndex()->get("net.minecraftforge");
- if (!vlist) {
- return;
- }
- VersionSelectDialog vselect(vlist.get(), tr("Select Forge version"), this);
- vselect.setExactFilter(BaseVersionList::ParentVersionRole, m_profile->getComponentVersion("net.minecraft"));
- vselect.setEmptyString(tr("No Forge versions are currently available for Minecraft ") +
- m_profile->getComponentVersion("net.minecraft"));
- vselect.setEmptyErrorString(tr("Couldn't load or download the Forge version lists!"));
-
- auto currentVersion = m_profile->getComponentVersion("net.minecraftforge");
- if (!currentVersion.isEmpty()) {
- vselect.setCurrentVersion(currentVersion);
- }
-
- if (vselect.exec() && vselect.selectedVersion()) {
- auto vsn = vselect.selectedVersion();
- m_profile->setComponentVersion("net.minecraftforge", vsn->descriptor());
- m_profile->resolve(Net::Mode::Online);
- // m_profile->installVersion();
- preselect(m_profile->rowCount(QModelIndex()) - 1);
- m_container->refreshContainer();
- }
-}
-
-void VersionPage::on_actionInstall_Fabric_triggered()
-{
- auto vlist = APPLICATION->metadataIndex()->get("net.fabricmc.fabric-loader");
- if (!vlist) {
- return;
- }
- VersionSelectDialog vselect(vlist.get(), tr("Select Fabric Loader version"), this);
- vselect.setEmptyString(tr("No Fabric Loader versions are currently available."));
- vselect.setEmptyErrorString(tr("Couldn't load or download the Fabric Loader version lists!"));
-
- auto currentVersion = m_profile->getComponentVersion("net.fabricmc.fabric-loader");
- if (!currentVersion.isEmpty()) {
- vselect.setCurrentVersion(currentVersion);
- }
-
- if (vselect.exec() && vselect.selectedVersion()) {
- auto vsn = vselect.selectedVersion();
- m_profile->setComponentVersion("net.fabricmc.fabric-loader", vsn->descriptor());
- m_profile->resolve(Net::Mode::Online);
- preselect(m_profile->rowCount(QModelIndex()) - 1);
- m_container->refreshContainer();
- }
-}
-
-void VersionPage::on_actionInstall_Quilt_triggered()
+void VersionPage::on_actionInstall_Loader_triggered()
{
- auto vlist = APPLICATION->metadataIndex()->get("org.quiltmc.quilt-loader");
- if (!vlist) {
- return;
- }
- VersionSelectDialog vselect(vlist.get(), tr("Select Quilt Loader version"), this);
- vselect.setEmptyString(tr("No Quilt Loader versions are currently available."));
- vselect.setEmptyErrorString(tr("Couldn't load or download the Quilt Loader version lists!"));
-
- auto currentVersion = m_profile->getComponentVersion("org.quiltmc.quilt-loader");
- if (!currentVersion.isEmpty()) {
- vselect.setCurrentVersion(currentVersion);
- }
-
- if (vselect.exec() && vselect.selectedVersion()) {
- auto vsn = vselect.selectedVersion();
- m_profile->setComponentVersion("org.quiltmc.quilt-loader", vsn->descriptor());
- m_profile->resolve(Net::Mode::Online);
- preselect(m_profile->rowCount(QModelIndex()) - 1);
- m_container->refreshContainer();
- }
+ InstallLoaderDialog dialog(m_inst->getPackProfile(), QString(), this);
+ dialog.exec();
+ m_container->refreshContainer();
}
void VersionPage::on_actionAdd_Empty_triggered()
@@ -534,33 +452,6 @@ void VersionPage::on_actionAdd_Empty_triggered()
}
}
-void VersionPage::on_actionInstall_LiteLoader_triggered()
-{
- auto vlist = APPLICATION->metadataIndex()->get("com.mumfrey.liteloader");
- if (!vlist) {
- return;
- }
- VersionSelectDialog vselect(vlist.get(), tr("Select LiteLoader version"), this);
- vselect.setExactFilter(BaseVersionList::ParentVersionRole, m_profile->getComponentVersion("net.minecraft"));
- vselect.setEmptyString(tr("No LiteLoader versions are currently available for Minecraft ") +
- m_profile->getComponentVersion("net.minecraft"));
- vselect.setEmptyErrorString(tr("Couldn't load or download the LiteLoader version lists!"));
-
- auto currentVersion = m_profile->getComponentVersion("com.mumfrey.liteloader");
- if (!currentVersion.isEmpty()) {
- vselect.setCurrentVersion(currentVersion);
- }
-
- if (vselect.exec() && vselect.selectedVersion()) {
- auto vsn = vselect.selectedVersion();
- m_profile->setComponentVersion("com.mumfrey.liteloader", vsn->descriptor());
- m_profile->resolve(Net::Mode::Online);
- // m_profile->installVersion(vselect.selectedVersion());
- preselect(m_profile->rowCount(QModelIndex()) - 1);
- m_container->refreshContainer();
- }
-}
-
void VersionPage::on_actionLibrariesFolder_triggered()
{
DesktopServices::openDirectory(m_inst->getLocalLibraryPath(), true);
@@ -571,7 +462,7 @@ void VersionPage::on_actionMinecraftFolder_triggered()
DesktopServices::openDirectory(m_inst->gameRoot(), true);
}
-void VersionPage::versionCurrent(const QModelIndex& current, const QModelIndex& previous)
+void VersionPage::versionCurrent(const QModelIndex& current, [[maybe_unused]] const QModelIndex& previous)
{
currentIdx = current.row();
updateButtons(currentIdx);
diff --git a/launcher/ui/pages/instance/VersionPage.h b/launcher/ui/pages/instance/VersionPage.h
index 45d383f4..6915be88 100644
--- a/launcher/ui/pages/instance/VersionPage.h
+++ b/launcher/ui/pages/instance/VersionPage.h
@@ -68,11 +68,8 @@ class VersionPage : public QMainWindow, public BasePage {
private slots:
void on_actionChange_version_triggered();
- void on_actionInstall_Forge_triggered();
- void on_actionInstall_Fabric_triggered();
- void on_actionInstall_Quilt_triggered();
+ void on_actionInstall_Loader_triggered();
void on_actionAdd_Empty_triggered();
- void on_actionInstall_LiteLoader_triggered();
void on_actionReload_triggered();
void on_actionRemove_triggered();
void on_actionMove_up_triggered();
diff --git a/launcher/ui/pages/instance/VersionPage.ui b/launcher/ui/pages/instance/VersionPage.ui
index a73c42d6..9be21d49 100644
--- a/launcher/ui/pages/instance/VersionPage.ui
+++ b/launcher/ui/pages/instance/VersionPage.ui
@@ -98,11 +98,7 @@
<addaction name="actionEdit"/>
<addaction name="actionRevert"/>
<addaction name="separator"/>
- <addaction name="actionInstall_Forge"/>
- <addaction name="actionInstall_Fabric"/>
- <addaction name="actionInstall_Quilt"/>
- <addaction name="actionInstall_LiteLoader"/>
- <addaction name="separator"/>
+ <addaction name="actionInstall_Loader"/>
<addaction name="actionAdd_to_Minecraft_jar"/>
<addaction name="actionReplace_Minecraft_jar"/>
<addaction name="actionAdd_Agents"/>
@@ -116,26 +112,26 @@
</widget>
<action name="actionChange_version">
<property name="text">
- <string>Change version</string>
+ <string>Change Version</string>
</property>
<property name="toolTip">
- <string>Change version of the selected package.</string>
+ <string>Change version of the selected component.</string>
</property>
</action>
<action name="actionMove_up">
<property name="text">
- <string>Move up</string>
+ <string>Move Up</string>
</property>
<property name="toolTip">
- <string>Make the selected package apply sooner.</string>
+ <string>Make the selected component apply sooner.</string>
</property>
</action>
<action name="actionMove_down">
<property name="text">
- <string>Move down</string>
+ <string>Move Down</string>
</property>
<property name="toolTip">
- <string>Make the selected package apply later.</string>
+ <string>Make the selected component apply later.</string>
</property>
</action>
<action name="actionRemove">
@@ -143,7 +139,7 @@
<string>Remove</string>
</property>
<property name="toolTip">
- <string>Remove selected package from the instance.</string>
+ <string>Remove selected component from the instance.</string>
</property>
</action>
<action name="actionCustomize">
@@ -151,7 +147,7 @@
<string>Customize</string>
</property>
<property name="toolTip">
- <string>Customize selected package.</string>
+ <string>Customize selected component.</string>
</property>
</action>
<action name="actionEdit">
@@ -159,7 +155,7 @@
<string>Edit</string>
</property>
<property name="toolTip">
- <string>Edit selected package.</string>
+ <string>Edit selected component.</string>
</property>
</action>
<action name="actionRevert">
@@ -167,39 +163,15 @@
<string>Revert</string>
</property>
<property name="toolTip">
- <string>Revert the selected package to default.</string>
- </property>
- </action>
- <action name="actionInstall_Forge">
- <property name="text">
- <string>Install Forge</string>
- </property>
- <property name="toolTip">
- <string>Install the Minecraft Forge package.</string>
- </property>
- </action>
- <action name="actionInstall_Fabric">
- <property name="text">
- <string>Install Fabric</string>
- </property>
- <property name="toolTip">
- <string>Install the Fabric Loader package.</string>
- </property>
- </action>
- <action name="actionInstall_Quilt">
- <property name="text">
- <string>Install Quilt</string>
- </property>
- <property name="toolTip">
- <string>Install the Quilt Loader package.</string>
+ <string>Revert the selected component to default.</string>
</property>
</action>
- <action name="actionInstall_LiteLoader">
+ <action name="actionInstall_Loader">
<property name="text">
- <string>Install LiteLoader</string>
+ <string>Install Loader</string>
</property>
<property name="toolTip">
- <string>Install the LiteLoader package.</string>
+ <string>Install a mod loader.</string>
</property>
</action>
<action name="actionAdd_to_Minecraft_jar">
@@ -228,7 +200,7 @@
<string>Add Empty</string>
</property>
<property name="toolTip">
- <string>Add an empty custom package.</string>
+ <string>Add an empty custom component.</string>
</property>
</action>
<action name="actionReload">
@@ -236,12 +208,12 @@
<string>Reload</string>
</property>
<property name="toolTip">
- <string>Reload all packages.</string>
+ <string>Reload all components.</string>
</property>
</action>
<action name="actionDownload_All">
<property name="text">
- <string>Download All</string>
+ <string>Download all</string>
</property>
<property name="toolTip">
<string>Download the files needed to launch the instance now.</string>
diff --git a/launcher/ui/pages/instance/WorldListPage.cpp b/launcher/ui/pages/instance/WorldListPage.cpp
index fe477616..587bb6ce 100644
--- a/launcher/ui/pages/instance/WorldListPage.cpp
+++ b/launcher/ui/pages/instance/WorldListPage.cpp
@@ -327,7 +327,7 @@ void WorldListPage::mceditState(LoggedProcess::State state)
}
}
-void WorldListPage::worldChanged(const QModelIndex& current, const QModelIndex& previous)
+void WorldListPage::worldChanged([[maybe_unused]] const QModelIndex& current, [[maybe_unused]] const QModelIndex& previous)
{
QModelIndex index = getSelectedWorld();
bool enable = index.isValid();
diff --git a/launcher/ui/pages/modplatform/CustomPage.cpp b/launcher/ui/pages/modplatform/CustomPage.cpp
index 4ac21b01..068fb3a3 100644
--- a/launcher/ui/pages/modplatform/CustomPage.cpp
+++ b/launcher/ui/pages/modplatform/CustomPage.cpp
@@ -127,6 +127,9 @@ void CustomPage::loaderFilterChanged()
ui->loaderVersionList->setEmptyString(tr("No mod loader is selected."));
ui->loaderVersionList->setEmptyMode(VersionListView::String);
return;
+ } else if (ui->neoForgeFilter->isChecked()) {
+ ui->loaderVersionList->setExactFilter(BaseVersionList::ParentVersionRole, minecraftVersion);
+ m_selectedLoader = "net.neoforged";
} else if (ui->forgeFilter->isChecked()) {
ui->loaderVersionList->setExactFilter(BaseVersionList::ParentVersionRole, minecraftVersion);
m_selectedLoader = "net.minecraftforge";
diff --git a/launcher/ui/pages/modplatform/CustomPage.ui b/launcher/ui/pages/modplatform/CustomPage.ui
index 0d89b595..23351ccd 100644
--- a/launcher/ui/pages/modplatform/CustomPage.ui
+++ b/launcher/ui/pages/modplatform/CustomPage.ui
@@ -195,6 +195,16 @@
</widget>
</item>
<item>
+ <widget class="QRadioButton" name="neoForgeFilter">
+ <property name="text">
+ <string>NeoForge</string>
+ </property>
+ <attribute name="buttonGroup">
+ <string notr="true">loaderBtnGroup</string>
+ </attribute>
+ </widget>
+ </item>
+ <item>
<widget class="QRadioButton" name="forgeFilter">
<property name="text">
<string>Forge</string>
diff --git a/launcher/ui/pages/modplatform/ImportPage.cpp b/launcher/ui/pages/modplatform/ImportPage.cpp
index ba53d033..3e3c36b7 100644
--- a/launcher/ui/pages/modplatform/ImportPage.cpp
+++ b/launcher/ui/pages/modplatform/ImportPage.cpp
@@ -35,20 +35,28 @@
*/
#include "ImportPage.h"
+
+#include "ui/dialogs/ProgressDialog.h"
#include "ui_ImportPage.h"
#include <QFileDialog>
#include <QValidator>
+#include <utility>
+#include "ui/dialogs/CustomMessageBox.h"
#include "ui/dialogs/NewInstanceDialog.h"
+#include "modplatform/flame/FlameAPI.h"
+
+#include "Json.h"
+
#include "InstanceImportTask.h"
class UrlValidator : public QValidator {
public:
using QValidator::QValidator;
- State validate(QString& in, int& pos) const
+ State validate(QString& in, [[maybe_unused]] int& pos) const
{
const QUrl url(in);
if (url.isValid() && !url.isRelative() && !url.isEmpty()) {
@@ -106,10 +114,61 @@ void ImportPage::updateState()
bool isMRPack = fi.suffix() == "mrpack";
if (fi.exists() && (isZip || isMRPack)) {
- QFileInfo fi(url.fileName());
- dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url, this));
+ auto extra_info = QMap(m_extra_info);
+ qDebug() << "Pack Extra Info" << extra_info << m_extra_info;
+ dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url, this, std::move(extra_info)));
dialog->setSuggestedIcon("default");
}
+ } else if (url.scheme() == "curseforge") {
+ // need to find the download link for the modpack
+ // format of url curseforge://install?addonId=IDHERE&fileId=IDHERE
+ QUrlQuery query(url);
+ auto addonId = query.allQueryItemValues("addonId")[0];
+ auto fileId = query.allQueryItemValues("fileId")[0];
+ auto array = std::make_shared<QByteArray>();
+
+ auto api = FlameAPI();
+ auto job = api.getFile(addonId, fileId, array);
+
+ connect(job.get(), &NetJob::failed, this,
+ [this](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show(); });
+ connect(job.get(), &NetJob::succeeded, this, [this, array, addonId, fileId] {
+ qDebug() << "Returned CFURL Json:\n" << array->toStdString().c_str();
+ auto doc = Json::requireDocument(*array);
+ auto data = Json::ensureObject(Json::ensureObject(doc.object()), "data");
+ // No way to find out if it's a mod or a modpack before here
+ // And also we need to check if it ends with .zip, instead of any better way
+ auto fileName = Json::ensureString(data, "fileName");
+ if (fileName.endsWith(".zip")) {
+ // Have to use ensureString then use QUrl to get proper url encoding
+ auto dl_url = QUrl(Json::ensureString(data, "downloadUrl", "", "downloadUrl"));
+ if (!dl_url.isValid()) {
+ CustomMessageBox::selectable(
+ this, tr("Error"),
+ tr("The modpack %1 is blocked for third-parties! Please download it manually.").arg(fileName),
+ QMessageBox::Critical)
+ ->show();
+ return;
+ }
+
+ QFileInfo dl_file(dl_url.fileName());
+ QString pack_name = Json::ensureString(data, "displayName", dl_file.completeBaseName(), "displayName");
+
+ QMap<QString, QString> extra_info;
+ extra_info.insert("pack_id", addonId);
+ extra_info.insert("pack_version_id", fileId);
+
+ dialog->setSuggestedPack(pack_name, new InstanceImportTask(dl_url, this, std::move(extra_info)));
+ dialog->setSuggestedIcon("default");
+
+ } else {
+ CustomMessageBox::selectable(this, tr("Error"), tr("This url isn't a valid modpack !"), QMessageBox::Critical)->show();
+ }
+ });
+ ProgressDialog dlUrlDialod(this);
+ dlUrlDialod.setSkipButton(true, tr("Abort"));
+ dlUrlDialod.execWithTask(job.get());
+ return;
} else {
if (input.endsWith("?client=y")) {
input.chop(9);
@@ -118,7 +177,8 @@ void ImportPage::updateState()
}
// hook, line and sinker.
QFileInfo fi(url.fileName());
- dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url, this));
+ auto extra_info = QMap(m_extra_info);
+ dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url, this, std::move(extra_info)));
dialog->setSuggestedIcon("default");
}
} else {
@@ -132,6 +192,12 @@ void ImportPage::setUrl(const QString& url)
updateState();
}
+void ImportPage::setExtraInfo(const QMap<QString, QString>& extra_info)
+{
+ m_extra_info = extra_info;
+ updateState();
+}
+
void ImportPage::on_modpackBtn_clicked()
{
auto filter = QMimeDatabase().mimeTypeForName("application/zip").filterString();
diff --git a/launcher/ui/pages/modplatform/ImportPage.h b/launcher/ui/pages/modplatform/ImportPage.h
index d846d566..70d7736e 100644
--- a/launcher/ui/pages/modplatform/ImportPage.h
+++ b/launcher/ui/pages/modplatform/ImportPage.h
@@ -62,7 +62,7 @@ class ImportPage : public QWidget, public BasePage {
void setUrl(const QString& url);
void openedImpl() override;
-
+ void setExtraInfo(const QMap<QString, QString>& extra_info);
private slots:
void on_modpackBtn_clicked();
void updateState();
@@ -73,4 +73,5 @@ class ImportPage : public QWidget, public BasePage {
private:
Ui::ImportPage* ui = nullptr;
NewInstanceDialog* dialog = nullptr;
+ QMap<QString, QString> m_extra_info = {};
};
diff --git a/launcher/ui/pages/modplatform/ImportPage.ui b/launcher/ui/pages/modplatform/ImportPage.ui
index 3583cf90..9a9736b8 100644
--- a/launcher/ui/pages/modplatform/ImportPage.ui
+++ b/launcher/ui/pages/modplatform/ImportPage.ui
@@ -40,7 +40,7 @@
<item>
<widget class="QLabel" name="label_5">
<property name="text">
- <string>- CurseForge modpacks (ZIP)</string>
+ <string>- CurseForge modpacks (ZIP / curseforge:// URL)</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
diff --git a/launcher/ui/pages/modplatform/ModModel.cpp b/launcher/ui/pages/modplatform/ModModel.cpp
index b7537890..c628f74a 100644
--- a/launcher/ui/pages/modplatform/ModModel.cpp
+++ b/launcher/ui/pages/modplatform/ModModel.cpp
@@ -33,7 +33,7 @@ ResourceAPI::SearchArgs ModModel::createSearchArguments()
auto sort = getCurrentSortingMethodByIndex();
- return { ModPlatform::ResourceType::MOD, m_next_search_offset, m_search_term, sort, profile->getModLoaders(), versions };
+ return { ModPlatform::ResourceType::MOD, m_next_search_offset, m_search_term, sort, profile->getSupportedModLoaders(), versions };
}
ResourceAPI::VersionSearchArgs ModModel::createVersionsArguments(QModelIndex& entry)
@@ -48,7 +48,7 @@ ResourceAPI::VersionSearchArgs ModModel::createVersionsArguments(QModelIndex& en
if (!m_filter->versions.empty())
versions = m_filter->versions;
- return { pack, versions, profile->getModLoaders() };
+ return { pack, versions, profile->getSupportedModLoaders() };
}
ResourceAPI::ProjectInfoArgs ModModel::createInfoArguments(QModelIndex& entry)
diff --git a/launcher/ui/pages/modplatform/ModPage.cpp b/launcher/ui/pages/modplatform/ModPage.cpp
index 9b178048..d6cc1fdc 100644
--- a/launcher/ui/pages/modplatform/ModPage.cpp
+++ b/launcher/ui/pages/modplatform/ModPage.cpp
@@ -124,8 +124,7 @@ void ModPage::updateVersionList()
auto version = current_pack->versions[i];
bool valid = false;
for (auto& mcVer : m_filter->versions) {
- // NOTE: Flame doesn't care about loader, so passing it changes nothing.
- if (validateVersion(version, mcVer.toString(), packProfile->getModLoaders())) {
+ if (validateVersion(version, mcVer.toString(), packProfile->getSupportedModLoaders())) {
valid = true;
break;
}
diff --git a/launcher/ui/pages/modplatform/ModPage.h b/launcher/ui/pages/modplatform/ModPage.h
index 5510c191..5a43e49a 100644
--- a/launcher/ui/pages/modplatform/ModPage.h
+++ b/launcher/ui/pages/modplatform/ModPage.h
@@ -55,7 +55,7 @@ class ModPage : public ResourcePage {
virtual auto validateVersion(ModPlatform::IndexedVersion& ver,
QString mineVer,
- std::optional<ResourceAPI::ModLoaderTypes> loaders = {}) const -> bool = 0;
+ std::optional<ModPlatform::ModLoaderTypes> loaders = {}) const -> bool = 0;
[[nodiscard]] bool supportsFiltering() const override { return true; };
auto getFilter() const -> const std::shared_ptr<ModFilterWidget::Filter> { return m_filter; }
diff --git a/launcher/ui/pages/modplatform/ResourceModel.cpp b/launcher/ui/pages/modplatform/ResourceModel.cpp
index 49405a02..cb8f1920 100644
--- a/launcher/ui/pages/modplatform/ResourceModel.cpp
+++ b/launcher/ui/pages/modplatform/ResourceModel.cpp
@@ -17,7 +17,7 @@
#include "BuildConfig.h"
#include "Json.h"
-#include "net/Download.h"
+#include "net/ApiDownload.h"
#include "net/NetJob.h"
#include "modplatform/ModIndex.h"
@@ -102,7 +102,7 @@ QHash<int, QByteArray> ResourceModel::roleNames() const
return roles;
}
-bool ResourceModel::setData(const QModelIndex& index, const QVariant& value, int role)
+bool ResourceModel::setData(const QModelIndex& index, const QVariant& value, [[maybe_unused]] int role)
{
int pos = index.row();
if (pos >= m_packs.size() || pos < 0 || !index.isValid())
@@ -132,6 +132,32 @@ void ResourceModel::search()
if (hasActiveSearchJob())
return;
+ if (m_search_term.startsWith("#")) {
+ auto projectId = m_search_term.mid(1);
+ if (!projectId.isEmpty()) {
+ ResourceAPI::ProjectInfoCallbacks callbacks;
+
+ callbacks.on_fail = [this](QString reason) {
+ if (!s_running_models.constFind(this).value())
+ return;
+ searchRequestFailed(reason, -1);
+ };
+ callbacks.on_abort = [this] {
+ if (!s_running_models.constFind(this).value())
+ return;
+ searchRequestAborted();
+ };
+
+ callbacks.on_succeed = [this](auto& doc, auto& pack) {
+ if (!s_running_models.constFind(this).value())
+ return;
+ searchRequestForOneSucceeded(doc);
+ };
+ if (auto job = m_api->getProjectInfo({ projectId }, std::move(callbacks)); job)
+ runSearchJob(job);
+ return;
+ }
+ }
auto args{ createSearchArguments() };
auto callbacks{ createSearchCallbacks() };
@@ -189,11 +215,18 @@ void ResourceModel::loadEntry(QModelIndex& entry)
// Use default if no callbacks are set
if (!callbacks.on_succeed)
- callbacks.on_succeed = [this, entry](auto& doc, auto pack) {
+ callbacks.on_succeed = [this, entry](auto& doc, auto& newpack) {
if (!s_running_models.constFind(this).value())
return;
+ auto pack = newpack;
infoRequestSucceeded(doc, pack, entry);
};
+ if (!callbacks.on_fail)
+ callbacks.on_fail = [this](QString reason) {
+ if (!s_running_models.constFind(this).value())
+ return;
+ QMessageBox::critical(nullptr, tr("Error"), tr("A network error occurred. Could not load project info:%1").arg(reason));
+ };
if (auto job = m_api->getProjectInfo(std::move(args), std::move(callbacks)); job)
runInfoJob(job);
@@ -281,7 +314,7 @@ std::optional<QIcon> ResourceModel::getIcon(QModelIndex& index, const QUrl& url)
auto cache_entry = APPLICATION->metacache()->resolveEntry(
metaEntryBase(),
QString("logos/%1").arg(QString(QCryptographicHash::hash(url.toEncoded(), QCryptographicHash::Algorithm::Sha1).toHex())));
- auto icon_fetch_action = Net::Download::makeCached(url, cache_entry);
+ auto icon_fetch_action = Net::ApiDownload::makeCached(url, cache_entry);
auto full_file_path = cache_entry->getFullPath();
connect(icon_fetch_action.get(), &NetAction::succeeded, this, [=] {
@@ -310,7 +343,7 @@ std::optional<QIcon> ResourceModel::getIcon(QModelIndex& index, const QUrl& url)
#define NEED_FOR_CALLBACK_ASSERT(name) \
Q_ASSERT_X(0 != 0, #name, "You NEED to re-implement this if you intend on using the default callbacks.")
-QJsonArray ResourceModel::documentToArray(QJsonDocument& doc) const
+QJsonArray ResourceModel::documentToArray([[maybe_unused]] QJsonDocument& doc) const
{
NEED_FOR_CALLBACK_ASSERT("documentToArray");
return {};
@@ -372,7 +405,28 @@ void ResourceModel::searchRequestSucceeded(QJsonDocument& doc)
endInsertRows();
}
-void ResourceModel::searchRequestFailed(QString reason, int network_error_code)
+void ResourceModel::searchRequestForOneSucceeded(QJsonDocument& doc)
+{
+ ModPlatform::IndexedPack::Ptr pack = std::make_shared<ModPlatform::IndexedPack>();
+
+ try {
+ auto obj = Json::requireObject(doc);
+ if (obj.contains("data"))
+ obj = Json::requireObject(obj, "data");
+ loadIndexedPack(*pack, obj);
+ } catch (const JSONValidationError& e) {
+ qDebug() << doc;
+ qWarning() << "Error while reading " << debugName() << " resource info: " << e.cause();
+ }
+
+ m_search_state = SearchState::Finished;
+
+ beginInsertRows(QModelIndex(), m_packs.size(), m_packs.size() + 1);
+ m_packs.append(pack);
+ endInsertRows();
+}
+
+void ResourceModel::searchRequestFailed([[maybe_unused]] QString reason, int network_error_code)
{
switch (network_error_code) {
default:
diff --git a/launcher/ui/pages/modplatform/ResourceModel.h b/launcher/ui/pages/modplatform/ResourceModel.h
index 6533d9c6..ecf4f8f7 100644
--- a/launcher/ui/pages/modplatform/ResourceModel.h
+++ b/launcher/ui/pages/modplatform/ResourceModel.h
@@ -42,7 +42,10 @@ class ResourceModel : public QAbstractListModel {
[[nodiscard]] virtual auto debugName() const -> QString;
[[nodiscard]] virtual auto metaEntryBase() const -> QString = 0;
- [[nodiscard]] inline int rowCount(const QModelIndex& parent) const override { return parent.isValid() ? 0 : m_packs.size(); }
+ [[nodiscard]] inline int rowCount(const QModelIndex& parent) const override
+ {
+ return parent.isValid() ? 0 : static_cast<int>(m_packs.size());
+ }
[[nodiscard]] inline int columnCount(const QModelIndex& parent) const override { return parent.isValid() ? 0 : 1; }
[[nodiscard]] inline auto flags(const QModelIndex& index) const -> Qt::ItemFlags override { return QAbstractListModel::flags(index); }
@@ -146,6 +149,7 @@ class ResourceModel : public QAbstractListModel {
private:
/* Default search request callbacks */
void searchRequestSucceeded(QJsonDocument&);
+ void searchRequestForOneSucceeded(QJsonDocument&);
void searchRequestFailed(QString reason, int network_error_code);
void searchRequestAborted();
diff --git a/launcher/ui/pages/modplatform/ResourcePackModel.cpp b/launcher/ui/pages/modplatform/ResourcePackModel.cpp
index 18c14bf8..d436f320 100644
--- a/launcher/ui/pages/modplatform/ResourcePackModel.cpp
+++ b/launcher/ui/pages/modplatform/ResourcePackModel.cpp
@@ -9,7 +9,8 @@
namespace ResourceDownload {
ResourcePackResourceModel::ResourcePackResourceModel(BaseInstance const& base_inst, ResourceAPI* api)
- : ResourceModel(api), m_base_instance(base_inst){};
+ : ResourceModel(api), m_base_instance(base_inst)
+{}
/******** Make data requests ********/
diff --git a/launcher/ui/pages/modplatform/ResourcePage.cpp b/launcher/ui/pages/modplatform/ResourcePage.cpp
index 2925ec87..44a91003 100644
--- a/launcher/ui/pages/modplatform/ResourcePage.cpp
+++ b/launcher/ui/pages/modplatform/ResourcePage.cpp
@@ -4,7 +4,7 @@
/*
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
- * Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
+ * Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -44,9 +44,6 @@
#include <QKeyEvent>
#include "Markdown.h"
-#include "ResourceDownloadTask.h"
-
-#include "minecraft/MinecraftInstance.h"
#include "ui/dialogs/ResourceDownloadDialog.h"
#include "ui/pages/modplatform/ResourceModel.h"
@@ -283,7 +280,7 @@ void ResourcePage::updateVersionList()
updateSelectionButton();
}
-void ResourcePage::onSelectionChanged(QModelIndex curr, QModelIndex prev)
+void ResourcePage::onSelectionChanged(QModelIndex curr, [[maybe_unused]] QModelIndex prev)
{
if (!curr.isValid()) {
return;
@@ -310,9 +307,9 @@ void ResourcePage::onSelectionChanged(QModelIndex curr, QModelIndex prev)
updateUi();
}
-void ResourcePage::onVersionSelectionChanged(QString data)
+void ResourcePage::onVersionSelectionChanged(QString versionData)
{
- if (data.isNull() || data.isEmpty()) {
+ if (versionData.isNull() || versionData.isEmpty()) {
m_selected_version_index = -1;
return;
}
@@ -398,7 +395,7 @@ void ResourcePage::openUrl(const QUrl& url)
if (auto current_pack = getCurrentPack(); current_pack && slug != current_pack->slug) {
m_parent_dialog->selectPage(page);
- auto newPage = m_parent_dialog->getSelectedPage();
+ auto newPage = m_parent_dialog->selectedPage();
QLineEdit* searchEdit = newPage->m_ui->searchEdit;
auto model = newPage->m_model;
diff --git a/launcher/ui/pages/modplatform/ResourcePage.h b/launcher/ui/pages/modplatform/ResourcePage.h
index b4a87f57..7bec0a37 100644
--- a/launcher/ui/pages/modplatform/ResourcePage.h
+++ b/launcher/ui/pages/modplatform/ResourcePage.h
@@ -97,7 +97,11 @@ class ResourcePage : public QWidget, public BasePage {
virtual void openUrl(const QUrl&);
/** Whether the version is opted out or not. Currently only makes sense in CF. */
- virtual bool optedOut(ModPlatform::IndexedVersion& ver) const { return false; };
+ virtual bool optedOut(ModPlatform::IndexedVersion& ver) const
+ {
+ Q_UNUSED(ver);
+ return false;
+ };
public:
BaseInstance& m_base_instance;
diff --git a/launcher/ui/pages/modplatform/ShaderPackModel.cpp b/launcher/ui/pages/modplatform/ShaderPackModel.cpp
index aabd3be6..8c913657 100644
--- a/launcher/ui/pages/modplatform/ShaderPackModel.cpp
+++ b/launcher/ui/pages/modplatform/ShaderPackModel.cpp
@@ -9,7 +9,8 @@
namespace ResourceDownload {
ShaderPackResourceModel::ShaderPackResourceModel(BaseInstance const& base_inst, ResourceAPI* api)
- : ResourceModel(api), m_base_instance(base_inst){};
+ : ResourceModel(api), m_base_instance(base_inst)
+{}
/******** Make data requests ********/
diff --git a/launcher/ui/pages/modplatform/ShaderPackPage.cpp b/launcher/ui/pages/modplatform/ShaderPackPage.cpp
index fbf94e84..586dffc5 100644
--- a/launcher/ui/pages/modplatform/ShaderPackPage.cpp
+++ b/launcher/ui/pages/modplatform/ShaderPackPage.cpp
@@ -3,6 +3,7 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "ShaderPackPage.h"
+#include "modplatform/ModIndex.h"
#include "ui_ResourcePage.h"
#include "ShaderPackModel.h"
@@ -48,7 +49,7 @@ void ShaderPackResourcePage::addResourceToPage(ModPlatform::IndexedPack::Ptr pac
const std::shared_ptr<ResourceFolderModel> base_model)
{
QString custom_target_folder;
- if (version.loaders.contains(QStringLiteral("canvas")))
+ if (version.loaders & ModPlatform::Cauldron)
custom_target_folder = QStringLiteral("resourcepacks");
m_model->addPack(pack, version, base_model, false, custom_target_folder);
}
diff --git a/launcher/ui/pages/modplatform/atlauncher/AtlFilterModel.cpp b/launcher/ui/pages/modplatform/atlauncher/AtlFilterModel.cpp
index 9cd5eed5..dee3784e 100644
--- a/launcher/ui/pages/modplatform/atlauncher/AtlFilterModel.cpp
+++ b/launcher/ui/pages/modplatform/atlauncher/AtlFilterModel.cpp
@@ -67,9 +67,10 @@ bool FilterModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParen
if (searchTerm.isEmpty()) {
return true;
}
-
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
ATLauncher::IndexedPack pack = sourceModel()->data(index, Qt::UserRole).value<ATLauncher::IndexedPack>();
+ if (searchTerm.startsWith("#"))
+ return QString::number(pack.id) == searchTerm.mid(1);
return pack.name.contains(searchTerm, Qt::CaseInsensitive);
}
diff --git a/launcher/ui/pages/modplatform/atlauncher/AtlListModel.cpp b/launcher/ui/pages/modplatform/atlauncher/AtlListModel.cpp
index c6b087d6..b6fb7153 100644
--- a/launcher/ui/pages/modplatform/atlauncher/AtlListModel.cpp
+++ b/launcher/ui/pages/modplatform/atlauncher/AtlListModel.cpp
@@ -20,6 +20,9 @@
#include <BuildConfig.h>
#include <Json.h>
+#include "net/ApiDownload.h"
+#include "ui/widgets/ProjectItem.h"
+
namespace Atl {
ListModel::ListModel(QObject* parent) : QAbstractListModel(parent) {}
@@ -44,27 +47,50 @@ QVariant ListModel::data(const QModelIndex& index, int role) const
}
ATLauncher::IndexedPack pack = modpacks.at(pos);
- if (role == Qt::DisplayRole) {
- return pack.name;
- } else if (role == Qt::ToolTipRole) {
- return pack.name;
- } else if (role == Qt::DecorationRole) {
- if (m_logoMap.contains(pack.safeName)) {
- return (m_logoMap.value(pack.safeName));
+ switch (role) {
+ case Qt::ToolTipRole: {
+ if (pack.description.length() > 100) {
+ // some magic to prevent to long tooltips and replace html linebreaks
+ QString edit = pack.description.left(97);
+ edit = edit.left(edit.lastIndexOf("<br>")).left(edit.lastIndexOf(" ")).append("...");
+ return edit;
+ }
+ return pack.description;
}
- auto icon = APPLICATION->getThemedIcon("atlauncher-placeholder");
+ case Qt::DecorationRole: {
+ if (m_logoMap.contains(pack.safeName)) {
+ return (m_logoMap.value(pack.safeName));
+ }
+ auto icon = APPLICATION->getThemedIcon("atlauncher-placeholder");
- auto url = QString(BuildConfig.ATL_DOWNLOAD_SERVER_URL + "launcher/images/%1.png").arg(pack.safeName.toLower());
- ((ListModel*)this)->requestLogo(pack.safeName, url);
+ auto url = QString(BuildConfig.ATL_DOWNLOAD_SERVER_URL + "launcher/images/%1.png").arg(pack.safeName.toLower());
+ ((ListModel*)this)->requestLogo(pack.safeName, url);
- return icon;
- } else if (role == Qt::UserRole) {
- QVariant v;
- v.setValue(pack);
- return v;
+ return icon;
+ }
+ case Qt::UserRole: {
+ QVariant v;
+ v.setValue(pack);
+ return v;
+ }
+ case Qt::DisplayRole:
+ return pack.name;
+ case Qt::SizeHintRole:
+ return QSize(0, 58);
+ // Custom data
+ case UserDataTypes::TITLE:
+ return pack.name;
+ case UserDataTypes::DESCRIPTION:
+ return pack.description;
+ case UserDataTypes::SELECTED:
+ return false;
+ case UserDataTypes::INSTALLED:
+ return false;
+ default:
+ break;
}
- return QVariant();
+ return {};
}
void ListModel::request()
@@ -75,7 +101,7 @@ void ListModel::request()
auto netJob = makeShared<NetJob>("Atl::Request", APPLICATION->network());
auto url = QString(BuildConfig.ATL_DOWNLOAD_SERVER_URL + "launcher/json/packsnew.json");
- netJob->addNetAction(Net::Download::makeByteArray(QUrl(url), response));
+ netJob->addNetAction(Net::ApiDownload::makeByteArray(QUrl(url), response));
jobPtr = netJob;
jobPtr->start();
@@ -137,8 +163,7 @@ void ListModel::requestFailed(QString reason)
void ListModel::getLogo(const QString& logo, const QString& logoUrl, LogoCallback callback)
{
if (m_logoMap.contains(logo)) {
- callback(
- APPLICATION->metacache()->resolveEntry("ATLauncherPacks", QString("logos/%1").arg(logo.section(".", 0, 0)))->getFullPath());
+ callback(APPLICATION->metacache()->resolveEntry("ATLauncherPacks", QString("logos/%1").arg(logo))->getFullPath());
} else {
requestLogo(logo, logoUrl);
}
@@ -168,9 +193,9 @@ void ListModel::requestLogo(QString file, QString url)
return;
}
- MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("ATLauncherPacks", QString("logos/%1").arg(file.section(".", 0, 0)));
+ MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("ATLauncherPacks", QString("logos/%1").arg(file));
auto job = new NetJob(QString("ATLauncher Icon Download %1").arg(file), APPLICATION->network());
- job->addNetAction(Net::Download::makeCached(QUrl(url), entry));
+ job->addNetAction(Net::ApiDownload::makeCached(QUrl(url), entry));
auto fullPath = entry->getFullPath();
QObject::connect(job, &NetJob::succeeded, this, [this, file, fullPath, job] {
diff --git a/launcher/ui/pages/modplatform/atlauncher/AtlOptionalModDialog.cpp b/launcher/ui/pages/modplatform/atlauncher/AtlOptionalModDialog.cpp
index 62e406d3..6fb86773 100644
--- a/launcher/ui/pages/modplatform/atlauncher/AtlOptionalModDialog.cpp
+++ b/launcher/ui/pages/modplatform/atlauncher/AtlOptionalModDialog.cpp
@@ -43,6 +43,8 @@
#include "Json.h"
#include "modplatform/atlauncher/ATLShareCode.h"
+#include "net/ApiDownload.h"
+
AtlOptionalModListModel::AtlOptionalModListModel(QWidget* parent, ATLauncher::PackVersion version, QVector<ATLauncher::VersionMod> mods)
: QAbstractListModel(parent), m_version(version), m_mods(mods)
{
@@ -113,7 +115,7 @@ QVariant AtlOptionalModListModel::data(const QModelIndex& index, int role) const
return {};
}
-bool AtlOptionalModListModel::setData(const QModelIndex& index, const QVariant& value, int role)
+bool AtlOptionalModListModel::setData(const QModelIndex& index, [[maybe_unused]] const QVariant& value, int role)
{
if (role == Qt::CheckStateRole) {
auto row = index.row();
@@ -155,7 +157,7 @@ void AtlOptionalModListModel::useShareCode(const QString& code)
{
m_jobPtr.reset(new NetJob("Atl::Request", APPLICATION->network()));
auto url = QString(BuildConfig.ATL_API_BASE_URL + "share-codes/" + code);
- m_jobPtr->addNetAction(Net::Download::makeByteArray(QUrl(url), m_response));
+ m_jobPtr->addNetAction(Net::ApiDownload::makeByteArray(QUrl(url), m_response));
connect(m_jobPtr.get(), &NetJob::succeeded, this, &AtlOptionalModListModel::shareCodeSuccess);
connect(m_jobPtr.get(), &NetJob::failed, this, &AtlOptionalModListModel::shareCodeFailure);
@@ -206,7 +208,7 @@ void AtlOptionalModListModel::shareCodeSuccess()
emit dataChanged(AtlOptionalModListModel::index(0, EnabledColumn), AtlOptionalModListModel::index(m_mods.size() - 1, EnabledColumn));
}
-void AtlOptionalModListModel::shareCodeFailure(const QString& reason)
+void AtlOptionalModListModel::shareCodeFailure([[maybe_unused]] const QString& reason)
{
m_jobPtr.reset();
@@ -281,15 +283,15 @@ void AtlOptionalModListModel::setMod(ATLauncher::VersionMod mod, int index, bool
// if the dependency is 'effectively hidden', then track which mods
// depend on it - so we can efficiently disable it when no more dependents
// depend on it.
- auto dependants = m_dependants[dependencyName];
+ auto dependents = m_dependents[dependencyName];
if (enable) {
- dependants.append(mod.name);
+ dependents.append(mod.name);
} else {
- dependants.removeAll(mod.name);
+ dependents.removeAll(mod.name);
// if there are no longer any dependents, let's disable the mod
- if (dependencyMod.effectively_hidden && dependants.isEmpty()) {
+ if (dependencyMod.effectively_hidden && dependents.isEmpty()) {
setMod(dependencyMod, dependencyIndex, false, shouldEmit);
}
}
@@ -297,8 +299,8 @@ void AtlOptionalModListModel::setMod(ATLauncher::VersionMod mod, int index, bool
// disable mods that depend on this one, if disabling
if (!enable) {
- auto dependants = m_dependants[mod.name];
- for (const auto& dependencyName : dependants) {
+ auto dependents = m_dependents[mod.name];
+ for (const auto& dependencyName : dependents) {
auto dependencyIndex = m_index[dependencyName];
auto dependencyMod = m_mods.at(dependencyIndex);
diff --git a/launcher/ui/pages/modplatform/atlauncher/AtlOptionalModDialog.h b/launcher/ui/pages/modplatform/atlauncher/AtlOptionalModDialog.h
index 72a946da..55903003 100644
--- a/launcher/ui/pages/modplatform/atlauncher/AtlOptionalModDialog.h
+++ b/launcher/ui/pages/modplatform/atlauncher/AtlOptionalModDialog.h
@@ -90,7 +90,7 @@ class AtlOptionalModListModel : public QAbstractListModel {
QMap<QString, bool> m_selection;
QMap<QString, int> m_index;
- QMap<QString, QVector<QString>> m_dependants;
+ QMap<QString, QVector<QString>> m_dependents;
};
class AtlOptionalModDialog : public QDialog {
diff --git a/launcher/ui/pages/modplatform/atlauncher/AtlPage.cpp b/launcher/ui/pages/modplatform/atlauncher/AtlPage.cpp
index 4c9dec58..c7e80027 100644
--- a/launcher/ui/pages/modplatform/atlauncher/AtlPage.cpp
+++ b/launcher/ui/pages/modplatform/atlauncher/AtlPage.cpp
@@ -35,11 +35,11 @@
*/
#include "AtlPage.h"
+#include "ui/widgets/ProjectItem.h"
#include "ui_AtlPage.h"
#include "BuildConfig.h"
-#include "AtlOptionalModDialog.h"
#include "AtlUserInteractionSupportImpl.h"
#include "modplatform/atlauncher/ATLPackInstallTask.h"
#include "ui/dialogs/NewInstanceDialog.h"
@@ -71,6 +71,8 @@ AtlPage::AtlPage(NewInstanceDialog* dialog, QWidget* parent) : QWidget(parent),
connect(ui->sortByBox, &QComboBox::currentTextChanged, this, &AtlPage::onSortingSelectionChanged);
connect(ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &AtlPage::onSelectionChanged);
connect(ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &AtlPage::onVersionSelectionChanged);
+
+ ui->packView->setItemDelegate(new ProjectItemDelegate(this));
}
AtlPage::~AtlPage()
@@ -123,13 +125,13 @@ void AtlPage::triggerSearch()
filterModel->setSearchTerm(ui->searchEdit->text());
}
-void AtlPage::onSortingSelectionChanged(QString data)
+void AtlPage::onSortingSelectionChanged(QString sort)
{
- auto toSet = filterModel->getAvailableSortings().value(data);
+ auto toSet = filterModel->getAvailableSortings().value(sort);
filterModel->setSorting(toSet);
}
-void AtlPage::onSelectionChanged(QModelIndex first, QModelIndex second)
+void AtlPage::onSelectionChanged(QModelIndex first, [[maybe_unused]] QModelIndex second)
{
ui->versionSelectionBox->clear();
@@ -151,13 +153,13 @@ void AtlPage::onSelectionChanged(QModelIndex first, QModelIndex second)
suggestCurrent();
}
-void AtlPage::onVersionSelectionChanged(QString data)
+void AtlPage::onVersionSelectionChanged(QString version)
{
- if (data.isNull() || data.isEmpty()) {
+ if (version.isNull() || version.isEmpty()) {
selectedVersion = "";
return;
}
- selectedVersion = data;
+ selectedVersion = version;
suggestCurrent();
}
diff --git a/launcher/ui/pages/modplatform/atlauncher/AtlPage.ui b/launcher/ui/pages/modplatform/atlauncher/AtlPage.ui
index 746aa6d1..8b674733 100644
--- a/launcher/ui/pages/modplatform/atlauncher/AtlPage.ui
+++ b/launcher/ui/pages/modplatform/atlauncher/AtlPage.ui
@@ -11,21 +11,28 @@
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
- <item row="1" column="0" colspan="2">
- <layout class="QGridLayout" name="gridLayout_3">
- <item row="1" column="0">
- <widget class="QTreeView" name="packView">
- <property name="alternatingRowColors">
- <bool>true</bool>
+ <item row="3" column="0" colspan="2">
+ <layout class="QGridLayout" name="gridLayout_4" columnstretch="0,0,0" rowminimumheight="0" columnminimumwidth="0,0,0">
+ <item row="0" column="2">
+ <widget class="QComboBox" name="versionSelectionBox"/>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Version selected:</string>
</property>
- <property name="iconSize">
- <size>
- <width>96</width>
- <height>48</height>
- </size>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
+ <item row="0" column="0">
+ <widget class="QComboBox" name="sortByBox"/>
+ </item>
+ </layout>
+ </item>
+ <item row="2" column="0" colspan="2">
+ <layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="1">
<widget class="QTextBrowser" name="packDescription">
<property name="openExternalLinks">
@@ -36,39 +43,22 @@
</property>
</widget>
</item>
- <item row="0" column="0" colspan="2">
- <widget class="QLabel" name="label_2">
- <property name="text">
- <string>Warning: This is still a work in progress. If you run into issues with the imported modpack, it may be a bug.</string>
- </property>
- <property name="wordWrap">
+ <item row="1" column="0">
+ <widget class="QTreeView" name="packView">
+ <property name="alternatingRowColors">
<bool>true</bool>
</property>
- </widget>
- </item>
- </layout>
- </item>
- <item row="2" column="0" colspan="2">
- <layout class="QGridLayout" name="gridLayout_4" columnstretch="0,0,0" rowminimumheight="0" columnminimumwidth="0,0,0">
- <item row="0" column="2">
- <widget class="QComboBox" name="versionSelectionBox"/>
- </item>
- <item row="0" column="1">
- <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 name="iconSize">
+ <size>
+ <width>96</width>
+ <height>48</height>
+ </size>
</property>
</widget>
</item>
- <item row="0" column="0">
- <widget class="QComboBox" name="sortByBox"/>
- </item>
</layout>
</item>
- <item row="0" column="0">
+ <item row="1" column="0">
<widget class="QLineEdit" name="searchEdit">
<property name="placeholderText">
<string>Search and filter...</string>
@@ -78,6 +68,31 @@
</property>
</widget>
</item>
+ <item row="1" column="1">
+ <widget class="QPushButton" name="pushButton">
+ <property name="text">
+ <string>Search</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0" colspan="2">
+ <widget class="QLabel" name="label_2">
+ <property name="font">
+ <font>
+ <italic>true</italic>
+ </font>
+ </property>
+ <property name="text">
+ <string>Warning: This is still a work in progress. If you run into issues with the imported modpack, it may be a bug.</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
<tabstops>
diff --git a/launcher/ui/pages/modplatform/flame/FlameModel.cpp b/launcher/ui/pages/modplatform/flame/FlameModel.cpp
index 83c1270b..8875a945 100644
--- a/launcher/ui/pages/modplatform/flame/FlameModel.cpp
+++ b/launcher/ui/pages/modplatform/flame/FlameModel.cpp
@@ -1,8 +1,12 @@
#include "FlameModel.h"
#include <Json.h>
#include "Application.h"
+#include "modplatform/ResourceAPI.h"
+#include "modplatform/flame/FlameAPI.h"
#include "ui/widgets/ProjectItem.h"
+#include "net/ApiDownload.h"
+
#include <Version.h>
#include <QtMath>
@@ -70,7 +74,7 @@ QVariant ListModel::data(const QModelIndex& index, int role) const
return QVariant();
}
-bool ListModel::setData(const QModelIndex& index, const QVariant& value, int role)
+bool ListModel::setData(const QModelIndex& index, const QVariant& value, [[maybe_unused]] int role)
{
int pos = index.row();
if (pos >= modpacks.size() || pos < 0 || !index.isValid())
@@ -104,9 +108,9 @@ void ListModel::requestLogo(QString logo, QString url)
return;
}
- MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("FlamePacks", QString("logos/%1").arg(logo.section(".", 0, 0)));
+ MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("FlamePacks", QString("logos/%1").arg(logo));
auto job = new NetJob(QString("Flame Icon Download %1").arg(logo), APPLICATION->network());
- job->addNetAction(Net::Download::makeCached(QUrl(url), entry));
+ job->addNetAction(Net::ApiDownload::makeCached(QUrl(url), entry));
auto fullPath = entry->getFullPath();
QObject::connect(job, &NetJob::succeeded, this, [this, logo, fullPath, job] {
@@ -130,7 +134,7 @@ void ListModel::requestLogo(QString logo, QString url)
void ListModel::getLogo(const QString& logo, const QString& logoUrl, LogoCallback callback)
{
if (m_logoMap.contains(logo)) {
- callback(APPLICATION->metacache()->resolveEntry("FlamePacks", QString("logos/%1").arg(logo.section(".", 0, 0)))->getFullPath());
+ callback(APPLICATION->metacache()->resolveEntry("FlamePacks", QString("logos/%1").arg(logo))->getFullPath());
} else {
requestLogo(logo, logoUrl);
}
@@ -141,7 +145,7 @@ Qt::ItemFlags ListModel::flags(const QModelIndex& index) const
return QAbstractListModel::flags(index);
}
-bool ListModel::canFetchMore(const QModelIndex& parent) const
+bool ListModel::canFetchMore([[maybe_unused]] const QModelIndex& parent) const
{
return searchState == CanPossiblyFetchMore;
}
@@ -159,6 +163,21 @@ void ListModel::fetchMore(const QModelIndex& parent)
void ListModel::performPaginatedSearch()
{
+ if (currentSearchTerm.startsWith("#")) {
+ auto projectId = currentSearchTerm.mid(1);
+ if (!projectId.isEmpty()) {
+ ResourceAPI::ProjectInfoCallbacks callbacks;
+
+ callbacks.on_fail = [this](QString reason) { searchRequestFailed(reason); };
+ callbacks.on_succeed = [this](auto& doc, auto& pack) { searchRequestForOneSucceeded(doc); };
+ static const FlameAPI api;
+ if (auto job = api.getProjectInfo({ projectId }, std::move(callbacks)); job) {
+ jobPtr = job;
+ jobPtr->start();
+ }
+ return;
+ }
+ }
auto netJob = makeShared<NetJob>("Flame::Search", APPLICATION->network());
auto searchUrl = QString(
"https://api.curseforge.com/v1/mods/search?"
@@ -173,7 +192,7 @@ void ListModel::performPaginatedSearch()
.arg(currentSearchTerm)
.arg(currentSort + 1);
- netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), response));
+ netJob->addNetAction(Net::ApiDownload::makeByteArray(QUrl(searchUrl), response));
jobPtr = netJob;
jobPtr->start();
QObject::connect(netJob.get(), &NetJob::succeeded, this, &ListModel::searchRequestFinished);
@@ -187,23 +206,24 @@ void ListModel::searchWithTerm(const QString& term, int sort)
}
currentSearchTerm = term;
currentSort = sort;
- if (jobPtr) {
+ if (hasActiveSearchJob()) {
jobPtr->abort();
searchState = ResetRequested;
return;
- } else {
- beginResetModel();
- modpacks.clear();
- endResetModel();
- searchState = None;
}
+ beginResetModel();
+ modpacks.clear();
+ endResetModel();
+ searchState = None;
+
nextSearchOffset = 0;
performPaginatedSearch();
}
void Flame::ListModel::searchRequestFinished()
{
- jobPtr.reset();
+ if (hasActiveSearchJob())
+ return;
QJsonParseError parse_error;
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
@@ -244,6 +264,25 @@ void Flame::ListModel::searchRequestFinished()
endInsertRows();
}
+void Flame::ListModel::searchRequestForOneSucceeded(QJsonDocument& doc)
+{
+ jobPtr.reset();
+
+ auto packObj = Json::ensureObject(doc.object(), "data");
+
+ Flame::IndexedPack pack;
+ try {
+ Flame::loadIndexedPack(pack, packObj);
+ } catch (const JSONValidationError& e) {
+ qWarning() << "Error while loading pack from CurseForge: " << e.cause();
+ return;
+ }
+
+ beginInsertRows(QModelIndex(), modpacks.size(), modpacks.size() + 1);
+ modpacks.append({ pack });
+ endInsertRows();
+}
+
void Flame::ListModel::searchRequestFailed(QString reason)
{
jobPtr.reset();
diff --git a/launcher/ui/pages/modplatform/flame/FlameModel.h b/launcher/ui/pages/modplatform/flame/FlameModel.h
index b3bc96b8..fd8496df 100644
--- a/launcher/ui/pages/modplatform/flame/FlameModel.h
+++ b/launcher/ui/pages/modplatform/flame/FlameModel.h
@@ -40,6 +40,9 @@ class ListModel : public QAbstractListModel {
void getLogo(const QString& logo, const QString& logoUrl, LogoCallback callback);
void searchWithTerm(const QString& term, const int sort);
+ [[nodiscard]] bool hasActiveSearchJob() const { return jobPtr && jobPtr->isRunning(); }
+ [[nodiscard]] Task::Ptr activeSearchJob() { return hasActiveSearchJob() ? jobPtr : nullptr; }
+
private slots:
void performPaginatedSearch();
@@ -48,6 +51,7 @@ class ListModel : public QAbstractListModel {
void searchRequestFinished();
void searchRequestFailed(QString reason);
+ void searchRequestForOneSucceeded(QJsonDocument&);
private:
void requestLogo(QString file, QString url);
@@ -63,7 +67,7 @@ class ListModel : public QAbstractListModel {
int currentSort = 0;
int nextSearchOffset = 0;
enum SearchState { None, CanPossiblyFetchMore, ResetRequested, Finished } searchState = None;
- NetJob::Ptr jobPtr;
+ Task::Ptr jobPtr;
std::shared_ptr<QByteArray> response = std::make_shared<QByteArray>();
};
diff --git a/launcher/ui/pages/modplatform/flame/FlamePage.cpp b/launcher/ui/pages/modplatform/flame/FlamePage.cpp
index 9be7ce8b..584d94ad 100644
--- a/launcher/ui/pages/modplatform/flame/FlamePage.cpp
+++ b/launcher/ui/pages/modplatform/flame/FlamePage.cpp
@@ -46,9 +46,12 @@
#include "ui/dialogs/NewInstanceDialog.h"
#include "ui/widgets/ProjectItem.h"
+#include "net/ApiDownload.h"
+
static FlameAPI api;
-FlamePage::FlamePage(NewInstanceDialog* dialog, QWidget* parent) : QWidget(parent), ui(new Ui::FlamePage), dialog(dialog)
+FlamePage::FlamePage(NewInstanceDialog* dialog, QWidget* parent)
+ : QWidget(parent), ui(new Ui::FlamePage), dialog(dialog), m_fetch_progress(this, false)
{
ui->setupUi(this);
connect(ui->searchButton, &QPushButton::clicked, this, &FlamePage::triggerSearch);
@@ -59,6 +62,17 @@ FlamePage::FlamePage(NewInstanceDialog* dialog, QWidget* parent) : QWidget(paren
ui->versionSelectionBox->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
ui->versionSelectionBox->view()->parentWidget()->setMaximumHeight(300);
+ m_search_timer.setTimerType(Qt::TimerType::CoarseTimer);
+ m_search_timer.setSingleShot(true);
+
+ connect(&m_search_timer, &QTimer::timeout, this, &FlamePage::triggerSearch);
+
+ m_fetch_progress.hideIfInactive(true);
+ m_fetch_progress.setFixedHeight(24);
+ m_fetch_progress.progressFormat("");
+
+ ui->gridLayout->addWidget(&m_fetch_progress, 2, 0, 1, ui->gridLayout->columnCount());
+
// index is used to set the sorting with the curseforge api
ui->sortByBox->addItem(tr("Sort by Featured"));
ui->sortByBox->addItem(tr("Sort by Popularity"));
@@ -88,6 +102,11 @@ bool FlamePage::eventFilter(QObject* watched, QEvent* event)
triggerSearch();
keyEvent->accept();
return true;
+ } else {
+ if (m_search_timer.isActive())
+ m_search_timer.stop();
+
+ m_search_timer.start(350);
}
}
return QWidget::eventFilter(watched, event);
@@ -112,9 +131,10 @@ void FlamePage::openedImpl()
void FlamePage::triggerSearch()
{
listModel->searchWithTerm(ui->searchEdit->text(), ui->sortByBox->currentIndex());
+ m_fetch_progress.watch(listModel->activeSearchJob().get());
}
-void FlamePage::onSelectionChanged(QModelIndex curr, QModelIndex prev)
+void FlamePage::onSelectionChanged(QModelIndex curr, [[maybe_unused]] QModelIndex prev)
{
ui->versionSelectionBox->clear();
@@ -132,7 +152,8 @@ void FlamePage::onSelectionChanged(QModelIndex curr, QModelIndex prev)
auto netJob = new NetJob(QString("Flame::PackVersions(%1)").arg(current.name), APPLICATION->network());
auto response = std::make_shared<QByteArray>();
int addonId = current.addonId;
- netJob->addNetAction(Net::Download::makeByteArray(QString("https://api.curseforge.com/v1/mods/%1/files").arg(addonId), response));
+ netJob->addNetAction(
+ Net::ApiDownload::makeByteArray(QString("https://api.curseforge.com/v1/mods/%1/files").arg(addonId), response));
QObject::connect(netJob, &NetJob::succeeded, this, [this, response, addonId, curr] {
if (addonId != current.addonId) {
@@ -208,17 +229,17 @@ void FlamePage::suggestCurrent()
dialog->setSuggestedPack(current.name, new InstanceImportTask(version.downloadUrl, this, std::move(extra_info)));
QString editedLogoName;
- editedLogoName = "curseforge_" + current.logoName.section(".", 0, 0);
+ editedLogoName = "curseforge_" + current.logoName;
listModel->getLogo(current.logoName, current.logoUrl,
[this, editedLogoName](QString logo) { dialog->setSuggestedIconFromFile(logo, editedLogoName); });
}
-void FlamePage::onVersionSelectionChanged(QString data)
+void FlamePage::onVersionSelectionChanged(QString version)
{
bool is_blocked = false;
ui->versionSelectionBox->currentData().toInt(&is_blocked);
- if (data.isNull() || data.isEmpty() || is_blocked) {
+ if (version.isNull() || version.isEmpty() || is_blocked) {
m_selected_version_index = -1;
return;
}
diff --git a/launcher/ui/pages/modplatform/flame/FlamePage.h b/launcher/ui/pages/modplatform/flame/FlamePage.h
index ff5c7975..d35858fb 100644
--- a/launcher/ui/pages/modplatform/flame/FlamePage.h
+++ b/launcher/ui/pages/modplatform/flame/FlamePage.h
@@ -39,8 +39,9 @@
#include <Application.h>
#include <modplatform/flame/FlamePackIndex.h>
-#include "tasks/Task.h"
+#include <QTimer>
#include "ui/pages/BasePage.h"
+#include "ui/widgets/ProgressWidget.h"
namespace Ui {
class FlamePage;
@@ -86,4 +87,9 @@ class FlamePage : public QWidget, public BasePage {
Flame::IndexedPack current;
int m_selected_version_index = -1;
+
+ ProgressWidget m_fetch_progress;
+
+ // Used to do instant searching with a delay to cache quick changes
+ QTimer m_search_timer;
};
diff --git a/launcher/ui/pages/modplatform/flame/FlamePage.ui b/launcher/ui/pages/modplatform/flame/FlamePage.ui
index 71d19513..f9e1fe67 100644
--- a/launcher/ui/pages/modplatform/flame/FlamePage.ui
+++ b/launcher/ui/pages/modplatform/flame/FlamePage.ui
@@ -47,7 +47,7 @@
</item>
</layout>
</item>
- <item row="2" column="0">
+ <item row="3" column="0">
<layout class="QHBoxLayout">
<item>
<widget class="QListView" name="packView">
@@ -77,7 +77,7 @@
</item>
</layout>
</item>
- <item row="3" column="0">
+ <item row="4" column="0">
<layout class="QHBoxLayout">
<item>
<widget class="QComboBox" name="sortByBox"/>
diff --git a/launcher/ui/pages/modplatform/flame/FlameResourceModels.cpp b/launcher/ui/pages/modplatform/flame/FlameResourceModels.cpp
index 0fb67c50..7d18e72a 100644
--- a/launcher/ui/pages/modplatform/flame/FlameResourceModels.cpp
+++ b/launcher/ui/pages/modplatform/flame/FlameResourceModels.cpp
@@ -31,8 +31,8 @@ void FlameModModel::loadIndexedPackVersions(ModPlatform::IndexedPack& m, QJsonAr
auto FlameModModel::loadDependencyVersions(const ModPlatform::Dependency& m, QJsonArray& arr) -> ModPlatform::IndexedVersion
{
- return FlameMod::loadDependencyVersions(m, arr);
-};
+ return FlameMod::loadDependencyVersions(m, arr, &m_base_instance);
+}
auto FlameModModel::documentToArray(QJsonDocument& obj) const -> QJsonArray
{
@@ -121,4 +121,27 @@ auto FlameTexturePackModel::documentToArray(QJsonDocument& obj) const -> QJsonAr
return Json::ensureArray(obj.object(), "data");
}
+FlameShaderPackModel::FlameShaderPackModel(const BaseInstance& base) : ShaderPackResourceModel(base, new FlameAPI) {}
+
+void FlameShaderPackModel::loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj)
+{
+ FlameMod::loadIndexedPack(m, obj);
+}
+
+// We already deal with the URLs when initializing the pack, due to the API response's structure
+void FlameShaderPackModel::loadExtraPackInfo(ModPlatform::IndexedPack& m, QJsonObject& obj)
+{
+ FlameMod::loadBody(m, obj);
+}
+
+void FlameShaderPackModel::loadIndexedPackVersions(ModPlatform::IndexedPack& m, QJsonArray& arr)
+{
+ FlameMod::loadIndexedPackVersions(m, arr, APPLICATION->network(), &m_base_instance);
+}
+
+auto FlameShaderPackModel::documentToArray(QJsonDocument& obj) const -> QJsonArray
+{
+ return Json::ensureArray(obj.object(), "data");
+}
+
} // namespace ResourceDownload
diff --git a/launcher/ui/pages/modplatform/flame/FlameResourceModels.h b/launcher/ui/pages/modplatform/flame/FlameResourceModels.h
index 6cfd6a6f..76dbd7b3 100644
--- a/launcher/ui/pages/modplatform/flame/FlameResourceModels.h
+++ b/launcher/ui/pages/modplatform/flame/FlameResourceModels.h
@@ -68,4 +68,21 @@ class FlameTexturePackModel : public TexturePackResourceModel {
auto documentToArray(QJsonDocument& obj) const -> QJsonArray override;
};
+class FlameShaderPackModel : public ShaderPackResourceModel {
+ Q_OBJECT
+
+ public:
+ FlameShaderPackModel(const BaseInstance&);
+ ~FlameShaderPackModel() override = default;
+
+ private:
+ [[nodiscard]] QString debugName() const override { return Flame::debugName() + " (Model)"; }
+ [[nodiscard]] QString metaEntryBase() const override { return Flame::metaEntryBase(); }
+
+ void loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj) override;
+ void loadExtraPackInfo(ModPlatform::IndexedPack& m, QJsonObject& obj) override;
+ void loadIndexedPackVersions(ModPlatform::IndexedPack& m, QJsonArray& arr) override;
+ auto documentToArray(QJsonDocument& obj) const -> QJsonArray override;
+};
+
} // namespace ResourceDownload
diff --git a/launcher/ui/pages/modplatform/flame/FlameResourcePages.cpp b/launcher/ui/pages/modplatform/flame/FlameResourcePages.cpp
index dc17e705..23373ec9 100644
--- a/launcher/ui/pages/modplatform/flame/FlameResourcePages.cpp
+++ b/launcher/ui/pages/modplatform/flame/FlameResourcePages.cpp
@@ -68,10 +68,10 @@ FlameModPage::FlameModPage(ModDownloadDialog* dialog, BaseInstance& instance) :
auto FlameModPage::validateVersion(ModPlatform::IndexedVersion& ver,
QString mineVer,
- std::optional<ResourceAPI::ModLoaderTypes> loaders) const -> bool
+ std::optional<ModPlatform::ModLoaderTypes> loaders) const -> bool
{
- Q_UNUSED(loaders);
- return ver.mcVersion.contains(mineVer) && !ver.downloadUrl.isEmpty();
+ return ver.mcVersion.contains(mineVer) && !ver.downloadUrl.isEmpty() &&
+ (!loaders.has_value() || !ver.loaders || loaders.value() & ver.loaders);
}
bool FlameModPage::optedOut(ModPlatform::IndexedVersion& ver) const
@@ -173,6 +173,45 @@ void FlameTexturePackPage::openUrl(const QUrl& url)
TexturePackResourcePage::openUrl(url);
}
+FlameShaderPackPage::FlameShaderPackPage(ShaderPackDownloadDialog* dialog, BaseInstance& instance)
+ : ShaderPackResourcePage(dialog, instance)
+{
+ m_model = new FlameShaderPackModel(instance);
+ m_ui->packView->setModel(m_model);
+
+ addSortings();
+
+ // sometimes Qt just ignores virtual slots and doesn't work as intended it seems,
+ // so it's best not to connect them in the parent's constructor...
+ connect(m_ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
+ connect(m_ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &FlameShaderPackPage::onSelectionChanged);
+ connect(m_ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &FlameShaderPackPage::onVersionSelectionChanged);
+ connect(m_ui->resourceSelectionButton, &QPushButton::clicked, this, &FlameShaderPackPage::onResourceSelected);
+
+ m_ui->packDescription->setMetaEntry(metaEntryBase());
+}
+
+bool FlameShaderPackPage::optedOut(ModPlatform::IndexedVersion& ver) const
+{
+ return isOptedOut(ver);
+}
+
+void FlameShaderPackPage::openUrl(const QUrl& url)
+{
+ if (url.scheme().isEmpty()) {
+ QString query = url.query(QUrl::FullyDecoded);
+
+ if (query.startsWith("remoteUrl=")) {
+ // attempt to resolve url from warning page
+ query.remove(0, 10);
+ ShaderPackResourcePage::openUrl({ QUrl::fromPercentEncoding(query.toUtf8()) }); // double decoding is necessary
+ return;
+ }
+ }
+
+ ShaderPackResourcePage::openUrl(url);
+}
+
// I don't know why, but doing this on the parent class makes it so that
// other mod providers start loading before being selected, at least with
// my Qt, so we need to implement this in every derived class...
@@ -188,5 +227,9 @@ auto FlameTexturePackPage::shouldDisplay() const -> bool
{
return true;
}
+auto FlameShaderPackPage::shouldDisplay() const -> bool
+{
+ return true;
+}
} // namespace ResourceDownload
diff --git a/launcher/ui/pages/modplatform/flame/FlameResourcePages.h b/launcher/ui/pages/modplatform/flame/FlameResourcePages.h
index c6ebc1ea..f2f5ceca 100644
--- a/launcher/ui/pages/modplatform/flame/FlameResourcePages.h
+++ b/launcher/ui/pages/modplatform/flame/FlameResourcePages.h
@@ -44,6 +44,7 @@
#include "ui/pages/modplatform/ModPage.h"
#include "ui/pages/modplatform/ResourcePackPage.h"
+#include "ui/pages/modplatform/ShaderPackPage.h"
#include "ui/pages/modplatform/TexturePackPage.h"
namespace ResourceDownload {
@@ -95,7 +96,7 @@ class FlameModPage : public ModPage {
bool validateVersion(ModPlatform::IndexedVersion& ver,
QString mineVer,
- std::optional<ResourceAPI::ModLoaderTypes> loaders = {}) const override;
+ std::optional<ModPlatform::ModLoaderTypes> loaders = {}) const override;
bool optedOut(ModPlatform::IndexedVersion& ver) const override;
void openUrl(const QUrl& url) override;
@@ -155,4 +156,31 @@ class FlameTexturePackPage : public TexturePackResourcePage {
void openUrl(const QUrl& url) override;
};
+class FlameShaderPackPage : public ShaderPackResourcePage {
+ Q_OBJECT
+
+ public:
+ static FlameShaderPackPage* create(ShaderPackDownloadDialog* dialog, BaseInstance& instance)
+ {
+ return ShaderPackResourcePage::create<FlameShaderPackPage>(dialog, instance);
+ }
+
+ FlameShaderPackPage(ShaderPackDownloadDialog* dialog, BaseInstance& instance);
+ ~FlameShaderPackPage() override = default;
+
+ [[nodiscard]] bool shouldDisplay() const override;
+
+ [[nodiscard]] inline auto displayName() const -> QString override { return Flame::displayName(); }
+ [[nodiscard]] inline auto icon() const -> QIcon override { return Flame::icon(); }
+ [[nodiscard]] inline auto id() const -> QString override { return Flame::id(); }
+ [[nodiscard]] inline auto debugName() const -> QString override { return Flame::debugName(); }
+ [[nodiscard]] inline auto metaEntryBase() const -> QString override { return Flame::metaEntryBase(); }
+
+ [[nodiscard]] inline auto helpPage() const -> QString override { return ""; }
+
+ bool optedOut(ModPlatform::IndexedVersion& ver) const override;
+
+ void openUrl(const QUrl& url) override;
+};
+
} // namespace ResourceDownload
diff --git a/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.cpp b/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.cpp
index 5c9ff63b..d3ead083 100644
--- a/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.cpp
+++ b/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.cpp
@@ -17,6 +17,7 @@
*/
#include "ImportFTBPage.h"
+#include "ui/widgets/ProjectItem.h"
#include "ui_ImportFTBPage.h"
#include <QWidget>
@@ -32,17 +33,30 @@ ImportFTBPage::ImportFTBPage(NewInstanceDialog* dialog, QWidget* parent) : QWidg
ui->setupUi(this);
{
+ currentModel = new FilterModel(this);
listModel = new ListModel(this);
+ currentModel->setSourceModel(listModel);
- ui->modpackList->setModel(listModel);
+ ui->modpackList->setModel(currentModel);
ui->modpackList->setSortingEnabled(true);
ui->modpackList->header()->hide();
ui->modpackList->setIndentation(0);
ui->modpackList->setIconSize(QSize(42, 42));
+
+ for (int i = 0; i < currentModel->getAvailableSortings().size(); i++) {
+ ui->sortByBox->addItem(currentModel->getAvailableSortings().keys().at(i));
+ }
+
+ ui->sortByBox->setCurrentText(currentModel->translateCurrentSorting());
}
connect(ui->modpackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &ImportFTBPage::onPublicPackSelectionChanged);
+ connect(ui->sortByBox, &QComboBox::currentTextChanged, this, &ImportFTBPage::onSortingSelectionChanged);
+
+ connect(ui->searchEdit, &QLineEdit::textChanged, this, &ImportFTBPage::triggerSearch);
+
+ ui->modpackList->setItemDelegate(new ProjectItemDelegate(this));
ui->modpackList->selectionModel()->reset();
}
@@ -86,7 +100,7 @@ void ImportFTBPage::onPublicPackSelectionChanged(QModelIndex now, QModelIndex pr
onPackSelectionChanged();
return;
}
- Modpack selectedPack = listModel->data(now, Qt::UserRole).value<Modpack>();
+ Modpack selectedPack = currentModel->data(now, Qt::UserRole).value<Modpack>();
onPackSelectionChanged(&selectedPack);
}
@@ -101,4 +115,15 @@ void ImportFTBPage::onPackSelectionChanged(Modpack* pack)
dialog->setSuggestedPack();
}
+void ImportFTBPage::onSortingSelectionChanged(QString sort)
+{
+ FilterModel::Sorting toSet = currentModel->getAvailableSortings().value(sort);
+ currentModel->setSorting(toSet);
+}
+
+void ImportFTBPage::triggerSearch()
+{
+ currentModel->setSearchTerm(ui->searchEdit->text());
+}
+
} // namespace FTBImportAPP
diff --git a/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.h b/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.h
index 54c49f7b..8e966127 100644
--- a/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.h
+++ b/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.h
@@ -53,12 +53,15 @@ class ImportFTBPage : public QWidget, public BasePage {
void suggestCurrent();
void onPackSelectionChanged(Modpack* pack = nullptr);
private slots:
+ void onSortingSelectionChanged(QString data);
void onPublicPackSelectionChanged(QModelIndex first, QModelIndex second);
+ void triggerSearch();
private:
bool initialized = false;
Modpack selected;
ListModel* listModel = nullptr;
+ FilterModel* currentModel = nullptr;
NewInstanceDialog* dialog = nullptr;
Ui::ImportFTBPage* ui = nullptr;
diff --git a/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.ui b/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.ui
index 32d548b0..5e09fb6d 100644
--- a/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.ui
+++ b/launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.ui
@@ -10,8 +10,8 @@
<height>1011</height>
</rect>
</property>
- <layout class="QHBoxLayout" name="horizontalLayout">
- <item>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="1" column="1">
<widget class="QTreeView" name="modpackList">
<property name="maximumSize">
<size>
@@ -21,6 +21,54 @@
</property>
</widget>
</item>
+ <item row="0" column="1">
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QLineEdit" name="searchEdit">
+ <property name="placeholderText">
+ <string>Search and filter...</string>
+ </property>
+ <property name="clearButtonEnabled">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushButton">
+ <property name="text">
+ <string>Search</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="2" column="1">
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="QComboBox" name="sortByBox">
+ <property name="minimumSize">
+ <size>
+ <width>265</width>
+ <height>0</height>
+ </size>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
</layout>
</widget>
<resources/>
diff --git a/launcher/ui/pages/modplatform/import_ftb/ListModel.cpp b/launcher/ui/pages/modplatform/import_ftb/ListModel.cpp
index dc78f451..134bdc0c 100644
--- a/launcher/ui/pages/modplatform/import_ftb/ListModel.cpp
+++ b/launcher/ui/pages/modplatform/import_ftb/ListModel.cpp
@@ -23,7 +23,9 @@
#include <QIcon>
#include <QProcessEnvironment>
#include "FileSystem.h"
+#include "StringUtils.h"
#include "modplatform/import_ftb/PackHelpers.h"
+#include "ui/widgets/ProjectItem.h"
namespace FTBImportAPP {
@@ -71,18 +73,99 @@ QVariant ListModel::data(const QModelIndex& index, int role) const
}
auto pack = modpacks.at(pos);
- if (role == Qt::DisplayRole) {
- return pack.name;
- } else if (role == Qt::DecorationRole) {
- return pack.icon;
- } else if (role == Qt::UserRole) {
- QVariant v;
- v.setValue(pack);
- return v;
- } else if (role == Qt::ToolTipRole) {
- return tr("Minecraft %1").arg(pack.mcVersion);
+ if (role == Qt::ToolTipRole) {
}
- return QVariant();
+ switch (role) {
+ case Qt::ToolTipRole:
+ return tr("Minecraft %1").arg(pack.mcVersion);
+ case Qt::DecorationRole:
+ return pack.icon;
+ case Qt::UserRole: {
+ QVariant v;
+ v.setValue(pack);
+ return v;
+ }
+ case Qt::DisplayRole:
+ return pack.name;
+ case Qt::SizeHintRole:
+ return QSize(0, 58);
+ // Custom data
+ case UserDataTypes::TITLE:
+ return pack.name;
+ case UserDataTypes::DESCRIPTION:
+ return tr("Minecraft %1").arg(pack.mcVersion);
+ case UserDataTypes::SELECTED:
+ return false;
+ case UserDataTypes::INSTALLED:
+ return false;
+ default:
+ break;
+ }
+
+ return {};
+}
+
+FilterModel::FilterModel(QObject* parent) : QSortFilterProxyModel(parent)
+{
+ currentSorting = Sorting::ByGameVersion;
+ sortings.insert(tr("Sort by Name"), Sorting::ByName);
+ sortings.insert(tr("Sort by Game Version"), Sorting::ByGameVersion);
+}
+
+bool FilterModel::lessThan(const QModelIndex& left, const QModelIndex& right) const
+{
+ Modpack leftPack = sourceModel()->data(left, Qt::UserRole).value<Modpack>();
+ Modpack rightPack = sourceModel()->data(right, Qt::UserRole).value<Modpack>();
+
+ if (currentSorting == Sorting::ByGameVersion) {
+ Version lv(leftPack.mcVersion);
+ Version rv(rightPack.mcVersion);
+ return lv < rv;
+
+ } else if (currentSorting == Sorting::ByName) {
+ return StringUtils::naturalCompare(leftPack.name, rightPack.name, Qt::CaseSensitive) >= 0;
+ }
+
+ // UHM, some inavlid value set?!
+ qWarning() << "Invalid sorting set!";
+ return true;
+}
+
+bool FilterModel::filterAcceptsRow([[maybe_unused]] int sourceRow, [[maybe_unused]] const QModelIndex& sourceParent) const
+{
+ if (searchTerm.isEmpty()) {
+ return true;
+ }
+ QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
+ Modpack pack = sourceModel()->data(index, Qt::UserRole).value<Modpack>();
+ return pack.name.contains(searchTerm, Qt::CaseInsensitive);
+}
+
+void FilterModel::setSearchTerm(const QString term)
+{
+ searchTerm = term.trimmed();
+ invalidate();
+}
+
+const QMap<QString, FilterModel::Sorting> FilterModel::getAvailableSortings()
+{
+ return sortings;
+}
+
+QString FilterModel::translateCurrentSorting()
+{
+ return sortings.key(currentSorting);
+}
+
+void FilterModel::setSorting(Sorting s)
+{
+ currentSorting = s;
+ invalidate();
+}
+
+FilterModel::Sorting FilterModel::getCurrentSorting()
+{
+ return currentSorting;
}
} // namespace FTBImportAPP \ No newline at end of file
diff --git a/launcher/ui/pages/modplatform/import_ftb/ListModel.h b/launcher/ui/pages/modplatform/import_ftb/ListModel.h
index c67aa896..11192827 100644
--- a/launcher/ui/pages/modplatform/import_ftb/ListModel.h
+++ b/launcher/ui/pages/modplatform/import_ftb/ListModel.h
@@ -20,11 +20,33 @@
#include <QAbstractListModel>
#include <QIcon>
+#include <QSortFilterProxyModel>
#include <QVariant>
#include "modplatform/import_ftb/PackHelpers.h"
namespace FTBImportAPP {
+class FilterModel : public QSortFilterProxyModel {
+ Q_OBJECT
+ public:
+ FilterModel(QObject* parent = Q_NULLPTR);
+ enum Sorting { ByName, ByGameVersion };
+ const QMap<QString, Sorting> getAvailableSortings();
+ QString translateCurrentSorting();
+ void setSorting(Sorting sorting);
+ Sorting getCurrentSorting();
+ void setSearchTerm(QString term);
+
+ protected:
+ bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override;
+ bool lessThan(const QModelIndex& left, const QModelIndex& right) const override;
+
+ private:
+ QMap<QString, Sorting> sortings;
+ Sorting currentSorting;
+ QString searchTerm;
+};
+
class ListModel : public QAbstractListModel {
Q_OBJECT
diff --git a/launcher/ui/pages/modplatform/legacy_ftb/ListModel.cpp b/launcher/ui/pages/modplatform/legacy_ftb/ListModel.cpp
index 1731ff2c..49666cf6 100644
--- a/launcher/ui/pages/modplatform/legacy_ftb/ListModel.cpp
+++ b/launcher/ui/pages/modplatform/legacy_ftb/ListModel.cpp
@@ -35,11 +35,13 @@
#include "ListModel.h"
#include "Application.h"
+#include "net/ApiDownload.h"
#include "net/HttpMetaCache.h"
#include "net/NetJob.h"
#include <Version.h>
#include "StringUtils.h"
+#include "ui/widgets/ProjectItem.h"
#include <QLabel>
#include <QtMath>
@@ -76,9 +78,22 @@ bool FilterModel::lessThan(const QModelIndex& left, const QModelIndex& right) co
return true;
}
-bool FilterModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const
+bool FilterModel::filterAcceptsRow([[maybe_unused]] int sourceRow, [[maybe_unused]] const QModelIndex& sourceParent) const
{
- return true;
+ if (searchTerm.isEmpty()) {
+ return true;
+ }
+ QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
+ Modpack pack = sourceModel()->data(index, Qt::UserRole).value<Modpack>();
+ if (searchTerm.startsWith("#"))
+ return pack.packCode == searchTerm.mid(1);
+ return pack.name.contains(searchTerm, Qt::CaseInsensitive);
+}
+
+void FilterModel::setSearchTerm(const QString term)
+{
+ searchTerm = term.trimmed();
+ invalidate();
}
const QMap<QString, FilterModel::Sorting> FilterModel::getAvailableSortings()
@@ -138,45 +153,63 @@ QVariant ListModel::data(const QModelIndex& index, int role) const
}
Modpack pack = modpacks.at(pos);
- if (role == Qt::DisplayRole) {
- return pack.name + "\n" + translatePackType(pack.type);
- } else if (role == Qt::ToolTipRole) {
- if (pack.description.length() > 100) {
- // some magic to prevent to long tooltips and replace html linebreaks
- QString edit = pack.description.left(97);
- edit = edit.left(edit.lastIndexOf("<br>")).left(edit.lastIndexOf(" ")).append("...");
- return edit;
+ switch (role) {
+ case Qt::ToolTipRole: {
+ if (pack.description.length() > 100) {
+ // some magic to prevent to long tooltips and replace html linebreaks
+ QString edit = pack.description.left(97);
+ edit = edit.left(edit.lastIndexOf("<br>")).left(edit.lastIndexOf(" ")).append("...");
+ return edit;
+ }
+ return pack.description;
+ }
+ case Qt::DecorationRole: {
+ if (m_logoMap.contains(pack.logo)) {
+ return (m_logoMap.value(pack.logo));
+ }
+ QIcon icon = APPLICATION->getThemedIcon("screenshot-placeholder");
+ ((ListModel*)this)->requestLogo(pack.logo);
+ return icon;
}
- return pack.description;
- } else if (role == Qt::DecorationRole) {
- if (m_logoMap.contains(pack.logo)) {
- return (m_logoMap.value(pack.logo));
+ case Qt::UserRole: {
+ QVariant v;
+ v.setValue(pack);
+ return v;
}
- QIcon icon = APPLICATION->getThemedIcon("screenshot-placeholder");
- ((ListModel*)this)->requestLogo(pack.logo);
- return icon;
- } else if (role == Qt::ForegroundRole) {
- if (pack.broken) {
- // FIXME: Hardcoded color
- return QColor(255, 0, 50);
- } else if (pack.bugged) {
- // FIXME: Hardcoded color
- // bugged pack, currently only indicates bugged xml
- return QColor(244, 229, 66);
+ case Qt::ForegroundRole: {
+ if (pack.broken) {
+ // FIXME: Hardcoded color
+ return QColor(255, 0, 50);
+ } else if (pack.bugged) {
+ // FIXME: Hardcoded color
+ // bugged pack, currently only indicates bugged xml
+ return QColor(244, 229, 66);
+ }
}
- } else if (role == Qt::UserRole) {
- QVariant v;
- v.setValue(pack);
- return v;
+ case Qt::DisplayRole:
+ return pack.name;
+ case Qt::SizeHintRole:
+ return QSize(0, 58);
+ // Custom data
+ case UserDataTypes::TITLE:
+ return pack.name;
+ case UserDataTypes::DESCRIPTION:
+ return pack.description;
+ case UserDataTypes::SELECTED:
+ return false;
+ case UserDataTypes::INSTALLED:
+ return false;
+ default:
+ break;
}
- return QVariant();
+ return {};
}
-void ListModel::fill(ModpackList modpacks)
+void ListModel::fill(ModpackList modpacks_)
{
beginResetModel();
- this->modpacks = modpacks;
+ this->modpacks = modpacks_;
endResetModel();
}
@@ -229,9 +262,9 @@ void ListModel::requestLogo(QString file)
return;
}
- MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(file.section(".", 0, 0)));
+ MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(file));
NetJob* job = new NetJob(QString("FTB Icon Download for %1").arg(file), APPLICATION->network());
- job->addNetAction(Net::Download::makeCached(QUrl(QString(BuildConfig.LEGACY_FTB_CDN_BASE_URL + "static/%1").arg(file)), entry));
+ job->addNetAction(Net::ApiDownload::makeCached(QUrl(QString(BuildConfig.LEGACY_FTB_CDN_BASE_URL + "static/%1").arg(file)), entry));
auto fullPath = entry->getFullPath();
QObject::connect(job, &NetJob::finished, this, [this, file, fullPath, job] {
@@ -255,7 +288,7 @@ void ListModel::requestLogo(QString file)
void ListModel::getLogo(const QString& logo, LogoCallback callback)
{
if (m_logoMap.contains(logo)) {
- callback(APPLICATION->metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(logo.section(".", 0, 0)))->getFullPath());
+ callback(APPLICATION->metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(logo))->getFullPath());
} else {
requestLogo(logo);
}
diff --git a/launcher/ui/pages/modplatform/legacy_ftb/ListModel.h b/launcher/ui/pages/modplatform/legacy_ftb/ListModel.h
index 51a58d99..c802a4b5 100644
--- a/launcher/ui/pages/modplatform/legacy_ftb/ListModel.h
+++ b/launcher/ui/pages/modplatform/legacy_ftb/ListModel.h
@@ -25,6 +25,7 @@ class FilterModel : public QSortFilterProxyModel {
QString translateCurrentSorting();
void setSorting(Sorting sorting);
Sorting getCurrentSorting();
+ void setSearchTerm(QString term);
protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override;
@@ -33,6 +34,7 @@ class FilterModel : public QSortFilterProxyModel {
private:
QMap<QString, Sorting> sortings;
Sorting currentSorting;
+ QString searchTerm;
};
class ListModel : public QAbstractListModel {
diff --git a/launcher/ui/pages/modplatform/legacy_ftb/Page.cpp b/launcher/ui/pages/modplatform/legacy_ftb/Page.cpp
index ef8e9892..4104f139 100644
--- a/launcher/ui/pages/modplatform/legacy_ftb/Page.cpp
+++ b/launcher/ui/pages/modplatform/legacy_ftb/Page.cpp
@@ -35,6 +35,7 @@
*/
#include "Page.h"
+#include "ui/widgets/ProjectItem.h"
#include "ui_Page.h"
#include <QInputDialog>
@@ -110,6 +111,8 @@ Page::Page(NewInstanceDialog* dialog, QWidget* parent) : QWidget(parent), dialog
connect(ui->sortByBox, &QComboBox::currentTextChanged, this, &Page::onSortingSelectionChanged);
connect(ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &Page::onVersionSelectionItemChanged);
+ connect(ui->searchEdit, &QLineEdit::textChanged, this, &Page::triggerSearch);
+
connect(ui->publicPackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &Page::onPublicPackSelectionChanged);
connect(ui->thirdPartyPackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &Page::onThirdPartyPackSelectionChanged);
connect(ui->privatePackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &Page::onPrivatePackSelectionChanged);
@@ -125,6 +128,9 @@ Page::Page(NewInstanceDialog* dialog, QWidget* parent) : QWidget(parent), dialog
ui->thirdPartyPackList->selectionModel()->reset();
ui->privatePackList->selectionModel()->reset();
+ ui->publicPackList->setItemDelegate(new ProjectItemDelegate(this));
+ ui->thirdPartyPackList->setItemDelegate(new ProjectItemDelegate(this));
+ ui->privatePackList->setItemDelegate(new ProjectItemDelegate(this));
onTabChanged(ui->tabWidget->currentIndex());
}
@@ -215,7 +221,7 @@ void Page::ftbPrivatePackDataDownloadSuccessfully(Modpack pack)
privateListModel->addPack(pack);
}
-void Page::ftbPrivatePackDataDownloadFailed(QString reason, QString packCode)
+void Page::ftbPrivatePackDataDownloadFailed([[maybe_unused]] QString reason, QString packCode)
{
auto reply = QMessageBox::question(this, tr("FTB private packs"),
tr("Failed to download pack information for code %1.\nShould it be removed now?").arg(packCode));
@@ -224,7 +230,7 @@ void Page::ftbPrivatePackDataDownloadFailed(QString reason, QString packCode)
}
}
-void Page::onPublicPackSelectionChanged(QModelIndex now, QModelIndex prev)
+void Page::onPublicPackSelectionChanged(QModelIndex now, [[maybe_unused]] QModelIndex prev)
{
if (!now.isValid()) {
onPackSelectionChanged();
@@ -234,7 +240,7 @@ void Page::onPublicPackSelectionChanged(QModelIndex now, QModelIndex prev)
onPackSelectionChanged(&selectedPack);
}
-void Page::onThirdPartyPackSelectionChanged(QModelIndex now, QModelIndex prev)
+void Page::onThirdPartyPackSelectionChanged(QModelIndex now, [[maybe_unused]] QModelIndex prev)
{
if (!now.isValid()) {
onPackSelectionChanged();
@@ -244,7 +250,7 @@ void Page::onThirdPartyPackSelectionChanged(QModelIndex now, QModelIndex prev)
onPackSelectionChanged(&selectedPack);
}
-void Page::onPrivatePackSelectionChanged(QModelIndex now, QModelIndex prev)
+void Page::onPrivatePackSelectionChanged(QModelIndex now, [[maybe_unused]] QModelIndex prev)
{
if (!now.isValid()) {
onPackSelectionChanged();
@@ -284,20 +290,20 @@ void Page::onPackSelectionChanged(Modpack* pack)
suggestCurrent();
}
-void Page::onVersionSelectionItemChanged(QString data)
+void Page::onVersionSelectionItemChanged(QString version)
{
- if (data.isNull() || data.isEmpty()) {
+ if (version.isNull() || version.isEmpty()) {
selectedVersion = "";
return;
}
- selectedVersion = data;
+ selectedVersion = version;
suggestCurrent();
}
-void Page::onSortingSelectionChanged(QString data)
+void Page::onSortingSelectionChanged(QString sort)
{
- FilterModel::Sorting toSet = publicFilterModel->getAvailableSortings().value(data);
+ FilterModel::Sorting toSet = publicFilterModel->getAvailableSortings().value(sort);
publicFilterModel->setSorting(toSet);
thirdPartyFilterModel->setSorting(toSet);
privateFilterModel->setSorting(toSet);
@@ -319,6 +325,8 @@ void Page::onTabChanged(int tab)
currentModpackInfo = ui->publicPackDescription;
}
+ triggerSearch();
+
currentList->selectionModel()->reset();
QModelIndex idx = currentList->currentIndex();
if (idx.isValid()) {
@@ -358,4 +366,9 @@ void Page::onRemovePackClicked()
onPackSelectionChanged();
}
+void Page::triggerSearch()
+{
+ currentModel->setSearchTerm(ui->searchEdit->text());
+}
+
} // namespace LegacyFTB
diff --git a/launcher/ui/pages/modplatform/legacy_ftb/Page.h b/launcher/ui/pages/modplatform/legacy_ftb/Page.h
index a12b0745..4d317b7c 100644
--- a/launcher/ui/pages/modplatform/legacy_ftb/Page.h
+++ b/launcher/ui/pages/modplatform/legacy_ftb/Page.h
@@ -43,7 +43,6 @@
#include "QObjectPtr.h"
#include "modplatform/legacy_ftb/PackFetchTask.h"
#include "modplatform/legacy_ftb/PackHelpers.h"
-#include "tasks/Task.h"
#include "ui/pages/BasePage.h"
class NewInstanceDialog;
@@ -56,8 +55,6 @@ class Page;
class ListModel;
class FilterModel;
-class PrivatePackListModel;
-class PrivatePackFilterModel;
class PrivatePackManager;
class Page : public QWidget, public BasePage {
@@ -98,6 +95,8 @@ class Page : public QWidget, public BasePage {
void onAddPackClicked();
void onRemovePackClicked();
+ void triggerSearch();
+
private:
FilterModel* currentModel = nullptr;
QTreeView* currentList = nullptr;
diff --git a/launcher/ui/pages/modplatform/legacy_ftb/Page.ui b/launcher/ui/pages/modplatform/legacy_ftb/Page.ui
index ad08dc25..56cba748 100644
--- a/launcher/ui/pages/modplatform/legacy_ftb/Page.ui
+++ b/launcher/ui/pages/modplatform/legacy_ftb/Page.ui
@@ -10,8 +10,29 @@
<height>602</height>
</rect>
</property>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
+ <layout class="QGridLayout" name="gridLayout_5">
+ <item row="0" column="0">
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QLineEdit" name="searchEdit">
+ <property name="placeholderText">
+ <string>Search and filter...</string>
+ </property>
+ <property name="clearButtonEnabled">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushButton">
+ <property name="text">
+ <string>Search</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="4" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
@@ -36,9 +57,9 @@
</item>
<item row="0" column="1">
<widget class="QTextBrowser" name="publicPackDescription">
- <property name="openExternalLinks">
- <bool>true</bool>
- </property>
+ <property name="openExternalLinks">
+ <bool>true</bool>
+ </property>
</widget>
</item>
</layout>
@@ -50,10 +71,10 @@
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="1">
<widget class="QTextBrowser" name="thirdPartyPackDescription">
- <property name="openExternalLinks">
- <bool>true</bool>
- </property>
- </widget>
+ <property name="openExternalLinks">
+ <bool>true</bool>
+ </property>
+ </widget>
</item>
<item row="0" column="0">
<widget class="QTreeView" name="thirdPartyPackList">
@@ -104,16 +125,16 @@
</item>
<item row="0" column="1" rowspan="3">
<widget class="QTextBrowser" name="privatePackDescription">
- <property name="openExternalLinks">
- <bool>true</bool>
- </property>
- </widget>
+ <property name="openExternalLinks">
+ <bool>true</bool>
+ </property>
+ </widget>
</item>
</layout>
</widget>
</widget>
</item>
- <item>
+ <item row="5" column="0">
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="1">
<widget class="QLabel" name="label">
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp
index 761e265d..f691a185 100644
--- a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp
+++ b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp
@@ -38,10 +38,12 @@
#include "BuildConfig.h"
#include "Json.h"
-#include "minecraft/MinecraftInstance.h"
-#include "minecraft/PackProfile.h"
+#include "modplatform/modrinth/ModrinthAPI.h"
+#include "net/NetJob.h"
#include "ui/widgets/ProjectItem.h"
+#include "net/ApiDownload.h"
+
#include <QMessageBox>
namespace Modrinth {
@@ -115,7 +117,7 @@ auto ModpackListModel::data(const QModelIndex& index, int role) const -> QVarian
return {};
}
-bool ModpackListModel::setData(const QModelIndex& index, const QVariant& value, int role)
+bool ModpackListModel::setData(const QModelIndex& index, const QVariant& value, [[maybe_unused]] int role)
{
int pos = index.row();
if (pos >= modpacks.size() || pos < 0 || !index.isValid())
@@ -128,7 +130,24 @@ bool ModpackListModel::setData(const QModelIndex& index, const QVariant& value,
void ModpackListModel::performPaginatedSearch()
{
- // TODO: Move to standalone API
+ if (hasActiveSearchJob())
+ return;
+
+ if (currentSearchTerm.startsWith("#")) {
+ auto projectId = currentSearchTerm.mid(1);
+ if (!projectId.isEmpty()) {
+ ResourceAPI::ProjectInfoCallbacks callbacks;
+
+ callbacks.on_fail = [this](QString reason) { searchRequestFailed(reason); };
+ callbacks.on_succeed = [this](auto& doc, auto& pack) { searchRequestForOneSucceeded(doc); };
+ static const ModrinthAPI api;
+ if (auto job = api.getProjectInfo({ projectId }, std::move(callbacks)); job) {
+ jobPtr = job;
+ jobPtr->start();
+ }
+ return;
+ }
+ } // TODO: Move to standalone API
auto netJob = makeShared<NetJob>("Modrinth::SearchModpack", APPLICATION->network());
auto searchAllUrl = QString(BuildConfig.MODRINTH_PROD_URL +
"/search?"
@@ -142,7 +161,7 @@ void ModpackListModel::performPaginatedSearch()
.arg(currentSearchTerm)
.arg(currentSort);
- netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchAllUrl), m_all_response));
+ netJob->addNetAction(Net::ApiDownload::makeByteArray(QUrl(searchAllUrl), m_all_response));
QObject::connect(netJob.get(), &NetJob::succeeded, this, [this] {
QJsonParseError parse_error_all{};
@@ -165,16 +184,17 @@ void ModpackListModel::performPaginatedSearch()
void ModpackListModel::refresh()
{
- if (jobPtr) {
+ if (hasActiveSearchJob()) {
jobPtr->abort();
searchState = ResetRequested;
return;
- } else {
- beginResetModel();
- modpacks.clear();
- endResetModel();
- searchState = None;
}
+
+ beginResetModel();
+ modpacks.clear();
+ endResetModel();
+ searchState = None;
+
nextSearchOffset = 0;
performPaginatedSearch();
}
@@ -194,8 +214,6 @@ static auto sortFromIndex(int index) -> QString
case 4:
return "updated";
}
-
- return {};
}
void ModpackListModel::searchWithTerm(const QString& term, const int sort)
@@ -218,9 +236,7 @@ void ModpackListModel::searchWithTerm(const QString& term, const int sort)
void ModpackListModel::getLogo(const QString& logo, const QString& logoUrl, LogoCallback callback)
{
if (m_logoMap.contains(logo)) {
- callback(APPLICATION->metacache()
- ->resolveEntry(m_parent->metaEntryBase(), QString("logos/%1").arg(logo.section(".", 0, 0)))
- ->getFullPath());
+ callback(APPLICATION->metacache()->resolveEntry(m_parent->metaEntryBase(), QString("logos/%1").arg(logo))->getFullPath());
} else {
requestLogo(logo, logoUrl);
}
@@ -232,10 +248,9 @@ void ModpackListModel::requestLogo(QString logo, QString url)
return;
}
- MetaEntryPtr entry =
- APPLICATION->metacache()->resolveEntry(m_parent->metaEntryBase(), QString("logos/%1").arg(logo.section(".", 0, 0)));
+ MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry(m_parent->metaEntryBase(), QString("logos/%1").arg(logo));
auto job = new NetJob(QString("%1 Icon Download %2").arg(m_parent->debugName()).arg(logo), APPLICATION->network());
- job->addNetAction(Net::Download::makeCached(QUrl(url), entry));
+ job->addNetAction(Net::ApiDownload::makeCached(QUrl(url), entry));
auto fullPath = entry->getFullPath();
QObject::connect(job, &NetJob::succeeded, this, [this, logo, fullPath, job] {
@@ -310,9 +325,29 @@ void ModpackListModel::searchRequestFinished(QJsonDocument& doc_all)
endInsertRows();
}
+void ModpackListModel::searchRequestForOneSucceeded(QJsonDocument& doc)
+{
+ jobPtr.reset();
+
+ auto packObj = doc.object();
+
+ Modrinth::Modpack pack;
+ try {
+ Modrinth::loadIndexedPack(pack, packObj);
+ pack.id = Json::ensureString(packObj, "id", pack.id);
+ } catch (const JSONValidationError& e) {
+ qWarning() << "Error while loading mod from " << m_parent->debugName() << ": " << e.cause();
+ return;
+ }
+
+ beginInsertRows(QModelIndex(), modpacks.size(), modpacks.size() + 1);
+ modpacks.append({ pack });
+ endInsertRows();
+}
+
void ModpackListModel::searchRequestFailed(QString reason)
{
- auto failed_action = jobPtr->getFailedActions().at(0);
+ auto failed_action = dynamic_cast<NetJob*>(jobPtr.get())->getFailedActions().at(0);
if (!failed_action->m_reply) {
// Network error
QMessageBox::critical(nullptr, tr("Error"), tr("A network error occurred. Could not load modpacks."));
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h
index 721c69f5..2a9d6226 100644
--- a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h
+++ b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h
@@ -73,6 +73,9 @@ class ModpackListModel : public QAbstractListModel {
void refresh();
void searchWithTerm(const QString& term, const int sort);
+ [[nodiscard]] bool hasActiveSearchJob() const { return jobPtr && jobPtr->isRunning(); }
+ [[nodiscard]] Task::Ptr activeSearchJob() { return hasActiveSearchJob() ? jobPtr : nullptr; }
+
void getLogo(const QString& logo, const QString& logoUrl, LogoCallback callback);
inline auto canFetchMore(const QModelIndex& parent) const -> bool override
@@ -83,6 +86,7 @@ class ModpackListModel : public QAbstractListModel {
public slots:
void searchRequestFinished(QJsonDocument& doc_all);
void searchRequestFailed(QString reason);
+ void searchRequestForOneSucceeded(QJsonDocument&);
protected slots:
@@ -111,7 +115,7 @@ class ModpackListModel : public QAbstractListModel {
int nextSearchOffset = 0;
enum SearchState { None, CanPossiblyFetchMore, ResetRequested, Finished } searchState = None;
- NetJob::Ptr jobPtr;
+ Task::Ptr jobPtr;
std::shared_ptr<QByteArray> m_all_response = std::make_shared<QByteArray>();
QByteArray m_specific_response;
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp
index b4d73b2f..8e2b9a90 100644
--- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp
+++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp
@@ -46,11 +46,14 @@
#include "ui/widgets/ProjectItem.h"
+#include "net/ApiDownload.h"
+
#include <QComboBox>
#include <QKeyEvent>
#include <QPushButton>
-ModrinthPage::ModrinthPage(NewInstanceDialog* dialog, QWidget* parent) : QWidget(parent), ui(new Ui::ModrinthPage), dialog(dialog)
+ModrinthPage::ModrinthPage(NewInstanceDialog* dialog, QWidget* parent)
+ : QWidget(parent), ui(new Ui::ModrinthPage), dialog(dialog), m_fetch_progress(this, false)
{
ui->setupUi(this);
@@ -62,6 +65,17 @@ ModrinthPage::ModrinthPage(NewInstanceDialog* dialog, QWidget* parent) : QWidget
ui->versionSelectionBox->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
ui->versionSelectionBox->view()->parentWidget()->setMaximumHeight(300);
+ m_search_timer.setTimerType(Qt::TimerType::CoarseTimer);
+ m_search_timer.setSingleShot(true);
+
+ connect(&m_search_timer, &QTimer::timeout, this, &ModrinthPage::triggerSearch);
+
+ m_fetch_progress.hideIfInactive(true);
+ m_fetch_progress.setFixedHeight(24);
+ m_fetch_progress.progressFormat("");
+
+ ui->gridLayout->addWidget(&m_fetch_progress, 2, 0, 1, ui->gridLayout->columnCount());
+
ui->sortByBox->addItem(tr("Sort by Relevance"));
ui->sortByBox->addItem(tr("Sort by Total Downloads"));
ui->sortByBox->addItem(tr("Sort by Follows"));
@@ -100,12 +114,17 @@ bool ModrinthPage::eventFilter(QObject* watched, QEvent* event)
this->triggerSearch();
keyEvent->accept();
return true;
+ } else {
+ if (m_search_timer.isActive())
+ m_search_timer.stop();
+
+ m_search_timer.start(350);
}
}
return QObject::eventFilter(watched, event);
}
-void ModrinthPage::onSelectionChanged(QModelIndex curr, QModelIndex prev)
+void ModrinthPage::onSelectionChanged(QModelIndex curr, [[maybe_unused]] QModelIndex prev)
{
ui->versionSelectionBox->clear();
@@ -127,7 +146,7 @@ void ModrinthPage::onSelectionChanged(QModelIndex curr, QModelIndex prev)
QString id = current.id;
- netJob->addNetAction(Net::Download::makeByteArray(QString("%1/project/%2").arg(BuildConfig.MODRINTH_PROD_URL, id), response));
+ netJob->addNetAction(Net::ApiDownload::makeByteArray(QString("%1/project/%2").arg(BuildConfig.MODRINTH_PROD_URL, id), response));
QObject::connect(netJob, &NetJob::succeeded, this, [this, response, id, curr] {
if (id != current.id) {
@@ -176,7 +195,7 @@ void ModrinthPage::onSelectionChanged(QModelIndex curr, QModelIndex prev)
QString id = current.id;
netJob->addNetAction(
- Net::Download::makeByteArray(QString("%1/project/%2/version").arg(BuildConfig.MODRINTH_PROD_URL, id), response));
+ Net::ApiDownload::makeByteArray(QString("%1/project/%2/version").arg(BuildConfig.MODRINTH_PROD_URL, id), response));
QObject::connect(netJob, &NetJob::succeeded, this, [this, response, id, curr] {
if (id != current.id) {
@@ -308,11 +327,12 @@ void ModrinthPage::suggestCurrent()
void ModrinthPage::triggerSearch()
{
m_model->searchWithTerm(ui->searchEdit->text(), ui->sortByBox->currentIndex());
+ m_fetch_progress.watch(m_model->activeSearchJob().get());
}
-void ModrinthPage::onVersionSelectionChanged(QString data)
+void ModrinthPage::onVersionSelectionChanged(QString version)
{
- if (data.isNull() || data.isEmpty()) {
+ if (version.isNull() || version.isEmpty()) {
selectedVersion = "";
return;
}
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h
index b7054c88..4240dcaf 100644
--- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h
+++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h
@@ -41,7 +41,9 @@
#include "ui/pages/BasePage.h"
#include "modplatform/modrinth/ModrinthPackManifest.h"
+#include "ui/widgets/ProgressWidget.h"
+#include <QTimer>
#include <QWidget>
namespace Ui {
@@ -88,4 +90,9 @@ class ModrinthPage : public QWidget, public BasePage {
Modrinth::Modpack current;
QString selectedVersion;
+
+ ProgressWidget m_fetch_progress;
+
+ // Used to do instant searching with a delay to cache quick changes
+ QTimer m_search_timer;
};
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.ui b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.ui
index 6d8b2b67..78a25fea 100644
--- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.ui
+++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.ui
@@ -10,8 +10,8 @@
<height>600</height>
</rect>
</property>
- <layout class="QVBoxLayout">
- <item>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="font">
<font>
@@ -29,7 +29,7 @@
</property>
</widget>
</item>
- <item>
+ <item row="1" column="0">
<layout class="QHBoxLayout">
<item>
<widget class="QLineEdit" name="searchEdit">
@@ -47,7 +47,7 @@
</item>
</layout>
</item>
- <item>
+ <item row="3" column="0">
<layout class="QHBoxLayout">
<item>
<widget class="QListView" name="packView">
@@ -77,7 +77,7 @@
</item>
</layout>
</item>
- <item>
+ <item row="4" column="0">
<layout class="QHBoxLayout">
<item>
<widget class="QComboBox" name="sortByBox"/>
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthResourceModels.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthResourceModels.cpp
index 00a0108a..85601829 100644
--- a/launcher/ui/pages/modplatform/modrinth/ModrinthResourceModels.cpp
+++ b/launcher/ui/pages/modplatform/modrinth/ModrinthResourceModels.cpp
@@ -39,13 +39,13 @@ void ModrinthModModel::loadExtraPackInfo(ModPlatform::IndexedPack& m, QJsonObjec
void ModrinthModModel::loadIndexedPackVersions(ModPlatform::IndexedPack& m, QJsonArray& arr)
{
- ::Modrinth::loadIndexedPackVersions(m, arr, APPLICATION->network(), &m_base_instance);
+ ::Modrinth::loadIndexedPackVersions(m, arr, &m_base_instance);
}
auto ModrinthModModel::loadDependencyVersions(const ModPlatform::Dependency& m, QJsonArray& arr) -> ModPlatform::IndexedVersion
{
- return ::Modrinth::loadDependencyVersions(m, arr);
-};
+ return ::Modrinth::loadDependencyVersions(m, arr, &m_base_instance);
+}
auto ModrinthModModel::documentToArray(QJsonDocument& obj) const -> QJsonArray
{
@@ -66,7 +66,7 @@ void ModrinthResourcePackModel::loadExtraPackInfo(ModPlatform::IndexedPack& m, Q
void ModrinthResourcePackModel::loadIndexedPackVersions(ModPlatform::IndexedPack& m, QJsonArray& arr)
{
- ::Modrinth::loadIndexedPackVersions(m, arr, APPLICATION->network(), &m_base_instance);
+ ::Modrinth::loadIndexedPackVersions(m, arr, &m_base_instance);
}
auto ModrinthResourcePackModel::documentToArray(QJsonDocument& obj) const -> QJsonArray
@@ -88,7 +88,7 @@ void ModrinthTexturePackModel::loadExtraPackInfo(ModPlatform::IndexedPack& m, QJ
void ModrinthTexturePackModel::loadIndexedPackVersions(ModPlatform::IndexedPack& m, QJsonArray& arr)
{
- ::Modrinth::loadIndexedPackVersions(m, arr, APPLICATION->network(), &m_base_instance);
+ ::Modrinth::loadIndexedPackVersions(m, arr, &m_base_instance);
}
auto ModrinthTexturePackModel::documentToArray(QJsonDocument& obj) const -> QJsonArray
@@ -110,7 +110,7 @@ void ModrinthShaderPackModel::loadExtraPackInfo(ModPlatform::IndexedPack& m, QJs
void ModrinthShaderPackModel::loadIndexedPackVersions(ModPlatform::IndexedPack& m, QJsonArray& arr)
{
- ::Modrinth::loadIndexedPackVersions(m, arr, APPLICATION->network(), &m_base_instance);
+ ::Modrinth::loadIndexedPackVersions(m, arr, &m_base_instance);
}
auto ModrinthShaderPackModel::documentToArray(QJsonDocument& obj) const -> QJsonArray
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthResourcePages.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthResourcePages.cpp
index 616c1a81..a4197b22 100644
--- a/launcher/ui/pages/modplatform/modrinth/ModrinthResourcePages.cpp
+++ b/launcher/ui/pages/modplatform/modrinth/ModrinthResourcePages.cpp
@@ -65,21 +65,9 @@ ModrinthModPage::ModrinthModPage(ModDownloadDialog* dialog, BaseInstance& instan
auto ModrinthModPage::validateVersion(ModPlatform::IndexedVersion& ver,
QString mineVer,
- std::optional<ResourceAPI::ModLoaderTypes> loaders) const -> bool
+ std::optional<ModPlatform::ModLoaderTypes> loaders) const -> bool
{
- auto loaderCompatible = !loaders.has_value();
-
- if (!loaderCompatible) {
- auto loaderStrings = ModrinthAPI::getModLoaderStrings(loaders.value());
- for (auto remoteLoader : ver.loaders) {
- if (loaderStrings.contains(remoteLoader)) {
- loaderCompatible = true;
- break;
- }
- }
- }
-
- return ver.mcVersion.contains(mineVer) && loaderCompatible;
+ return ver.mcVersion.contains(mineVer) && (!loaders.has_value() || !ver.loaders || loaders.value() & ver.loaders);
}
ModrinthResourcePackPage::ModrinthResourcePackPage(ResourcePackDownloadDialog* dialog, BaseInstance& instance)
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthResourcePages.h b/launcher/ui/pages/modplatform/modrinth/ModrinthResourcePages.h
index 86ba1ccb..311bcfe3 100644
--- a/launcher/ui/pages/modplatform/modrinth/ModrinthResourcePages.h
+++ b/launcher/ui/pages/modplatform/modrinth/ModrinthResourcePages.h
@@ -93,7 +93,7 @@ class ModrinthModPage : public ModPage {
[[nodiscard]] inline auto helpPage() const -> QString override { return "Mod-platform"; }
- auto validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, std::optional<ResourceAPI::ModLoaderTypes> loaders = {}) const
+ auto validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, std::optional<ModPlatform::ModLoaderTypes> loaders = {}) const
-> bool override;
};
diff --git a/launcher/ui/pages/modplatform/technic/TechnicModel.cpp b/launcher/ui/pages/modplatform/technic/TechnicModel.cpp
index 02d7fd5b..3cd1d9a2 100644
--- a/launcher/ui/pages/modplatform/technic/TechnicModel.cpp
+++ b/launcher/ui/pages/modplatform/technic/TechnicModel.cpp
@@ -38,6 +38,9 @@
#include "BuildConfig.h"
#include "Json.h"
+#include "net/ApiDownload.h"
+#include "ui/widgets/ProjectItem.h"
+
#include <QIcon>
Technic::ListModel::ListModel(QObject* parent) : QAbstractListModel(parent) {}
@@ -52,21 +55,47 @@ QVariant Technic::ListModel::data(const QModelIndex& index, int role) const
}
Modpack pack = modpacks.at(pos);
- if (role == Qt::DisplayRole) {
- return pack.name;
- } else if (role == Qt::DecorationRole) {
- if (m_logoMap.contains(pack.logoName)) {
- return (m_logoMap.value(pack.logoName));
+ switch (role) {
+ case Qt::ToolTipRole: {
+ if (pack.description.length() > 100) {
+ // some magic to prevent to long tooltips and replace html linebreaks
+ QString edit = pack.description.left(97);
+ edit = edit.left(edit.lastIndexOf("<br>")).left(edit.lastIndexOf(" ")).append("...");
+ return edit;
+ }
+ return pack.description;
+ }
+ case Qt::DecorationRole: {
+ if (m_logoMap.contains(pack.logoName)) {
+ return (m_logoMap.value(pack.logoName));
+ }
+ QIcon icon = APPLICATION->getThemedIcon("screenshot-placeholder");
+ ((ListModel*)this)->requestLogo(pack.logoName, pack.logoUrl);
+ return icon;
}
- QIcon icon = APPLICATION->getThemedIcon("screenshot-placeholder");
- ((ListModel*)this)->requestLogo(pack.logoName, pack.logoUrl);
- return icon;
- } else if (role == Qt::UserRole) {
- QVariant v;
- v.setValue(pack);
- return v;
+ case Qt::UserRole: {
+ QVariant v;
+ v.setValue(pack);
+ return v;
+ }
+ case Qt::DisplayRole:
+ return pack.name;
+ case Qt::SizeHintRole:
+ return QSize(0, 58);
+ // Custom data
+ case UserDataTypes::TITLE:
+ return pack.name;
+ case UserDataTypes::DESCRIPTION:
+ return pack.description;
+ case UserDataTypes::SELECTED:
+ return false;
+ case UserDataTypes::INSTALLED:
+ return false;
+ default:
+ break;
}
- return QVariant();
+
+ return {};
}
int Technic::ListModel::columnCount(const QModelIndex& parent) const
@@ -85,21 +114,25 @@ void Technic::ListModel::searchWithTerm(const QString& term)
return;
}
currentSearchTerm = term;
- if (jobPtr) {
+ if (hasActiveSearchJob()) {
jobPtr->abort();
searchState = ResetRequested;
return;
- } else {
- beginResetModel();
- modpacks.clear();
- endResetModel();
- searchState = None;
}
+
+ beginResetModel();
+ modpacks.clear();
+ endResetModel();
+ searchState = None;
+
performSearch();
}
void Technic::ListModel::performSearch()
{
+ if (hasActiveSearchJob())
+ return;
+
auto netJob = makeShared<NetJob>("Technic::Search", APPLICATION->network());
QString searchUrl = "";
if (currentSearchTerm.isEmpty()) {
@@ -111,12 +144,15 @@ void Technic::ListModel::performSearch()
} else if (currentSearchTerm.startsWith("https://api.technicpack.net/modpack/")) {
searchUrl = QString("%1?build=%2").arg(currentSearchTerm, BuildConfig.TECHNIC_API_BUILD);
searchMode = Single;
+ } else if (currentSearchTerm.startsWith("#")) {
+ searchUrl = QString("https://api.technicpack.net/modpack/%1?build=%2").arg(currentSearchTerm.mid(1), BuildConfig.TECHNIC_API_BUILD);
+ searchMode = Single;
} else {
searchUrl =
QString("%1search?build=%2&q=%3").arg(BuildConfig.TECHNIC_API_BASE_URL, BuildConfig.TECHNIC_API_BUILD, currentSearchTerm);
searchMode = List;
}
- netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), response));
+ netJob->addNetAction(Net::ApiDownload::makeByteArray(QUrl(searchUrl), response));
jobPtr = netJob;
jobPtr->start();
QObject::connect(netJob.get(), &NetJob::succeeded, this, &ListModel::searchRequestFinished);
@@ -157,7 +193,7 @@ void Technic::ListModel::searchRequestFinished()
pack.logoName = "null";
} else {
pack.logoUrl = rawURL;
- pack.logoName = rawURL.section(QLatin1Char('/'), -1).section(QLatin1Char('.'), 0, 0);
+ pack.logoName = rawURL.section(QLatin1Char('/'), -1);
}
pack.broken = false;
newList.append(pack);
@@ -179,7 +215,7 @@ void Technic::ListModel::searchRequestFinished()
auto iconUrl = Json::requireString(iconObj, "url");
pack.logoUrl = iconUrl;
- pack.logoName = iconUrl.section(QLatin1Char('/'), -1).section(QLatin1Char('.'), 0, 0);
+ pack.logoName = iconUrl.section(QLatin1Char('/'), -1);
} else {
pack.logoUrl = "null";
pack.logoName = "null";
@@ -254,7 +290,7 @@ void Technic::ListModel::requestLogo(QString logo, QString url)
MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("TechnicPacks", QString("logos/%1").arg(logo));
auto job = new NetJob(QString("Technic Icon Download %1").arg(logo), APPLICATION->network());
- job->addNetAction(Net::Download::makeCached(QUrl(url), entry));
+ job->addNetAction(Net::ApiDownload::makeCached(QUrl(url), entry));
auto fullPath = entry->getFullPath();
diff --git a/launcher/ui/pages/modplatform/technic/TechnicModel.h b/launcher/ui/pages/modplatform/technic/TechnicModel.h
index d7a635d4..aeb4f308 100644
--- a/launcher/ui/pages/modplatform/technic/TechnicModel.h
+++ b/launcher/ui/pages/modplatform/technic/TechnicModel.h
@@ -58,6 +58,9 @@ class ListModel : public QAbstractListModel {
void getLogo(const QString& logo, const QString& logoUrl, LogoCallback callback);
void searchWithTerm(const QString& term);
+ [[nodiscard]] bool hasActiveSearchJob() const { return jobPtr && jobPtr->isRunning(); }
+ [[nodiscard]] Task::Ptr activeSearchJob() { return hasActiveSearchJob() ? jobPtr : nullptr; }
+
private slots:
void searchRequestFinished();
void searchRequestFailed();
diff --git a/launcher/ui/pages/modplatform/technic/TechnicPage.cpp b/launcher/ui/pages/modplatform/technic/TechnicPage.cpp
index 88132754..190b7c68 100644
--- a/launcher/ui/pages/modplatform/technic/TechnicPage.cpp
+++ b/launcher/ui/pages/modplatform/technic/TechnicPage.cpp
@@ -34,6 +34,7 @@
*/
#include "TechnicPage.h"
+#include "ui/widgets/ProjectItem.h"
#include "ui_TechnicPage.h"
#include <QKeyEvent>
@@ -49,7 +50,10 @@
#include "Application.h"
#include "modplatform/technic/SolderPackManifest.h"
-TechnicPage::TechnicPage(NewInstanceDialog* dialog, QWidget* parent) : QWidget(parent), ui(new Ui::TechnicPage), dialog(dialog)
+#include "net/ApiDownload.h"
+
+TechnicPage::TechnicPage(NewInstanceDialog* dialog, QWidget* parent)
+ : QWidget(parent), ui(new Ui::TechnicPage), dialog(dialog), m_fetch_progress(this, false)
{
ui->setupUi(this);
connect(ui->searchButton, &QPushButton::clicked, this, &TechnicPage::triggerSearch);
@@ -57,8 +61,21 @@ TechnicPage::TechnicPage(NewInstanceDialog* dialog, QWidget* parent) : QWidget(p
model = new Technic::ListModel(this);
ui->packView->setModel(model);
+ m_search_timer.setTimerType(Qt::TimerType::CoarseTimer);
+ m_search_timer.setSingleShot(true);
+
+ connect(&m_search_timer, &QTimer::timeout, this, &TechnicPage::triggerSearch);
+
+ m_fetch_progress.hideIfInactive(true);
+ m_fetch_progress.setFixedHeight(24);
+ m_fetch_progress.progressFormat("");
+
+ ui->gridLayout->addWidget(&m_fetch_progress, 2, 0, 1, ui->gridLayout->columnCount());
+
connect(ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &TechnicPage::onSelectionChanged);
connect(ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &TechnicPage::onVersionSelectionChanged);
+
+ ui->packView->setItemDelegate(new ProjectItemDelegate(this));
}
bool TechnicPage::eventFilter(QObject* watched, QEvent* event)
@@ -69,6 +86,11 @@ bool TechnicPage::eventFilter(QObject* watched, QEvent* event)
triggerSearch();
keyEvent->accept();
return true;
+ } else {
+ if (m_search_timer.isActive())
+ m_search_timer.stop();
+
+ m_search_timer.start(350);
}
}
return QWidget::eventFilter(watched, event);
@@ -98,9 +120,10 @@ void TechnicPage::openedImpl()
void TechnicPage::triggerSearch()
{
model->searchWithTerm(ui->searchEdit->text());
+ m_fetch_progress.watch(model->activeSearchJob().get());
}
-void TechnicPage::onSelectionChanged(QModelIndex first, QModelIndex second)
+void TechnicPage::onSelectionChanged(QModelIndex first, [[maybe_unused]] QModelIndex second)
{
ui->versionSelectionBox->clear();
@@ -125,7 +148,7 @@ void TechnicPage::suggestCurrent()
return;
}
- QString editedLogoName = "technic_" + current.logoName.section(".", 0, 0);
+ QString editedLogoName = "technic_" + current.logoName;
model->getLogo(current.logoName, current.logoUrl,
[this, editedLogoName](QString logo) { dialog->setSuggestedIconFromFile(logo, editedLogoName); });
@@ -136,7 +159,7 @@ void TechnicPage::suggestCurrent()
auto netJob = makeShared<NetJob>(QString("Technic::PackMeta(%1)").arg(current.name), APPLICATION->network());
QString slug = current.slug;
- netJob->addNetAction(Net::Download::makeByteArray(
+ netJob->addNetAction(Net::ApiDownload::makeByteArray(
QString("%1modpack/%2?build=%3").arg(BuildConfig.TECHNIC_API_BASE_URL, slug, BuildConfig.TECHNIC_API_BUILD), response));
QObject::connect(netJob.get(), &NetJob::succeeded, this, [this, slug] {
jobPtr.reset();
@@ -232,7 +255,7 @@ void TechnicPage::metadataLoaded()
auto netJob = makeShared<NetJob>(QString("Technic::SolderMeta(%1)").arg(current.name), APPLICATION->network());
auto url = QString("%1/modpack/%2").arg(current.url, current.slug);
- netJob->addNetAction(Net::Download::makeByteArray(QUrl(url), response));
+ netJob->addNetAction(Net::ApiDownload::makeByteArray(QUrl(url), response));
QObject::connect(netJob.get(), &NetJob::succeeded, this, &TechnicPage::onSolderLoaded);
@@ -304,13 +327,13 @@ void TechnicPage::onSolderLoaded()
metadataLoaded();
}
-void TechnicPage::onVersionSelectionChanged(QString data)
+void TechnicPage::onVersionSelectionChanged(QString version)
{
- if (data.isNull() || data.isEmpty()) {
+ if (version.isNull() || version.isEmpty()) {
selectedVersion = "";
return;
}
- selectedVersion = data;
+ selectedVersion = version;
selectVersion();
}
diff --git a/launcher/ui/pages/modplatform/technic/TechnicPage.h b/launcher/ui/pages/modplatform/technic/TechnicPage.h
index 91b61eaf..01439337 100644
--- a/launcher/ui/pages/modplatform/technic/TechnicPage.h
+++ b/launcher/ui/pages/modplatform/technic/TechnicPage.h
@@ -35,13 +35,14 @@
#pragma once
+#include <QTimer>
#include <QWidget>
#include <Application.h>
#include "TechnicData.h"
#include "net/NetJob.h"
-#include "tasks/Task.h"
#include "ui/pages/BasePage.h"
+#include "ui/widgets/ProgressWidget.h"
namespace Ui {
class TechnicPage;
@@ -91,4 +92,9 @@ class TechnicPage : public QWidget, public BasePage {
NetJob::Ptr jobPtr;
std::shared_ptr<QByteArray> response = std::make_shared<QByteArray>();
+
+ ProgressWidget m_fetch_progress;
+
+ // Used to do instant searching with a delay to cache quick changes
+ QTimer m_search_timer;
};
diff --git a/launcher/ui/pages/modplatform/technic/TechnicPage.ui b/launcher/ui/pages/modplatform/technic/TechnicPage.ui
index 15bf645f..b988eda2 100644
--- a/launcher/ui/pages/modplatform/technic/TechnicPage.ui
+++ b/launcher/ui/pages/modplatform/technic/TechnicPage.ui
@@ -11,7 +11,7 @@
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
- <item row="3" column="0" colspan="2">
+ <item row="4" column="0" colspan="2">
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="2">
<widget class="QComboBox" name="versionSelectionBox"/>
@@ -44,7 +44,7 @@
</item>
</layout>
</item>
- <item row="2" column="0" colspan="2">
+ <item row="3" column="0" colspan="2">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QListView" name="packView">
diff --git a/launcher/ui/setupwizard/ThemeWizardPage.cpp b/launcher/ui/setupwizard/ThemeWizardPage.cpp
index 1c336921..fe11ed9a 100644
--- a/launcher/ui/setupwizard/ThemeWizardPage.cpp
+++ b/launcher/ui/setupwizard/ThemeWizardPage.cpp
@@ -61,7 +61,7 @@ void ThemeWizardPage::updateIcons()
void ThemeWizardPage::updateCat()
{
qDebug() << "Setting Cat";
- ui->catImagePreviewButton->setIcon(QIcon(QString(R"(%1)").arg(APPLICATION->getCatPack())));
+ ui->catImagePreviewButton->setIcon(QIcon(QString(R"(%1)").arg(APPLICATION->themeManager()->getCatPack())));
}
void ThemeWizardPage::retranslate()
diff --git a/launcher/ui/themes/CatPack.cpp b/launcher/ui/themes/CatPack.cpp
index f0d8ddd5..bbcb58bc 100644
--- a/launcher/ui/themes/CatPack.cpp
+++ b/launcher/ui/themes/CatPack.cpp
@@ -99,18 +99,22 @@ QDate ensureDay(int year, int month, int day)
QString JsonCatPack::path()
{
- const QDate now = QDate::currentDate();
+ return path(QDate::currentDate());
+}
+
+QString JsonCatPack::path(QDate now)
+{
for (auto var : m_variants) {
QDate startDate = ensureDay(now.year(), var.startTime.month, var.startTime.day);
QDate endDate = ensureDay(now.year(), var.endTime.month, var.endTime.day);
if (startDate > endDate) { // it's spans over multiple years
- if (endDate <= now) // end date is in the past so jump one year into the future for endDate
+ if (endDate < now) // end date is in the past so jump one year into the future for endDate
endDate = endDate.addYears(1);
else // end date is in the future so jump one year into the past for startDate
startDate = startDate.addYears(-1);
}
- if (startDate >= now && now >= endDate)
+ if (startDate <= now && now <= endDate)
return var.path;
}
return m_defaultPath;
diff --git a/launcher/ui/themes/CatPack.h b/launcher/ui/themes/CatPack.h
index b03a19f0..1d310e79 100644
--- a/launcher/ui/themes/CatPack.h
+++ b/launcher/ui/themes/CatPack.h
@@ -52,9 +52,9 @@ class BasicCatPack : public CatPack {
public:
BasicCatPack(QString id, QString name) : m_id(id), m_name(name) {}
BasicCatPack(QString id) : BasicCatPack(id, id) {}
- virtual QString id() { return m_id; };
- virtual QString name() { return m_name; };
- virtual QString path();
+ virtual QString id() override { return m_id; }
+ virtual QString name() override { return m_name; }
+ virtual QString path() override;
protected:
QString m_id;
@@ -83,7 +83,8 @@ class JsonCatPack : public BasicCatPack {
PartialDate endTime;
};
JsonCatPack(QFileInfo& manifestInfo);
- virtual QString path();
+ virtual QString path() override;
+ QString path(QDate now);
private:
QString m_defaultPath;
diff --git a/launcher/ui/themes/CustomTheme.cpp b/launcher/ui/themes/CustomTheme.cpp
index d1eaf157..29ecf625 100644
--- a/launcher/ui/themes/CustomTheme.cpp
+++ b/launcher/ui/themes/CustomTheme.cpp
@@ -148,7 +148,7 @@ static bool writeThemeJson(const QString& path,
try {
Json::write(rootObj, path);
return true;
- } catch (const Exception& e) {
+ } catch ([[maybe_unused]] const Exception& e) {
themeWarningLog() << "Failed to write theme json to" << path;
return false;
}
diff --git a/launcher/ui/themes/IconTheme.cpp b/launcher/ui/themes/IconTheme.cpp
new file mode 100644
index 00000000..4bd88985
--- /dev/null
+++ b/launcher/ui/themes/IconTheme.cpp
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include "IconTheme.h"
+
+#include <QFile>
+#include <QSettings>
+
+IconTheme::IconTheme(const QString& id, const QString& path) : m_id(id), m_path(path) {}
+
+bool IconTheme::load()
+{
+ const QString path = m_path + "/index.theme";
+
+ if (!QFile::exists(path))
+ return false;
+
+ QSettings settings(path, QSettings::IniFormat);
+ settings.beginGroup("Icon Theme");
+ m_name = settings.value("Name").toString();
+ settings.endGroup();
+ return !m_name.isNull();
+}
+
+QString IconTheme::id()
+{
+ return m_id;
+}
+
+QString IconTheme::path()
+{
+ return m_path;
+}
+
+QString IconTheme::name()
+{
+ return m_name;
+}
diff --git a/launcher/ui/themes/IconTheme.h b/launcher/ui/themes/IconTheme.h
new file mode 100644
index 00000000..4e466c6a
--- /dev/null
+++ b/launcher/ui/themes/IconTheme.h
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <QString>
+
+class IconTheme {
+ public:
+ IconTheme(const QString& id, const QString& path);
+ IconTheme() = default;
+
+ bool load();
+ QString id();
+ QString path();
+ QString name();
+
+ private:
+ QString m_id;
+ QString m_path;
+ QString m_name;
+};
diff --git a/launcher/ui/themes/ThemeManager.cpp b/launcher/ui/themes/ThemeManager.cpp
index 321f7db4..0bcac100 100644
--- a/launcher/ui/themes/ThemeManager.cpp
+++ b/launcher/ui/themes/ThemeManager.cpp
@@ -2,6 +2,7 @@
/*
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Tayou <git@tayou.org>
+ * Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -31,9 +32,8 @@
#include "Application.h"
-ThemeManager::ThemeManager(MainWindow* mainWindow)
+ThemeManager::ThemeManager()
{
- m_mainWindow = mainWindow;
initializeThemes();
initializeCatPacks();
}
@@ -59,53 +59,110 @@ ITheme* ThemeManager::getTheme(QString themeId)
return m_themes[themeId].get();
}
+QString ThemeManager::addIconTheme(IconTheme theme)
+{
+ QString id = theme.id();
+ if (m_icons.find(id) == m_icons.end())
+ m_icons.emplace(id, std::move(theme));
+ else
+ themeWarningLog() << "IconTheme(" << id << ") not added to prevent id duplication";
+ return id;
+}
+
void ThemeManager::initializeThemes()
{
// Icon themes
- {
- // TODO: icon themes and instance icons do not mesh well together. Rearrange and fix discrepancies!
- // set icon theme search path!
- auto searchPaths = QIcon::themeSearchPaths();
- searchPaths.append("iconthemes");
- QIcon::setThemeSearchPaths(searchPaths);
- themeDebugLog() << "<> Icon themes initialized.";
- }
+ initializeIcons();
// Initialize widget themes
- {
- themeDebugLog() << "<> Initializing Widget Themes";
- themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<SystemTheme>());
- auto darkThemeId = addTheme(std::make_unique<DarkTheme>());
- themeDebugLog() << "Loading Built-in Theme:" << darkThemeId;
- themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<BrightTheme>());
-
- // TODO: need some way to differentiate same name themes in different subdirectories (maybe smaller grey text next to theme name in
- // dropdown?)
- QString themeFolder = QDir("./themes/").absoluteFilePath("");
- themeDebugLog() << "Theme Folder Path: " << themeFolder;
-
- QDirIterator directoryIterator(themeFolder, QDir::Dirs | QDir::NoDotAndDotDot);
- while (directoryIterator.hasNext()) {
- QDir dir(directoryIterator.next());
- QFileInfo themeJson(dir.absoluteFilePath("theme.json"));
- if (themeJson.exists()) {
- // Load "theme.json" based themes
- themeDebugLog() << "Loading JSON Theme from:" << themeJson.absoluteFilePath();
- addTheme(std::make_unique<CustomTheme>(getTheme(darkThemeId), themeJson, true));
- } else {
- // Load pure QSS Themes
- QDirIterator stylesheetFileIterator(dir.absoluteFilePath(""), { "*.qss", "*.css" }, QDir::Files);
- while (stylesheetFileIterator.hasNext()) {
- QFile customThemeFile(stylesheetFileIterator.next());
- QFileInfo customThemeFileInfo(customThemeFile);
- themeDebugLog() << "Loading QSS Theme from:" << customThemeFileInfo.absoluteFilePath();
- addTheme(std::make_unique<CustomTheme>(getTheme(darkThemeId), customThemeFileInfo, false));
- }
+ initializeWidgets();
+}
+
+void ThemeManager::initializeIcons()
+{
+ // TODO: icon themes and instance icons do not mesh well together. Rearrange and fix discrepancies!
+ // set icon theme search path!
+ themeDebugLog() << "<> Initializing Icon Themes";
+
+ auto searchPaths = QIcon::themeSearchPaths();
+ searchPaths.append(m_iconThemeFolder.path());
+ QIcon::setThemeSearchPaths(searchPaths);
+
+ for (const QString& id : builtinIcons) {
+ IconTheme theme(id, QString(":/icons/%1").arg(id));
+ if (!theme.load()) {
+ themeWarningLog() << "Couldn't load built-in icon theme" << id;
+ continue;
+ }
+
+ addIconTheme(std::move(theme));
+ themeDebugLog() << "Loaded Built-In Icon Theme" << id;
+ }
+
+ if (!m_iconThemeFolder.mkpath("."))
+ themeWarningLog() << "Couldn't create icon theme folder";
+ themeDebugLog() << "Icon Theme Folder Path: " << m_iconThemeFolder.absolutePath();
+
+ QDirIterator directoryIterator(m_iconThemeFolder.path(), QDir::Dirs | QDir::NoDotAndDotDot);
+ while (directoryIterator.hasNext()) {
+ QDir dir(directoryIterator.next());
+ IconTheme theme(dir.dirName(), dir.path());
+ if (!theme.load())
+ continue;
+
+ addIconTheme(std::move(theme));
+ themeDebugLog() << "Loaded Custom Icon Theme from" << dir.path();
+ }
+
+ themeDebugLog() << "<> Icon themes initialized.";
+}
+
+void ThemeManager::initializeWidgets()
+{
+ themeDebugLog() << "<> Initializing Widget Themes";
+ themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<SystemTheme>());
+ auto darkThemeId = addTheme(std::make_unique<DarkTheme>());
+ themeDebugLog() << "Loading Built-in Theme:" << darkThemeId;
+ themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<BrightTheme>());
+
+ // TODO: need some way to differentiate same name themes in different subdirectories (maybe smaller grey text next to theme name in
+ // dropdown?)
+
+ if (!m_applicationThemeFolder.mkpath("."))
+ themeWarningLog() << "Couldn't create theme folder";
+ themeDebugLog() << "Theme Folder Path: " << m_applicationThemeFolder.absolutePath();
+
+ QDirIterator directoryIterator(m_applicationThemeFolder.path(), QDir::Dirs | QDir::NoDotAndDotDot);
+ while (directoryIterator.hasNext()) {
+ QDir dir(directoryIterator.next());
+ QFileInfo themeJson(dir.absoluteFilePath("theme.json"));
+ if (themeJson.exists()) {
+ // Load "theme.json" based themes
+ themeDebugLog() << "Loading JSON Theme from:" << themeJson.absoluteFilePath();
+ addTheme(std::make_unique<CustomTheme>(getTheme(darkThemeId), themeJson, true));
+ } else {
+ // Load pure QSS Themes
+ QDirIterator stylesheetFileIterator(dir.absoluteFilePath(""), { "*.qss", "*.css" }, QDir::Files);
+ while (stylesheetFileIterator.hasNext()) {
+ QFile customThemeFile(stylesheetFileIterator.next());
+ QFileInfo customThemeFileInfo(customThemeFile);
+ themeDebugLog() << "Loading QSS Theme from:" << customThemeFileInfo.absoluteFilePath();
+ addTheme(std::make_unique<CustomTheme>(getTheme(darkThemeId), customThemeFileInfo, false));
}
}
+ }
- themeDebugLog() << "<> Widget themes initialized.";
+ themeDebugLog() << "<> Widget themes initialized.";
+}
+
+QList<IconTheme*> ThemeManager::getValidIconThemes()
+{
+ QList<IconTheme*> ret;
+ ret.reserve(m_icons.size());
+ for (auto&& [id, theme] : m_icons) {
+ ret.append(&theme);
}
+ return ret;
}
QList<ITheme*> ThemeManager::getValidApplicationThemes()
@@ -128,17 +185,39 @@ QList<CatPack*> ThemeManager::getValidCatPacks()
return ret;
}
-void ThemeManager::setIconTheme(const QString& name)
+bool ThemeManager::isValidIconTheme(const QString& id)
{
- QIcon::setThemeName(name);
+ return !id.isEmpty() && m_icons.find(id) != m_icons.end();
}
-void ThemeManager::applyCurrentlySelectedTheme(bool initial)
+bool ThemeManager::isValidApplicationTheme(const QString& id)
{
- setIconTheme(APPLICATION->settings()->get("IconTheme").toString());
- themeDebugLog() << "<> Icon theme set.";
- setApplicationTheme(APPLICATION->settings()->get("ApplicationTheme").toString(), initial);
- themeDebugLog() << "<> Application theme set.";
+ return !id.isEmpty() && m_themes.find(id) != m_themes.end();
+}
+
+QDir ThemeManager::getIconThemesFolder()
+{
+ return m_iconThemeFolder;
+}
+
+QDir ThemeManager::getApplicationThemesFolder()
+{
+ return m_applicationThemeFolder;
+}
+
+QDir ThemeManager::getCatPacksFolder()
+{
+ return m_catPacksFolder;
+}
+
+void ThemeManager::setIconTheme(const QString& name)
+{
+ if (m_icons.find(name) == m_icons.end()) {
+ themeWarningLog() << "Tried to set invalid icon theme:" << name;
+ return;
+ }
+
+ QIcon::setThemeName(name);
}
void ThemeManager::setApplicationTheme(const QString& name, bool initial)
@@ -154,6 +233,15 @@ void ThemeManager::setApplicationTheme(const QString& name, bool initial)
}
}
+void ThemeManager::applyCurrentlySelectedTheme(bool initial)
+{
+ auto settings = APPLICATION->settings();
+ setIconTheme(settings->get("IconTheme").toString());
+ themeDebugLog() << "<> Icon theme set.";
+ setApplicationTheme(settings->get("ApplicationTheme").toString(), initial);
+ themeDebugLog() << "<> Application theme set.";
+}
+
QString ThemeManager::getCatPack(QString catName)
{
auto catIter = m_catPacks.find(!catName.isEmpty() ? catName : APPLICATION->settings()->get("BackgroundCat").toString());
@@ -187,9 +275,9 @@ void ThemeManager::initializeCatPacks()
for (auto [id, name] : defaultCats) {
addCatPack(std::unique_ptr<CatPack>(new BasicCatPack(id, name)));
}
- QDir catpacksDir("catpacks");
- QString catpacksFolder = catpacksDir.absoluteFilePath("");
- themeDebugLog() << "CatPacks Folder Path:" << catpacksFolder;
+ if (!m_catPacksFolder.mkpath("."))
+ themeWarningLog() << "Couldn't create catpacks folder";
+ themeDebugLog() << "CatPacks Folder Path:" << m_catPacksFolder.absolutePath();
QStringList supportedImageFormats;
for (auto format : QImageReader::supportedImageFormats()) {
@@ -206,9 +294,9 @@ void ThemeManager::initializeCatPacks()
}
};
- loadFiles(catpacksDir);
+ loadFiles(m_catPacksFolder);
- QDirIterator directoryIterator(catpacksFolder, QDir::Dirs | QDir::NoDotAndDotDot);
+ QDirIterator directoryIterator(m_catPacksFolder.path(), QDir::Dirs | QDir::NoDotAndDotDot);
while (directoryIterator.hasNext()) {
QDir dir(directoryIterator.next());
QFileInfo manifest(dir.absoluteFilePath("catpack.json"));
diff --git a/launcher/ui/themes/ThemeManager.h b/launcher/ui/themes/ThemeManager.h
index 1ce8c6f4..b5c66677 100644
--- a/launcher/ui/themes/ThemeManager.h
+++ b/launcher/ui/themes/ThemeManager.h
@@ -2,6 +2,7 @@
/*
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Tayou <git@tayou.org>
+ * Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,6 +20,7 @@
#include <QString>
+#include "IconTheme.h"
#include "ui/MainWindow.h"
#include "ui/themes/CatPack.h"
#include "ui/themes/ITheme.h"
@@ -34,11 +36,17 @@ inline auto themeWarningLog()
class ThemeManager {
public:
- ThemeManager(MainWindow* mainWindow);
+ ThemeManager();
+ QList<IconTheme*> getValidIconThemes();
QList<ITheme*> getValidApplicationThemes();
- void setIconTheme(const QString& name);
+ bool isValidIconTheme(const QString& id);
+ bool isValidApplicationTheme(const QString& id);
+ QDir getIconThemesFolder();
+ QDir getApplicationThemesFolder();
+ QDir getCatPacksFolder();
void applyCurrentlySelectedTheme(bool initial = false);
+ void setIconTheme(const QString& name);
void setApplicationTheme(const QString& name, bool initial = false);
/// @brief Returns the background based on selected and with events (Birthday, XMas, etc.)
@@ -49,12 +57,21 @@ class ThemeManager {
private:
std::map<QString, std::unique_ptr<ITheme>> m_themes;
+ std::map<QString, IconTheme> m_icons;
+ QDir m_iconThemeFolder{ "iconthemes" };
+ QDir m_applicationThemeFolder{ "themes" };
+ QDir m_catPacksFolder{ "catpacks" };
std::map<QString, std::unique_ptr<CatPack>> m_catPacks;
- MainWindow* m_mainWindow;
void initializeThemes();
void initializeCatPacks();
QString addTheme(std::unique_ptr<ITheme> theme);
ITheme* getTheme(QString themeId);
+ QString addIconTheme(IconTheme theme);
QString addCatPack(std::unique_ptr<CatPack> catPack);
+ void initializeIcons();
+ void initializeWidgets();
+
+ const QStringList builtinIcons{ "pe_colored", "pe_light", "pe_dark", "pe_blue", "breeze_light", "breeze_dark",
+ "OSX", "iOS", "flat", "flat_white", "multimc" };
};
diff --git a/launcher/ui/widgets/InfoFrame.cpp b/launcher/ui/widgets/InfoFrame.cpp
index a0fda952..69f72fea 100644
--- a/launcher/ui/widgets/InfoFrame.cpp
+++ b/launcher/ui/widgets/InfoFrame.cpp
@@ -158,12 +158,12 @@ QString InfoFrame::renderColorCodes(QString input)
//
// TODO: Wrap links inside <a> tags
- // https://minecraft.fandom.com/wiki/Formatting_codes#Color_codes
+ // https://minecraft.wiki/w/Formatting_codes#Color_codes
const QMap<QChar, QString> color_codes_map = { { '0', "#000000" }, { '1', "#0000AA" }, { '2', "#00AA00" }, { '3', "#00AAAA" },
{ '4', "#AA0000" }, { '5', "#AA00AA" }, { '6', "#FFAA00" }, { '7', "#AAAAAA" },
{ '8', "#555555" }, { '9', "#5555FF" }, { 'a', "#55FF55" }, { 'b', "#55FFFF" },
{ 'c', "#FF5555" }, { 'd', "#FF55FF" }, { 'e', "#FFFF55" }, { 'f', "#FFFFFF" } };
- // https://minecraft.fandom.com/wiki/Formatting_codes#Formatting_codes
+ // https://minecraft.wiki/w/Formatting_codes#Formatting_codes
const QMap<QChar, QString> formatting_codes_map = { { 'l', "b" }, { 'm', "s" }, { 'n', "u" }, { 'o', "i" } };
QString html("<html>");
@@ -348,7 +348,7 @@ void InfoFrame::setImage(QPixmap img)
}
}
-void InfoFrame::descriptionEllipsisHandler(QString link)
+void InfoFrame::descriptionEllipsisHandler([[maybe_unused]] QString link)
{
if (!m_current_box) {
m_current_box = CustomMessageBox::selectable(this, "", m_description);
@@ -359,7 +359,7 @@ void InfoFrame::descriptionEllipsisHandler(QString link)
}
}
-void InfoFrame::licenseEllipsisHandler(QString link)
+void InfoFrame::licenseEllipsisHandler([[maybe_unused]] QString link)
{
if (!m_current_box) {
m_current_box = CustomMessageBox::selectable(this, "", m_license);
@@ -370,7 +370,7 @@ void InfoFrame::licenseEllipsisHandler(QString link)
}
}
-void InfoFrame::boxClosed(int result)
+void InfoFrame::boxClosed([[maybe_unused]] int result)
{
m_current_box = nullptr;
}
diff --git a/launcher/ui/widgets/JavaSettingsWidget.cpp b/launcher/ui/widgets/JavaSettingsWidget.cpp
index 8c4048ff..d2d92191 100644
--- a/launcher/ui/widgets/JavaSettingsWidget.cpp
+++ b/launcher/ui/widgets/JavaSettingsWidget.cpp
@@ -46,7 +46,7 @@ void JavaSettingsWidget::setupUi()
m_verticalLayout = new QVBoxLayout(this);
m_verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
- m_versionWidget = new VersionSelectWidget(true, this);
+ m_versionWidget = new VersionSelectWidget(this);
m_verticalLayout->addWidget(m_versionWidget);
m_horizontalLayout = new QHBoxLayout();
@@ -126,6 +126,7 @@ void JavaSettingsWidget::setupUi()
void JavaSettingsWidget::initialize()
{
m_versionWidget->initialize(APPLICATION->javalist().get());
+ m_versionWidget->selectSearch();
m_versionWidget->setResizeOn(2);
auto s = APPLICATION->settings();
// Memory
@@ -185,12 +186,20 @@ QString JavaSettingsWidget::javaPath() const
int JavaSettingsWidget::maxHeapSize() const
{
- return m_maxMemSpinBox->value();
+ auto min = m_minMemSpinBox->value();
+ auto max = m_maxMemSpinBox->value();
+ if (max < min)
+ max = min;
+ return max;
}
int JavaSettingsWidget::minHeapSize() const
{
- return m_minMemSpinBox->value();
+ auto min = m_minMemSpinBox->value();
+ auto max = m_maxMemSpinBox->value();
+ if (min > max)
+ min = max;
+ return min;
}
bool JavaSettingsWidget::permGenEnabled() const
@@ -213,17 +222,9 @@ void JavaSettingsWidget::memoryValueChanged(int)
if (obj == m_minMemSpinBox && min != observedMinMemory) {
observedMinMemory = min;
actuallyChanged = true;
- if (min > max) {
- observedMaxMemory = min;
- m_maxMemSpinBox->setValue(min);
- }
} else if (obj == m_maxMemSpinBox && max != observedMaxMemory) {
observedMaxMemory = max;
actuallyChanged = true;
- if (min > max) {
- observedMinMemory = max;
- m_minMemSpinBox->setValue(max);
- }
} else if (obj == m_permGenSpinBox && permgen != observedPermGenMemory) {
observedPermGenMemory = permgen;
actuallyChanged = true;
@@ -360,8 +361,8 @@ void JavaSettingsWidget::checkJavaPath(const QString& path)
setJavaStatus(JavaStatus::Pending);
m_checker.reset(new JavaChecker());
m_checker->m_path = path;
- m_checker->m_minMem = m_minMemSpinBox->value();
- m_checker->m_maxMem = m_maxMemSpinBox->value();
+ m_checker->m_minMem = minHeapSize();
+ m_checker->m_maxMem = maxHeapSize();
if (m_permGenSpinBox->isVisible()) {
m_checker->m_permGen = m_permGenSpinBox->value();
}
@@ -414,6 +415,9 @@ void JavaSettingsWidget::updateThresholds()
} else if (observedMaxMemory > (m_availableMemory * 0.9)) {
iconName = "status-yellow";
m_labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation approaches your system memory capacity."));
+ } else if (observedMaxMemory < observedMinMemory) {
+ iconName = "status-yellow";
+ m_labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation is smaller than the minimum value"));
} else {
iconName = "status-good";
m_labelMaxMemIcon->setToolTip("");
diff --git a/launcher/ui/widgets/PageContainer.cpp b/launcher/ui/widgets/PageContainer.cpp
index f132643a..514e1d25 100644
--- a/launcher/ui/widgets/PageContainer.cpp
+++ b/launcher/ui/widgets/PageContainer.cpp
@@ -3,6 +3,7 @@
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
+ * Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -131,7 +132,12 @@ BasePage* PageContainer::getPage(QString pageId)
return m_model->findPageEntryById(pageId);
}
-const QList<BasePage*> PageContainer::getPages() const
+BasePage* PageContainer::selectedPage() const
+{
+ return m_currentPage;
+}
+
+const QList<BasePage*>& PageContainer::getPages() const
{
return m_model->pages();
}
diff --git a/launcher/ui/widgets/PageContainer.h b/launcher/ui/widgets/PageContainer.h
index 43aa0e7c..05be1c3a 100644
--- a/launcher/ui/widgets/PageContainer.h
+++ b/launcher/ui/widgets/PageContainer.h
@@ -2,6 +2,7 @@
/*
* Prism Launcher - Minecraft Launcher
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
+ * Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -75,9 +76,10 @@ class PageContainer : public QWidget, public BasePageContainer {
return false;
}
- virtual bool selectPage(QString pageId) override;
+ bool selectPage(QString pageId) override;
+ BasePage* selectedPage() const override;
BasePage* getPage(QString pageId) override;
- const QList<BasePage*> getPages() const;
+ const QList<BasePage*>& getPages() const;
void refreshContainer() override;
virtual void setParentContainer(BasePageContainer* container) { m_container = container; };
diff --git a/launcher/ui/widgets/PageContainer_p.h b/launcher/ui/widgets/PageContainer_p.h
index 9a7651c7..e61f6e15 100644
--- a/launcher/ui/widgets/PageContainer_p.h
+++ b/launcher/ui/widgets/PageContainer_p.h
@@ -89,6 +89,8 @@ class PageView : public QListView {
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
setItemDelegate(new PageViewDelegate(this));
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ // Adjust margins when using Breeze theme
+ setProperty("_kde_side_panel_view", true);
}
virtual QSize sizeHint() const
diff --git a/launcher/ui/widgets/ProjectItem.cpp b/launcher/ui/widgets/ProjectItem.cpp
index 1481c1b6..60b92b28 100644
--- a/launcher/ui/widgets/ProjectItem.cpp
+++ b/launcher/ui/widgets/ProjectItem.cpp
@@ -34,8 +34,8 @@ void ProjectItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o
icon_width = icon_size.width();
icon_height = icon_size.height();
- icon_x_margin = (rect.height() - icon_width) / 2;
icon_y_margin = (rect.height() - icon_height) / 2;
+ icon_x_margin = icon_y_margin; // use same margins for consistency
}
// Centralize icon with a margin to separate from the other elements
diff --git a/launcher/ui/widgets/SubTaskProgressBar.cpp b/launcher/ui/widgets/SubTaskProgressBar.cpp
index 39102197..b0e62e0f 100644
--- a/launcher/ui/widgets/SubTaskProgressBar.cpp
+++ b/launcher/ui/widgets/SubTaskProgressBar.cpp
@@ -26,7 +26,7 @@ unique_qobject_ptr<SubTaskProgressBar> SubTaskProgressBar::create(QWidget* paren
return unique_qobject_ptr<SubTaskProgressBar>(progress_bar);
}
-SubTaskProgressBar::SubTaskProgressBar(QWidget* parent) : ui(new Ui::SubTaskProgressBar)
+SubTaskProgressBar::SubTaskProgressBar(QWidget* parent) : QWidget(parent), ui(new Ui::SubTaskProgressBar)
{
ui->setupUi(this);
}
diff --git a/launcher/ui/widgets/ThemeCustomizationWidget.cpp b/launcher/ui/widgets/ThemeCustomizationWidget.cpp
index d26906bd..0de97441 100644
--- a/launcher/ui/widgets/ThemeCustomizationWidget.cpp
+++ b/launcher/ui/widgets/ThemeCustomizationWidget.cpp
@@ -19,6 +19,7 @@
#include "ui_ThemeCustomizationWidget.h"
#include "Application.h"
+#include "DesktopServices.h"
#include "ui/themes/ITheme.h"
#include "ui/themes/ThemeManager.h"
@@ -31,6 +32,13 @@ ThemeCustomizationWidget::ThemeCustomizationWidget(QWidget* parent) : QWidget(pa
connect(ui->widgetStyleComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&ThemeCustomizationWidget::applyWidgetTheme);
connect(ui->backgroundCatComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ThemeCustomizationWidget::applyCatTheme);
+
+ connect(ui->iconsFolder, &QPushButton::clicked, this,
+ [] { DesktopServices::openDirectory(APPLICATION->themeManager()->getIconThemesFolder().path()); });
+ connect(ui->widgetStyleFolder, &QPushButton::clicked, this,
+ [] { DesktopServices::openDirectory(APPLICATION->themeManager()->getApplicationThemesFolder().path()); });
+ connect(ui->catPackFolder, &QPushButton::clicked, this,
+ [] { DesktopServices::openDirectory(APPLICATION->themeManager()->getCatPacksFolder().path()); });
}
ThemeCustomizationWidget::~ThemeCustomizationWidget()
@@ -67,7 +75,7 @@ void ThemeCustomizationWidget::showFeatures(ThemeFields features)
ui->iconsComboBox->setEnabled(features & ThemeFields::ICONS);
ui->iconsLabel->setEnabled(features & ThemeFields::ICONS);
ui->widgetStyleComboBox->setEnabled(features & ThemeFields::WIDGETS);
- ui->widgetThemeLabel->setEnabled(features & ThemeFields::WIDGETS);
+ ui->widgetStyleLabel->setEnabled(features & ThemeFields::WIDGETS);
ui->backgroundCatComboBox->setEnabled(features & ThemeFields::CAT);
ui->backgroundCatLabel->setEnabled(features & ThemeFields::CAT);
}
@@ -76,11 +84,10 @@ void ThemeCustomizationWidget::applyIconTheme(int index)
{
auto settings = APPLICATION->settings();
auto originalIconTheme = settings->get("IconTheme").toString();
- auto& newIconTheme = m_iconThemeOptions[index].first;
- settings->set("IconTheme", newIconTheme);
-
+ auto newIconTheme = ui->iconsComboBox->currentData().toString();
if (originalIconTheme != newIconTheme) {
- APPLICATION->applyCurrentlySelectedTheme();
+ settings->set("IconTheme", newIconTheme);
+ APPLICATION->themeManager()->applyCurrentlySelectedTheme();
}
emit currentIconThemeChanged(index);
@@ -93,7 +100,7 @@ void ThemeCustomizationWidget::applyWidgetTheme(int index)
auto newAppTheme = ui->widgetStyleComboBox->currentData().toString();
if (originalAppTheme != newAppTheme) {
settings->set("ApplicationTheme", newAppTheme);
- APPLICATION->applyCurrentlySelectedTheme();
+ APPLICATION->themeManager()->applyCurrentlySelectedTheme();
}
emit currentWidgetThemeChanged(index);
@@ -121,18 +128,23 @@ void ThemeCustomizationWidget::loadSettings()
{
auto settings = APPLICATION->settings();
- auto iconTheme = settings->get("IconTheme").toString();
- for (auto& iconThemeFromList : m_iconThemeOptions) {
- QIcon iconForComboBox = QIcon(QString(":/icons/%1/scalable/settings").arg(iconThemeFromList.first));
- ui->iconsComboBox->addItem(iconForComboBox, iconThemeFromList.second);
- if (iconTheme == iconThemeFromList.first) {
- ui->iconsComboBox->setCurrentIndex(ui->iconsComboBox->count() - 1);
+ {
+ auto currentIconTheme = settings->get("IconTheme").toString();
+ auto iconThemes = APPLICATION->themeManager()->getValidIconThemes();
+ int idx = 0;
+ for (auto iconTheme : iconThemes) {
+ QIcon iconForComboBox = QIcon(iconTheme->path() + "/scalable/settings");
+ ui->iconsComboBox->addItem(iconForComboBox, iconTheme->name(), iconTheme->id());
+ if (currentIconTheme == iconTheme->id()) {
+ ui->iconsComboBox->setCurrentIndex(idx);
+ }
+ idx++;
}
}
{
auto currentTheme = settings->get("ApplicationTheme").toString();
- auto themes = APPLICATION->getValidApplicationThemes();
+ auto themes = APPLICATION->themeManager()->getValidApplicationThemes();
int idx = 0;
for (auto& theme : themes) {
ui->widgetStyleComboBox->addItem(theme->name(), theme->id());
@@ -144,7 +156,7 @@ void ThemeCustomizationWidget::loadSettings()
}
auto cat = settings->get("BackgroundCat").toString();
- for (auto& catFromList : APPLICATION->getValidCatPacks()) {
+ for (auto& catFromList : APPLICATION->themeManager()->getValidCatPacks()) {
QIcon catIcon = QIcon(QString("%1").arg(catFromList->path()));
ui->backgroundCatComboBox->addItem(catIcon, catFromList->name(), catFromList->id());
if (cat == catFromList->id()) {
diff --git a/launcher/ui/widgets/ThemeCustomizationWidget.h b/launcher/ui/widgets/ThemeCustomizationWidget.h
index af47c788..cef5fb6c 100644
--- a/launcher/ui/widgets/ThemeCustomizationWidget.h
+++ b/launcher/ui/widgets/ThemeCustomizationWidget.h
@@ -31,7 +31,7 @@ class ThemeCustomizationWidget : public QWidget {
public:
explicit ThemeCustomizationWidget(QWidget* parent = nullptr);
- ~ThemeCustomizationWidget();
+ ~ThemeCustomizationWidget() override;
void showFeatures(ThemeFields features);
@@ -52,18 +52,4 @@ class ThemeCustomizationWidget : public QWidget {
private:
Ui::ThemeCustomizationWidget* ui;
-
- // TODO finish implementing
- QList<std::pair<QString, QString>> m_iconThemeOptions{ { "pe_colored", QObject::tr("Simple (Colored Icons)") },
- { "pe_light", QObject::tr("Simple (Light Icons)") },
- { "pe_dark", QObject::tr("Simple (Dark Icons)") },
- { "pe_blue", QObject::tr("Simple (Blue Icons)") },
- { "breeze_light", QObject::tr("Breeze Light") },
- { "breeze_dark", QObject::tr("Breeze Dark") },
- { "OSX", QObject::tr("OSX") },
- { "iOS", QObject::tr("iOS") },
- { "flat", QObject::tr("Flat") },
- { "flat_white", QObject::tr("Flat (White)") },
- { "multimc", QObject::tr("Legacy") },
- { "custom", QObject::tr("Custom") } };
};
diff --git a/launcher/ui/widgets/ThemeCustomizationWidget.ui b/launcher/ui/widgets/ThemeCustomizationWidget.ui
index f216a610..4503181c 100644
--- a/launcher/ui/widgets/ThemeCustomizationWidget.ui
+++ b/launcher/ui/widgets/ThemeCustomizationWidget.ui
@@ -40,22 +40,43 @@
</widget>
</item>
<item row="0" column="1">
- <widget class="QComboBox" name="iconsComboBox">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="focusPolicy">
- <enum>Qt::StrongFocus</enum>
- </property>
- </widget>
+ <layout class="QHBoxLayout" name="iconsLayout">
+ <item>
+ <widget class="QComboBox" name="iconsComboBox">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="focusPolicy">
+ <enum>Qt::StrongFocus</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="iconsFolder">
+ <property name="toolTip">
+ <string>View icon themes folder.</string>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ <property name="icon">
+ <iconset theme="viewfolder">
+ <normaloff>.</normaloff>.</iconset>
+ </property>
+ <property name="flat">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
</item>
<item row="1" column="0">
- <widget class="QLabel" name="widgetThemeLabel">
+ <widget class="QLabel" name="widgetStyleLabel">
<property name="text">
- <string>&amp;Colors</string>
+ <string>&amp;Widgets</string>
</property>
<property name="buddy">
<cstring>widgetStyleComboBox</cstring>
@@ -63,17 +84,38 @@
</widget>
</item>
<item row="1" column="1">
- <widget class="QComboBox" name="widgetStyleComboBox">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="focusPolicy">
- <enum>Qt::StrongFocus</enum>
- </property>
- </widget>
+ <layout class="QHBoxLayout" name="widgetStyleLayout">
+ <item>
+ <widget class="QComboBox" name="widgetStyleComboBox">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="focusPolicy">
+ <enum>Qt::StrongFocus</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="widgetStyleFolder">
+ <property name="toolTip">
+ <string>View widget themes folder.</string>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ <property name="icon">
+ <iconset theme="viewfolder">
+ <normaloff>.</normaloff>.</iconset>
+ </property>
+ <property name="flat">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
</item>
<item row="2" column="0">
<widget class="QLabel" name="backgroundCatLabel">
@@ -89,7 +131,7 @@
</widget>
</item>
<item row="2" column="1">
- <layout class="QHBoxLayout" name="horizontalLayout">
+ <layout class="QHBoxLayout" name="catLayout">
<item>
<widget class="QComboBox" name="backgroundCatComboBox">
<property name="sizePolicy">
@@ -107,15 +149,15 @@
</widget>
</item>
<item>
- <widget class="QPushButton" name="catInfoLabel">
+ <widget class="QPushButton" name="catPackFolder">
<property name="toolTip">
- <string>The cat appears in the background and is not shown by default. It is only made visible when pressing the Cat button in the Toolbar.</string>
+ <string>View cat packs folder.</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
- <iconset theme="about">
+ <iconset theme="viewfolder">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="flat">
diff --git a/launcher/ui/widgets/VariableSizedImageObject.cpp b/launcher/ui/widgets/VariableSizedImageObject.cpp
index 4daf513a..f655fc38 100644
--- a/launcher/ui/widgets/VariableSizedImageObject.cpp
+++ b/launcher/ui/widgets/VariableSizedImageObject.cpp
@@ -25,6 +25,7 @@
#include "Application.h"
+#include "net/ApiDownload.h"
#include "net/NetJob.h"
enum FormatProperties { ImageData = QTextFormat::UserProperty + 1 };
@@ -97,7 +98,7 @@ void VariableSizedImageObject::loadImage(QTextDocument* doc, const QUrl& source,
QString("images/%1").arg(QString(QCryptographicHash::hash(source.toEncoded(), QCryptographicHash::Algorithm::Sha1).toHex())));
auto job = new NetJob(QString("Load Image: %1").arg(source.fileName()), APPLICATION->network());
- job->addNetAction(Net::Download::makeCached(source, entry));
+ job->addNetAction(Net::ApiDownload::makeCached(source, entry));
auto full_entry_path = entry->getFullPath();
auto source_url = source;
diff --git a/launcher/ui/widgets/VersionSelectWidget.cpp b/launcher/ui/widgets/VersionSelectWidget.cpp
index 9647dc79..a24630b3 100644
--- a/launcher/ui/widgets/VersionSelectWidget.cpp
+++ b/launcher/ui/widgets/VersionSelectWidget.cpp
@@ -11,9 +11,7 @@
#include "ui/dialogs/CustomMessageBox.h"
-VersionSelectWidget::VersionSelectWidget(QWidget* parent) : VersionSelectWidget(false, parent) {}
-
-VersionSelectWidget::VersionSelectWidget(bool focusSearch, QWidget* parent) : QWidget(parent), focusSearch(focusSearch)
+VersionSelectWidget::VersionSelectWidget(QWidget* parent) : QWidget(parent)
{
setObjectName(QStringLiteral("VersionSelectWidget"));
verticalLayout = new QVBoxLayout(this);
@@ -114,9 +112,6 @@ void VersionSelectWidget::initialize(BaseVersionList* vlist)
listView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
listView->header()->setSectionResizeMode(resizeOnColumn, QHeaderView::Stretch);
- if (focusSearch)
- search->setFocus();
-
if (!m_vlist->isLoaded()) {
loadList();
} else {
@@ -199,6 +194,16 @@ void VersionSelectWidget::selectCurrent()
}
}
+void VersionSelectWidget::selectSearch()
+{
+ search->setFocus();
+}
+
+VersionListView* VersionSelectWidget::view()
+{
+ return listView;
+}
+
void VersionSelectWidget::selectRecommended()
{
auto idx = m_proxyModel->getRecommended();
@@ -221,14 +226,19 @@ BaseVersion::Ptr VersionSelectWidget::selectedVersion() const
return variant.value<BaseVersion::Ptr>();
}
+void VersionSelectWidget::setFuzzyFilter(BaseVersionList::ModelRoles role, QString filter)
+{
+ m_proxyModel->setFilter(role, new ContainsFilter(filter));
+}
+
void VersionSelectWidget::setExactFilter(BaseVersionList::ModelRoles role, QString filter)
{
m_proxyModel->setFilter(role, new ExactFilter(filter));
}
-void VersionSelectWidget::setFuzzyFilter(BaseVersionList::ModelRoles role, QString filter)
+void VersionSelectWidget::setExactIfPresentFilter(BaseVersionList::ModelRoles role, QString filter)
{
- m_proxyModel->setFilter(role, new ContainsFilter(filter));
+ m_proxyModel->setFilter(role, new ExactIfPresentFilter(filter));
}
void VersionSelectWidget::setFilter(BaseVersionList::ModelRoles role, Filter* filter)
diff --git a/launcher/ui/widgets/VersionSelectWidget.h b/launcher/ui/widgets/VersionSelectWidget.h
index b7f40101..99729fbd 100644
--- a/launcher/ui/widgets/VersionSelectWidget.h
+++ b/launcher/ui/widgets/VersionSelectWidget.h
@@ -51,7 +51,6 @@ class VersionSelectWidget : public QWidget {
Q_OBJECT
public:
explicit VersionSelectWidget(QWidget* parent);
- explicit VersionSelectWidget(bool focusSearch = false, QWidget* parent = 0);
~VersionSelectWidget();
//! loads the list if needed.
@@ -64,15 +63,19 @@ class VersionSelectWidget : public QWidget {
BaseVersion::Ptr selectedVersion() const;
void selectRecommended();
void selectCurrent();
+ void selectSearch();
+ VersionListView* view();
void setCurrentVersion(const QString& version);
void setFuzzyFilter(BaseVersionList::ModelRoles role, QString filter);
void setExactFilter(BaseVersionList::ModelRoles role, QString filter);
+ void setExactIfPresentFilter(BaseVersionList::ModelRoles role, QString filter);
void setFilter(BaseVersionList::ModelRoles role, Filter* filter);
void setEmptyString(QString emptyString);
void setEmptyErrorString(QString emptyErrorString);
void setEmptyMode(VersionListView::EmptyMode mode);
void setResizeOn(int column);
+
bool eventFilter(QObject* watched, QEvent* event) override;
signals:
@@ -97,7 +100,6 @@ class VersionSelectWidget : public QWidget {
int resizeOnColumn = 0;
Task* loadTask;
bool preselectedAlready = false;
- bool focusSearch;
QVBoxLayout* verticalLayout = nullptr;
VersionListView* listView = nullptr;
diff --git a/launcher/ui/widgets/WideBar.cpp b/launcher/ui/widgets/WideBar.cpp
index b793d84f..46caaaef 100644
--- a/launcher/ui/widgets/WideBar.cpp
+++ b/launcher/ui/widgets/WideBar.cpp
@@ -204,8 +204,10 @@ static void copyAction(QAction* from, QAction* to)
void WideBar::showVisibilityMenu(QPoint const& position)
{
- if (!m_bar_menu)
+ if (!m_bar_menu) {
m_bar_menu = std::make_unique<QMenu>(this);
+ m_bar_menu->setTearOffEnabled(true);
+ }
if (m_menu_state == MenuState::Dirty) {
for (auto* old_action : m_bar_menu->actions())