#include <stdio.h>
#include <stdlib.h>
+#include <gconf/gconf-client.h>
+#include <telepathy-glib/util.h>
+
#include "azimuth.h"
+#include "azimuth-gconf.h"
#include "position-publisher.h"
G_DEFINE_TYPE(Azimuth, azimuth, G_TYPE_OBJECT)
{
GMainLoop *loop;
PositionPublisher *publisher;
+ GConfClient *gconf;
};
#define AZIMUTH_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), AZIMUTH_TYPE, AzimuthPrivate))
static void
-azimuth_init (Azimuth *obj)
+enabled_changed (Azimuth *self,
+ gboolean enabled)
+{
+ AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (self);
+
+ if (enabled)
+ {
+ g_print ("enable publishing\n");
+ if (priv->publisher != NULL)
+ return;
+
+ priv->publisher = position_publisher_new ();
+ }
+ else
+ {
+ g_print ("disable publishing\n");
+ if (priv->publisher == NULL)
+ return;
+
+ g_object_unref (priv->publisher);
+ priv->publisher = NULL;
+ }
+}
+
+static void
+gconf_notification_cb (GConfClient *client,
+ guint cnxn_id,
+ GConfEntry *entry,
+ gpointer user_data)
{
- AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (obj);
+ Azimuth *self = user_data;
+ const gchar *key = gconf_entry_get_key (entry);
+ GConfValue *value = gconf_entry_get_value (entry);
+
+ if (!tp_strdiff (key, AZIMUTH_GCONF_KEY_ENABLED) &&
+ value->type == GCONF_VALUE_BOOL)
+ {
+ gboolean enabled = gconf_value_get_bool (value);
+
+ enabled_changed (self, enabled);
+ }
+}
+
+static void
+azimuth_init (Azimuth *self)
+{
+ AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (self);
priv->loop = g_main_loop_new (NULL, FALSE);
priv->publisher = NULL;
+
+ priv->gconf = gconf_client_get_default ();
+
+ gconf_client_add_dir (priv->gconf, AZIMUTH_GCONF_SECTION,
+ GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
+
+ gconf_client_notify_add (priv->gconf, AZIMUTH_GCONF_SECTION,
+ gconf_notification_cb, self, NULL, NULL);
}
static void
priv->loop = NULL;
}
+ if (priv->gconf != NULL)
+ {
+ g_object_unref (priv->gconf);
+ priv->gconf = NULL;
+ }
+
if (G_OBJECT_CLASS (azimuth_parent_class)->dispose)
G_OBJECT_CLASS (azimuth_parent_class)->dispose (object);
}
azimuth_run (Azimuth *self)
{
AzimuthPrivate *priv = AZIMUTH_GET_PRIVATE (self);
+ gboolean enabled;
- g_assert (priv->publisher == NULL);
- priv->publisher = position_publisher_new ();
+ enabled = gconf_client_get_bool (priv->gconf, AZIMUTH_GCONF_KEY_ENABLED,
+ NULL);
+ if (enabled)
+ {
+ g_print ("publishing is enabled\n");
+ g_assert (priv->publisher == NULL);
+ priv->publisher = position_publisher_new ();
+ }
+ else
+ {
+ g_print ("publishing is disabled\n");
+ }
g_print ("azimuth running\n");
g_main_loop_run (priv->loop);