Break after deleting current item in chatroom list
[empathy-mirror.git] / libempathy-gtk / empathy-conf.c
blob62efa60c66158a3c95ed44b8dffe708cbb210efa
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
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>
23 #include "config.h"
25 #include <string.h>
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)
39 typedef struct {
40 GConfClient *gconf_client;
41 } EmpathyConfPriv;
43 typedef struct {
44 EmpathyConf *conf;
45 EmpathyConfNotifyFunc func;
46 gpointer user_data;
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;
55 static void
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));
67 static void
68 empathy_conf_init (EmpathyConf *conf)
70 EmpathyConfPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (conf,
71 EMPATHY_TYPE_CONF, EmpathyConfPriv);
73 conf->priv = priv;
74 priv->gconf_client = gconf_client_get_default ();
76 gconf_client_add_dir (priv->gconf_client,
77 EMPATHY_CONF_ROOT,
78 GCONF_CLIENT_PRELOAD_ONELEVEL,
79 NULL);
80 gconf_client_add_dir (priv->gconf_client,
81 DESKTOP_INTERFACE_ROOT,
82 GCONF_CLIENT_PRELOAD_NONE,
83 NULL);
86 static void
87 conf_finalize (GObject *object)
89 EmpathyConfPriv *priv;
91 priv = GET_PRIV (object);
93 gconf_client_remove_dir (priv->gconf_client,
94 EMPATHY_CONF_ROOT,
95 NULL);
96 gconf_client_remove_dir (priv->gconf_client,
97 DESKTOP_INTERFACE_ROOT,
98 NULL);
100 g_object_unref (priv->gconf_client);
102 G_OBJECT_CLASS (empathy_conf_parent_class)->finalize (object);
105 EmpathyConf *
106 empathy_conf_get (void)
108 if (!global_conf) {
109 global_conf = g_object_new (EMPATHY_TYPE_CONF, NULL);
112 return global_conf;
115 void
116 empathy_conf_shutdown (void)
118 if (global_conf) {
119 g_object_unref (global_conf);
120 global_conf = NULL;
124 gboolean
125 empathy_conf_set_int (EmpathyConf *conf,
126 const gchar *key,
127 gint value)
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,
138 key,
139 value,
140 NULL);
143 gboolean
144 empathy_conf_get_int (EmpathyConf *conf,
145 const gchar *key,
146 gint *value)
148 EmpathyConfPriv *priv;
149 GError *error = NULL;
151 *value = 0;
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,
159 key,
160 &error);
162 if (error) {
163 g_error_free (error);
164 return FALSE;
167 return TRUE;
170 gboolean
171 empathy_conf_set_bool (EmpathyConf *conf,
172 const gchar *key,
173 gboolean value)
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,
185 key,
186 value,
187 NULL);
190 gboolean
191 empathy_conf_get_bool (EmpathyConf *conf,
192 const gchar *key,
193 gboolean *value)
195 EmpathyConfPriv *priv;
196 GError *error = NULL;
198 *value = FALSE;
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,
206 key,
207 &error);
209 if (error) {
210 g_error_free (error);
211 return FALSE;
214 return TRUE;
217 gboolean
218 empathy_conf_set_string (EmpathyConf *conf,
219 const gchar *key,
220 const gchar *value)
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,
231 key,
232 value,
233 NULL);
236 gboolean
237 empathy_conf_get_string (EmpathyConf *conf,
238 const gchar *key,
239 gchar **value)
241 EmpathyConfPriv *priv;
242 GError *error = NULL;
244 *value = 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,
251 key,
252 &error);
254 if (error) {
255 g_error_free (error);
256 return FALSE;
259 return TRUE;
262 gboolean
263 empathy_conf_set_string_list (EmpathyConf *conf,
264 const gchar *key,
265 GSList *value)
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,
274 key,
275 GCONF_VALUE_STRING,
276 value,
277 NULL);
280 gboolean
281 empathy_conf_get_string_list (EmpathyConf *conf,
282 const gchar *key,
283 GSList **value)
285 EmpathyConfPriv *priv;
286 GError *error = NULL;
288 *value = 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,
295 key,
296 GCONF_VALUE_STRING,
297 &error);
298 if (error) {
299 g_error_free (error);
300 return FALSE;
303 return TRUE;
306 static void
307 conf_notify_data_free (EmpathyConfNotifyData *data)
309 g_object_unref (data->conf);
310 g_slice_free (EmpathyConfNotifyData, data);
313 static void
314 conf_notify_func (GConfClient *client,
315 guint id,
316 GConfEntry *entry,
317 gpointer user_data)
319 EmpathyConfNotifyData *data;
321 data = user_data;
323 data->func (data->conf,
324 gconf_entry_get_key (entry),
325 data->user_data);
328 guint
329 empathy_conf_notify_add (EmpathyConf *conf,
330 const gchar *key,
331 EmpathyConfNotifyFunc func,
332 gpointer user_data)
334 EmpathyConfPriv *priv;
335 guint id;
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);
343 data->func = func;
344 data->user_data = user_data;
345 data->conf = g_object_ref (conf);
347 id = gconf_client_notify_add (priv->gconf_client,
348 key,
349 conf_notify_func,
350 data,
351 (GFreeFunc) conf_notify_data_free,
352 NULL);
354 return id;
357 gboolean
358 empathy_conf_notify_remove (EmpathyConf *conf,
359 guint id)
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);
369 return TRUE;