1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2006 Imendio AB
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Authors: Richard Hult <richard@imendio.com>
27 #include <gconf/gconf-client.h>
29 #include "gossip-conf.h"
30 #include "gossip-debug.h"
32 #define DEBUG_DOMAIN "Config"
34 #define GOSSIP_CONF_ROOT "/apps/empathy"
35 #define DESKTOP_INTERFACE_ROOT "/desktop/gnome/interface"
37 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GOSSIP_TYPE_CONF, GossipConfPriv))
40 GConfClient *gconf_client;
45 GossipConfNotifyFunc func;
47 } GossipConfNotifyData;
49 static void conf_finalize (GObject *object);
51 G_DEFINE_TYPE (GossipConf, gossip_conf, G_TYPE_OBJECT);
53 static GossipConf *global_conf = NULL;
56 gossip_conf_class_init (GossipConfClass *class)
58 GObjectClass *object_class;
60 object_class = G_OBJECT_CLASS (class);
62 object_class->finalize = conf_finalize;
64 g_type_class_add_private (object_class, sizeof (GossipConfPriv));
68 gossip_conf_init (GossipConf *conf)
72 priv = GET_PRIV (conf);
74 priv->gconf_client = gconf_client_get_default ();
76 gconf_client_add_dir (priv->gconf_client,
78 GCONF_CLIENT_PRELOAD_ONELEVEL,
80 gconf_client_add_dir (priv->gconf_client,
81 DESKTOP_INTERFACE_ROOT,
82 GCONF_CLIENT_PRELOAD_NONE,
87 conf_finalize (GObject *object)
91 priv = GET_PRIV (object);
93 gconf_client_remove_dir (priv->gconf_client,
96 gconf_client_remove_dir (priv->gconf_client,
97 DESKTOP_INTERFACE_ROOT,
100 g_object_unref (priv->gconf_client);
102 G_OBJECT_CLASS (gossip_conf_parent_class)->finalize (object);
106 gossip_conf_get (void)
109 global_conf = g_object_new (GOSSIP_TYPE_CONF, NULL);
116 gossip_conf_shutdown (void)
119 g_object_unref (global_conf);
125 gossip_conf_set_int (GossipConf *conf,
129 GossipConfPriv *priv;
131 g_return_val_if_fail (GOSSIP_IS_CONF (conf), FALSE);
133 gossip_debug (DEBUG_DOMAIN, "Setting int:'%s' to %d", key, value);
135 priv = GET_PRIV (conf);
137 return gconf_client_set_int (priv->gconf_client,
144 gossip_conf_get_int (GossipConf *conf,
148 GossipConfPriv *priv;
149 GError *error = NULL;
153 g_return_val_if_fail (GOSSIP_IS_CONF (conf), FALSE);
154 g_return_val_if_fail (value != NULL, FALSE);
156 priv = GET_PRIV (conf);
158 *value = gconf_client_get_int (priv->gconf_client,
163 g_error_free (error);
171 gossip_conf_set_bool (GossipConf *conf,
175 GossipConfPriv *priv;
177 g_return_val_if_fail (GOSSIP_IS_CONF (conf), FALSE);
179 gossip_debug (DEBUG_DOMAIN, "Setting bool:'%s' to %d ---> %s",
180 key, value, value ? "true" : "false");
182 priv = GET_PRIV (conf);
184 return gconf_client_set_bool (priv->gconf_client,
191 gossip_conf_get_bool (GossipConf *conf,
195 GossipConfPriv *priv;
196 GError *error = NULL;
200 g_return_val_if_fail (GOSSIP_IS_CONF (conf), FALSE);
201 g_return_val_if_fail (value != NULL, FALSE);
203 priv = GET_PRIV (conf);
205 *value = gconf_client_get_bool (priv->gconf_client,
210 g_error_free (error);
218 gossip_conf_set_string (GossipConf *conf,
222 GossipConfPriv *priv;
224 g_return_val_if_fail (GOSSIP_IS_CONF (conf), FALSE);
226 gossip_debug (DEBUG_DOMAIN, "Setting string:'%s' to '%s'",
229 priv = GET_PRIV (conf);
231 return gconf_client_set_string (priv->gconf_client,
238 gossip_conf_get_string (GossipConf *conf,
242 GossipConfPriv *priv;
243 GError *error = NULL;
247 g_return_val_if_fail (GOSSIP_IS_CONF (conf), FALSE);
249 priv = GET_PRIV (conf);
251 *value = gconf_client_get_string (priv->gconf_client,
256 g_error_free (error);
264 gossip_conf_set_string_list (GossipConf *conf,
268 GossipConfPriv *priv;
270 g_return_val_if_fail (GOSSIP_IS_CONF (conf), FALSE);
272 priv = GET_PRIV (conf);
274 return gconf_client_set_list (priv->gconf_client,
282 gossip_conf_get_string_list (GossipConf *conf,
286 GossipConfPriv *priv;
287 GError *error = NULL;
291 g_return_val_if_fail (GOSSIP_IS_CONF (conf), FALSE);
293 priv = GET_PRIV (conf);
295 *value = gconf_client_get_list (priv->gconf_client,
300 g_error_free (error);
308 conf_notify_data_free (GossipConfNotifyData *data)
310 g_object_unref (data->conf);
311 g_slice_free (GossipConfNotifyData, data);
315 conf_notify_func (GConfClient *client,
320 GossipConfNotifyData *data;
324 data->func (data->conf,
325 gconf_entry_get_key (entry),
330 gossip_conf_notify_add (GossipConf *conf,
332 GossipConfNotifyFunc func,
335 GossipConfPriv *priv;
337 GossipConfNotifyData *data;
339 g_return_val_if_fail (GOSSIP_IS_CONF (conf), 0);
341 priv = GET_PRIV (conf);
343 data = g_slice_new (GossipConfNotifyData);
345 data->user_data = user_data;
346 data->conf = g_object_ref (conf);
348 id = gconf_client_notify_add (priv->gconf_client,
352 (GFreeFunc) conf_notify_data_free,
359 gossip_conf_notify_remove (GossipConf *conf,
362 GossipConfPriv *priv;
364 g_return_val_if_fail (GOSSIP_IS_CONF (conf), FALSE);
366 priv = GET_PRIV (conf);
368 gconf_client_notify_remove (priv->gconf_client, id);