]> git.0d.be Git - empathy.git/blob - libempathy/empathy-contact-list.c
Completely reworked ContactList API. Fixes bug #471611, bug #467280, bug #459540...
[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 Collabora Ltd.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program 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  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  *
20  * Authors: Xavier Claessens <xclaesse@gmail.com>
21  */
22
23 #include "config.h"
24
25 #include "empathy-contact-list.h"
26 #include "empathy-marshal.h"
27
28 static void contact_list_base_init (gpointer klass);
29
30 GType
31 empathy_contact_list_get_type (void)
32 {
33         static GType type = 0;
34
35         if (!type) {
36                 static const GTypeInfo type_info = {
37                         sizeof (EmpathyContactListIface),
38                         contact_list_base_init,
39                         NULL,
40                 };
41
42                 type = g_type_register_static (G_TYPE_INTERFACE,
43                                                "EmpathyContactList",
44                                                &type_info, 0);
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 ("members-changed",
57                               G_TYPE_FROM_CLASS (klass),
58                               G_SIGNAL_RUN_LAST,
59                               0,
60                               NULL, NULL,
61                               empathy_marshal_VOID__OBJECT_OBJECT_UINT_STRING_BOOLEAN,
62                               G_TYPE_NONE,
63                               5, EMPATHY_TYPE_CONTACT, EMPATHY_TYPE_CONTACT,
64                               G_TYPE_UINT, G_TYPE_STRING, G_TYPE_BOOLEAN);
65
66                 g_signal_new ("pendings-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 ("groups-changed",
77                               G_TYPE_FROM_CLASS (klass),
78                               G_SIGNAL_RUN_LAST,
79                               0,
80                               NULL, NULL,
81                               empathy_marshal_VOID__OBJECT_STRING_BOOLEAN,
82                               G_TYPE_NONE,
83                               3, EMPATHY_TYPE_CONTACT, G_TYPE_STRING, G_TYPE_BOOLEAN);
84
85                 initialized = TRUE;
86         }
87 }
88
89 void
90 empathy_contact_list_add (EmpathyContactList *list,
91                           EmpathyContact     *contact,
92                           const gchar        *message)
93 {
94         g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list));
95         g_return_if_fail (EMPATHY_IS_CONTACT (contact));
96
97         if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->add) {
98                 EMPATHY_CONTACT_LIST_GET_IFACE (list)->add (list, contact, message);
99         }
100 }
101
102 void
103 empathy_contact_list_remove (EmpathyContactList *list,
104                              EmpathyContact     *contact,
105                              const gchar        *message)
106 {
107         g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list));
108         g_return_if_fail (EMPATHY_IS_CONTACT (contact));
109
110         if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->remove) {
111                 EMPATHY_CONTACT_LIST_GET_IFACE (list)->remove (list, contact, message);
112         }
113 }
114
115 GList *
116 empathy_contact_list_get_members (EmpathyContactList *list)
117 {
118         g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
119
120         if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_members) {
121                 return EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_members (list);
122         }
123
124         return NULL;
125 }
126
127 GList *
128 empathy_contact_list_get_pendings (EmpathyContactList *list)
129 {
130         g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
131
132         if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_pendings) {
133                 return EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_pendings (list);
134         }
135
136         return NULL;
137 }
138
139 GList *
140 empathy_contact_list_get_all_groups (EmpathyContactList *list)
141 {
142         g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
143
144         if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_all_groups) {
145                 return EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_all_groups (list);
146         }
147
148         return NULL;
149 }
150
151 GList *
152 empathy_contact_list_get_groups (EmpathyContactList *list,
153                                  EmpathyContact     *contact)
154 {
155         g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
156         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
157
158         if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_groups) {
159                 return EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_groups (list, contact);
160         }
161
162         return NULL;
163 }
164
165 void
166 empathy_contact_list_add_to_group (EmpathyContactList *list,
167                                    EmpathyContact     *contact,
168                                    const gchar        *group)
169 {
170         g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list));
171         g_return_if_fail (EMPATHY_IS_CONTACT (contact));
172         g_return_if_fail (group != NULL);
173
174         if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->add_to_group) {
175                 EMPATHY_CONTACT_LIST_GET_IFACE (list)->add_to_group (list, contact, group);
176         }
177 }
178
179 void
180 empathy_contact_list_remove_from_group (EmpathyContactList *list,
181                                         EmpathyContact     *contact,
182                                         const gchar        *group)
183 {
184         g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list));
185         g_return_if_fail (EMPATHY_IS_CONTACT (contact));
186         g_return_if_fail (group != NULL);
187
188         if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->remove_from_group) {
189                 EMPATHY_CONTACT_LIST_GET_IFACE (list)->remove_from_group (list, contact, group);
190         }
191 }
192
193 void
194 empathy_contact_list_rename_group (EmpathyContactList *list,
195                                    const gchar        *old_group,
196                                    const gchar        *new_group)
197 {
198         g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list));
199         g_return_if_fail (old_group != NULL);
200         g_return_if_fail (new_group != NULL);
201
202         if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->rename_group) {
203                 EMPATHY_CONTACT_LIST_GET_IFACE (list)->rename_group (list, old_group, new_group);
204         }
205 }
206