~elementary-os/ubuntu-package-imports/geoclue-2.0-bionic

« back to all changes in this revision

Viewing changes to src/geocode-glib/geocode-place.c

  • Committer: RabbitBot
  • Date: 2018-03-13 02:28:15 UTC
  • Revision ID: rabbitbot@elementary.io-20180313022815-09zi5rzcm3grfnxe
Initial import, version 2.4.7-1ubuntu1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Copyright (C) 2012 Bastien Nocera
 
3
 
 
4
   The Gnome Library is free software; you can redistribute it and/or
 
5
   modify it under the terms of the GNU Library General Public License as
 
6
   published by the Free Software Foundation; either version 2 of the
 
7
   License, or (at your option) any later version.
 
8
 
 
9
   The Gnome Library is distributed in the hope that it will be useful,
 
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
   Library General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU Library General Public
 
15
   License along with the Gnome Library; see the file COPYING.LIB.  If not,
 
16
   write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
17
   Boston, MA 02110-1301  USA.
 
18
 
 
19
   Authors: Bastien Nocera <hadess@hadess.net>
 
20
            Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
 
21
 
 
22
 */
 
23
 
 
24
#include <gio/gio.h>
 
25
#include <geocode-glib/geocode-place.h>
 
26
#include <geocode-glib/geocode-bounding-box.h>
 
27
#include <geocode-glib/geocode-enum-types.h>
 
28
#include <geocode-glib/geocode-glib-private.h>
 
29
 
 
30
/**
 
31
 * SECTION:geocode-place
 
32
 * @short_description: Geocode place object
 
33
 * @include: geocode-glib/geocode-glib.h
 
34
 *
 
35
 * The #GeocodePlace instance represents a place on earth. While
 
36
 * #GeocodeLocation represents a point on the planet, #GeocodePlace represents
 
37
 * places, e.g street, town, village, county, country or points of interest
 
38
 * (POI) etc.
 
39
 **/
 
40
 
 
41
struct _GeocodePlacePrivate {
 
42
        char *name;
 
43
        GeocodePlaceType place_type;
 
44
        GeocodeLocation *location;
 
45
        GeocodeBoundingBox *bbox;
 
46
 
 
47
        char *street_address;
 
48
        char *street;
 
49
        char *building;
 
50
        char *postal_code;
 
51
        char *area;
 
52
        char *town;
 
53
        char *county;
 
54
        char *state;
 
55
        char *admin_area;
 
56
        char *country_code;
 
57
        char *country;
 
58
        char *continent;
 
59
        char *osm_id;
 
60
        GeocodePlaceOsmType osm_type;
 
61
};
 
62
 
 
63
enum {
 
64
        PROP_0,
 
65
 
 
66
        PROP_NAME,
 
67
        PROP_PLACE_TYPE,
 
68
        PROP_LOCATION,
 
69
        PROP_STREET_ADDRESS,
 
70
        PROP_STREET,
 
71
        PROP_BUILDING,
 
72
        PROP_POSTAL_CODE,
 
73
        PROP_AREA,
 
74
        PROP_TOWN,
 
75
        PROP_COUNTY,
 
76
        PROP_STATE,
 
77
        PROP_ADMINISTRATIVE_AREA,
 
78
        PROP_COUNTRY_CODE,
 
79
        PROP_COUNTRY,
 
80
        PROP_CONTINENT,
 
81
        PROP_ICON,
 
82
        PROP_BBOX,
 
83
        PROP_OSM_ID,
 
84
        PROP_OSM_TYPE
 
85
};
 
86
 
 
87
G_DEFINE_TYPE (GeocodePlace, geocode_place, G_TYPE_OBJECT)
 
88
 
 
89
static void
 
90
geocode_place_get_property (GObject    *object,
 
91
                            guint       property_id,
 
92
                            GValue     *value,
 
93
                            GParamSpec *pspec)
 
94
{
 
95
        GeocodePlace *place = GEOCODE_PLACE (object);
 
96
 
 
97
        switch (property_id) {
 
98
        case PROP_NAME:
 
99
                g_value_set_string (value,
 
100
                                    geocode_place_get_name (place));
 
101
                break;
 
102
 
 
103
        case PROP_PLACE_TYPE:
 
104
                g_value_set_enum (value,
 
105
                                  geocode_place_get_place_type (place));
 
106
                break;
 
107
 
 
108
        case PROP_LOCATION:
 
109
                g_value_set_object (value,
 
110
                                    geocode_place_get_location (place));
 
111
                break;
 
112
 
 
113
        case PROP_STREET_ADDRESS:
 
114
                g_value_set_string (value,
 
115
                                    geocode_place_get_street_address (place));
 
116
                break;
 
117
 
 
118
        case PROP_STREET:
 
119
                g_value_set_string (value,
 
120
                                    geocode_place_get_street (place));
 
121
                break;
 
122
 
 
123
        case PROP_BUILDING:
 
124
                g_value_set_string (value,
 
125
                                    geocode_place_get_building (place));
 
126
                break;
 
127
 
 
128
        case PROP_POSTAL_CODE:
 
129
                g_value_set_string (value,
 
130
                                    geocode_place_get_postal_code (place));
 
131
                break;
 
132
 
 
133
        case PROP_AREA:
 
134
                g_value_set_string (value,
 
135
                                    geocode_place_get_area (place));
 
136
                break;
 
137
 
 
138
        case PROP_TOWN:
 
139
                g_value_set_string (value,
 
140
                                    geocode_place_get_town (place));
 
141
                break;
 
142
 
 
143
        case PROP_COUNTY:
 
144
                g_value_set_string (value,
 
145
                                    geocode_place_get_county (place));
 
146
                break;
 
147
 
 
148
        case PROP_STATE:
 
149
                g_value_set_string (value,
 
150
                                    geocode_place_get_state (place));
 
151
                break;
 
152
 
 
153
        case PROP_ADMINISTRATIVE_AREA:
 
154
                g_value_set_string (value,
 
155
                                    geocode_place_get_administrative_area (place));
 
156
                break;
 
157
 
 
158
        case PROP_COUNTRY_CODE:
 
159
                g_value_set_string (value,
 
160
                                    geocode_place_get_country_code (place));
 
161
                break;
 
162
 
 
163
        case PROP_COUNTRY:
 
164
                g_value_set_string (value,
 
165
                                    geocode_place_get_country (place));
 
166
                break;
 
167
 
 
168
        case PROP_CONTINENT:
 
169
                g_value_set_string (value,
 
170
                                    geocode_place_get_continent (place));
 
171
                break;
 
172
 
 
173
        case PROP_ICON:
 
174
                g_value_set_object (value,
 
175
                                    geocode_place_get_icon (place));
 
176
                break;
 
177
 
 
178
        case PROP_BBOX:
 
179
                g_value_set_object (value,
 
180
                                    geocode_place_get_bounding_box (place));
 
181
                break;
 
182
 
 
183
        case PROP_OSM_ID:
 
184
                g_value_set_string (value,
 
185
                                    geocode_place_get_osm_id (place));
 
186
                break;
 
187
 
 
188
        case PROP_OSM_TYPE:
 
189
                g_value_set_enum (value,
 
190
                                  geocode_place_get_osm_type (place));
 
191
                break;
 
192
 
 
193
        default:
 
194
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
195
                break;
 
196
        }
 
197
}
 
