fixed a crash when creating account
[empathy-mirror.git] / libempathy / empathy-contact-list.c
blobd4859210a6508e3dab49d40d9bf55d710a8a5167
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * Copyright (C) 2007-2008 Collabora Ltd.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library 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 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Authors: Xavier Claessens <xclaesse@gmail.com>
22 #include "config.h"
24 #include "empathy-contact-list.h"
25 #include "empathy-marshal.h"
27 static void contact_list_base_init (gpointer klass);
29 GType
30 empathy_contact_list_get_type (void)
32 static GType type = 0;
34 if (!type) {
35 static const GTypeInfo type_info = {
36 sizeof (EmpathyContactListIface),
37 contact_list_base_init,
38 NULL,
41 type = g_type_register_static (G_TYPE_INTERFACE,
42 "EmpathyContactList",
43 &type_info, 0);
45 g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
48 return type;
51 static void
52 contact_list_base_init (gpointer klass)
54 static gboolean initialized = FALSE;
56 if (!initialized) {
57 g_signal_new ("member-renamed",
58 G_TYPE_FROM_CLASS (klass),
59 G_SIGNAL_RUN_LAST,
61 NULL, NULL,
62 _empathy_marshal_VOID__OBJECT_OBJECT_UINT_STRING,
63 G_TYPE_NONE,
64 4, EMPATHY_TYPE_CONTACT, EMPATHY_TYPE_CONTACT, G_TYPE_UINT, G_TYPE_STRING);
66 g_signal_new ("members-changed",
67 G_TYPE_FROM_CLASS (klass),
68 G_SIGNAL_RUN_LAST,
70 NULL, NULL,
71 _empathy_marshal_VOID__OBJECT_OBJECT_UINT_STRING_BOOLEAN,
72 G_TYPE_NONE,
73 5, EMPATHY_TYPE_CONTACT, EMPATHY_TYPE_CONTACT,
74 G_TYPE_UINT, G_TYPE_STRING, G_TYPE_BOOLEAN);
76 g_signal_new ("pendings-changed",
77 G_TYPE_FROM_CLASS (klass),
78 G_SIGNAL_RUN_LAST,
80 NULL, NULL,
81 _empathy_marshal_VOID__OBJECT_OBJECT_UINT_STRING_BOOLEAN,
82 G_TYPE_NONE,
83 5, EMPATHY_TYPE_CONTACT, EMPATHY_TYPE_CONTACT,
84 G_TYPE_UINT, G_TYPE_STRING, G_TYPE_BOOLEAN);
86 g_signal_new ("groups-changed",
87 G_TYPE_FROM_CLASS (klass),
88 G_SIGNAL_RUN_LAST,
90 NULL, NULL,
91 _empathy_marshal_VOID__OBJECT_STRING_BOOLEAN,
92 G_TYPE_NONE,
93 3, EMPATHY_TYPE_CONTACT, G_TYPE_STRING, G_TYPE_BOOLEAN);
95 initialized = TRUE;
99 void
100 empathy_contact_list_add (EmpathyContactList *list,
101 EmpathyContact *contact,
102 const gchar *message)
104 g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list));
105 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
107 if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->add) {
108 EMPATHY_CONTACT_LIST_GET_IFACE (list)->add (list, contact, message);
112 void
113 empathy_contact_list_remove (EmpathyContactList *list,
114 EmpathyContact *contact,
115 const gchar *message)
117 g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list));
118 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
120 if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->remove) {
121 EMPATHY_CONTACT_LIST_GET_IFACE (list)->remove (list, contact, message);
125 GList *
126 empathy_contact_list_get_members (EmpathyContactList *list)
128 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
130 if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_members) {
131 return EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_members (list);
134 return NULL;
137 EmpathyContactMonitor *
138 empathy_contact_list_get_monitor (EmpathyContactList *list)
140 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
142 if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_monitor) {
143 return EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_monitor (list);
146 return NULL;
149 GList *
150 empathy_contact_list_get_pendings (EmpathyContactList *list)
152 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
154 if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_pendings) {
155 return EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_pendings (list);
158 return NULL;
161 GList *
162 empathy_contact_list_get_all_groups (EmpathyContactList *list)
164 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
166 if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_all_groups) {
167 return EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_all_groups (list);
170 return NULL;
173 GList *
174 empathy_contact_list_get_groups (EmpathyContactList *list,
175 EmpathyContact *contact)
177 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
178 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
180 if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_groups) {
181 return EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_groups (list, contact);
184 return NULL;
187 void
188 empathy_contact_list_add_to_group (EmpathyContactList *list,
189 EmpathyContact *contact,
190 const gchar *group)
192 g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list));
193 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
194 g_return_if_fail (group != NULL);
196 if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->add_to_group) {
197 EMPATHY_CONTACT_LIST_GET_IFACE (list)->add_to_group (list, contact, group);
201 void
202 empathy_contact_list_remove_from_group (EmpathyContactList *list,
203 EmpathyContact *contact,
204 const gchar *group)
206 g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list));
207 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
208 g_return_if_fail (group != NULL);
210 if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->remove_from_group) {
211 EMPATHY_CONTACT_LIST_GET_IFACE (list)->remove_from_group (list, contact, group);
215 void
216 empathy_contact_list_rename_group (EmpathyContactList *list,
217 const gchar *old_group,
218 const gchar *new_group)
220 g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list));
221 g_return_if_fail (old_group != NULL);
222 g_return_if_fail (new_group != NULL);
224 if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->rename_group) {
225 EMPATHY_CONTACT_LIST_GET_IFACE (list)->rename_group (list, old_group, new_group);
229 void
230 empathy_contact_list_remove_group (EmpathyContactList *list,
231 const gchar *group)
233 g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list));
234 g_return_if_fail (group != NULL);
236 if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->remove_group) {
237 EMPATHY_CONTACT_LIST_GET_IFACE (list)->remove_group (list, group);
241 EmpathyContactListFlags
242 empathy_contact_list_get_flags (EmpathyContactList *list)
244 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), 0);
246 if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_flags) {
247 return EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_flags (list);
248 } else {
249 return 0;