diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 3b553f4b1..661c6c5be 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -58,6 +58,7 @@ #include "ui/pages/global/APIPage.h" #include "ui/pages/global/AccountListPage.h" #include "ui/pages/global/CustomCommandsPage.h" +#include "ui/pages/global/EnvironmentVariablesPage.h" #include "ui/pages/global/ExternalToolsPage.h" #include "ui/pages/global/JavaPage.h" #include "ui/pages/global/LanguagePage.h" @@ -719,6 +720,8 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv) m_settings->registerSetting("CloseAfterLaunch", false); m_settings->registerSetting("QuitAfterGameStop", false); + m_settings->registerSetting("Env", QVariant(QMap())); + // Custom Microsoft Authentication Client ID m_settings->registerSetting("MSAClientIDOverride", ""); @@ -744,6 +747,7 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv) m_globalSettingsProvider->addPage(); m_globalSettingsProvider->addPage(); m_globalSettingsProvider->addPage(); + m_globalSettingsProvider->addPage(); m_globalSettingsProvider->addPage(); m_globalSettingsProvider->addPage(); m_globalSettingsProvider->addPage(); diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 9fd77f176..99acf8fc5 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -889,6 +889,8 @@ SET(LAUNCHER_SOURCES ui/pages/global/AccountListPage.h ui/pages/global/CustomCommandsPage.cpp ui/pages/global/CustomCommandsPage.h + ui/pages/global/EnvironmentVariablesPage.cpp + ui/pages/global/EnvironmentVariablesPage.h ui/pages/global/ExternalToolsPage.cpp ui/pages/global/ExternalToolsPage.h ui/pages/global/JavaPage.cpp @@ -1040,6 +1042,8 @@ SET(LAUNCHER_SOURCES ui/widgets/Common.h ui/widgets/CustomCommands.cpp ui/widgets/CustomCommands.h + ui/widgets/EnvironmentVariables.cpp + ui/widgets/EnvironmentVariables.h ui/widgets/DropLabel.cpp ui/widgets/DropLabel.h ui/widgets/FocusLineEdit.cpp @@ -1150,6 +1154,7 @@ qt_wrap_ui(LAUNCHER_UI ui/pages/modplatform/technic/TechnicPage.ui ui/widgets/InstanceCardWidget.ui ui/widgets/CustomCommands.ui + ui/widgets/EnvironmentVariables.ui ui/widgets/InfoFrame.ui ui/widgets/ModFilterWidget.ui ui/widgets/SubTaskProgressBar.ui diff --git a/launcher/minecraft/MinecraftInstance.cpp b/launcher/minecraft/MinecraftInstance.cpp index a4571e626..9d177f318 100644 --- a/launcher/minecraft/MinecraftInstance.cpp +++ b/launcher/minecraft/MinecraftInstance.cpp @@ -188,6 +188,9 @@ void MinecraftInstance::loadSpecificSettings() auto legacySettings = m_settings->registerSetting("OverrideLegacySettings", false); m_settings->registerOverride(global_settings->getSetting("OnlineFixes"), legacySettings); + auto envSetting = m_settings->registerSetting("OverrideEnv", false); + m_settings->registerOverride(global_settings->getSetting("Env"), envSetting); + m_settings->set("InstanceType", "OneSix"); } @@ -598,6 +601,23 @@ QProcessEnvironment MinecraftInstance::createLaunchEnvironment() } #endif + // custom env + + auto insertEnv = [&env](QMap envMap) { + if (envMap.isEmpty()) + return; + + for (auto iter = envMap.begin(); iter != envMap.end(); iter++) + env.insert(iter.key(), iter.value().toString()); + }; + + bool overrideEnv = settings()->get("OverrideEnv").toBool(); + + if (!overrideEnv) + insertEnv(APPLICATION->settings()->get("Env").toMap()); + else + insertEnv(settings()->get("Env").toMap()); + return env; } diff --git a/launcher/resources/breeze_dark/breeze_dark.qrc b/launcher/resources/breeze_dark/breeze_dark.qrc index 320ca8171..61d82ec30 100644 --- a/launcher/resources/breeze_dark/breeze_dark.qrc +++ b/launcher/resources/breeze_dark/breeze_dark.qrc @@ -9,6 +9,7 @@ scalable/copy.svg scalable/coremods.svg scalable/custom-commands.svg + scalable/environment-variables.svg scalable/discord.svg scalable/externaltools.svg scalable/help.svg diff --git a/launcher/resources/breeze_dark/scalable/environment-variables.svg b/launcher/resources/breeze_dark/scalable/environment-variables.svg new file mode 100644 index 000000000..308c4a239 --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/environment-variables.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/breeze_light/breeze_light.qrc b/launcher/resources/breeze_light/breeze_light.qrc index e88cd9a00..2211c7188 100644 --- a/launcher/resources/breeze_light/breeze_light.qrc +++ b/launcher/resources/breeze_light/breeze_light.qrc @@ -9,6 +9,7 @@ scalable/copy.svg scalable/coremods.svg scalable/custom-commands.svg + scalable/environment-variables.svg scalable/discord.svg scalable/externaltools.svg scalable/help.svg diff --git a/launcher/resources/breeze_light/scalable/environment-variables.svg b/launcher/resources/breeze_light/scalable/environment-variables.svg new file mode 100644 index 000000000..f5d4acc3b --- /dev/null +++ b/launcher/resources/breeze_light/scalable/environment-variables.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/launcher/resources/flat/flat.qrc b/launcher/resources/flat/flat.qrc index 2fd5daefe..8876027da 100644 --- a/launcher/resources/flat/flat.qrc +++ b/launcher/resources/flat/flat.qrc @@ -11,6 +11,7 @@ scalable/copy.svg scalable/coremods.svg scalable/custom-commands.svg + scalable/environment-variables.svg scalable/discord.svg scalable/externaltools.svg scalable/help.svg diff --git a/launcher/resources/flat/scalable/custom-commands.svg b/launcher/resources/flat/scalable/custom-commands.svg index a35634b16..f2e587843 100644 --- a/launcher/resources/flat/scalable/custom-commands.svg +++ b/launcher/resources/flat/scalable/custom-commands.svg @@ -1,86 +1 @@ - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - + diff --git a/launcher/resources/flat/scalable/environment-variables.svg b/launcher/resources/flat/scalable/environment-variables.svg new file mode 100644 index 000000000..a35634b16 --- /dev/null +++ b/launcher/resources/flat/scalable/environment-variables.svg @@ -0,0 +1,86 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + diff --git a/launcher/resources/flat_white/flat_white.qrc b/launcher/resources/flat_white/flat_white.qrc index a1c940da0..83b178cbf 100644 --- a/launcher/resources/flat_white/flat_white.qrc +++ b/launcher/resources/flat_white/flat_white.qrc @@ -11,6 +11,7 @@ scalable/copy.svg scalable/coremods.svg scalable/custom-commands.svg + scalable/environment-variables.svg scalable/discord.svg scalable/externaltools.svg scalable/help.svg diff --git a/launcher/resources/flat_white/scalable/custom-commands.svg b/launcher/resources/flat_white/scalable/custom-commands.svg index fe1cf9987..0ba459cff 100644 --- a/launcher/resources/flat_white/scalable/custom-commands.svg +++ b/launcher/resources/flat_white/scalable/custom-commands.svg @@ -1,86 +1 @@ - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - + diff --git a/launcher/resources/flat_white/scalable/environment-variables.svg b/launcher/resources/flat_white/scalable/environment-variables.svg new file mode 100644 index 000000000..fe1cf9987 --- /dev/null +++ b/launcher/resources/flat_white/scalable/environment-variables.svg @@ -0,0 +1,86 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + diff --git a/launcher/resources/multimc/multimc.qrc b/launcher/resources/multimc/multimc.qrc index 80981559b..eeba32186 100644 --- a/launcher/resources/multimc/multimc.qrc +++ b/launcher/resources/multimc/multimc.qrc @@ -73,8 +73,8 @@ 64x64/screenshots.png scalable/screenshots.svg - scalable/custom-commands.svg + scalable/environment-variables.svg 16x16/cat.png diff --git a/launcher/resources/multimc/scalable/custom-commands.svg b/launcher/resources/multimc/scalable/custom-commands.svg index b7f1a149b..0d502bb1d 100644 --- a/launcher/resources/multimc/scalable/custom-commands.svg +++ b/launcher/resources/multimc/scalable/custom-commands.svg @@ -1,338 +1,4339 @@ + + width="128" + height="128" + id="svg2756" + sodipodi:version="0.32" + inkscape:version="0.45.1" + version="1.0" + sodipodi:docname="konsole.svg" + inkscape:output_extension="org.inkscape.output.svg.inkscape" + sodipodi:docbase="/home/david/sandbox"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + inkscape:zoom="4" + inkscape:cx="64" + inkscape:cy="73.608336" + inkscape:document-units="px" + inkscape:current-layer="layer1" + height="128px" + width="128px" + showgrid="true" + gridspacingy="4px" + gridspacingx="4px" + gridempspacing="0" + inkscape:window-width="971" + inkscape:window-height="648" + inkscape:window-x="46" + inkscape:window-y="45" /> + id="metadata2761"> image/svg+xml - + inkscape:label="Livello 1" + inkscape:groupmode="layer" + id="layer1"> + + + + + + + + + + + - - + x="12" + y="16" + width="104" + height="80" + id="rect30" /> - - - - - - - - - - - - - - - - - - - - - + id="g32" + transform="matrix(1.0851064,0,0,1.1142857,3.2340422,6.9714286)"> + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - + id="g2644"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/launcher/resources/multimc/scalable/environment-variables.svg b/launcher/resources/multimc/scalable/environment-variables.svg new file mode 100644 index 000000000..5e136b202 --- /dev/null +++ b/launcher/resources/multimc/scalable/environment-variables.svg @@ -0,0 +1,346 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + diff --git a/launcher/resources/pe_blue/pe_blue.qrc b/launcher/resources/pe_blue/pe_blue.qrc index da45ef9a1..717d3972e 100644 --- a/launcher/resources/pe_blue/pe_blue.qrc +++ b/launcher/resources/pe_blue/pe_blue.qrc @@ -10,6 +10,7 @@ scalable/copy.svg scalable/coremods.svg scalable/custom-commands.svg + scalable/environment-variables.svg scalable/externaltools.svg scalable/help.svg scalable/instance-settings.svg diff --git a/launcher/resources/pe_blue/scalable/environment-variables.svg b/launcher/resources/pe_blue/scalable/environment-variables.svg new file mode 100644 index 000000000..61c63a4c5 --- /dev/null +++ b/launcher/resources/pe_blue/scalable/environment-variables.svg @@ -0,0 +1,345 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/launcher/resources/pe_colored/pe_colored.qrc b/launcher/resources/pe_colored/pe_colored.qrc index ba5bd44f9..023c81e74 100644 --- a/launcher/resources/pe_colored/pe_colored.qrc +++ b/launcher/resources/pe_colored/pe_colored.qrc @@ -10,6 +10,7 @@ scalable/copy.svg scalable/coremods.svg scalable/custom-commands.svg + scalable/environment-variables.svg scalable/externaltools.svg scalable/help.svg scalable/instance-settings.svg diff --git a/launcher/resources/pe_colored/scalable/environment-variables.svg b/launcher/resources/pe_colored/scalable/environment-variables.svg new file mode 100644 index 000000000..c1aab6bca --- /dev/null +++ b/launcher/resources/pe_colored/scalable/environment-variables.svg @@ -0,0 +1,347 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/launcher/resources/pe_dark/pe_dark.qrc b/launcher/resources/pe_dark/pe_dark.qrc index 2bfec42cb..c97fb469c 100644 --- a/launcher/resources/pe_dark/pe_dark.qrc +++ b/launcher/resources/pe_dark/pe_dark.qrc @@ -10,6 +10,7 @@ scalable/copy.svg scalable/coremods.svg scalable/custom-commands.svg + scalable/environment-variables.svg scalable/externaltools.svg scalable/help.svg scalable/instance-settings.svg diff --git a/launcher/resources/pe_dark/scalable/environment-variables.svg b/launcher/resources/pe_dark/scalable/environment-variables.svg new file mode 100644 index 000000000..46a3445f4 --- /dev/null +++ b/launcher/resources/pe_dark/scalable/environment-variables.svg @@ -0,0 +1,345 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/launcher/resources/pe_light/pe_light.qrc b/launcher/resources/pe_light/pe_light.qrc index 25d5da73b..b590dd2c6 100644 --- a/launcher/resources/pe_light/pe_light.qrc +++ b/launcher/resources/pe_light/pe_light.qrc @@ -10,6 +10,7 @@ scalable/copy.svg scalable/coremods.svg scalable/custom-commands.svg + scalable/environment-variables.svg scalable/externaltools.svg scalable/help.svg scalable/instance-settings.svg diff --git a/launcher/resources/pe_light/scalable/environment-variables.svg b/launcher/resources/pe_light/scalable/environment-variables.svg new file mode 100644 index 000000000..b8d562ffe --- /dev/null +++ b/launcher/resources/pe_light/scalable/environment-variables.svg @@ -0,0 +1,345 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/launcher/ui/pages/global/EnvironmentVariablesPage.cpp b/launcher/ui/pages/global/EnvironmentVariablesPage.cpp new file mode 100644 index 000000000..2d44ed624 --- /dev/null +++ b/launcher/ui/pages/global/EnvironmentVariablesPage.cpp @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2023 TheKodeToad + * + * 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 . + */ + +#include +#include +#include + +#include "EnvironmentVariablesPage.h" + +EnvironmentVariablesPage::EnvironmentVariablesPage(QWidget* parent) : QWidget(parent) +{ + auto verticalLayout = new QVBoxLayout(this); + verticalLayout->setObjectName(QStringLiteral("verticalLayout")); + verticalLayout->setContentsMargins(0, 0, 0, 0); + + auto tabWidget = new QTabWidget(this); + tabWidget->setObjectName(QStringLiteral("tabWidget")); + variables = new EnvironmentVariables(this); + variables->setContentsMargins(6, 6, 6, 6); + tabWidget->addTab(variables, "Foo"); + tabWidget->tabBar()->hide(); + verticalLayout->addWidget(tabWidget); + + variables->initialize(false, false, APPLICATION->settings()->get("Env").toMap()); +} + +QString EnvironmentVariablesPage::displayName() const +{ + return tr("Environment Variables"); +} + +QIcon EnvironmentVariablesPage::icon() const +{ + return APPLICATION->getThemedIcon("environment-variables"); +} + +QString EnvironmentVariablesPage::id() const +{ + return "environment-variables"; +} + +QString EnvironmentVariablesPage::helpPage() const +{ + return "Environment-variables"; +} + +bool EnvironmentVariablesPage::apply() +{ + APPLICATION->settings()->set("Env", variables->value()); + return true; +} + +void EnvironmentVariablesPage::retranslate() +{ + variables->retranslate(); +} diff --git a/launcher/ui/pages/global/EnvironmentVariablesPage.h b/launcher/ui/pages/global/EnvironmentVariablesPage.h new file mode 100644 index 000000000..6e80775ec --- /dev/null +++ b/launcher/ui/pages/global/EnvironmentVariablesPage.h @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2023 TheKodeToad + * + * 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 . + */ + +#pragma once + +#include + +#include "ui/pages/BasePage.h" +#include "ui/widgets/EnvironmentVariables.h" + +class EnvironmentVariablesPage : public QWidget, public BasePage { + Q_OBJECT + + public: + explicit EnvironmentVariablesPage(QWidget* parent = nullptr); + + QString displayName() const override; + QIcon icon() const override; + QString id() const override; + QString helpPage() const override; + + bool apply() override; + void retranslate() override; + + private: + EnvironmentVariables* variables; +}; diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.cpp b/launcher/ui/pages/instance/InstanceSettingsPage.cpp index c0ced2415..74785f97e 100644 --- a/launcher/ui/pages/instance/InstanceSettingsPage.cpp +++ b/launcher/ui/pages/instance/InstanceSettingsPage.cpp @@ -90,6 +90,9 @@ void InstanceSettingsPage::globalSettingsButtonClicked(bool) case 2: APPLICATION->ShowGlobalSettings(this, "custom-commands"); return; + case 3: + APPLICATION->ShowGlobalSettings(this, "environment-variables"); + return; default: APPLICATION->ShowGlobalSettings(this, "minecraft-settings"); return; @@ -199,6 +202,14 @@ void InstanceSettingsPage::applySettings() m_settings->reset("PostExitCommand"); } + // Environment Variables + auto env = ui->environmentVariables->override(); + m_settings->set("OverrideEnv", env); + if (env) + m_settings->set("Env", ui->environmentVariables->value()); + else + m_settings->reset("Env"); + // Workarounds bool workarounds = ui->nativeWorkaroundsGroupBox->isChecked(); m_settings->set("OverrideNativeWorkarounds", workarounds); @@ -318,6 +329,9 @@ void InstanceSettingsPage::loadSettings() ui->customCommands->initialize(true, m_settings->get("OverrideCommands").toBool(), m_settings->get("PreLaunchCommand").toString(), m_settings->get("WrapperCommand").toString(), m_settings->get("PostExitCommand").toString()); + // Environment variables + ui->environmentVariables->initialize(true, m_settings->get("OverrideEnv").toBool(), m_settings->get("Env").toMap()); + // Workarounds ui->nativeWorkaroundsGroupBox->setChecked(m_settings->get("OverrideNativeWorkarounds").toBool()); ui->useNativeGLFWCheck->setChecked(m_settings->get("UseNativeGLFW").toBool()); @@ -484,6 +498,7 @@ void InstanceSettingsPage::retranslate() { ui->retranslateUi(this); ui->customCommands->retranslate(); // TODO: why is this seperate from the others? + ui->environmentVariables->retranslate(); } void InstanceSettingsPage::updateThresholds() diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.ui b/launcher/ui/pages/instance/InstanceSettingsPage.ui index 8defaccb3..ad348cc0b 100644 --- a/launcher/ui/pages/instance/InstanceSettingsPage.ui +++ b/launcher/ui/pages/instance/InstanceSettingsPage.ui @@ -35,13 +35,10 @@ - - QTabWidget::Rounded - 0 - + Java @@ -254,7 +251,7 @@ - + Game windows @@ -414,7 +411,7 @@ - + Custom commands @@ -424,6 +421,16 @@ + + + Environment variables + + + + + + + Workarounds @@ -736,6 +743,12 @@
ui/widgets/CustomCommands.h
1 + + EnvironmentVariables + QWidget +
ui/widgets/EnvironmentVariables.h
+ 1 +
openGlobalJavaSettingsButton diff --git a/launcher/ui/widgets/EnvironmentVariables.cpp b/launcher/ui/widgets/EnvironmentVariables.cpp new file mode 100644 index 000000000..633fc6122 --- /dev/null +++ b/launcher/ui/widgets/EnvironmentVariables.cpp @@ -0,0 +1,110 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2023 TheKodeToad + * + * 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 . + */ + +#include + +#include "Application.h" +#include "EnvironmentVariables.h" +#include "ui/dialogs/CustomMessageBox.h" +#include "ui_EnvironmentVariables.h" + +EnvironmentVariables::EnvironmentVariables(QWidget* parent) : QWidget(parent), ui(new Ui::EnvironmentVariables) +{ + ui->setupUi(this); + ui->list->installEventFilter(this); + + ui->list->sortItems(0, Qt::AscendingOrder); + ui->list->setSortingEnabled(true); + ui->list->header()->resizeSections(QHeaderView::Interactive); + ui->list->header()->resizeSection(0, 200); + + connect(ui->add, &QPushButton::clicked, this, [this] { + auto item = new QTreeWidgetItem(ui->list); + item->setText(0, "ENV_VAR"); + item->setText(1, "value"); + item->setFlags(item->flags() | Qt::ItemIsEditable); + ui->list->addTopLevelItem(item); + ui->list->selectionModel()->select(ui->list->model()->index(ui->list->indexOfTopLevelItem(item), 0), + QItemSelectionModel::ClearAndSelect | QItemSelectionModel::SelectionFlag::Rows); + ui->list->editItem(item); + }); + + connect(ui->remove, &QPushButton::clicked, this, [this] { + for (QTreeWidgetItem* item : ui->list->selectedItems()) + ui->list->takeTopLevelItem(ui->list->indexOfTopLevelItem(item)); + }); + + connect(ui->clear, &QPushButton::clicked, this, [this] { ui->list->clear(); }); +} + +EnvironmentVariables::~EnvironmentVariables() +{ + delete ui; +} + +void EnvironmentVariables::initialize(bool instance, bool override, const QMap& value) +{ + // update widgets to settings + ui->groupBox->setCheckable(instance); + ui->groupBox->setChecked(override); + + // populate + ui->list->clear(); + for (auto iter = value.begin(); iter != value.end(); iter++) { + auto item = new QTreeWidgetItem(ui->list); + item->setText(0, iter.key()); + item->setText(1, iter.value().toString()); + item->setFlags(item->flags() | Qt::ItemIsEditable); + ui->list->addTopLevelItem(item); + } +} + +bool EnvironmentVariables::eventFilter(QObject* watched, QEvent* event) +{ + if (watched == ui->list && event->type() == QEvent::KeyPress) { + const QKeyEvent* keyEvent = (QKeyEvent*)event; + if (keyEvent->key() == Qt::Key_Delete) { + emit ui->remove->clicked(); + return true; + } + } + + return QObject::eventFilter(watched, event); +} + +void EnvironmentVariables::retranslate() +{ + ui->retranslateUi(this); +} + +bool EnvironmentVariables::override() const +{ + if (!ui->groupBox->isCheckable()) + return false; + return ui->groupBox->isChecked(); +} + +QMap EnvironmentVariables::value() const +{ + QMap result; + QTreeWidgetItem* item = ui->list->topLevelItem(0); + for (int i = 1; item != nullptr; item = ui->list->topLevelItem(i++)) + result[item->text(0)] = item->text(1); + + return result; +} diff --git a/launcher/ui/widgets/EnvironmentVariables.h b/launcher/ui/widgets/EnvironmentVariables.h new file mode 100644 index 000000000..092d586bd --- /dev/null +++ b/launcher/ui/widgets/EnvironmentVariables.h @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2023 TheKodeToad + * + * 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 . + */ + +#pragma once + +#include +#include + +namespace Ui { +class EnvironmentVariables; +} + +class EnvironmentVariables : public QWidget { + Q_OBJECT + + public: + explicit EnvironmentVariables(QWidget* state = nullptr); + ~EnvironmentVariables() override; + void initialize(bool instance, bool override, const QMap& value); + bool eventFilter(QObject* watched, QEvent* event) override; + + void retranslate(); + bool override() const; + QMap value() const; + + private: + Ui::EnvironmentVariables* ui; +}; diff --git a/launcher/ui/widgets/EnvironmentVariables.ui b/launcher/ui/widgets/EnvironmentVariables.ui new file mode 100644 index 000000000..ded5b2ded --- /dev/null +++ b/launcher/ui/widgets/EnvironmentVariables.ui @@ -0,0 +1,115 @@ + + + EnvironmentVariables + + + + 0 + 0 + 565 + 410 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + &Environment Variables + + + true + + + + + + true + + + QAbstractItemView::ExtendedSelection + + + false + + + false + + + true + + + false + + + + Name + + + + + Value + + + + + + + + + + &Add + + + + + + + &Remove + + + + + + + &Clear + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + +