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,
162 gossip_debug (DEBUG_DOMAIN, "Getting int:'%s' (=%d), error:'%s'",
163 key, *value, error ? error->message : "None");
166 g_error_free (error);
174 gossip_conf_set_bool (GossipConf *conf,
178 GossipConfPriv *priv;
180 g_return_val_if_fail (GOSSIP_IS_CONF (conf), FALSE);
182 gossip_debug (DEBUG_DOMAIN, "Setting bool:'%s' to %d ---> %s",
183 key, value, value ? "true" : "false");
185 priv = GET_PRIV (conf);
187 return gconf_client_set_bool (priv->gconf_client,
194 gossip_conf_get_bool (GossipConf *conf,
198 GossipConfPriv *priv;
199 GError *error = NULL;
203 g_return_val_if_fail (GOSSIP_IS_CONF (conf), FALSE);
204 g_return_val_if_fail (value != NULL, FALSE);
206 priv = GET_PRIV (conf);
208 *value = gconf_client_get_bool (priv->gconf_client,
212 gossip_debug (DEBUG_DOMAIN, "Getting bool:'%s' (=%d ---> %s), error:'%s'",
213 key, *value, *value ? "true" : "false",
214 error ? error->message : "None");
217 g_error_free (error);
225 gossip_conf_set_string (GossipConf *conf,
229 GossipConfPriv *priv;
231 g_return_val_if_fail (GOSSIP_IS_CONF (conf), FALSE);
233 gossip_debug (DEBUG_DOMAIN, "Setting string:'%s' to '%s'",
236 priv = GET_PRIV (conf);
238 return gconf_client_set_string (priv->gconf_client,
245 gossip_conf_get_string (GossipConf *conf,
249 GossipConfPriv *priv;
250 GError *error = NULL;
254 g_return_val_if_fail (GOSSIP_IS_CONF (conf), FALSE);
256 priv = GET_PRIV (conf);
258 *value = gconf_client_get_string (priv->gconf_client,
262 gossip_debug (DEBUG_DOMAIN, "Getting string:'%s' (='%s'), error:'%s'",
263 key, *value, error ? error->message : "None");
266 g_error_free (error);
274 gossip_conf_set_string_list (GossipConf *conf,
278 GossipConfPriv *priv;
280 g_return_val_if_fail (GOSSIP_IS_CONF (conf), FALSE);
282 priv = GET_PRIV (conf);
284 return gconf_client_set_list (priv->gconf_client,
292 gossip_conf_get_string_list (GossipConf *conf,
296 GossipConfPriv *priv;
297 GError *error = NULL;
301 g_return_val_if_fail (GOSSIP_IS_CONF (conf), FALSE);
303 priv = GET_PRIV (conf);
305 *value = gconf_client_get_list (priv->gconf_client,
310 g_error_free (error);
318 conf_notify_data_free (GossipConfNotifyData *data)
320 g_object_unref (data->conf);
321 g_slice_free (GossipConfNotifyData, data);
325 conf_notify_func (GConfClient *client,
330 GossipConfNotifyData *data;
334 data->func (data->conf,
335 gconf_entry_get_key (entry),
340 gossip_conf_notify_add (GossipConf *conf,
342 GossipConfNotifyFunc func,
345 GossipConfPriv *priv;
347 GossipConfNotifyData *data;
349 g_return_val_if_fail (GOSSIP_IS_CONF (conf), 0);
351 priv = GET_PRIV (conf);
353 data = g_slice_new (GossipConfNotifyData);
355 data->user_data = user_data;
356 data->conf = g_object_ref (conf);
358 id = gconf_client_notify_add (priv->gconf_client,
362 (GFreeFunc) conf_notify_data_free,
369 gossip_conf_notify_remove (GossipConf *conf,
372 GossipConfPriv *priv;
374 g_return_val_if_fail (GOSSIP_IS_CONF (conf), FALSE);
376 priv = GET_PRIV (conf);
378 gconf_client_notify_remove (priv->gconf_client, id);