Enable GPS from Azimuth according to configuration
[azimuth] / src / azimuth.c
index bc3445a..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 ();
+      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 ();
+      priv->publisher = position_publisher_new (TRUE, start_gps);
     }
   else
     {