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
char *psz_longtext; /* Long comment on the configuration option */
module_value_t value; /* Option value */
module_value_t orig;
module_value_t saved;
module_value_t min;
module_value_t max;
......@@ -180,7 +179,6 @@ struct module_config_t
bool b_restart; /* Flag to indicate the option needs a restart */
/* to take effect */
/* 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_safe;
......
......@@ -72,8 +72,8 @@ enum vlc_module_properties
VLC_CONFIG_VOLATILE,
/* don't write variable to storage (args=none) */
VLC_CONFIG_PERSISTENT,
/* always write variable to storage (args=none) */
VLC_CONFIG_PERSISTENT_OBSOLETE,
/* unused (ignored) */
VLC_CONFIG_RESTART,
/* restart required to apply value change (args=none) */
......@@ -419,9 +419,6 @@ enum vlc_module_properties
#define change_need_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 */
#define change_private() \
vlc_config_set (p_config, VLC_CONFIG_PRIVATE);
......
......@@ -482,10 +482,8 @@ vlc_module_begin ()
set_subcategory( SUBCAT_INTERFACE_MAIN )
add_loadfile( "skins2-last", "", SKINS2_LAST, SKINS2_LAST_LONG,
true )
change_autosave ()
add_string( "skins2-config", "", SKINS2_CONFIG, SKINS2_CONFIG_LONG,
true )
change_autosave ()
change_private ()
#ifdef WIN32
add_bool( "skins2-systray", true, SKINS2_SYSTRAY,
......
......@@ -66,7 +66,6 @@ vlc_module_begin ()
add_string( "podcast-urls", NULL,
URLS_TEXT, URLS_LONGTEXT, false )
change_autosave ()
set_capability( "services_discovery", 0 )
set_callbacks( Open, Close )
......
......@@ -473,7 +473,6 @@ void config_Free( module_t *p_module )
{
free (p_item->value.psz);
free (p_item->orig.psz);
free (p_item->saved.psz);
}
if( p_item->ppsz_list )
......
......@@ -228,7 +228,7 @@ int config_LoadConfigFile( vlc_object_t *p_this )
msg_Warn (p_this, "Integer value (%s) for %s: %m",
psz_option_value, psz_option_name);
else
item->saved.i = item->value.i = l;
item->value.i = l;
break;
}
......@@ -236,14 +236,11 @@ int config_LoadConfigFile( vlc_object_t *p_this )
if (!*psz_option_value)
break; /* ignore empty option */
item->value.f = (float)atof (psz_option_value);
item->saved.f = item->value.f;
break;
default:
free ((char *)item->value.psz);
free ((char *)item->saved.psz);
item->value.psz = convert (psz_option_value);
item->saved.psz = strdupnull (item->value.psz);
break;
}
}
......@@ -357,7 +354,7 @@ static int config_PrepareDir (vlc_object_t *obj)
* save.
* 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;
char *permanent = NULL, *temporary = NULL;
......@@ -520,65 +517,36 @@ static int SaveConfigFile( vlc_object_t *p_this, bool b_autosave )
|| p_item->b_unsaveable) /* ignore volatile option */
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))
{
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,
(p_item->i_type == CONFIG_ITEM_BOOL)
? N_("boolean") : N_("integer"),
val == p_item->orig.i,
p_item->psz_name, "%"PRId64, val);
p_item->saved.i = val;
}
else
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"),
val == p_item->orig.f,
p_item->psz_name, "%f", val);
p_item->saved.f = val;
}
else
{
const char *psz_value = b_retain ? p_item->saved.psz
: p_item->value.psz;
const char *psz_value = p_item->value.psz;
bool modified;
assert (IsConfigStringType (p_item->i_type));
if (b_retain && (psz_value == NULL)) /* FIXME: hack */
psz_value = 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);
modified = !!strcmp (psz_value ? psz_value : "",
p_item->orig.psz ? p_item->orig.psz : "");
config_Write (file, p_item->psz_text, N_("string"),
!modified, p_item->psz_name, "%s",
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;
}
}
if (!b_retain)
p_item->b_dirty = false;
}
}
......@@ -666,13 +634,13 @@ int config_AutoSaveConfigFile( vlc_object_t *p_this )
p_item < p_end && !save;
p_item++ )
{
save = p_item->b_autosave && p_item->b_dirty;
save = p_item->b_dirty;
}
}
if (save)
/* Note: this will get the read lock recursively. Ok. */
ret = SaveConfigFile (p_this, true);
ret = SaveConfigFile (p_this);
vlc_rwlock_unlock (&config_lock);
module_list_free (list);
......@@ -682,5 +650,5 @@ int config_AutoSaveConfigFile( vlc_object_t *p_this )
#undef config_SaveConfigFile
int config_SaveConfigFile( vlc_object_t *p_this )
{
return SaveConfigFile( p_this, false );
return SaveConfigFile (p_this);
}
......@@ -2710,34 +2710,24 @@ vlc_module_begin ()
add_string( "bookmark1", NULL,
BOOKMARK1_TEXT, BOOKMARK_LONGTEXT, false )
change_autosave()
add_string( "bookmark2", NULL,
BOOKMARK2_TEXT, BOOKMARK_LONGTEXT, false )
change_autosave()
add_string( "bookmark3", NULL,
BOOKMARK3_TEXT, BOOKMARK_LONGTEXT, false )
change_autosave()
add_string( "bookmark4", NULL,
BOOKMARK4_TEXT, BOOKMARK_LONGTEXT, false )
change_autosave()
add_string( "bookmark5", NULL,
BOOKMARK5_TEXT, BOOKMARK_LONGTEXT, false )
change_autosave()
add_string( "bookmark6", NULL,
BOOKMARK6_TEXT, BOOKMARK_LONGTEXT, false )
change_autosave()
add_string( "bookmark7", NULL,
BOOKMARK7_TEXT, BOOKMARK_LONGTEXT, false )
change_autosave()
add_string( "bookmark8", NULL,
BOOKMARK8_TEXT, BOOKMARK_LONGTEXT, false )
change_autosave()
add_string( "bookmark9", NULL,
BOOKMARK9_TEXT, BOOKMARK_LONGTEXT, false )
change_autosave()
add_string( "bookmark10", NULL,
BOOKMARK10_TEXT, BOOKMARK_LONGTEXT, false )
change_autosave()
#define HELP_TEXT \
N_("print help for VLC (can be combined with --advanced and " \
......
......@@ -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].orig.psz != NULL)
? strdup (p_module->p_config[i].orig.psz) : NULL;
p_module->p_config[i].saved.psz = NULL;
}
else
{
memcpy (&p_module->p_config[i].value, &p_module->p_config[i].orig,
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;
......
......@@ -267,13 +267,13 @@ int vlc_plugin_set (module_t *module, module_config_t *item, int propid, ...)
{
if (IsConfigIntegerType (item->i_type))
{
item->orig.i = item->saved.i =
item->orig.i =
item->value.i = va_arg (ap, int64_t);
}
else
if (IsConfigFloatType (item->i_type))
{
item->orig.f = item->saved.f =
item->orig.f =
item->value.f = va_arg (ap, double);
}
else
......@@ -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 *);
item->value.psz = value ? strdup (value) : NULL;
item->orig.psz = value ? strdup (value) : NULL;
item->saved.psz = value ? strdup (value) : NULL;
}
break;
}
......@@ -313,10 +312,6 @@ int vlc_plugin_set (module_t *module, module_config_t *item, int propid, ...)
item->b_unsaveable = true;
break;
case VLC_CONFIG_PERSISTENT:
item->b_autosave = true;
break;
case VLC_CONFIG_RESTART:
item->b_restart = true;
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