#include <gconf/gconf-client.h>
#include <telepathy-glib/util.h>
+#include <location/location-gpsd-control.h>
+
#include "azimuth.h"
#include "azimuth-gconf.h"
#include "position-publisher.h"
GMainLoop *loop;
PositionPublisher *publisher;
GConfClient *gconf;
+ LocationGPSDControl *gps_control;
};
#define AZIMUTH_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), AZIMUTH_TYPE, AzimuthPrivate))
static void
+update_gps (Azimuth *self)
+{
+ AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (self);
+ gboolean start_gps;
+
+ start_gps = gconf_client_get_bool (priv->gconf,
+ AZIMUTH_GCONF_KEY_START_GPS, NULL);
+
+ if (priv->publisher != NULL && start_gps)
+ {
+ g_print ("starting GPS\n");
+ location_gpsd_control_start (priv->gps_control);
+ }
+ else
+ {
+ g_print ("stopping GPS\n");
+ location_gpsd_control_stop (priv->gps_control);
+ }
+}
+
+static void
enabled_changed (Azimuth *self,
gboolean enabled)
{
if (enabled)
{
- gboolean start_gps;
if (priv->publisher != NULL)
return;
- 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);
+ g_print ("enable publishing\n");
+ priv->publisher = position_publisher_new (TRUE);
}
else
{
g_object_unref (priv->publisher);
priv->publisher = NULL;
}
-}
-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);
- }
+ update_gps (self);
}
static void
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);
+ update_gps (self);
}
}
gconf_client_notify_add (priv->gconf, AZIMUTH_GCONF_SECTION,
gconf_notification_cb, self, NULL, NULL);
+
+ /* GPS controller */
+ priv->gps_control = location_gpsd_control_get_default();
+
+ g_object_set (G_OBJECT(priv->gps_control),
+ "preferred-method", LOCATION_METHOD_USER_SELECTED,
+ "preferred-interval", LOCATION_INTERVAL_120S,
+ NULL);
}
static void
priv->gconf = NULL;
}
+ if (priv->gps_control != NULL)
+ {
+ location_gpsd_control_stop (priv->gps_control);
+ g_object_unref (priv->gps_control);
+ priv->gps_control = NULL;
+ }
+
if (G_OBJECT_CLASS (azimuth_parent_class)->dispose)
G_OBJECT_CLASS (azimuth_parent_class)->dispose (object);
}
{
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 (start gps: %s)\n",
- start_gps ? "yes" : "no");
+ g_print ("publishing is enabled\n");
g_assert (priv->publisher == NULL);
- priv->publisher = position_publisher_new (TRUE, start_gps);
+ priv->publisher = position_publisher_new (TRUE);
+
+ update_gps (self);
}
else
{