Enable GPS from Azimuth according to configuration
authorAlban Crequy <alban.crequy@collabora.co.uk>
Mon, 3 May 2010 17:31:46 +0000 (18:31 +0100)
committerAlban Crequy <alban.crequy@collabora.co.uk>
Mon, 3 May 2010 17:38:26 +0000 (18:38 +0100)
src/azimuth.c
src/position-publisher.c

index 5c1337d..57d3a76 100644 (file)
@@ -51,11 +51,15 @@ enabled_changed (Azimuth *self,
 
   if (enabled)
     {
-      g_print ("enable publishing\n");
+      gboolean start_gps;
       if (priv->publisher != NULL)
         return;
 
-      priv->publisher = position_publisher_new (TRUE, FALSE);
+      start_gps = gconf_client_get_bool (priv->gconf,
+          AZIMUTH_GCONF_KEY_START_GPS, NULL);
+      g_print ("enable publishing (start gps: %s)\n",
+          start_gps ? "yes" : "no");
+      priv->publisher = position_publisher_new (TRUE, start_gps);
     }
   else
     {
@@ -69,6 +73,19 @@ enabled_changed (Azimuth *self,
 }
 
 static void
+start_gps_changed (Azimuth *self,
+    gboolean start_gps)
+{
+  AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (self);
+
+  if (priv->publisher)
+    {
+      g_print ("%s GPS\n", start_gps ? "Start" : "Stop");
+      g_object_set (priv->publisher, "start-gps", start_gps, NULL);
+    }
+}
+
+static void
 gconf_notification_cb (GConfClient *client,
     guint cnxn_id,
     GConfEntry *entry,
@@ -85,6 +102,14 @@ gconf_notification_cb (GConfClient *client,
 
       enabled_changed (self, enabled);
     }
+
+  if (!tp_strdiff (key, AZIMUTH_GCONF_KEY_START_GPS) &&
+      value->type == GCONF_VALUE_BOOL)
+    {
+      gboolean start_gps = gconf_value_get_bool (value);
+
+      start_gps_changed (self, start_gps);
+    }
 }
 
 static void
@@ -154,14 +179,18 @@ azimuth_run (Azimuth *self)
 {
   AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (self);
   gboolean enabled;
+  gboolean start_gps;
 
   enabled = gconf_client_get_bool (priv->gconf, AZIMUTH_GCONF_KEY_ENABLED,
       NULL);
+  start_gps = gconf_client_get_bool (priv->gconf, AZIMUTH_GCONF_KEY_START_GPS,
+      NULL);
   if (enabled)
     {
-      g_print ("publishing is enabled\n");
+      g_print ("publishing is enabled (start gps: %s)\n",
+          start_gps ? "yes" : "no");
       g_assert (priv->publisher == NULL);
-      priv->publisher = position_publisher_new (TRUE, FALSE);
+      priv->publisher = position_publisher_new (TRUE, start_gps);
     }
   else
     {
index 77e6ab3..361c770 100644 (file)
@@ -327,6 +327,12 @@ position_publisher_dispose (GObject *object)
 
   priv->dispose_has_run = TRUE;
 
+  if (priv->start_gps)
+    {
+      location_gpsd_control_stop (priv->gps_control);
+      priv->start_gps = FALSE;
+    }
+
   g_object_unref (priv->watcher);
   g_object_unref (priv->gps_control);
   g_object_unref (priv->gps_device);
@@ -392,7 +398,12 @@ position_publisher_set_property (GObject *object,
       priv->blur = g_value_get_boolean (value);
       break;
     case PROP_START_GPS:
-      priv->blur = g_value_get_boolean (value);
+      priv->start_gps = g_value_get_boolean (value);
+      if (priv->start_gps)
+        location_gpsd_control_start (priv->gps_control);
+      else
+        location_gpsd_control_stop (priv->gps_control);
+
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);