Exemple #1
0
void
gimp_controllers_restore (Gimp          *gimp,
                          GimpUIManager *ui_manager)
{
  GimpControllerManager *manager;
  gchar                 *filename;
  GError                *error = NULL;

  g_return_if_fail (GIMP_IS_GIMP (gimp));
  g_return_if_fail (GIMP_IS_UI_MANAGER (ui_manager));

  manager = gimp_controller_manager_get (gimp);

  g_return_if_fail (manager != NULL);
  g_return_if_fail (manager->ui_manager == NULL);

  manager->ui_manager = g_object_ref (ui_manager);

  filename = gimp_personal_rc_file ("controllerrc");

  if (gimp->be_verbose)
    g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));

  if (! gimp_config_deserialize_file (GIMP_CONFIG (manager->controllers),
                                      filename, NULL, &error))
    {
      if (error->code == GIMP_CONFIG_ERROR_OPEN_ENOENT)
        {
          g_clear_error (&error);
          g_free (filename);

          filename = g_build_filename (gimp_sysconf_directory (),
                                       "controllerrc", NULL);

          if (! gimp_config_deserialize_file (GIMP_CONFIG (manager->controllers),
                                              filename, NULL, &error))
            {
              gimp_message (gimp, NULL, GIMP_MESSAGE_ERROR,
                            "%s", error->message);
            }
        }
      else
        {
          gimp_message (gimp, NULL, GIMP_MESSAGE_ERROR, "%s", error->message);
        }

      g_clear_error (&error);
    }

  gimp_list_reverse (GIMP_LIST (manager->controllers));

  g_free (filename);
}
Exemple #2
0
void
dialogs_load_recent_docks (Gimp *gimp)
{
  gchar  *filename;
  GError *error = NULL;

  g_return_if_fail (GIMP_IS_GIMP (gimp));

  filename = gimp_personal_rc_file ("dockrc");

  if (gimp->be_verbose)
    g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));

  if (! gimp_config_deserialize_file (GIMP_CONFIG (global_recent_docks),
                                      filename,
                                      NULL, &error))
    {
      if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
        gimp_message (gimp, NULL, GIMP_MESSAGE_ERROR, "%s", error->message);

      g_clear_error (&error);
    }

  gimp_list_reverse (GIMP_LIST (global_recent_docks));

  g_free (filename);
}
GList *
gimp_tool_preset_load (GimpContext  *context,
                       const gchar  *filename,
                       GError      **error)
{
  GimpToolPreset *tool_preset;

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

  tool_preset = g_object_new (GIMP_TYPE_TOOL_PRESET,
                              "gimp", context->gimp,
                              NULL);

  if (gimp_config_deserialize_file (GIMP_CONFIG (tool_preset),
                                    filename,
                                    NULL, error))
    {
      return g_list_prepend (NULL, tool_preset);
    }

  g_object_unref (tool_preset);

  return NULL;
}
Exemple #4
0
/**
 * gimp_templates_migrate:
 * @olddir: the old user directory
 *
 * Migrating the templaterc from GIMP 2.0 to GIMP 2.2 needs this special
 * hack since we changed the way that units are handled. This function
 * merges the user's templaterc with the systemwide templaterc. The goal
 * is to replace the unit for a couple of default templates with "pixels".
 **/
