1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /*
3 * GData Client
4 * Copyright (C) Philip Withnall 2009–2010 <philip@tecnocode.co.uk>
5 *
6 * GData Client is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * GData Client is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with GData Client. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 /**
21 * SECTION:gdata-gd-postal-address
22 * @short_description: GData postal address element
23 * @stability: Stable
24 * @include: gdata/gd/gdata-gd-postal-address.h
25 *
26 * #GDataGDPostalAddress represents a "structuredPostalAddress" element from the
27 * <ulink type="http" url="http://code.google.com/apis/gdata/docs/2.0/elements.html#gdStructuredPostalAddress">GData specification</ulink>.
28 * Note that it does not represent a simple "postalAddress" element, as "structuredPostalAddress" is now used wherever possible in the GData API.
29 *
30 * Since: 0.4.0
31 */
32
33 #include <glib.h>
34 #include <libxml/parser.h>
35 #include <string.h>
36
37 #include "gdata-gd-postal-address.h"
38 #include "gdata-parsable.h"
39 #include "gdata-parser.h"
40 #include "gdata-comparable.h"
41
42 static void gdata_gd_postal_address_comparable_init (GDataComparableIface *iface);
43 static void gdata_gd_postal_address_finalize (GObject *object);
44 static void gdata_gd_postal_address_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
45 static void gdata_gd_postal_address_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
46 static gboolean pre_parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *root_node, gpointer user_data, GError **error);
47 static gboolean parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_data, GError **error);
48 static void pre_get_xml (GDataParsable *parsable, GString *xml_string);
49 static void get_xml (GDataParsable *parsable, GString *xml_string);
50 static void get_namespaces (GDataParsable *parsable, GHashTable *namespaces);
51
52 struct _GDataGDPostalAddressPrivate {
53 gchar *formatted_address;
54 gchar *relation_type;
55 gchar *label;
56 gboolean is_primary;
57 gchar *mail_class;
58 gchar *usage;
59 gchar *agent;
60 gchar *house_name;
61 gchar *street;
62 gchar *po_box;
63 gchar *neighborhood;
64 gchar *city;
65 gchar *subregion;
66 gchar *region;
67 gchar *postcode;
68 gchar *country;
69 gchar *country_code;
70 };
71
72 enum {
73 PROP_FORMATTED_ADDRESS = 1,
74 PROP_RELATION_TYPE,
75 PROP_LABEL,
76 PROP_IS_PRIMARY,
77 PROP_MAIL_CLASS,
78 PROP_USAGE,
79 PROP_AGENT,
80 PROP_HOUSE_NAME,
81 PROP_STREET,
82 PROP_PO_BOX,
83 PROP_NEIGHBORHOOD,
84 PROP_CITY,
85 PROP_SUBREGION,
86 PROP_REGION,
87 PROP_POSTCODE,
88 PROP_COUNTRY,
89 PROP_COUNTRY_CODE
90 };
91
G_DEFINE_TYPE_WITH_CODE(GDataGDPostalAddress,gdata_gd_postal_address,GDATA_TYPE_PARSABLE,G_IMPLEMENT_INTERFACE (GDATA_TYPE_COMPARABLE,gdata_gd_postal_address_comparable_init))92 G_DEFINE_TYPE_WITH_CODE (GDataGDPostalAddress, gdata_gd_postal_address, GDATA_TYPE_PARSABLE,
93 G_IMPLEMENT_INTERFACE (GDATA_TYPE_COMPARABLE, gdata_gd_postal_address_comparable_init))
94
95 static void
96 gdata_gd_postal_address_class_init (GDataGDPostalAddressClass *klass)
97 {
98 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
99 GDataParsableClass *parsable_class = GDATA_PARSABLE_CLASS (klass);
100
101 g_type_class_add_private (klass, sizeof (GDataGDPostalAddressPrivate));
102
103 gobject_class->get_property = gdata_gd_postal_address_get_property;
104 gobject_class->set_property = gdata_gd_postal_address_set_property;
105 gobject_class->finalize = gdata_gd_postal_address_finalize;
106
107 parsable_class->pre_parse_xml = pre_parse_xml;
108 parsable_class->parse_xml = parse_xml;
109 parsable_class->pre_get_xml = pre_get_xml;
110 parsable_class->get_xml = get_xml;
111 parsable_class->get_namespaces = get_namespaces;
112 parsable_class->element_name = "structuredPostalAddress";
113 parsable_class->element_namespace = "gd";
114
115 /**
116 * GDataGDPostalAddress:address:
117 *
118 * The postal address itself, formatted and unstructured. It is preferred to use the other, structured properties rather than this one.
119 *
120 * For more information, see the
121 * <ulink type="http" url="http://code.google.com/apis/gdata/docs/2.0/elements.html#gdStructuredPostalAddress">GData specification</ulink>.
122 *
123 * Since: 0.4.0
124 */
125 g_object_class_install_property (gobject_class, PROP_FORMATTED_ADDRESS,
126 g_param_spec_string ("address",
127 "Address", "The postal address itself.",
128 NULL,
129 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
130
131 /**
132 * GDataGDPostalAddress:relation-type:
133 *
134 * A programmatic value that identifies the type of postal address. For example: %GDATA_GD_POSTAL_ADDRESS_WORK or
135 * %GDATA_GD_POSTAL_ADDRESS_OTHER.
136 *
137 * For more information, see the
138 * <ulink type="http" url="http://code.google.com/apis/gdata/docs/2.0/elements.html#gdStructuredPostalAddress">GData specification</ulink>.
139 *
140 * Since: 0.4.0
141 */
142 g_object_class_install_property (gobject_class, PROP_RELATION_TYPE,
143 g_param_spec_string ("relation-type",
144 "Relation type", "A programmatic value that identifies the type of postal address.",
145 GDATA_GD_POSTAL_ADDRESS_WORK,
146 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
147
148 /**
149 * GDataGDPostalAddress:label:
150 *
151 * A simple string value used to name this postal address. It allows UIs to display a label such as "Work", "Personal", "Preferred", etc.
152 *
153 * For more information, see the
154 * <ulink type="http" url="http://code.google.com/apis/gdata/docs/2.0/elements.html#gdStructuredPostalAddress">GData specification</ulink>.
155 *
156 * Since: 0.4.0
157 */
158 g_object_class_install_property (gobject_class, PROP_LABEL,
159 g_param_spec_string ("label",
160 "Label", "A simple string value used to name this postal address.",
161 NULL,
162 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
163
164 /**
165 * GDataGDPostalAddress:is-primary:
166 *
167 * Indicates which postal address out of a group is primary.
168 *
169 * For more information, see the
170 * <ulink type="http" url="http://code.google.com/apis/gdata/docs/2.0/elements.html#gdStructuredPostalAddress">GData specification</ulink>.
171 *
172 * Since: 0.4.0
173 */
174 g_object_class_install_property (gobject_class, PROP_IS_PRIMARY,
175 g_param_spec_boolean ("is-primary",
176 "Primary?", "Indicates which postal address out of a group is primary.",
177 FALSE,
178 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
179
180 /**
181 * GDataGDPostalAddress:mail-class:
182 *
183 * Classes of mail accepted at this address. For example: %GDATA_GD_MAIL_CLASS_LETTERS or %GDATA_GD_MAIL_CLASS_BOTH.
184 *
185 * For more information, see the
186 * <ulink type="http" url="http://code.google.com/apis/gdata/docs/2.0/elements.html#gdStructuredPostalAddress">GData specification</ulink>.
187 *
188 * Since: 0.5.0
189 */
190 g_object_class_install_property (gobject_class, PROP_MAIL_CLASS,
191 g_param_spec_string ("mail-class",
192 "Mail class", "Classes of mail accepted at this address.",
193 GDATA_GD_MAIL_CLASS_BOTH,
194 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
195
196 /**
197 * GDataGDPostalAddress:usage:
198 *
199 * The context in which this address can be used. For example: %GDATA_GD_ADDRESS_USAGE_GENERAL or %GDATA_GD_ADDRESS_USAGE_LOCAL.
200 *
201 * For more information, see the
202 * <ulink type="http" url="http://code.google.com/apis/gdata/docs/2.0/elements.html#gdStructuredPostalAddress">GData specification</ulink>.
203 *
204 * Since: 0.5.0
205 */
206 g_object_class_install_property (gobject_class, PROP_USAGE,
207 g_param_spec_string ("usage",
208 "Usage", "The context in which this address can be used.",
209 GDATA_GD_ADDRESS_USAGE_GENERAL,
210 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
211
212 /**
213 * GDataGDPostalAddress:agent:
214 *
215 * The agent who actually receives the mail. Used in work addresses. Also for "in care of" or "c/o".
216 *
217 * For more information, see the
218 * <ulink type="http" url="http://code.google.com/apis/gdata/docs/2.0/elements.html#gdStructuredPostalAddress">GData specification</ulink>.
219 *
220 * Since: 0.5.0
221 */
222 g_object_class_install_property (gobject_class, PROP_AGENT,
223 g_param_spec_string ("agent",
224 "Agent", "The agent who actually receives the mail.",
225 NULL,
226 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
227
228 /**
229 * GDataGDPostalAddress:house-name:
230 *
231 * Used in places where houses or buildings have names (and not necessarily numbers).
232 *
233 * For more information, see the
234 * <ulink type="http" url="http://code.google.com/apis/gdata/docs/2.0/elements.html#gdStructuredPostalAddress">GData specification</ulink>.
235 *
236 * Since: 0.5.0
237 */
238 g_object_class_install_property (gobject_class, PROP_HOUSE_NAME,
239 g_param_spec_string ("house-name",
240 "House name", "Used in places where houses or buildings have names (and not numbers).",
241 NULL,
242 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
243
244 /**
245 * GDataGDPostalAddress:street:
246 *
247 * Can be street, avenue, road, etc. This element also includes the house number and room/apartment/flat/floor number.
248 *
249 * For more information, see the
250 * <ulink type="http" url="http://code.google.com/apis/gdata/docs/2.0/elements.html#gdStructuredPostalAddress">GData specification</ulink>.
251 *
252 * Since: 0.5.0
253 */
254 g_object_class_install_property (gobject_class, PROP_STREET,
255 g_param_spec_string ("street",
256 "Street", "Can be street, avenue, road, etc.",
257 NULL,
258 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
259
260 /**
261 * GDataGDPostalAddress:po-box:
262 *
263 * Covers actual P.O. boxes, drawers, locked bags, etc. This is usually but not always mutually exclusive with #GDataGDPostalAddress:street.
264 *
265 * For more information, see the
266 * <ulink type="http" url="http://code.google.com/apis/gdata/docs/2.0/elements.html#gdStructuredPostalAddress">GData specification</ulink>.
267 *
268 * Since: 0.5.0
269 */
270 g_object_class_install_property (gobject_class, PROP_PO_BOX,
271 g_param_spec_string ("po-box",
272 "PO box", "Covers actual P.O. boxes, drawers, locked bags, etc.",
273 NULL,
274 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
275
276 /**
277 * GDataGDPostalAddress:neighborhood:
278 *
279 * This is used to disambiguate a street address when a city contains more than one street with the same name, or to specify a small place
280 * whose mail is routed through a larger postal town. In China it could be a county or a minor city.
281 *
282 * For more information, see the
283 * <ulink type="http" url="http://code.google.com/apis/gdata/docs/2.0/elements.html#gdStructuredPostalAddress">GData specification</ulink>.
284 *
285 * Since: 0.5.0
286 */
287 g_object_class_install_property (gobject_class, PROP_NEIGHBORHOOD,
288 g_param_spec_string ("neighborhood",
289 "Neighborhood", "This is used to disambiguate a street address.",
290 NULL,
291 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
292
293 /**
294 * GDataGDPostalAddress:city:
295 *
296 * Can be city, village, town, borough, etc. This is the postal town and not necessarily the place of residence or place of business.
297 *
298 * For more information, see the
299 * <ulink type="http" url="http://code.google.com/apis/gdata/docs/2.0/elements.html#gdStructuredPostalAddress">GData specification</ulink>.
300 *
301 * Since: 0.5.0
302 */
303 g_object_class_install_property (gobject_class, PROP_CITY,
304 g_param_spec_string ("city",
305 "City", "Can be city, village, town, borough, etc.",
306 NULL,
307 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
308
309 /**
310 * GDataGDPostalAddress:subregion:
311 *
312 * Handles administrative districts such as U.S. or U.K. counties that are not used for mail addressing purposes.
313 * Subregion is not intended for delivery addresses.
314 *
315 * For more information, see the
316 * <ulink type="http" url="http://code.google.com/apis/gdata/docs/2.0/elements.html#gdStructuredPostalAddress">GData specification</ulink>.
317 *
318 * Since: 0.5.0
319 */
320 g_object_class_install_property (gobject_class, PROP_SUBREGION,
321 g_param_spec_string ("subregion",
322 "Subregion", "Handles administrative districts such as U.S. or U.K. counties.",
323 NULL,
324 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
325
326 /**
327 * GDataGDPostalAddress:region:
328 *
329 * A state, province, county (in Ireland), Land (in Germany), departement (in France), etc.
330 *
331 * For more information, see the
332 * <ulink type="http" url="http://code.google.com/apis/gdata/docs/2.0/elements.html#gdStructuredPostalAddress">GData specification</ulink>.
333 *
334 * Since: 0.5.0
335 */
336 g_object_class_install_property (gobject_class, PROP_REGION,
337 g_param_spec_string ("region",
338 "Region", "A state, province, county, Land, departement, etc.",
339 NULL,
340 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
341
342 /**
343 * GDataGDPostalAddress:postcode:
344 *
345 * Postal code. Usually country-wide, but sometimes specific to the city (e.g. "2" in "Dublin 2, Ireland" addresses).
346 *
347 * For more information, see the
348 * <ulink type="http" url="http://code.google.com/apis/gdata/docs/2.0/elements.html#gdStructuredPostalAddress">GData specification</ulink>.
349 *
350 * Since: 0.5.0
351 */
352 g_object_class_install_property (gobject_class, PROP_POSTCODE,
353 g_param_spec_string ("postcode",
354 "Postcode", "Postal code.",
355 NULL,
356 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
357
358 /**
359 * GDataGDPostalAddress:country:
360 *
361 * The name of the country. Since this is paired with #GDataGDPostalAddress:country-code, they must both be set with
362 * gdata_gd_postal_address_set_country().
363 *
364 * For more information, see the
365 * <ulink type="http" url="http://code.google.com/apis/gdata/docs/2.0/elements.html#gdStructuredPostalAddress">GData specification</ulink>.
366 *
367 * Since: 0.5.0
368 */
369 g_object_class_install_property (gobject_class, PROP_COUNTRY,
370 g_param_spec_string ("country",
371 "Country", "The name of the country.",
372 NULL,
373 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
374
375 /**
376 * GDataGDPostalAddress:country-code:
377 *
378 * The ISO 3166-1 alpha-2 country code for the country in #GDataGDPostalAddress:country. Since this is paired with
379 * #GDataGDPostalAddress:country, they must both be set with gdata_gd_postal_address_set_country().
380 *
381 * For more information, see the
382 * <ulink type="http" url="http://code.google.com/apis/gdata/docs/2.0/elements.html#gdStructuredPostalAddress">GData specification</ulink>
383 * or <ulink type="http" url="http://www.iso.org/iso/iso-3166-1_decoding_table">ISO 3166-1 alpha-2</ulink>.
384 *
385 * Since: 0.5.0
386 */
387 g_object_class_install_property (gobject_class, PROP_COUNTRY_CODE,
388 g_param_spec_string ("country-code",
389 "Country code", "The ISO 3166-1 alpha-2 country code for the country.",
390 NULL,
391 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
392 }
393
394 static gint
compare_with(GDataComparable * self,GDataComparable * other)395 compare_with (GDataComparable *self, GDataComparable *other)
396 {
397 GDataGDPostalAddressPrivate *a = ((GDataGDPostalAddress*) self)->priv, *b = ((GDataGDPostalAddress*) other)->priv;
398
399 if (g_strcmp0 (a->street, b->street) == 0 && g_strcmp0 (a->po_box, b->po_box) == 0 &&
400 g_strcmp0 (a->city, b->city) == 0 && g_strcmp0 (a->postcode, b->postcode) == 0)
401 return 0;
402 return 1;
403 }
404
405 static void
gdata_gd_postal_address_comparable_init(GDataComparableIface * iface)406 gdata_gd_postal_address_comparable_init (GDataComparableIface *iface)
407 {
408 iface->compare_with = compare_with;
409 }
410
411 static void
gdata_gd_postal_address_init(GDataGDPostalAddress * self)412 gdata_gd_postal_address_init (GDataGDPostalAddress *self)
413 {
414 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GDATA_TYPE_GD_POSTAL_ADDRESS, GDataGDPostalAddressPrivate);
415 }
416
417 static void
gdata_gd_postal_address_finalize(GObject * object)418 gdata_gd_postal_address_finalize (GObject *object)
419 {
420 GDataGDPostalAddressPrivate *priv = GDATA_GD_POSTAL_ADDRESS (object)->priv;
421
422 g_free (priv->formatted_address);
423 g_free (priv->relation_type);
424 g_free (priv->label);
425 g_free (priv->mail_class);
426 g_free (priv->usage);
427 g_free (priv->agent);
428 g_free (priv->house_name);
429 g_free (priv->street);
430 g_free (priv->po_box);
431 g_free (priv->neighborhood);
432 g_free (priv->city);
433 g_free (priv->subregion);
434 g_free (priv->region);
435 g_free (priv->postcode);
436 g_free (priv->country);
437 g_free (priv->country_code);
438
439 /* Chain up to the parent class */
440 G_OBJECT_CLASS (gdata_gd_postal_address_parent_class)->finalize (object);
441 }
442
443 static void
gdata_gd_postal_address_get_property(GObject * object,guint property_id,GValue * value,GParamSpec * pspec)444 gdata_gd_postal_address_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
445 {
446 GDataGDPostalAddressPrivate *priv = GDATA_GD_POSTAL_ADDRESS (object)->priv;
447
448 switch (property_id) {
449 case PROP_FORMATTED_ADDRESS:
450 g_value_set_string (value, priv->formatted_address);
451 break;
452 case PROP_RELATION_TYPE:
453 g_value_set_string (value, priv->relation_type);
454 break;
455 case PROP_LABEL:
456 g_value_set_string (value, priv->label);
457 break;
458 case PROP_IS_PRIMARY:
459 g_value_set_boolean (value, priv->is_primary);
460 break;
461 case PROP_MAIL_CLASS:
462 g_value_set_string (value, priv->mail_class);
463 break;
464 case PROP_USAGE:
465 g_value_set_string (value, priv->usage);
466 break;
467 case PROP_AGENT:
468 g_value_set_string (value, priv->agent);
469 break;
470 case PROP_HOUSE_NAME:
471 g_value_set_string (value, priv->house_name);
472 break;
473 case PROP_STREET:
474 g_value_set_string (value, priv->street);
475 break;
476 case PROP_PO_BOX:
477 g_value_set_string (value, priv->po_box);
478 break;
479 case PROP_NEIGHBORHOOD:
480 g_value_set_string (value, priv->neighborhood);
481 break;
482 case PROP_CITY:
483 g_value_set_string (value, priv->city);
484 break;
485 case PROP_SUBREGION:
486 g_value_set_string (value, priv->subregion);
487 break;
488 case PROP_REGION:
489 g_value_set_string (value, priv->region);
490 break;
491 case PROP_POSTCODE:
492 g_value_set_string (value, priv->postcode);
493 break;
494 case PROP_COUNTRY:
495 g_value_set_string (value, priv->country);
496 break;
497 case PROP_COUNTRY_CODE:
498 g_value_set_string (value, priv->country_code);
499 break;
500 default:
501 /* We don't have any other property... */
502 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
503 break;
504 }
505 }
506
507 static void
gdata_gd_postal_address_set_property(GObject * object,guint property_id,const GValue * value,GParamSpec * pspec)508 gdata_gd_postal_address_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
509 {
510 GDataGDPostalAddress *self = GDATA_GD_POSTAL_ADDRESS (object);
511
512 switch (property_id) {
513 case PROP_FORMATTED_ADDRESS:
514 gdata_gd_postal_address_set_address (self, g_value_get_string (value));
515 break;
516 case PROP_RELATION_TYPE:
517 gdata_gd_postal_address_set_relation_type (self, g_value_get_string (value));
518 break;
519 case PROP_LABEL:
520 gdata_gd_postal_address_set_label (self, g_value_get_string (value));
521 break;
522 case PROP_IS_PRIMARY:
523 gdata_gd_postal_address_set_is_primary (self, g_value_get_boolean (value));
524 break;
525 case PROP_MAIL_CLASS:
526 gdata_gd_postal_address_set_mail_class (self, g_value_get_string (value));
527 break;
528 case PROP_USAGE:
529 gdata_gd_postal_address_set_usage (self, g_value_get_string (value));
530 break;
531 case PROP_AGENT:
532 gdata_gd_postal_address_set_agent (self, g_value_get_string (value));
533 break;
534 case PROP_HOUSE_NAME:
535 gdata_gd_postal_address_set_house_name (self, g_value_get_string (value));
536 break;
537 case PROP_STREET:
538 gdata_gd_postal_address_set_street (self, g_value_get_string (value));
539 break;
540 case PROP_PO_BOX:
541 gdata_gd_postal_address_set_po_box (self, g_value_get_string (value));
542 break;
543 case PROP_NEIGHBORHOOD:
544 gdata_gd_postal_address_set_neighborhood (self, g_value_get_string (value));
545 break;
546 case PROP_CITY:
547 gdata_gd_postal_address_set_city (self, g_value_get_string (value));
548 break;
549 case PROP_SUBREGION:
550 gdata_gd_postal_address_set_subregion (self, g_value_get_string (value));
551 break;
552 case PROP_REGION:
553 gdata_gd_postal_address_set_region (self, g_value_get_string (value));
554 break;
555 case PROP_POSTCODE:
556 gdata_gd_postal_address_set_postcode (self, g_value_get_string (value));
557 break;
558 default:
559 /* We don't have any other property... */
560 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
561 break;
562 }
563 }
564
565 static gboolean
pre_parse_xml(GDataParsable * parsable,xmlDoc * doc,xmlNode * root_node,gpointer user_data,GError ** error)566 pre_parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *root_node, gpointer user_data, GError **error)
567 {
568 xmlChar *rel;
569 gboolean primary_bool;
570 GDataGDPostalAddressPrivate *priv = GDATA_GD_POSTAL_ADDRESS (parsable)->priv;
571
572 /* Is it the primary postal address? */
573 if (gdata_parser_boolean_from_property (root_node, "primary", &primary_bool, 0, error) == FALSE)
574 return FALSE;
575
576 rel = xmlGetProp (root_node, (xmlChar*) "rel");
577 if (rel != NULL && *rel == '\0') {
578 xmlFree (rel);
579 return gdata_parser_error_required_property_missing (root_node, "rel", error);
580 }
581
582 priv->relation_type = (gchar*) rel;
583 priv->label = (gchar*) xmlGetProp (root_node, (xmlChar*) "label");
584 priv->mail_class = (gchar*) xmlGetProp (root_node, (xmlChar*) "mailClass");
585 priv->usage = (gchar*) xmlGetProp (root_node, (xmlChar*) "usage");
586 priv->is_primary = primary_bool;
587
588 return TRUE;
589 }
590
591 static gboolean
parse_xml(GDataParsable * parsable,xmlDoc * doc,xmlNode * node,gpointer user_data,GError ** error)592 parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_data, GError **error)
593 {
594 gboolean success;
595 GDataGDPostalAddressPrivate *priv = GDATA_GD_POSTAL_ADDRESS (parsable)->priv;
596
597 if (gdata_parser_is_namespace (node, "http://schemas.google.com/g/2005") == TRUE) {
598 if (gdata_parser_string_from_element (node, "agent", P_NO_DUPES, &(priv->agent), &success, error) == TRUE ||
599 gdata_parser_string_from_element (node, "housename", P_NO_DUPES, &(priv->house_name), &success, error) == TRUE ||
600 gdata_parser_string_from_element (node, "pobox", P_NO_DUPES, &(priv->po_box), &success, error) == TRUE ||
601 gdata_parser_string_from_element (node, "street", P_NO_DUPES, &(priv->street), &success, error) == TRUE ||
602 gdata_parser_string_from_element (node, "neighborhood", P_NO_DUPES, &(priv->neighborhood), &success, error) == TRUE ||
603 gdata_parser_string_from_element (node, "city", P_NO_DUPES, &(priv->city), &success, error) == TRUE ||
604 gdata_parser_string_from_element (node, "subregion", P_NO_DUPES, &(priv->subregion), &success, error) == TRUE ||
605 gdata_parser_string_from_element (node, "region", P_NO_DUPES, &(priv->region), &success, error) == TRUE ||
606 gdata_parser_string_from_element (node, "postcode", P_NO_DUPES, &(priv->postcode), &success, error) == TRUE ||
607 gdata_parser_string_from_element (node, "formattedAddress", P_NO_DUPES, &(priv->formatted_address), &success, error) == TRUE) {
608 return success;
609 } else if (xmlStrcmp (node->name, (xmlChar*) "country") == 0) {
610 /* gd:country */
611 priv->country_code = (gchar*) xmlGetProp (node, (xmlChar*) "code");
612 priv->country = (gchar*) xmlNodeListGetString (doc, node->children, TRUE);
613
614 return TRUE;
615 }
616 }
617
618 return GDATA_PARSABLE_CLASS (gdata_gd_postal_address_parent_class)->parse_xml (parsable, doc, node, user_data, error);
619 }
620
621 static void
pre_get_xml(GDataParsable * parsable,GString * xml_string)622 pre_get_xml (GDataParsable *parsable, GString *xml_string)
623 {
624 GDataGDPostalAddressPrivate *priv = GDATA_GD_POSTAL_ADDRESS (parsable)->priv;
625
626 if (priv->relation_type != NULL)
627 gdata_parser_string_append_escaped (xml_string, " rel='", priv->relation_type, "'");
628 if (priv->label != NULL)
629 gdata_parser_string_append_escaped (xml_string, " label='", priv->label, "'");
630 if (priv->mail_class != NULL)
631 gdata_parser_string_append_escaped (xml_string, " mailClass='", priv->mail_class, "'");
632 if (priv->usage != NULL)
633 gdata_parser_string_append_escaped (xml_string, " usage='", priv->usage, "'");
634
635 if (priv->is_primary == TRUE)
636 g_string_append (xml_string, " primary='true'");
637 else
638 g_string_append (xml_string, " primary='false'");
639 }
640
641 static void
get_xml(GDataParsable * parsable,GString * xml_string)642 get_xml (GDataParsable *parsable, GString *xml_string)
643 {
644 GDataGDPostalAddressPrivate *priv = GDATA_GD_POSTAL_ADDRESS (parsable)->priv;
645
646 #define OUTPUT_STRING_ELEMENT(E,F) \
647 if (priv->F != NULL) \
648 gdata_parser_string_append_escaped (xml_string, "<gd:" E ">", priv->F, "</gd:" E ">");
649
650 OUTPUT_STRING_ELEMENT ("agent", agent)
651 OUTPUT_STRING_ELEMENT ("housename", house_name)
652 OUTPUT_STRING_ELEMENT ("street", street)
653 OUTPUT_STRING_ELEMENT ("pobox", po_box)
654 OUTPUT_STRING_ELEMENT ("neighborhood", neighborhood)
655 OUTPUT_STRING_ELEMENT ("city", city)
656 OUTPUT_STRING_ELEMENT ("subregion", subregion)
657 OUTPUT_STRING_ELEMENT ("region", region)
658 OUTPUT_STRING_ELEMENT ("postcode", postcode)
659
660 if (priv->country != NULL) {
661 if (priv->country_code != NULL)
662 gdata_parser_string_append_escaped (xml_string, "<gd:country code='", priv->country_code, "'>");
663 else
664 g_string_append (xml_string, "<gd:country>");
665 gdata_parser_string_append_escaped (xml_string, NULL, priv->country, "</gd:country>");
666 }
667
668 OUTPUT_STRING_ELEMENT ("formattedAddress", formatted_address)
669
670 #undef OUTPUT_STRING_ELEMENT
671 }
672
673 static void
get_namespaces(GDataParsable * parsable,GHashTable * namespaces)674 get_namespaces (GDataParsable *parsable, GHashTable *namespaces)
675 {
676 g_hash_table_insert (namespaces, (gchar*) "gd", (gchar*) "http://schemas.google.com/g/2005");
677 }
678
679 /**
680 * gdata_gd_postal_address_new:
681 * @relation_type: (allow-none): the relationship between the address and its owner, or %NULL
682 * @label: (allow-none): a human-readable label for the address, or %NULL
683 * @is_primary: %TRUE if this phone number is its owner's primary number, %FALSE otherwise
684 *
685 * Creates a new #GDataGDPostalAddress. More information is available in the <ulink type="http"
686 * url="http://code.google.com/apis/gdata/docs/2.0/elements.html#gdStructuredPostalAddress">GData specification</ulink>.
687 *
688 * Return value: a new #GDataGDPostalAddress, or %NULL; unref with g_object_unref()
689 *
690 * Since: 0.2.0
691 */
692 GDataGDPostalAddress *
gdata_gd_postal_address_new(const gchar * relation_type,const gchar * label,gboolean is_primary)693 gdata_gd_postal_address_new (const gchar *relation_type, const gchar *label, gboolean is_primary)
694 {
695 g_return_val_if_fail (relation_type == NULL || *relation_type != '\0', NULL);
696 return g_object_new (GDATA_TYPE_GD_POSTAL_ADDRESS, "relation-type", relation_type, "label", label, "is-primary", is_primary, NULL);
697 }
698
699 /**
700 * gdata_gd_postal_address_get_address:
701 * @self: a #GDataGDPostalAddress
702 *
703 * Gets the #GDataGDPostalAddress:address property.
704 *
705 * Return value: the postal address itself, or %NULL
706 *
707 * Since: 0.4.0
708 */
709 const gchar *
gdata_gd_postal_address_get_address(GDataGDPostalAddress * self)710 gdata_gd_postal_address_get_address (GDataGDPostalAddress *self)
711 {
712 g_return_val_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self), NULL);
713 return self->priv->formatted_address;
714 }
715
716 /**
717 * gdata_gd_postal_address_set_address:
718 * @self: a #GDataGDPostalAddress
719 * @address: (allow-none): the new postal address, or %NULL
720 *
721 * Sets the #GDataGDPostalAddress:address property to @address.
722 *
723 * Since: 0.4.0
724 */
725 void
gdata_gd_postal_address_set_address(GDataGDPostalAddress * self,const gchar * address)726 gdata_gd_postal_address_set_address (GDataGDPostalAddress *self, const gchar *address)
727 {
728 g_return_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self));
729
730 /* Trim leading and trailing whitespace from the address.
731 * See here: http://code.google.com/apis/gdata/docs/1.0/elements.html#gdPostalAddress */
732 g_free (self->priv->formatted_address);
733 self->priv->formatted_address = gdata_parser_utf8_trim_whitespace (address);
734 g_object_notify (G_OBJECT (self), "address");
735 }
736
737 /**
738 * gdata_gd_postal_address_get_relation_type:
739 * @self: a #GDataGDPostalAddress
740 *
741 * Gets the #GDataGDPostalAddress:relation-type property.
742 *
743 * Return value: the postal address' relation type, or %NULL
744 *
745 * Since: 0.4.0
746 */
747 const gchar *
gdata_gd_postal_address_get_relation_type(GDataGDPostalAddress * self)748 gdata_gd_postal_address_get_relation_type (GDataGDPostalAddress *self)
749 {
750 g_return_val_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self), NULL);
751 return self->priv->relation_type;
752 }
753
754 /**
755 * gdata_gd_postal_address_set_relation_type:
756 * @self: a #GDataGDPostalAddress
757 * @relation_type: (allow-none): the new relation type for the postal_address, or %NULL
758 *
759 * Sets the #GDataGDPostalAddress:relation-type property to @relation_type.
760 *
761 * Set @relation_type to %NULL to unset the property in the postal address.
762 *
763 * Since: 0.4.0
764 */
765 void
gdata_gd_postal_address_set_relation_type(GDataGDPostalAddress * self,const gchar * relation_type)766 gdata_gd_postal_address_set_relation_type (GDataGDPostalAddress *self, const gchar *relation_type)
767 {
768 g_return_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self));
769 g_return_if_fail (relation_type == NULL || *relation_type != '\0');
770
771 g_free (self->priv->relation_type);
772 self->priv->relation_type = g_strdup (relation_type);
773 g_object_notify (G_OBJECT (self), "relation-type");
774 }
775
776 /**
777 * gdata_gd_postal_address_get_label:
778 * @self: a #GDataGDPostalAddress
779 *
780 * Gets the #GDataGDPostalAddress:label property.
781 *
782 * Return value: the postal address' label, or %NULL
783 *
784 * Since: 0.4.0
785 */
786 const gchar *
gdata_gd_postal_address_get_label(GDataGDPostalAddress * self)787 gdata_gd_postal_address_get_label (GDataGDPostalAddress *self)
788 {
789 g_return_val_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self), NULL);
790 return self->priv->label;
791 }
792
793 /**
794 * gdata_gd_postal_address_set_label:
795 * @self: a #GDataGDPostalAddress
796 * @label: (allow-none): the new label for the postal address, or %NULL
797 *
798 * Sets the #GDataGDPostalAddress:label property to @label.
799 *
800 * Set @label to %NULL to unset the property in the postal address.
801 *
802 * Since: 0.4.0
803 */
804 void
gdata_gd_postal_address_set_label(GDataGDPostalAddress * self,const gchar * label)805 gdata_gd_postal_address_set_label (GDataGDPostalAddress *self, const gchar *label)
806 {
807 g_return_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self));
808
809 g_free (self->priv->label);
810 self->priv->label = g_strdup (label);
811 g_object_notify (G_OBJECT (self), "label");
812 }
813
814 /**
815 * gdata_gd_postal_address_is_primary:
816 * @self: a #GDataGDPostalAddress
817 *
818 * Gets the #GDataGDPostalAddress:is-primary property.
819 *
820 * Return value: %TRUE if this is the primary postal address, %FALSE otherwise
821 *
822 * Since: 0.4.0
823 */
824 gboolean
gdata_gd_postal_address_is_primary(GDataGDPostalAddress * self)825 gdata_gd_postal_address_is_primary (GDataGDPostalAddress *self)
826 {
827 g_return_val_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self), FALSE);
828 return self->priv->is_primary;
829 }
830
831 /**
832 * gdata_gd_postal_address_set_is_primary:
833 * @self: a #GDataGDPostalAddress
834 * @is_primary: %TRUE if this is the primary postal address, %FALSE otherwise
835 *
836 * Sets the #GDataGDPostalAddress:is-primary property to @is_primary.
837 *
838 * Since: 0.4.0
839 */
840 void
gdata_gd_postal_address_set_is_primary(GDataGDPostalAddress * self,gboolean is_primary)841 gdata_gd_postal_address_set_is_primary (GDataGDPostalAddress *self, gboolean is_primary)
842 {
843 g_return_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self));
844
845 self->priv->is_primary = is_primary;
846 g_object_notify (G_OBJECT (self), "is-primary");
847 }
848
849 /**
850 * gdata_gd_postal_address_get_mail_class:
851 * @self: a #GDataGDPostalAddress
852 *
853 * Gets the #GDataGDPostalAddress:mail-class property.
854 *
855 * Return value: the postal address' mail class, or %NULL
856 *
857 * Since: 0.5.0
858 */
859 const gchar *
gdata_gd_postal_address_get_mail_class(GDataGDPostalAddress * self)860 gdata_gd_postal_address_get_mail_class (GDataGDPostalAddress *self)
861 {
862 g_return_val_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self), NULL);
863 return self->priv->mail_class;
864 }
865
866 /**
867 * gdata_gd_postal_address_set_mail_class:
868 * @self: a #GDataGDPostalAddress
869 * @mail_class: (allow-none): the new mail class for the postal address, or %NULL
870 *
871 * Sets the #GDataGDPostalAddress:mail-class property to @mail_class.
872 *
873 * Set @mail_class to %NULL to unset the property in the postal address.
874 *
875 * Since: 0.5.0
876 */
877 void
gdata_gd_postal_address_set_mail_class(GDataGDPostalAddress * self,const gchar * mail_class)878 gdata_gd_postal_address_set_mail_class (GDataGDPostalAddress *self, const gchar *mail_class)
879 {
880 g_return_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self));
881 g_return_if_fail (mail_class == NULL || *mail_class != '\0');
882
883 g_free (self->priv->mail_class);
884 self->priv->mail_class = g_strdup (mail_class);
885 g_object_notify (G_OBJECT (self), "mail-class");
886 }
887
888 /**
889 * gdata_gd_postal_address_get_usage:
890 * @self: a #GDataGDPostalAddress
891 *
892 * Gets the #GDataGDPostalAddress:usage property.
893 *
894 * Return value: the postal address' usage, or %NULL
895 *
896 * Since: 0.5.0
897 */
898 const gchar *
gdata_gd_postal_address_get_usage(GDataGDPostalAddress * self)899 gdata_gd_postal_address_get_usage (GDataGDPostalAddress *self)
900 {
901 g_return_val_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self), NULL);
902 return self->priv->usage;
903 }
904
905 /**
906 * gdata_gd_postal_address_set_usage:
907 * @self: a #GDataGDPostalAddress
908 * @usage: (allow-none): the new usage for the postal address, or %NULL
909 *
910 * Sets the #GDataGDPostalAddress:usage property to @usage.
911 *
912 * Set @usage to %NULL to unset the property in the postal address.
913 *
914 * Since: 0.5.0
915 */
916 void
gdata_gd_postal_address_set_usage(GDataGDPostalAddress * self,const gchar * usage)917 gdata_gd_postal_address_set_usage (GDataGDPostalAddress *self, const gchar *usage)
918 {
919 g_return_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self));
920 g_return_if_fail (usage == NULL || *usage != '\0');
921
922 g_free (self->priv->usage);
923 self->priv->usage = g_strdup (usage);
924 g_object_notify (G_OBJECT (self), "usage");
925 }
926
927 /**
928 * gdata_gd_postal_address_get_agent:
929 * @self: a #GDataGDPostalAddress
930 *
931 * Gets the #GDataGDPostalAddress:agent property.
932 *
933 * Return value: the postal address' agent, or %NULL
934 *
935 * Since: 0.5.0
936 */
937 const gchar *
gdata_gd_postal_address_get_agent(GDataGDPostalAddress * self)938 gdata_gd_postal_address_get_agent (GDataGDPostalAddress *self)
939 {
940 g_return_val_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self), NULL);
941 return self->priv->agent;
942 }
943
944 /**
945 * gdata_gd_postal_address_set_agent:
946 * @self: a #GDataGDPostalAddress
947 * @agent: (allow-none): the new agent for the postal address, or %NULL
948 *
949 * Sets the #GDataGDPostalAddress:agent property to @agent.
950 *
951 * Set @agent to %NULL to unset the property in the postal address.
952 *
953 * Since: 0.5.0
954 */
955 void
gdata_gd_postal_address_set_agent(GDataGDPostalAddress * self,const gchar * agent)956 gdata_gd_postal_address_set_agent (GDataGDPostalAddress *self, const gchar *agent)
957 {
958 g_return_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self));
959 g_return_if_fail (agent == NULL || *agent != '\0');
960
961 g_free (self->priv->agent);
962 self->priv->agent = g_strdup (agent);
963 g_object_notify (G_OBJECT (self), "agent");
964 }
965
966 /**
967 * gdata_gd_postal_address_get_house_name:
968 * @self: a #GDataGDPostalAddress
969 *
970 * Gets the #GDataGDPostalAddress:house-name property.
971 *
972 * Return value: the postal address' house name, or %NULL
973 *
974 * Since: 0.5.0
975 */
976 const gchar *
gdata_gd_postal_address_get_house_name(GDataGDPostalAddress * self)977 gdata_gd_postal_address_get_house_name (GDataGDPostalAddress *self)
978 {
979 g_return_val_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self), NULL);
980 return self->priv->house_name;
981 }
982
983 /**
984 * gdata_gd_postal_address_set_house_name:
985 * @self: a #GDataGDPostalAddress
986 * @house_name: (allow-none): the new house name for the postal address, or %NULL
987 *
988 * Sets the #GDataGDPostalAddress:house-name property to @house_name.
989 *
990 * Set @house_name to %NULL to unset the property in the postal address.
991 *
992 * Since: 0.5.0
993 */
994 void
gdata_gd_postal_address_set_house_name(GDataGDPostalAddress * self,const gchar * house_name)995 gdata_gd_postal_address_set_house_name (GDataGDPostalAddress *self, const gchar *house_name)
996 {
997 g_return_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self));
998 g_return_if_fail (house_name == NULL || *house_name != '\0');
999
1000 g_free (self->priv->house_name);
1001 self->priv->house_name = g_strdup (house_name);
1002 g_object_notify (G_OBJECT (self), "house-name");
1003 }
1004
1005 /**
1006 * gdata_gd_postal_address_get_street:
1007 * @self: a #GDataGDPostalAddress
1008 *
1009 * Gets the #GDataGDPostalAddress:street property.
1010 *
1011 * Return value: the postal address' street, or %NULL
1012 *
1013 * Since: 0.5.0
1014 */
1015 const gchar *
gdata_gd_postal_address_get_street(GDataGDPostalAddress * self)1016 gdata_gd_postal_address_get_street (GDataGDPostalAddress *self)
1017 {
1018 g_return_val_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self), NULL);
1019 return self->priv->street;
1020 }
1021
1022 /**
1023 * gdata_gd_postal_address_set_street:
1024 * @self: a #GDataGDPostalAddress
1025 * @street: (allow-none): the new street for the postal address, or %NULL
1026 *
1027 * Sets the #GDataGDPostalAddress:street property to @street.
1028 *
1029 * Set @street to %NULL to unset the property in the postal address.
1030 *
1031 * Since: 0.5.0
1032 */
1033 void
gdata_gd_postal_address_set_street(GDataGDPostalAddress * self,const gchar * street)1034 gdata_gd_postal_address_set_street (GDataGDPostalAddress *self, const gchar *street)
1035 {
1036 g_return_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self));
1037 g_return_if_fail (street == NULL || *street != '\0');
1038
1039 g_free (self->priv->street);
1040 self->priv->street = g_strdup (street);
1041 g_object_notify (G_OBJECT (self), "street");
1042 }
1043
1044 /**
1045 * gdata_gd_postal_address_get_po_box:
1046 * @self: a #GDataGDPostalAddress
1047 *
1048 * Gets the #GDataGDPostalAddress:po-box property.
1049 *
1050 * Return value: the postal address' P.O. box, or %NULL
1051 *
1052 * Since: 0.5.0
1053 */
1054 const gchar *
gdata_gd_postal_address_get_po_box(GDataGDPostalAddress * self)1055 gdata_gd_postal_address_get_po_box (GDataGDPostalAddress *self)
1056 {
1057 g_return_val_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self), NULL);
1058 return self->priv->po_box;
1059 }
1060
1061 /**
1062 * gdata_gd_postal_address_set_po_box:
1063 * @self: a #GDataGDPostalAddress
1064 * @po_box: (allow-none): the new P.O. box for the postal address, or %NULL
1065 *
1066 * Sets the #GDataGDPostalAddress:po-box property to @po_box.
1067 *
1068 * Set @po_box to %NULL to unset the property in the postal address.
1069 *
1070 * Since: 0.5.0
1071 */
1072 void
gdata_gd_postal_address_set_po_box(GDataGDPostalAddress * self,const gchar * po_box)1073 gdata_gd_postal_address_set_po_box (GDataGDPostalAddress *self, const gchar *po_box)
1074 {
1075 g_return_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self));
1076 g_return_if_fail (po_box == NULL || *po_box != '\0');
1077
1078 g_free (self->priv->po_box);
1079 self->priv->po_box = g_strdup (po_box);
1080 g_object_notify (G_OBJECT (self), "po-box");
1081 }
1082
1083 /**
1084 * gdata_gd_postal_address_get_neighborhood:
1085 * @self: a #GDataGDPostalAddress
1086 *
1087 * Gets the #GDataGDPostalAddress:neighborhood property.
1088 *
1089 * Return value: the postal address' neighborhood, or %NULL
1090 *
1091 * Since: 0.5.0
1092 */
1093 const gchar *
gdata_gd_postal_address_get_neighborhood(GDataGDPostalAddress * self)1094 gdata_gd_postal_address_get_neighborhood (GDataGDPostalAddress *self)
1095 {
1096 g_return_val_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self), NULL);
1097 return self->priv->neighborhood;
1098 }
1099
1100 /**
1101 * gdata_gd_postal_address_set_neighborhood:
1102 * @self: a #GDataGDPostalAddress
1103 * @neighborhood: (allow-none): the new neighborhood for the postal address, or %NULL
1104 *
1105 * Sets the #GDataGDPostalAddress:neighborhood property to @neighborhood.
1106 *
1107 * Set @neighborhood to %NULL to unset the property in the postal address.
1108 *
1109 * Since: 0.5.0
1110 */
1111 void
gdata_gd_postal_address_set_neighborhood(GDataGDPostalAddress * self,const gchar * neighborhood)1112 gdata_gd_postal_address_set_neighborhood (GDataGDPostalAddress *self, const gchar *neighborhood)
1113 {
1114 g_return_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self));
1115 g_return_if_fail (neighborhood == NULL || *neighborhood != '\0');
1116
1117 g_free (self->priv->neighborhood);
1118 self->priv->neighborhood = g_strdup (neighborhood);
1119 g_object_notify (G_OBJECT (self), "neighborhood");
1120 }
1121
1122 /**
1123 * gdata_gd_postal_address_get_city:
1124 * @self: a #GDataGDPostalAddress
1125 *
1126 * Gets the #GDataGDPostalAddress:city property.
1127 *
1128 * Return value: the postal address' city, or %NULL
1129 *
1130 * Since: 0.5.0
1131 */
1132 const gchar *
gdata_gd_postal_address_get_city(GDataGDPostalAddress * self)1133 gdata_gd_postal_address_get_city (GDataGDPostalAddress *self)
1134 {
1135 g_return_val_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self), NULL);
1136 return self->priv->city;
1137 }
1138
1139 /**
1140 * gdata_gd_postal_address_set_city:
1141 * @self: a #GDataGDPostalAddress
1142 * @city: (allow-none): the new city for the postal address, or %NULL
1143 *
1144 * Sets the #GDataGDPostalAddress:city property to @city.
1145 *
1146 * Set @city to %NULL to unset the property in the postal address.
1147 *
1148 * Since: 0.5.0
1149 */
1150 void
gdata_gd_postal_address_set_city(GDataGDPostalAddress * self,const gchar * city)1151 gdata_gd_postal_address_set_city (GDataGDPostalAddress *self, const gchar *city)
1152 {
1153 g_return_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self));
1154 g_return_if_fail (city == NULL || *city != '\0');
1155
1156 g_free (self->priv->city);
1157 self->priv->city = g_strdup (city);
1158 g_object_notify (G_OBJECT (self), "city");
1159 }
1160
1161 /**
1162 * gdata_gd_postal_address_get_subregion:
1163 * @self: a #GDataGDPostalAddress
1164 *
1165 * Gets the #GDataGDPostalAddress:subregion property.
1166 *
1167 * Return value: the postal address' subregion, or %NULL
1168 *
1169 * Since: 0.5.0
1170 */
1171 const gchar *
gdata_gd_postal_address_get_subregion(GDataGDPostalAddress * self)1172 gdata_gd_postal_address_get_subregion (GDataGDPostalAddress *self)
1173 {
1174 g_return_val_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self), NULL);
1175 return self->priv->subregion;
1176 }
1177
1178 /**
1179 * gdata_gd_postal_address_set_subregion:
1180 * @self: a #GDataGDPostalAddress
1181 * @subregion: (allow-none): the new subregion for the postal address, or %NULL
1182 *
1183 * Sets the #GDataGDPostalAddress:subregion property to @subregion.
1184 *
1185 * Set @subregion to %NULL to unset the property in the postal address.
1186 *
1187 * Since: 0.5.0
1188 */
1189 void
gdata_gd_postal_address_set_subregion(GDataGDPostalAddress * self,const gchar * subregion)1190 gdata_gd_postal_address_set_subregion (GDataGDPostalAddress *self, const gchar *subregion)
1191 {
1192 g_return_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self));
1193 g_return_if_fail (subregion == NULL || *subregion != '\0');
1194
1195 g_free (self->priv->subregion);
1196 self->priv->subregion = g_strdup (subregion);
1197 g_object_notify (G_OBJECT (self), "subregion");
1198 }
1199
1200 /**
1201 * gdata_gd_postal_address_get_region:
1202 * @self: a #GDataGDPostalAddress
1203 *
1204 * Gets the #GDataGDPostalAddress:region property.
1205 *
1206 * Return value: the postal address' region, or %NULL
1207 *
1208 * Since: 0.5.0
1209 */
1210 const gchar *
gdata_gd_postal_address_get_region(GDataGDPostalAddress * self)1211 gdata_gd_postal_address_get_region (GDataGDPostalAddress *self)
1212 {
1213 g_return_val_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self), NULL);
1214 return self->priv->region;
1215 }
1216
1217 /**
1218 * gdata_gd_postal_address_set_region:
1219 * @self: a #GDataGDPostalAddress
1220 * @region: (allow-none): the new region for the postal address, or %NULL
1221 *
1222 * Sets the #GDataGDPostalAddress:region property to @region.
1223 *
1224 * Set @region to %NULL to unset the property in the postal address.
1225 *
1226 * Since: 0.5.0
1227 */
1228 void
gdata_gd_postal_address_set_region(GDataGDPostalAddress * self,const gchar * region)1229 gdata_gd_postal_address_set_region (GDataGDPostalAddress *self, const gchar *region)
1230 {
1231 g_return_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self));
1232 g_return_if_fail (region == NULL || *region != '\0');
1233
1234 g_free (self->priv->region);
1235 self->priv->region = g_strdup (region);
1236 g_object_notify (G_OBJECT (self), "region");
1237 }
1238
1239 /**
1240 * gdata_gd_postal_address_get_postcode:
1241 * @self: a #GDataGDPostalAddress
1242 *
1243 * Gets the #GDataGDPostalAddress:postcode property.
1244 *
1245 * Return value: the postal address' postcode, or %NULL
1246 *
1247 * Since: 0.5.0
1248 */
1249 const gchar *
gdata_gd_postal_address_get_postcode(GDataGDPostalAddress * self)1250 gdata_gd_postal_address_get_postcode (GDataGDPostalAddress *self)
1251 {
1252 g_return_val_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self), NULL);
1253 return self->priv->postcode;
1254 }
1255
1256 /**
1257 * gdata_gd_postal_address_set_postcode:
1258 * @self: a #GDataGDPostalAddress
1259 * @postcode: (allow-none): the new postcode for the postal address, or %NULL
1260 *
1261 * Sets the #GDataGDPostalAddress:postcode property to @postcode.
1262 *
1263 * Set @postcode to %NULL to unset the property in the postal address.
1264 *
1265 * Since: 0.5.0
1266 */
1267 void
gdata_gd_postal_address_set_postcode(GDataGDPostalAddress * self,const gchar * postcode)1268 gdata_gd_postal_address_set_postcode (GDataGDPostalAddress *self, const gchar *postcode)
1269 {
1270 g_return_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self));
1271 g_return_if_fail (postcode == NULL || *postcode != '\0');
1272
1273 g_free (self->priv->postcode);
1274 self->priv->postcode = g_strdup (postcode);
1275 g_object_notify (G_OBJECT (self), "postcode");
1276 }
1277
1278 /**
1279 * gdata_gd_postal_address_get_country:
1280 * @self: a #GDataGDPostalAddress
1281 *
1282 * Gets the #GDataGDPostalAddress:country property.
1283 *
1284 * Return value: the postal address' country, or %NULL
1285 *
1286 * Since: 0.5.0
1287 */
1288 const gchar *
gdata_gd_postal_address_get_country(GDataGDPostalAddress * self)1289 gdata_gd_postal_address_get_country (GDataGDPostalAddress *self)
1290 {
1291 g_return_val_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self), NULL);
1292 return self->priv->country;
1293 }
1294
1295 /**
1296 * gdata_gd_postal_address_get_country_code:
1297 * @self: a #GDataGDPostalAddress
1298 *
1299 * Gets the #GDataGDPostalAddress:country-code property.
1300 *
1301 * Return value: the postal address' ISO 3166-1 alpha-2 country code, or %NULL
1302 *
1303 * Since: 0.5.0
1304 */
1305 const gchar *
gdata_gd_postal_address_get_country_code(GDataGDPostalAddress * self)1306 gdata_gd_postal_address_get_country_code (GDataGDPostalAddress *self)
1307 {
1308 g_return_val_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self), NULL);
1309 return self->priv->country_code;
1310 }
1311
1312 /**
1313 * gdata_gd_postal_address_set_country:
1314 * @self: a #GDataGDPostalAddress
1315 * @country: (allow-none): the new country for the postal address, or %NULL
1316 * @country_code: (allow-none): the new country code for the postal address, or %NULL
1317 *
1318 * Sets the #GDataGDPostalAddress:country property to @country, and #GDataGDPostalAddress:country-code to @country_code.
1319 *
1320 * Set @country or @country_code to %NULL to unset the relevant property in the postal address. If a @country_code is provided, a @country must
1321 * also be provided.
1322 *
1323 * Since: 0.5.0
1324 */
1325 void
gdata_gd_postal_address_set_country(GDataGDPostalAddress * self,const gchar * country,const gchar * country_code)1326 gdata_gd_postal_address_set_country (GDataGDPostalAddress *self, const gchar *country, const gchar *country_code)
1327 {
1328 g_return_if_fail (GDATA_IS_GD_POSTAL_ADDRESS (self));
1329 g_return_if_fail (country != NULL || country_code == NULL);
1330 g_return_if_fail (country == NULL || *country != '\0');
1331 g_return_if_fail (country_code == NULL || *country_code != '\0');
1332
1333 g_free (self->priv->country);
1334 g_free (self->priv->country_code);
1335 self->priv->country = g_strdup (country);
1336 self->priv->country_code = g_strdup (country_code);
1337
1338 g_object_freeze_notify (G_OBJECT (self));
1339 g_object_notify (G_OBJECT (self), "country");
1340 g_object_notify (G_OBJECT (self), "country-code");
1341 g_object_thaw_notify (G_OBJECT (self));
1342 }
1343