]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-roster-model.c
3fd84b7fcfd4d7b82806f247796208e90a193008
[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   SIG_GROUPS_CHANGED,
31   LAST_SIGNAL
32 };
33
34 static guint signals[LAST_SIGNAL];
35
36 static void
37 empathy_roster_model_default_init (EmpathyRosterModelInterface *iface)
38 {
39   signals[SIG_INDIVIDUAL_ADDED] =
40     g_signal_new ("individual-added",
41         EMPATHY_TYPE_ROSTER_MODEL,
42         G_SIGNAL_RUN_LAST,
43         0, NULL, NULL, NULL,
44         G_TYPE_NONE, 1,
45         FOLKS_TYPE_INDIVIDUAL);
46
47   signals[SIG_INDIVIDUAL_REMOVED] =
48     g_signal_new ("individual-removed",
49         EMPATHY_TYPE_ROSTER_MODEL,
50         G_SIGNAL_RUN_LAST,
51         0, NULL, NULL, NULL,
52         G_TYPE_NONE, 1,
53         FOLKS_TYPE_INDIVIDUAL);
54
55   signals[SIG_GROUPS_CHANGED] =
56     g_signal_new ("groups-changed",
57         EMPATHY_TYPE_ROSTER_MODEL,
58         G_SIGNAL_RUN_LAST,
59         0, NULL, NULL, NULL,
60         G_TYPE_NONE, 3,
61         FOLKS_TYPE_INDIVIDUAL,
62         G_TYPE_STRING,
63         G_TYPE_BOOLEAN);
64 }
65
66 /***** Restricted *****/
67
68 void
69 empathy_roster_model_fire_individual_added (EmpathyRosterModel *self,
70     FolksIndividual *individual)
71 {
72   g_signal_emit (self, signals[SIG_INDIVIDUAL_ADDED], 0, individual);
73 }
74
75 void
76 empathy_roster_model_fire_individual_removed (EmpathyRosterModel *self,
77     FolksIndividual *individual)
78 {
79   g_signal_emit (self, signals[SIG_INDIVIDUAL_REMOVED], 0, individual);
80 }
81
82 void
83 empathy_roster_model_fire_groups_changed (EmpathyRosterModel *self,
84     FolksIndividual *individual,
85     const gchar *group,
86     gboolean is_member)
87 {
88   g_signal_emit (self, signals[SIG_GROUPS_CHANGED], 0, individual, group,
89       is_member);
90 }
91
92 /***** Public *****/
93
94 /**
95  * empathy_roster_model_get_individuals:
96  * @self: a #EmpathyRosterModel
97  *
98  * Returns all the individuals stored by @self.
99  *
100  * Returns: (transfer container): a #GList of #FolksIndividual
101  */
102 GList *
103 empathy_roster_model_get_individuals (EmpathyRosterModel *self)
104 {
105   EmpathyRosterModelInterface *iface;
106
107   g_return_val_if_fail (EMPATHY_IS_ROSTER_MODEL (self), NULL);
108
109   iface = EMPATHY_ROSTER_MODEL_GET_IFACE (self);
110   g_return_val_if_fail (iface->get_individuals != NULL, NULL);
111
112   return (* iface->get_individuals) (self);
113 }
114
115 /**
116  * empathy_roster_model_dup_groups_for_individual:
117  * @self: a #EmpathyRosterModel
118  * @individual: a #FolksIndidivual
119  *
120  * Returns the groups of which @individual is a member of.
121  *
122  * Returns: (transfer full): a #GList of (gchar *) representing the
123  * groups of @individual
124  */
125 GList *
126 empathy_roster_model_dup_groups_for_individual (EmpathyRosterModel *self,
127     FolksIndividual *individual)
128 {
129   EmpathyRosterModelInterface *iface;
130
131   g_return_val_if_fail (EMPATHY_IS_ROSTER_MODEL (self), NULL);
132
133   iface = EMPATHY_ROSTER_MODEL_GET_IFACE (self);
134   g_return_val_if_fail (iface->dup_groups_for_individual != NULL, NULL);
135
136   return (* iface->dup_groups_for_individual) (self, individual);
137 }