198
 
 
199
static void
 
200
geocode_place_set_property(GObject      *object,
 
201
                           guint         property_id,
 
202
                           const GValue *value,
 
203
                           GParamSpec   *pspec)
 
204
{
 
205
        GeocodePlace *place = GEOCODE_PLACE (object);
 
206
 
 
207
        switch (property_id) {
 
208
        case PROP_NAME:
 
209
                place->priv->name = g_value_dup_string (value);
 
210
                break;
 
211
 
 
212
        case PROP_PLACE_TYPE:
 
213
                place->priv->place_type = g_value_get_enum (value);
 
214
                break;
 
215
 
 
216
        case PROP_LOCATION:
 
217
                place->priv->location = g_value_dup_object (value);
 
218
                break;
 
219
 
 
220
        case PROP_STREET_ADDRESS:
 
221
                geocode_place_set_street_address (place,
 
222
                                                  g_value_get_string (value));
 
223
                break;
 
224
 
 
225
        case PROP_STREET:
 
226
                geocode_place_set_street (place, g_value_get_string (value));
 
227
                break;
 
228
 
 
229
        case PROP_BUILDING:
 
230
                geocode_place_set_building (place, g_value_get_string (value));
 
231
                break;
 
232
 
 
233
        case PROP_POSTAL_CODE:
 
234
                geocode_place_set_postal_code (place,
 
235
                                               g_value_get_string (value));
 
236
                break;
 
237
 
 
238
        case PROP_AREA:
 
239
                geocode_place_set_area (place, g_value_get_string (value));
 
240
                break;
 
241
 
 
242
        case PROP_TOWN:
 
243
                geocode_place_set_town (place, g_value_get_string (value));
 
244
                break;
 
245
 
 
246
        case PROP_COUNTY:
 
247
                geocode_place_set_county (place, g_value_get_string (value));
 
248
                break;
 
249
 
 
250
        case PROP_STATE:
 
251
                geocode_place_set_state (place, g_value_get_string (value));
 
252
                break;
 
253
 
 
254
        case PROP_ADMINISTRATIVE_AREA:
 
255
                geocode_place_set_administrative_area (place,
 
256
                                                       g_value_get_string (value));
 
257
                break;
 
258
 
 
259
        case PROP_COUNTRY_CODE:
 
260
                geocode_place_set_country_code (place,
 
261
                                                g_value_get_string (value));
 
262
                break;
 
263
 
 
264
        case PROP_COUNTRY:
 
265
                geocode_place_set_country (place,
 
266
                                           g_value_get_string (value));
 
267
                break;
 
268
 
 
269
        case PROP_CONTINENT:
 
270
                geocode_place_set_continent (place, g_value_get_string (value));
 
271
                break;
 
272
 
 
273
        case PROP_BBOX:
 
274
                place->priv->bbox = g_value_dup_object (value);
 
275
                break;
 
276
 
 
277
        case PROP_OSM_ID:
 
278
                place->priv->osm_id = g_value_dup_string (value);
 
279
                break;
 
280
 
 
281
        case PROP_OSM_TYPE:
 
282
                place->priv->osm_type = g_value_get_enum (value);
 
283
                break;
 
284
 
 
285
        default:
 
286
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
287
                break;
 
288
        }
 
289
}
 
290
 
 
291
static void
 
292
geocode_place_dispose (GObject *gplace)
 
293
{
 
294
        GeocodePlace *place = (GeocodePlace *) gplace;
 
295
 
 
296
        g_clear_object (&place->priv->location);
 
297
        g_clear_object (&place->priv->bbox);
 
298
 
 
299
        g_clear_pointer (&place->priv->name, g_free);
 
300
        g_clear_pointer (&place->priv->osm_id, g_free);
 
301
        g_clear_pointer (&place->priv->street_address, g_free);
 
302
        g_clear_pointer (&place->priv->street, g_free);
 
303
        g_clear_pointer (&place->priv->building, g_free);
 
304
        g_clear_pointer (&place->priv->postal_code, g_free);
 
305
        g_clear_pointer (&place->priv->area, g_free);
 
306
        g_clear_pointer (&place->priv->town, g_free);
 
307
        g_clear_pointer (&place->priv->county, g_free);
 
308
        g_clear_pointer (&place->priv->state, g_free);
 
309
        g_clear_pointer (&place->priv->admin_area, g_free);
 
310
        g_clear_pointer (&place->priv->country_code, g_free);
 
311
        g_clear_pointer (&place->priv->country, g_free);
 
312
        g_clear_pointer (&place->priv->continent, g_free);
 
313
 
 
314
        G_OBJECT_CLASS (geocode_place_parent_class)->dispose (gplace);
 
315
}
 
