]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-roster-model.c
GNOME Goal: Update icon names
[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 #include "empathy-roster-model.h"
22
23 G_DEFINE_INTERFACE (EmpathyRosterModel, empathy_roster_model, G_TYPE_OBJECT)
24
25 enum
26 {
27   SIG_INDIVIDUAL_ADDED,
28   SIG_INDIVIDUAL_REMOVED,
29   SIG_GROUPS_CHANGED,
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   signals[SIG_GROUPS_CHANGED] =
55     g_signal_new ("groups-changed",
56         EMPATHY_TYPE_ROSTER_MODEL,
57         G_SIGNAL_RUN_LAST,
58         0, NULL, NULL, NULL,
59         G_TYPE_NONE, 3,
60         FOLKS_TYPE_INDIVIDUAL,
61         G_TYPE_STRING,
62         G_TYPE_BOOLEAN);
63 }
64
65 /***** Restricted *****/
66
67 void
68 empathy_roster_model_fire_individual_added (EmpathyRosterModel *self,
69     FolksIndividual *individual)
70 {
71   g_signal_emit (self, signals[SIG_INDIVIDUAL_ADDED], 0, individual);
72 }
73
74 void
75 empathy_roster_model_fire_individual_removed (EmpathyRosterModel *self,
76     FolksIndividual *individual)
77 {
78   g_signal_emit (self, signals[SIG_INDIVIDUAL_REMOVED], 0, individual);
79 }
80
81 void
82 empathy_roster_model_fire_groups_changed (EmpathyRosterModel *self,
83     FolksIndividual *individual,
84     const gchar *group,
85     gboolean is_member)
86 {
87   g_signal_emit (self, signals[SIG_GROUPS_CHANGED], 0, individual, group,
88       is_member);
89 }
90
91 /***** Public *****/
92
93 /**
94  * empathy_roster_model_get_individuals:
95  * @self: a #EmpathyRosterModel
96  *
97  * Returns all the individuals stored by @self.
98  *
99  * Returns: (transfer container): a #GList of #FolksIndividual
100  */
101 GList *
102 empathy_roster_model_get_individuals (EmpathyRosterModel *self)
103 {
104   EmpathyRosterModelInterface *iface;
105
106   g_return_val_if_fail (EMPATHY_IS_ROSTER_MODEL (self), NULL);
107
108   iface = EMPATHY_ROSTER_MODEL_GET_IFACE (self);
109   g_return_val_if_fail (iface->get_individuals != NULL, NULL);
110
111   return (* iface->get_individuals) (self);
112 }
113
114 /**
115  * empathy_roster_model_dup_groups_for_individual:
116  * @self: a #EmpathyRosterModel
117  * @individual: a #FolksIndidivual
118  *
119  * Returns the groups of which @individual is a member of.
120  *
121  * Returns: (transfer full): a #GList of (gchar *) representing the
122  * groups of @individual
123  */
124 GList *
125 empathy_roster_model_dup_groups_for_individual (EmpathyRosterModel *self,
126     FolksIndividual *individual)
127 {
128   EmpathyRosterModelInterface *iface;
129
130   g_return_val_if_fail (EMPATHY_IS_ROSTER_MODEL (self), NULL);
131
132   iface = EMPATHY_ROSTER_MODEL_GET_IFACE (self);
133   g_return_val_if_fail (iface->dup_groups_for_individual != NULL, NULL);
134
135   return (* iface->dup_groups_for_individual) (self, individual);
136 }