1 /* * Copyright (C) 2009 Collabora Ltd.
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 * Authors: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
23 #include <libnotify/notification.h>
24 #include <libnotify/notify.h>
26 #include <libempathy/empathy-utils.h>
28 #include <libempathy-gtk/empathy-ui-utils.h>
29 #include <libempathy-gtk/empathy-conf.h>
31 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
32 #include <libempathy/empathy-debug.h>
34 #include "empathy-notify-manager.h"
36 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyNotifyManager)
40 /* owned (gchar *) => TRUE */
41 GHashTable *capabilities;
42 } EmpathyNotifyManagerPriv;
44 G_DEFINE_TYPE (EmpathyNotifyManager, empathy_notify_manager, G_TYPE_OBJECT);
46 static EmpathyNotifyManager *notify_manager = NULL;
49 notify_manager_constructor (GType type,
50 guint n_construct_params,
51 GObjectConstructParam *construct_params)
55 if (notify_manager != NULL)
56 return g_object_ref (notify_manager);
58 retval = G_OBJECT_CLASS (empathy_notify_manager_parent_class)->constructor
59 (type, n_construct_params, construct_params);
61 notify_manager = EMPATHY_NOTIFY_MANAGER (retval);
62 g_object_add_weak_pointer (retval, (gpointer) ¬ify_manager);
68 notify_manager_finalize (GObject *object)
70 EmpathyNotifyManagerPriv *priv = GET_PRIV (object);
72 g_hash_table_destroy (priv->capabilities);
74 G_OBJECT_CLASS (empathy_notify_manager_parent_class)->finalize (object);
78 empathy_notify_manager_class_init (EmpathyNotifyManagerClass *klass)
80 GObjectClass *object_class = G_OBJECT_CLASS (klass);
82 object_class->finalize = notify_manager_finalize;
83 object_class->constructor = notify_manager_constructor;
85 g_type_class_add_private (object_class, sizeof (EmpathyNotifyManagerPriv));
89 empathy_notify_manager_init (EmpathyNotifyManager *self)
91 EmpathyNotifyManagerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
92 EMPATHY_TYPE_NOTIFY_MANAGER, EmpathyNotifyManagerPriv);
97 priv->capabilities = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
100 /* fetch capabilities */
101 list = notify_get_server_caps ();
102 for (l = list; l != NULL; l = g_list_next (l))
104 gchar *cap = l->data;
106 DEBUG ("add capability: %s", cap);
107 /* owernship of the string is transfered to the hash table */
108 g_hash_table_insert (priv->capabilities, cap, GUINT_TO_POINTER (TRUE));
113 EmpathyNotifyManager *
114 empathy_notify_manager_dup_singleton (void)
116 return g_object_new (EMPATHY_TYPE_NOTIFY_MANAGER, NULL);
120 empathy_notify_manager_has_capability (EmpathyNotifyManager *self,
123 EmpathyNotifyManagerPriv *priv = GET_PRIV (self);
125 return g_hash_table_lookup (priv->capabilities, cap) != NULL;
129 empathy_notify_manager_get_pixbuf_for_notification (EmpathyNotifyManager *self,
130 EmpathyContact *contact,
131 const char *icon_name)
133 GdkPixbuf *pixbuf = NULL;
136 pixbuf = empathy_pixbuf_avatar_from_contact_scaled (contact, 48, 48);
139 pixbuf = empathy_pixbuf_from_icon_name_sized (icon_name, 48);
145 empathy_notify_manager_notification_is_enabled (EmpathyNotifyManager *self)
150 conf = empathy_conf_get ();
153 empathy_conf_get_bool (conf, EMPATHY_PREFS_NOTIFICATIONS_ENABLED, &res);
158 if (!empathy_check_available_state ())
160 empathy_conf_get_bool (conf, EMPATHY_PREFS_NOTIFICATIONS_DISABLED_AWAY,