From 61a627be9a0d353ee9fc4d8edecde948aab5d243 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Wed, 23 Jan 2008 13:16:06 +0000 Subject: Move empathy-conf to libempathy-gtk. libempathy do not depend directly on gconf anymore. svn path=/trunk/; revision=597 --- libempathy-gtk/Makefile.am | 2 + libempathy-gtk/empathy-avatar-chooser.c | 3 +- libempathy-gtk/empathy-chat-view.c | 2 +- libempathy-gtk/empathy-chat-window.c | 2 +- libempathy-gtk/empathy-chat.c | 2 +- libempathy-gtk/empathy-conf.c | 373 ++++++++++++++++++++++++++++++++ libempathy-gtk/empathy-conf.h | 87 ++++++++ libempathy-gtk/empathy-group-chat.c | 2 +- libempathy-gtk/empathy-main-window.c | 2 +- libempathy-gtk/empathy-preferences.c | 3 +- libempathy-gtk/empathy-spell.c | 2 +- libempathy-gtk/empathy-status-icon.c | 2 +- libempathy-gtk/empathy-theme-manager.c | 2 +- libempathy-gtk/empathy-theme.c | 2 +- 14 files changed, 474 insertions(+), 12 deletions(-) create mode 100644 libempathy-gtk/empathy-conf.c create mode 100644 libempathy-gtk/empathy-conf.h (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am index 721bd82e2..083065f81 100644 --- a/libempathy-gtk/Makefile.am +++ b/libempathy-gtk/Makefile.am @@ -15,6 +15,7 @@ libempathy_gtk_la_SOURCES = \ ephy-spinner.c ephy-spinner.h \ empathy-main-window.c \ empathy-status-icon.c \ + empathy-conf.c \ empathy-contact-widget.c \ empathy-contact-dialogs.c \ empathy-accounts-dialog.c \ @@ -69,6 +70,7 @@ libempathy_gtk_headers = \ empathy-images.h \ empathy-main-window.h \ empathy-status-icon.h \ + empathy-conf.h \ empathy-contact-widget.h \ empathy-contact-dialogs.h \ empathy-accounts-dialog.h \ diff --git a/libempathy-gtk/empathy-avatar-chooser.c b/libempathy-gtk/empathy-avatar-chooser.c index 348186a6c..ba557787c 100644 --- a/libempathy-gtk/empathy-avatar-chooser.c +++ b/libempathy-gtk/empathy-avatar-chooser.c @@ -30,9 +30,10 @@ #include #include -#include + #include "empathy-avatar-chooser.h" +#include "empathy-conf.h" #include "empathy-preferences.h" #include "empathy-ui-utils.h" diff --git a/libempathy-gtk/empathy-chat-view.c b/libempathy-gtk/empathy-chat-view.c index d6c85606f..f4ad7f316 100644 --- a/libempathy-gtk/empathy-chat-view.c +++ b/libempathy-gtk/empathy-chat-view.c @@ -44,10 +44,10 @@ #include #include -#include #include "empathy-chat-view.h" #include "empathy-chat.h" +#include "empathy-conf.h" #include "empathy-preferences.h" #include "empathy-theme-manager.h" #include "empathy-ui-utils.h" diff --git a/libempathy-gtk/empathy-chat-window.c b/libempathy-gtk/empathy-chat-window.c index b6409f6a8..5acddc1e6 100644 --- a/libempathy-gtk/empathy-chat-window.c +++ b/libempathy-gtk/empathy-chat-window.c @@ -43,7 +43,6 @@ #include #include #include -#include #include #include "empathy-chat-window.h" @@ -52,6 +51,7 @@ #include "empathy-contact-dialogs.h" #include "empathy-log-window.h" #include "empathy-new-chatroom-dialog.h" +#include "empathy-conf.h" #include "empathy-preferences.h" #include "empathy-private-chat.h" #include "empathy-group-chat.h" diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c index d07b84b07..fbdf6df44 100644 --- a/libempathy-gtk/empathy-chat.c +++ b/libempathy-gtk/empathy-chat.c @@ -40,12 +40,12 @@ #include #include #include -#include #include #include "empathy-chat.h" #include "empathy-chat-window.h" #include "empathy-geometry.h" +#include "empathy-conf.h" #include "empathy-preferences.h" #include "empathy-spell.h" #include "empathy-spell-dialog.h" diff --git a/libempathy-gtk/empathy-conf.c b/libempathy-gtk/empathy-conf.c new file mode 100644 index 000000000..1ec3feeb4 --- /dev/null +++ b/libempathy-gtk/empathy-conf.c @@ -0,0 +1,373 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2006 Imendio AB + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Authors: Richard Hult + */ + +#include "config.h" + +#include + +#include + +#include + +#include "empathy-conf.h" + +#define DEBUG_DOMAIN "Config" + +#define EMPATHY_CONF_ROOT "/apps/empathy" +#define DESKTOP_INTERFACE_ROOT "/desktop/gnome/interface" + +#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_CONF, EmpathyConfPriv)) + +typedef struct { + GConfClient *gconf_client; +} EmpathyConfPriv; + +typedef struct { + EmpathyConf *conf; + EmpathyConfNotifyFunc func; + gpointer user_data; +} EmpathyConfNotifyData; + +static void conf_finalize (GObject *object); + +G_DEFINE_TYPE (EmpathyConf, empathy_conf, G_TYPE_OBJECT); + +static EmpathyConf *global_conf = NULL; + +static void +empathy_conf_class_init (EmpathyConfClass *class) +{ + GObjectClass *object_class; + + object_class = G_OBJECT_CLASS (class); + + object_class->finalize = conf_finalize; + + g_type_class_add_private (object_class, sizeof (EmpathyConfPriv)); +} + +static void +empathy_conf_init (EmpathyConf *conf) +{ + EmpathyConfPriv *priv; + + priv = GET_PRIV (conf); + + priv->gconf_client = gconf_client_get_default (); + + gconf_client_add_dir (priv->gconf_client, + EMPATHY_CONF_ROOT, + GCONF_CLIENT_PRELOAD_ONELEVEL, + NULL); + gconf_client_add_dir (priv->gconf_client, + DESKTOP_INTERFACE_ROOT, + GCONF_CLIENT_PRELOAD_NONE, + NULL); +} + +static void +conf_finalize (GObject *object) +{ + EmpathyConfPriv *priv; + + priv = GET_PRIV (object); + + gconf_client_remove_dir (priv->gconf_client, + EMPATHY_CONF_ROOT, + NULL); + gconf_client_remove_dir (priv->gconf_client, + DESKTOP_INTERFACE_ROOT, + NULL); + + g_object_unref (priv->gconf_client); + + G_OBJECT_CLASS (empathy_conf_parent_class)->finalize (object); +} + +EmpathyConf * +empathy_conf_get (void) +{ + if (!global_conf) { + global_conf = g_object_new (EMPATHY_TYPE_CONF, NULL); + } + + return global_conf; +} + +void +empathy_conf_shutdown (void) +{ + if (global_conf) { + g_object_unref (global_conf); + global_conf = NULL; + } +} + +gboolean +empathy_conf_set_int (EmpathyConf *conf, + const gchar *key, + gint value) +{ + EmpathyConfPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_CONF (conf), FALSE); + + empathy_debug (DEBUG_DOMAIN, "Setting int:'%s' to %d", key, value); + + priv = GET_PRIV (conf); + + return gconf_client_set_int (priv->gconf_client, + key, + value, + NULL); +} + +gboolean +empathy_conf_get_int (EmpathyConf *conf, + const gchar *key, + gint *value) +{ + EmpathyConfPriv *priv; + GError *error = NULL; + + *value = 0; + + g_return_val_if_fail (EMPATHY_IS_CONF (conf), FALSE); + g_return_val_if_fail (value != NULL, FALSE); + + priv = GET_PRIV (conf); + + *value = gconf_client_get_int (priv->gconf_client, + key, + &error); + + if (error) { + g_error_free (error); + return FALSE; + } + + return TRUE; +} + +gboolean +empathy_conf_set_bool (EmpathyConf *conf, + const gchar *key, + gboolean value) +{ + EmpathyConfPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_CONF (conf), FALSE); + + empathy_debug (DEBUG_DOMAIN, "Setting bool:'%s' to %d ---> %s", + key, value, value ? "true" : "false"); + + priv = GET_PRIV (conf); + + return gconf_client_set_bool (priv->gconf_client, + key, + value, + NULL); +} + +gboolean +empathy_conf_get_bool (EmpathyConf *conf, + const gchar *key, + gboolean *value) +{ + EmpathyConfPriv *priv; + GError *error = NULL; + + *value = FALSE; + + g_return_val_if_fail (EMPATHY_IS_CONF (conf), FALSE); + g_return_val_if_fail (value != NULL, FALSE); + + priv = GET_PRIV (conf); + + *value = gconf_client_get_bool (priv->gconf_client, + key, + &error); + + if (error) { + g_error_free (error); + return FALSE; + } + + return TRUE; +} + +gboolean +empathy_conf_set_string (EmpathyConf *conf, + const gchar *key, + const gchar *value) +{ + EmpathyConfPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_CONF (conf), FALSE); + + empathy_debug (DEBUG_DOMAIN, "Setting string:'%s' to '%s'", + key, value); + + priv = GET_PRIV (conf); + + return gconf_client_set_string (priv->gconf_client, + key, + value, + NULL); +} + +gboolean +empathy_conf_get_string (EmpathyConf *conf, + const gchar *key, + gchar **value) +{ + EmpathyConfPriv *priv; + GError *error = NULL; + + *value = NULL; + + g_return_val_if_fail (EMPATHY_IS_CONF (conf), FALSE); + + priv = GET_PRIV (conf); + + *value = gconf_client_get_string (priv->gconf_client, + key, + &error); + + if (error) { + g_error_free (error); + return FALSE; + } + + return TRUE; +} + +gboolean +empathy_conf_set_string_list (EmpathyConf *conf, + const gchar *key, + GSList *value) +{ + EmpathyConfPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_CONF (conf), FALSE); + + priv = GET_PRIV (conf); + + return gconf_client_set_list (priv->gconf_client, + key, + GCONF_VALUE_STRING, + value, + NULL); +} + +gboolean +empathy_conf_get_string_list (EmpathyConf *conf, + const gchar *key, + GSList **value) +{ + EmpathyConfPriv *priv; + GError *error = NULL; + + *value = NULL; + + g_return_val_if_fail (EMPATHY_IS_CONF (conf), FALSE); + + priv = GET_PRIV (conf); + + *value = gconf_client_get_list (priv->gconf_client, + key, + GCONF_VALUE_STRING, + &error); + if (error) { + g_error_free (error); + return FALSE; + } + + return TRUE; +} + +static void +conf_notify_data_free (EmpathyConfNotifyData *data) +{ + g_object_unref (data->conf); + g_slice_free (EmpathyConfNotifyData, data); +} + +static void +conf_notify_func (GConfClient *client, + guint id, + GConfEntry *entry, + gpointer user_data) +{ + EmpathyConfNotifyData *data; + + data = user_data; + + data->func (data->conf, + gconf_entry_get_key (entry), + data->user_data); +} + +guint +empathy_conf_notify_add (EmpathyConf *conf, + const gchar *key, + EmpathyConfNotifyFunc func, + gpointer user_data) +{ + EmpathyConfPriv *priv; + guint id; + EmpathyConfNotifyData *data; + + g_return_val_if_fail (EMPATHY_IS_CONF (conf), 0); + + priv = GET_PRIV (conf); + + data = g_slice_new (EmpathyConfNotifyData); + data->func = func; + data->user_data = user_data; + data->conf = g_object_ref (conf); + + id = gconf_client_notify_add (priv->gconf_client, + key, + conf_notify_func, + data, + (GFreeFunc) conf_notify_data_free, + NULL); + + return id; +} + +gboolean +empathy_conf_notify_remove (EmpathyConf *conf, + guint id) +{ + EmpathyConfPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_CONF (conf), FALSE); + + priv = GET_PRIV (conf); + + gconf_client_notify_remove (priv->gconf_client, id); + + return TRUE; +} + diff --git a/libempathy-gtk/empathy-conf.h b/libempathy-gtk/empathy-conf.h new file mode 100644 index 000000000..7e8e60e25 --- /dev/null +++ b/libempathy-gtk/empathy-conf.h @@ -0,0 +1,87 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2006 Imendio AB + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __EMPATHY_CONF_H__ +#define __EMPATHY_CONF_H__ + +#include + +G_BEGIN_DECLS + +#define EMPATHY_TYPE_CONF (empathy_conf_get_type ()) +#define EMPATHY_CONF(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EMPATHY_TYPE_CONF, EmpathyConf)) +#define EMPATHY_CONF_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), EMPATHY_TYPE_CONF, EmpathyConfClass)) +#define EMPATHY_IS_CONF(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EMPATHY_TYPE_CONF)) +#define EMPATHY_IS_CONF_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_CONF)) +#define EMPATHY_CONF_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_CONF, EmpathyConfClass)) + +typedef struct _EmpathyConf EmpathyConf; +typedef struct _EmpathyConfClass EmpathyConfClass; + +struct _EmpathyConf { + GObject parent; +}; + +struct _EmpathyConfClass { + GObjectClass parent_class; +}; + +typedef void (*EmpathyConfNotifyFunc) (EmpathyConf *conf, + const gchar *key, + gpointer user_data); + +GType empathy_conf_get_type (void) G_GNUC_CONST; +EmpathyConf *empathy_conf_get (void); +void empathy_conf_shutdown (void); +guint empathy_conf_notify_add (EmpathyConf *conf, + const gchar *key, + EmpathyConfNotifyFunc func, + gpointer data); +gboolean empathy_conf_notify_remove (EmpathyConf *conf, + guint id); +gboolean empathy_conf_set_int (EmpathyConf *conf, + const gchar *key, + gint value); +gboolean empathy_conf_get_int (EmpathyConf *conf, + const gchar *key, + gint *value); +gboolean empathy_conf_set_bool (EmpathyConf *conf, + const gchar *key, + gboolean value); +gboolean empathy_conf_get_bool (EmpathyConf *conf, + const gchar *key, + gboolean *value); +gboolean empathy_conf_set_string (EmpathyConf *conf, + const gchar *key, + const gchar *value); +gboolean empathy_conf_get_string (EmpathyConf *conf, + const gchar *key, + gchar **value); +gboolean empathy_conf_set_string_list (EmpathyConf *conf, + const gchar *key, + GSList *value); +gboolean empathy_conf_get_string_list (EmpathyConf *conf, + const gchar *key, + GSList **value); + +G_END_DECLS + +#endif /* __EMPATHY_CONF_H__ */ + diff --git a/libempathy-gtk/empathy-group-chat.c b/libempathy-gtk/empathy-group-chat.c index 534f66c27..4f86ef2ba 100644 --- a/libempathy-gtk/empathy-group-chat.c +++ b/libempathy-gtk/empathy-group-chat.c @@ -40,7 +40,6 @@ #include #include #include -#include #include "empathy-group-chat.h" #include "empathy-chat.h" @@ -51,6 +50,7 @@ //#include "empathy-sound.h" #include "empathy-images.h" #include "empathy-ui-utils.h" +#include "empathy-conf.h" #include "empathy-preferences.h" #define DEBUG_DOMAIN "GroupChat" diff --git a/libempathy-gtk/empathy-main-window.c b/libempathy-gtk/empathy-main-window.c index 6b51eccad..951b80e95 100644 --- a/libempathy-gtk/empathy-main-window.c +++ b/libempathy-gtk/empathy-main-window.c @@ -28,7 +28,6 @@ #include #include -#include #include #include #include @@ -47,6 +46,7 @@ #include "empathy-presence-chooser.h" #include "empathy-ui-utils.h" #include "empathy-geometry.h" +#include "empathy-conf.h" #include "empathy-preferences.h" #include "empathy-accounts-dialog.h" #include "empathy-about-dialog.h" diff --git a/libempathy-gtk/empathy-preferences.c b/libempathy-gtk/empathy-preferences.c index d6e21a733..50c9d5660 100644 --- a/libempathy-gtk/empathy-preferences.c +++ b/libempathy-gtk/empathy-preferences.c @@ -30,8 +30,7 @@ #include #include -#include - +#include "empathy-conf.h" #include "empathy-preferences.h" #include "empathy-ui-utils.h" #include "empathy-theme-manager.h" diff --git a/libempathy-gtk/empathy-spell.c b/libempathy-gtk/empathy-spell.c index 88696cca3..b6620118a 100644 --- a/libempathy-gtk/empathy-spell.c +++ b/libempathy-gtk/empathy-spell.c @@ -33,9 +33,9 @@ #endif #include -#include #include "empathy-spell.h" +#include "empathy-conf.h" #include "empathy-preferences.h" #define DEBUG_DOMAIN "Spell" diff --git a/libempathy-gtk/empathy-status-icon.c b/libempathy-gtk/empathy-status-icon.c index 24132e655..9e62a1e18 100644 --- a/libempathy-gtk/empathy-status-icon.c +++ b/libempathy-gtk/empathy-status-icon.c @@ -35,13 +35,13 @@ #include #include #include -#include #include #include #include "empathy-status-icon.h" #include "empathy-contact-dialogs.h" #include "empathy-presence-chooser.h" +#include "empathy-conf.h" #include "empathy-preferences.h" #include "empathy-ui-utils.h" #include "empathy-accounts-dialog.h" diff --git a/libempathy-gtk/empathy-theme-manager.c b/libempathy-gtk/empathy-theme-manager.c index 6bece7506..94276c964 100644 --- a/libempathy-gtk/empathy-theme-manager.c +++ b/libempathy-gtk/empathy-theme-manager.c @@ -26,9 +26,9 @@ #include #include -#include #include "empathy-chat-view.h" +#include "empathy-conf.h" #include "empathy-preferences.h" #include "empathy-theme.h" #include "empathy-theme-boxes.h" diff --git a/libempathy-gtk/empathy-theme.c b/libempathy-gtk/empathy-theme.c index 1895b8ccb..c8a9a0d48 100644 --- a/libempathy-gtk/empathy-theme.c +++ b/libempathy-gtk/empathy-theme.c @@ -24,12 +24,12 @@ #include #include -#include #include #include #include #include "empathy-chat.h" +#include "empathy-conf.h" #include "empathy-preferences.h" #include "empathy-theme.h" #include "empathy-smiley-manager.h" -- cgit v1.2.3