From 661317f74c5314d3f8617814311e9f23e3b4e60b Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Fri, 4 Apr 2014 17:09:54 +0200 Subject: [PATCH] libgimpwidgets: make using GimpColorProfileComboBox easier If the passed dialog is a GimpColorProfileChooserDialog, handle its "response" signal automatically and also destroy it when the combo box is destroyed (before we leaked all dialogs). Remove the same callback from all places using GimpColorProfileComboBox. --- app/dialogs/preferences-dialog.c | 26 ------------- libgimpwidgets/gimpcolorprofilecombobox.c | 46 +++++++++++++++++++++++ modules/display-filter-proof.c | 24 ------------ plug-ins/common/lcms.c | 27 +------------ 4 files changed, 47 insertions(+), 76 deletions(-) diff --git a/app/dialogs/preferences-dialog.c b/app/dialogs/preferences-dialog.c index 816ea31fd1..6541597a29 100644 --- a/app/dialogs/preferences-dialog.c +++ b/app/dialogs/preferences-dialog.c @@ -776,28 +776,6 @@ prefs_table_new (gint rows, return table; } -static void -prefs_profile_combo_dialog_response (GimpColorProfileChooserDialog *dialog, - gint response, - GimpColorProfileComboBox *combo) -{ - if (response == GTK_RESPONSE_ACCEPT) - { - gchar *filename; - - filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); - - if (filename) - { - gimp_color_profile_combo_box_set_active (combo, filename, NULL); - - g_free (filename); - } - } - - gtk_widget_hide (GTK_WIDGET (dialog)); -} - static void prefs_profile_combo_changed (GimpColorProfileComboBox *combo, GObject *config) @@ -855,10 +833,6 @@ prefs_profile_combo_box_new (GObject *config, g_free (filename); - g_signal_connect (dialog, "response", - G_CALLBACK (prefs_profile_combo_dialog_response), - combo); - g_signal_connect (combo, "changed", G_CALLBACK (prefs_profile_combo_changed), config); diff --git a/libgimpwidgets/gimpcolorprofilecombobox.c b/libgimpwidgets/gimpcolorprofilecombobox.c index 2878c3cb88..8a6abc447e 100644 --- a/libgimpwidgets/gimpcolorprofilecombobox.c +++ b/libgimpwidgets/gimpcolorprofilecombobox.c @@ -32,6 +32,7 @@ #include "gimpwidgetstypes.h" +#include "gimpcolorprofilechooserdialog.h" #include "gimpcolorprofilecombobox.h" #include "gimpcolorprofilestore.h" #include "gimpcolorprofilestore-private.h" @@ -80,6 +81,10 @@ static gboolean gimp_color_profile_row_separator_func (GtkTreeModel *model, GtkTreeIter *iter, gpointer data); +static void gimp_color_profile_combo_dialog_response (GimpColorProfileChooserDialog *dialog, + gint response, + GimpColorProfileComboBox *combo); + G_DEFINE_TYPE (GimpColorProfileComboBox, gimp_color_profile_combo_box, GTK_TYPE_COMBO_BOX) @@ -162,6 +167,9 @@ gimp_color_profile_combo_box_finalize (GObject *object) if (combo->dialog) { + if (GIMP_IS_COLOR_PROFILE_CHOOSER_DIALOG (combo->dialog)) + gtk_widget_destroy (combo->dialog); + g_object_unref (combo->dialog); combo->dialog = NULL; } @@ -190,6 +198,11 @@ gimp_color_profile_combo_box_set_property (GObject *object, case PROP_DIALOG: g_return_if_fail (combo_box->dialog == NULL); combo_box->dialog = g_value_dup_object (value); + + if (GIMP_IS_COLOR_PROFILE_CHOOSER_DIALOG (combo_box->dialog)) + g_signal_connect (combo_box->dialog, "response", + G_CALLBACK (gimp_color_profile_combo_dialog_response), + combo_box); break; case PROP_MODEL: @@ -296,6 +309,17 @@ gimp_color_profile_combo_box_changed (GtkComboBox *combo) * gchar *history = gimp_personal_rc_file ("profilerc"); * * + * The recommended @dialog type to use is a #GimpColorProfileChooserDialog. + * If a #GimpColorProfileChooserDialog is passed, #GimpColorProfileComboBox + * will take complete control over the dialog, which means connecting + * a GtkDialog::response() callback by itself, and take care of destroying + * the dialog when the combo box is destroyed. + * + * If another type of @dialog is passed, this has to be implemented + * separately. + * + * See also gimp_color_profile_combo_box_new_with_model(). + * * Return value: a new #GimpColorProfileComboBox. * * Since: GIMP 2.4 @@ -493,3 +517,25 @@ gimp_color_profile_row_separator_func (GtkTreeModel *model, return FALSE; } } + +static void +gimp_color_profile_combo_dialog_response (GimpColorProfileChooserDialog *dialog, + gint response, + GimpColorProfileComboBox *combo) +{ + if (response == GTK_RESPONSE_ACCEPT) + { + gchar *filename; + + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); + + if (filename) + { + gimp_color_profile_combo_box_set_active (combo, filename, NULL); + + g_free (filename); + } + } + + gtk_widget_hide (GTK_WIDGET (dialog)); +} diff --git a/modules/display-filter-proof.c b/modules/display-filter-proof.c index 5868065ad1..839c0a518d 100644 --- a/modules/display-filter-proof.c +++ b/modules/display-filter-proof.c @@ -259,26 +259,6 @@ cdisplay_proof_convert_buffer (GimpColorDisplay *display, } } -static void -cdisplay_proof_file_chooser_dialog_response (GtkFileChooser *dialog, - gint response, - GimpColorProfileComboBox *combo) -{ - if (response == GTK_RESPONSE_ACCEPT) - { - gchar *filename = gtk_file_chooser_get_filename (dialog); - - if (filename) - { - gimp_color_profile_combo_box_set_active (combo, filename, NULL); - - g_free (filename); - } - } - - gtk_widget_hide (GTK_WIDGET (dialog)); -} - static void cdisplay_proof_profile_changed (GtkWidget *combo, CdisplayProof *proof) @@ -314,10 +294,6 @@ cdisplay_proof_configure (GimpColorDisplay *display) combo = gimp_color_profile_combo_box_new (dialog, history); g_free (history); - g_signal_connect (dialog, "response", - G_CALLBACK (cdisplay_proof_file_chooser_dialog_response), - combo); - g_signal_connect (combo, "changed", G_CALLBACK (cdisplay_proof_profile_changed), proof); diff --git a/plug-ins/common/lcms.c b/plug-ins/common/lcms.c index 49b1decf1e..68ba4395e6 100644 --- a/plug-ins/common/lcms.c +++ b/plug-ins/common/lcms.c @@ -1237,26 +1237,6 @@ lcms_icc_apply_dialog (gint32 image, return run; } -static void -lcms_icc_file_chooser_dialog_response (GtkFileChooser *dialog, - gint response, - GimpColorProfileComboBox *combo) -{ - if (response == GTK_RESPONSE_ACCEPT) - { - gchar *filename = gtk_file_chooser_get_filename (dialog); - - if (filename) - { - gimp_color_profile_combo_box_set_active (combo, filename, NULL); - - g_free (filename); - } - } - - gtk_widget_hide (GTK_WIDGET (dialog)); -} - static GtkWidget * lcms_icc_combo_box_new (GimpColorConfig *config, const gchar *filename) @@ -1270,16 +1250,11 @@ lcms_icc_combo_box_new (GimpColorConfig *config, cmsHPROFILE profile = NULL; dialog = gimp_color_profile_chooser_dialog_new (_("Select destination profile")); + history = gimp_personal_rc_file ("profilerc"); - combo = gimp_color_profile_combo_box_new (dialog, history); - g_free (history); - g_signal_connect (dialog, "response", - G_CALLBACK (lcms_icc_file_chooser_dialog_response), - combo); - if (config->rgb_profile) { GError *error = NULL;