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); }
static void tool_manager_connect_options (GimpContext *user_context, GimpToolInfo *tool_info) { if (tool_info->context_props) { GimpCoreConfig *config = user_context->gimp->config; GimpContextPropMask global_props = 0; /* FG and BG are always shared between all tools */ global_props |= GIMP_CONTEXT_FOREGROUND_MASK; global_props |= GIMP_CONTEXT_BACKGROUND_MASK; if (config->global_brush) global_props |= GIMP_CONTEXT_BRUSH_MASK; if (config->global_dynamics) global_props |= GIMP_CONTEXT_DYNAMICS_MASK; if (config->global_pattern) global_props |= GIMP_CONTEXT_PATTERN_MASK; if (config->global_palette) global_props |= GIMP_CONTEXT_PALETTE_MASK; if (config->global_gradient) global_props |= GIMP_CONTEXT_GRADIENT_MASK; if (config->global_font) global_props |= GIMP_CONTEXT_FONT_MASK; gimp_context_copy_properties (GIMP_CONTEXT (tool_info->tool_options), user_context, tool_info->context_props & ~global_props); gimp_context_set_parent (GIMP_CONTEXT (tool_info->tool_options), user_context); } }
static void tool_manager_preset_changed (GimpContext *user_context, GimpToolPreset *preset, GimpToolManager *tool_manager) { GimpToolInfo *preset_tool; gboolean tool_change = FALSE; if (! preset || user_context->gimp->busy) return; preset_tool = gimp_context_get_tool (GIMP_CONTEXT (preset->tool_options)); if (preset_tool != gimp_context_get_tool (user_context)) tool_change = TRUE; if (! tool_change) tool_manager_disconnect_options (user_context, preset_tool); gimp_config_copy (GIMP_CONFIG (preset->tool_options), GIMP_CONFIG (preset_tool->tool_options), 0); if (tool_change) gimp_context_set_tool (user_context, preset_tool); else tool_manager_connect_options (user_context, preset_tool); gimp_context_copy_properties (GIMP_CONTEXT (preset->tool_options), user_context, gimp_tool_preset_get_prop_mask (preset)); }
static void tool_manager_preset_changed (GimpContext *user_context, GimpToolPreset *preset, GimpToolManager *tool_manager) { GimpToolInfo *preset_tool; gchar *options_name; gboolean tool_change = FALSE; if (! preset || user_context->gimp->busy) return; preset_tool = gimp_context_get_tool (GIMP_CONTEXT (preset->tool_options)); if (preset_tool != gimp_context_get_tool (user_context)) tool_change = TRUE; /* save the name, we don't want to overwrite it */ options_name = g_strdup (gimp_object_get_name (preset_tool->tool_options)); gimp_config_copy (GIMP_CONFIG (preset->tool_options), GIMP_CONFIG (preset_tool->tool_options), 0); /* restore the saved name */ gimp_object_take_name (GIMP_OBJECT (preset_tool->tool_options), options_name); if (tool_change) gimp_context_set_tool (user_context, preset_tool); gimp_context_copy_properties (GIMP_CONTEXT (preset->tool_options), user_context, gimp_tool_preset_get_prop_mask (preset)); if (GIMP_IS_PAINT_OPTIONS (preset->tool_options)) { GimpToolOptions *src; GimpToolOptions *dest; GimpContextPropMask prop_mask = 0; src = preset->tool_options; dest = tool_manager->active_tool->tool_info->tool_options; /* copy various data objects' additional tool options again * manually, they might have been overwritten by e.g. the "link * brush stuff to brush defaults" logic in gimptooloptions.c */ if (preset->use_brush) prop_mask |= GIMP_CONTEXT_PROP_MASK_BRUSH; if (preset->use_dynamics) prop_mask |= GIMP_CONTEXT_PROP_MASK_DYNAMICS; if (preset->use_gradient) prop_mask |= GIMP_CONTEXT_PROP_MASK_GRADIENT; gimp_paint_options_copy_props (GIMP_PAINT_OPTIONS (src), GIMP_PAINT_OPTIONS (dest), prop_mask); } }
static void gimp_device_info_constructed (GObject *object) { GimpDeviceInfo *info = GIMP_DEVICE_INFO (object); Gimp *gimp; G_OBJECT_CLASS (parent_class)->constructed (object); g_assert ((info->device == NULL && info->display == NULL) || (GDK_IS_DEVICE (info->device) && GDK_IS_DISPLAY (info->display))); gimp = GIMP_CONTEXT (object)->gimp; if (info->device) { g_object_set_data (G_OBJECT (info->device), GIMP_DEVICE_INFO_DATA_KEY, info); gimp_object_set_name (GIMP_OBJECT (info), info->device->name); info->mode = info->device->mode; info->n_axes = info->device->num_axes; info->n_keys = info->device->num_keys; } gimp_context_define_properties (GIMP_CONTEXT (object), GIMP_DEVICE_INFO_CONTEXT_MASK, FALSE); gimp_context_copy_properties (gimp_get_user_context (gimp), GIMP_CONTEXT (object), GIMP_DEVICE_INFO_CONTEXT_MASK); gimp_context_set_serialize_properties (GIMP_CONTEXT (object), GIMP_DEVICE_INFO_CONTEXT_MASK); /* FIXME: this is ugly and needs to be done via "notify" once * the contexts' properties are dynamic. */ g_signal_connect (object, "foreground-changed", G_CALLBACK (gimp_device_info_changed), NULL); g_signal_connect (object, "background-changed", G_CALLBACK (gimp_device_info_changed), NULL); g_signal_connect (object, "tool-changed", G_CALLBACK (gimp_device_info_changed), NULL); g_signal_connect (object, "brush-changed", G_CALLBACK (gimp_device_info_changed), NULL); g_signal_connect (object, "pattern-changed", G_CALLBACK (gimp_device_info_changed), NULL); g_signal_connect (object, "gradient-changed", G_CALLBACK (gimp_device_info_changed), NULL); }
static void tool_manager_connect_options (GimpToolManager *tool_manager, GimpContext *user_context, GimpToolInfo *tool_info) { if (tool_info->context_props) { GimpCoreConfig *config = user_context->gimp->config; GimpContextPropMask global_props = 0; /* FG and BG are always shared between all tools */ global_props |= GIMP_CONTEXT_PROP_MASK_FOREGROUND; global_props |= GIMP_CONTEXT_PROP_MASK_BACKGROUND; if (config->global_brush) global_props |= GIMP_CONTEXT_PROP_MASK_BRUSH; if (config->global_dynamics) global_props |= GIMP_CONTEXT_PROP_MASK_DYNAMICS; if (config->global_pattern) global_props |= GIMP_CONTEXT_PROP_MASK_PATTERN; if (config->global_palette) global_props |= GIMP_CONTEXT_PROP_MASK_PALETTE; if (config->global_gradient) global_props |= GIMP_CONTEXT_PROP_MASK_GRADIENT; if (config->global_font) global_props |= GIMP_CONTEXT_PROP_MASK_FONT; gimp_context_copy_properties (GIMP_CONTEXT (tool_info->tool_options), user_context, tool_info->context_props & ~global_props); gimp_context_set_parent (GIMP_CONTEXT (tool_info->tool_options), user_context); if (GIMP_IS_PAINT_OPTIONS (tool_info->tool_options)) { if (config->global_brush) gimp_paint_options_copy_brush_props (tool_manager->shared_paint_options, GIMP_PAINT_OPTIONS (tool_info->tool_options)); if (config->global_dynamics) gimp_paint_options_copy_dynamics_props (tool_manager->shared_paint_options, GIMP_PAINT_OPTIONS (tool_info->tool_options)); if (config->global_gradient) gimp_paint_options_copy_gradient_props (tool_manager->shared_paint_options, GIMP_PAINT_OPTIONS (tool_info->tool_options)); } } }
void gimp_tools_restore (Gimp *gimp) { GimpContainer *gimp_list; GimpObject *object; GFile *file; GList *list; GError *error = NULL; g_return_if_fail (GIMP_IS_GIMP (gimp)); gimp_list = gimp_list_new (GIMP_TYPE_TOOL_INFO, FALSE); file = gimp_directory_file ("toolrc", NULL); if (gimp->be_verbose) g_print ("Parsing '%s'\n", gimp_file_get_utf8_name (file)); if (gimp_config_deserialize_gfile (GIMP_CONFIG (gimp_list), file, 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; 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_object_unref (file); g_object_unref (gimp_list); /* make the generic operation tool invisible by default */ object = gimp_container_get_child_by_name (gimp->tool_info_list, "gimp-operation-tool"); if (object) g_object_set (object, "visible", FALSE, NULL); 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_config_reset (GIMP_CONFIG (tool_info->tool_options)); } if (! gimp_contexts_load (gimp, &error)) { gimp_message_literal (gimp, NULL, GIMP_MESSAGE_WARNING, error->message); g_clear_error (&error); } /* make sure there is always a tool active, so broken config files * can't leave us with no initial tool */ if (! gimp_context_get_tool (gimp_get_user_context (gimp))) { gimp_context_set_tool (gimp_get_user_context (gimp), gimp_get_tool_info_iter (gimp)->data); } 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_PROP_MASK_ALL &~ (tool_info->context_props | GIMP_CONTEXT_PROP_MASK_TOOL | GIMP_CONTEXT_PROP_MASK_PAINT_INFO)); 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)); } }
static void tool_manager_preset_changed (GimpContext *user_context, GimpToolPreset *preset, GimpToolManager *tool_manager) { GimpToolInfo *preset_tool; gchar *options_name; gboolean tool_change = FALSE; if (! preset || user_context->gimp->busy) return; preset_tool = gimp_context_get_tool (GIMP_CONTEXT (preset->tool_options)); if (preset_tool != gimp_context_get_tool (user_context)) tool_change = TRUE; if (! tool_change) tool_manager_disconnect_options (tool_manager, user_context, preset_tool); /* save the name, we don't want to overwrite it */ options_name = g_strdup (gimp_object_get_name (preset_tool->tool_options)); gimp_config_copy (GIMP_CONFIG (preset->tool_options), GIMP_CONFIG (preset_tool->tool_options), 0); /* restore the saved name */ gimp_object_take_name (GIMP_OBJECT (preset_tool->tool_options), options_name); if (tool_change) gimp_context_set_tool (user_context, preset_tool); else tool_manager_connect_options (tool_manager, user_context, preset_tool); gimp_context_copy_properties (GIMP_CONTEXT (preset->tool_options), user_context, gimp_tool_preset_get_prop_mask (preset)); if (GIMP_IS_PAINT_OPTIONS (preset->tool_options)) { GimpCoreConfig *config = user_context->gimp->config; GimpToolOptions *src = preset->tool_options; GimpToolOptions *dest = tool_manager->active_tool->tool_info->tool_options; /* if connect_options() did overwrite the brush options and the * preset contains a brush, use the brush options from the * preset */ if (config->global_brush && preset->use_brush) gimp_paint_options_copy_brush_props (GIMP_PAINT_OPTIONS (src), GIMP_PAINT_OPTIONS (dest)); if (config->global_dynamics && preset->use_dynamics) gimp_paint_options_copy_dynamics_props (GIMP_PAINT_OPTIONS (src), GIMP_PAINT_OPTIONS (dest)); if (config->global_gradient && preset->use_gradient) gimp_paint_options_copy_gradient_props (GIMP_PAINT_OPTIONS (src), GIMP_PAINT_OPTIONS (dest)); } }
static gboolean gimp_tool_preset_deserialize_property (GimpConfig *config, guint property_id, GValue *value, GParamSpec *pspec, GScanner *scanner, GTokenType *expected) { GimpToolPreset *tool_preset = GIMP_TOOL_PRESET (config); switch (property_id) { case PROP_TOOL_OPTIONS: { GObject *options; gchar *type_name; GType type; GimpContextPropMask serialize_props; if (! gimp_scanner_parse_string (scanner, &type_name)) { *expected = G_TOKEN_STRING; break; } type = g_type_from_name (type_name); if (! type) { g_scanner_error (scanner, "unable to determine type of '%s'", type_name); *expected = G_TOKEN_STRING; g_free (type_name); break; } if (! g_type_is_a (type, GIMP_TYPE_TOOL_OPTIONS)) { g_scanner_error (scanner, "'%s' is not a subclass of GimpToolOptions", type_name); *expected = G_TOKEN_STRING; g_free (type_name); break; } g_free (type_name); options = g_object_new (type, "gimp", tool_preset->gimp, NULL); /* Initialize all GimpContext object properties that can be * used by presets with some non-NULL object, so loading a * broken preset won't leave us with NULL objects that have * bad effects. See bug #742159. */ gimp_context_copy_properties (gimp_get_user_context (tool_preset->gimp), GIMP_CONTEXT (options), GIMP_CONTEXT_BRUSH_MASK | GIMP_CONTEXT_DYNAMICS_MASK | GIMP_CONTEXT_PATTERN_MASK | GIMP_CONTEXT_GRADIENT_MASK | GIMP_CONTEXT_PALETTE_MASK | GIMP_CONTEXT_FONT_MASK); if (! GIMP_CONFIG_GET_INTERFACE (options)->deserialize (GIMP_CONFIG (options), scanner, 1, NULL)) { g_object_unref (options); break; } /* we need both tool and tool-info on the options */ if (gimp_context_get_tool (GIMP_CONTEXT (options))) { g_object_set (options, "tool-info", gimp_context_get_tool (GIMP_CONTEXT (options)), NULL); } else if (GIMP_TOOL_OPTIONS (options)->tool_info) { g_object_set (options, "tool", GIMP_TOOL_OPTIONS (options)->tool_info, NULL); } else { /* if we have none, the options set_property() logic will * replace the NULL with its best guess */ g_object_set (options, "tool", NULL, "tool-info", NULL, NULL); } serialize_props = gimp_context_get_serialize_properties (GIMP_CONTEXT (options)); gimp_context_set_serialize_properties (GIMP_CONTEXT (options), serialize_props | GIMP_CONTEXT_TOOL_MASK); g_value_take_object (value, options); } break; default: return FALSE; } return TRUE; }