Beispiel #1
0
gboolean
gimp_config_dump (GObject              *gimp,
                  GimpConfigDumpFormat  format)
{
  GOutputStream    *output;
  GimpConfigWriter *writer;
  GimpConfig       *rc;

  g_return_val_if_fail (G_IS_OBJECT (gimp), FALSE);

  rc = g_object_new (GIMP_TYPE_RC,
                     "gimp", gimp,
                     NULL);

#ifdef G_OS_WIN32
  output = g_win32_output_stream_new ((gpointer) 1, FALSE);
#else
  output = g_unix_output_stream_new (1, FALSE);
#endif

  writer = gimp_config_writer_new_stream (output, NULL, NULL);

  switch (format)
    {
    case GIMP_CONFIG_DUMP_NONE:
      break;

    case GIMP_CONFIG_DUMP_GIMPRC:
      gimp_config_writer_comment (writer,
                                  "Dump of the GIMP default configuration");
      gimp_config_writer_linefeed (writer);
      gimp_config_serialize_properties (rc, writer);
      gimp_config_writer_linefeed (writer);
      break;

    case GIMP_CONFIG_DUMP_GIMPRC_SYSTEM:
      dump_gimprc_system (rc, writer, output);
      break;

    case GIMP_CONFIG_DUMP_GIMPRC_MANPAGE:
      dump_gimprc_manpage (rc, writer, output);
      break;
    }

  gimp_config_writer_finish (writer, NULL, NULL);
  g_object_unref (output);
  g_object_unref (rc);

  return TRUE;
}
Beispiel #2
0
static void
dump_gimprc_system (GimpConfig       *rc,
                    GimpConfigWriter *writer,
                    GOutputStream    *output)
{
  GObjectClass  *klass;
  GParamSpec   **property_specs;
  guint          n_property_specs;
  guint          i;

  gimp_config_writer_comment (writer, system_gimprc_header);
  gimp_config_writer_linefeed (writer);

  klass = G_OBJECT_GET_CLASS (rc);
  property_specs = g_object_class_list_properties (klass, &n_property_specs);

  for (i = 0; i < n_property_specs; i++)
    {
      GParamSpec *prop_spec = property_specs[i];
      gchar      *comment;

      if (! (prop_spec->flags & GIMP_CONFIG_PARAM_SERIALIZE))
        continue;

      if (prop_spec->flags & GIMP_CONFIG_PARAM_IGNORE)
        continue;

      comment = dump_describe_param (prop_spec);
      if (comment)
        {
          gimp_config_writer_comment (writer, comment);
          g_free (comment);
        }

      gimp_config_writer_comment_mode (writer, TRUE);
      gimp_config_writer_linefeed (writer);

      gimp_config_serialize_property (rc, prop_spec, writer);

      gimp_config_writer_comment_mode (writer, FALSE);
      gimp_config_writer_linefeed (writer);
    }

  g_free (property_specs);
}
/**
 * gimp_config_writer_new_file:
 * @filename: a filename
 * @atomic: if %TRUE the file is written atomically
 * @header: text to include as comment at the top of the file
 * @error: return location for errors
 *
 * Creates a new #GimpConfigWriter and sets it up to write to
 * @filename. If @atomic is %TRUE, a temporary file is used to avoid
 * possible race conditions. The temporary file is then moved to
 * @filename when the writer is closed.
 *
 * Return value: a new #GimpConfigWriter or %NULL in case of an error
 *
 * Since: GIMP 2.4
 **/
