~ubuntu-branches/ubuntu/precise/empathy/precise-proposed-201205180810

« back to all changes in this revision

Viewing changes to libempathy-gtk/empathy-location-manager.c

  • Committer: Bazaar Package Importer
  • Author(s): Jonny Lamb
  • Date: 2011-05-10 10:26:38 UTC
  • mfrom: (1.6.19 upstream)
  • mto: This revision was merged to the branch mainline in revision 148.
  • Revision ID: james.westby@ubuntu.com-20110510102638-mheu0gept28psszf
Tags: 3.1.1-1
* New upstream release.
* debian/control:
  + Update glib and tp-glib build-dep versions for new release.
  + Change libgcr-dev build-dep to libgcr-3-dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <string.h>
25
25
#include <time.h>
26
26
 
27
 
#include <glib/gi18n.h>
 
27
#include <glib/gi18n-lib.h>
28
28
 
29
29
#include <telepathy-glib/account-manager.h>
30
30
#include <telepathy-glib/util.h>
39
39
#include "libempathy/empathy-gsettings.h"
40
40
#include "libempathy/empathy-location.h"
41
41
#include "libempathy/empathy-utils.h"
 
42
#include "libempathy/empathy-time.h"
42
43
 
43
44
#define DEBUG_FLAG EMPATHY_DEBUG_LOCATION
44
45
#include "libempathy/empathy-debug.h"
47
48
#define TIMEOUT 10
48
49
static EmpathyLocationManager *location_manager = NULL;
49
50
 
50
 
#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyLocationManager)
51
 
typedef struct {
 
51
struct _EmpathyLocationManagerPrivate {
52
52
    gboolean geoclue_is_setup;
53
53
    /* Contains the location to be sent to accounts.  Geoclue is used
54
54
     * to populate it.  This HashTable uses Telepathy's style (string,
68
68
 
69
69
    /* The idle id for publish_on_idle func */
70
70
    guint timeout_id;
71
 
} EmpathyLocationManagerPriv;
 
71
};
72
72
 
73
73
G_DEFINE_TYPE (EmpathyLocationManager, empathy_location_manager, G_TYPE_OBJECT);
74
74
 
98
98
static void
99
99
location_manager_dispose (GObject *object)
100
100
{
101
 
  EmpathyLocationManagerPriv *priv = GET_PRIV (object);
 
101
  EmpathyLocationManager *self = (EmpathyLocationManager *) object;
102
102
  void (*dispose) (GObject *) =
103
103
    G_OBJECT_CLASS (empathy_location_manager_parent_class)->dispose;
104
104
 
105
 
  if (priv->account_manager != NULL)
106
 
  {
107
 
    g_object_unref (priv->account_manager);
108
 
    priv->account_manager = NULL;
109
 
  }
110
 
 
111
 
  if (priv->gsettings_loc != NULL)
112
 
  {
113
 
    g_object_unref (priv->gsettings_loc);
114
 
    priv->gsettings_loc = NULL;
115
 
  }
116
 
 
117
 
  if (priv->gc_client != NULL)
118
 
  {
119
 
    g_object_unref (priv->gc_client);
120
 
    priv->gc_client = NULL;
121
 
  }
122
 
 
123
 
  if (priv->gc_position != NULL)
124
 
  {
125
 
    g_object_unref (priv->gc_position);
126
 
    priv->gc_position = NULL;
127
 
  }
128
 
 
129
 
  if (priv->gc_address != NULL)
130
 
  {
131
 
    g_object_unref (priv->gc_address);
132
 
    priv->gc_address = NULL;
133
 
  }
134
 
 
135
 
  if (priv->location != NULL)
136
 
  {
137
 
    g_hash_table_unref (priv->location);
138
 
    priv->location = NULL;
139
 
  }
 
105
  tp_clear_object (&self->priv->account_manager);
 
106
  tp_clear_object (&self->priv->gsettings_loc);
 
107
  tp_clear_object (&self->priv->gc_client);
 
108
  tp_clear_object (&self->priv->gc_position);
 
109
  tp_clear_object (&self->priv->gc_address);
 
110
  tp_clear_pointer (&self->priv->location, g_hash_table_unref);
140
111
 
141
112
  if (dispose != NULL)
142
113
    dispose (object);
143
114
}
144
115
 
145
116
static void
146
 
location_manager_get_property (GObject *object,
147
 
                      guint param_id,
148
 
                      GValue *value,
149
 
                      GParamSpec *pspec)
150
 
{
151
 
  /*EmpathyLocationManagerPriv *priv = GET_PRIV (object); */
152
 
 
153
 
  switch (param_id)
154
 
    {
155
 
      default:
156
 
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
157
 
        break;
158
 
    };
159
 
}
160
 
 
161
 
static void
162
 
location_manager_set_property (GObject *object,
163
 
                      guint param_id,
164
 
                      const GValue *value,
165
 
                      GParamSpec *pspec)
166
 
{
167
 
  /* EmpathyLocationManagerPriv *priv = GET_PRIV (object); */
168
 
 
169
 
  switch (param_id)
170
 
    {
171
 
      default:
172
 
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
173
 
        break;
174
 
    };
175
 
}
176
 
 
177
 
static void
178
117
empathy_location_manager_class_init (EmpathyLocationManagerClass *class)
179
118
{
180
119
  GObjectClass *object_class;
183
122
 
184
123
  object_class->constructor = location_manager_constructor;
185
124
  object_class->dispose = location_manager_dispose;
186
 
  object_class->get_property = location_manager_get_property;
187
 
  object_class->set_property = location_manager_set_property;
188
125
 
189
 
  g_type_class_add_private (object_class, sizeof (EmpathyLocationManagerPriv));
 
126
  g_type_class_add_private (object_class, sizeof (EmpathyLocationManagerPrivate));
190
127
}
191
128
 
192
129
static void
204
141
    TpConnection *conn,
205
142
    gboolean force_publication)
206
143
{
207
 
  EmpathyLocationManagerPriv *priv = GET_PRIV (self);
208
144
  guint connection_status = -1;
209
145
 
210
146
  if (!conn)
212
148
 
213
149
  if (!force_publication)
214
150
    {
215
 
      if (!g_settings_get_boolean (priv->gsettings_loc,
 
151
      if (!g_settings_get_boolean (self->priv->gsettings_loc,
216
152
            EMPATHY_PREFS_LOCATION_PUBLISH))
217
153
        return;
218
154
    }
223
159
    return;
224
160
 
225
161
  DEBUG ("Publishing %s location to connection %p",
226
 
      (g_hash_table_size (priv->location) == 0 ? "empty" : ""),
 
162
      (g_hash_table_size (self->priv->location) == 0 ? "empty" : ""),
227
163
      conn);
228
164
 
229
165
  tp_cli_connection_interface_location_call_set_location (conn, -1,
230
 
      priv->location, publish_location_cb, NULL, NULL, G_OBJECT (self));
 
166
      self->priv->location, publish_location_cb, NULL, NULL, G_OBJECT (self));
231
167
}
232
168
 
233
169
typedef struct
272
208
publish_to_all_connections (EmpathyLocationManager *self,
273
209
    gboolean force_publication)
274
210
{
275
 
  EmpathyLocationManagerPriv *priv = GET_PRIV (self);
276
211
  PublishToAllData *data;
277
212
 
278
213
  data = g_slice_new0 (PublishToAllData);
279
214
  data->self = g_object_ref (self);
280
215
  data->force_publication = force_publication;
281
216
 
282
 
  tp_account_manager_prepare_async (priv->account_manager, NULL,
 
217
  tp_account_manager_prepare_async (self->priv->account_manager, NULL,
283
218
      publish_to_all_am_prepared_cb, data);
284
219
}
285
220
 
287
222
publish_on_idle (gpointer user_data)
288
223
{
289
224
  EmpathyLocationManager *manager = EMPATHY_LOCATION_MANAGER (user_data);
290
 
  EmpathyLocationManagerPriv *priv = GET_PRIV (manager);
291
225
 
292
 
  priv->timeout_id = 0;
 
226
  manager->priv->timeout_id = 0;
293
227
  publish_to_all_connections (manager, TRUE);
294
228
  return FALSE;
295
229
}
301
235
    guint reason,
302
236
    gchar *dbus_error_name,
303
237
    GHashTable *details,
304
 
    gpointer *self)
 
238
    gpointer user_data)
305
239
{
306
 
  EmpathyLocationManagerPriv *priv = GET_PRIV (self);
 
240
  EmpathyLocationManager *self = user_data;
307
241
  TpConnection *conn;
308
242
 
309
243
  conn = tp_account_get_connection (account);
311
245
  DEBUG ("New connection %p", conn);
312
246
 
313
247
  /* Don't publish if it is already planned (ie startup) */
314
 
  if (priv->timeout_id == 0)
 
248
  if (self->priv->timeout_id == 0)
315
249
    {
316
250
      publish_location (EMPATHY_LOCATION_MANAGER (self), conn,
317
251
          FALSE);
321
255
static void
322
256
update_timestamp (EmpathyLocationManager *self)
323
257
{
324
 
  EmpathyLocationManagerPriv *priv= GET_PRIV (self);
325
 
  GValue *new_value;
326
 
  gint64 stamp64;
327
 
  time_t timestamp;
328
 
 
329
 
  timestamp = time (NULL);
330
 
  stamp64 = (gint64) timestamp;
331
 
  new_value = tp_g_value_slice_new_int64 (stamp64);
332
 
  g_hash_table_insert (priv->location, g_strdup (EMPATHY_LOCATION_TIMESTAMP),
333
 
      new_value);
334
 
  DEBUG ("\t - Timestamp: %" G_GINT64_FORMAT, stamp64);
 
258
  gint64 timestamp;
 
259
 
 
260
  timestamp = empathy_time_get_current ();
 
261
  tp_asv_set_int64 (self->priv->location, EMPATHY_LOCATION_TIMESTAMP,
 
262
      timestamp);
 
263
 
 
264
  DEBUG ("\t - Timestamp: %" G_GINT64_FORMAT, timestamp);
335
265
}
336
266
 
337
267
static void
339
269
                    int timestamp,
340
270
                    GHashTable *details,
341
271
                    GeoclueAccuracy *accuracy,
342
 
                    gpointer self)
 
272
                    gpointer user_data)
343
273
{
 
274
  EmpathyLocationManager *self = user_data;
344
275
  GeoclueAccuracyLevel level;
345
 
  EmpathyLocationManagerPriv *priv = GET_PRIV (self);
346
276
  GHashTableIter iter;
347
277
  gpointer key, value;
348
278
 
350
280
  DEBUG ("New address (accuracy level %d):", level);
351
281
  /* FIXME: Publish accuracy level also considering the position's */
352
282
 
353
 
  g_hash_table_remove (priv->location, EMPATHY_LOCATION_STREET);
354
 
  g_hash_table_remove (priv->location, EMPATHY_LOCATION_AREA);
355
 
  g_hash_table_remove (priv->location, EMPATHY_LOCATION_REGION);
356
 
  g_hash_table_remove (priv->location, EMPATHY_LOCATION_COUNTRY);
357
 
  g_hash_table_remove (priv->location, EMPATHY_LOCATION_COUNTRY_CODE);
358
 
  g_hash_table_remove (priv->location, EMPATHY_LOCATION_POSTAL_CODE);
 
283
  g_hash_table_remove (self->priv->location, EMPATHY_LOCATION_STREET);
 
284
  g_hash_table_remove (self->priv->location, EMPATHY_LOCATION_AREA);
 
285
  g_hash_table_remove (self->priv->location, EMPATHY_LOCATION_REGION);
 
286
  g_hash_table_remove (self->priv->location, EMPATHY_LOCATION_COUNTRY);
 
287
  g_hash_table_remove (self->priv->location, EMPATHY_LOCATION_COUNTRY_CODE);
 
288
  g_hash_table_remove (self->priv->location, EMPATHY_LOCATION_POSTAL_CODE);
359
289
 
360
290
  if (g_hash_table_size (details) == 0)
361
291
    {
366
296
  g_hash_table_iter_init (&iter, details);
367
297
  while (g_hash_table_iter_next (&iter, &key, &value))
368
298
    {
369
 
      GValue *new_value;
370
299
      /* Discard street information if reduced accuracy is on */
371
 
      if (priv->reduce_accuracy &&
 
300
      if (self->priv->reduce_accuracy &&
372
301
          !tp_strdiff (key, EMPATHY_LOCATION_STREET))
373
302
        continue;
374
303
 
375
 
      new_value = tp_g_value_slice_new_string (value);
376
 
      g_hash_table_insert (priv->location, g_strdup (key), new_value);
 
304
      tp_asv_set_string (self->priv->location, key, value);
377
305
 
378
306
      DEBUG ("\t - %s: %s", (gchar *) key, (gchar *) value);
379
307
    }
380
308
 
381
309
  update_timestamp (self);
382
 
  if (priv->timeout_id == 0)
383
 
    priv->timeout_id = g_timeout_add_seconds (TIMEOUT, publish_on_idle, self);
 
310
  if (self->priv->timeout_id == 0)
 
311
    self->priv->timeout_id = g_timeout_add_seconds (TIMEOUT, publish_on_idle,
 
312
        self);
384
313
}
385
314
 
386
315
static void
410
339
                     double longitude,
411
340
                     double altitude,
412
341
                     GeoclueAccuracy *accuracy,
413
 
                     gpointer self)
 
342
                     gpointer user_data)
