2023-11-01 21:11:11 +00:00
|
|
|
// This file Copyright © Mnemosyne LLC.
|
2022-11-02 00:32:26 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
|
|
|
|
2023-11-21 15:02:03 +00:00
|
|
|
#include <utility> // std::move()
|
|
|
|
|
2023-04-14 19:33:23 +00:00
|
|
|
#include "libtransmission/session-settings.h"
|
|
|
|
#include "libtransmission/variant.h"
|
2022-11-02 00:32:26 +00:00
|
|
|
|
2023-09-08 00:05:16 +00:00
|
|
|
void tr_session_settings::load(tr_variant const& src)
|
2022-11-02 00:32:26 +00:00
|
|
|
{
|
2023-09-08 00:05:16 +00:00
|
|
|
auto const* map = src.get_if<tr_variant::Map>();
|
|
|
|
if (map == nullptr)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-02 00:32:26 +00:00
|
|
|
#define V(key, field, type, default_value, comment) \
|
2023-09-08 00:05:16 +00:00
|
|
|
if (auto const iter = map->find(key); iter != std::end(*map)) \
|
2022-11-02 00:32:26 +00:00
|
|
|
{ \
|
2023-09-08 00:05:16 +00:00
|
|
|
if (auto val = libtransmission::VariantConverter::load<decltype(field)>(iter->second); val) \
|
2022-11-02 00:32:26 +00:00
|
|
|
{ \
|
|
|
|
this->field = *val; \
|
|
|
|
} \
|
|
|
|
}
|
2022-11-02 14:04:22 +00:00
|
|
|
SESSION_SETTINGS_FIELDS(V)
|
2022-11-02 00:32:26 +00:00
|
|
|
#undef V
|
|
|
|
}
|
|
|
|
|
2023-09-08 00:05:16 +00:00
|
|
|
tr_variant tr_session_settings::settings() const
|
2022-11-02 00:32:26 +00:00
|
|
|
{
|
2023-09-08 00:05:16 +00:00
|
|
|
auto map = tr_variant::Map{};
|
2022-11-02 00:32:26 +00:00
|
|
|
#define V(key, field, type, default_value, comment) \
|
2023-09-08 00:05:16 +00:00
|
|
|
map.try_emplace(key, libtransmission::VariantConverter::save<decltype(field)>(field));
|
2022-11-02 00:32:26 +00:00
|
|
|
SESSION_SETTINGS_FIELDS(V)
|
|
|
|
#undef V
|
2023-09-08 00:05:16 +00:00
|
|
|
return tr_variant{ std::move(map) };
|
|
|
|
}
|
|
|
|
|
|
|
|
tr_variant tr_session_settings::default_settings()
|
|
|
|
{
|
|
|
|
return tr_session_settings{}.settings();
|
2022-11-02 00:32:26 +00:00
|
|
|
}
|