]> git.0d.be Git - empathy.git/blob - libempathy/empathy-contact-list.c
Merge branch 'sasl'
[empathy.git] / libempathy / empathy-contact-list.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2007-2008 Collabora Ltd.
4  *
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.
9  *
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.
14  *
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
18  *
19  * Authors: Xavier Claessens <xclaesse@gmail.com>
20  */
21
22 #include "config.h"
23
24 #include "empathy-contact-list.h"
25 #include "empathy-marshal.h"
26
27 static void contact_list_base_init (gpointer klass);
28
29 GType
30 empathy_contact_list_get_type (void)
31 {
32         static GType type = 0;
33
34         if (!type) {
35                 static const GTypeInfo type_info = {
36                         sizeof (EmpathyContactListIface),
37                         contact_list_base_init,
38                         NULL,
39                 };
40
41                 type = g_type_register_static (G_TYPE_INTERFACE,
42                                                "EmpathyContactList",
43                                                &type_info, 0);
44
45                 g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
46         }
47
48         return type;
49 }
50
51 static void
52 contact_list_base_init (gpointer klass)
53 {
54         static gboolean initialized = FALSE;
55
56         if (!initialized) {
57                 g_signal_new ("member-renamed",
58                               G_TYPE_FROM_CLASS (klass),
59                               G_SIGNAL_RUN_LAST,
60                               0,
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);
65
66                 g_signal_new ("members-changed",
67                               G_TYPE_FROM_CLASS (klass),
68                               G_SIGNAL_RUN_LAST,
69                               0,
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);
75
76                 g_signal_new ("favourites-changed",
77                               G_TYPE_FROM_CLASS (klass),
78                               G_SIGNAL_RUN_LAST,
79                               0,
80                               NULL, NULL,
81                               _empathy_marshal_VOID__OBJECT_BOOLEAN,
82                               G_TYPE_NONE,
83                               2, EMPATHY_TYPE_CONTACT, G_TYPE_BOOLEAN);
84
85                 g_signal_new ("pendings-changed",
86                               G_TYPE_FROM_CLASS (klass),
87                               G_SIGNAL_RUN_LAST,
88                               0,
89                               NULL, NULL,
90                               _empathy_marshal_VOID__OBJECT_OBJECT_UINT_STRING_BOOLEAN,
91                               G_TYPE_NONE,
92                               5, EMPATHY_TYPE_CONTACT, EMPATHY_TYPE_CONTACT,
93                               G_TYPE_UINT, G_TYPE_STRING, G_TYPE_BOOLEAN);
94
95                 g_signal_new ("groups-changed",
96                               G_TYPE_FROM_CLASS (klass),
97                               G_SIGNAL_RUN_LAST,
98                               0,
99                               NULL, NULL,
100                               _empathy_marshal_VOID__OBJECT_STRING_BOOLEAN,
101                               G_TYPE_NONE,
102                               3, EMPATHY_TYPE_CONTACT, G_TYPE_STRING, G_TYPE_BOOLEAN);
103
104                 initialized = TRUE;
105         }
106 }
107
108 void
109 empathy_contact_list_add (EmpathyContactList *list,
110                           EmpathyContact     *contact,
111                           const gchar        *message)
112 {
113         g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list));
114         g_return_if_fail (EMPATHY_IS_CONTACT (contact));
115
116         if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->add) {
117                 EMPATHY_CONTACT_LIST_GET_IFACE (list)->add (list, contact, message);
118         }
119 }
120
121 void
122 empathy_contact_list_remove (EmpathyContactList *list,
123                              EmpathyContact     *contact,
124                              const gchar        *message)
125 {
126         g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list));
127         g_return_if_fail (EMPATHY_IS_CONTACT (contact));
128
129         if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->remove) {
130                 EMPATHY_CONTACT_LIST_GET_IFACE (list)->remove (list, contact, message);
131         }
132 }
133
134 GList *
135 empathy_contact_list_get_members (EmpathyContactList *list)
136 {
137         g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
138
139         if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_members) {
140                 return EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_members (list);
141         }
142
143         return NULL;
144 }
145
146 GList *
147 empathy_contact_list_get_pendings (EmpathyContactList *list)
148 {
149         g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
150
151         if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_pendings) {
152                 return EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_pendings (list);
153         }
154
155         return NULL;
156 }
157
158 GList *
159 empathy_contact_list_get_all_groups (EmpathyContactList *list)
160 {
161         g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
162
163         if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_all_groups) {
164                 return EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_all_groups (list);
165         }
166
167         return NULL;
168 }
169
170 GList *
171 empathy_contact_list_get_groups (EmpathyContactList *list,
172                                  EmpathyContact     *contact)
173 {
174         g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
175         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
176
177         if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_groups) {
178                 return EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_groups (list, contact);
179         }
180
181         return NULL;
182 }
183
184 void
185 empathy_contact_list_add_to_group (EmpathyContactList *list,
186                                    EmpathyContact     *contact,
187                                    const gchar        *group)
188 {
189         g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list));
190         g_return_if_fail (EMPATHY_IS_CONTACT (contact));
191         g_return_if_fail (group != NULL);
192
193         if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->add_to_group) {
194                 EMPATHY_CONTACT_LIST_GET_IFACE (list)->add_to_group (list, contact, group);
195         }
196 }
197
198 void
199 empathy_contact_list_remove_from_group (EmpathyContactList *list,
200                                         EmpathyContact     *contact,
201                                         const gchar        *group)
202 {
203         g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list));
204         g_return_if_fail (EMPATHY_IS_CONTACT (contact));
205         g_return_if_fail (group != NULL);
206
207         if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->remove_from_group) {
208                 EMPATHY_CONTACT_LIST_GET_IFACE (list)->remove_from_group (list, contact, group);
209         }
210 }
211
212 void
213 empathy_contact_list_rename_group (EmpathyContactList *list,
214                                    const gchar        *old_group,
215                                    const gchar        *new_group)
216 {
217         g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list));
218         g_return_if_fail (old_group != NULL);
219         g_return_if_fail (new_group != NULL);
220
221         if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->rename_group) {
222                 EMPATHY_CONTACT_LIST_GET_IFACE (list)->rename_group (list, old_group, new_group);
223         }
224 }
225
226 void
227 empathy_contact_list_remove_group (EmpathyContactList *list,
228                                    const gchar *group)
229 {
230         g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list));
231         g_return_if_fail (group != NULL);
232
233         if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->remove_group) {
234                 EMPATHY_CONTACT_LIST_GET_IFACE (list)->remove_group (list, group);
235         }
236 }
237
238 EmpathyContactListFlags
239 empathy_contact_list_get_flags (EmpathyContactList *list)
240 {
241         g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), 0);
242
243         if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_flags) {
244                 return EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_flags (list);
245         } else {
246                 return 0;
247         }
248 }
249
250 gboolean
251 empathy_contact_list_is_favourite (EmpathyContactList *list,
252                                    EmpathyContact     *contact)
253 {
254         if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->is_favourite) {
255                 return EMPATHY_CONTACT_LIST_GET_IFACE (list)->is_favourite (
256                         list, contact);
257         }
258
259         return FALSE;
260 }
261
262 void
263 empathy_contact_list_add_to_favourites (EmpathyContactList *list,
264                                         EmpathyContact     *contact)
265 {
266         if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->add_favourite) {
267                 EMPATHY_CONTACT_LIST_GET_IFACE (list)->add_favourite (list,
268                         contact);
269         }
270 }
271
272 void
273 empathy_contact_list_remove_from_favourites (EmpathyContactList *list,
274                                              EmpathyContact     *contact)
275 {
276         if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->remove_favourite) {
277                 EMPATHY_CONTACT_LIST_GET_IFACE (list)->remove_favourite (list,
278                         contact);
279         }
280 }