/** * gimp_config_is_equal_to: * @a: a #GObject that implements the #GimpConfigInterface. * @b: another #GObject of the same type as @a. * * Compares the two objects. The default implementation of the * #GimpConfigInterface compares the object properties and thus only * works for objects that are completely defined by their * properties. * * Return value: %TRUE if the two objects are equal. * * Since: 2.4 **/ gboolean gimp_config_is_equal_to (GimpConfig *a, GimpConfig *b) { g_return_val_if_fail (GIMP_IS_CONFIG (a), FALSE); g_return_val_if_fail (GIMP_IS_CONFIG (b), FALSE); g_return_val_if_fail (G_TYPE_FROM_INSTANCE (a) == G_TYPE_FROM_INSTANCE (b), FALSE); return GIMP_CONFIG_GET_INTERFACE (a)->equal (a, b); }
/** * gimp_config_deserialize_string: * @config: a #GObject that implements the #GimpConfigInterface. * @text: string to deserialize (in UTF-8 encoding) * @text_len: length of @text in bytes or -1 * @data: client data * @error: return location for a possible error * * Configures @config from @text. Basically this function creates a * properly configured #GScanner for you and calls the deserialize * function of the @config's #GimpConfigInterface. * * Returns: %TRUE if deserialization succeeded, %FALSE otherwise. * * Since: 2.4 **/ gboolean gimp_config_deserialize_string (GimpConfig *config, const gchar *text, gint text_len, gpointer data, GError **error) { GScanner *scanner; gboolean success; g_return_val_if_fail (GIMP_IS_CONFIG (config), FALSE); g_return_val_if_fail (text != NULL || text_len == 0, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); scanner = gimp_scanner_new_string (text, text_len, error); g_object_freeze_notify (G_OBJECT (config)); success = GIMP_CONFIG_GET_INTERFACE (config)->deserialize (config, scanner, 0, data); g_object_thaw_notify (G_OBJECT (config)); gimp_scanner_destroy (scanner); if (! success) g_assert (error == NULL || *error != NULL); return success; }
/** * gimp_config_deserialize_stream: * @config: a #GObject that implements the #GimpConfigInterface. * @input: the #GInputStream to read configuration from. * @data: user data passed to the deserialize implementation. * @error: return location for a possible error * * Reads configuration data from @input and configures @config * accordingly. Basically this function creates a properly configured * #GScanner for you and calls the deserialize function of the * @config's #GimpConfigInterface. * * Return value: %TRUE if deserialization succeeded, %FALSE otherwise. * * Since: 2.10 **/ gboolean gimp_config_deserialize_stream (GimpConfig *config, GInputStream *input, gpointer data, GError **error) { GScanner *scanner; gboolean success; g_return_val_if_fail (GIMP_IS_CONFIG (config), FALSE); g_return_val_if_fail (G_IS_INPUT_STREAM (input), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); scanner = gimp_scanner_new_stream (input, error); if (! scanner) return FALSE; g_object_freeze_notify (G_OBJECT (config)); success = GIMP_CONFIG_GET_INTERFACE (config)->deserialize (config, scanner, 0, data); g_object_thaw_notify (G_OBJECT (config)); gimp_scanner_destroy (scanner); if (! success) g_assert (error == NULL || *error != NULL); return success; }
/** * gimp_config_duplicate: * @config: a #GObject that implements the #GimpConfigInterface. * * Creates a copy of the passed object by copying all object * properties. The default implementation of the #GimpConfigInterface * only works for objects that are completely defined by their * properties. * * Return value: the duplicated #GimpConfig object * * Since: 2.4 **/ gpointer gimp_config_duplicate (GimpConfig *config) { g_return_val_if_fail (GIMP_IS_CONFIG (config), NULL); return GIMP_CONFIG_GET_INTERFACE (config)->duplicate (config); }
/** * gimp_config_reset: * @config: a #GObject that implements the #GimpConfigInterface. * * Resets the object to its default state. The default implementation of the * #GimpConfigInterface only works for objects that are completely defined by * their properties. * * Since: GIMP 2.4 **/ void gimp_config_reset (GimpConfig *config) { g_return_if_fail (GIMP_IS_CONFIG (config)); GIMP_CONFIG_GET_INTERFACE (config)->reset (config); }
/** * gimp_config_deserialize: * @config: a #GObject that implements the #GimpConfigInterface. * @filename: the name of the file to read configuration from. * @data: user data passed to the deserialize implementation. * @error: * * Opens the file specified by @filename, reads configuration data * from it and configures @config accordingly. Basically this function * creates a properly configured #GScanner for you and calls the * deserialize function of the @config's #GimpConfigInterface. * * Return value: %TRUE if deserialization succeeded, %FALSE otherwise. * * Since: GIMP 2.4 **/ gboolean gimp_config_deserialize_file (GimpConfig *config, const gchar *filename, gpointer data, GError **error) { GScanner *scanner; gboolean success; g_return_val_if_fail (GIMP_IS_CONFIG (config), FALSE); g_return_val_if_fail (filename != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); scanner = gimp_scanner_new_file (filename, error); if (! scanner) return FALSE; success = GIMP_CONFIG_GET_INTERFACE (config)->deserialize (config, scanner, 0, data); gimp_scanner_destroy (scanner); if (! success) g_assert (error == NULL || *error != NULL); return success; }
void gimp_image_map_tool_edit_as (GimpImageMapTool *im_tool, const gchar *new_tool_id, GimpConfig *config) { GimpDisplay *display; GimpContext *user_context; GimpToolInfo *tool_info; GimpTool *new_tool; g_return_if_fail (GIMP_IS_IMAGE_MAP_TOOL (im_tool)); g_return_if_fail (new_tool_id); g_return_if_fail (GIMP_IS_CONFIG (config)); display = GIMP_TOOL (im_tool)->display; user_context = gimp_get_user_context (display->gimp); tool_info = (GimpToolInfo *) gimp_container_get_child_by_name (display->gimp->tool_info_list, new_tool_id); gimp_context_set_tool (user_context, tool_info); tool_manager_initialize_active (display->gimp, display); new_tool = tool_manager_get_active (display->gimp); GIMP_IMAGE_MAP_TOOL (new_tool)->default_config = g_object_ref (config); gimp_image_map_tool_reset (GIMP_IMAGE_MAP_TOOL (new_tool)); }
/** * gimp_config_reset: * @config: a #GObject that implements the #GimpConfigInterface. * * Resets the object to its default state. The default implementation of the * #GimpConfigInterface only works for objects that are completely defined by * their properties. * * Since: 2.4 **/ void gimp_config_reset (GimpConfig *config) { g_return_if_fail (GIMP_IS_CONFIG (config)); g_object_freeze_notify (G_OBJECT (config)); GIMP_CONFIG_GET_INTERFACE (config)->reset (config); g_object_thaw_notify (G_OBJECT (config)); }
/** * gimp_config_copy: * @src: a #GObject that implements the #GimpConfigInterface. * @dest: another #GObject of the same type as @a. * @flags: a mask of GParamFlags * * Compares all read- and write-able properties from @src and @dest * that have all @flags set. Differing values are then copied from * @src to @dest. If @flags is 0, all differing read/write properties. * * Properties marked as "construct-only" are not touched. * * Return value: %TRUE if @dest was modified, %FALSE otherwise * * Since: 2.6 **/ gboolean gimp_config_copy (GimpConfig *src, GimpConfig *dest, GParamFlags flags) { gboolean changed; g_return_val_if_fail (GIMP_IS_CONFIG (src), FALSE); g_return_val_if_fail (GIMP_IS_CONFIG (dest), FALSE); g_return_val_if_fail (G_TYPE_FROM_INSTANCE (src) == G_TYPE_FROM_INSTANCE (dest), FALSE); g_object_freeze_notify (G_OBJECT (dest)); changed = GIMP_CONFIG_GET_INTERFACE (src)->copy (src, dest, flags); g_object_thaw_notify (G_OBJECT (dest)); return changed; }
/** * gimp_config_serialize: * @config: a #GObject that implements the #GimpConfigInterface. * @writer: the #GimpConfigWriter to use. * @data: client data * * Serialize the #GimpConfig object. * * Returns: %TRUE if serialization succeeded, %FALSE otherwise. * * Since: 2.8 **/ gboolean gimp_config_serialize (GimpConfig *config, GimpConfigWriter *writer, gpointer data) { g_return_val_if_fail (GIMP_IS_CONFIG (config), FALSE); return GIMP_CONFIG_GET_INTERFACE (config)->serialize (config, writer, data); }
/** * gimp_config_deserialize: * @config: a #GObject that implements the #GimpConfigInterface. * @scanner: the #GScanner to use. * @nest_level: the nest level. * @data: client data. * * Deserialize the #GimpConfig object. * * Returns: %TRUE if deserialization succeeded, %FALSE otherwise. * * Since: 2.8 **/ gboolean gimp_config_deserialize (GimpConfig *config, GScanner *scanner, gint nest_level, gpointer data) { g_return_val_if_fail (GIMP_IS_CONFIG (config), FALSE); return GIMP_CONFIG_GET_INTERFACE (config)->deserialize (config, scanner, nest_level, data); }
/** * gimp_config_serialize_to_fd: * @config: a #GObject that implements the #GimpConfigInterface. * @fd: a file descriptor, opened for writing * @data: user data passed to the serialize implementation. * * Serializes the object properties of @config to the given file * descriptor. * * Return value: %TRUE if serialization succeeded, %FALSE otherwise. * * Since: 2.4 **/ gboolean gimp_config_serialize_to_fd (GimpConfig *config, gint fd, gpointer data) { GimpConfigWriter *writer; g_return_val_if_fail (GIMP_IS_CONFIG (config), FALSE); g_return_val_if_fail (fd > 0, FALSE); writer = gimp_config_writer_new_fd (fd); if (!writer) return FALSE; GIMP_CONFIG_GET_INTERFACE (config)->serialize (config, writer, data); return gimp_config_writer_finish (writer, NULL, NULL); }
/** * gimp_config_serialize_to_string: * @config: a #GObject that implements the #GimpConfigInterface. * @data: user data passed to the serialize implementation. * * Serializes the object properties of @config to a string. * * Return value: a newly allocated NUL-terminated string. * * Since: 2.4 **/ gchar * gimp_config_serialize_to_string (GimpConfig *config, gpointer data) { GimpConfigWriter *writer; GString *str; g_return_val_if_fail (GIMP_IS_CONFIG (config), NULL); str = g_string_new (NULL); writer = gimp_config_writer_new_string (str); GIMP_CONFIG_GET_INTERFACE (config)->serialize (config, writer, data); gimp_config_writer_finish (writer, NULL, NULL); return g_string_free (str, FALSE); }
/** * gimp_rc_foreach_unknown_token: * @config: a #GObject. * @func: a function to call for each key/value pair. * @user_data: data to pass to @func. * * Calls @func for each key/value stored with the @config using * gimp_rc_add_unknown_token(). **/ void gimp_rc_foreach_unknown_token (GimpConfig *config, GimpConfigForeachFunc func, gpointer user_data) { GSList *unknown_tokens; GSList *list; g_return_if_fail (GIMP_IS_CONFIG (config)); g_return_if_fail (func != NULL); unknown_tokens = g_object_get_data (G_OBJECT (config), GIMP_RC_UNKNOWN_TOKENS); for (list = unknown_tokens; list; list = g_slist_next (list)) { GimpConfigToken *token = list->data; func (token->key, token->value, user_data); } }
/** * gimp_config_serialize_to_gfile: * @config: a #GObject that implements the #GimpConfigInterface. * @file: the #GFile to write the configuration to. * @header: optional file header (must be ASCII only) * @footer: optional file footer (must be ASCII only) * @data: user data passed to the serialize implementation. * @error: return location for a possible error * * Serializes the object properties of @config to the file specified * by @file. If a file with that name already exists, it is * overwritten. Basically this function opens @file for you and calls * the serialize function of the @config's #GimpConfigInterface. * * Return value: %TRUE if serialization succeeded, %FALSE otherwise. * * Since: 2.10 **/ gboolean gimp_config_serialize_to_gfile (GimpConfig *config, GFile *file, const gchar *header, const gchar *footer, gpointer data, GError **error) { GimpConfigWriter *writer; g_return_val_if_fail (GIMP_IS_CONFIG (config), FALSE); g_return_val_if_fail (G_IS_FILE (file), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); writer = gimp_config_writer_new_gfile (file, TRUE, header, error); if (!writer) return FALSE; GIMP_CONFIG_GET_INTERFACE (config)->serialize (config, writer, data); return gimp_config_writer_finish (writer, footer, error); }
/** * gimp_config_serialize_to_stream: * @config: a #GObject that implements the #GimpConfigInterface. * @output: the #GOutputStream to write the configuration to. * @header: optional file header (must be ASCII only) * @footer: optional file footer (must be ASCII only) * @data: user data passed to the serialize implementation. * @error: return location for a possible error * * Serializes the object properties of @config to the stream specified * by @output. * * Return value: %TRUE if serialization succeeded, %FALSE otherwise. * * Since: 2.10 **/ gboolean gimp_config_serialize_to_stream (GimpConfig *config, GOutputStream *output, const gchar *header, const gchar *footer, gpointer data, GError **error) { GimpConfigWriter *writer; g_return_val_if_fail (GIMP_IS_CONFIG (config), FALSE); g_return_val_if_fail (G_IS_OUTPUT_STREAM (output), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); writer = gimp_config_writer_new_stream (output, header, error); if (!writer) return FALSE; GIMP_CONFIG_GET_INTERFACE (config)->serialize (config, writer, data); return gimp_config_writer_finish (writer, footer, error); }
/** * gimp_rc_lookup_unknown_token: * @config: a #GObject. * @key: a nul-terminated string to identify the value. * * This function retrieves data that was previously attached using * gimp_rc_add_unknown_token(). You should not free or modify * the returned string. * * Returns: a pointer to a constant string. **/ const gchar * gimp_rc_lookup_unknown_token (GimpConfig *config, const gchar *key) { GSList *unknown_tokens; GSList *list; g_return_val_if_fail (GIMP_IS_CONFIG (config), NULL); g_return_val_if_fail (key != NULL, NULL); unknown_tokens = g_object_get_data (G_OBJECT (config), GIMP_RC_UNKNOWN_TOKENS); for (list = unknown_tokens; list; list = g_slist_next (list)) { GimpConfigToken *token = list->data; if (strcmp (token->key, key) == 0) return token->value; } return NULL; }
/** * gimp_rc_add_unknown_token: * @config: a #GObject. * @key: a nul-terminated string to identify the value. * @value: a nul-terminated string representing the value. * * This function adds arbitrary key/value pairs to a GObject. It's * purpose is to attach additional data to a #GimpConfig object that * can be stored along with the object properties when serializing the * object to a configuration file. Please note however that the * default gimp_config_serialize() implementation does not serialize * unknown tokens. * * If you want to remove a key/value pair from the object, call this * function with a %NULL @value. **/ void gimp_rc_add_unknown_token (GimpConfig *config, const gchar *key, const gchar *value) { GimpConfigToken *token; GSList *unknown_tokens; GSList *last; GSList *list; g_return_if_fail (GIMP_IS_CONFIG (config)); g_return_if_fail (key != NULL); unknown_tokens = (GSList *) g_object_get_data (G_OBJECT (config), GIMP_RC_UNKNOWN_TOKENS); for (last = NULL, list = unknown_tokens; list; last = list, list = g_slist_next (list)) { token = (GimpConfigToken *) list->data; if (strcmp (token->key, key) == 0) { g_free (token->value); if (value) { token->value = g_strdup (value); } else { g_free (token->key); unknown_tokens = g_slist_remove (unknown_tokens, token); g_object_set_data_full (G_OBJECT (config), GIMP_RC_UNKNOWN_TOKENS, unknown_tokens, (GDestroyNotify) gimp_rc_destroy_unknown_tokens); } return; } } if (!value) return; token = g_slice_new (GimpConfigToken); token->key = g_strdup (key); token->value = g_strdup (value); if (last) { last = g_slist_last (g_slist_append (last, token)); } else { unknown_tokens = g_slist_append (NULL, token); g_object_set_data_full (G_OBJECT (config), GIMP_RC_UNKNOWN_TOKENS, unknown_tokens, (GDestroyNotify) gimp_rc_destroy_unknown_tokens); } }
/** * gimp_config_deserialize_properties: * @config: a #GimpConfig. * @scanner: a #GScanner. * @nest_level: the nest level * * This function uses the @scanner to configure the properties of @config. * * Return value: %TRUE on success, %FALSE otherwise. * * Since: GIMP 2.4 **/ gboolean gimp_config_deserialize_properties (GimpConfig *config, GScanner *scanner, gint nest_level) { GObjectClass *klass; GParamSpec **property_specs; guint n_property_specs; guint i; guint scope_id; guint old_scope_id; GTokenType token; GTokenType next; g_return_val_if_fail (GIMP_IS_CONFIG (config), FALSE); klass = G_OBJECT_GET_CLASS (config); property_specs = g_object_class_list_properties (klass, &n_property_specs); if (! property_specs) return TRUE; scope_id = g_type_qname (G_TYPE_FROM_INSTANCE (config)); old_scope_id = g_scanner_set_scope (scanner, scope_id); for (i = 0; i < n_property_specs; i++) { GParamSpec *prop_spec = property_specs[i]; if (prop_spec->flags & GIMP_CONFIG_PARAM_SERIALIZE) { g_scanner_scope_add_symbol (scanner, scope_id, prop_spec->name, prop_spec); } } g_free (property_specs); g_object_freeze_notify (G_OBJECT (config)); token = G_TOKEN_LEFT_PAREN; while (TRUE) { next = g_scanner_peek_next_token (scanner); if (G_UNLIKELY (next != token && ! (token == G_TOKEN_SYMBOL && next == G_TOKEN_IDENTIFIER))) { break; } token = g_scanner_get_next_token (scanner); switch (token) { case G_TOKEN_LEFT_PAREN: token = G_TOKEN_SYMBOL; break; case G_TOKEN_IDENTIFIER: token = gimp_config_skip_unknown_property (scanner); break; case G_TOKEN_SYMBOL: token = gimp_config_deserialize_property (config, scanner, nest_level); break; case G_TOKEN_RIGHT_PAREN: token = G_TOKEN_LEFT_PAREN; break; default: /* do nothing */ break; } } g_scanner_set_scope (scanner, old_scope_id); g_object_thaw_notify (G_OBJECT (config)); if (token == G_TOKEN_NONE) return FALSE; return gimp_config_deserialize_return (scanner, token, nest_level); }