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>
29 #include "azimuth-gconf.h"
30 #include "position-publisher.h"
32 G_DEFINE_TYPE(Azimuth, azimuth, G_TYPE_OBJECT)
34 /* private structure */
35 typedef struct _AzimuthPrivate AzimuthPrivate;
37 struct _AzimuthPrivate
40 PositionPublisher *publisher;
44 #define AZIMUTH_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), AZIMUTH_TYPE, AzimuthPrivate))
47 enabled_changed (Azimuth *self,
50 AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (self);
55 if (priv->publisher != NULL)
58 start_gps = gconf_client_get_bool (priv->gconf,
59 AZIMUTH_GCONF_KEY_START_GPS, NULL);
60 g_print ("enable publishing (start gps: %s)\n",
61 start_gps ? "yes" : "no");
62 priv->publisher = position_publisher_new (TRUE, start_gps);
66 g_print ("disable publishing\n");
67 if (priv->publisher == NULL)
70 g_object_unref (priv->publisher);
71 priv->publisher = NULL;
76 start_gps_changed (Azimuth *self,
79 AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (self);
83 g_print ("%s GPS\n", start_gps ? "Start" : "Stop");
84 g_object_set (priv->publisher, "start-gps", start_gps, NULL);
89 gconf_notification_cb (GConfClient *client,
94 Azimuth *self = user_data;
95 const gchar *key = gconf_entry_get_key (entry);
96 GConfValue *value = gconf_entry_get_value (entry);
98 if (!tp_strdiff (key, AZIMUTH_GCONF_KEY_ENABLED) &&
99 value->type == GCONF_VALUE_BOOL)
101 gboolean enabled = gconf_value_get_bool (value);
103 enabled_changed (self, enabled);
106 if (!tp_strdiff (key, AZIMUTH_GCONF_KEY_START_GPS) &&
107 value->type == GCONF_VALUE_BOOL)
109 gboolean start_gps = gconf_value_get_bool (value);
111 start_gps_changed (self, start_gps);
116 azimuth_init (Azimuth *self)
118 AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (self);
120 priv->loop = g_main_loop_new (NULL, FALSE);
121 priv->publisher = NULL;
123 priv->gconf = gconf_client_get_default ();
125 gconf_client_add_dir (priv->gconf, AZIMUTH_GCONF_SECTION,
126 GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
128 gconf_client_notify_add (priv->gconf, AZIMUTH_GCONF_SECTION,
129 gconf_notification_cb, self, NULL, NULL);
133 azimuth_dispose (GObject *object)
135 Azimuth *self = AZIMUTH (object);
136 AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (self);
138 if (priv->publisher != NULL)
140 g_object_unref (priv->publisher);
141 priv->publisher = NULL;
144 if (priv->loop != NULL)
146 g_main_loop_unref (priv->loop);
150 if (priv->gconf != NULL)
152 g_object_unref (priv->gconf);
156 if (G_OBJECT_CLASS (azimuth_parent_class)->dispose)
157 G_OBJECT_CLASS (azimuth_parent_class)->dispose (object);
161 azimuth_class_init (AzimuthClass *azimuth_class)
163 GObjectClass *object_class = G_OBJECT_CLASS (azimuth_class);
165 g_type_class_add_private (azimuth_class, sizeof (AzimuthPrivate));
167 object_class->dispose = azimuth_dispose;
173 return g_object_new (AZIMUTH_TYPE,
178 azimuth_run (Azimuth *self)
180 AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (self);
184 enabled = gconf_client_get_bool (priv->gconf, AZIMUTH_GCONF_KEY_ENABLED,
186 start_gps = gconf_client_get_bool (priv->gconf, AZIMUTH_GCONF_KEY_START_GPS,
190 g_print ("publishing is enabled (start gps: %s)\n",
191 start_gps ? "yes" : "no");
192 g_assert (priv->publisher == NULL);
193 priv->publisher = position_publisher_new (TRUE, start_gps);
197 g_print ("publishing is disabled\n");
200 g_print ("azimuth running\n");
201 g_main_loop_run (priv->loop);