316
 
 
317
static void
 
318
geocode_place_class_init (GeocodePlaceClass *klass)
 
319
{
 
320
        GObjectClass *gplace_class = G_OBJECT_CLASS (klass);
 
321
        GParamSpec *pspec;
 
322
 
 
323
        gplace_class->dispose = geocode_place_dispose;
 
324
        gplace_class->get_property = geocode_place_get_property;
 
325
        gplace_class->set_property = geocode_place_set_property;
 
326
 
 
327
        g_type_class_add_private (klass, sizeof (GeocodePlacePrivate));
 
328
 
 
329
        /**
 
330
         * GeocodePlace:name:
 
331
         *
 
332
         * The name of the place.
 
333
         */
 
334
        pspec = g_param_spec_string ("name",
 
335
                                     "Name",
 
336
                                     "Name",
 
337
                                     NULL,
 
338
                                     G_PARAM_READWRITE |
 
339
                                     G_PARAM_STATIC_STRINGS);
 
340
        g_object_class_install_property (gplace_class, PROP_NAME, pspec);
 
341
 
 
342
        /**
 
343
         * GeocodePlace:place-type:
 
344
         *
 
345
         * The type of the place.
 
346
         */
 
347
        pspec = g_param_spec_enum ("place-type",
 
348
                                   "PlaceType",
 
349
                                   "Place Type",
 
350
                                   GEOCODE_TYPE_PLACE_TYPE,
 
351
                                   GEOCODE_PLACE_TYPE_UNKNOWN,
 
352
                                   G_PARAM_READWRITE |
 
353
                                   G_PARAM_CONSTRUCT_ONLY |
 
354
                                   G_PARAM_STATIC_STRINGS);
 
355
        g_object_class_install_property (gplace_class, PROP_PLACE_TYPE, pspec);
 
356
 
 
357
        /**
 
358
         * GeocodePlace:location:
 
359
         *
 
360
         * The location info for the place.
 
361
         */
 
362
        pspec = g_param_spec_object ("location",
 
363
                                     "Location",
 
364
                                     "Location Info",
 
365
                                     GEOCODE_TYPE_LOCATION,
 
366
                                     G_PARAM_READWRITE |
 
367
                                     G_PARAM_STATIC_STRINGS);
 
368
        g_object_class_install_property (gplace_class, PROP_LOCATION, pspec);
 
369
 
 
370
        /**
 
371
         * GeocodePlace:street-address:
 
372
         *
 
373
         * The street address.
 
374
         */
 
375
        pspec = g_param_spec_string ("street-address",
 
376
                                     "StreetAddress",
 
377
                                     "Street Address",
 
378
                                     NULL,
 
379
                                     G_PARAM_READWRITE |
 
380
                                     G_PARAM_STATIC_STRINGS);
 
381
        g_object_class_install_property (gplace_class, PROP_STREET_ADDRESS, pspec);
 
382
 
 
383
        /**
 
384
         * GeocodePlace:street:
 
385
         *
 
386
         * The street name.
 
387
         */
 
388
        pspec = g_param_spec_string ("street",
 
389
                                     "Street",
 
390
                                     "Street name",
 
391
                                     NULL,
 
392
                                     G_PARAM_READWRITE |
 
393
                                     G_PARAM_STATIC_STRINGS);
 
394
        g_object_class_install_property (gplace_class, PROP_STREET, pspec);
 
395
 
 
396
        /**
 
397
         * GeocodePlace:building:
 
398
         *
 
399
         * A specific building on a street or in an area.
 
400
         */
 
401
        pspec = g_param_spec_string ("building",
 
402
                                     "Building",
 
403
                                     "A specific building on a street or in an area",
 
404
                                     NULL,
 
405
                                     G_PARAM_READWRITE |
 
406
                                     G_PARAM_STATIC_STRINGS);
 
407
        g_object_class_install_property (gplace_class, PROP_BUILDING, pspec);
 
408
 
 
409
        /**
 
410
         * GeocodePlace:postal-code:
 
411
         *
 
412
         * The postal code.
 
413
         */
 
414
        pspec = g_param_spec_string ("postal-code",
 
415
                                     "PostalCode",
 
416
                                     "Postal Code",
 
417
                                     NULL,
 
418
                                     G_PARAM_READWRITE |
 
419
                                     G_PARAM_STATIC_STRINGS);
 
420
        g_object_class_install_property (gplace_class, PROP_POSTAL_CODE, pspec);
 
421
 
 
422
        /**
 
423
         * GeocodePlace:area:
 
424
         *
 
425
         * A named area such as a campus or neighborhood.
 
426
         */
 
427
        pspec = g_param_spec_string ("area",
 
428
                                     "Area",
 
429
                                     "A named area such as a campus or neighborhood",
 
430
                                     NULL,
 
431
                                     G_PARAM_READWRITE |
 
432
                                     G_PARAM_STATIC_STRINGS);
 
433
        g_object_class_install_property (gplace_class, PROP_AREA, pspec);
 
434
 
 
435
        /**
 
436
         * GeocodePlace:town:
 
437
         *
 
438
         * The town.
 
439
         */
 
440
        pspec = g_param_spec_string ("town",
 
441
                                     "Town",
 
442
                                     "Town",
 
443
                                     NULL,
 
444
                                     G_PARAM_READWRITE |
 
445
                                     G_PARAM_STATIC_STRINGS);
 
446
        g_object_class_install_property (gplace_class, PROP_TOWN, pspec);
 
447
 
 
448
        /**
 
449
         * GeocodePlace:state:
 
450
         *
 
451
         * The state.
 
452
         */
 
453
        pspec = g_param_spec_string ("state",
 
454
                                     "State",
 
455
                                     "State",
 
456
                                     NULL,
 
457
                                     G_PARAM_READWRITE |
 
458
                                     G_PARAM_STATIC_STRINGS);
 
459
        g_object_class_install_property (gplace_class, PROP_STATE, pspec);
 
460
 
 
461
        /**
 
462
         * GeocodePlace:county:
 
463
         *
 
464
         * The county.
 
465
         */
 
466
        pspec = g_param_spec_string ("county",
 
467
                                     "County",
 
468
                                     "County",
 
469
                                     NULL,
 
470
                                     G_PARAM_READWRITE |
 
471
                                     G_PARAM_STATIC_STRINGS);
 
472
        g_object_class_install_property (gplace_class, PROP_COUNTY, pspec);
 
473
 
 
474
        /**
 
475
         * GeocodePlace:administrative-area:
 
476
         *
 
477
         * The local administrative area.
 
478
         */
 
479
        pspec = g_param_spec_string ("administrative-area",
 
480
                                     "AdministrativeArea",
 
481
                                     "Local administrative area",
 
482
                                     NULL,
 
483
                                     G_PARAM_READWRITE |
 
484
                                     G_PARAM_STATIC_STRINGS);
 
485
        g_object_class_install_property (gplace_class, PROP_ADMINISTRATIVE_AREA, pspec);
 
486
 
 
487
        /**
 
488
         * GeocodePlace:country-code:
 
489
         *
 
490
         * The country code.
 
491
         */
 
492
        pspec = g_param_spec_string ("country-code",
 
493
                                     "CountryCode",
 
494
                                     "ISO Country Code",
 
495
                                     NULL,
 
496
                                     G_PARAM_READWRITE |
 
497
                                     G_PARAM_STATIC_STRINGS);
 
498
        g_object_class_install_property (gplace_class, PROP_COUNTRY_CODE, pspec);
 
499
 
 
500
        /**
 
501
         * GeocodePlace:country:
 
502
         *
 
503
         * The country.
 
504
         */
 
505
        pspec = g_param_spec_string ("country",
 
506
                                     "Country",
 
507
                                     "Country",
 
508
                                     NULL,
 
509
                                     G_PARAM_READWRITE |
 
510
                                     G_PARAM_STATIC_STRINGS);
 
511
        g_object_class_install_property (gplace_class, PROP_COUNTRY, pspec);
 
512
 
 
513
        /**
 
514
         * GeocodePlace:continent:
 
515
         *
 
516
         * The continent.
 
517
         */
 
518
        pspec = g_param_spec_string ("continent",
 
519
                                     "Continent",
 
520
                                     "Continent",
 
521
                                     NULL,
 
522
                                     G_PARAM_READWRITE |
 
523
                                     G_PARAM_STATIC_STRINGS);
 
524
        g_object_class_install_property (gplace_class, PROP_CONTINENT, pspec);
 
525
 
 
526
        /**
 
527
         * GeocodePlace:icon:
 
528
         *
 
529
         * #GIcon representing the @GeocodePlace.
 
530
         */
 
531
        pspec = g_param_spec_object ("icon",
 
532
                                     "Icon",
 
533
                                     "An icon representing the the place",
 
534
                                     G_TYPE_ICON,
 
535
                                     G_PARAM_READABLE |
 
536
                                     G_PARAM_STATIC_STRINGS);
 
537
        g_object_class_install_property (gplace_class, PROP_ICON, pspec);
 
538
 
 
539
        /**
 
540
         * GeocodePlace:bounding-box:
 
541
         *
 
542
         * The bounding box for the place.
 
543
         */
 
544
        pspec = g_param_spec_object ("bounding-box",
 
545
                                     "Bounding Box",
 
546
                                     "The bounding box for the place",
 
547
                                     GEOCODE_TYPE_BOUNDING_BOX,
 
548
                                     G_PARAM_READWRITE |
 
549
                                     G_PARAM_STATIC_STRINGS);
 
550
        g_object_class_install_property (gplace_class, PROP_BBOX, pspec);
 
551
 
 
552
        /**
 
553
         * GeocodePlace:osm-id:
 
554
         *
 
555
         * The OpenStreetMap id of the place.
 
556
         */
 
557
        pspec = g_param_spec_string ("osm-id",
 
558
                                     "OSM ID",
 
559
                                     "The OpenStreetMap ID of the place",
 
560
                                     NULL,
 
561
                                     G_PARAM_READWRITE |
 
562
                                     G_PARAM_STATIC_STRINGS);
 
563
        g_object_class_install_property (gplace_class, PROP_OSM_ID, pspec);
 
564
 
 
565
        /**
 
566
         * GeocodePlace:osm-type:
 
567
         *
 
568
         * The OpenStreetMap type of the place.
 
569
         */
 
570
        pspec = g_param_spec_enum ("osm-type",
 
571
                                   "OSM Type",
 
572
                                   "The OpenStreetMap type of the place",
 
573
                                   GEOCODE_TYPE_PLACE_OSM_TYPE,
 
574
                                   GEOCODE_PLACE_OSM_TYPE_UNKNOWN,
 
575
                                   G_PARAM_READWRITE |
 
576
                                   G_PARAM_STATIC_STRINGS);
 
577
        g_object_class_install_property (gplace_class, PROP_OSM_TYPE, pspec);
 
578
}
 
