Commit 0693298d authored by Michael Natterer's avatar Michael Natterer 😴

libgimpcolor, *: change all GimpColorConfig getters to return const gchar*

instead of a gchar* which has to be freed. Cache all the strings in
the GimpColorConfig instance.
parent 6f81975b
......@@ -292,8 +292,6 @@ gimp_image_convert_color_profile (GimpImage *image,
GimpColorProfile *src_profile;
GimpColorProfile *builtin_profile;
const Babl *layer_format;
gchar *src_label;
gchar *dest_label;
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
g_return_val_if_fail (dest_profile != NULL, FALSE);
......@@ -311,16 +309,11 @@ gimp_image_convert_color_profile (GimpImage *image,
return TRUE;
}
src_label = gimp_color_profile_get_label (src_profile);
dest_label = gimp_color_profile_get_label (dest_profile);
if (progress)
gimp_progress_start (progress, FALSE,
_("Converting from '%s' to '%s'"),
src_label, dest_label);
g_free (dest_label);
g_free (src_label);
gimp_color_profile_get_label (src_profile),
gimp_color_profile_get_label (dest_profile));
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_CONVERT,
_("Color profile conversion"));
......
......@@ -1884,9 +1884,9 @@ plug_in_icc_profile_info_invoker (GimpProcedure *procedure,
profile = gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (image));
profile_name = gimp_color_profile_get_model (profile);
profile_desc = gimp_color_profile_get_description (profile);
profile_info = gimp_color_profile_get_summary (profile);
profile_name = g_strdup (gimp_color_profile_get_model (profile));
profile_desc = g_strdup (gimp_color_profile_get_description (profile));
profile_info = g_strdup (gimp_color_profile_get_summary (profile));
g_object_unref (profile);
......@@ -1935,9 +1935,9 @@ plug_in_icc_profile_file_info_invoker (GimpProcedure *procedure,
if (p)
{
profile_name = gimp_color_profile_get_model (p);
profile_desc = gimp_color_profile_get_description (p);
profile_info = gimp_color_profile_get_summary (p);
profile_name = g_strdup (gimp_color_profile_get_model (p));
profile_desc = g_strdup (gimp_color_profile_get_description (p));
profile_info = g_strdup (gimp_color_profile_get_summary (p));
g_object_unref (p);
}
......
......@@ -60,6 +60,13 @@ struct _GimpColorProfilePrivate
cmsHPROFILE lcms_profile;
guint8 *data;
gsize length;
gchar *description;
gchar *manufacturer;
gchar *model;
gchar *copyright;
gchar *label;
gchar *summary;
};
......@@ -119,6 +126,13 @@ gimp_color_profile_finalize (GObject *object)
profile->priv->length = 0;
}
g_free (profile->priv->description);
g_free (profile->priv->manufacturer);
g_free (profile->priv->model);
g_free (profile->priv->copyright);
g_free (profile->priv->label);
g_free (profile->priv->summary);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
......@@ -376,8 +390,6 @@ gimp_color_profile_get_info (GimpColorProfile *profile,
cmsUInt32Number size;
gchar *text = NULL;
g_return_val_if_fail (GIMP_IS_COLOR_PROFILE (profile), NULL);
size = cmsGetProfileInfoASCII (profile->priv->lcms_profile, info,
"en", "US", NULL, 0);
if (size > 0)
......@@ -399,165 +411,181 @@ gimp_color_profile_get_info (GimpColorProfile *profile,
* gimp_color_profile_get_description:
* @profile: a #GimpColorProfile
*
* Return value: a newly allocated string containing @profile's
* description. Free with g_free().
* Return value: a string containing @profile's description. The
* returned value belongs to @profile and must not be
* modified or freed.
*
* Since: 2.10
**/
gchar *
const gchar *
gimp_color_profile_get_description (GimpColorProfile *profile)
{
return gimp_color_profile_get_info (profile, cmsInfoDescription);
g_return_val_if_fail (GIMP_IS_COLOR_PROFILE (profile), NULL);
if (! profile->priv->description)
profile->priv->description =
gimp_color_profile_get_info (profile, cmsInfoDescription);
return profile->priv->description;
}
/**
* gimp_color_profile_get_manufacturer:
* @profile: a #GimpColorProfile
*
* Return value: a newly allocated string containing @profile's
* manufacturer. Free with g_free().
* Return value: a string containing @profile's manufacturer. The
* returned value belongs to @profile and must not be
* modified or freed.
*
* Since: 2.10
**/
gchar *
const gchar *
gimp_color_profile_get_manufacturer (GimpColorProfile *profile)
{
return gimp_color_profile_get_info (profile, cmsInfoManufacturer);
g_return_val_if_fail (GIMP_IS_COLOR_PROFILE (profile), NULL);
if (! profile->priv->manufacturer)
profile->priv->manufacturer =
gimp_color_profile_get_info (profile, cmsInfoManufacturer);
return profile->priv->manufacturer;
}
/**
* gimp_color_profile_get_model:
* @profile: a #GimpColorProfile
*
* Return value: a newly allocated string containing @profile's
* model. Free with g_free().
* Return value: a string containing @profile's model. The returned
* value belongs to @profile and must not be modified or
* freed.
*
* Since: 2.10
**/
gchar *
const gchar *
gimp_color_profile_get_model (GimpColorProfile *profile)
{
return gimp_color_profile_get_info (profile, cmsInfoModel);
g_return_val_if_fail (GIMP_IS_COLOR_PROFILE (profile), NULL);
if (! profile->priv->model)
profile->priv->model =
gimp_color_profile_get_info (profile, cmsInfoModel);
return profile->priv->model;
}
/**
* gimp_color_profile_get_copyright:
* @profile: a #GimpColorProfile
*
* Return value: a newly allocated string containing @profile's
* copyright. Free with g_free().
* Return value: a string containing @profile's copyright. The
* returned value belongs to @profile and must not be
* modified or freed.
*
* Since: 2.10
**/
gchar *
const gchar *
gimp_color_profile_get_copyright (GimpColorProfile *profile)
{
return gimp_color_profile_get_info (profile, cmsInfoCopyright);
g_return_val_if_fail (GIMP_IS_COLOR_PROFILE (profile), NULL);
if (! profile->priv->copyright)
profile->priv->copyright =
gimp_color_profile_get_info (profile, cmsInfoCopyright);
return profile->priv->copyright;
}
/**
* gimp_color_profile_get_label:
* @profile: a #GimpColorProfile
*
* This function returns a newly allocated string containing
* @profile's "title", a string that can be used to label the profile
* in a user interface.
* This function returns a string containing @profile's "title", a
* string that can be used to label the profile in a user interface.
*
* Return value: the @profile's label. Free with g_free().
* Return value: the @profile's label. The returned value belongs to
* @profile and must not be modified or freed.
*
* Since: 2.10
**/
gchar *
const gchar *
gimp_color_profile_get_label (GimpColorProfile *profile)
{
gchar *label;
g_return_val_if_fail (GIMP_IS_COLOR_PROFILE (profile), NULL);
label = gimp_color_profile_get_description (profile);
if (label && ! strlen (label))
if (! profile->priv->label)
{
g_free (label);
label = NULL;
}
const gchar *label = gimp_color_profile_get_description (profile);
if (! label)
label = gimp_color_profile_get_model (profile);
if (! label || ! strlen (label))
label = gimp_color_profile_get_model (profile);
if (label && ! strlen (label))
{
g_free (label);
label = NULL;
}
if (! label || ! strlen (label))
label = _("(unnamed profile)");
if (! label)
label = g_strdup (_("(unnamed profile)"));
profile->priv->label = g_strdup (label);
}
return label;
return profile->priv->label;
}
/**
* gimp_color_profile_get_summary:
* @profile: a #GimpColorProfile
*
* This function return a newly allocated string containing a
* multi-line summary of @profile's description, model, manufacturer
* and copyright, to be used as detailled information about the
* prpfile in a user interface.
* This function return a string containing a multi-line summary of
* @profile's description, model, manufacturer and copyright, to be
* used as detailled information about the profile in a user
* interface.
*
* Return value: the @profile's summary. Free with g_free().
* Return value: the @profile's summary. The returned value belongs to
* @profile and must not be modified or freed.
*
* Since: 2.10
**/
gchar *
const gchar *
gimp_color_profile_get_summary (GimpColorProfile *profile)
{
GString *string;
gchar *text;
g_return_val_if_fail (GIMP_IS_COLOR_PROFILE (profile), NULL);
string = g_string_new (NULL);
text = gimp_color_profile_get_description (profile);
if (text)
if (! profile->priv->summary)
{
g_string_append (string, text);
g_free (text);
}
GString *string = g_string_new (NULL);
const gchar *text;
text = gimp_color_profile_get_model (profile);
if (text)
{
if (string->len > 0)
g_string_append (string, "\n");
text = gimp_color_profile_get_description (profile);
if (text)
g_string_append (string, text);
g_string_append (string, text);
g_free (text);
}
text = gimp_color_profile_get_model (profile);
if (text)
{
if (string->len > 0)
g_string_append (string, "\n");
text = gimp_color_profile_get_manufacturer (profile);
if (text)
{
if (string->len > 0)
g_string_append (string, "\n");
g_string_append (string, text);
}
g_string_append (string, text);
g_free (text);
}
text = gimp_color_profile_get_manufacturer (profile);
if (text)
{
if (string->len > 0)
g_string_append (string, "\n");
text = gimp_color_profile_get_copyright (profile);
if (text)
{
if (string->len > 0)
g_string_append (string, "\n");
g_string_append (string, text);
}
text = gimp_color_profile_get_copyright (profile);
if (text)
{
if (string->len > 0)
g_string_append (string, "\n");
}
g_string_append (string, text);
g_free (text);
profile->priv->summary = g_string_free (string, FALSE);
}
return g_string_free (string, FALSE);
return profile->priv->summary;
}
/**
......
......@@ -80,13 +80,13 @@ const guint8 * gimp_color_profile_get_icc_profile (GimpColorProfile *
gsize *length);
gpointer gimp_color_profile_get_lcms_profile (GimpColorProfile *profile);
gchar * gimp_color_profile_get_description (GimpColorProfile *profile);
gchar * gimp_color_profile_get_manufacturer (GimpColorProfile *profile);
gchar * gimp_color_profile_get_model (GimpColorProfile *profile);
gchar * gimp_color_profile_get_copyright (GimpColorProfile *profile);
const gchar * gimp_color_profile_get_description (GimpColorProfile *profile);
const gchar * gimp_color_profile_get_manufacturer (GimpColorProfile *profile);
const gchar * gimp_color_profile_get_model (GimpColorProfile *profile);
const gchar * gimp_color_profile_get_copyright (GimpColorProfile *profile);
gchar * gimp_color_profile_get_label (GimpColorProfile *profile);
gchar * gimp_color_profile_get_summary (GimpColorProfile *profile);
const gchar * gimp_color_profile_get_label (GimpColorProfile *profile);
const gchar * gimp_color_profile_get_summary (GimpColorProfile *profile);
gboolean gimp_color_profile_is_equal (GimpColorProfile *profile1,
GimpColorProfile *profile2);
......
......@@ -415,7 +415,6 @@ 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));
......@@ -438,22 +437,16 @@ gimp_color_profile_combo_box_set_active (GimpColorProfileComboBox *combo,
}
else
{
l = gimp_color_profile_get_label (profile);
label = gimp_color_profile_get_label (profile);
g_object_unref (profile);
}
}
else
{
l = g_strdup (label);
}
if (_gimp_color_profile_store_history_add (GIMP_COLOR_PROFILE_STORE (model),
filename, l, &iter))
filename, label, &iter))
{
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &iter);
}
g_free (l);
}
/**
......
......@@ -136,8 +136,8 @@ gimp_color_profile_view_set_profile (GimpColorProfileView *view,
if (view->priv->profile)
{
GtkTextIter iter;
gchar *label;
gchar *summary;
const gchar *label;
const gchar *summary;
g_object_ref (view->priv->profile);
......@@ -156,9 +156,6 @@ gimp_color_profile_view_set_profile (GimpColorProfileView *view,
if (summary)
gtk_text_buffer_insert (buffer, &iter, summary, -1);
g_free (label);
g_free (summary);
}
}
......
......@@ -357,8 +357,6 @@ colorsel_cmyk_config_changed (ColorselCmyk *module)
GimpColorProfile *cmyk_profile = NULL;
cmsHPROFILE rgb_lcms;
cmsHPROFILE cmyk_lcms;
gchar *label;
gchar *summary;
gchar *text;
if (module->rgb2cmyk)
......@@ -388,16 +386,14 @@ colorsel_cmyk_config_changed (ColorselCmyk *module)
if (! cmyk_profile)
goto out;
label = gimp_color_profile_get_label (cmyk_profile);
summary = gimp_color_profile_get_summary (cmyk_profile);
text = g_strdup_printf (_("Profile: %s"), label);
text = g_strdup_printf (_("Profile: %s"),
gimp_color_profile_get_label (cmyk_profile));
gtk_label_set_text (GTK_LABEL (module->name_label), text);
gimp_help_set_help_data (module->name_label, summary, NULL);
g_free (text);
g_free (label);
g_free (summary);
gimp_help_set_help_data (module->name_label,
gimp_color_profile_get_summary (cmyk_profile),
NULL);
rgb_lcms = gimp_color_profile_get_lcms_profile (rgb_profile);
cmyk_lcms = gimp_color_profile_get_lcms_profile (cmyk_profile);
......
......@@ -343,8 +343,8 @@ cdisplay_lcms_update_profile_label (CdisplayLcms *lcms,
GimpColorManaged *managed;
GtkWidget *label;
GimpColorProfile *profile = NULL;
gchar *text;
gchar *tooltip;
const gchar *text;
const gchar *tooltip;
config = gimp_color_display_get_config (GIMP_COLOR_DISPLAY (lcms));
managed = gimp_color_display_get_managed (GIMP_COLOR_DISPLAY (lcms));
......@@ -378,16 +378,13 @@ cdisplay_lcms_update_profile_label (CdisplayLcms *lcms,
}
else
{
text = g_strdup (_("None"));
text = _("None");
tooltip = NULL;
}
gtk_label_set_text (GTK_LABEL (label), text);
gimp_help_set_help_data (label, tooltip, NULL);
g_free (text);
g_free (tooltip);
if (profile)
g_object_unref (profile);
}
......
......@@ -426,19 +426,15 @@ lcms_icc_apply (GimpColorConfig *config,
if (gimp_color_profile_is_equal (src_profile, dest_profile))
{
gchar *src_label = gimp_color_profile_get_label (src_profile);
gchar *dest_label = gimp_color_profile_get_label (dest_profile);
g_printerr ("lcms: skipping conversion because profiles are equal:\n"
" %s\n"
" %s\n",
gimp_color_profile_get_label (src_profile),
gimp_color_profile_get_label (dest_profile));
g_object_unref (src_profile);
g_object_unref (dest_profile);
g_printerr ("lcms: skipping conversion because profiles seem to be equal:\n");
g_printerr (" %s\n", src_label);
g_printerr (" %s\n", dest_label);
g_free (src_label);
g_free (dest_label);
if (file)
g_object_unref (file);
......@@ -530,16 +526,14 @@ lcms_icc_profile_src_label_new (gint32 image,
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
name = gimp_color_profile_get_label (profile);
label = g_object_new (GTK_TYPE_LABEL,
"label", name,
"label", gimp_color_profile_get_label (profile),
"wrap", TRUE,
"justify", GTK_JUSTIFY_LEFT,
"xalign", 0.0,
"yalign", 0.0,
"xpad", 24,
NULL);
g_free (name);
gimp_label_set_attributes (GTK_LABEL (label),
PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD,
......@@ -554,13 +548,10 @@ static GtkWidget *
lcms_icc_profile_dest_label_new (GimpColorProfile *profile)
{
GtkWidget *label;
gchar *name;
gchar *text;
name = gimp_color_profile_get_label (profile);
text = g_strdup_printf (_("Convert the image to the RGB working space (%s)?"),
name);
g_free (name);
gimp_color_profile_get_label (profile));
label = g_object_new (GTK_TYPE_LABEL,
"label", text,
......@@ -653,7 +644,6 @@ lcms_icc_combo_box_new (GimpColorConfig *config,
GtkWidget *dialog;
gchar *history;
gchar *label;
gchar *name;
const gchar *rgb_filename = NULL;
GimpColorProfile *profile = NULL;
GError *error = NULL;
......@@ -679,9 +669,8 @@ lcms_icc_combo_box_new (GimpColorConfig *config,
if (! profile)
profile = gimp_color_profile_new_srgb ();
name = gimp_color_profile_get_label (profile);
label = g_strdup_printf (_("RGB workspace (%s)"), name);
g_free (name);
label = g_strdup_printf (_("RGB workspace (%s)"),
gimp_color_profile_get_label (profile));
g_object_unref (profile);
......@@ -708,7 +697,6 @@ lcms_dialog (GimpColorConfig *config,
GtkWidget *label;
GtkWidget *combo;
GimpColorProfile *src_profile;
gchar *name;
gboolean success = FALSE;
gboolean run;
......@@ -748,15 +736,11 @@ lcms_dialog (GimpColorConfig *config,
gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
name = gimp_color_profile_get_label (src_profile);
label = gtk_label_new (name);
label = gtk_label_new (gimp_color_profile_get_label (src_profile));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_container_add (GTK_CONTAINER (frame), label);
gtk_widget_show (label);
g_free (name);
frame = gimp_frame_new (apply ? _("Convert to") : _("Assign"));
gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
......
......@@ -1784,9 +1784,9 @@ HELP
profile = gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (image));
profile_name = gimp_color_profile_get_model (profile);
profile_desc = gimp_color_profile_get_description (profile);
profile_info = gimp_color_profile_get_summary (profile);
profile_name = g_strdup (gimp_color_profile_get_model (profile));
profile_desc = g_strdup (gimp_color_profile_get_description (profile));
profile_info = g_strdup (gimp_color_profile_get_summary (profile));
g_object_unref (profile);
......@@ -1833,9 +1833,9 @@ HELP
if (p)
{
profile_name = gimp_color_profile_get_model (p);
profile_desc = gimp_color_profile_get_description (p);
profile_info = gimp_color_profile_get_summary (p);
profile_name = g_strdup (gimp_color_profile_get_model (p));
profile_desc = g_strdup (gimp_color_profile_get_description (p));
profile_info = g_strdup (gimp_color_profile_get_summary (p));
g_object_unref (p);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment