After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 373856 - Wish: Function to convert a GdkColor to a string
Wish: Function to convert a GdkColor to a string
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Backend: X11
2.10.x
Other Linux
: Normal enhancement
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2006-11-11 14:27 UTC by Matthew Barnes
Modified: 2006-12-21 12:35 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Proposed patch (2.71 KB, patch)
2006-11-11 17:23 UTC, Matthew Barnes
none Details | Review
Revised patch (2.80 KB, patch)
2006-12-07 05:07 UTC, Matthew Barnes
accepted-commit_now Details | Review

Description Matthew Barnes 2006-11-11 14:27:55 UTC
Applications sometimes allow users to customize colors using a color selection dialog.  These preferences must be retained across sessions, usually by writing a textual representation of a GdkColor to GConf or a configuration file.  Later, the textual representation is passed to gdk_color_parse() to recreate the original GdkColor.

While generating such a representation can be as simple as a one-line "printf" operation, it would be courteous for the GDK API to provide a standard method.

Hence, I propose the following addition to GDK:

    gchar * gdk_color_to_string (GdkColor *color)

This function returns a newly-allocated string representation of the GdkColor in the form of "#rrrrggggbbbb", where 'rrrr', 'gggg' and 'bbbb' are the hexadecimal values of the GdkColor's red, green and blue components, respectively.  Note that the pixel component of the GdkColor is lost in the conversion.

The resulting string can be passed to gdk_color_parse() to recreate the original GdkColor (sans the pixel component).
Comment 1 Matthew Barnes 2006-11-11 17:23:39 UTC
Created attachment 76396 [details] [review]
Proposed patch
Comment 2 Behdad Esfahbod 2006-11-13 05:59:19 UTC
Should this go down to Pango too?
Comment 3 Matthew Barnes 2006-12-06 15:04:07 UTC
Not sure if that question was for me, but I think since GDK defers to Pango for parsing color strings it might make sense to do the same for generating color strings.  Would Pango benefit from a pango_color_to_string() function?
Comment 4 Behdad Esfahbod 2006-12-06 19:10:25 UTC
(In reply to comment #3)
> Not sure if that question was for me, but I think since GDK defers to Pango for
> parsing color strings it might make sense to do the same for generating color
> strings.  Would Pango benefit from a pango_color_to_string() function?

That would be useful in language bindings at least.  I'm fine with adding it.  I'll go ahead and add that today.  Will be in Pango 1.16.
Comment 5 Behdad Esfahbod 2006-12-06 22:46:41 UTC
Will be in Pango 1.15.2:

2006-12-06  Behdad Esfahbod  <behdad@gnome.org>

        Bug 373856 – Wish: Function to convert a GdkColor to a string
        Patch from Matthew Barnes

        * docs/pango-sections.txt:
        * docs/tmpl/text-attributes.sgml:
        * pango/pango-attributes.h:
        * pango/pango.def:
        * pango/pango-color.c (pango_color_to_string):
        New public function pango_color_to_string().



Note that your patch doesn't have the Since: tag in docs.  You can now use pango_color_to_string() for the one-line function in gdk. :)
Comment 6 Matthew Barnes 2006-12-07 05:07:25 UTC
Created attachment 77869 [details] [review]
Revised patch

Here's a revised patch that uses pango_color_to_string().
Comment 7 Matthias Clasen 2006-12-21 06:19:57 UTC
I'm not normally a fan of adding too many trivial functions like this, 
but since you've already got it into pango, go ahead and add this to
HEAD, but please make sure that you bump the pango requirement to
1.15.2 in configure.in
Comment 8 Matthew Barnes 2006-12-21 12:35:14 UTC
Committed.

2006-12-21  Matthew Barnes  <mbarnes@redhat.com>

        * docs/reference/gdk/gdk-sections.txt:
        * gdk/gdkcolor.[ch] (gdk_color_to_string): Add a function for
        converting a GdkColor to a string (#373856).

        * configure.in: Bump pango requirement to 1.15.2.