579
 
 
580
static void
 
581
geocode_place_init (GeocodePlace *place)
 
582
{
 
583
        place->priv = G_TYPE_INSTANCE_GET_PRIVATE ((place),
 
584
                                                      GEOCODE_TYPE_PLACE,
 
585
                                                      GeocodePlacePrivate);
 
586
        place->priv->bbox = NULL;
 
587
        place->priv->osm_type = GEOCODE_PLACE_OSM_TYPE_UNKNOWN;
 
588
}
 
589
 
 
590
/**
 
591
 * geocode_place_new:
 
592
 * @name: the name of place
 
593
 * @place_type: the type of place
 
594
 *
 
595
 * Creates a new #GeocodePlace object.
 
596
 *
 
597
 * Returns: a new #GeocodePlace object. Use g_object_unref() when done.
 
598
 **/
 
599
GeocodePlace *
 
600
geocode_place_new (const char      *name,
 
601
                   GeocodePlaceType place_type)
 
602
{
 
603
        return g_object_new (GEOCODE_TYPE_PLACE,
 
604
                             "name", name,
 
605
                             "place-type", place_type,
 
606
                             NULL);
 
607
}
 
608
 
 
609
/**
 
610
 * geocode_place_new_with_location:
 
611
 * @name: the name of place
 
612
 * @place_type: the type of place
 
613
 * @location: the location info for the place
 
614
 *
 
615
 * Creates a new #GeocodePlace object.
 
616
 *
 
617
 * Returns: a new #GeocodePlace object. Use g_object_unref() when done.
 
618
 **/
 
