[libgdata] [calendar] Add the remaining XML output to GDataCalendarCalendar



commit a777890b44052c1266deb51864444a901511bb1c
Author: Philip Withnall <philip tecnocode co uk>
Date:   Sun May 10 23:29:12 2009 +0100

    [calendar] Add the remaining XML output to GDataCalendarCalendar
---
 docs/reference/gdata-sections.txt                 |    1 +
 gdata/gdata-types.c                               |   19 +++++++++++++
 gdata/gdata-types.h                               |    1 +
 gdata/gdata.symbols                               |    1 +
 gdata/services/calendar/gdata-calendar-calendar.c |   30 ++++++++++++++-------
 gdata/tests/general.c                             |   25 +++++++++++++++++
 6 files changed, 67 insertions(+), 10 deletions(-)

diff --git a/docs/reference/gdata-sections.txt b/docs/reference/gdata-sections.txt
index 39ad95c..d103564 100644
--- a/docs/reference/gdata-sections.txt
+++ b/docs/reference/gdata-sections.txt
@@ -567,6 +567,7 @@ GDataCalendarEventPrivate
 <TITLE>GData Types</TITLE>
 GDataColor
 gdata_color_from_hexadecimal
+gdata_color_to_hexadecimal
 <SUBSECTION Standard>
 GDATA_TYPE_COLOR
 GDATA_TYPE_G_TIME_VAL
diff --git a/gdata/gdata-types.c b/gdata/gdata-types.c
index 8edc06f..74f44fd 100644
--- a/gdata/gdata-types.c
+++ b/gdata/gdata-types.c
@@ -133,3 +133,22 @@ gdata_color_from_hexadecimal (const gchar *hexadecimal, GDataColor *color)
 
 	return TRUE;
 }
+
+/**
+ * gdata_color_to_hexadecimal:
+ * @color: a #GDataColor
+ *
+ * Returns a string describing @color in hexadecimal form; in the form <literal>#<replaceable>rr</replaceable><replaceable>gg</replaceable>
+ * <replaceable>bb</replaceable></literal>, where <replaceable>rr</replaceable> is a two-digit hexadecimal red intensity value,
+ * <replaceable>gg</replaceable> is green and <replaceable>bb</replaceable> is blue. The hash is always present.
+ *
+ * Return value: the color string; free with g_free()
+ *
+ * Since: 0.3.0
+ **/
+gchar *
+gdata_color_to_hexadecimal (GDataColor *color)
+{
+	g_return_val_if_fail (color != NULL, NULL);
+	return g_strdup_printf ("#%02x%02x%02x", color->red, color->green, color->blue);
+}
diff --git a/gdata/gdata-types.h b/gdata/gdata-types.h
index b899041..c650db2 100644
--- a/gdata/gdata-types.h
+++ b/gdata/gdata-types.h
@@ -45,6 +45,7 @@ typedef struct {
 #define GDATA_TYPE_COLOR (gdata_color_get_type ())
 GType gdata_color_get_type (void) G_GNUC_CONST;
 gboolean gdata_color_from_hexadecimal (const gchar *hexadecimal, GDataColor *color);
+gchar *gdata_color_to_hexadecimal (GDataColor *color) G_GNUC_WARN_UNUSED_RESULT;
 
 G_END_DECLS
 
diff --git a/gdata/gdata.symbols b/gdata/gdata.symbols
index a0f4d26..a323aaa 100644
--- a/gdata/gdata.symbols
+++ b/gdata/gdata.symbols
@@ -1,5 +1,6 @@
 gdata_color_get_type
 gdata_color_from_hexadecimal
+gdata_color_to_hexadecimal
 gdata_entry_get_type
 gdata_entry_new
 gdata_entry_new_from_xml
diff --git a/gdata/services/calendar/gdata-calendar-calendar.c b/gdata/services/calendar/gdata-calendar-calendar.c
index aa50580..64839a9 100644
--- a/gdata/services/calendar/gdata-calendar-calendar.c
+++ b/gdata/services/calendar/gdata-calendar-calendar.c
@@ -373,22 +373,32 @@ parse_xml (GDataEntry *entry, xmlDoc *doc, xmlNode *node, GError **error)
 static void
 get_xml (GDataEntry *entry, GString *xml_string)
 {
+	gchar *colour;
 	GDataCalendarCalendarPrivate *priv = GDATA_CALENDAR_CALENDAR (entry)->priv;
 
 	/* Chain up to the parent class */
 	GDATA_ENTRY_CLASS (gdata_calendar_calendar_parent_class)->get_xml (entry, xml_string);
 
 	/* Add all the Calendar-specific XML */
-	if (priv->timezone != NULL)
-		g_string_append_printf (xml_string, "<gCal:timezone value='%s'/>", priv->timezone);
-
-	/* TODO:
-	 * - Finish supporting all tags
-	 * - Check all tags here are valid for insertions and updates
-	 * - Check things are escaped (or not) as appropriate
-	 * - Write a function to encapsulate g_markup_escape_text and
-	 *   g_string_append_printf to reduce the number of allocations
-	 */
+	if (priv->timezone != NULL) {
+		gchar *timezone = g_markup_escape_text (priv->timezone, -1);
+		g_string_append_printf (xml_string, "<gCal:timezone value='%s'/>", timezone);
+		g_free (timezone);
+	}
+
+	if (priv->is_hidden == TRUE)
+		g_string_append (xml_string, "<gCal:hidden value='true'/>");
+	else
+		g_string_append (xml_string, "<gCal:hidden value='false'/>");
+
+	colour = gdata_color_to_hexadecimal (&(priv->colour));
+	g_string_append_printf (xml_string, "<gCal:color value='%s'/>", colour);
+	g_free (colour);
+
+	if (priv->is_selected == TRUE)
+		g_string_append (xml_string, "<gCal:selected value='true'/>");
+	else
+		g_string_append (xml_string, "<gCal:selected value='false'/>");
 }
 
 static void
diff --git a/gdata/tests/general.c b/gdata/tests/general.c
index b47e930..c5c3108 100644
--- a/gdata/tests/general.c
+++ b/gdata/tests/general.c
@@ -212,6 +212,30 @@ test_color_parsing (void)
 	g_assert (gdata_color_from_hexadecimal ("this is not a real colour!", &color) == FALSE);
 }
 
+static void
+test_color_output (void)
+{
+	GDataColor color;
+	gchar *color_string;
+
+	/* General test */
+	g_assert (gdata_color_from_hexadecimal ("#F99Ff0", &color) == TRUE);
+	color_string = gdata_color_to_hexadecimal (&color);
+	g_assert_cmpstr (color_string, ==, "#f99ff0");
+	g_free (color_string);
+
+	/* Boundary tests */
+	g_assert (gdata_color_from_hexadecimal ("#ffffff", &color) == TRUE);
+	color_string = gdata_color_to_hexadecimal (&color);
+	g_assert_cmpstr (color_string, ==, "#ffffff");
+	g_free (color_string);
+
+	g_assert (gdata_color_from_hexadecimal ("#000000", &color) == TRUE);
+	color_string = gdata_color_to_hexadecimal (&color);
+	g_assert_cmpstr (color_string, ==, "#000000");
+	g_free (color_string);
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -223,6 +247,7 @@ main (int argc, char *argv[])
 	g_test_add_func ("/entry/parse_xml", test_entry_parse_xml);
 	g_test_add_func ("/query/categories", test_query_categories);
 	g_test_add_func ("/color/parsing", test_color_parsing);
+	g_test_add_func ("/color/output", test_color_output);
 
 	return g_test_run ();
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]