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 update_blur (Azimuth *self)
73 AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (self);
76 if (priv->publisher == NULL)
79 blur = gconf_client_get_bool (priv->gconf,
80 AZIMUTH_GCONF_KEY_BLUR, NULL);
82 position_publisher_set_blur (priv->publisher, blur);
86 enabled_changed (Azimuth *self,
89 AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (self);
93 if (priv->publisher != NULL)
96 g_print ("enable publishing\n");
97 priv->publisher = position_publisher_new ();
103 g_print ("disable publishing\n");
104 if (priv->publisher == NULL)
107 g_object_unref (priv->publisher);
108 priv->publisher = NULL;
115 gconf_notification_cb (GConfClient *client,
120 Azimuth *self = user_data;
121 const gchar *key = gconf_entry_get_key (entry);
122 GConfValue *value = gconf_entry_get_value (entry);
124 if (!tp_strdiff (key, AZIMUTH_GCONF_KEY_ENABLED) &&
125 value->type == GCONF_VALUE_BOOL)
127 gboolean enabled = gconf_value_get_bool (value);
129 enabled_changed (self, enabled);
132 else if (!tp_strdiff (key, AZIMUTH_GCONF_KEY_START_GPS) &&
133 value->type == GCONF_VALUE_BOOL)
138 else if (!tp_strdiff (key, AZIMUTH_GCONF_KEY_BLUR) &&
139 value->type == GCONF_VALUE_BOOL)
146 azimuth_init (Azimuth *self)
148 AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (self);
150 priv->loop = g_main_loop_new (NULL, FALSE);
151 priv->publisher = NULL;
153 priv->gconf = gconf_client_get_default ();
155 gconf_client_add_dir (priv->gconf, AZIMUTH_GCONF_SECTION,
156 GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
158 gconf_client_notify_add (priv->gconf, AZIMUTH_GCONF_SECTION,
159 gconf_notification_cb, self, NULL, NULL);
162 priv->gps_control = location_gpsd_control_get_default();
164 g_object_set (G_OBJECT(priv->gps_control),
165 "preferred-method", LOCATION_METHOD_USER_SELECTED,
166 "preferred-interval", LOCATION_INTERVAL_120S,
171 azimuth_dispose (GObject *object)
173 Azimuth *self = AZIMUTH (object);
174 AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (self);
176 if (priv->publisher != NULL)
178 g_object_unref (priv->publisher);
179 priv->publisher = NULL;
182 if (priv->loop != NULL)
184 g_main_loop_unref (priv->loop);
188 if (priv->gconf != NULL)
190 g_object_unref (priv->gconf);
194 if (priv->gps_control != NULL)
196 location_gpsd_control_stop (priv->gps_control);
197 g_object_unref (priv->gps_control);
198 priv->gps_control = NULL;
201 if (G_OBJECT_CLASS (azimuth_parent_class)->dispose)
202 G_OBJECT_CLASS (azimuth_parent_class)->dispose (object);
206 azimuth_class_init (AzimuthClass *azimuth_class)
208 GObjectClass *object_class = G_OBJECT_CLASS (azimuth_class);
210 g_type_class_add_private (azimuth_class, sizeof (AzimuthPrivate));
212 object_class->dispose = azimuth_dispose;
218 return g_object_new (AZIMUTH_TYPE,
223 azimuth_run (Azimuth *self)
225 AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (self);
228 enabled = gconf_client_get_bool (priv->gconf, AZIMUTH_GCONF_KEY_ENABLED,
232 g_print ("publishing is enabled\n");
233 g_assert (priv->publisher == NULL);
234 priv->publisher = position_publisher_new ();
241 g_print ("publishing is disabled\n");
244 g_print ("azimuth running\n");
245 g_main_loop_run (priv->loop);