예제 #1
0
void
gimp_session_info_book_serialize (GimpConfigWriter    *writer,
                                  GimpSessionInfoBook *info)
{
  GList *pages;

  g_return_if_fail (writer != NULL);
  g_return_if_fail (info != NULL);

  gimp_config_writer_open (writer, "book");

  if (info->position != 0)
    {
      gimp_config_writer_open (writer, "position");
      gimp_config_writer_printf (writer, "%d", info->position);
      gimp_config_writer_close (writer);
    }

  gimp_config_writer_open (writer, "current-page");
  gimp_config_writer_printf (writer, "%d", info->current_page);
  gimp_config_writer_close (writer);

  for (pages = info->dockables; pages; pages = g_list_next (pages))
    gimp_session_info_dockable_serialize (writer, pages->data);

  gimp_config_writer_close (writer);
}
예제 #2
0
void
gimp_session_info_dock_serialize (GimpConfigWriter    *writer,
                                  GimpSessionInfoDock *dock_info)
{
  GList *list;

  g_return_if_fail (writer != NULL);
  g_return_if_fail (dock_info != NULL);

  gimp_config_writer_open (writer, dock_info->dock_type);

  if (dock_info->side != -1)
    {
      const char *side_text =
        dock_info->side == GIMP_ALIGN_LEFT ? "left" : "right";

      gimp_config_writer_open (writer, "side");
      gimp_config_writer_print (writer, side_text, strlen (side_text));
      gimp_config_writer_close (writer);
    }

  if (dock_info->position != 0)
    gimp_session_write_position (writer, dock_info->position);

  for (list = dock_info->books; list; list = g_list_next (list))
    gimp_session_info_book_serialize (writer, list->data);

  gimp_config_writer_close (writer);
}
예제 #3
0
static gboolean
gimp_session_info_serialize (GimpConfig       *config,
                             GimpConfigWriter *writer,
                             gpointer          data)
{
  GimpSessionInfo      *info  = GIMP_SESSION_INFO (config);
  GimpSessionInfoClass *klass = GIMP_SESSION_INFO_GET_CLASS (info);
  GList                *iter  = NULL;
  gint                  x_to_write;
  gint                  y_to_write;
  gint                  w_to_write;
  gint                  h_to_write;

  if (info->p->factory_entry && info->p->factory_entry->identifier)
    {
      gimp_config_writer_open (writer, "factory-entry");
      gimp_config_writer_string (writer, info->p->factory_entry->identifier);
      gimp_config_writer_close (writer);
    }

  x_to_write = gimp_session_info_class_apply_position_accuracy (klass,
                                                                info->p->x);
  y_to_write = gimp_session_info_class_apply_position_accuracy (klass,
                                                                info->p->y);
  w_to_write = gimp_session_info_class_apply_position_accuracy (klass,
                                                                info->p->width);
  h_to_write = gimp_session_info_class_apply_position_accuracy (klass,
                                                                info->p->height);

  gimp_config_writer_open (writer, "position");
  gimp_config_writer_printf (writer, "%d %d", x_to_write, y_to_write);
  gimp_config_writer_close (writer);

  if (info->p->width > 0 && info->p->height > 0)
    {
      gimp_config_writer_open (writer, "size");
      gimp_config_writer_printf (writer, "%d %d", w_to_write, h_to_write);
      gimp_config_writer_close (writer);
    }

  if (info->p->open)
    {
      gimp_config_writer_open (writer, "open-on-exit");

      if (info->p->screen != DEFAULT_SCREEN)
        gimp_config_writer_printf (writer, "%d", info->p->screen);

      gimp_config_writer_close (writer);
    }

  if (info->p->aux_info)
    gimp_session_info_aux_serialize (writer, info->p->aux_info);

  for (iter = info->p->docks; iter; iter = g_list_next (iter))
    gimp_session_info_dock_serialize (writer, iter->data);

  return TRUE;
}
예제 #4
0
static gboolean
gimp_session_info_serialize (GimpConfig       *config,
                             GimpConfigWriter *writer,
                             gpointer          data)
{
  GimpSessionInfo *info = GIMP_SESSION_INFO (config);
  GList           *iter = NULL;
  gint             x;
  gint             y;
  gint             width;
  gint             height;

  if (info->p->factory_entry && info->p->factory_entry->identifier)
    {
      gimp_config_writer_open (writer, "factory-entry");
      gimp_config_writer_string (writer, info->p->factory_entry->identifier);
      gimp_config_writer_close (writer);
    }

  x      = gimp_session_info_apply_position_accuracy (info->p->x);
  y      = gimp_session_info_apply_position_accuracy (info->p->y);
  width  = gimp_session_info_apply_position_accuracy (info->p->width);
  height = gimp_session_info_apply_position_accuracy (info->p->height);

  gimp_config_writer_open (writer, "position");
  gimp_config_writer_printf (writer, "%d %d", x, y);
  gimp_config_writer_close (writer);

  if (info->p->width > 0 && info->p->height > 0)
    {
      gimp_config_writer_open (writer, "size");
      gimp_config_writer_printf (writer, "%d %d", width, height);
      gimp_config_writer_close (writer);
    }

  if (info->p->monitor != DEFAULT_MONITOR)
    {
      gimp_config_writer_open (writer, "monitor");
      gimp_config_writer_printf (writer, "%d", monitor_number (info->p->monitor));
      gimp_config_writer_close (writer);
    }

  if (info->p->open)
    {
      gimp_config_writer_open (writer, "open-on-exit");
      gimp_config_writer_close (writer);
    }

  if (info->p->aux_info)
    gimp_session_info_aux_serialize (writer, info->p->aux_info);

  for (iter = info->p->docks; iter; iter = g_list_next (iter))
    gimp_session_info_dock_serialize (writer, iter->data);

  return TRUE;
}
예제 #5
0
파일: color-history.c 프로젝트: frne/gimp
void
color_history_save (Gimp *gimp)
{
  GimpConfigWriter *writer;
  GFile            *file;
  gint              i;

  g_return_if_fail (GIMP_IS_GIMP (gimp));

  file = gimp_personal_rc_gfile ("colorrc");

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

  writer = gimp_config_writer_new_gfile (file,
                                         TRUE,
                                         "GIMP colorrc\n\n"
                                         "This file holds a list of "
                                         "recently used colors.",
                                         NULL);
  g_object_unref (file);

  if (!writer)
    return;

  if (! color_history_initialized)
    color_history_init ();

  gimp_config_writer_open (writer, "color-history");

  for (i = 0; i < COLOR_HISTORY_SIZE; i++)
    {
      gchar buf[4][G_ASCII_DTOSTR_BUF_SIZE];

      g_ascii_formatd (buf[0],
                       G_ASCII_DTOSTR_BUF_SIZE, "%f", color_history[i].r);
      g_ascii_formatd (buf[1],
                       G_ASCII_DTOSTR_BUF_SIZE, "%f", color_history[i].g);
      g_ascii_formatd (buf[2],
                       G_ASCII_DTOSTR_BUF_SIZE, "%f", color_history[i].b);
      g_ascii_formatd (buf[3],
                       G_ASCII_DTOSTR_BUF_SIZE, "%f", color_history[i].a);

      gimp_config_writer_open (writer, "color-rgba");
      gimp_config_writer_printf (writer, "%s %s %s %s",
                                 buf[0], buf[1], buf[2], buf[3]);
      gimp_config_writer_close (writer);
    }

  gimp_config_writer_close (writer);

  gimp_config_writer_finish (writer, "end of colorrc", NULL);
}
예제 #6
0
static gboolean
gimp_controller_info_serialize_property (GimpConfig       *config,
                                         guint             property_id,
                                         const GValue     *value,
                                         GParamSpec       *pspec,
                                         GimpConfigWriter *writer)
{
  GHashTable *mapping;

  if (property_id != PROP_MAPPING)
    return FALSE;

  mapping = g_value_get_boxed (value);

  if (mapping)
    {
      gimp_config_writer_open (writer, pspec->name);

      g_hash_table_foreach (mapping,
                            (GHFunc) gimp_controller_info_serialize_mapping,
                            writer);

      gimp_config_writer_close (writer);
    }

  return TRUE;
}
예제 #7
0
파일: session.c 프로젝트: Amerekanets/gimp
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;
}
예제 #8
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;
}
예제 #9
0
static void
gimp_controller_info_serialize_mapping (gpointer key,
                                        gpointer value,
                                        gpointer data)
{
  const gchar      *event_name  = key;
  const gchar      *action_name = value;
  GimpConfigWriter *writer      = data;

  gimp_config_writer_open (writer, "map");
  gimp_config_writer_string (writer, event_name);
  gimp_config_writer_string (writer, action_name);
  gimp_config_writer_close (writer);
}
예제 #10
0
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);
        }
    }
}
예제 #11
0
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;
      const gchar      *p;
      GFile            *file;
      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 = "";

      file = gimp_directory_file ("modulerc", NULL);

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

      writer = gimp_config_writer_new_gfile (file, TRUE,
                                             "GIMP modulerc", &error);
      g_object_unref (file);

      if (writer)
        {
          gimp_config_writer_open (writer, "module-load-inhibit");
          gimp_config_writer_string (writer, 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_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message);
          g_clear_error (&error);
        }
    }
}
예제 #12
0
void
gimp_action_history_exit (Gimp *gimp)
{
  GimpGuiConfig         *config;
  GimpActionHistoryItem *item;
  GList                 *actions;
  GFile                 *file;
  GimpConfigWriter      *writer;
  gint                   min_count = 0;
  gint                   i;

  g_return_if_fail (GIMP_IS_GIMP (gimp));

  config = GIMP_GUI_CONFIG (gimp->config);

  /* If we have more items than current history size, trim the history
   * and move down all count so that 1 is lower.
   */
  item = g_list_nth_data (history.items, config->action_history_size);
  if (item)
    min_count = item->count - 1;

  file = gimp_directory_file (GIMP_ACTION_HISTORY_FILENAME, NULL);

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

  writer = gimp_config_writer_new_gfile (file, TRUE, "GIMP action-history",
                                         NULL);
  g_object_unref (file);

  for (actions = history.items, i = 0;
       actions && i < config->action_history_size;
       actions = g_list_next (actions), i++)
    {
      item = actions->data;

      gimp_config_writer_open (writer, "history-item");
      gimp_config_writer_string (writer, item->action_name);
      gimp_config_writer_printf (writer, "%d", item->count - min_count);
      gimp_config_writer_close (writer);
    }

  gimp_config_writer_finish (writer, "end of action-history", NULL);

  gimp_action_history_clear (gimp);
}
예제 #13
0
void
gimp_session_write_position (GimpConfigWriter *writer,
                             gint              position)
{
  GimpSessionInfoClass *klass;
  gint                  pos_to_write;

  klass = g_type_class_ref (GIMP_TYPE_SESSION_INFO);

  pos_to_write =
    gimp_session_info_class_apply_position_accuracy (klass,
                                                     position);

  gimp_config_writer_open (writer, "position");
  gimp_config_writer_printf (writer, "%d", pos_to_write);
  gimp_config_writer_close (writer);

  g_type_class_unref (klass);
}
예제 #14
0
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);
    }
}
예제 #15
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);
}
예제 #16
0
파일: gimp-units.c 프로젝트: LebedevRI/gimp
void
gimp_unitrc_save (Gimp *gimp)
{
  GimpConfigWriter *writer;
  GFile            *file;
  gint              i;
  GError           *error = NULL;

  g_return_if_fail (GIMP_IS_GIMP (gimp));

  file = gimp_directory_file ("unitrc", NULL);

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

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

  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);
    }
}
예제 #17
0
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);
}
예제 #18
0
파일: session.c 프로젝트: jiapei100/gimp
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;
}
예제 #19
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);
}