Merge branch 'develop' of https://github.com/PrismLauncher/PrismLauncher into toggle_deps
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
@ -101,7 +101,7 @@ QString getCreditsHtml()
|
||||
stream << "<h3>" << QObject::tr("With thanks to", "About Credits") << "</h3>\n";
|
||||
stream << QString("<p>Boba %1</p>\n").arg(getWebsite("https://bobaonline.neocities.org/"));
|
||||
stream << QString("<p>Davi Rafael %1</p>\n").arg(getWebsite("https://auti.one/"));
|
||||
stream << QString("<p>Fulmine %1</p>\n").arg(getWebsite("https://www.fulmine.xyz/"));
|
||||
stream << QString("<p>Fulmine %1</p>\n").arg(getWebsite("https://fulmine.xyz/"));
|
||||
stream << QString("<p>ely %1</p>\n").arg(getGitHub("elyrodso"));
|
||||
stream << QString("<p>gon sawa %1</p>\n").arg(getGitHub("gonsawa"));
|
||||
stream << QString("<p>Pankakes</p>\n");
|
||||
|
@ -43,7 +43,7 @@
|
||||
#include "FileIgnoreProxy.h"
|
||||
|
||||
class BaseInstance;
|
||||
typedef std::shared_ptr<BaseInstance> InstancePtr;
|
||||
using InstancePtr = std::shared_ptr<BaseInstance>;
|
||||
|
||||
namespace Ui {
|
||||
class ExportInstanceDialog;
|
||||
|
@ -214,10 +214,11 @@ void ExportToModListDialog::addExtra(ExportToModList::OptionalData option)
|
||||
void ExportToModListDialog::enableCustom(bool enabled)
|
||||
{
|
||||
ui->authorsCheckBox->setHidden(enabled);
|
||||
ui->versionCheckBox->setHidden(enabled);
|
||||
ui->urlCheckBox->setHidden(enabled);
|
||||
|
||||
ui->authorsButton->setHidden(!enabled);
|
||||
|
||||
ui->versionCheckBox->setHidden(enabled);
|
||||
ui->versionButton->setHidden(!enabled);
|
||||
|
||||
ui->urlCheckBox->setHidden(enabled);
|
||||
ui->urlButton->setHidden(!enabled);
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>650</width>
|
||||
<height>446</height>
|
||||
<height>522</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -61,18 +61,37 @@
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QGroupBox" name="templateGroup">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Template</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QTextEdit" name="templateText"/>
|
||||
<widget class="QTextEdit" name="templateText">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QGroupBox" name="optionsGroup">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Optional Info</string>
|
||||
</property>
|
||||
|
@ -188,7 +188,7 @@ void ModUpdateDialog::checkCandidates()
|
||||
}
|
||||
}
|
||||
|
||||
if (m_include_deps) { // dependencies
|
||||
if (m_include_deps && !APPLICATION->settings()->get("ModDependenciesDisabled").toBool()) { // dependencies
|
||||
auto depTask = makeShared<GetModDependenciesTask>(this, m_instance, m_mod_model.get(), selectedVers);
|
||||
|
||||
connect(depTask.get(), &Task::failed, this,
|
||||
|
@ -270,13 +270,15 @@ QList<BasePage*> ModDownloadDialog::getPages()
|
||||
|
||||
GetModDependenciesTask::Ptr ModDownloadDialog::getModDependenciesTask()
|
||||
{
|
||||
if (auto model = dynamic_cast<ModFolderModel*>(getBaseModel().get()); model) {
|
||||
QList<std::shared_ptr<GetModDependenciesTask::PackDependency>> selectedVers;
|
||||
for (auto& selected : getTasks()) {
|
||||
selectedVers.append(std::make_shared<GetModDependenciesTask::PackDependency>(selected->getPack(), selected->getVersion()));
|
||||
}
|
||||
if (!APPLICATION->settings()->get("ModDependenciesDisabled").toBool()) { // dependencies
|
||||
if (auto model = dynamic_cast<ModFolderModel*>(getBaseModel().get()); model) {
|
||||
QList<std::shared_ptr<GetModDependenciesTask::PackDependency>> selectedVers;
|
||||
for (auto& selected : getTasks()) {
|
||||
selectedVers.append(std::make_shared<GetModDependenciesTask::PackDependency>(selected->getPack(), selected->getVersion()));
|
||||
}
|
||||
|
||||
return makeShared<GetModDependenciesTask>(this, m_instance, model, selectedVers);
|
||||
return makeShared<GetModDependenciesTask>(this, m_instance, model, selectedVers);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ class AccessibleInstanceView : public QAccessibleTableInterface, public QAccessi
|
||||
|
||||
protected:
|
||||
// maybe vector
|
||||
typedef QHash<int, QAccessible::Id> ChildCache;
|
||||
using ChildCache = QHash<int, QAccessible::Id>;
|
||||
mutable ChildCache childToId;
|
||||
|
||||
virtual ~AccessibleInstanceView();
|
||||
|
@ -77,4 +77,4 @@ class BasePage {
|
||||
bool isOpened = false;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<BasePage> BasePagePtr;
|
||||
using BasePagePtr = std::shared_ptr<BasePage>;
|
||||
|
@ -26,7 +26,7 @@ class BasePageProvider {
|
||||
};
|
||||
|
||||
class GenericPageProvider : public BasePageProvider {
|
||||
typedef std::function<BasePage*()> PageCreator;
|
||||
using PageCreator = std::function<BasePage*()>;
|
||||
|
||||
public:
|
||||
explicit GenericPageProvider(const QString& dialogTitle) : m_dialogTitle(dialogTitle) {}
|
||||
|
@ -42,22 +42,17 @@
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include "net/NetJob.h"
|
||||
|
||||
#include "ui/dialogs/CustomMessageBox.h"
|
||||
#include "ui/dialogs/MSALoginDialog.h"
|
||||
#include "ui/dialogs/OfflineLoginDialog.h"
|
||||
#include "ui/dialogs/ProgressDialog.h"
|
||||
#include "ui/dialogs/SkinUploadDialog.h"
|
||||
|
||||
#include "minecraft/auth/AccountTask.h"
|
||||
#include "minecraft/services/SkinDelete.h"
|
||||
#include "tasks/Task.h"
|
||||
|
||||
#include "Application.h"
|
||||
|
||||
#include "BuildConfig.h"
|
||||
|
||||
AccountListPage::AccountListPage(QWidget* parent) : QMainWindow(parent), ui(new Ui::AccountListPage)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
@ -172,6 +167,12 @@ void AccountListPage::on_actionAddOffline_triggered()
|
||||
|
||||
void AccountListPage::on_actionRemove_triggered()
|
||||
{
|
||||
auto response = CustomMessageBox::selectable(this, tr("Remove account?"), tr("Do you really want to delete this account?"),
|
||||
QMessageBox::Question, QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
|
||||
->exec();
|
||||
if (response != QMessageBox::Yes) {
|
||||
return;
|
||||
}
|
||||
QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes();
|
||||
if (selection.size() > 0) {
|
||||
QModelIndex selected = selection.first();
|
||||
|
71
launcher/ui/pages/global/EnvironmentVariablesPage.cpp
Normal file
71
launcher/ui/pages/global/EnvironmentVariablesPage.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
// 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 <QTabBar>
|
||||
#include <QTabWidget>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#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();
|
||||
}
|
42
launcher/ui/pages/global/EnvironmentVariablesPage.h
Normal file
42
launcher/ui/pages/global/EnvironmentVariablesPage.h
Normal file
@ -0,0 +1,42 @@
|
||||
// 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 <Application.h>
|
||||
|
||||
#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;
|
||||
};
|
@ -223,6 +223,7 @@ void LauncherPage::applySettings()
|
||||
|
||||
// Mods
|
||||
s->set("ModMetadataDisabled", ui->metadataDisableBtn->isChecked());
|
||||
s->set("ModDependenciesDisabled", ui->dependenciesDisableBtn->isChecked());
|
||||
}
|
||||
void LauncherPage::loadSettings()
|
||||
{
|
||||
@ -278,6 +279,7 @@ void LauncherPage::loadSettings()
|
||||
// Mods
|
||||
ui->metadataDisableBtn->setChecked(s->get("ModMetadataDisabled").toBool());
|
||||
ui->metadataWarningLabel->setHidden(!ui->metadataDisableBtn->isChecked());
|
||||
ui->dependenciesDisableBtn->setChecked(s->get("ModDependenciesDisabled").toBool());
|
||||
}
|
||||
|
||||
void LauncherPage::refreshFontPreview()
|
||||
|
@ -186,6 +186,16 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="dependenciesDisableBtn">
|
||||
<property name="toolTip">
|
||||
<string>Disable automatically checking and installation of mod dependencies.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Do not install mod dependencies</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -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()
|
||||
|
@ -35,13 +35,10 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTabWidget" name="settingsTabs">
|
||||
<property name="tabShape">
|
||||
<enum>QTabWidget::Rounded</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="minecraftTab">
|
||||
<widget class="QWidget" name="minecraftPage">
|
||||
<attribute name="title">
|
||||
<string notr="true">Java</string>
|
||||
</attribute>
|
||||
@ -254,7 +251,7 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="javaTab">
|
||||
<widget class="QWidget" name="javaPage">
|
||||
<attribute name="title">
|
||||
<string>Game windows</string>
|
||||
</attribute>
|
||||
@ -414,7 +411,7 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab">
|
||||
<widget class="QWidget" name="customCommandsPage">
|
||||
<attribute name="title">
|
||||
<string>Custom commands</string>
|
||||
</attribute>
|
||||
@ -424,6 +421,16 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="environmentVariablesPage">
|
||||
<attribute name="title">
|
||||
<string>Environment variables</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_16">
|
||||
<item>
|
||||
<widget class="EnvironmentVariables" name="environmentVariables" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="workaroundsPage">
|
||||
<attribute name="title">
|
||||
<string>Workarounds</string>
|
||||
@ -736,6 +743,12 @@
|
||||
<header>ui/widgets/CustomCommands.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>EnvironmentVariables</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>ui/widgets/EnvironmentVariables.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>openGlobalJavaSettingsButton</tabstop>
|
||||
|
@ -221,6 +221,10 @@ void ModFolderPage::updateMods(bool includeDeps)
|
||||
QMessageBox::critical(this, tr("Error"), tr("Please install a mod loader first!"));
|
||||
return;
|
||||
}
|
||||
if (APPLICATION->settings()->get("ModMetadataDisabled").toBool()) {
|
||||
QMessageBox::critical(this, tr("Error"), tr("Mod updates are unavailable when metadata is disabled!"));
|
||||
return;
|
||||
}
|
||||
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection()).indexes();
|
||||
|
||||
auto mods_list = m_model->selectedMods(selection);
|
||||
|
@ -68,8 +68,8 @@
|
||||
#include <FileSystem.h>
|
||||
#include "RWStorage.h"
|
||||
|
||||
typedef RWStorage<QString, QIcon> SharedIconCache;
|
||||
typedef std::shared_ptr<SharedIconCache> SharedIconCachePtr;
|
||||
using SharedIconCache = RWStorage<QString, QIcon>;
|
||||
using SharedIconCachePtr = std::shared_ptr<SharedIconCache>;
|
||||
|
||||
class ThumbnailingResult : public QObject {
|
||||
Q_OBJECT
|
||||
|
@ -24,8 +24,8 @@
|
||||
|
||||
namespace Atl {
|
||||
|
||||
typedef QMap<QString, QIcon> LogoMap;
|
||||
typedef std::function<void(QString)> LogoCallback;
|
||||
using LogoMap = QMap<QString, QIcon>;
|
||||
using LogoCallback = std::function<void(QString)>;
|
||||
|
||||
class ListModel : public QAbstractListModel {
|
||||
Q_OBJECT
|
||||
|
@ -19,8 +19,8 @@
|
||||
|
||||
namespace Flame {
|
||||
|
||||
typedef QMap<QString, QIcon> LogoMap;
|
||||
typedef std::function<void(QString)> LogoCallback;
|
||||
using LogoMap = QMap<QString, QIcon>;
|
||||
using LogoCallback = std::function<void(QString)>;
|
||||
|
||||
class ListModel : public QAbstractListModel {
|
||||
Q_OBJECT
|
||||
|
@ -13,8 +13,8 @@
|
||||
|
||||
namespace LegacyFTB {
|
||||
|
||||
typedef QMap<QString, QIcon> FTBLogoMap;
|
||||
typedef std::function<void(QString)> LogoCallback;
|
||||
using FTBLogoMap = QMap<QString, QIcon>;
|
||||
using LogoCallback = std::function<void(QString)>;
|
||||
|
||||
class FilterModel : public QSortFilterProxyModel {
|
||||
Q_OBJECT
|
||||
|
@ -42,7 +42,7 @@
|
||||
|
||||
namespace Technic {
|
||||
|
||||
typedef std::function<void(QString)> LogoCallback;
|
||||
using LogoCallback = std::function<void(QString)>;
|
||||
|
||||
class ListModel : public QAbstractListModel {
|
||||
Q_OBJECT
|
||||
|
110
launcher/ui/widgets/EnvironmentVariables.cpp
Normal file
110
launcher/ui/widgets/EnvironmentVariables.cpp
Normal file
@ -0,0 +1,110 @@
|
||||
// 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 <QKeyEvent>
|
||||
|
||||
#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<QString, QVariant>& 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<QString, QVariant> EnvironmentVariables::value() const
|
||||
{
|
||||
QMap<QString, QVariant> 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;
|
||||
}
|
43
launcher/ui/widgets/EnvironmentVariables.h
Normal file
43
launcher/ui/widgets/EnvironmentVariables.h
Normal file
@ -0,0 +1,43 @@
|
||||
// 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 <QMap>
|
||||
#include <QWidget>
|
||||
|
||||
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<QString, QVariant>& value);
|
||||
bool eventFilter(QObject* watched, QEvent* event) override;
|
||||
|
||||
void retranslate();
|
||||
bool override() const;
|
||||
QMap<QString, QVariant> value() const;
|
||||
|
||||
private:
|
||||
Ui::EnvironmentVariables* ui;
|
||||
};
|
115
launcher/ui/widgets/EnvironmentVariables.ui
Normal file
115
launcher/ui/widgets/EnvironmentVariables.ui
Normal file
@ -0,0 +1,115 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>EnvironmentVariables</class>
|
||||
<widget class="QWidget" name="EnvironmentVariables">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>565</width>
|
||||
<height>410</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>&Environment Variables</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QTreeWidget" name="list">
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||
</property>
|
||||
<property name="rootIsDecorated">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="itemsExpandable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="animated">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="expandsOnDoubleClick">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Value</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="buttons">
|
||||
<item>
|
||||
<widget class="QPushButton" name="add">
|
||||
<property name="text">
|
||||
<string>&Add</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="remove">
|
||||
<property name="text">
|
||||
<string>&Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="clear">
|
||||
<property name="text">
|
||||
<string>&Clear</string>
|
||||
</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>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Reference in New Issue
Block a user