619
GeocodePlace *
 
620
geocode_place_new_with_location (const char      *name,
 
621
                                 GeocodePlaceType place_type,
 
622
                                 GeocodeLocation *location)
 
623
{
 
624
        return g_object_new (GEOCODE_TYPE_PLACE,
 
625
                             "name", name,
 
626
                             "place-type", place_type,
 
627
                             "location", location,
 
628
                             NULL);
 
629
}
 
630
 
 
631
/**
 
632
 * geocode_place_set_name:
 
633
 * @place: A place
 
634
 * @name: the name of place
 
635
 *
 
636
 * Sets the name of the @place to @name.
 
637
 **/
 
638
void
 
639
geocode_place_set_name (GeocodePlace *place,
 
640
                        const char   *name)
 
641
{
 
642
        g_return_if_fail (GEOCODE_IS_PLACE (place));
 
643
        g_return_if_fail (name != NULL);
 
644
 
 
645
        g_free (place->priv->name);
 
646
        place->priv->name = g_strdup (name);
 
647
}
 
648
 
 
649
/**
 
650
 * geocode_place_get_name:
 
651
 * @place: A place
 
652
 *
 
653
 * Gets the name of the @place.
 
654
 *
 
655
 * Returns: The name of the @place.
 
656
 **/
 
657
const char *
 
658
geocode_place_get_name (GeocodePlace *place)
 
659
{
 
660
        g_return_val_if_fail (GEOCODE_IS_PLACE (place), NULL);
 
661
 
 
662
        return place->priv->name;
 
663
 
 
664
}
 
665
 
 
666
/**
 
667
 * geocode_place_get_place_type:
 
668
 * @place: A place
 
669
 *
 
670
 * Gets the type of the @place.
 
671
 *
 
672
 * Returns: The type of the @place.
 
673
 **/
 
674
GeocodePlaceType
 
675
geocode_place_get_place_type (GeocodePlace *place)
 
676
{
 
677
        g_return_val_if_fail (GEOCODE_IS_PLACE (place),
 
678
                              GEOCODE_PLACE_TYPE_UNKNOWN);
 
679
 
 
680
        return place->priv->place_type;
 
681
}
 
682
 
 
683
/**
 
684
 * geocode_place_set_location:
 
685
 * @place: A place
 
686
 * @location: A location
 
687
 *
 
688
 * Sets the location of @place to @location.
 
689
 **/
 
690
void
 
691
geocode_place_set_location (GeocodePlace *place,
 
692
                            GeocodeLocation *location)
 
693
{
 
694
        g_return_if_fail (GEOCODE_IS_PLACE (place));
 
695
        g_return_if_fail (GEOCODE_IS_LOCATION (location));
 
696
 
 
697
        g_clear_object (&place->priv->location);
 
698
        place->priv->location = g_object_ref (location);
 
699
}
 
700
 
 
701
/**
 
702
 * geocode_place_get_location:
 
703
 * @place: A place
 
704
 *
 
705
 * Gets the associated location object.
 
706
 *
 
707
 * Returns: (transfer none): The associated location object.
 
708
 **/
 
709
GeocodeLocation *
 
710
geocode_place_get_location (GeocodePlace *place)
 
711
{
 
712
        g_return_val_if_fail (GEOCODE_IS_PLACE (place), NULL);
 
713
 
 
714
        return place->priv->location;
 
715
}
 
716
 
 
717
/**
 
718
 * geocode_place_set_street_address:
 
719
 * @place: A place
 
720
 * @street_address: a street address for the place
 
721
 *
 
722
 * Sets the street address of @place to @street_address.
 
723
 **/
 
724
void
 
725
geocode_place_set_street_address (GeocodePlace *place,
 
726
                                  const char   *street_address)
 
727
{
 
728
        g_return_if_fail (GEOCODE_IS_PLACE (place));
 
729
        g_return_if_fail (street_address != NULL);
 
730
 
 
731
        g_free (place->priv->street_address);
 
732
        place->priv->street_address = g_strdup (street_address);
 
733
}
 
734
 
 
735
/**
 
736
 * geocode_place_get_street_address:
 
737
 * @place: A place
 
738
 *
 
739
 * Gets the street address of the @place.
 
740
 *
 
741
 * Returns: The street address of the @place.
 
742
 **/
 
743
const char *
 
744
geocode_place_get_street_address (GeocodePlace *place)
 
745
{
 
746
        g_return_val_if_fail (GEOCODE_IS_PLACE (place), NULL);
 
747
 
 
748
        return place->priv->street_address;
 
749
}
 
750
 
 
751
/**
 
752
 * geocode_place_set_street:
 
753
 * @place: A place
 
754
 * @street: a street
 
755
 *
 
756
 * Sets the street of @place to @street.
 
757
 **/
 
758
void
 
759
geocode_place_set_street (GeocodePlace *place,
 
760
                          const char   *street)
 
761
{
 
762
        g_return_if_fail (GEOCODE_IS_PLACE (place));
 
763
        g_return_if_fail (street != NULL);
 
764
 
 
765
        g_free (place->priv->street);
 
766
        place->priv->street = g_strdup (street);
 
767
}
 
768
 
 
769
/**
 
770
 * geocode_place_get_street:
 
771
 * @place: A place
 
772
 *
 
773
 * Gets the street of the @place.
 
774
 *
 
775
 * Returns: The street of the @place.
 
776
 **/
 
777
const char *
 
