From 8fd67e0e95b7436d347f105ae4dd8fbb59c4b319 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Sat, 10 Mar 2007 21:22:22 +0000 Subject: [PATCH] cache the result of gimp_plug_in_procedure_get_label() and made the return 2007-03-10 Sven Neumann * app/plug-in/gimppluginprocedure.[ch]: cache the result of gimp_plug_in_procedure_get_label() and made the return value const. * app/actions/plug-in-actions.c * app/plug-in/gimpplugin-cleanup.c * app/plug-in/gimppluginmanager.c * app/widgets/gimpfiledialog.c * app/widgets/gimpfileprocview.c * app/widgets/gimpimagepropview.c: changed accordingly. * app/file/file-open.c * app/file/file-save.c: include the plug-in name (or actually the label) in the error messages. svn path=/trunk/; revision=22095 --- ChangeLog | 17 +++++++++++++++++ app/actions/plug-in-actions.c | 17 +++++------------ app/file/file-open.c | 8 +++++--- app/file/file-save.c | 3 ++- app/plug-in/gimpplugin-cleanup.c | 9 +++------ app/plug-in/gimppluginmanager.c | 13 +++++-------- app/plug-in/gimppluginprocedure.c | 13 ++++++++++--- app/plug-in/gimppluginprocedure.h | 3 ++- app/widgets/gimpfiledialog.c | 5 +---- app/widgets/gimpfileprocview.c | 8 +++----- app/widgets/gimpimagepropview.c | 7 ++----- 11 files changed, 55 insertions(+), 48 deletions(-) diff --git a/ChangeLog b/ChangeLog index af7efe7706..be1a025aff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2007-03-10 Sven Neumann + + * app/plug-in/gimppluginprocedure.[ch]: cache the result of + gimp_plug_in_procedure_get_label() and made the return value const. + + + * app/actions/plug-in-actions.c + * app/plug-in/gimpplugin-cleanup.c + * app/plug-in/gimppluginmanager.c + * app/widgets/gimpfiledialog.c + * app/widgets/gimpfileprocview.c + * app/widgets/gimpimagepropview.c: changed accordingly. + + * app/file/file-open.c + * app/file/file-save.c: include the plug-in name (or actually the + label) in the error messages. + 2007-03-10 Michael Natterer * app/core/core-types.h: don't include libgimpmath/gimpmathtypes.h diff --git a/app/actions/plug-in-actions.c b/app/actions/plug-in-actions.c index 7320801f57..05ac9b9803 100644 --- a/app/actions/plug-in-actions.c +++ b/app/actions/plug-in-actions.c @@ -495,17 +495,15 @@ plug_in_actions_history_changed (GimpPlugInManager *manager, if (proc) { - gchar *label; - gchar *repeat; - gchar *reshow; + const gchar *label; + gchar *repeat; + gchar *reshow; label = gimp_plug_in_procedure_get_label (proc); repeat = g_strdup_printf (_("Re_peat \"%s\""), label); reshow = g_strdup_printf (_("R_e-Show \"%s\""), label); - g_free (label); - gimp_action_group_set_action_label (group, "plug-in-repeat", repeat); gimp_action_group_set_action_label (group, "plug-in-reshow", reshow); @@ -523,25 +521,20 @@ plug_in_actions_history_changed (GimpPlugInManager *manager, for (i = 0; i < gimp_plug_in_manager_history_length (manager); i++) { GtkAction *action; - gchar *name = g_strdup_printf ("plug-in-recent-%02d", i + 1); - gchar *label; + gchar *name = g_strdup_printf ("plug-in-recent-%02d", i + 1); action = gtk_action_group_get_action (GTK_ACTION_GROUP (group), name); g_free (name); proc = gimp_plug_in_manager_history_nth (manager, i); - label = gimp_plug_in_procedure_get_label (proc); - g_object_set (action, "visible", TRUE, "procedure", proc, - "label", label, + "label", gimp_plug_in_procedure_get_label (proc), "stock-id", gimp_plug_in_procedure_get_stock_id (proc), "tooltip", gimp_plug_in_procedure_get_blurb (proc), NULL); - - g_free (label); } for (; i < gimp_plug_in_manager_history_size (manager); i++) diff --git a/app/file/file-open.c b/app/file/file-open.c index 90a9c6896f..51e03e5313 100644 --- a/app/file/file-open.c +++ b/app/file/file-open.c @@ -166,15 +166,17 @@ file_open_image (Gimp *gimp, else { g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, - _("Plug-In returned SUCCESS but did not " - "return an image")); + _("%s plug-in returned SUCCESS but did not " + "return an image"), + gimp_plug_in_procedure_get_label (file_proc)); *status = GIMP_PDB_EXECUTION_ERROR; } } else if (*status != GIMP_PDB_CANCEL) { g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, - _("Plug-In could not open image")); + _("%s plug-In could not open image"), + gimp_plug_in_procedure_get_label (file_proc)); } g_value_array_free (return_vals); diff --git a/app/file/file-save.c b/app/file/file-save.c index 137345fa5f..d25e723d47 100644 --- a/app/file/file-save.c +++ b/app/file/file-save.c @@ -190,7 +190,8 @@ file_save (GimpImage *image, else if (status != GIMP_PDB_CANCEL) { g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, - _("Plug-In could not save image")); + _("%s plug-in could not save image"), + gimp_plug_in_procedure_get_label (file_proc)); } g_object_unref (image); diff --git a/app/plug-in/gimpplugin-cleanup.c b/app/plug-in/gimpplugin-cleanup.c index aa9360cba7..0e7d151d9b 100644 --- a/app/plug-in/gimpplugin-cleanup.c +++ b/app/plug-in/gimpplugin-cleanup.c @@ -159,14 +159,11 @@ gimp_plug_in_cleanup (GimpPlugIn *plug_in, if (cleanup->undo_group_count != image->group_count) { - gchar *label; - - label = gimp_plug_in_procedure_get_label (GIMP_PLUG_IN_PROCEDURE (proc_frame->procedure)); + GimpProcedure *proc = proc_frame->procedure; g_message ("Plug-In '%s' left image undo in inconsistent state, " - "closing open undo groups.", label); - - g_free (label); + "closing open undo groups.", + gimp_plug_in_procedure_get_label (GIMP_PLUG_IN_PROCEDURE (proc))); while (image->pushing_undo_group != GIMP_UNDO_GROUP_NONE && cleanup->undo_group_count < image->group_count) diff --git a/app/plug-in/gimppluginmanager.c b/app/plug-in/gimppluginmanager.c index 51bd111d77..0899cfe4fc 100644 --- a/app/plug-in/gimppluginmanager.c +++ b/app/plug-in/gimppluginmanager.c @@ -955,11 +955,11 @@ gimp_plug_in_manager_file_proc_compare (gconstpointer a, gconstpointer b, gpointer data) { - const GimpPlugInProcedure *proc_a = a; - const GimpPlugInProcedure *proc_b = b; - gchar *label_a; - gchar *label_b; - gint retval = 0; + GimpPlugInProcedure *proc_a = GIMP_PLUG_IN_PROCEDURE (a); + GimpPlugInProcedure *proc_b = GIMP_PLUG_IN_PROCEDURE (b); + const gchar *label_a; + const gchar *label_b; + gint retval = 0; if (g_str_has_prefix (proc_a->prog, "gimp-xcf")) return -1; @@ -973,8 +973,5 @@ gimp_plug_in_manager_file_proc_compare (gconstpointer a, if (label_a && label_b) retval = g_utf8_collate (label_a, label_b); - g_free (label_a); - g_free (label_b); - return retval; } diff --git a/app/plug-in/gimppluginprocedure.c b/app/plug-in/gimppluginprocedure.c index e1e5deca62..98ad960da4 100644 --- a/app/plug-in/gimppluginprocedure.c +++ b/app/plug-in/gimppluginprocedure.c @@ -124,6 +124,8 @@ gimp_plug_in_procedure_finalize (GObject *object) g_list_foreach (proc->menu_paths, (GFunc) g_free, NULL); g_list_free (proc->menu_paths); + g_free (proc->label); + g_free (proc->icon_data); g_free (proc->image_types); @@ -518,8 +520,8 @@ gimp_plug_in_procedure_add_menu_path (GimpPlugInProcedure *proc, return FALSE; } -gchar * -gimp_plug_in_procedure_get_label (const GimpPlugInProcedure *proc) +const gchar * +gimp_plug_in_procedure_get_label (GimpPlugInProcedure *proc) { const gchar *path; gchar *stripped; @@ -528,6 +530,9 @@ gimp_plug_in_procedure_get_label (const GimpPlugInProcedure *proc) g_return_val_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc), NULL); + if (proc->label) + return proc->label; + if (proc->menu_label) path = dgettext (proc->locale_domain, proc->menu_label); else if (proc->menu_paths) @@ -552,7 +557,9 @@ gimp_plug_in_procedure_get_label (const GimpPlugInProcedure *proc) if (ellipsis && ellipsis == (label + strlen (label) - 3)) *ellipsis = '\0'; - return label; + proc->label = label; + + return proc->label; } const gchar * diff --git a/app/plug-in/gimppluginprocedure.h b/app/plug-in/gimppluginprocedure.h index 5f3b2be947..34716bdfec 100644 --- a/app/plug-in/gimppluginprocedure.h +++ b/app/plug-in/gimppluginprocedure.h @@ -48,6 +48,7 @@ struct _GimpPlugInProcedure gchar *help_domain; gchar *menu_label; GList *menu_paths; + gchar *label; GimpIconType icon_type; gint icon_data_length; guint8 *icon_data; @@ -103,7 +104,7 @@ gboolean gimp_plug_in_procedure_add_menu_path (GimpPlugInProcedure const gchar *menu_path, GError **error); -gchar * gimp_plug_in_procedure_get_label (const GimpPlugInProcedure *proc); +const gchar * gimp_plug_in_procedure_get_label (GimpPlugInProcedure *proc); const gchar * gimp_plug_in_procedure_get_blurb (const GimpPlugInProcedure *proc); void gimp_plug_in_procedure_set_icon (GimpPlugInProcedure *proc, diff --git a/app/widgets/gimpfiledialog.c b/app/widgets/gimpfiledialog.c index 555959efec..63e1891b65 100644 --- a/app/widgets/gimpfiledialog.c +++ b/app/widgets/gimpfiledialog.c @@ -535,14 +535,11 @@ gimp_file_dialog_add_filters (GimpFileDialog *dialog, if (file_proc->extensions_list) { GtkFileFilter *filter = gtk_file_filter_new (); - gchar *label; GString *str; GSList *ext; gint i; - label = gimp_plug_in_procedure_get_label (file_proc); - str = g_string_new (label); - g_free (label); + str = g_string_new (gimp_plug_in_procedure_get_label (file_proc)); /* an arbitrary limit to keep the file dialog from becoming too wide */ #define MAX_EXTENSIONS 4 diff --git a/app/widgets/gimpfileprocview.c b/app/widgets/gimpfileprocview.c index 7ac25ddce6..4d94277d54 100644 --- a/app/widgets/gimpfileprocview.c +++ b/app/widgets/gimpfileprocview.c @@ -139,9 +139,9 @@ gimp_file_proc_view_new (Gimp *gimp, if (! proc->prefixes_list) /* skip URL loaders */ { - gchar *label = gimp_plug_in_procedure_get_label (proc); - gchar *help_id = gimp_plug_in_procedure_get_help_id (proc); - GSList *list2; + const gchar *label = gimp_plug_in_procedure_get_label (proc); + gchar *help_id = gimp_plug_in_procedure_get_help_id (proc); + GSList *list2; if (label) { @@ -152,8 +152,6 @@ gimp_file_proc_view_new (Gimp *gimp, COLUMN_EXTENSIONS, proc->extensions, COLUMN_HELP_ID, help_id, -1); - - g_free (label); } g_free (help_id); diff --git a/app/widgets/gimpimagepropview.c b/app/widgets/gimpimagepropview.c index 8518284f72..f2ee8178af 100644 --- a/app/widgets/gimpimagepropview.c +++ b/app/widgets/gimpimagepropview.c @@ -363,7 +363,6 @@ gimp_image_prop_view_label_set_filetype (GtkWidget *label, { GimpPlugInManager *manager = image->gimp->plug_in_manager; GimpPlugInProcedure *proc; - gchar *text; proc = gimp_image_get_save_proc (image); if (! proc) @@ -377,10 +376,8 @@ gimp_image_prop_view_label_set_filetype (GtkWidget *label, } } - text = proc ? gimp_plug_in_procedure_get_label (proc) : NULL; - - gtk_label_set_text (GTK_LABEL (label), text); - g_free (text); + gtk_label_set_text (GTK_LABEL (label), + proc ? gimp_plug_in_procedure_get_label (proc) : NULL); } static void