void
gimp_templates_migrate (const gchar *olddir)
{
  GimpContainer *templates = gimp_list_new (GIMP_TYPE_TEMPLATE, TRUE);
  gchar         *filename  = gimp_personal_rc_file ("templaterc");

  if (gimp_config_deserialize_file (GIMP_CONFIG (templates), filename,
                                    NULL, NULL))
    {
      gchar *tmp = g_build_filename (gimp_sysconf_directory (),
                                     "templaterc", NULL);

      if (olddir && (strstr (olddir, "2.0") || strstr (olddir, "2.2")))
        {
          /* We changed the spelling of a couple of template names:
           *
           * - from upper to lower case between 2.0 and 2.2
           * - from "dpi" to "ppi" between 2.2 and 2.4
           */
          GimpContainerClass *class = GIMP_CONTAINER_GET_CLASS (templates);
          gpointer            func  = class->get_child_by_name;

          class->get_child_by_name = gimp_templates_migrate_get_child_by_name;

          gimp_config_deserialize_file (GIMP_CONFIG (templates),
                                        tmp, NULL, NULL);

          class->get_child_by_name = func;
        }
      else
        {
Exemple #5
0
void
dialogs_load_recent_docks (Gimp *gimp)
{
  gchar  *filename;
  GError *error = NULL;

  g_return_if_fail (GIMP_IS_GIMP (gimp));

  filename = dialogs_get_dockrc_filename ();

  if (gimp->be_verbose)
    g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));

  if (! gimp_config_deserialize_file (GIMP_CONFIG (global_recent_docks),
                                      filename,
                                      NULL, &error))
    {
      if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
        gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message);

      g_clear_error (&error);
    }

  /* In GIMP 2.6 dockrc did not contain the factory entries for the
   * session infos, so set that up manually if needed
   */
  gimp_container_foreach (global_recent_docks,
                          (GFunc) dialogs_ensure_factory_entry_on_recent_dock,
                          NULL);

  gimp_list_reverse (GIMP_LIST (global_recent_docks));

  g_free (filename);
}
Exemple #6
0
void
gimp_templates_load (Gimp *gimp)
{
  gchar  *filename;
  GError *error = NULL;

  g_return_if_fail (GIMP_IS_GIMP (gimp));
  g_return_if_fail (GIMP_IS_LIST (gimp->templates));

  filename = gimp_personal_rc_file ("templaterc");

  if (gimp->be_verbose)
    g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));

  if (! gimp_config_deserialize_file (GIMP_CONFIG (gimp->templates),
                                      filename, NULL, &error))
    {
      if (error->code == GIMP_CONFIG_ERROR_OPEN_ENOENT)
        {
          g_clear_error (&error);
          g_free (filename);

          filename = g_build_filename (gimp_sysconf_directory (),
                                       "templaterc", NULL);

          if (! gimp_config_deserialize_file (GIMP_CONFIG (gimp->templates),
                                              filename, NULL, &error))
            {
              gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR,
                                    error->message);
            }
        }
      else
        {
          gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message);
        }

      g_clear_error (&error);
    }

  gimp_list_reverse (GIMP_LIST (gimp->templates));

  g_free (filename);
}
Exemple #7
0
void
gimp_devices_restore (Gimp *gimp)
{
  GimpDeviceManager *manager;
  GimpContext       *user_context;
  GimpDeviceInfo    *current_device;
  GList             *list;
  gchar             *filename;
  GError            *error = NULL;

  g_return_if_fail (GIMP_IS_GIMP (gimp));

  manager = gimp_devices_get_manager (gimp);

  g_return_if_fail (GIMP_IS_DEVICE_MANAGER (manager));

  user_context = gimp_get_user_context (gimp);

  for (list = GIMP_LIST (manager)->list;
       list;
       list = g_list_next (list))
    {
      GimpDeviceInfo *device_info = list->data;

      gimp_context_copy_properties (user_context, GIMP_CONTEXT (device_info),
                                    GIMP_DEVICE_INFO_CONTEXT_MASK);

      gimp_device_info_set_default_tool (device_info);
    }

  filename = gimp_personal_rc_file ("devicerc");

  if (gimp->be_verbose)
    g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));

  if (! gimp_config_deserialize_file (GIMP_CONFIG (manager),
                                      filename,
                                      gimp,
                                      &error))
    {
      if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
        gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message);

      g_error_free (error);
      /* don't bail out here */
    }

  g_free (filename);

  current_device = gimp_device_manager_get_current_device (manager);

  gimp_context_copy_properties (GIMP_CONTEXT (current_device), user_context,
                                GIMP_DEVICE_INFO_CONTEXT_MASK);
  gimp_context_set_parent (GIMP_CONTEXT (current_device), user_context);
}
Exemple #8
0
static void
gimp_rc_load (GimpRc *rc)
{
  GError *error = NULL;

  g_return_if_fail (GIMP_IS_RC (rc));

  if (rc->verbose)
    g_print ("Parsing '%s'\n",
             gimp_filename_to_utf8 (rc->system_gimprc));

  if (! gimp_config_deserialize_file (GIMP_CONFIG (rc),
                                      rc->system_gimprc, NULL, &error))
    {
      if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
        g_message ("%s", error->message);

      g_clear_error (&error);
    }

  if (rc->verbose)
    g_print ("Parsing '%s'\n",
             gimp_filename_to_utf8 (rc->user_gimprc));

  if (! gimp_config_deserialize_file (GIMP_CONFIG (rc),
                                      rc->user_gimprc, NULL, &error))
    {
      if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
        {
          g_message ("%s", error->message);

          gimp_config_file_backup_on_error (rc->user_gimprc, "gimprc", NULL);
        }

      g_clear_error (&error);
    }
}
Exemple #9
0
/**
 * gimp_rc_save:
 * @gimprc: a #GimpRc object.
 *
 * Saves any settings that differ from the system-wide defined
 * defaults to the users personal gimprc file.
 **/
