From f42e4374d55a3b68b0c4fcb342d9cdcd5d15c9c7 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 28 Aug 2016 19:42:03 +0200 Subject: command: export profile list as a property Targeted at scripts, which can do whatever they want with it. This comes with the promise that they could get randomly broken any time. See #977. --- options/m_config.c | 27 +++++++++++++++++++++++++++ options/m_config.h | 2 ++ 2 files changed, 29 insertions(+) (limited to 'options') diff --git a/options/m_config.c b/options/m_config.c index 1cb01ebfdc..3dbbb5020a 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -36,6 +36,7 @@ #include "options/m_option.h" #include "common/msg.h" #include "common/msg_control.h" +#include "misc/node.h" static const union m_option_value default_value; @@ -933,6 +934,32 @@ int m_config_set_profile(struct m_config *config, char *name, int flags) return 0; } +struct mpv_node m_config_get_profiles(struct m_config *config) +{ + struct mpv_node root; + node_init(&root, MPV_FORMAT_NODE_ARRAY, NULL); + + for (m_profile_t *profile = config->profiles; profile; profile = profile->next) + { + struct mpv_node *entry = node_array_add(&root, MPV_FORMAT_NODE_MAP); + + node_map_add_string(entry, "name", profile->name); + if (profile->desc) + node_map_add_string(entry, "profile-desc", profile->desc); + + struct mpv_node *opts = + node_map_add(entry, "options", MPV_FORMAT_NODE_ARRAY); + + for (int n = 0; n < profile->num_opts; n++) { + struct mpv_node *opt_entry = node_array_add(opts, MPV_FORMAT_NODE_MAP); + node_map_add_string(opt_entry, "key", profile->opts[n * 2 + 0]); + node_map_add_string(opt_entry, "value", profile->opts[n * 2 + 1]); + } + } + + return root; +} + void *m_config_alloc_struct(void *talloc_ctx, const struct m_sub_options *subopts) { diff --git a/options/m_config.h b/options/m_config.h index ed34389921..5937a4492e 100644 --- a/options/m_config.h +++ b/options/m_config.h @@ -247,6 +247,8 @@ int m_config_set_profile_option(struct m_config *config, struct m_profile *p, */ int m_config_set_profile(struct m_config *config, char *name, int flags); +struct mpv_node m_config_get_profiles(struct m_config *config); + void *m_config_alloc_struct(void *talloc_ctx, const struct m_sub_options *subopts); -- cgit v1.2.3