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.
This commit is contained in:
Michael Natterer 2014-04-02 13:03:52 +02:00
parent 80a71f1e50
commit 3f826d02fa
4 changed files with 44 additions and 86 deletions

View File

@ -19,10 +19,6 @@
#include <string.h> #include <string.h>
#include <glib.h> /* lcms.h uses the "inline" keyword */
#include <lcms2.h>
#include <gegl.h> #include <gegl.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
@ -780,26 +776,6 @@ prefs_table_new (gint rows,
return table; 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 static void
prefs_profile_combo_dialog_response (GimpColorProfileChooserDialog *dialog, prefs_profile_combo_dialog_response (GimpColorProfileChooserDialog *dialog,
gint response, gint response,
@ -813,7 +789,7 @@ prefs_profile_combo_dialog_response (GimpColorProfileChooserDialog *dialog,
if (filename) if (filename)
{ {
prefs_profile_combo_box_set_active (combo, filename); gimp_color_profile_combo_box_set_active (combo, filename, NULL);
g_free (filename); g_free (filename);
} }

View File

@ -21,8 +21,15 @@
#include "config.h" #include "config.h"
#include <glib.h> /* lcms.h uses the "inline" keyword */
#include <lcms2.h>
#include <gegl.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include "libgimpcolor/gimpcolor.h"
#include "gimpwidgetstypes.h" #include "gimpwidgetstypes.h"
#include "gimpcolorprofilecombobox.h" #include "gimpcolorprofilecombobox.h"
@ -388,14 +395,42 @@ gimp_color_profile_combo_box_set_active (GimpColorProfileComboBox *combo,
{ {
GtkTreeModel *model; GtkTreeModel *model;
GtkTreeIter iter; GtkTreeIter iter;
gchar *l = NULL;
g_return_if_fail (GIMP_IS_COLOR_PROFILE_COMBO_BOX (combo)); g_return_if_fail (GIMP_IS_COLOR_PROFILE_COMBO_BOX (combo));
model = gtk_combo_box_get_model (GTK_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), if (_gimp_color_profile_store_history_add (GIMP_COLOR_PROFILE_STORE (model),
filename, label, &iter)) filename, l, &iter))
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &iter); {
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &iter);
}
g_free (l);
} }
/** /**

View File

@ -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 static void
cdisplay_proof_file_chooser_dialog_response (GtkFileChooser *dialog, cdisplay_proof_file_chooser_dialog_response (GtkFileChooser *dialog,
gint response, gint response,
@ -290,7 +270,7 @@ cdisplay_proof_file_chooser_dialog_response (GtkFileChooser *dialog,
if (filename) if (filename)
{ {
cdisplay_proof_combo_box_set_active (combo, filename); gimp_color_profile_combo_box_set_active (combo, filename, NULL);
g_free (filename); g_free (filename);
} }
@ -343,8 +323,8 @@ cdisplay_proof_configure (GimpColorDisplay *display)
proof); proof);
if (proof->profile) if (proof->profile)
cdisplay_proof_combo_box_set_active (GIMP_COLOR_PROFILE_COMBO_BOX (combo), gimp_color_profile_combo_box_set_active (GIMP_COLOR_PROFILE_COMBO_BOX (combo),
proof->profile); proof->profile, NULL);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0, gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("_Profile:"), 0.0, 0.5, _("_Profile:"), 0.0, 0.5,

View File

@ -1237,36 +1237,6 @@ lcms_icc_apply_dialog (gint32 image,
return run; 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 static void
lcms_icc_file_chooser_dialog_response (GtkFileChooser *dialog, lcms_icc_file_chooser_dialog_response (GtkFileChooser *dialog,
gint response, gint response,
@ -1278,7 +1248,7 @@ lcms_icc_file_chooser_dialog_response (GtkFileChooser *dialog,
if (filename) if (filename)
{ {
lcms_icc_combo_box_set_active (combo, filename); gimp_color_profile_combo_box_set_active (combo, filename, NULL);
g_free (filename); g_free (filename);
} }
@ -1347,11 +1317,8 @@ lcms_icc_combo_box_new (GimpColorConfig *config,
rgb_filename, label); rgb_filename, label);
g_free (label); g_free (label);
if (filename) gimp_color_profile_combo_box_set_active (GIMP_COLOR_PROFILE_COMBO_BOX (combo),
lcms_icc_combo_box_set_active (GIMP_COLOR_PROFILE_COMBO_BOX (combo), filename, NULL);
filename);
else
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
return combo; return combo;
} }