2 * azimuth.c - Source for Azimith
3 * Copyright (C) 2010 Guillaume Desmottes
4 * @author Guillaume Desmottes <gdesmott@gnome.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <gconf/gconf-client.h>
26 #include <telepathy-glib/util.h>
28 #include <location/location-gpsd-control.h>
31 #include "azimuth-gconf.h"
32 #include "position-publisher.h"
34 G_DEFINE_TYPE(Azimuth, azimuth, G_TYPE_OBJECT)
36 /* private structure */
37 typedef struct _AzimuthPrivate AzimuthPrivate;
39 struct _AzimuthPrivate
42 PositionPublisher *publisher;
44 LocationGPSDControl *gps_control;
47 #define AZIMUTH_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), AZIMUTH_TYPE, AzimuthPrivate))
50 update_gps (Azimuth *self)
52 AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (self);
55 start_gps = gconf_client_get_bool (priv->gconf,
56 AZIMUTH_GCONF_KEY_START_GPS, NULL);
58 if (priv->publisher != NULL && start_gps)
60 g_print ("starting GPS\n");
61 location_gpsd_control_start (priv->gps_control);
65 g_print ("stopping GPS\n");
66 location_gpsd_control_stop (priv->gps_control);
71 enabled_changed (Azimuth *self,
74 AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (self);
78 if (priv->publisher != NULL)
81 g_print ("enable publishing\n");
82 priv->publisher = position_publisher_new (TRUE);
86 g_print ("disable publishing\n");
87 if (priv->publisher == NULL)
90 g_object_unref (priv->publisher);
91 priv->publisher = NULL;
98 gconf_notification_cb (GConfClient *client,
103 Azimuth *self = user_data;
104 const gchar *key = gconf_entry_get_key (entry);
105 GConfValue *value = gconf_entry_get_value (entry);
107 if (!tp_strdiff (key, AZIMUTH_GCONF_KEY_ENABLED) &&
108 value->type == GCONF_VALUE_BOOL)
110 gboolean enabled = gconf_value_get_bool (value);
112 enabled_changed (self, enabled);
115 if (!tp_strdiff (key, AZIMUTH_GCONF_KEY_START_GPS) &&
116 value->type == GCONF_VALUE_BOOL)
123 azimuth_init (Azimuth *self)
125 AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (self);
127 priv->loop = g_main_loop_new (NULL, FALSE);
128 priv->publisher = NULL;
130 priv->gconf = gconf_client_get_default ();
132 gconf_client_add_dir (priv->gconf, AZIMUTH_GCONF_SECTION,
133 GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
135 gconf_client_notify_add (priv->gconf, AZIMUTH_GCONF_SECTION,
136 gconf_notification_cb, self, NULL, NULL);
139 priv->gps_control = location_gpsd_control_get_default();
141 g_object_set (G_OBJECT(priv->gps_control),
142 "preferred-method", LOCATION_METHOD_USER_SELECTED,
143 "preferred-interval", LOCATION_INTERVAL_120S,
148 azimuth_dispose (GObject *object)
150 Azimuth *self = AZIMUTH (object);
151 AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (self);
153 if (priv->publisher != NULL)
155 g_object_unref (priv->publisher);
156 priv->publisher = NULL;
159 if (priv->loop != NULL)
161 g_main_loop_unref (priv->loop);
165 if (priv->gconf != NULL)
167 g_object_unref (priv->gconf);
171 if (priv->gps_control != NULL)
173 location_gpsd_control_stop (priv->gps_control);
174 g_object_unref (priv->gps_control);
175 priv->gps_control = NULL;
178 if (G_OBJECT_CLASS (azimuth_parent_class)->dispose)
179 G_OBJECT_CLASS (azimuth_parent_class)->dispose (object);
183 azimuth_class_init (AzimuthClass *azimuth_class)
185 GObjectClass *object_class = G_OBJECT_CLASS (azimuth_class);
187 g_type_class_add_private (azimuth_class, sizeof (AzimuthPrivate));
189 object_class->dispose = azimuth_dispose;
195 return g_object_new (AZIMUTH_TYPE,
200 azimuth_run (Azimuth *self)
202 AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (self);
205 enabled = gconf_client_get_bool (priv->gconf, AZIMUTH_GCONF_KEY_ENABLED,
209 g_print ("publishing is enabled\n");
210 g_assert (priv->publisher == NULL);
211 priv->publisher = position_publisher_new (TRUE);
217 g_print ("publishing is disabled\n");
220 g_print ("azimuth running\n");
221 g_main_loop_run (priv->loop);