Commit 2792431a authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Automatically save all configuration items

parent d625d6c0
...@@ -151,7 +151,6 @@ struct module_config_t ...@@ -151,7 +151,6 @@ struct module_config_t
char *psz_longtext; /* Long comment on the configuration option */ char *psz_longtext; /* Long comment on the configuration option */
module_value_t value; /* Option value */ module_value_t value; /* Option value */
module_value_t orig; module_value_t orig;
module_value_t saved;
module_value_t min; module_value_t min;
module_value_t max; module_value_t max;
...@@ -180,7 +179,6 @@ struct module_config_t ...@@ -180,7 +179,6 @@ struct module_config_t
bool b_restart; /* Flag to indicate the option needs a restart */ bool b_restart; /* Flag to indicate the option needs a restart */
/* to take effect */ /* to take effect */
/* Option values loaded from config file */ /* Option values loaded from config file */
bool b_autosave; /* Config will be auto-saved at exit time */
bool b_unsaveable; /* Config should not be saved */ bool b_unsaveable; /* Config should not be saved */
bool b_safe; bool b_safe;
......
...@@ -72,8 +72,8 @@ enum vlc_module_properties ...@@ -72,8 +72,8 @@ enum vlc_module_properties
VLC_CONFIG_VOLATILE, VLC_CONFIG_VOLATILE,
/* don't write variable to storage (args=none) */ /* don't write variable to storage (args=none) */
VLC_CONFIG_PERSISTENT, VLC_CONFIG_PERSISTENT_OBSOLETE,
/* always write variable to storage (args=none) */ /* unused (ignored) */
VLC_CONFIG_RESTART, VLC_CONFIG_RESTART,
/* restart required to apply value change (args=none) */ /* restart required to apply value change (args=none) */
...@@ -419,9 +419,6 @@ enum vlc_module_properties ...@@ -419,9 +419,6 @@ enum vlc_module_properties
#define change_need_restart() \ #define change_need_restart() \
vlc_config_set (p_config, VLC_CONFIG_RESTART); vlc_config_set (p_config, VLC_CONFIG_RESTART);
#define change_autosave() \
vlc_config_set (p_config, VLC_CONFIG_PERSISTENT);
/* For options that are saved but hidden from the preferences panel */ /* For options that are saved but hidden from the preferences panel */
#define change_private() \ #define change_private() \
vlc_config_set (p_config, VLC_CONFIG_PRIVATE); vlc_config_set (p_config, VLC_CONFIG_PRIVATE);
......
...@@ -482,10 +482,8 @@ vlc_module_begin () ...@@ -482,10 +482,8 @@ vlc_module_begin ()
set_subcategory( SUBCAT_INTERFACE_MAIN ) set_subcategory( SUBCAT_INTERFACE_MAIN )
add_loadfile( "skins2-last", "", SKINS2_LAST, SKINS2_LAST_LONG, add_loadfile( "skins2-last", "", SKINS2_LAST, SKINS2_LAST_LONG,
true ) true )
change_autosave ()
add_string( "skins2-config", "", SKINS2_CONFIG, SKINS2_CONFIG_LONG, add_string( "skins2-config", "", SKINS2_CONFIG, SKINS2_CONFIG_LONG,
true ) true )
change_autosave ()
change_private () change_private ()
#ifdef WIN32 #ifdef WIN32
add_bool( "skins2-systray", true, SKINS2_SYSTRAY, add_bool( "skins2-systray", true, SKINS2_SYSTRAY,
......
...@@ -66,7 +66,6 @@ vlc_module_begin () ...@@ -66,7 +66,6 @@ vlc_module_begin ()
add_string( "podcast-urls", NULL, add_string( "podcast-urls", NULL,
URLS_TEXT, URLS_LONGTEXT, false ) URLS_TEXT, URLS_LONGTEXT, false )
change_autosave ()
set_capability( "services_discovery", 0 ) set_capability( "services_discovery", 0 )
set_callbacks( Open, Close ) set_callbacks( Open, Close )
......
...@@ -473,7 +473,6 @@ void config_Free( module_t *p_module ) ...@@ -473,7 +473,6 @@ void config_Free( module_t *p_module )
{ {
free (p_item->value.psz); free (p_item->value.psz);
free (p_item->orig.psz); free (p_item->orig.psz);
free (p_item->saved.psz);
} }
if( p_item->ppsz_list ) if( p_item->ppsz_list )
......
...@@ -228,7 +228,7 @@ int config_LoadConfigFile( vlc_object_t *p_this ) ...@@ -228,7 +228,7 @@ int config_LoadConfigFile( vlc_object_t *p_this )
msg_Warn (p_this, "Integer value (%s) for %s: %m", msg_Warn (p_this, "Integer value (%s) for %s: %m",
psz_option_value, psz_option_name); psz_option_value, psz_option_name);
else else
item->saved.i = item->value.i = l; item->value.i = l;
break; break;
} }
...@@ -236,14 +236,11 @@ int config_LoadConfigFile( vlc_object_t *p_this ) ...@@ -236,14 +236,11 @@ int config_LoadConfigFile( vlc_object_t *p_this )
if (!*psz_option_value) if (!*psz_option_value)
break; /* ignore empty option */ break; /* ignore empty option */
item->value.f = (float)atof (psz_option_value); item->value.f = (float)atof (psz_option_value);
item->saved.f = item->value.f;
break; break;
default: default:
free ((char *)item->value.psz); free ((char *)item->value.psz);
free ((char *)item->saved.psz);
item->value.psz = convert (psz_option_value); item->value.psz = convert (psz_option_value);
item->saved.psz = strdupnull (item->value.psz);
break; break;
} }
} }
...@@ -357,7 +354,7 @@ static int config_PrepareDir (vlc_object_t *obj) ...@@ -357,7 +354,7 @@ static int config_PrepareDir (vlc_object_t *obj)
* save. * save.
* Really stupid no ? * Really stupid no ?
*****************************************************************************/ *****************************************************************************/
static int SaveConfigFile( vlc_object_t *p_this, bool b_autosave ) static int SaveConfigFile (vlc_object_t *p_this)
{ {
module_t *p_parser; module_t *p_parser;
char *permanent = NULL, *temporary = NULL; char *permanent = NULL, *temporary = NULL;
...@@ -520,66 +517,37 @@ static int SaveConfigFile( vlc_object_t *p_this, bool b_autosave ) ...@@ -520,66 +517,37 @@ static int SaveConfigFile( vlc_object_t *p_this, bool b_autosave )
|| p_item->b_unsaveable) /* ignore volatile option */ || p_item->b_unsaveable) /* ignore volatile option */
continue; continue;
/* Do not save the new value in the configuration file
* if doing an autosave, and the item is not an "autosaved" one. */
bool b_retain = b_autosave && !p_item->b_autosave;
if (IsConfigIntegerType (p_item->i_type)) if (IsConfigIntegerType (p_item->i_type))
{ {
int64_t val = b_retain ? p_item->saved.i : p_item->value.i; int64_t val = p_item->value.i;
config_Write (file, p_item->psz_text, config_Write (file, p_item->psz_text,
(p_item->i_type == CONFIG_ITEM_BOOL) (p_item->i_type == CONFIG_ITEM_BOOL)
? N_("boolean") : N_("integer"), ? N_("boolean") : N_("integer"),
val == p_item->orig.i, val == p_item->orig.i,
p_item->psz_name, "%"PRId64, val); p_item->psz_name, "%"PRId64, val);
p_item->saved.i = val;
} }
else else
if (IsConfigFloatType (p_item->i_type)) if (IsConfigFloatType (p_item->i_type))
{ {
float val = b_retain ? p_item->saved.f : p_item->value.f; float val = p_item->value.f;
config_Write (file, p_item->psz_text, N_("float"), config_Write (file, p_item->psz_text, N_("float"),
val == p_item->orig.f, val == p_item->orig.f,
p_item->psz_name, "%f", val); p_item->psz_name, "%f", val);
p_item->saved.f = val;
} }
else else
{ {
const char *psz_value = b_retain ? p_item->saved.psz const char *psz_value = p_item->value.psz;
: p_item->value.psz;
bool modified; bool modified;
assert (IsConfigStringType (p_item->i_type)); assert (IsConfigStringType (p_item->i_type));
if (b_retain && (psz_value == NULL)) /* FIXME: hack */ modified = !!strcmp (psz_value ? psz_value : "",
psz_value = p_item->orig.psz; p_item->orig.psz ? p_item->orig.psz : "");
modified =
(psz_value != NULL)
? ((p_item->orig.psz != NULL)
? (strcmp (psz_value, p_item->orig.psz) != 0)
: true)
: (p_item->orig.psz != NULL);
config_Write (file, p_item->psz_text, N_("string"), config_Write (file, p_item->psz_text, N_("string"),
!modified, p_item->psz_name, "%s", !modified, p_item->psz_name, "%s",
psz_value ? psz_value : ""); psz_value ? psz_value : "");
if ( !b_retain )
{
free ((char *)p_item->saved.psz);
if( (psz_value && p_item->orig.psz &&
strcmp( psz_value, p_item->orig.psz )) ||
!psz_value || !p_item->orig.psz)
p_item->saved.psz = strdupnull (psz_value);
else
p_item->saved.psz = NULL;
}
} }
p_item->b_dirty = false;
if (!b_retain)
p_item->b_dirty = false;
} }
} }
vlc_rwlock_unlock (&config_lock); vlc_rwlock_unlock (&config_lock);
...@@ -666,13 +634,13 @@ int config_AutoSaveConfigFile( vlc_object_t *p_this ) ...@@ -666,13 +634,13 @@ int config_AutoSaveConfigFile( vlc_object_t *p_this )
p_item < p_end && !save; p_item < p_end && !save;
p_item++ ) p_item++ )
{ {
save = p_item->b_autosave && p_item->b_dirty; save = p_item->b_dirty;
} }
} }
if (save) if (save)
/* Note: this will get the read lock recursively. Ok. */ /* Note: this will get the read lock recursively. Ok. */
ret = SaveConfigFile (p_this, true); ret = SaveConfigFile (p_this);
vlc_rwlock_unlock (&config_lock); vlc_rwlock_unlock (&config_lock);
module_list_free (list); module_list_free (list);
...@@ -682,5 +650,5 @@ int config_AutoSaveConfigFile( vlc_object_t *p_this ) ...@@ -682,5 +650,5 @@ int config_AutoSaveConfigFile( vlc_object_t *p_this )
#undef config_SaveConfigFile #undef config_SaveConfigFile
int config_SaveConfigFile( vlc_object_t *p_this ) int config_SaveConfigFile( vlc_object_t *p_this )
{ {
return SaveConfigFile( p_this, false ); return SaveConfigFile (p_this);
} }
...@@ -2710,34 +2710,24 @@ vlc_module_begin () ...@@ -2710,34 +2710,24 @@ vlc_module_begin ()
add_string( "bookmark1", NULL, add_string( "bookmark1", NULL,
BOOKMARK1_TEXT, BOOKMARK_LONGTEXT, false ) BOOKMARK1_TEXT, BOOKMARK_LONGTEXT, false )
change_autosave()
add_string( "bookmark2", NULL, add_string( "bookmark2", NULL,
BOOKMARK2_TEXT, BOOKMARK_LONGTEXT, false ) BOOKMARK2_TEXT, BOOKMARK_LONGTEXT, false )
change_autosave()
add_string( "bookmark3", NULL, add_string( "bookmark3", NULL,
BOOKMARK3_TEXT, BOOKMARK_LONGTEXT, false ) BOOKMARK3_TEXT, BOOKMARK_LONGTEXT, false )
change_autosave()
add_string( "bookmark4", NULL, add_string( "bookmark4", NULL,
BOOKMARK4_TEXT, BOOKMARK_LONGTEXT, false ) BOOKMARK4_TEXT, BOOKMARK_LONGTEXT, false )
change_autosave()
add_string( "bookmark5", NULL, add_string( "bookmark5", NULL,
BOOKMARK5_TEXT, BOOKMARK_LONGTEXT, false ) BOOKMARK5_TEXT, BOOKMARK_LONGTEXT, false )
change_autosave()
add_string( "bookmark6", NULL, add_string( "bookmark6", NULL,
BOOKMARK6_TEXT, BOOKMARK_LONGTEXT, false ) BOOKMARK6_TEXT, BOOKMARK_LONGTEXT, false )
change_autosave()
add_string( "bookmark7", NULL, add_string( "bookmark7", NULL,
BOOKMARK7_TEXT, BOOKMARK_LONGTEXT, false ) BOOKMARK7_TEXT, BOOKMARK_LONGTEXT, false )
change_autosave()
add_string( "bookmark8", NULL, add_string( "bookmark8", NULL,
BOOKMARK8_TEXT, BOOKMARK_LONGTEXT, false ) BOOKMARK8_TEXT, BOOKMARK_LONGTEXT, false )
change_autosave()
add_string( "bookmark9", NULL, add_string( "bookmark9", NULL,
BOOKMARK9_TEXT, BOOKMARK_LONGTEXT, false ) BOOKMARK9_TEXT, BOOKMARK_LONGTEXT, false )
change_autosave()
add_string( "bookmark10", NULL, add_string( "bookmark10", NULL,
BOOKMARK10_TEXT, BOOKMARK_LONGTEXT, false ) BOOKMARK10_TEXT, BOOKMARK_LONGTEXT, false )
change_autosave()
#define HELP_TEXT \ #define HELP_TEXT \
N_("print help for VLC (can be combined with --advanced and " \ N_("print help for VLC (can be combined with --advanced and " \
......
...@@ -368,15 +368,10 @@ static int CacheLoadConfig( module_t *p_module, FILE *file ) ...@@ -368,15 +368,10 @@ static int CacheLoadConfig( module_t *p_module, FILE *file )
p_module->p_config[i].value.psz = p_module->p_config[i].value.psz =
(p_module->p_config[i].orig.psz != NULL) (p_module->p_config[i].orig.psz != NULL)
? strdup (p_module->p_config[i].orig.psz) : NULL; ? strdup (p_module->p_config[i].orig.psz) : NULL;
p_module->p_config[i].saved.psz = NULL;
} }
else else
{
memcpy (&p_module->p_config[i].value, &p_module->p_config[i].orig, memcpy (&p_module->p_config[i].value, &p_module->p_config[i].orig,
sizeof (p_module->p_config[i].value)); sizeof (p_module->p_config[i].value));
memcpy (&p_module->p_config[i].saved, &p_module->p_config[i].orig,
sizeof (p_module->p_config[i].saved));
}
p_module->p_config[i].b_dirty = false; p_module->p_config[i].b_dirty = false;
......
...@@ -267,13 +267,13 @@ int vlc_plugin_set (module_t *module, module_config_t *item, int propid, ...) ...@@ -267,13 +267,13 @@ int vlc_plugin_set (module_t *module, module_config_t *item, int propid, ...)
{ {
if (IsConfigIntegerType (item->i_type)) if (IsConfigIntegerType (item->i_type))
{ {
item->orig.i = item->saved.i = item->orig.i =
item->value.i = va_arg (ap, int64_t); item->value.i = va_arg (ap, int64_t);
} }
else else
if (IsConfigFloatType (item->i_type)) if (IsConfigFloatType (item->i_type))
{ {
item->orig.f = item->saved.f = item->orig.f =
item->value.f = va_arg (ap, double); item->value.f = va_arg (ap, double);
} }
else else
...@@ -282,7 +282,6 @@ int vlc_plugin_set (module_t *module, module_config_t *item, int propid, ...) ...@@ -282,7 +282,6 @@ int vlc_plugin_set (module_t *module, module_config_t *item, int propid, ...)
const char *value = va_arg (ap, const char *); const char *value = va_arg (ap, const char *);
item->value.psz = value ? strdup (value) : NULL; item->value.psz = value ? strdup (value) : NULL;
item->orig.psz = value ? strdup (value) : NULL; item->orig.psz = value ? strdup (value) : NULL;
item->saved.psz = value ? strdup (value) : NULL;
} }
break; break;
} }
...@@ -313,10 +312,6 @@ int vlc_plugin_set (module_t *module, module_config_t *item, int propid, ...) ...@@ -313,10 +312,6 @@ int vlc_plugin_set (module_t *module, module_config_t *item, int propid, ...)
item->b_unsaveable = true; item->b_unsaveable = true;
break; break;
case VLC_CONFIG_PERSISTENT:
item->b_autosave = true;
break;
case VLC_CONFIG_RESTART: case VLC_CONFIG_RESTART:
item->b_restart = true; item->b_restart = true;
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment