]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-roster-model.c
Added new function _get_top_individuals in the model
[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, 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_get_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 container): a #GList of (const gchar *) representing the
122  * groups of @individual
123  */
124 GList *
125 empathy_roster_model_get_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->get_groups_for_individual != NULL, NULL);
134
135   return (* iface->get_groups_for_individual) (self, individual);
136 }
137
138 /**
139  * empathy_roster_model_get_top_individuals:
140  * @self: a #EmpathyRosterModel
141  *
142  * Returns a list of the top_individuals.
143  *
144  * Return value: (transfer none): a #GList of #FolksIndividual
145  */
146 GList *
147 empathy_roster_model_get_top_individuals (EmpathyRosterModel *self)
148 {
149   EmpathyRosterModelInterface *iface;
150
151   g_return_val_if_fail (EMPATHY_IS_ROSTER_MODEL (self), NULL);
152
153   iface = EMPATHY_ROSTER_MODEL_GET_IFACE (self);
154   g_return_val_if_fail (iface->get_top_individuals != NULL, NULL);
155
156   return (* iface->get_top_individuals) (self);
157 }