GimpConfigWriter *
gimp_config_writer_new_file (const gchar  *filename,
                             gboolean      atomic,
                             const gchar  *header,
                             GError      **error)
{
  GimpConfigWriter *writer;
  gchar            *tmpname = NULL;
  gint              fd;

  g_return_val_if_fail (filename != NULL, NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  if (atomic)
    {
      tmpname = g_strconcat (filename, "XXXXXX", NULL);

      fd = g_mkstemp (tmpname);

      if (fd == -1)
        {
          g_set_error (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE,
                       _("Could not create temporary file for '%s': %s"),
                       gimp_filename_to_utf8 (filename), g_strerror (errno));
          g_free (tmpname);
          return NULL;
        }
    }
  else
    {
      fd = g_creat (filename, 0644);

      if (fd == -1)
        {
          g_set_error (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE,
                       _("Could not open '%s' for writing: %s"),
                       gimp_filename_to_utf8 (filename), g_strerror (errno));
          return NULL;
        }
    }

  writer = g_slice_new0 (GimpConfigWriter);

  writer->fd       = fd;
  writer->filename = g_strdup (filename);
  writer->tmpname  = tmpname;
  writer->buffer   = g_string_new (NULL);

  if (header)
    {
      gimp_config_writer_comment (writer, header);
      gimp_config_writer_linefeed (writer);
    }

  return writer;
}
Beispiel #4
0
/**
 * gimp_config_writer_new_gfile:
 * @file: a #GFile
 * @atomic: if %TRUE the file is written atomically
 * @header: text to include as comment at the top of the file
 * @error: return location for errors
 *
 * Creates a new #GimpConfigWriter and sets it up to write to
 * @file. If @atomic is %TRUE, a temporary file is used to avoid
 * possible race conditions. The temporary file is then moved to @file
 * when the writer is closed.
 *
 * Return value: a new #GimpConfigWriter or %NULL in case of an error
 *
 * Since: GIMP 2.10
 **/
GimpConfigWriter *
gimp_config_writer_new_gfile (GFile        *file,
                              gboolean      atomic,
                              const gchar  *header,
                              GError      **error)
{
  GimpConfigWriter *writer;
  GOutputStream    *output;
  GError           *my_error = NULL;

  g_return_val_if_fail (G_IS_FILE (file), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  if (atomic)
    {
      output = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE,
                                                G_FILE_CREATE_NONE,
                                                NULL, &my_error));
      if (! output)
        g_set_error (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE,
                     _("Could not create temporary file for '%s': %s"),
                     gimp_file_get_utf8_name (file), my_error->message);
    }
  else
    {
      output = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE,
                                                G_FILE_CREATE_REPLACE_DESTINATION,
                                                NULL, &my_error));
      if (! output)
        g_set_error (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE,
                     _("Could not open '%s' for writing: %s"),
                     gimp_file_get_utf8_name (file), my_error->message);
    }

  if (! output)
    {
      g_clear_error (&my_error);
      return NULL;
    }

  writer = g_slice_new0 (GimpConfigWriter);

  writer->output = output;
  writer->file   = g_object_ref (file);
  writer->buffer = g_string_new (NULL);

  if (header)
    {
      gimp_config_writer_comment (writer, header);
      gimp_config_writer_linefeed (writer);
    }

  return writer;
}
Beispiel #5
0
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;
}
Beispiel #6
0
/**
 * gimp_config_writer_finish:
 * @writer: a #GimpConfigWriter
 * @footer: text to include as comment at the bottom of the file
 * @error: return location for possible errors
 *
 * This function finishes the work of @writer and frees it afterwards.
 * It closes all open elements, appends an optional comment and
 * releases all resources allocated by @writer. You must not access
 * the @writer afterwards.
 *
 * Return value: %TRUE if everything could be successfully written,
 *               %FALSE otherwise
 *
 * Since: GIMP 2.4
 **/
