From 1d1d1fbff9648e9adf7acf571514abf618ffc40f Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Wed, 21 Jul 2021 11:06:41 +0200 Subject: options: add watch-later-options This allows configuring which options are saved by quit-watch-later. Fixes #4126, #4641 and #5567. Toggling a video or audio filter twice would treat the option as changed because the backup value is NULL, and the current value of vf/af is a list with one empty item, so obj_settings_list_equal had to be changed. --- player/configfiles.c | 88 +++++++++------------------------------------------- player/core.h | 2 -- player/main.c | 5 ++- 3 files changed, 18 insertions(+), 77 deletions(-) (limited to 'player') diff --git a/player/configfiles.c b/player/configfiles.c index 83aed38d27..65dd9df425 100644 --- a/player/configfiles.c +++ b/player/configfiles.c @@ -37,6 +37,7 @@ #include "misc/ctype.h" #include "options/path.h" #include "options/m_config.h" +#include "options/m_config_frontend.h" #include "options/parse_configfile.h" #include "common/playlist.h" #include "options/options.h" @@ -237,63 +238,6 @@ exit: return res; } -static const char *const backup_properties[] = { - "osd-level", - //"loop", - "speed", - "options/edition", - "pause", - "volume", - "mute", - "audio-delay", - //"balance", - "fullscreen", - "ontop", - "border", - "gamma", - "brightness", - "contrast", - "saturation", - "hue", - "options/deinterlace", - "vf", - "af", - "panscan", - "options/aid", - "options/vid", - "options/sid", - "sub-delay", - "sub-speed", - "sub-pos", - "sub-visibility", - "sub-scale", - "sub-use-margins", - "sub-ass-force-margins", - "sub-ass-vsfilter-aspect-compat", - "sub-ass-override", - "ab-loop-a", - "ab-loop-b", - "options/video-aspect-override", - 0 -}; - -// Used to retrieve default settings, which should not be stored in the -// resume config. Uses backup_properties[] meaning/order of values. -// This explicitly includes values set by config files and command line. -void mp_get_resume_defaults(struct MPContext *mpctx) -{ - char **list = - talloc_zero_array(mpctx, char*, MP_ARRAY_SIZE(backup_properties)); - for (int i = 0; backup_properties[i]; i++) { - const char *pname = backup_properties[i]; - char *val = NULL; - int r = mp_property_do(pname, M_PROPERTY_GET_STRING, &val, mpctx); - if (r == M_PROPERTY_OK) - list[i] = talloc_steal(list, val); - } - mpctx->resume_defaults = list; -} - // Should follow what parser-cfg.c does/needs static bool needs_config_quoting(const char *s) { @@ -368,25 +312,21 @@ void mp_write_watch_later_conf(struct MPContext *mpctx) } else { fprintf(file, "start=%f\n", pos); } - for (int i = 0; backup_properties[i]; i++) { - const char *pname = backup_properties[i]; - char *val = NULL; - int r = mp_property_do(pname, M_PROPERTY_GET_STRING, &val, mpctx); - if (r == M_PROPERTY_OK) { - if (strncmp(pname, "options/", 8) == 0) - pname += 8; - // Only store it if it's different from the initial value. - char *prev = mpctx->resume_defaults[i]; - if (!prev || strcmp(prev, val) != 0) { - if (needs_config_quoting(val)) { - // e.g. '%6%STRING' - fprintf(file, "%s=%%%d%%%s\n", pname, (int)strlen(val), val); - } else { - fprintf(file, "%s=%s\n", pname, val); - } + char **watch_later_options = mpctx->opts->watch_later_options; + for (int i = 0; watch_later_options && watch_later_options[i]; i++) { + char *pname = watch_later_options[i]; + // Only store it if it's different from the initial value. + if (m_config_watch_later_backup_opt_changed(mpctx->mconfig, pname)) { + char *val = NULL; + mp_property_do(pname, M_PROPERTY_GET_STRING, &val, mpctx); + if (needs_config_quoting(val)) { + // e.g. '%6%STRING' + fprintf(file, "%s=%%%d%%%s\n", pname, (int)strlen(val), val); + } else { + fprintf(file, "%s=%s\n", pname, val); } + talloc_free(val); } - talloc_free(val); } fclose(file); diff --git a/player/core.h b/player/core.h index fcb513bed1..1d5b395b07 100644 --- a/player/core.h +++ b/player/core.h @@ -295,7 +295,6 @@ typedef struct MPContext { // Return code to use with PT_QUIT int quit_custom_rc; bool has_quit_custom_rc; - char **resume_defaults; // Global file statistics int files_played; // played without issues (even if stopped by user) @@ -511,7 +510,6 @@ void audio_start_ao(struct MPContext *mpctx); // configfiles.c void mp_parse_cfgfiles(struct MPContext *mpctx); void mp_load_auto_profiles(struct MPContext *mpctx); -void mp_get_resume_defaults(struct MPContext *mpctx); void mp_load_playback_resume(struct MPContext *mpctx, const char *file); void mp_write_watch_later_conf(struct MPContext *mpctx); void mp_delete_watch_later_conf(struct MPContext *mpctx, const char *file); diff --git a/player/main.c b/player/main.c index 58be00b6d8..e039f61975 100644 --- a/player/main.c +++ b/player/main.c @@ -353,7 +353,10 @@ int mp_initialize(struct MPContext *mpctx, char **options) m_config_set_profile(mpctx->mconfig, "pseudo-gui", 0); } - mp_get_resume_defaults(mpctx); + // Backup the default settings, which should not be stored in the resume + // config files. This explicitly includes values set by config files and + // the command line. + m_config_backup_watch_later_opts(mpctx->mconfig); mp_input_load_config(mpctx->input); -- cgit v1.2.3