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 <libempathy/empathy-debug.h>
31 #include "empathy-conf.h"
33 #define DEBUG_DOMAIN "Config"
35 #define EMPATHY_CONF_ROOT "/apps/empathy"
36 #define DESKTOP_INTERFACE_ROOT "/desktop/gnome/interface"
38 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_CONF, EmpathyConfPriv))
41 GConfClient *gconf_client;
46 EmpathyConfNotifyFunc func;
48 } EmpathyConfNotifyData;
50 static void conf_finalize (GObject *object);
52 G_DEFINE_TYPE (EmpathyConf, empathy_conf, G_TYPE_OBJECT);
54 static EmpathyConf *global_conf = NULL;
57 empathy_conf_class_init (EmpathyConfClass *class)
59 GObjectClass *object_class;
61 object_class = G_OBJECT_CLASS (class);
63 object_class->finalize = conf_finalize;
65 g_type_class_add_private (object_class, sizeof (EmpathyConfPriv));
69 empathy_conf_init (EmpathyConf *conf)
71 EmpathyConfPriv *priv;
73 priv = GET_PRIV (conf);
75 priv->gconf_client = gconf_client_get_default ();
77 gconf_client_add_dir (priv->gconf_client,
79 GCONF_CLIENT_PRELOAD_ONELEVEL,
81 gconf_client_add_dir (priv->gconf_client,
82 DESKTOP_INTERFACE_ROOT,
83 GCONF_CLIENT_PRELOAD_NONE,
88 conf_finalize (GObject *object)
90 EmpathyConfPriv *priv;
92 priv = GET_PRIV (object);
94 gconf_client_remove_dir (priv->gconf_client,
97 gconf_client_remove_dir (priv->gconf_client,
98 DESKTOP_INTERFACE_ROOT,
101 g_object_unref (priv->gconf_client);
103 G_OBJECT_CLASS (empathy_conf_parent_class)->finalize (object);
107 empathy_conf_get (void)
110 global_conf = g_object_new (EMPATHY_TYPE_CONF, NULL);
117 empathy_conf_shutdown (void)
120 g_object_unref (global_conf);
126 empathy_conf_set_int (EmpathyConf *conf,
130 EmpathyConfPriv *priv;
132 g_return_val_if_fail (EMPATHY_IS_CONF (conf), FALSE);
134 empathy_debug (DEBUG_DOMAIN, "Setting int:'%s' to %d", key, value);
136 priv = GET_PRIV (conf);
138 return gconf_client_set_int (priv->gconf_client,
145 empathy_conf_get_int (EmpathyConf *conf,
149 EmpathyConfPriv *priv;
150 GError *error = NULL;
154 g_return_val_if_fail (EMPATHY_IS_CONF (conf), FALSE);
155 g_return_val_if_fail (value != NULL, FALSE);
157 priv = GET_PRIV (conf);
159 *value = gconf_client_get_int (priv->gconf_client,
164 g_error_free (error);
172 empathy_conf_set_bool (EmpathyConf *conf,
176 EmpathyConfPriv *priv;
178 g_return_val_if_fail (EMPATHY_IS_CONF (conf), FALSE);
180 empathy_debug (DEBUG_DOMAIN, "Setting bool:'%s' to %d ---> %s",
181 key, value, value ? "true" : "false");
183 priv = GET_PRIV (conf);
185 return gconf_client_set_bool (priv->gconf_client,
192 empathy_conf_get_bool (EmpathyConf *conf,
196 EmpathyConfPriv *priv;
197 GError *error = NULL;
201 g_return_val_if_fail (EMPATHY_IS_CONF (conf), FALSE);
202 g_return_val_if_fail (value != NULL, FALSE);
204 priv = GET_PRIV (conf);
206 *value = gconf_client_get_bool (priv->gconf_client,
211 g_error_free (error);
219 empathy_conf_set_string (EmpathyConf *conf,
223 EmpathyConfPriv *priv;
225 g_return_val_if_fail (EMPATHY_IS_CONF (conf), FALSE);
227 empathy_debug (DEBUG_DOMAIN, "Setting string:'%s' to '%s'",
230 priv = GET_PRIV (conf);
232 return gconf_client_set_string (priv->gconf_client,
239 empathy_conf_get_string (EmpathyConf *conf,
243 EmpathyConfPriv *priv;
244 GError *error = NULL;
248 g_return_val_if_fail (EMPATHY_IS_CONF (conf), FALSE);
250 priv = GET_PRIV (conf);
252 *value = gconf_client_get_string (priv->gconf_client,
257 g_error_free (error);
265 empathy_conf_set_string_list (EmpathyConf *conf,
269 EmpathyConfPriv *priv;
271 g_return_val_if_fail (EMPATHY_IS_CONF (conf), FALSE);
273 priv = GET_PRIV (conf);
275 return gconf_client_set_list (priv->gconf_client,
283 empathy_conf_get_string_list (EmpathyConf *conf,
287 EmpathyConfPriv *priv;
288 GError *error = NULL;
292 g_return_val_if_fail (EMPATHY_IS_CONF (conf), FALSE);
294 priv = GET_PRIV (conf);
296 *value = gconf_client_get_list (priv->gconf_client,
301 g_error_free (error);
309 conf_notify_data_free (EmpathyConfNotifyData *data)
311 g_object_unref (data->conf);
312 g_slice_free (EmpathyConfNotifyData, data);
316 conf_notify_func (GConfClient *client,
321 EmpathyConfNotifyData *data;
325 data->func (data->conf,
326 gconf_entry_get_key (entry),
331 empathy_conf_notify_add (EmpathyConf *conf,
333 EmpathyConfNotifyFunc func,
336 EmpathyConfPriv *priv;
338 EmpathyConfNotifyData *data;
340 g_return_val_if_fail (EMPATHY_IS_CONF (conf), 0);
342 priv = GET_PRIV (conf);
344 data = g_slice_new (EmpathyConfNotifyData);
346 data->user_data = user_data;
347 data->conf = g_object_ref (conf);
349 id = gconf_client_notify_add (priv->gconf_client,
353 (GFreeFunc) conf_notify_data_free,
360 empathy_conf_notify_remove (EmpathyConf *conf,
363 EmpathyConfPriv *priv;
365 g_return_val_if_fail (EMPATHY_IS_CONF (conf), FALSE);
367 priv = GET_PRIV (conf);
369 gconf_client_notify_remove (priv->gconf_client, id);