Only set config properties which are present in the config file
This commit is contained in:
parent
0bf27662c5
commit
2e5c5026bc
1 changed files with 12 additions and 18 deletions
|
@ -104,46 +104,40 @@ settings_new_from_file (const gchar* filename,
|
||||||
pspec = pspecs[i];
|
pspec = pspecs[i];
|
||||||
if (!(pspec->flags & G_PARAM_WRITABLE))
|
if (!(pspec->flags & G_PARAM_WRITABLE))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
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 (!g_key_file_has_key (key_file, "settings", property, NULL))
|
||||||
|
continue;
|
||||||
|
|
||||||
if (type == G_TYPE_PARAM_STRING)
|
if (type == G_TYPE_PARAM_STRING)
|
||||||
{
|
{
|
||||||
str = sokoke_key_file_get_string_default (key_file,
|
str = g_key_file_get_string (key_file, "settings", property, NULL);
|
||||||
"settings", property,
|
|
||||||
G_PARAM_SPEC_STRING (pspec)->default_value, NULL);
|
|
||||||
g_object_set (settings, property, str, NULL);
|
g_object_set (settings, property, str, NULL);
|
||||||
g_free (str);
|
g_free (str);
|
||||||
}
|
}
|
||||||
else if (type == G_TYPE_PARAM_INT)
|
else if (type == G_TYPE_PARAM_INT)
|
||||||
{
|
{
|
||||||
integer = sokoke_key_file_get_integer_default (key_file,
|
integer = g_key_file_get_integer (key_file, "settings", property, NULL);
|
||||||
"settings", property,
|
|
||||||
G_PARAM_SPEC_INT (pspec)->default_value, NULL);
|
|
||||||
g_object_set (settings, property, integer, NULL);
|
g_object_set (settings, property, integer, NULL);
|
||||||
}
|
}
|
||||||
else if (type == G_TYPE_PARAM_FLOAT)
|
else if (type == G_TYPE_PARAM_FLOAT)
|
||||||
{
|
{
|
||||||
number = sokoke_key_file_get_double_default (key_file,
|
number = g_key_file_get_double (key_file, "settings", property, NULL);
|
||||||
"settings", property,
|
|
||||||
G_PARAM_SPEC_FLOAT (pspec)->default_value, NULL);
|
|
||||||
g_object_set (settings, property, number, NULL);
|
g_object_set (settings, property, number, NULL);
|
||||||
}
|
}
|
||||||
else if (type == G_TYPE_PARAM_BOOLEAN)
|
else if (type == G_TYPE_PARAM_BOOLEAN)
|
||||||
{
|
{
|
||||||
boolean = sokoke_key_file_get_boolean_default (key_file,
|
boolean = g_key_file_get_boolean (key_file, "settings", property, NULL);
|
||||||
"settings", property,
|
|
||||||
G_PARAM_SPEC_BOOLEAN (pspec)->default_value, NULL);
|
|
||||||
g_object_set (settings, property, boolean, NULL);
|
g_object_set (settings, property, boolean, NULL);
|
||||||
}
|
}
|
||||||
else if (type == G_TYPE_PARAM_ENUM)
|
else if (type == G_TYPE_PARAM_ENUM)
|
||||||
{
|
{
|
||||||
GEnumClass* enum_class = G_ENUM_CLASS (
|
GEnumClass* enum_class = G_ENUM_CLASS (
|
||||||
g_type_class_ref (pspec->value_type));
|
g_type_class_peek (pspec->value_type));
|
||||||
GEnumValue* enum_value = g_enum_get_value (enum_class,
|
GEnumValue* enum_value;
|
||||||
G_PARAM_SPEC_ENUM (pspec)->default_value);
|
|
||||||
str = sokoke_key_file_get_string_default (key_file,
|
str = g_key_file_get_string (key_file, "settings", property, NULL);
|
||||||
"settings", property,
|
|
||||||
enum_value->value_name, NULL);
|
|
||||||
enum_value = g_enum_get_value_by_name (enum_class, str);
|
enum_value = g_enum_get_value_by_name (enum_class, str);
|
||||||
if (enum_value)
|
if (enum_value)
|
||||||
g_object_set (settings, property, enum_value->value, NULL);
|
g_object_set (settings, property, enum_value->value, NULL);
|
||||||
|
|
Loading…
Reference in a new issue