From b6766e1ca0146de939e6645b743634bda717b719 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joshua=20Vanda=C3=ABle?= Date: Wed, 13 Aug 2025 00:33:52 +0200 Subject: GameCubePane: Use ConfigControls where applicable --- .../Config/ConfigControls/ConfigUserPath.cpp | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Source/Core/DolphinQt/Config/ConfigControls/ConfigUserPath.cpp (limited to 'Source/Core/DolphinQt/Config/ConfigControls/ConfigUserPath.cpp') diff --git a/Source/Core/DolphinQt/Config/ConfigControls/ConfigUserPath.cpp b/Source/Core/DolphinQt/Config/ConfigControls/ConfigUserPath.cpp new file mode 100644 index 0000000000..1b6c03f915 --- /dev/null +++ b/Source/Core/DolphinQt/Config/ConfigControls/ConfigUserPath.cpp @@ -0,0 +1,59 @@ +// Copyright 2025 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "DolphinQt/Config/ConfigControls/ConfigUserPath.h" + +#include +#include + +#include "Common/FileUtil.h" + +#include "DolphinQt/Config/ConfigControls/ConfigText.h" +#include "DolphinQt/QtUtils/ModalMessageBox.h" + +ConfigUserPath::ConfigUserPath(const unsigned int dir_index, + const Config::Info& setting) + : ConfigUserPath(dir_index, setting, nullptr) +{ +} + +ConfigUserPath::ConfigUserPath(const unsigned int dir_index, + const Config::Info& setting, Config::Layer* layer) + : ConfigText(setting, layer), m_dir_index(dir_index) +{ + OnConfigChanged(); + + connect(this, &QLineEdit::editingFinished, this, &ConfigUserPath::Update); +} + +// Display the effective path: if Config has a value, use it; otherwise fall back to UserPath. +// Config values only serve to initialize UserPath at startup, an empty config meaning "use the +// current UserPath". +void ConfigUserPath::RefreshText() +{ + const std::string config_value = ReadValue(m_setting); + const std::string userpath_value = File::GetUserPath(m_dir_index); + const QString text = QString::fromStdString(config_value.empty() ? userpath_value : config_value); + setText(text); +} + +void ConfigUserPath::Update() +{ + const QString new_text = text().trimmed(); + if (new_text.isEmpty()) + { + ModalMessageBox::warning(this, tr("Empty Value"), + tr("This field cannot be left empty. Please enter a value.")); + RefreshText(); + return; + } + + const std::string value = new_text.toStdString(); + File::SetUserPath(m_dir_index, value); + SaveValue(m_setting, value); +} + +void ConfigUserPath::OnConfigChanged() +{ + RefreshText(); +} -- cgit v1.2.3