libgimpcolor: add gimp_lcms_profile_get_label()

which returns a string meant to label the profile in the GUI, it's
either the profile's description, its model, or "(unnamed profile)" as
a fallback. Use the function instead of duplicating that logic
inconsistently and imcompletely all over the place.
This commit is contained in:
Michael Natterer 2014-03-30 03:12:42 +02:00
parent 67391f6d9e
commit d7037650df
9 changed files with 75 additions and 86 deletions

View file

@ -792,10 +792,7 @@ prefs_profile_combo_box_set_active (GimpColorProfileComboBox *combo,
if (profile) if (profile)
{ {
label = gimp_lcms_profile_get_description (profile); label = gimp_lcms_profile_get_label (profile);
if (! label)
label = gimp_lcms_profile_get_model (profile);
cmsCloseProfile (profile); cmsCloseProfile (profile);
} }

View file

@ -40,6 +40,7 @@ EXPORTS
gimp_lcms_create_srgb_profile gimp_lcms_create_srgb_profile
gimp_lcms_profile_get_copyright gimp_lcms_profile_get_copyright
gimp_lcms_profile_get_description gimp_lcms_profile_get_description
gimp_lcms_profile_get_label
gimp_lcms_profile_get_manufacturer gimp_lcms_profile_get_manufacturer
gimp_lcms_profile_get_model gimp_lcms_profile_get_model
gimp_lcms_profile_get_summary gimp_lcms_profile_get_summary

View file

@ -161,6 +161,36 @@ gimp_lcms_profile_get_copyright (GimpColorProfile profile)
return gimp_lcms_profile_get_info (profile, cmsInfoCopyright); return gimp_lcms_profile_get_info (profile, cmsInfoCopyright);
} }
gchar *
gimp_lcms_profile_get_label (GimpColorProfile profile)
{
gchar *label;
g_return_val_if_fail (profile != NULL, NULL);
label = gimp_lcms_profile_get_description (profile);
if (label && ! strlen (label))
{
g_free (label);
label = NULL;
}
if (! label)
label = gimp_lcms_profile_get_model (profile);
if (label && ! strlen (label))
{
g_free (label);
label = NULL;
}
if (! label)
label = g_strdup (_("(unnamed profile)"));
return label;
}
gchar * gchar *
gimp_lcms_profile_get_summary (GimpColorProfile profile) gimp_lcms_profile_get_summary (GimpColorProfile profile)
{ {

View file

@ -46,6 +46,7 @@ gchar * gimp_lcms_profile_get_manufacturer (GimpColorProfile profil
gchar * gimp_lcms_profile_get_model (GimpColorProfile profile); gchar * gimp_lcms_profile_get_model (GimpColorProfile profile);
gchar * gimp_lcms_profile_get_copyright (GimpColorProfile profile); gchar * gimp_lcms_profile_get_copyright (GimpColorProfile profile);
gchar * gimp_lcms_profile_get_label (GimpColorProfile profile);
gchar * gimp_lcms_profile_get_summary (GimpColorProfile profile); gchar * gimp_lcms_profile_get_summary (GimpColorProfile profile);
gboolean gimp_lcms_profile_is_equal (GimpColorProfile profile1, gboolean gimp_lcms_profile_is_equal (GimpColorProfile profile1,

View file

@ -106,8 +106,7 @@ gimp_color_profile_view_set_profile (GimpColorProfileView *view,
{ {
GtkTextBuffer *buffer; GtkTextBuffer *buffer;
GtkTextIter iter; GtkTextIter iter;
gchar *desc; gchar *label;
gchar *model;
gchar *summary; gchar *summary;
g_return_if_fail (GIMP_IS_COLOR_PROFILE_VIEW (view)); g_return_if_fail (GIMP_IS_COLOR_PROFILE_VIEW (view));
@ -123,22 +122,13 @@ gimp_color_profile_view_set_profile (GimpColorProfileView *view,
gtk_text_buffer_get_start_iter (buffer, &iter); gtk_text_buffer_get_start_iter (buffer, &iter);
desc = gimp_lcms_profile_get_description (profile); label = gimp_lcms_profile_get_label (profile);
model = gimp_lcms_profile_get_model (profile);
summary = gimp_lcms_profile_get_summary (profile); summary = gimp_lcms_profile_get_summary (profile);
if ((desc && strlen (desc)) || if (label && strlen (label))
(model && strlen (model)))
{ {
gchar *title;
if (desc && strlen (desc))
title = desc;
else
title = model;
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
title, -1, label, -1,
"strong", NULL); "strong", NULL);
gtk_text_buffer_insert (buffer, &iter, "\n", 1); gtk_text_buffer_insert (buffer, &iter, "\n", 1);
} }
@ -146,8 +136,7 @@ gimp_color_profile_view_set_profile (GimpColorProfileView *view,
if (summary) if (summary)
gtk_text_buffer_insert (buffer, &iter, summary, -1); gtk_text_buffer_insert (buffer, &iter, summary, -1);
g_free (desc); g_free (label);
g_free (model);
g_free (summary); g_free (summary);
} }

View file

@ -379,7 +379,7 @@ colorsel_cmyk_config_changed (ColorselCmyk *module)
cmsUInt32Number flags = 0; cmsUInt32Number flags = 0;
cmsHPROFILE rgb_profile; cmsHPROFILE rgb_profile;
cmsHPROFILE cmyk_profile; cmsHPROFILE cmyk_profile;
gchar *name; gchar *label;
gchar *summary; gchar *summary;
gchar *text; gchar *text;
@ -407,18 +407,15 @@ colorsel_cmyk_config_changed (ColorselCmyk *module)
if (! cmyk_profile) if (! cmyk_profile)
goto out; goto out;
name = gimp_lcms_profile_get_description (cmyk_profile); label = gimp_lcms_profile_get_label (cmyk_profile);
if (! name)
name = gimp_lcms_profile_get_model (cmyk_profile);
summary = gimp_lcms_profile_get_summary (cmyk_profile); summary = gimp_lcms_profile_get_summary (cmyk_profile);
text = g_strdup_printf (_("Profile: %s"), name); text = g_strdup_printf (_("Profile: %s"), label);
gtk_label_set_text (GTK_LABEL (module->name_label), text); gtk_label_set_text (GTK_LABEL (module->name_label), text);
gimp_help_set_help_data (module->name_label, summary, NULL); gimp_help_set_help_data (module->name_label, summary, NULL);
g_free (text); g_free (text);
g_free (name); g_free (label);
g_free (summary); g_free (summary);
if (config->display_intent == if (config->display_intent ==

View file

@ -167,27 +167,18 @@ cdisplay_lcms_finalize (GObject *object)
static void static void
cdisplay_lcms_profile_get_info (cmsHPROFILE profile, cdisplay_lcms_profile_get_info (cmsHPROFILE profile,
gchar **name, gchar **label,
gchar **info) gchar **summary)
{ {
if (profile) if (profile)
{ {
*name = gimp_lcms_profile_get_description (profile); *label = gimp_lcms_profile_get_label (profile);
if (! *name) *summary = gimp_lcms_profile_get_summary (profile);
*name = gimp_lcms_profile_get_model (profile);
if (! *name)
{
/* a color profile without a name */
*name = g_strdup (_("(unnamed profile)"));
}
*info = gimp_lcms_profile_get_summary (profile);
} }
else else
{ {
*name = g_strdup (_("None")); *label = g_strdup (_("None"));
*info = NULL; *summary = NULL;
} }
} }

View file

@ -271,10 +271,7 @@ cdisplay_proof_combo_box_set_active (GimpColorProfileComboBox *combo,
if (profile) if (profile)
{ {
label = gimp_lcms_profile_get_description (profile); label = gimp_lcms_profile_get_label (profile);
if (! label)
label = gimp_lcms_profile_get_model (profile);
cmsCloseProfile (profile); cmsCloseProfile (profile);
} }

View file

@ -578,18 +578,18 @@ lcms_icc_apply (GimpColorConfig *config,
if (gimp_lcms_profile_is_equal (src_profile, dest_profile)) if (gimp_lcms_profile_is_equal (src_profile, dest_profile))
{ {
gchar *src_desc = gimp_lcms_profile_get_description (src_profile); gchar *src_label = gimp_lcms_profile_get_label (src_profile);
gchar *dest_desc = gimp_lcms_profile_get_description (dest_profile); gchar *dest_label = gimp_lcms_profile_get_label (dest_profile);
cmsCloseProfile (src_profile); cmsCloseProfile (src_profile);
cmsCloseProfile (dest_profile); cmsCloseProfile (dest_profile);
g_printerr ("lcms: skipping conversion because profiles seem to be equal:\n"); g_printerr ("lcms: skipping conversion because profiles seem to be equal:\n");
g_printerr (" %s\n", src_desc); g_printerr (" %s\n", src_label);
g_printerr (" %s\n", dest_desc); g_printerr (" %s\n", dest_label);
g_free (src_desc); g_free (src_label);
g_free (dest_desc); g_free (dest_label);
return GIMP_PDB_SUCCESS; return GIMP_PDB_SUCCESS;
} }
@ -785,8 +785,8 @@ lcms_image_apply_profile (gint32 image,
GimpColorRenderingIntent intent, GimpColorRenderingIntent intent,
gboolean bpc) gboolean bpc)
{ {
gchar *src_desc; gchar *src_label;
gchar *dest_desc; gchar *dest_label;
gint32 saved_selection = -1; gint32 saved_selection = -1;
gimp_image_undo_group_start (image); gimp_image_undo_group_start (image);
@ -798,21 +798,16 @@ lcms_image_apply_profile (gint32 image,
return FALSE; return FALSE;
} }
src_desc = gimp_lcms_profile_get_description (src_profile); src_label = gimp_lcms_profile_get_label (src_profile);
if (! src_desc) dest_label = gimp_lcms_profile_get_label (dest_profile);
src_desc = gimp_lcms_profile_get_model (src_profile);
dest_desc = gimp_lcms_profile_get_description (dest_profile);
if (! dest_desc)
dest_desc = gimp_lcms_profile_get_model (dest_profile);
gimp_progress_init_printf (_("Converting from '%s' to '%s'"), gimp_progress_init_printf (_("Converting from '%s' to '%s'"),
src_desc, dest_desc); src_label, dest_label);
g_printerr ("lcms: converting from '%s' to '%s'\n", src_desc, dest_desc); g_printerr ("lcms: converting from '%s' to '%s'\n", src_label, dest_label);
g_free (dest_desc); g_free (dest_label);
g_free (src_desc); g_free (src_label);
if (! gimp_selection_is_empty (image)) if (! gimp_selection_is_empty (image))
{ {
@ -1079,7 +1074,6 @@ lcms_icc_profile_src_label_new (gint32 image,
GtkWidget *vbox; GtkWidget *vbox;
GtkWidget *label; GtkWidget *label;
gchar *name; gchar *name;
gchar *desc;
gchar *text; gchar *text;
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
@ -1101,16 +1095,16 @@ lcms_icc_profile_src_label_new (gint32 image,
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
gtk_widget_show (label); gtk_widget_show (label);
desc = gimp_lcms_profile_get_description (profile); name = gimp_lcms_profile_get_label (profile);
label = g_object_new (GTK_TYPE_LABEL, label = g_object_new (GTK_TYPE_LABEL,
"label", desc, "label", name,
"wrap", TRUE, "wrap", TRUE,
"justify", GTK_JUSTIFY_LEFT, "justify", GTK_JUSTIFY_LEFT,
"xalign", 0.0, "xalign", 0.0,
"yalign", 0.0, "yalign", 0.0,
"xpad", 24, "xpad", 24,
NULL); NULL);
g_free (desc); g_free (name);
gimp_label_set_attributes (GTK_LABEL (label), gimp_label_set_attributes (GTK_LABEL (label),
PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD, PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD,
@ -1125,13 +1119,13 @@ static GtkWidget *
lcms_icc_profile_dest_label_new (cmsHPROFILE profile) lcms_icc_profile_dest_label_new (cmsHPROFILE profile)
{ {
GtkWidget *label; GtkWidget *label;
gchar *desc; gchar *name;
gchar *text; gchar *text;
desc = gimp_lcms_profile_get_description (profile); name = gimp_lcms_profile_get_label (profile);
text = g_strdup_printf (_("Convert the image to the RGB working space (%s)?"), text = g_strdup_printf (_("Convert the image to the RGB working space (%s)?"),
desc); name);
g_free (desc); g_free (name);
label = g_object_new (GTK_TYPE_LABEL, label = g_object_new (GTK_TYPE_LABEL,
"label", text, "label", text,
@ -1238,10 +1232,7 @@ lcms_icc_combo_box_set_active (GimpColorProfileComboBox *combo,
if (profile) if (profile)
{ {
label = gimp_lcms_profile_get_description (profile); label = gimp_lcms_profile_get_label (profile);
if (! label)
label = gimp_lcms_profile_get_model (profile);
cmsCloseProfile (profile); cmsCloseProfile (profile);
} }
@ -1319,15 +1310,12 @@ lcms_icc_combo_box_new (GimpColorConfig *config,
if (! profile) if (! profile)
profile = gimp_lcms_create_srgb_profile (); profile = gimp_lcms_create_srgb_profile ();
name = gimp_lcms_profile_get_description (profile); name = gimp_lcms_profile_get_label (profile);
if (! name)
name = gimp_lcms_profile_get_model (profile);
cmsCloseProfile (profile);
label = g_strdup_printf (_("RGB workspace (%s)"), name); label = g_strdup_printf (_("RGB workspace (%s)"), name);
g_free (name); g_free (name);
cmsCloseProfile (profile);
gimp_color_profile_combo_box_add (GIMP_COLOR_PROFILE_COMBO_BOX (combo), gimp_color_profile_combo_box_add (GIMP_COLOR_PROFILE_COMBO_BOX (combo),
rgb_filename, label); rgb_filename, label);
g_free (label); g_free (label);
@ -1404,9 +1392,7 @@ lcms_dialog (GimpColorConfig *config,
gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame); gtk_widget_show (frame);
name = gimp_lcms_profile_get_description (src_profile); name = gimp_lcms_profile_get_label (src_profile);
if (! name)
name = gimp_lcms_profile_get_model (src_profile);
label = gtk_label_new (name); label = gtk_label_new (name);
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);