From 3f826d02faf29c71aabfab05418224e77494a391 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Wed, 2 Apr 2014 13:03:52 +0200 Subject: [PATCH] libgimpwidgets: make GimpColorProfileComboBox use lcms and improve gimp_color_profile_combo_box_set_active() to get the profile's label from the ICC file if no label was provided. Simplifies all its callers and removes code duplication. --- app/dialogs/preferences-dialog.c | 26 +-------------- libgimpwidgets/gimpcolorprofilecombobox.c | 39 +++++++++++++++++++++-- modules/display-filter-proof.c | 26 ++------------- plug-ins/common/lcms.c | 39 ++--------------------- 4 files changed, 44 insertions(+), 86 deletions(-) diff --git a/app/dialogs/preferences-dialog.c b/app/dialogs/preferences-dialog.c index e95c461cb9..816ea31fd1 100644 --- a/app/dialogs/preferences-dialog.c +++ b/app/dialogs/preferences-dialog.c @@ -19,10 +19,6 @@ #include -#include /* lcms.h uses the "inline" keyword */ - -#include - #include #include @@ -780,26 +776,6 @@ prefs_table_new (gint rows, return table; } -static void -prefs_profile_combo_box_set_active (GimpColorProfileComboBox *combo, - const gchar *filename) -{ - cmsHPROFILE profile = NULL; - gchar *label = NULL; - - if (filename) - profile = cmsOpenProfileFromFile (filename, "r"); - - if (profile) - { - label = gimp_lcms_profile_get_label (profile); - cmsCloseProfile (profile); - } - - gimp_color_profile_combo_box_set_active (combo, filename, label); - g_free (label); -} - static void prefs_profile_combo_dialog_response (GimpColorProfileChooserDialog *dialog, gint response, @@ -813,7 +789,7 @@ prefs_profile_combo_dialog_response (GimpColorProfileChooserDialog *dialog, if (filename) { - prefs_profile_combo_box_set_active (combo, filename); + gimp_color_profile_combo_box_set_active (combo, filename, NULL); g_free (filename); } diff --git a/libgimpwidgets/gimpcolorprofilecombobox.c b/libgimpwidgets/gimpcolorprofilecombobox.c index 0a1b3196f3..2878c3cb88 100644 --- a/libgimpwidgets/gimpcolorprofilecombobox.c +++ b/libgimpwidgets/gimpcolorprofilecombobox.c @@ -21,8 +21,15 @@ #include "config.h" +#include /* lcms.h uses the "inline" keyword */ + +#include + +#include #include +#include "libgimpcolor/gimpcolor.h" + #include "gimpwidgetstypes.h" #include "gimpcolorprofilecombobox.h" @@ -388,14 +395,42 @@ gimp_color_profile_combo_box_set_active (GimpColorProfileComboBox *combo, { GtkTreeModel *model; GtkTreeIter iter; + gchar *l = NULL; g_return_if_fail (GIMP_IS_COLOR_PROFILE_COMBO_BOX (combo)); model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo)); + if (filename && ! (label && *label)) + { + cmsHPROFILE profile; + GError *error = NULL; + + profile = gimp_lcms_profile_open_from_file (filename, &error); + + if (! profile) + { + g_message ("%s", error->message); + g_clear_error (&error); + } + else + { + l = gimp_lcms_profile_get_label (profile); + cmsCloseProfile (profile); + } + } + else + { + l = g_strdup (label); + } + if (_gimp_color_profile_store_history_add (GIMP_COLOR_PROFILE_STORE (model), - filename, label, &iter)) - gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &iter); + filename, l, &iter)) + { + gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &iter); + } + + g_free (l); } /** diff --git a/modules/display-filter-proof.c b/modules/display-filter-proof.c index 777310f645..5868065ad1 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_combo_box_set_active (GimpColorProfileComboBox *combo, - const gchar *filename) -{ - cmsHPROFILE profile = NULL; - gchar *label = NULL; - - if (filename) - profile = cmsOpenProfileFromFile (filename, "r"); - - if (profile) - { - label = gimp_lcms_profile_get_label (profile); - cmsCloseProfile (profile); - } - - gimp_color_profile_combo_box_set_active (combo, filename, label); - g_free (label); -} - static void cdisplay_proof_file_chooser_dialog_response (GtkFileChooser *dialog, gint response, @@ -290,7 +270,7 @@ cdisplay_proof_file_chooser_dialog_response (GtkFileChooser *dialog, if (filename) { - cdisplay_proof_combo_box_set_active (combo, filename); + gimp_color_profile_combo_box_set_active (combo, filename, NULL); g_free (filename); } @@ -343,8 +323,8 @@ cdisplay_proof_configure (GimpColorDisplay *display) proof); if (proof->profile) - cdisplay_proof_combo_box_set_active (GIMP_COLOR_PROFILE_COMBO_BOX (combo), - proof->profile); + gimp_color_profile_combo_box_set_active (GIMP_COLOR_PROFILE_COMBO_BOX (combo), + proof->profile, NULL); gimp_table_attach_aligned (GTK_TABLE (table), 0, 0, _("_Profile:"), 0.0, 0.5, diff --git a/plug-ins/common/lcms.c b/plug-ins/common/lcms.c index ce93d8418d..49b1decf1e 100644 --- a/plug-ins/common/lcms.c +++ b/plug-ins/common/lcms.c @@ -1237,36 +1237,6 @@ lcms_icc_apply_dialog (gint32 image, return run; } -static void -lcms_icc_combo_box_set_active (GimpColorProfileComboBox *combo, - const gchar *filename) -{ - cmsHPROFILE profile = NULL; - gchar *label = NULL; - - if (filename) - { - GError *error = NULL; - - profile = gimp_lcms_profile_open_from_file (filename, &error); - - if (! profile) - { - g_message ("%s", error->message); - g_clear_error (&error); - } - } - - if (profile) - { - label = gimp_lcms_profile_get_label (profile); - cmsCloseProfile (profile); - } - - gimp_color_profile_combo_box_set_active (combo, filename, label); - g_free (label); -} - static void lcms_icc_file_chooser_dialog_response (GtkFileChooser *dialog, gint response, @@ -1278,7 +1248,7 @@ lcms_icc_file_chooser_dialog_response (GtkFileChooser *dialog, if (filename) { - lcms_icc_combo_box_set_active (combo, filename); + gimp_color_profile_combo_box_set_active (combo, filename, NULL); g_free (filename); } @@ -1347,11 +1317,8 @@ lcms_icc_combo_box_new (GimpColorConfig *config, rgb_filename, label); g_free (label); - if (filename) - lcms_icc_combo_box_set_active (GIMP_COLOR_PROFILE_COMBO_BOX (combo), - filename); - else - gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0); + gimp_color_profile_combo_box_set_active (GIMP_COLOR_PROFILE_COMBO_BOX (combo), + filename, NULL); return combo; }