]> git.0d.be Git - empathy.git/blob - libempathy/empathy-contact-list.c
Add support for blinking when there is an event. Make use of EmpathyIdle
[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 ("contact-added",
57                               G_TYPE_FROM_CLASS (klass),
58                               G_SIGNAL_RUN_LAST,
59                               0,
60                               NULL, NULL,
61                               g_cclosure_marshal_VOID__OBJECT,
62                               G_TYPE_NONE,
63                               1, GOSSIP_TYPE_CONTACT);
64
65                 g_signal_new ("contact-removed",
66                               G_TYPE_FROM_CLASS (klass),
67                               G_SIGNAL_RUN_LAST,
68                               0,
69                               NULL, NULL,
70                               g_cclosure_marshal_VOID__OBJECT,
71                               G_TYPE_NONE,
72                               1, GOSSIP_TYPE_CONTACT);
73
74                 g_signal_new ("local-pending",
75                               G_TYPE_FROM_CLASS (klass),
76                               G_SIGNAL_RUN_LAST,
77                               0,
78                               NULL, NULL,
79                               empathy_marshal_VOID__OBJECT_STRING,
80                               G_TYPE_NONE,
81                               2, GOSSIP_TYPE_CONTACT, G_TYPE_STRING);
82
83                 initialized = TRUE;
84         }
85 }
86
87 EmpathyContactListInfo *
88 empathy_contact_list_info_new (GossipContact *contact,
89                                const gchar   *message)
90 {
91         EmpathyContactListInfo *info;
92
93         g_return_val_if_fail (GOSSIP_IS_CONTACT (contact), NULL);
94
95         info = g_slice_new0 (EmpathyContactListInfo);
96         info->contact = g_object_ref (contact);
97         info->message = g_strdup (message);
98
99         return info;
100 }                              
101
102 void
103 empathy_contact_list_info_free (EmpathyContactListInfo *info)
104 {
105         if (!info) {
106                 return;
107         }
108
109         if (info->contact) {
110                 g_object_unref (info->contact);
111         }
112         g_free (info->message);
113
114         g_slice_free (EmpathyContactListInfo, info);
115 }
116
117 void
118 empathy_contact_list_setup (EmpathyContactList *list)
119 {
120         g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list));
121
122         if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->setup) {
123                 EMPATHY_CONTACT_LIST_GET_IFACE (list)->setup (list);
124         }
125 }
126
127 GossipContact *
128 empathy_contact_list_find (EmpathyContactList *list,
129                            const gchar        *id)
130 {
131         g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
132
133         if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->find) {
134                 return EMPATHY_CONTACT_LIST_GET_IFACE (list)->find (list, id);
135         }
136
137         return NULL;
138 }
139
140 void
141 empathy_contact_list_add (EmpathyContactList *list,
142                           GossipContact      *contact,
143                           const gchar        *message)
144 {
145         g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list));
146
147         if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->add) {
148                 EMPATHY_CONTACT_LIST_GET_IFACE (list)->add (list, contact, message);
149         }
150 }
151
152 void
153 empathy_contact_list_remove (EmpathyContactList *list,
154                              GossipContact      *contact,
155                              const gchar        *message)
156 {
157         g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list));
158
159         if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->remove) {
160                 EMPATHY_CONTACT_LIST_GET_IFACE (list)->remove (list, contact, message);
161         }
162 }
163
164 GList *
165 empathy_contact_list_get_members (EmpathyContactList *list)
166 {
167         g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
168
169         if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_members) {
170                 return EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_members (list);
171         }
172
173         return NULL;
174 }
175
176 GList *
177 empathy_contact_list_get_local_pending (EmpathyContactList *list)
178 {
179         g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
180
181         if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_local_pending) {
182                 return EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_local_pending (list);
183         }
184
185         return NULL;
186 }
187