void
gimp_rc_save (GimpRc *rc)
{
  GimpRc *global;
  gchar  *header;
  GError *error = NULL;

  const gchar *top =
    "GIMP gimprc\n"
    "\n"
    "This is your personal gimprc file.  Any variable defined in this file "
    "takes precedence over the value defined in the system-wide gimprc: ";
  const gchar *bottom =
    "\n"
    "Most values can be set within GIMP by changing some options in "
    "the Preferences dialog.";
  const gchar *footer =
    "end of gimprc";

  g_return_if_fail (GIMP_IS_RC (rc));

  global = g_object_new (GIMP_TYPE_RC, NULL);

  gimp_config_deserialize_file (GIMP_CONFIG (global),
                                rc->system_gimprc, NULL, NULL);

  header = g_strconcat (top, rc->system_gimprc, bottom, NULL);

  if (rc->verbose)
    g_print ("Writing '%s'\n",
             gimp_filename_to_utf8 (rc->user_gimprc));

  if (! gimp_config_serialize_to_file (GIMP_CONFIG (rc),
                                       rc->user_gimprc,
                                       header, footer, global,
                                       &error))
    {
      g_message ("%s", error->message);
      g_error_free (error);
    }

  g_free (header);
  g_object_unref (global);
}
Exemple #10
0
gboolean
gimp_contexts_load (Gimp    *gimp,
                    GError **error)
{
  gchar    *filename;
  GError   *my_error = NULL;
  gboolean  success;

  g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  filename = gimp_personal_rc_file ("contextrc");

  if (gimp->be_verbose)
    g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));

  success = gimp_config_deserialize_file (GIMP_CONFIG (gimp_get_user_context (gimp)),
                                          filename,
                                          NULL, &my_error);

  if (! success)
    {
      if (my_error->code == GIMP_CONFIG_ERROR_OPEN_ENOENT)
        {
          g_clear_error (&my_error);
          success = TRUE;
        }
      else
        {
          g_propagate_error (error, my_error);
        }
    }

  g_free (filename);

  return success;
}
Exemple #11
0
void
gimp_tools_restore (Gimp *gimp)
{
  GimpContainer *gimp_list;
  gchar         *filename;
  GList         *list;
  GError        *error = NULL;

  g_return_if_fail (GIMP_IS_GIMP (gimp));

  gimp_list = gimp_list_new (GIMP_TYPE_TOOL_INFO, FALSE);

  filename = gimp_personal_rc_file ("toolrc");

  if (gimp->be_verbose)
    g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));

  if (gimp_config_deserialize_file (GIMP_CONFIG (gimp_list), filename,
                                    NULL, NULL))
    {
      gint n = gimp_container_get_n_children (gimp->tool_info_list);
      gint i;

      gimp_list_reverse (GIMP_LIST (gimp_list));

      for (list = GIMP_LIST (gimp_list)->list, i = 0;
           list;
           list = g_list_next (list), i++)
        {
          const gchar *name;
          GimpObject  *object;

          name = gimp_object_get_name (list->data);

          object = gimp_container_get_child_by_name (gimp->tool_info_list,
                                                     name);

          if (object)
            {
              g_object_set (object,
                            "visible", GIMP_TOOL_INFO (list->data)->visible,
                            NULL);

              gimp_container_reorder (gimp->tool_info_list,
                                      object, MIN (i, n - 1));
            }
        }
    }

  g_free (filename);
  g_object_unref (gimp_list);

  for (list = gimp_get_tool_info_iter (gimp);
       list;
       list = g_list_next (list))
    {
      GimpToolInfo *tool_info = GIMP_TOOL_INFO (list->data);

      /*  get default values from prefs (see bug #120832)  */
      gimp_tool_options_reset (tool_info->tool_options);
    }

  if (! gimp_contexts_load (gimp, &error))
    {
      gimp_message_literal (gimp, NULL, GIMP_MESSAGE_WARNING, error->message);
      g_clear_error (&error);
    }

  for (list = gimp_get_tool_info_iter (gimp);
       list;
       list = g_list_next (list))
    {
      GimpToolInfo           *tool_info = GIMP_TOOL_INFO (list->data);
      GimpToolOptionsGUIFunc  options_gui_func;
      GtkWidget              *options_gui;

      /*  copy all context properties except those the tool actually
       *  uses, because the subsequent deserialize() on the tool
       *  options will only set the properties that were set to
       *  non-default values at the time of saving, and we want to
       *  keep these default values as if they have been saved.
       * (see bug #541586).
       */
      gimp_context_copy_properties (gimp_get_user_context (gimp),
                                    GIMP_CONTEXT (tool_info->tool_options),
                                    GIMP_CONTEXT_ALL_PROPS_MASK &~
                                    (tool_info->context_props |
                                     GIMP_CONTEXT_TOOL_MASK   |
                                     GIMP_CONTEXT_PAINT_INFO_MASK));

      gimp_tool_options_deserialize (tool_info->tool_options, NULL);

      options_gui_func = g_object_get_data (G_OBJECT (tool_info),
                                            "gimp-tool-options-gui-func");

      if (options_gui_func)
        {
          options_gui = (* options_gui_func) (tool_info->tool_options);
        }
      else
        {
          GtkWidget *label;

          options_gui = gimp_tool_options_gui (tool_info->tool_options);

          label = gtk_label_new (_("This tool has\nno options."));
          gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
          gimp_label_set_attributes (GTK_LABEL (label),
                                     PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
                                     -1);
          gtk_box_pack_start (GTK_BOX (options_gui), label, FALSE, FALSE, 6);
          gtk_widget_show (label);
        }

      gimp_tools_set_tool_options_gui (tool_info->tool_options,
                                       g_object_ref_sink (options_gui));
    }
}