aboutsummaryrefslogtreecommitdiffstats
path: root/filter/filter-colour.c
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2007-04-02 12:19:25 +0800
committerMatthew Barnes <mbarnes@src.gnome.org>2007-04-02 12:19:25 +0800
commitb5365bc587c99c0eb18293c4e70029782a185d56 (patch)
treec28ff26a508bcb3195b7b74868540f3c9ffc1458 /filter/filter-colour.c
parent7dd3f720c743488c2aac7b6a1cfcdb97b1c1ac70 (diff)
downloadgsoc2013-evolution-b5365bc587c99c0eb18293c4e70029782a185d56.tar
gsoc2013-evolution-b5365bc587c99c0eb18293c4e70029782a185d56.tar.gz
gsoc2013-evolution-b5365bc587c99c0eb18293c4e70029782a185d56.tar.bz2
gsoc2013-evolution-b5365bc587c99c0eb18293c4e70029782a185d56.tar.lz
gsoc2013-evolution-b5365bc587c99c0eb18293c4e70029782a185d56.tar.xz
gsoc2013-evolution-b5365bc587c99c0eb18293c4e70029782a185d56.tar.zst
gsoc2013-evolution-b5365bc587c99c0eb18293c4e70029782a185d56.zip
** Fixes bug #373116
2007-04-01 Matthew Barnes <mbarnes@redhat.com> ** Fixes bug #373116 * calendar/gui/calendar-component.c (ensure_sources): * calendar/gui/e-cal-model.c (ecm_get_color_for_component): * calendar/gui/memos-component.c (ensure_sources): * calendar/gui/migration.c (create_calendar_contact_source), (create_calendar_sources), (create_task_sources), (create_memo_sources), (add_gw_esource): * calendar/gui/tasks-component.c (ensure_sources): * plugins/groupwise-account-setup/camel-gw-listener.c (add_esource): Use the new ESource color API. * calendar/gui/dialogs/cal-prefs-dialog.c: * calendar/gui/dialogs/cal-prefs-dialog.glade: * calendar/gui/dialogs/calendar-setup.c: * calendar/gui/dialogs/calendar-setup.glade: * filter-colour.c (get_widget): * mail/em-composer-prefs.c: * mail/em-composer-prefs.h: * mail/em-mailer-prefs.c: * mail/em-mailer-prefs.h: * mail/mail-config.glade: Migrate from GnomeColorPicker to GtkColorButton. * filter/filter-colour.h: Store color as a GdkColor instead of separate RGBA components. * filter/filter-colour.c (color_eq): Use gdk_color_equal() to compare colors. * filter/filter-colour.c (xml_encode): Encode color as a single property ("spec"). * filter/filter-colour.c (xml_decode): Read the color from a single property ("spec"). Provide a migration path for old XML files. * calendar/gui/calendar-component.c (calendar_config_get_tasks_due_today_color), (calendar_config_get_tasks_overdue_color): Return a GdkColor instead of an X color specification. * calendar/gui/calendar-component.c (calendar_config_set_tasks_due_today_color), (calendar_config_set_tasks_overdue_color): Accept a GdkColor instead of an X color specification. * calenar/gui/e-cal-model-tasks.c (ecmt_get_color_for_component): Adapt to modified color API in calendar-component.c by converting the GdkColor to an X color specification. This is an ugly hack to be fixed later. svn path=/trunk/; revision=33349
Diffstat (limited to 'filter/filter-colour.c')
-rw-r--r--filter/filter-colour.c108
1 files changed, 50 insertions, 58 deletions
diff --git a/filter/filter-colour.c b/filter/filter-colour.c
index 78db9d848c..97a343bc63 100644
--- a/filter/filter-colour.c
+++ b/filter/filter-colour.c
@@ -26,7 +26,7 @@
#endif
#include <gtk/gtksignal.h>
-#include <libgnomeui/gnome-color-picker.h>
+#include <gtk/gtkcolorbutton.h>
#include "libedataserver/e-sexp.h"
#include "filter-colour.h"
@@ -120,13 +120,11 @@ filter_colour_new (void)
static int
colour_eq (FilterElement *fe, FilterElement *cm)
{
- FilterColour *fc = (FilterColour *)fe, *cc = (FilterColour *)cm;
-
- return FILTER_ELEMENT_CLASS (parent_class)->eq (fe, cm)
- && fc->r == cc->r
- && fc->g == cc->g
- && fc->b == cc->b
- && fc->a == cc->a;
+ FilterColour *fc = (FilterColour *) fe;
+ FilterColour *cc = (FilterColour *) cm;
+
+ return FILTER_ELEMENT_CLASS (parent_class)->eq (fe, cm)
+ && gdk_color_equal (&fc->color, &cc->color);
}
static void
@@ -139,76 +137,70 @@ xml_create (FilterElement *fe, xmlNodePtr node)
static xmlNodePtr
xml_encode (FilterElement *fe)
{
- xmlNodePtr value;
FilterColour *fc = (FilterColour *)fe;
- char hex[16];
-
- d(printf("Encoding colour as xml\n"));
+ xmlNodePtr value;
+ gchar spec[16];
+
+ g_snprintf (spec, sizeof (spec), "#%04x%04x%04x",
+ fc->color.red, fc->color.green, fc->color.blue);
+
value = xmlNewNode(NULL, "value");
xmlSetProp(value, "name", fe->name);
xmlSetProp(value, "type", "colour");
-
- sprintf(hex, "%04x", fc->r);
- xmlSetProp(value, "red", hex);
- sprintf(hex, "%04x", fc->g);
- xmlSetProp(value, "green", hex);
- sprintf(hex, "%04x", fc->b);
- xmlSetProp(value, "blue", hex);
- sprintf(hex, "%04x", fc->a);
- xmlSetProp(value, "alpha", hex);
-
- return value;
-}
+ xmlSetProp(value, "spec", spec);
-static guint16
-get_value (xmlNodePtr node, char *name)
-{
- unsigned int ret;
- char *value;
-
- value = xmlGetProp(node, name);
- sscanf(value, "%04x", &ret);
- xmlFree(value);
- return ret;
+ return value;
}
-
static int
xml_decode (FilterElement *fe, xmlNodePtr node)
{
FilterColour *fc = (FilterColour *)fe;
-
+ xmlChar *prop;
+
xmlFree (fe->name);
fe->name = xmlGetProp(node, "name");
- fc->r = get_value(node, "red");
- fc->g = get_value(node, "green");
- fc->b = get_value(node, "blue");
- fc->a = get_value(node, "alpha");
-
+
+ prop = xmlGetProp(node, "spec");
+ if (prop != NULL) {
+ gdk_color_parse(prop, &fc->color);
+ xmlFree (prop);
+ } else {
+ /* try reading the old RGB properties */
+ prop = xmlGetProp(node, "red");
+ sscanf(prop, "%" G_GINT16_MODIFIER "x", &fc->color.red);
+ xmlFree (prop);
+ prop = xmlGetProp(node, "green");
+ sscanf(prop, "%" G_GINT16_MODIFIER "x", &fc->color.green);
+ xmlFree (prop);
+ prop = xmlGetProp(node, "blue");
+ sscanf(prop, "%" G_GINT16_MODIFIER "x", &fc->color.blue);
+ xmlFree (prop);
+ }
+
return 0;
}
static void
-set_colour (GnomeColorPicker *cp, guint r, guint g, guint b, guint a, FilterColour *fc)
+set_color (GtkColorButton *color_button, FilterColour *fc)
{
- fc->r = r;
- fc->g = g;
- fc->b = b;
- fc->a = a;
+ gtk_color_button_get_color (color_button, &fc->color);
}
static GtkWidget *
get_widget (FilterElement *fe)
{
FilterColour *fc = (FilterColour *) fe;
- GnomeColorPicker *cp;
-
- cp = (GnomeColorPicker *) gnome_color_picker_new ();
- gnome_color_picker_set_i16 (cp, fc->r, fc->g, fc->b, fc->a);
- gtk_widget_show ((GtkWidget *) cp);
- g_signal_connect (cp, "color_set", G_CALLBACK (set_colour), fe);
+ GtkWidget *color_button;
+
+ color_button = gtk_color_button_new_with_color (&fc->color);
+ gtk_widget_show (color_button);
+
+ g_signal_connect (
+ G_OBJECT (color_button), "color_set",
+ G_CALLBACK (set_color), fe);
- return (GtkWidget *) cp;
+ return color_button;
}
static void
@@ -221,9 +213,9 @@ static void
format_sexp (FilterElement *fe, GString *out)
{
FilterColour *fc = (FilterColour *)fe;
- char *str;
-
- str = g_strdup_printf ("#%02x%02x%02x", (fc->r >> 8) & 0xff, (fc->g >> 8) & 0xff, (fc->b >> 8) & 0xff);
- e_sexp_encode_string (out, str);
- g_free (str);
+ gchar spec[16];
+
+ g_snprintf (spec, sizeof (spec), "#%04x%04x%04x",
+ fc->color.red, fc->color.green, fc->color.blue);
+ e_sexp_encode_string (out, spec);
}