414
343
{
415
 
  EmpathyLocationManagerPriv *priv = GET_PRIV (self);
 
344
  EmpathyLocationManager *self = user_data;
416
345
  GeoclueAccuracyLevel level;
417
346
  gdouble mean, horizontal, vertical;
418
 
  GValue *new_value;
419
 
 
420
347
 
421
348
  geoclue_accuracy_get_details (accuracy, &level, &horizontal, &vertical);
422
349
  DEBUG ("New position (accuracy level %d)", level);
426
353
  if (fields & GEOCLUE_POSITION_FIELDS_LONGITUDE)
427
354
    {
428
355
 
429
 
      if (priv->reduce_accuracy)
 
356
      if (self->priv->reduce_accuracy)
430
357
        /* Truncate at 1 decimal place */
431
358
        longitude = ((int) (longitude * 10)) / 10.0;
432
359
 
433
 
      new_value = tp_g_value_slice_new_double (longitude);
434
 
      g_hash_table_insert (priv->location, g_strdup (EMPATHY_LOCATION_LON),
435
 
          new_value);
 
360
      tp_asv_set_double (self->priv->location, EMPATHY_LOCATION_LON, longitude);
 
361
 
436
362
      DEBUG ("\t - Longitude: %f", longitude);
437
363
    }
438
364
  else
439
365
    {
440
 
      g_hash_table_remove (priv->location, EMPATHY_LOCATION_LON);
 
366
      g_hash_table_remove (self->priv->location, EMPATHY_LOCATION_LON);
441
367
    }
442
368
 
443
369
  if (fields & GEOCLUE_POSITION_FIELDS_LATITUDE)
444
370
    {
445
 
      if (priv->reduce_accuracy)
 
371
      if (self->priv->reduce_accuracy)
446
372
        /* Truncate at 1 decimal place */
447
373
        latitude = ((int) (latitude * 10)) / 10.0;
448
374
 
449
 
      new_value = tp_g_value_slice_new_double (latitude);
450
 
      g_hash_table_replace (priv->location, g_strdup (EMPATHY_LOCATION_LAT),
451
 
          new_value);
 
375
      tp_asv_set_double (self->priv->location, EMPATHY_LOCATION_LAT, latitude);
 
376
 
452
377
      DEBUG ("\t - Latitude: %f", latitude);
453
378
    }
454
379
  else
455
380
    {
456
 
      g_hash_table_remove (priv->location, EMPATHY_LOCATION_LAT);
 
381
      g_hash_table_remove (self->priv->location, EMPATHY_LOCATION_LAT);
457
382
    }
458
383
 
459
384
  if (fields & GEOCLUE_POSITION_FIELDS_ALTITUDE)
460
385
    {
461
 
      new_value = tp_g_value_slice_new_double (altitude);
462
 
      g_hash_table_replace (priv->location, g_strdup (EMPATHY_LOCATION_ALT),
463
 
          new_value);
 
386
      tp_asv_set_double (self->priv->location, EMPATHY_LOCATION_ALT, altitude);
 
387
 
464
388
      DEBUG ("\t - Altitude: %f", altitude);
465
389
    }
466
390
  else
467
391
    {
468
 
      g_hash_table_remove (priv->location, EMPATHY_LOCATION_ALT);
 
392
      g_hash_table_remove (self->priv->location, EMPATHY_LOCATION_ALT);
469
393
    }
470
394
 
471
395
  if (level == GEOCLUE_ACCURACY_LEVEL_DETAILED)
472
396
    {
473
397
      mean = (horizontal + vertical) / 2.0;
474
 
      new_value = tp_g_value_slice_new_double (mean);
475
 
      g_hash_table_replace (priv->location,
476
 
          g_strdup (EMPATHY_LOCATION_ACCURACY), new_value);
 
398
      tp_asv_set_double (self->priv->location, EMPATHY_LOCATION_ACCURACY, mean);
 
399
 
477
400
      DEBUG ("\t - Accuracy: %f", mean);
478
401
    }
479
402
  else
480
403
    {
481
 
      g_hash_table_remove (priv->location, EMPATHY_LOCATION_ACCURACY);
 
404
      g_hash_table_remove (self->priv->location, EMPATHY_LOCATION_ACCURACY);
482
405
    }
483
406
 
484
407
  update_timestamp (self);
485
 
  if (priv->timeout_id == 0)
486
 
    priv->timeout_id = g_timeout_add_seconds (TIMEOUT, publish_on_idle, self);
 
408
  if (self->priv->timeout_id == 0)
 
409
    self->priv->timeout_id = g_timeout_add_seconds (TIMEOUT, publish_on_idle,
 
410
        self);
487
411
}
488
412
 
