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.
This commit is contained in:
Michael Natterer
2014-04-04 17:09:54 +02:00
parent 40d42d113e
commit 661317f74c
4 changed files with 47 additions and 76 deletions

View File

@ -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);

View File

@ -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");
* </programlisting></informalexample>
*
* 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));
}

View File

@ -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);

View File

@ -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;