778
geocode_place_get_street (GeocodePlace *place)
 
779
{
 
780
        g_return_val_if_fail (GEOCODE_IS_PLACE (place), NULL);
 
781
 
 
782
        return place->priv->street;
 
783
}
 
784
 
 
785
/**
 
786
 * geocode_place_set_building:
 
787
 * @place: A place
 
788
 * @building: a building
 
789
 *
 
790
 * Sets the building of @place to @building.
 
791
 **/
 
792
void
 
793
geocode_place_set_building (GeocodePlace *place,
 
794
                            const char   *building)
 
795
{
 
796
        g_return_if_fail (GEOCODE_IS_PLACE (place));
 
797
        g_return_if_fail (building != NULL);
 
798
 
 
799
        g_free (place->priv->building);
 
800
        place->priv->building = g_strdup (building);
 
801
}
 
802
 
 
803
/**
 
804
 * geocode_place_get_building:
 
805
 * @place: A place
 
806
 *
 
807
 * Gets the building of the @place.
 
808
 *
 
809
 * Returns: The building of the @place.
 
810
 **/
 
811
const char *
 
812
geocode_place_get_building (GeocodePlace *place)
 
813
{
 
814
        g_return_val_if_fail (GEOCODE_IS_PLACE (place), NULL);
 
815
 
 
816
        return place->priv->building;
 
817
}
 
818
 
 
819
/**
 
820
 * geocode_place_set_postal_code:
 
821
 * @place: A place
 
822
 * @postal_code: a postal code for the place
 
823
 *
 
824
 * Sets the postal code of @place to @postal_code.
 
825
 **/
 
826
void
 
827
geocode_place_set_postal_code (GeocodePlace *place,
 
828
                               const char   *postal_code)
 
829
{
 
830
        g_return_if_fail (GEOCODE_IS_PLACE (place));
 
831
        g_return_if_fail (postal_code != NULL);
 
832
 
 
833
        g_free (place->priv->postal_code);
 
834
        place->priv->postal_code = g_strdup (postal_code);
 
835
}
 
836
 
 
837
/**
 
838
 * geocode_place_get_postal_code:
 
839
 * @place: A place
 
840
 *
 
841
 * Gets the postal code of the @place.
 
842
 *
 
843
 * Returns: The postal code of the @place.
 
844
 **/
 
845
const char *
 
846
geocode_place_get_postal_code (GeocodePlace *place)
 
847
{
 
848
        g_return_val_if_fail (GEOCODE_IS_PLACE (place), NULL);
 
849
 
 
850
        return place->priv->postal_code;
 
851
}
 
852
 
 
853
/**
 
854
 * geocode_place_set_area:
 
855
 * @place: A place
 
856
 * @area: a area
 
857
 *
 
858
 * Sets the area of @place to @area.
 
859
 **/
 
860
void
 
861
geocode_place_set_area (GeocodePlace *place,
 
862
                        const char   *area)
 
863
{
 
864
        g_return_if_fail (GEOCODE_IS_PLACE (place));
 
865
        g_return_if_fail (area != NULL);
 
866
 
 
867
        g_free (place->priv->area);
 
868
        place->priv->area = g_strdup (area);
 
869
}
 
870
 
 
871
/**
 
872
 * geocode_place_get_area:
 
873
 * @place: A place
 
874
 *
 
875
 * Gets the area of the @place.
 
876
 *
 
877
 * Returns: The area of the @place.
 
878
 **/
 
879
const char *
 
880
geocode_place_get_area (GeocodePlace *place)
 
881
{
 
882
        g_return_val_if_fail (GEOCODE_IS_PLACE (place), NULL);
 
883
 
 
884
        return place->priv->area;
 
885
}
 
886
 
 
887
/**
 
888
 * geocode_place_set_town:
 
889
 * @place: A place
 
890
 * @town: a town for the place
 
891
 *
 
892
 * Sets the town of @place to @town.
 
893
 **/
 
894
void
 
895
geocode_place_set_town (GeocodePlace *place,
 
896
                        const char   *town)
 
897
{
 
898
        g_return_if_fail (GEOCODE_IS_PLACE (place));
 
899
        g_return_if_fail (town != NULL);
 
900
 
 
901
        g_free (place->priv->town);
 
902
        place->priv->town = g_strdup (town);
 
903
}
 
904
 
 
905
/**
 
906
 * geocode_place_get_town:
 
907
 * @place: A place
 
908
 *
 
909
 * Gets the town of the @place.
 
910
 *
 
911
 * Returns: The town of the @place.
 
912
 **/
 
913
const char *
 
914
geocode_place_get_town (GeocodePlace *place)
 
915
{
 
916
        g_return_val_if_fail (GEOCODE_IS_PLACE (place), NULL);
 
917
 
 
918
        return place->priv->town;
 
919
}
 
920
 
 
921
/**
 
922
 * geocode_place_set_county:
 
923
 * @place: A place
 
924
 * @county: a county for the place
 
925
 *
 
926
 * Sets the county of @place to @county.
 
927
 **/
 
928
void
 
929
geocode_place_set_county (GeocodePlace *place,
 
930
                          const char   *county)
 
931
{
 
932
        g_return_if_fail (GEOCODE_IS_PLACE (place));
 
933
        g_return_if_fail (county != NULL);
 
934
 
 
935
        g_free (place->priv->county);
 
936
        place->priv->county = g_strdup (county);
 
937
}
 
938
 
 
939
/**
 
940
 * geocode_place_get_county:
 
941
 * @place: A place
 
942
 *
 
943
 * Gets the county of the @place.
 
944
 *
 
945
 * Returns: The country of the @place.
 
946
 **/
 
947
const char *
 
948
geocode_place_get_county (GeocodePlace *place)
 
949
{
 
950
        g_return_val_if_fail (GEOCODE_IS_PLACE (place), NULL);
 
951
 
 
952
        return place->priv->county;
 
953
}
 
