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