gboolean
gimp_config_writer_finish (GimpConfigWriter  *writer,
                           const gchar       *footer,
                           GError           **error)
{
  gboolean success = TRUE;

  g_return_val_if_fail (writer != NULL, FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  if (writer->depth < 0)
    {
      g_warning ("gimp_config_writer_finish: depth < 0 !!");
    }
  else
    {
      while (writer->depth)
        gimp_config_writer_close (writer);
    }

  if (footer)
    {
      gimp_config_writer_linefeed (writer);
      gimp_config_writer_comment (writer, footer);
    }

  if (writer->output)
    {
      success = gimp_config_writer_close_output (writer, error);

      if (writer->file)
        g_object_unref (writer->file);

      g_string_free (writer->buffer, TRUE);
    }

  if (writer->error)
    {
      if (error && *error == NULL)
        g_propagate_error (error, writer->error);
      else
        g_clear_error (&writer->error);

      success = FALSE;
    }

  g_slice_free (GimpConfigWriter, writer);

  return success;
}
gboolean
gimp_config_dump (GimpConfigDumpFormat  format)
{
  GimpConfigWriter *writer;
  GimpConfig       *rc;

  rc = g_object_new (GIMP_TYPE_RC, NULL);
  writer = gimp_config_writer_new_fd (1);

  switch (format)
    {
    case GIMP_CONFIG_DUMP_NONE:
      break;

    case GIMP_CONFIG_DUMP_GIMPRC:
      gimp_config_writer_comment (writer,
                                  "Dump of the GIMP default configuration");
      gimp_config_writer_linefeed (writer);
      gimp_config_serialize_properties (rc, writer);
      gimp_config_writer_linefeed (writer);
      break;

    case GIMP_CONFIG_DUMP_GIMPRC_SYSTEM:
      dump_gimprc_system (rc, writer, 1);
      break;

    case GIMP_CONFIG_DUMP_GIMPRC_MANPAGE:
      dump_gimprc_manpage (rc, writer, 1);
      break;
    }

  gimp_config_writer_finish (writer, NULL, NULL);
  g_object_unref (rc);

  return TRUE;
}
Beispiel #8
0
static void
parasite_serialize (const gchar      *key,
                    GimpParasite     *parasite,
                    GimpConfigWriter *writer)
{
  if (! gimp_parasite_is_persistent (parasite))
    return;

  gimp_config_writer_open (writer, parasite_symbol);

  gimp_config_writer_printf (writer, "\"%s\" %lu %lu",
                             gimp_parasite_name (parasite),
                             gimp_parasite_flags (parasite),
                             gimp_parasite_data_size (parasite));

  gimp_config_writer_data (writer,
                           gimp_parasite_data_size (parasite),
                           gimp_parasite_data (parasite));

  gimp_config_writer_close (writer);
  gimp_config_writer_linefeed (writer);
}
Beispiel #9
0
/**
 * gimp_config_writer_new_stream:
 * @output: a #GOutputStream
 * @header: text to include as comment at the top of the file
 * @error: return location for errors
 *
 * Creates a new #GimpConfigWriter and sets it up to write to
 * @output.
 *
 * Return value: a new #GimpConfigWriter or %NULL in case of an error
 *
 * Since: GIMP 2.10
 **/
GimpConfigWriter *
gimp_config_writer_new_stream (GOutputStream  *output,
                               const gchar    *header,
                               GError        **error)
{
  GimpConfigWriter *writer;

  g_return_val_if_fail (G_IS_OUTPUT_STREAM (output), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  writer = g_slice_new0 (GimpConfigWriter);

  writer->output = g_object_ref (output);
  writer->buffer = g_string_new (NULL);

  if (header)
    {
      gimp_config_writer_comment (writer, header);
      gimp_config_writer_linefeed (writer);
    }

  return writer;
}
Beispiel #10
0
gboolean
plug_in_rc_write (GSList  *plug_in_defs,
                  GFile   *file,
                  GError **error)
{
  GimpConfigWriter *writer;
  GEnumClass       *enum_class;
  GSList           *list;

  writer = gimp_config_writer_new_gfile (file,
                                         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  *path;
          gchar  *utf8;

          path = g_file_get_path (plug_in_def->file);
          utf8 = g_filename_to_utf8 (path, -1, NULL, NULL, NULL);
          g_free (path);

          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_ICON_NAME:
                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);
}
Beispiel #11
0
void
session_save (Gimp     *gimp,
              gboolean  always_save)
{
  GimpConfigWriter *writer;
  GFile            *file;
  GError           *error = NULL;

  g_return_if_fail (GIMP_IS_GIMP (gimp));

  if (sessionrc_deleted && ! always_save)
    return;

  file = session_file (gimp);

  if (gimp->be_verbose)
    g_print ("Writing '%s'\n", gimp_file_get_utf8_name (file));

  writer =
    gimp_config_writer_new_gfile (file,
                                  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_object_unref (file);

  if (!writer)
    return;

  gimp_dialog_factory_save (gimp_dialog_factory_get_singleton (), writer);
  gimp_config_writer_linefeed (writer);

  gimp_config_writer_open (writer, "hide-docks");
  gimp_config_writer_identifier (writer,
                                 GIMP_GUI_CONFIG (gimp->config)->hide_docks ?
                                 "yes" : "no");
  gimp_config_writer_close (writer);

  gimp_config_writer_open (writer, "single-window-mode");
  gimp_config_writer_identifier (writer,
                                 GIMP_GUI_CONFIG (gimp->config)->single_window_mode ?
                                 "yes" : "no");
  gimp_config_writer_close (writer);

  gimp_config_writer_open (writer, "show-tabs");
  gimp_config_writer_printf (writer,
                             GIMP_GUI_CONFIG (gimp->config)->show_tabs ?
                             "yes" : "no");
  gimp_config_writer_close (writer);

  gimp_config_writer_open (writer, "tabs-position");
  gimp_config_writer_printf (writer, "%d",
                             GIMP_GUI_CONFIG (gimp->config)->tabs_position);
  gimp_config_writer_close (writer);

  gimp_config_writer_open (writer, "last-tip-shown");
  gimp_config_writer_printf (writer, "%d",
                             GIMP_GUI_CONFIG (gimp->config)->last_tip_shown);
  gimp_config_writer_close (writer);

  if (! gimp_config_writer_finish (writer, "end of sessionrc", &error))
    {
      gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message);
      g_clear_error (&error);
    }

  dialogs_save_recent_docks (gimp);

  sessionrc_deleted = FALSE;
}
Beispiel #12
0
/**
 * gimp_config_writer_new_gfile:
 * @file: a #GFile
 * @atomic: if %TRUE the file is written atomically
 * @header: text to include as comment at the top of the file
 * @error: return location for errors
 *
 * Creates a new #GimpConfigWriter and sets it up to write to
 * @file. If @atomic is %TRUE, a temporary file is used to avoid
 * possible race conditions. The temporary file is then moved to @file
 * when the writer is closed.
 *
 * Return value: a new #GimpConfigWriter or %NULL in case of an error
 *
 * Since: 2.10
 **/
GimpConfigWriter *
gimp_config_writer_new_gfile (GFile        *file,
                              gboolean      atomic,
                              const gchar  *header,
                              GError      **error)
{
  GimpConfigWriter *writer;
  GOutputStream    *output;
  GFile            *dir;

  g_return_val_if_fail (G_IS_FILE (file), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  dir = g_file_get_parent (file);
  if (dir && ! g_file_query_exists (dir, NULL))
    {
      if (! g_file_make_directory_with_parents (dir, NULL, error))
        g_prefix_error (error,
                        _("Could not create directory '%s' for '%s': "),
                        gimp_file_get_utf8_name (dir),
                        gimp_file_get_utf8_name (file));
    }
  g_object_unref (dir);

  if (error && *error)
    return NULL;

  if (atomic)
    {
      output = G_OUTPUT_STREAM (g_file_replace (file,
                                                NULL, FALSE, G_FILE_CREATE_NONE,
                                                NULL, error));
      if (! output)
        g_prefix_error (error,
                        _("Could not create temporary file for '%s': "),
                        gimp_file_get_utf8_name (file));
    }
  else
    {
      output = G_OUTPUT_STREAM (g_file_replace (file,
                                                NULL, FALSE,
                                                G_FILE_CREATE_REPLACE_DESTINATION,
                                                NULL, error));
    }

  if (! output)
    return NULL;

  writer = g_slice_new0 (GimpConfigWriter);

  writer->output = output;
  writer->file   = g_object_ref (file);
  writer->buffer = g_string_new (NULL);

  if (header)
    {
      gimp_config_writer_comment (writer, header);
      gimp_config_writer_linefeed (writer);
    }

  return writer;
}