Only write settings with values that differ from the defaults
This commit is contained in:
parent
e8d700be44
commit
0542a0fcf2
1 changed files with 18 additions and 13 deletions
|
@ -204,36 +204,39 @@ settings_save_to_file (MidoriWebSettings* settings,
|
||||||
type = G_PARAM_SPEC_TYPE (pspec);
|
type = G_PARAM_SPEC_TYPE (pspec);
|
||||||
property = g_param_spec_get_name (pspec);
|
property = g_param_spec_get_name (pspec);
|
||||||
if (!(pspec->flags & G_PARAM_WRITABLE))
|
if (!(pspec->flags & G_PARAM_WRITABLE))
|
||||||
{
|
|
||||||
gchar* prop_comment = g_strdup_printf ("# %s", property);
|
|
||||||
g_key_file_set_string (key_file, "settings", prop_comment, "");
|
|
||||||
g_free (prop_comment);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
if (type == G_TYPE_PARAM_STRING)
|
if (type == G_TYPE_PARAM_STRING)
|
||||||
{
|
{
|
||||||
gchar* string;
|
gchar* string;
|
||||||
|
const gchar* def_string = G_PARAM_SPEC_STRING (pspec)->default_value;
|
||||||
g_object_get (settings, property, &string, NULL);
|
g_object_get (settings, property, &string, NULL);
|
||||||
g_key_file_set_string (key_file, "settings", property,
|
if (!string)
|
||||||
string ? string : "");
|
string = g_strdup ("");
|
||||||
|
if (!def_string)
|
||||||
|
def_string = "";
|
||||||
|
if (strcmp (string, def_string))
|
||||||
|
g_key_file_set_string (key_file, "settings", property, string);
|
||||||
g_free (string);
|
g_free (string);
|
||||||
}
|
}
|
||||||
else if (type == G_TYPE_PARAM_INT)
|
else if (type == G_TYPE_PARAM_INT)
|
||||||
{
|
{
|
||||||
gint integer;
|
gint integer;
|
||||||
g_object_get (settings, property, &integer, NULL);
|
g_object_get (settings, property, &integer, NULL);
|
||||||
|
if (integer != G_PARAM_SPEC_INT (pspec)->default_value)
|
||||||
g_key_file_set_integer (key_file, "settings", property, integer);
|
g_key_file_set_integer (key_file, "settings", property, integer);
|
||||||
}
|
}
|
||||||
else if (type == G_TYPE_PARAM_FLOAT)
|
else if (type == G_TYPE_PARAM_FLOAT)
|
||||||
{
|
{
|
||||||
gfloat number;
|
gfloat number;
|
||||||
g_object_get (settings, property, &number, NULL);
|
g_object_get (settings, property, &number, NULL);
|
||||||
|
if (number != G_PARAM_SPEC_FLOAT (pspec)->default_value)
|
||||||
g_key_file_set_double (key_file, "settings", property, number);
|
g_key_file_set_double (key_file, "settings", property, number);
|
||||||
}
|
}
|
||||||
else if (type == G_TYPE_PARAM_BOOLEAN)
|
else if (type == G_TYPE_PARAM_BOOLEAN)
|
||||||
{
|
{
|
||||||
gboolean truth;
|
gboolean truth;
|
||||||
g_object_get (settings, property, &truth, NULL);
|
g_object_get (settings, property, &truth, NULL);
|
||||||
|
if (truth != G_PARAM_SPEC_BOOLEAN (pspec)->default_value)
|
||||||
g_key_file_set_boolean (key_file, "settings", property, truth);
|
g_key_file_set_boolean (key_file, "settings", property, truth);
|
||||||
}
|
}
|
||||||
else if (type == G_TYPE_PARAM_ENUM)
|
else if (type == G_TYPE_PARAM_ENUM)
|
||||||
|
@ -241,8 +244,10 @@ settings_save_to_file (MidoriWebSettings* settings,
|
||||||
GEnumClass* enum_class = G_ENUM_CLASS (
|
GEnumClass* enum_class = G_ENUM_CLASS (
|
||||||
g_type_class_ref (pspec->value_type));
|
g_type_class_ref (pspec->value_type));
|
||||||
gint integer;
|
gint integer;
|
||||||
|
GEnumValue* enum_value;
|
||||||
g_object_get (settings, property, &integer, NULL);
|
g_object_get (settings, property, &integer, NULL);
|
||||||
GEnumValue* enum_value = g_enum_get_value (enum_class, integer);
|
enum_value = g_enum_get_value (enum_class, integer);
|
||||||
|
if (integer != G_PARAM_SPEC_ENUM (pspec)->default_value)
|
||||||
g_key_file_set_string (key_file, "settings", property,
|
g_key_file_set_string (key_file, "settings", property,
|
||||||
enum_value->value_name);
|
enum_value->value_name);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue