[gimp] libgimpwidgets: make GimpColorProfileComboBox use lcms



commit 3f826d02faf29c71aabfab05418224e77494a391
Author: Michael Natterer <mitch gimp org>
Date:   Wed Apr 2 13:03:52 2014 +0200

    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 e95c461..816ea31 100644
--- a/app/dialogs/preferences-dialog.c
+++ b/app/dialogs/preferences-dialog.c
@@ -19,10 +19,6 @@
 
 #include <string.h>
 
-#include <glib.h>  /* lcms.h uses the "inline" keyword */
-
-#include <lcms2.h>
-
 #include <gegl.h>
 #include <gtk/gtk.h>
 
@@ -781,26 +777,6 @@ prefs_table_new (gint          rows,
 }
 
 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,
                                      GimpColorProfileComboBox      *combo)
@@ -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 0a1b319..2878c3c 100644
--- a/libgimpwidgets/gimpcolorprofilecombobox.c
+++ b/libgimpwidgets/gimpcolorprofilecombobox.c
@@ -21,8 +21,15 @@
 
 #include "config.h"
 
+#include <glib.h>  /* lcms.h uses the "inline" keyword */
+
+#include <lcms2.h>
+
+#include <gegl.h>
 #include <gtk/gtk.h>
 
+#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 777310f..5868065 100644
--- a/modules/display-filter-proof.c
+++ b/modules/display-filter-proof.c
@@ -260,26 +260,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,
                                              GimpColorProfileComboBox *combo)
@@ -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 ce93d84..49b1dec 100644
--- a/plug-ins/common/lcms.c
+++ b/plug-ins/common/lcms.c
@@ -1238,36 +1238,6 @@ lcms_icc_apply_dialog (gint32       image,
 }
 
 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,
                                        GimpColorProfileComboBox *combo)
@@ -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;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]