/** * 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_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_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_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_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; }
/** * 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_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_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)); }
static GTokenType gimp_config_deserialize_object (GValue *value, GimpConfig *config, GParamSpec *prop_spec, GScanner *scanner, gint nest_level) { GimpConfigInterface *config_iface; GimpConfig *prop_object; g_object_get_property (G_OBJECT (config), prop_spec->name, value); prop_object = g_value_get_object (value); if (! prop_object) { /* if the object property is not GIMP_CONFIG_PARAM_AGGREGATE, read * the type of the object and create it */ if (! (prop_spec->flags & GIMP_CONFIG_PARAM_AGGREGATE)) { gchar *type_name; GType type; if (! gimp_scanner_parse_string (scanner, &type_name)) return G_TOKEN_STRING; type = g_type_from_name (type_name); g_free (type_name); if (! g_type_is_a (type, prop_spec->value_type)) return G_TOKEN_STRING; prop_object = g_object_new (type, NULL); g_value_take_object (value, prop_object); } else { return G_TOKEN_RIGHT_PAREN; } } config_iface = GIMP_CONFIG_GET_INTERFACE (prop_object); if (! config_iface) return gimp_config_deserialize_any (value, prop_spec, scanner); if (! config_iface->deserialize (prop_object, scanner, nest_level + 1, NULL)) return G_TOKEN_NONE; return G_TOKEN_RIGHT_PAREN; }
/** * 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_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; }
static void gimp_dialog_factories_save_foreach (gconstpointer key, GimpDialogFactory *factory, GimpConfigWriter *writer) { GList *infos; for (infos = factory->session_infos; infos; infos = g_list_next (infos)) { GimpSessionInfo *info = infos->data; /* we keep session info entries for all toplevel dialogs created * by the factory but don't save them if they don't want to be * managed */ if (info->dockable_entry || (info->toplevel_entry && ! info->toplevel_entry->session_managed)) continue; if (info->widget) gimp_session_info_get_info (info); gimp_config_writer_open (writer, "session-info"); gimp_config_writer_string (writer, gimp_object_get_name (GIMP_OBJECT (factory))); gimp_config_writer_string (writer, info->toplevel_entry ? info->toplevel_entry->identifier : "dock"); GIMP_CONFIG_GET_INTERFACE (info)->serialize (GIMP_CONFIG (info), writer, NULL); gimp_config_writer_close (writer); if (info->widget) gimp_session_info_clear_info (info); } }
/** * 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_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); }
static gboolean gimp_tool_preset_deserialize_property (GimpConfig *config, guint property_id, GValue *value, GParamSpec *pspec, GScanner *scanner, GTokenType *expected) { GimpToolPreset *tool_preset = GIMP_TOOL_PRESET (config); switch (property_id) { case PROP_TOOL_OPTIONS: { GObject *options; gchar *type_name; GType type; GimpContextPropMask serialize_props; if (! gimp_scanner_parse_string (scanner, &type_name)) { *expected = G_TOKEN_STRING; break; } type = g_type_from_name (type_name); if (! type) { g_scanner_error (scanner, "unable to determine type of '%s'", type_name); *expected = G_TOKEN_STRING; g_free (type_name); break; } if (! g_type_is_a (type, GIMP_TYPE_TOOL_OPTIONS)) { g_scanner_error (scanner, "'%s' is not a subclass of GimpToolOptions", type_name); *expected = G_TOKEN_STRING; g_free (type_name); break; } g_free (type_name); options = g_object_new (type, "gimp", tool_preset->gimp, NULL); /* Initialize all GimpContext object properties that can be * used by presets with some non-NULL object, so loading a * broken preset won't leave us with NULL objects that have * bad effects. See bug #742159. */ gimp_context_copy_properties (gimp_get_user_context (tool_preset->gimp), GIMP_CONTEXT (options), GIMP_CONTEXT_BRUSH_MASK | GIMP_CONTEXT_DYNAMICS_MASK | GIMP_CONTEXT_PATTERN_MASK | GIMP_CONTEXT_GRADIENT_MASK | GIMP_CONTEXT_PALETTE_MASK | GIMP_CONTEXT_FONT_MASK); if (! GIMP_CONFIG_GET_INTERFACE (options)->deserialize (GIMP_CONFIG (options), scanner, 1, NULL)) { g_object_unref (options); break; } /* we need both tool and tool-info on the options */ if (gimp_context_get_tool (GIMP_CONTEXT (options))) { g_object_set (options, "tool-info", gimp_context_get_tool (GIMP_CONTEXT (options)), NULL); } else if (GIMP_TOOL_OPTIONS (options)->tool_info) { g_object_set (options, "tool", GIMP_TOOL_OPTIONS (options)->tool_info, NULL); } else { /* if we have none, the options set_property() logic will * replace the NULL with its best guess */ g_object_set (options, "tool", NULL, "tool-info", NULL, NULL); } serialize_props = gimp_context_get_serialize_properties (GIMP_CONTEXT (options)); gimp_context_set_serialize_properties (GIMP_CONTEXT (options), serialize_props | GIMP_CONTEXT_TOOL_MASK); g_value_take_object (value, options); } break; default: return FALSE; } return TRUE; }