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., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301 USA
20 * Authors: Richard Hult <richard@imendio.com>
27 #include <gconf/gconf-client.h>
29 #include <libempathy/empathy-utils.h>
30 #include "empathy-conf.h"
32 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
33 #include <libempathy/empathy-debug.h>
35 #define EMPATHY_CONF_ROOT "/apps/empathy"
36 #define DESKTOP_INTERFACE_ROOT "/desktop/gnome/interface"
38 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyConf)
40 GConfClient
*gconf_client
;
45 EmpathyConfNotifyFunc func
;
47 } EmpathyConfNotifyData
;
49 static void conf_finalize (GObject
*object
);
51 G_DEFINE_TYPE (EmpathyConf
, empathy_conf
, G_TYPE_OBJECT
);
53 static EmpathyConf
*global_conf
= NULL
;
56 empathy_conf_class_init (EmpathyConfClass
*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 (EmpathyConfPriv
));
68 empathy_conf_init (EmpathyConf
*conf
)
70 EmpathyConfPriv
*priv
= G_TYPE_INSTANCE_GET_PRIVATE (conf
,
71 EMPATHY_TYPE_CONF
, EmpathyConfPriv
);
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
)
89 EmpathyConfPriv
*priv
;
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 (empathy_conf_parent_class
)->finalize (object
);
106 empathy_conf_get (void)
109 global_conf
= g_object_new (EMPATHY_TYPE_CONF
, NULL
);
116 empathy_conf_shutdown (void)
119 g_object_unref (global_conf
);
125 empathy_conf_set_int (EmpathyConf
*conf
,
129 EmpathyConfPriv
*priv
;
131 g_return_val_if_fail (EMPATHY_IS_CONF (conf
), FALSE
);
133 DEBUG ("Setting int:'%s' to %d", key
, value
);
135 priv
= GET_PRIV (conf
);
137 return gconf_client_set_int (priv
->gconf_client
,
144 empathy_conf_get_int (EmpathyConf
*conf
,
148 EmpathyConfPriv
*priv
;
149 GError
*error
= NULL
;
153 g_return_val_if_fail (EMPATHY_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 empathy_conf_set_bool (EmpathyConf
*conf
,
175 EmpathyConfPriv
*priv
;
177 g_return_val_if_fail (EMPATHY_IS_CONF (conf
), FALSE
);
179 DEBUG ("Setting bool:'%s' to %d ---> %s", key
, value
,
180 value
? "true" : "false");
182 priv
= GET_PRIV (conf
);
184 return gconf_client_set_bool (priv
->gconf_client
,
191 empathy_conf_get_bool (EmpathyConf
*conf
,
195 EmpathyConfPriv
*priv
;
196 GError
*error
= NULL
;
200 g_return_val_if_fail (EMPATHY_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 empathy_conf_set_string (EmpathyConf
*conf
,
222 EmpathyConfPriv
*priv
;
224 g_return_val_if_fail (EMPATHY_IS_CONF (conf
), FALSE
);
226 DEBUG ("Setting string:'%s' to '%s'", key
, value
);
228 priv
= GET_PRIV (conf
);
230 return gconf_client_set_string (priv
->gconf_client
,
237 empathy_conf_get_string (EmpathyConf
*conf
,
241 EmpathyConfPriv
*priv
;
242 GError
*error
= NULL
;
246 g_return_val_if_fail (EMPATHY_IS_CONF (conf
), FALSE
);
248 priv
= GET_PRIV (conf
);
250 *value
= gconf_client_get_string (priv
->gconf_client
,
255 g_error_free (error
);
263 empathy_conf_set_string_list (EmpathyConf
*conf
,
267 EmpathyConfPriv
*priv
;
269 g_return_val_if_fail (EMPATHY_IS_CONF (conf
), FALSE
);
271 priv
= GET_PRIV (conf
);
273 return gconf_client_set_list (priv
->gconf_client
,
281 empathy_conf_get_string_list (EmpathyConf
*conf
,
285 EmpathyConfPriv
*priv
;
286 GError
*error
= NULL
;
290 g_return_val_if_fail (EMPATHY_IS_CONF (conf
), FALSE
);
292 priv
= GET_PRIV (conf
);
294 *value
= gconf_client_get_list (priv
->gconf_client
,
299 g_error_free (error
);
307 conf_notify_data_free (EmpathyConfNotifyData
*data
)
309 g_object_unref (data
->conf
);
310 g_slice_free (EmpathyConfNotifyData
, data
);
314 conf_notify_func (GConfClient
*client
,
319 EmpathyConfNotifyData
*data
;
323 data
->func (data
->conf
,
324 gconf_entry_get_key (entry
),
329 empathy_conf_notify_add (EmpathyConf
*conf
,
331 EmpathyConfNotifyFunc func
,
334 EmpathyConfPriv
*priv
;
336 EmpathyConfNotifyData
*data
;
338 g_return_val_if_fail (EMPATHY_IS_CONF (conf
), 0);
340 priv
= GET_PRIV (conf
);
342 data
= g_slice_new (EmpathyConfNotifyData
);
344 data
->user_data
= user_data
;
345 data
->conf
= g_object_ref (conf
);
347 id
= gconf_client_notify_add (priv
->gconf_client
,
351 (GFreeFunc
) conf_notify_data_free
,
358 empathy_conf_notify_remove (EmpathyConf
*conf
,
361 EmpathyConfPriv
*priv
;
363 g_return_val_if_fail (EMPATHY_IS_CONF (conf
), FALSE
);
365 priv
= GET_PRIV (conf
);
367 gconf_client_notify_remove (priv
->gconf_client
, id
);