954
 
 
955
/**
 
956
 * geocode_place_set_state:
 
957
 * @place: A place
 
958
 * @state: a state for the place
 
959
 *
 
960
 * Sets the state of @place to @state.
 
961
 **/
 
962
void
 
963
geocode_place_set_state (GeocodePlace *place,
 
964
                         const char   *state)
 
965
{
 
966
        g_return_if_fail (GEOCODE_IS_PLACE (place));
 
967
        g_return_if_fail (state != NULL);
 
968
 
 
969
        g_free (place->priv->state);
 
970
        place->priv->state = g_strdup (state);
 
971
}
 
972
 
 
973
/**
 
974
 * geocode_place_get_state:
 
975
 * @place: A place
 
976
 *
 
977
 * Gets the state of the @place.
 
978
 *
 
979
 * Returns: The state of the @place.
 
980
 **/
 
981
const char *
 
982
geocode_place_get_state (GeocodePlace *place)
 
983
{
 
984
        g_return_val_if_fail (GEOCODE_IS_PLACE (place), NULL);
 
985
 
 
986
        return place->priv->state;
 
987
}
 
988
 
 
989
/**
 
990
 * geocode_place_set_administrative_area:
 
991
 * @place: A place
 
992
 * @admin_area: an administrative area for the place
 
993
 *
 
994
 * Sets the local administrative area of @place to @admin_area.
 
995
 **/
 
996
void
 
997
geocode_place_set_administrative_area (GeocodePlace *place,
 
998
                                       const char   *admin_area)
 
999
{
 
1000
        g_return_if_fail (GEOCODE_IS_PLACE (place));
 
1001
        g_return_if_fail (admin_area != NULL);
 
1002
 
 
1003
        g_free (place->priv->admin_area);
 
1004
        place->priv->admin_area = g_strdup (admin_area);
 
1005
}
 
1006
 
 
1007
/**
 
1008
 * geocode_place_get_administrative_area:
 
1009
 * @place: A place
 
1010
 *
 
1011
 * Gets the local administrative area of the @place.
 
1012
 *
 
1013
 * Returns: The local administrative area of the @place.
 
1014
 **/
 
1015
const char *
 
1016
geocode_place_get_administrative_area (GeocodePlace *place)
 
1017
{
 
1018
        g_return_val_if_fail (GEOCODE_IS_PLACE (place), NULL);
 
1019
 
 
1020
        return place->priv->admin_area;
 
1021
}
 
1022
 
 
1023
/**
 
1024
 * geocode_place_set_country_code:
 
1025
 * @place: A place
 
1026
 * @country_code: an ISO country code for the place
 
1027
 *
 
1028
 * Sets the ISO country code of @place to @country_code.
 
1029
 **/
 
1030
void
 
1031
geocode_place_set_country_code (GeocodePlace *place,
 
1032
                                const char   *country_code)
 
1033
{
 
1034
        g_return_if_fail (GEOCODE_IS_PLACE (place));
 
1035
        g_return_if_fail (country_code != NULL);
 
1036
 
 
1037
        g_free (place->priv->country_code);
 
1038
        place->priv->country_code = g_utf8_strup (country_code, -1);
 
1039
}
 
1040
 
 
1041
/**
 
1042
 * geocode_place_get_country_code:
 
1043
 * @place: A place
 
1044
 *
 
1045
 * Gets the ISO-3166 country code of the @place.
 
1046
 *
 
1047
 * Returns: The ISO-3166 country code of the @place, in upper case.
 
1048
 **/
 
1049
const char *
 
1050
geocode_place_get_country_code (GeocodePlace *place)
 
1051
{
 
1052
        g_return_val_if_fail (GEOCODE_IS_PLACE (place), NULL);
 
1053
 
 
1054
        return place->priv->country_code;
 
1055
}
 
1056
 
 
1057
/**
 
1058
 * geocode_place_set_country:
 
1059
 * @place: A place
 
1060
 * @country: a country for the place
 
1061
 *
 
1062
 * Sets the country of @place to @country.
 
1063
 **/
 
1064
void
 
1065
geocode_place_set_country (GeocodePlace *place,
 
1066
                           const char   *country)
 
1067
{
 
1068
        g_return_if_fail (GEOCODE_IS_PLACE (place));
 
1069
        g_return_if_fail (country != NULL);
 
1070
 
 
1071
        g_free (place->priv->country);
 
1072
        place->priv->country = g_strdup (country);
 
1073
}
 
1074
 
 
1075
/**
 
1076
 * geocode_place_get_country:
 
1077
 * @place: A place
 
1078
 *
 
1079
 * Gets the country of the @place.
 
1080
 *
 
1081
 * Returns: The country of the @place.
 
1082
 **/
 
1083
const char *
 
1084
geocode_place_get_country (GeocodePlace *place)
 
1085
{
 
1086
        g_return_val_if_fail (GEOCODE_IS_PLACE (place), NULL);
 
1087
 
 
1088
        return place->priv->country;
 
1089
}
 
1090
 
 
1091
/**
 
1092
 * geocode_place_set_continent:
 
1093
 * @place: A place
 
1094
 * @continent: a continent for the place
 
1095
 *
 
1096
 * Sets the continent of @place to @continent.
 
1097
 **/
 
1098
void
 
1099
geocode_place_set_continent (GeocodePlace *place,
 
1100
                             const char   *continent)
 
1101
{
 
1102
        g_return_if_fail (GEOCODE_IS_PLACE (place));
 
1103
        g_return_if_fail (continent != NULL);
 
1104
 
 
1105
        g_free (place->priv->continent);
 
1106
        place->priv->continent = g_strdup (continent);
 
1107
}
 
1108
 
 
1109
/**
 
1110
 * geocode_place_get_continent:
 
1111
 * @place: A place
 
1112
 *
 
1113
 * Gets the continent of the @place.
 
1114
 *
 
1115
 * Returns: The continent of the @place.
 
1116
 **/
 
1117
const char *
 
1118
geocode_place_get_continent (GeocodePlace *place)
 