489
413
static void
512
436
static gboolean
513
437
set_requirements (EmpathyLocationManager *self)
514
438
{
515
 
  EmpathyLocationManagerPriv *priv = GET_PRIV (self);
516
439
  GError *error = NULL;
517
440
 
518
 
  if (!geoclue_master_client_set_requirements (priv->gc_client,
519
 
          GEOCLUE_ACCURACY_LEVEL_COUNTRY, 0, FALSE, priv->resources,
 
441
  if (!geoclue_master_client_set_requirements (self->priv->gc_client,
 
442
          GEOCLUE_ACCURACY_LEVEL_COUNTRY, 0, FALSE, self->priv->resources,
520
443
          &error))
521
444
    {
522
445
      DEBUG ("set_requirements failed: %s", error->message);
530
453
static void
531
454
update_resources (EmpathyLocationManager *self)
532
455
{
533
 
  EmpathyLocationManagerPriv *priv = GET_PRIV (self);
534
 
 
535
 
  DEBUG ("Updating resources %d", priv->resources);
536
 
 
537
 
  if (!priv->geoclue_is_setup)
 
456
  DEBUG ("Updating resources %d", self->priv->resources);
 
457
 
 
458
  if (!self->priv->geoclue_is_setup)
538
459
    return;
539
460
 
540
461
  /* As per Geoclue bug #15126, using NONE results in no address
543
464
  if (!set_requirements (self))
544
465
    return;
545
466
 
546
 
  geoclue_address_get_address_async (priv->gc_address,
 
467
  geoclue_address_get_address_async (self->priv->gc_address,
547
468
      initial_address_cb, self);
548
 
  geoclue_position_get_position_async (priv->gc_position,
 
469
  geoclue_position_get_position_async (self->priv->gc_position,
549
470
      initial_position_cb, self);
550
471
}
551
472
 
552
473
static void
553
474
setup_geoclue (EmpathyLocationManager *self)
554
475
{
555
 
  EmpathyLocationManagerPriv *priv = GET_PRIV (self);
556
 
 
557
476
  GeoclueMaster *master;
558
477
  GError *error = NULL;
559
478
 
560
479
  DEBUG ("Setting up Geoclue");
561
480
  master = geoclue_master_get_default ();
562
 
  priv->gc_client = geoclue_master_create_client (master, NULL, &error);
 
481
  self->priv->gc_client = geoclue_master_create_client (master, NULL, &error);
563
482
  g_object_unref (master);
564
483
 
565
 
  if (priv->gc_client == NULL)
 
484
  if (self->priv->gc_client == NULL)
566
485
    {
567
486
      DEBUG ("Failed to GeoclueMasterClient: %s", error->message);
568
487
      g_error_free (error);
573
492
    return;
574
493
 
575
494
  /* Get updated when the position is changes */
576
 
  priv->gc_position = geoclue_master_client_create_position (
577
 
      priv->gc_client, &error);
578
 
  if (priv->gc_position == NULL)
 
495
  self->priv->gc_position = geoclue_master_client_create_position (
 
496
      self->priv->gc_client, &error);
 
497
  if (self->priv->gc_position == NULL)
579
498
    {
580
499
      DEBUG ("Failed to create GeocluePosition: %s", error->message);
581
500
      g_error_free (error);
582
501
      return;
583
502
    }
584
503
 
585
 
  g_signal_connect (G_OBJECT (priv->gc_position), "position-changed",
 
504
  g_signal_connect (G_OBJECT (self->priv->gc_position), "position-changed",
586
505
      G_CALLBACK (position_changed_cb), self);
587
506
 
588
507
  /* Get updated when the address changes */
589
 
  priv->gc_address = geoclue_master_client_create_address (
590
 
      priv->gc_client, &error);
591
 
  if (priv->gc_address == NULL)
 
508
  self->priv->gc_address = geoclue_master_client_create_address (
 
509
      self->priv->gc_client, &error);
 
510
  if (self->priv->gc_address == NULL)
592
511
    {
593
512
      DEBUG ("Failed to create GeoclueAddress: %s", error->message);
594
513
      g_error_free (error);
595
514
      return;
596
515
    }
597
516
 
598
 
  g_signal_connect (G_OBJECT (priv->gc_address), "address-changed",
 
517
  g_signal_connect (G_OBJECT (self->priv->gc_address), "address-changed",
599
518
      G_CALLBACK (address_changed_cb), self);
600
519
 
601
 
  priv->geoclue_is_setup = TRUE;
 
520
  self->priv->geoclue_is_setup = TRUE;
602
521
}
603
522
 
604
523
static void
606
525
            const gchar *key,
607
526
            gpointer user_data)
608
527
{
609
 
  EmpathyLocationManager *manager = EMPATHY_LOCATION_MANAGER (user_data);
610
 
  EmpathyLocationManagerPriv *priv = GET_PRIV (manager);
 
528
  EmpathyLocationManager *self = EMPATHY_LOCATION_MANAGER (user_data);
611
529
 
612
530
  DEBUG ("Publish Conf changed");
613
531
 
614
532
  if (g_settings_get_boolean (gsettings_loc, key))
615
533
    {
616
 
      if (!priv->geoclue_is_setup)
617
 
        setup_geoclue (manager);
 
534
      if (!self->priv->geoclue_is_setup)
 
535
        setup_geoclue (self);
618
536
      /* if still not setup than the init failed */
619
 
      if (!priv->geoclue_is_setup)
 
537
      if (!self->priv->geoclue_is_setup)
620
538
        return;
621
539
 
622
 
      geoclue_address_get_address_async (priv->gc_address,
623
 
          initial_address_cb, manager);
624
 
      geoclue_position_get_position_async (priv->gc_position,
625
 
          initial_position_cb, manager);
 
540
      geoclue_address_get_address_async (self->priv->gc_address,
 
541
          initial_address_cb, self);
 
542
      geoclue_position_get_position_async (self->priv->gc_position,
 
543
          initial_position_cb, self);
626
544
    }
627
545
  else
628
546
    {
629
547
      /* As per XEP-0080: send an empty location to have remove current
630
548
       * location from the servers
631
549
       */
632
 
      g_hash_table_remove_all (priv->location);
633
 
      publish_to_all_connections (manager, TRUE);
 
550
      g_hash_table_remove_all (self->priv->location);
 
551
      publish_to_all_connections (self, TRUE);
634
552
    }
635
553
 
636
554
}
640
558
             const gchar *key,
641
559
             gpointer user_data)
642
560
{
643
 
  EmpathyLocationManager *manager = EMPATHY_LOCATION_MANAGER (user_data);
644
 
  EmpathyLocationManagerPriv *priv = GET_PRIV (manager);
 
561
  EmpathyLocationManager *self = EMPATHY_LOCATION_MANAGER (user_data);
645
562
  GeoclueResourceFlags resource = 0;
646
563
 
647
564
  DEBUG ("%s changed", key);
654
571
    resource = GEOCLUE_RESOURCE_GPS;
655
572
 
656
573
  if (g_settings_get_boolean (gsettings_loc, key))
657
 
    priv->resources |= resource;
 
574
    self->priv->resources |= resource;
658
575
  else
659
 
    priv->resources &= ~resource;
 
576
    self->priv->resources &= ~resource;
660
577
 
661
 
  if (priv->geoclue_is_setup)
662
 
    update_resources (manager);
 
578
  if (self->priv->geoclue_is_setup)
 
579
    update_resources (self);
663
580
}
664
581
 
665
582
static void
667
584
             const gchar *key,
668
585
             gpointer user_data)
669
586
{
670
 
  EmpathyLocationManager *manager = EMPATHY_LOCATION_MANAGER (user_data);
671
 
  EmpathyLocationManagerPriv *priv = GET_PRIV (manager);
 
587
  EmpathyLocationManager *self = EMPATHY_LOCATION_MANAGER (user_data);
672
588
 
673
589
  DEBUG ("%s changed", key);
674
590
 
675
 
  priv->reduce_accuracy = g_settings_get_boolean (gsettings_loc, key);
 
591
  self->priv->reduce_accuracy = g_settings_get_boolean (gsettings_loc, key);
676
592
 
677
 
  if (!priv->geoclue_is_setup)
 
593
  if (!self->priv->geoclue_is_setup)
678
594
    return;
679
595
 
680
 
  geoclue_address_get_address_async (priv->gc_address,
681
 
      initial_address_cb, manager);
682
 
  geoclue_position_get_position_async (priv->gc_position,
683
 
      initial_position_cb, manager);
 
596
  geoclue_address_get_address_async (self->priv->gc_address,
 
597
      initial_address_cb, self);
 
598
  geoclue_position_get_position_async (self->priv->gc_position,
 
599
      initial_position_cb, self);
684
600
}
685
601
 
686
602
static void
714
630
static void
715
631
empathy_location_manager_init (EmpathyLocationManager *self)
716
632
{
717
 
  EmpathyLocationManagerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
718
 
      EMPATHY_TYPE_LOCATION_MANAGER, EmpathyLocationManagerPriv);
 
633
  EmpathyLocationManagerPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
 
634
      EMPATHY_TYPE_LOCATION_MANAGER, EmpathyLocationManagerPrivate);
719
635
 
720
636
  self->priv = priv;
721
637
  priv->geoclue_is_setup = FALSE;
722
 
  priv->location = g_hash_table_new_full (g_direct_hash, g_direct_equal,
723
 
      g_free, (GDestroyNotify) tp_g_value_slice_free);
 
638
  priv->location = tp_asv_new (NULL, NULL);
724
639
  priv->gsettings_loc = g_settings_new (EMPATHY_PREFS_LOCATION_SCHEMA);
725
640
 
726
641
  /* Setup account status callbacks */