DolphinQt: Add an optional default value to ConfigUserPath constructor

The optional default value is used to implement `ConfigUserPath::Reset()`.
Since `ConfigUserPath` must not be empty, there was no easy way to reset
these paths to their default value.

With this change users of `ConfigUserPath` can now set the default path.
At the moment users of `ConfigUserPath` must place a reset button and
connect a callback to `ConfigUserPath::Reset` on their own.
This commit is contained in:
Maximilian Mader 2026-04-15 17:36:37 +02:00
parent 296e81a8a3
commit 514beb2081
No known key found for this signature in database
GPG Key ID: F71D56A3151C4FB3
2 changed files with 27 additions and 4 deletions

View File

@ -13,13 +13,21 @@
ConfigUserPath::ConfigUserPath(const unsigned int dir_index,
const Config::Info<std::string>& setting)
: ConfigUserPath(dir_index, setting, nullptr)
: ConfigUserPath(dir_index, setting, "", nullptr)
{
}
ConfigUserPath::ConfigUserPath(const unsigned int dir_index,
const Config::Info<std::string>& setting, Config::Layer* layer)
: ConfigText(setting, layer), m_dir_index(dir_index)
const Config::Info<std::string>& setting,
const std::string default_value)
: ConfigUserPath(dir_index, setting, default_value, nullptr)
{
}
ConfigUserPath::ConfigUserPath(const unsigned int dir_index,
const Config::Info<std::string>& setting,
const std::string default_value, Config::Layer* layer)
: ConfigText(setting, layer), m_dir_index(dir_index), m_default_value(default_value)
{
OnConfigChanged();
@ -57,3 +65,14 @@ void ConfigUserPath::OnConfigChanged()
{
RefreshText();
}
void ConfigUserPath::Reset()
{
if (m_default_value.empty())
return;
File::SetUserPath(m_dir_index, m_default_value);
SaveValue(m_setting, m_default_value);
RefreshText();
}

View File

@ -15,7 +15,10 @@ class ConfigUserPath final : public ConfigText
public:
ConfigUserPath(const unsigned int dir_index, const Config::Info<std::string>& setting);
ConfigUserPath(const unsigned int dir_index, const Config::Info<std::string>& setting,
Config::Layer* layer);
std::string default_value);
ConfigUserPath(const unsigned int dir_index, const Config::Info<std::string>& setting,
std::string default_value, Config::Layer* layer);
void Reset();
protected:
void OnConfigChanged() override;
@ -25,4 +28,5 @@ private:
void Update();
const unsigned int m_dir_index;
const std::string m_default_value;
};