1119
{
 
1120
        g_return_val_if_fail (GEOCODE_IS_PLACE (place), NULL);
 
1121
 
 
1122
        return place->priv->continent;
 
1123
}
 
1124
 
 
1125
static char *
 
1126
get_icon_name (GeocodePlace *place)
 
1127
{
 
1128
        char *icon_name;
 
1129
 
 
1130
        switch (place->priv->place_type) {
 
1131
 
 
1132
        case GEOCODE_PLACE_TYPE_BUILDING:
 
1133
                icon_name = "poi-building";
 
1134
                break;
 
1135
 
 
1136
        case GEOCODE_PLACE_TYPE_TOWN:
 
1137
                icon_name = "poi-town";
 
1138
                break;
 
1139
 
 
1140
        case GEOCODE_PLACE_TYPE_AIRPORT:
 
1141
                icon_name = "poi-airport";
 
1142
                break;
 
1143
 
 
1144
        case GEOCODE_PLACE_TYPE_RAILWAY_STATION:
 
1145
                icon_name = "poi-railway-station";
 
1146
                break;
 
1147
 
 
1148
        case GEOCODE_PLACE_TYPE_BUS_STOP:
 
1149
                icon_name = "poi-bus-stop";
 
1150
                break;
 
1151
 
 
1152
        case GEOCODE_PLACE_TYPE_STREET:
 
1153
                icon_name = "poi-car";
 
1154
                break;
 
1155
 
 
1156
        case GEOCODE_PLACE_TYPE_SCHOOL:
 
1157
                icon_name = "poi-school";
 
1158
                break;
 
1159
 
 
1160
        case GEOCODE_PLACE_TYPE_PLACE_OF_WORSHIP:
 
1161
                icon_name = "poi-place-of-worship";
 
1162
                break;
 
1163
 
 
1164
        case GEOCODE_PLACE_TYPE_RESTAURANT:
 
1165
                icon_name = "poi-restaurant";
 
1166
                break;
 
1167
 
 
1168
        case GEOCODE_PLACE_TYPE_BAR:
 
1169
                icon_name = "poi-bar";
 
1170
                break;
 
1171
 
 
1172
        case GEOCODE_PLACE_TYPE_LIGHT_RAIL_STATION:
 
1173
                icon_name = "poi-light-rail-station";
 
1174
                break;
 
1175
 
 
1176
        default:
 
1177
                icon_name = "poi-marker"; /* generic marker */
 
1178
                break;
 
1179
        }
 
1180
 
 
1181
        return icon_name;
 
1182
}
 
1183
 
 
1184
/**
 
1185
 * geocode_place_get_icon:
 
1186
 * @place: A place
 
1187
 *
 
1188
 * Gets the #GIcon representing the @place.
 
1189
 *
 
1190
 * Returns: (transfer none): The #GIcon representing the @place.
 
1191
 **/
 
1192
GIcon *
 
1193
geocode_place_get_icon (GeocodePlace *place)
 
1194
{
 
1195
        char *icon_name;
 
1196
 
 
1197
        g_return_val_if_fail (GEOCODE_IS_PLACE (place), NULL);
 
1198
 
 
1199
        icon_name = get_icon_name (place);
 
1200
 
 
1201
        return g_icon_new_for_string (icon_name, NULL);
 
1202
}
 
1203
 
 
1204
/**
 
1205
 * geocode_place_get_bounding_box:
 
1206
 * @place: A place
 
1207
 *
 
1208
 * Gets the bounding box for the place @place.
 
1209
 *
 
1210
 * Returns: (transfer none): A #GeocodeBoundingBox, or NULL if boundaries are
 
1211
 * unknown.
 
1212
 **/
 
1213
GeocodeBoundingBox *
 
1214
geocode_place_get_bounding_box (GeocodePlace *place)
 
1215
{
 
1216
        g_return_val_if_fail (GEOCODE_IS_PLACE (place), NULL);
 
1217
 
 
1218
        return place->priv->bbox;
 
1219
}
 
1220
 
 
1221
/**
 
1222
 * geocode_place_set_bounding_box:
 
1223
 * @place: A place
 
1224
 * @bbox: A #GeocodeBoundingBox for the place
 
1225
 *
 
1226
 * Sets the #GeocodeBoundingBox for the place @place.
 
1227
 *
 
1228
 **/
 
1229
void
 
1230
geocode_place_set_bounding_box (GeocodePlace       *place,
 
1231
                                GeocodeBoundingBox *bbox)
 
1232
{
 
1233
        g_return_if_fail (GEOCODE_IS_PLACE (place));
 
1234
        g_return_if_fail (GEOCODE_IS_BOUNDING_BOX (bbox));
 
1235
 
 
1236
        g_clear_object (&place->priv->bbox);
 
1237
        place->priv->bbox = g_object_ref (bbox);
 
1238
}
 
1239
 
 
1240
/**
 
1241
 * geocode_place_get_osm_id:
 
1242
 * @place: A place
 
1243
 *
 
1244
 * Gets the OpenStreetMap ID of the @place.
 
1245
 *
 
1246
 * Returns: The osm ID of the @place.
 
1247
 **/
 
1248
const char *
 
1249
geocode_place_get_osm_id (GeocodePlace *place)
 
1250
{
 
1251
        g_return_val_if_fail (GEOCODE_IS_PLACE (place), NULL);
 
1252
 
 
1253
        return place->priv->osm_id;
 
1254
}
 
1255
 
 
1256
/**
 
1257
 * geocode_place_get_osm_type:
 
1258
 * @place: A place
 
1259
 *
 
1260
 * Gets the OpenStreetMap type of the @place.
 
1261
 *
 
1262
 * Returns: The osm type of the @place.
 
1263
 **/
 
1264
GeocodePlaceOsmType
 
1265
geocode_place_get_osm_type (GeocodePlace *place)
 
1266
{
 
1267
        g_return_val_if_fail (GEOCODE_IS_PLACE (place), GEOCODE_PLACE_OSM_TYPE_UNKNOWN);
 
1268
 
 
1269
        return place->priv->osm_type;
 
1270
}