]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-roster-model.c
roster-model: add API to track individuals
[empathy.git] / libempathy-gtk / empathy-roster-model.c
1 /*
2  * empathy-roster-model.c
3  *
4  * Copyright (C) 2012 Collabora Ltd. <http://www.collabora.co.uk/>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20 #include "config.h"
21
22 #include "empathy-roster-model.h"
23
24 G_DEFINE_INTERFACE (EmpathyRosterModel, empathy_roster_model, G_TYPE_OBJECT)
25
26 enum
27 {
28   SIG_INDIVIDUAL_ADDED,
29   SIG_INDIVIDUAL_REMOVED,
30   LAST_SIGNAL
31 };
32
33 static guint signals[LAST_SIGNAL];
34
35 static void
36 empathy_roster_model_default_init (EmpathyRosterModelInterface *iface)
37 {
38   signals[SIG_INDIVIDUAL_ADDED] =
39     g_signal_new ("individual-added",
40         EMPATHY_TYPE_ROSTER_MODEL,
41         G_SIGNAL_RUN_LAST,
42         0, NULL, NULL, NULL,
43         G_TYPE_NONE, 1,
44         FOLKS_TYPE_INDIVIDUAL);
45
46   signals[SIG_INDIVIDUAL_REMOVED] =
47     g_signal_new ("individual-removed",
48         EMPATHY_TYPE_ROSTER_MODEL,
49         G_SIGNAL_RUN_LAST,
50         0, NULL, NULL, NULL,
51         G_TYPE_NONE, 1,
52         FOLKS_TYPE_INDIVIDUAL);
53 }
54
55 /***** Restricted *****/
56
57 void
58 empathy_roster_model_fire_individual_added (EmpathyRosterModel *self,
59     FolksIndividual *individual)
60 {
61   g_signal_emit (self, signals[SIG_INDIVIDUAL_ADDED], 0, individual);
62 }
63
64 void
65 empathy_roster_model_fire_individual_removed (EmpathyRosterModel *self,
66     FolksIndividual *individual)
67 {
68   g_signal_emit (self, signals[SIG_INDIVIDUAL_REMOVED], 0, individual);
69 }
70
71 /***** Public *****/
72
73 GList *
74 empathy_roster_model_get_individuals (EmpathyRosterModel *self)
75 {
76   EmpathyRosterModelInterface *iface;
77
78   g_return_val_if_fail (EMPATHY_IS_ROSTER_MODEL (self), NULL);
79
80   iface = EMPATHY_ROSTER_MODEL_GET_IFACE (self);
81   g_return_val_if_fail (iface->get_individuals != NULL, NULL);
82
83   return (* iface->get_individuals) (self);
84 }