void session_save (Gimp *gimp, gboolean always_save) { GimpConfigWriter *writer; gchar *filename; GError *error = NULL; g_return_if_fail (GIMP_IS_GIMP (gimp)); if (sessionrc_deleted && ! always_save) return; filename = session_filename (gimp); if (gimp->be_verbose) g_print ("Writing '%s'\n", gimp_filename_to_utf8 (filename)); writer = gimp_config_writer_new_file (filename, TRUE, "GIMP sessionrc\n\n" "This file takes session-specific info " "(that is info, you want to keep between " "two GIMP sessions). You are not supposed " "to edit it manually, but of course you " "can do. The sessionrc will be entirely " "rewritten every time you quit GIMP. " "If this file isn't found, defaults are " "used.", NULL); g_free (filename); if (!writer) return; gimp_dialog_factories_session_save (writer); gimp_config_writer_linefeed (writer); /* save last tip shown */ gimp_config_writer_open (writer, "last-tip-shown"); gimp_config_writer_printf (writer, "%d", GIMP_GUI_CONFIG (gimp->config)->last_tip + 1); gimp_config_writer_close (writer); if (! gimp_config_writer_finish (writer, "end of sessionrc", &error)) { gimp_message (gimp, NULL, GIMP_MESSAGE_ERROR, "%s", error->message); g_clear_error (&error); } sessionrc_deleted = FALSE; }
void gimp_modules_unload (Gimp *gimp) { g_return_if_fail (GIMP_IS_GIMP (gimp)); if (! gimp->no_interface && gimp->write_modulerc) { GimpConfigWriter *writer; GString *str; gchar *p; gchar *filename; GError *error = NULL; str = g_string_new (NULL); g_list_foreach (gimp->module_db->modules, add_to_inhibit_string, str); if (str->len > 0) p = str->str + 1; else p = ""; filename = gimp_personal_rc_file ("modulerc"); if (gimp->be_verbose) g_print ("Writing '%s'\n", gimp_filename_to_utf8 (filename)); writer = gimp_config_writer_new_file (filename, TRUE, "GIMP modulerc", &error); g_free (filename); if (writer) { gimp_config_writer_open (writer, "module-load-inhibit"); gimp_config_writer_printf (writer, "\"%s\"", p); gimp_config_writer_close (writer); gimp_config_writer_finish (writer, "end of modulerc", &error); gimp->write_modulerc = FALSE; } g_string_free (str, TRUE); if (error) { gimp_message (gimp, NULL, GIMP_MESSAGE_ERROR, "%s", error->message); g_clear_error (&error); } } }
/** * gimp_config_serialize_to_file: * @config: a #GObject that implements the #GimpConfigInterface. * @filename: the name of the file 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 @filename. If a file with that name already exists, it is * overwritten. Basically this function opens @filename for you and * calls the serialize function of the @config's #GimpConfigInterface. * * Return value: %TRUE if serialization succeeded, %FALSE otherwise. * * Since: 2.4 **/ gboolean gimp_config_serialize_to_file (GimpConfig *config, const gchar *filename, 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 (filename != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); writer = gimp_config_writer_new_file (filename, 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_color_profile_store_save (GimpColorProfileStore *store, const gchar *filename, GError **error) { GimpConfigWriter *writer; GtkTreeModel *model; GtkTreeIter iter; gchar *labels[HISTORY_SIZE] = { NULL, }; GFile *files[HISTORY_SIZE] = { NULL, }; gboolean iter_valid; gint i; writer = gimp_config_writer_new_file (filename, TRUE, "GIMP color profile history", error); if (! writer) return FALSE; model = GTK_TREE_MODEL (store); for (iter_valid = gtk_tree_model_get_iter_first (model, &iter); iter_valid; iter_valid = gtk_tree_model_iter_next (model, &iter)) { gint type; gint index; gtk_tree_model_get (model, &iter, GIMP_COLOR_PROFILE_STORE_ITEM_TYPE, &type, GIMP_COLOR_PROFILE_STORE_INDEX, &index, -1); if (type == GIMP_COLOR_PROFILE_STORE_ITEM_FILE && index >= 0 && index < HISTORY_SIZE) { if (labels[index] || files[index]) g_warning ("%s: double index %d", G_STRFUNC, index); gtk_tree_model_get (model, &iter, GIMP_COLOR_PROFILE_STORE_LABEL, &labels[index], GIMP_COLOR_PROFILE_STORE_FILE, &files[index], -1); } } for (i = 0; i < HISTORY_SIZE; i++) { if (files[i] && labels[i]) { gchar *uri = g_file_get_uri (files[i]); if (uri) { gimp_config_writer_open (writer, "color-profile"); gimp_config_writer_string (writer, labels[i]); gimp_config_writer_string (writer, uri); gimp_config_writer_close (writer); g_free (uri); } } if (files[i]) g_object_unref (files[i]); g_free (labels[i]); } return gimp_config_writer_finish (writer, "end of color profile history", error); }
gboolean plug_in_rc_write (GSList *plug_in_defs, const gchar *filename, GError **error) { GimpConfigWriter *writer; GEnumClass *enum_class; GSList *list; writer = gimp_config_writer_new_file (filename, FALSE, "GIMP pluginrc\n\n" "This file can safely be removed and " "will be automatically regenerated by " "querying the installed plugins.", error); if (!writer) return FALSE; enum_class = g_type_class_ref (GIMP_TYPE_ICON_TYPE); gimp_config_writer_open (writer, "protocol-version"); gimp_config_writer_printf (writer, "%d", GIMP_PROTOCOL_VERSION); gimp_config_writer_close (writer); gimp_config_writer_open (writer, "file-version"); gimp_config_writer_printf (writer, "%d", PLUG_IN_RC_FILE_VERSION); gimp_config_writer_close (writer); gimp_config_writer_linefeed (writer); for (list = plug_in_defs; list; list = list->next) { GimpPlugInDef *plug_in_def = list->data; if (plug_in_def->procedures) { GSList *list2; gchar *utf8; utf8 = g_filename_to_utf8 (plug_in_def->prog, -1, NULL, NULL, NULL); if (! utf8) continue; gimp_config_writer_open (writer, "plug-in-def"); gimp_config_writer_string (writer, utf8); gimp_config_writer_printf (writer, "%"G_GINT64_FORMAT, plug_in_def->mtime); g_free (utf8); for (list2 = plug_in_def->procedures; list2; list2 = list2->next) { GimpPlugInProcedure *proc = list2->data; GimpProcedure *procedure = GIMP_PROCEDURE (proc); GEnumValue *enum_value; GList *list3; gint i; if (proc->installed_during_init) continue; gimp_config_writer_open (writer, "proc-def"); gimp_config_writer_printf (writer, "\"%s\" %d", procedure->original_name, procedure->proc_type); gimp_config_writer_linefeed (writer); gimp_config_writer_string (writer, procedure->blurb); gimp_config_writer_linefeed (writer); gimp_config_writer_string (writer, procedure->help); gimp_config_writer_linefeed (writer); gimp_config_writer_string (writer, procedure->author); gimp_config_writer_linefeed (writer); gimp_config_writer_string (writer, procedure->copyright); gimp_config_writer_linefeed (writer); gimp_config_writer_string (writer, procedure->date); gimp_config_writer_linefeed (writer); gimp_config_writer_string (writer, proc->menu_label); gimp_config_writer_linefeed (writer); gimp_config_writer_printf (writer, "%d", g_list_length (proc->menu_paths)); for (list3 = proc->menu_paths; list3; list3 = list3->next) { gimp_config_writer_open (writer, "menu-path"); gimp_config_writer_string (writer, list3->data); gimp_config_writer_close (writer); } gimp_config_writer_open (writer, "icon"); enum_value = g_enum_get_value (enum_class, proc->icon_type); gimp_config_writer_identifier (writer, enum_value->value_nick); gimp_config_writer_printf (writer, "%d", proc->icon_data_length); switch (proc->icon_type) { case GIMP_ICON_TYPE_STOCK_ID: case GIMP_ICON_TYPE_IMAGE_FILE: gimp_config_writer_string (writer, (gchar *) proc->icon_data); break; case GIMP_ICON_TYPE_INLINE_PIXBUF: gimp_config_writer_data (writer, proc->icon_data_length, proc->icon_data); break; } gimp_config_writer_close (writer); if (proc->file_proc) { gimp_config_writer_open (writer, proc->image_types ? "save-proc" : "load-proc"); if (proc->extensions && *proc->extensions) { gimp_config_writer_open (writer, "extension"); gimp_config_writer_string (writer, proc->extensions); gimp_config_writer_close (writer); } if (proc->prefixes && *proc->prefixes) { gimp_config_writer_open (writer, "prefix"); gimp_config_writer_string (writer, proc->prefixes); gimp_config_writer_close (writer); } if (proc->magics && *proc->magics) { gimp_config_writer_open (writer, "magic"); gimp_config_writer_string (writer, proc->magics); gimp_config_writer_close (writer); } if (proc->mime_type) { gimp_config_writer_open (writer, "mime-type"); gimp_config_writer_string (writer, proc->mime_type); gimp_config_writer_close (writer); } if (proc->handles_uri) { gimp_config_writer_open (writer, "handles-uri"); gimp_config_writer_close (writer); } if (proc->thumb_loader) { gimp_config_writer_open (writer, "thumb-loader"); gimp_config_writer_string (writer, proc->thumb_loader); gimp_config_writer_close (writer); } gimp_config_writer_close (writer); } gimp_config_writer_linefeed (writer); gimp_config_writer_string (writer, proc->image_types); gimp_config_writer_linefeed (writer); gimp_config_writer_printf (writer, "%d %d", procedure->num_args, procedure->num_values); for (i = 0; i < procedure->num_args; i++) { GParamSpec *pspec = procedure->args[i]; gimp_config_writer_open (writer, "proc-arg"); gimp_config_writer_printf (writer, "%d", gimp_pdb_compat_arg_type_from_gtype (G_PARAM_SPEC_VALUE_TYPE (pspec))); gimp_config_writer_string (writer, g_param_spec_get_name (pspec)); gimp_config_writer_string (writer, g_param_spec_get_blurb (pspec)); gimp_config_writer_close (writer); } for (i = 0; i < procedure->num_values; i++) { GParamSpec *pspec = procedure->values[i]; gimp_config_writer_open (writer, "proc-arg"); gimp_config_writer_printf (writer, "%d", gimp_pdb_compat_arg_type_from_gtype (G_PARAM_SPEC_VALUE_TYPE (pspec))); gimp_config_writer_string (writer, g_param_spec_get_name (pspec)); gimp_config_writer_string (writer, g_param_spec_get_blurb (pspec)); gimp_config_writer_close (writer); } gimp_config_writer_close (writer); } if (plug_in_def->locale_domain_name) { gimp_config_writer_open (writer, "locale-def"); gimp_config_writer_string (writer, plug_in_def->locale_domain_name); if (plug_in_def->locale_domain_path) gimp_config_writer_string (writer, plug_in_def->locale_domain_path); gimp_config_writer_close (writer); } if (plug_in_def->help_domain_name) { gimp_config_writer_open (writer, "help-def"); gimp_config_writer_string (writer, plug_in_def->help_domain_name); if (plug_in_def->help_domain_uri) gimp_config_writer_string (writer, plug_in_def->help_domain_uri); gimp_config_writer_close (writer); } if (plug_in_def->has_init) { gimp_config_writer_open (writer, "has-init"); gimp_config_writer_close (writer); } gimp_config_writer_close (writer); } } g_type_class_unref (enum_class); return gimp_config_writer_finish (writer, "end of pluginrc", error); }
void gimp_unitrc_save (Gimp *gimp) { GimpConfigWriter *writer; gchar *filename; gint i; GError *error = NULL; g_return_if_fail (GIMP_IS_GIMP (gimp)); filename = gimp_personal_rc_file ("unitrc"); if (gimp->be_verbose) g_print ("Writing '%s'\n", gimp_filename_to_utf8 (filename)); writer = gimp_config_writer_new_file (filename, TRUE, "GIMP units\n\n" "This file contains the user unit database. " "You can edit this list with the unit " "editor. You are not supposed to edit it " "manually, but of course you can do.\n" "This file will be entirely rewritten each " "time you exit.", NULL); g_free (filename); if (!writer) return; /* save user defined units */ for (i = _gimp_unit_get_number_of_built_in_units (gimp); i < _gimp_unit_get_number_of_units (gimp); i++) { if (_gimp_unit_get_deletion_flag (gimp, i) == FALSE) { gchar buf[G_ASCII_DTOSTR_BUF_SIZE]; gimp_config_writer_open (writer, "unit-info"); gimp_config_writer_string (writer, _gimp_unit_get_identifier (gimp, i)); gimp_config_writer_open (writer, "factor"); gimp_config_writer_print (writer, g_ascii_formatd (buf, sizeof (buf), "%f", _gimp_unit_get_factor (gimp, i)), -1); gimp_config_writer_close (writer); gimp_config_writer_open (writer, "digits"); gimp_config_writer_printf (writer, "%d", _gimp_unit_get_digits (gimp, i)); gimp_config_writer_close (writer); gimp_config_writer_open (writer, "symbol"); gimp_config_writer_string (writer, _gimp_unit_get_symbol (gimp, i)); gimp_config_writer_close (writer); gimp_config_writer_open (writer, "abbreviation"); gimp_config_writer_string (writer, _gimp_unit_get_abbreviation (gimp, i)); gimp_config_writer_close (writer); gimp_config_writer_open (writer, "singular"); gimp_config_writer_string (writer, _gimp_unit_get_singular (gimp, i)); gimp_config_writer_close (writer); gimp_config_writer_open (writer, "plural"); gimp_config_writer_string (writer, _gimp_unit_get_plural (gimp, i)); gimp_config_writer_close (writer); gimp_config_writer_close (writer); } } if (! gimp_config_writer_finish (writer, "end of units", &error)) { gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message); g_clear_error (&error); } }