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);
54 g_print ("enable publishing\n");
55 if (priv->publisher != NULL)
58 priv->publisher = position_publisher_new ();
62 g_print ("disable publishing\n");
63 if (priv->publisher == NULL)
66 g_object_unref (priv->publisher);
67 priv->publisher = NULL;
72 gconf_notification_cb (GConfClient *client,
77 Azimuth *self = user_data;
78 const gchar *key = gconf_entry_get_key (entry);
79 GConfValue *value = gconf_entry_get_value (entry);
81 if (!tp_strdiff (key, AZIMUTH_GCONF_KEY_ENABLED) &&
82 value->type == GCONF_VALUE_BOOL)
84 gboolean enabled = gconf_value_get_bool (value);
86 enabled_changed (self, enabled);
91 azimuth_init (Azimuth *self)
93 AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (self);
95 priv->loop = g_main_loop_new (NULL, FALSE);
96 priv->publisher = NULL;
98 priv->gconf = gconf_client_get_default ();
100 gconf_client_add_dir (priv->gconf, AZIMUTH_GCONF_SECTION,
101 GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
103 gconf_client_notify_add (priv->gconf, AZIMUTH_GCONF_SECTION,
104 gconf_notification_cb, self, NULL, NULL);
108 azimuth_dispose (GObject *object)
110 Azimuth *self = AZIMUTH (object);
111 AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (self);
113 if (priv->publisher != NULL)
115 g_object_unref (priv->publisher);
116 priv->publisher = NULL;
119 if (priv->loop != NULL)
121 g_main_loop_unref (priv->loop);
125 if (priv->gconf != NULL)
127 g_object_unref (priv->gconf);
131 if (G_OBJECT_CLASS (azimuth_parent_class)->dispose)
132 G_OBJECT_CLASS (azimuth_parent_class)->dispose (object);
136 azimuth_class_init (AzimuthClass *azimuth_class)
138 GObjectClass *object_class = G_OBJECT_CLASS (azimuth_class);
140 g_type_class_add_private (azimuth_class, sizeof (AzimuthPrivate));
142 object_class->dispose = azimuth_dispose;
148 return g_object_new (AZIMUTH_TYPE,
153 azimuth_run (Azimuth *self)
155 AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (self);
158 enabled = gconf_client_get_bool (priv->gconf, AZIMUTH_GCONF_KEY_ENABLED,
162 g_print ("publishing is enabled\n");
163 g_assert (priv->publisher == NULL);
164 priv->publisher = position_publisher_new ();
168 g_print ("publishing is disabled\n");
171 g_print ("azimuth running\n");
172 g_main_loop_run (priv->loop);