+gboolean
+tilda_controller_set_property_from_config (TildaController *self, const gchar *property)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_CONTROLLER(self));
+
+ GError *error = NULL;
+ gboolean ret;
+
+ GParamSpec *pspec;
+ GValue *value = g_malloc0(sizeof(GValue));
+ gboolean (*parse_func) (GKeyFile *keyfile, const gchar *group_name, const gchar *key, GValue *value, GError **error);
+
+ /* Get the pspec for this property */
+ pspec = g_object_class_find_property (G_OBJECT_GET_CLASS(self), property);
+
+ /* Make sure that this property exists */
+ if (pspec == NULL)
+ {
+ g_critical ("FIXME: developer error -- unable to find property: %s\n", property);
+ exit (1);
+ }
+
+ /* Initialize the GValue that is going to hold the returned value */
+ g_value_init (value, pspec->value_type);
+
+ /* Set the correct function to do the parsing */
+ if (g_type_is_a (pspec->value_type, G_TYPE_INT))
+ parse_func = tilda_config_parse_integer;
+ else if (g_type_is_a (pspec->value_type, G_TYPE_BOOLEAN))
+ parse_func = tilda_config_parse_boolean;
+ else if (g_type_is_a (pspec->value_type, G_TYPE_STRING))
+ parse_func = tilda_config_parse_string;
+ else if (g_type_is_a (pspec->value_type, G_TYPE_ENUM))
+ parse_func = tilda_config_parse_enum;
+ else
+ {
+ g_critical ("FIXME: developer error -- unknown property type: %s\n", g_type_name(pspec->value_type));
+ exit(1);
+ }
+
+ /* Do the [Controller] lookup */
+ ret = parse_func (config_userprefs, "Controller", property, value, &error);
+
+ if (error)
+ {
+ if (error->code == G_KEY_FILE_ERROR_INVALID_VALUE)
+ g_warning (error->message);
+
+ g_clear_error (&error);
+ }
+ else
+ goto success;
+
+ /* Do the [Global] lookup */
+ ret = parse_func (config_userprefs, "Global", property, value, &error);
+
+ if (error)
+ {
+ if (error->code == G_KEY_FILE_ERROR_INVALID_VALUE)
+ g_warning (error->message);
+
+ g_clear_error (&error);
+ }
+ else
+ goto success;
+
+ /* Do the [controller-defaults] lookup */
+ ret = parse_func (config_defaults, "controller-defaults", property, value, &error);
+
+ if (error)
+ {
+ if (error->code == G_KEY_FILE_ERROR_INVALID_VALUE)
+ g_warning (error->message);
+
+ g_clear_error (&error);
+
+ /* This is somewhat of a nasty hack, but I really do want to just set the property to
+ * NULL if there is no default, but ONLY for strings. */
+ if (parse_func == tilda_config_parse_string)
+ {
+ g_value_set_string (value, NULL);
+ goto success;
+ }
+ }
+ else
+ goto success;
+
+//failure:
+ g_critical (_("Unable to find a value for controller property: %s\n"), property);
+ return FALSE;
+
+success:
+ g_object_set_property (G_OBJECT(self), property, value);
+ g_value_unset (value);
+ g_free (value);
+ return TRUE;
+}
+