--- evolution-data-server-1.9.3/libedataserverui/e-source-selector.c.e-source-color 2006-04-26 04:21:21.000000000 -0400 +++ evolution-data-server-1.9.3/libedataserverui/e-source-selector.c 2006-12-15 16:02:47.000000000 -0500 @@ -411,15 +411,24 @@ NULL); } else { ESource *source; - guint32 color; GdkPixbuf *pixbuf = NULL; + const gchar *color_spec; + GdkColor color; g_assert (E_IS_SOURCE (data)); source = E_SOURCE (data); - if (e_source_get_color (source, &color)) { + color_spec = e_source_peek_color_spec (source); + if (color_spec != NULL && gdk_color_parse (color_spec, &color)) { + guint32 rgba; + pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 16, 16); - gdk_pixbuf_fill (pixbuf, color << 8); + + rgba = (((color.red & 0xff00) << 8) | + ((color.green & 0xff00)) | + ((color.blue & 0xff00) >> 8)) << 8; + + gdk_pixbuf_fill (pixbuf, rgba); } g_object_set (renderer, --- evolution-data-server-1.9.3/libedataserver/e-source.h.e-source-color 2005-08-31 00:26:10.000000000 -0400 +++ evolution-data-server-1.9.3/libedataserver/e-source.h 2006-12-15 16:02:47.000000000 -0500 @@ -82,20 +82,27 @@ const char *relative_uri); void e_source_set_absolute_uri (ESource *source, const char *absolute_uri); +void e_source_set_color_spec (ESource *source, + const gchar *color_spec); void e_source_set_readonly (ESource *source, gboolean readonly); +#ifndef EDS_DISABLE_DEPRECATED void e_source_set_color (ESource *source, guint32 color); void e_source_unset_color (ESource *source); +#endif ESourceGroup *e_source_peek_group (ESource *source); const char *e_source_peek_uid (ESource *source); const char *e_source_peek_name (ESource *source); const char *e_source_peek_relative_uri (ESource *source); const char *e_source_peek_absolute_uri (ESource *source); +const char *e_source_peek_color_spec (ESource *source); gboolean e_source_get_readonly (ESource *source); +#ifndef EDS_DISABLE_DEPRECATED gboolean e_source_get_color (ESource *source, guint32 *color_return); +#endif char *e_source_get_uri (ESource *source); --- evolution-data-server-1.9.3/libedataserver/e-source.c.e-source-color 2006-08-03 07:29:44.000000000 -0400 +++ evolution-data-server-1.9.3/libedataserver/e-source.c 2006-12-15 16:02:47.000000000 -0500 @@ -32,10 +32,6 @@ #define ES_CLASS(obj) E_SOURCE_CLASS (G_OBJECT_GET_CLASS (obj)) -/* String used to put the color in the XML. */ -#define COLOR_FORMAT_STRING "%06x" - - /* Private members. */ struct _ESourcePrivate { @@ -48,8 +44,7 @@ gboolean readonly; - gboolean has_color; - guint32 color; + gchar *color_spec; GHashTable *properties; }; @@ -89,6 +84,7 @@ g_free (priv->name); g_free (priv->relative_uri); g_free (priv->absolute_uri); + g_free (priv->color_spec); g_hash_table_destroy (priv->properties); @@ -143,6 +139,28 @@ g_free, g_free); } +/* Private methods. */ + +static gboolean +set_color_spec (ESource *source, + const gchar *color_spec) +{ + ESourcePrivate *priv = source->priv; + gboolean do_cmp; + + if (color_spec == priv->color_spec) + return FALSE; + + do_cmp = (color_spec != NULL && priv->color_spec != NULL); + if (do_cmp && g_ascii_strcasecmp (color_spec, priv->color_spec) == 0) + return FALSE; + + g_free (priv->color_spec); + priv->color_spec = g_strdup (color_spec); + + return TRUE; +} + /* Public methods. */ ESource * @@ -300,19 +318,22 @@ xmlChar *name; xmlChar *relative_uri; xmlChar *absolute_uri; - xmlChar *color_string; - gboolean retval; + xmlChar *color_spec; + xmlChar *color; + gboolean retval = FALSE; gboolean changed = FALSE; name = xmlGetProp (node, "name"); relative_uri = xmlGetProp (node, "relative_uri"); absolute_uri = xmlGetProp (node, "uri"); - color_string = xmlGetProp (node, "color"); + color_spec = xmlGetProp (node, "color_spec"); + color = xmlGetProp (node, "color"); /* obsolete */ - if (name == NULL || (relative_uri == NULL && absolute_uri == NULL)) { - retval = FALSE; + if (name == NULL || (relative_uri == NULL && absolute_uri == NULL)) + goto done; + + if (color_spec != NULL && color != NULL) goto done; - } if (source->priv->name == NULL || strcmp (name, source->priv->name) != 0 @@ -334,21 +355,15 @@ changed = TRUE; } - if (color_string == NULL) { - if (source->priv->has_color) { - source->priv->has_color = FALSE; - changed = TRUE; - } + if (color == NULL) { + /* It is okay for color_spec to be NULL. */ + changed |= set_color_spec (source, color_spec); } else { - guint32 color = 0; - - sscanf (color_string, COLOR_FORMAT_STRING, &color); - if (! source->priv->has_color || source->priv->color != color) { - source->priv->has_color = TRUE; - source->priv->color = color; - changed = TRUE; - } + gchar buffer[8]; + g_snprintf (buffer, sizeof (buffer), "#%s", color); + changed |= set_color_spec (source, buffer); } + if (g_hash_table_size (source->priv->properties) && !node->children) { g_hash_table_destroy (source->priv->properties); source->priv->properties = g_hash_table_new_full (g_str_hash, g_str_equal, @@ -387,8 +402,8 @@ xmlFree (relative_uri); if (absolute_uri != NULL) xmlFree (absolute_uri); - if (color_string != NULL) - xmlFree (color_string); + if (color_spec != NULL) + xmlFree (color_spec); return retval; } @@ -552,18 +567,12 @@ e_source_set_color (ESource *source, guint32 color) { - g_return_if_fail (E_IS_SOURCE (source)); + gchar color_spec[8]; - if (source->priv->readonly) - return; - - if (source->priv->has_color && source->priv->color == color) - return; - - source->priv->has_color = TRUE; - source->priv->color = color; + g_return_if_fail (E_IS_SOURCE (source)); - g_signal_emit (source, signals[CHANGED], 0); + g_snprintf (color_spec, sizeof (color_spec), "#%06x", color); + e_source_set_color_spec (source, color_spec); } void @@ -571,13 +580,29 @@ { g_return_if_fail (E_IS_SOURCE (source)); - if (! source->priv->has_color) - return; - - source->priv->has_color = FALSE; - g_signal_emit (source, signals[CHANGED], 0); + e_source_set_color_spec (source, NULL); } +/** + * e_source_set_color_spec: + * @source: an ESource + * @color_spec: a string specifying the color + * + * Store a textual representation of a color in @source. The @color_spec + * string should be parsable by #gdk_color_parse(), or %NULL to unset the + * color in @source. + * + * Since: 1.10 + **/ +void +e_source_set_color_spec (ESource *source, + const gchar *color_spec) +{ + g_return_if_fail (E_IS_SOURCE (source)); + + if (!source->priv->readonly && set_color_spec (source, color_spec)) + g_signal_emit (source, signals[CHANGED], 0); +} ESourceGroup * e_source_peek_group (ESource *source) @@ -619,6 +644,25 @@ return source->priv->absolute_uri; } +/** + * e_source_peek_color_spec: + * @source: an ESource + * + * Return the textual representation of the color for @source, or %NULL if it + * has none. The returned string should be parsable by #gdk_color_parse(). + * + * Return value: a string specifying the color + * + * Since: 1.10 + **/ +const char * +e_source_peek_color_spec (ESource *source) +{ + g_return_val_if_fail (E_IS_SOURCE (source), NULL); + + return source->priv->color_spec; +} + gboolean e_source_get_readonly (ESource *source) { @@ -643,13 +687,21 @@ e_source_get_color (ESource *source, guint32 *color_return) { + const gchar *color_spec; + guint32 color; + g_return_val_if_fail (E_IS_SOURCE (source), FALSE); - if (! source->priv->has_color) + color_spec = e_source_peek_color_spec (source); + + if (color_spec == NULL) + return FALSE; + + if (sscanf (color_spec, "#%06x", &color) != 1) return FALSE; if (color_return != NULL) - *color_return = source->priv->color; + *color_return = color; return TRUE; } @@ -689,8 +741,6 @@ xmlNodePtr parent_node) { ESourcePrivate *priv; - gboolean has_color; - guint32 color; xmlNodePtr node; const char *abs_uri = NULL, *relative_uri = NULL; @@ -709,13 +759,9 @@ xmlSetProp (node, "uri", abs_uri); if (relative_uri) xmlSetProp (node, "relative_uri", relative_uri); - - has_color = e_source_get_color (source, &color); - if (has_color) { - char *color_string = g_strdup_printf (COLOR_FORMAT_STRING, color); - xmlSetProp (node, "color", color_string); - g_free (color_string); - } + + if (priv->color_spec != NULL) + xmlSetProp (node, "color_spec", priv->color_spec); if (g_hash_table_size (priv->properties) != 0) { xmlNodePtr properties_node; @@ -848,7 +894,6 @@ e_source_copy (ESource *source) { ESource *new_source; - guint32 color; g_return_val_if_fail (E_IS_SOURCE (source), NULL); @@ -857,8 +902,7 @@ e_source_set_name (new_source, e_source_peek_name (source)); - if (e_source_get_color (source, &color)) - e_source_set_color (new_source, color); + new_source->priv->color_spec = g_strdup (source->priv->color_spec); new_source->priv->absolute_uri = g_strdup (e_source_peek_absolute_uri (source)); --- evolution-data-server-1.9.3/libedataserver/test-source-list.c.e-source-color 2005-10-14 07:31:40.000000000 -0400 +++ evolution-data-server-1.9.3/libedataserver/test-source-list.c 2006-12-15 16:02:47.000000000 -0500 @@ -91,17 +91,16 @@ dump_source (ESource *source) { char *uri = e_source_get_uri (source); - gboolean has_color; - guint32 color; + const gchar *color_spec; g_print ("\tSource %s\n", e_source_peek_uid (source)); g_print ("\t\tname: %s\n", e_source_peek_name (source)); g_print ("\t\trelative_uri: %s\n", e_source_peek_relative_uri (source)); g_print ("\t\tabsolute_uri: %s\n", uri); - has_color = e_source_get_color (source, &color); - if (has_color) - g_print ("\t\tcolor: %06x\n", color); + color_spec = e_source_peek_color_spec (source); + if (color_spec != NULL) + g_print ("\t\tcolor: %s\n", color_spec); g_print ("\t\tproperties:\n"); e_source_foreach_property (source, (GHFunc) dump_property, NULL); @@ -429,7 +428,6 @@ if (set_color_arg != NULL) { ESource *source; - guint32 color; if (add_source_arg == NULL && source_arg == NULL) { fprintf (stderr, @@ -442,8 +440,7 @@ else source = e_source_list_peek_source_by_uid (list, source_arg); - sscanf (set_color_arg, "%06x", &color); - e_source_set_color (source, color); + e_source_set_color_spec (source, set_color_arg); e_source_list_sync (list, NULL); } @@ -461,7 +458,7 @@ else source = e_source_list_peek_source_by_uid (list, source_arg); - e_source_unset_color (source); + e_source_set_color_spec (source, NULL); e_source_list_sync (list, NULL); }