1 /*
2  * group-mixin.h - Header for TpGroupMixin
3  * Copyright (C) 2006-2007 Collabora Ltd. <http://www.collabora.co.uk/>
4  * Copyright (C) 2006-2007 Nokia Corporation
5  *   @author Ole Andre Vadla Ravnaas <ole.andre.ravnaas@collabora.co.uk>
6  *   @author Robert McQueen <robert.mcqueen@collabora.co.uk>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22 
23 #if defined (TP_DISABLE_SINGLE_INCLUDE) && !defined (_TP_IN_META_HEADER) && !defined (_TP_COMPILATION)
24 #error "Only <telepathy-glib/telepathy-glib.h> and <telepathy-glib/telepathy-glib-dbus.h> can be included directly."
25 #endif
26 
27 #ifndef __TP_GROUP_MIXIN_H__
28 #define __TP_GROUP_MIXIN_H__
29 
30 #include <telepathy-glib/dbus-properties-mixin.h>
31 #include <telepathy-glib/handle-repo.h>
32 #include <telepathy-glib/svc-channel.h>
33 #include <telepathy-glib/util.h>
34 
35 G_BEGIN_DECLS
36 
37 typedef struct _TpGroupMixinClass TpGroupMixinClass;
38 typedef struct _TpGroupMixinClassPrivate TpGroupMixinClassPrivate;
39 
40 typedef struct _TpGroupMixin TpGroupMixin;
41 typedef struct _TpGroupMixinPrivate TpGroupMixinPrivate;
42 
43 /**
44  * TpGroupMixinAddMemberFunc:
45  * @obj: An object implementing the group interface with this mixin
46  * @handle: The handle of the contact to be added
47  * @message: A message to be sent if the protocol supports it
48  * @error: Used to return a Telepathy D-Bus error if %FALSE is returned
49  *
50  * Signature of the callback used to add a member to the group.
51  * This should perform the necessary operations in the underlying IM protocol
52  * to cause the member to be added.
53  *
54  * Returns: %TRUE on success, %FALSE with @error set on error
55  */
56 typedef gboolean (*TpGroupMixinAddMemberFunc) (GObject *obj,
57     TpHandle handle, const gchar *message, GError **error);
58 
59 /**
60  * TpGroupMixinRemMemberFunc:
61  * @obj: An object implementing the group interface with this mixin
62  * @handle: The handle of the contact to be removed
63  * @message: A message to be sent if the protocol supports it
64  * @error: Used to return a Telepathy D-Bus error if %FALSE is returned
65  *
66  * Signature of the callback used to remove a member from the group.
67  * This should perform the necessary operations in the underlying IM protocol
68  * to cause the member to be removed.
69  *
70  * Returns: %TRUE on success, %FALSE with @error set on error
71  */
72 typedef gboolean (*TpGroupMixinRemMemberFunc) (GObject *obj,
73     TpHandle handle, const gchar *message, GError **error);
74 
75 /**
76  * TpGroupMixinRemMemberWithReasonFunc:
77  * @obj: An object implementing the group interface with this mixin
78  * @handle: The handle of the contact to be removed
79  * @message: A message to be sent if the protocol supports it
80  * @reason: A #TpChannelGroupChangeReason indicating the reason
81  * @error: Used to return a Telepathy D-Bus error if %FALSE is returned
82  *
83  * Signature of the callback used to remove a member from the group.
84  * This should perform the necessary operations in the underlying IM protocol
85  * to cause the member to be removed.
86  *
87  * Set this with tp_group_mixin_class_set_remove_with_reason_func(), .
88  *
89  * Returns: %TRUE on success, %FALSE with @error set on error
90  */
91 typedef gboolean (*TpGroupMixinRemMemberWithReasonFunc) (GObject *obj,
92     TpHandle handle, const gchar *message, guint reason, GError **error);
93 
94 void tp_group_mixin_class_set_remove_with_reason_func (GObjectClass *cls,
95     TpGroupMixinRemMemberWithReasonFunc func);
96 
97 /**
98  * TpGroupMixin:
99  * @handle_repo: The connection's contact handle repository
100  * @self_handle: The local user's handle within this group, or 0 if none.
101  *  Set using tp_group_mixin_init() and tp_group_mixin_change_self_handle().
102  * @group_flags: This group's flags. Set using tp_group_mixin_change_flags();
103  *  defaults to 0.
104  * @members: The members of the group. Alter using
105  *  tp_group_mixin_change_members().
106  * @local_pending: Members awaiting the local user's approval to join the
107  *  group. Alter using tp_group_mixin_change_members().
108  * @remote_pending: Members awaiting remote (e.g. remote user or server)
109  *  approval to join the group. Alter using tp_group_mixin_change_members().
110  * @priv: Pointer to opaque private data
111  *
112  * Structure representing the group mixin as used in a particular class.
113  * To be placed in the implementation's instance structure.
114  *
115  * All fields should be considered read-only.
116  */
117 struct _TpGroupMixin {
118   TpHandleRepoIface *handle_repo;
119   TpHandle self_handle;
120 
121   TpChannelGroupFlags group_flags;
122 
123   TpHandleSet *members;
124   TpHandleSet *local_pending;
125   TpHandleSet *remote_pending;
126 
127   TpGroupMixinPrivate *priv;
128 };
129 
130 /**
131  * TpGroupMixinClass:
132  * @add_member: The add-member function that was passed to
133  *  tp_group_mixin_class_init()
134  * @remove_member: The remove-member function that was passed to
135  *  tp_group_mixin_class_init()
136  * @priv: Pointer to opaque private data
137  *
138  * Structure representing the group mixin as used in a particular class.
139  * To be placed in the implementation's class structure.
140  *
141  * Initialize this with tp_group_mixin_class_init().
142  *
143  * All fields should be considered read-only.
144  */
145 struct _TpGroupMixinClass {
146   TpGroupMixinAddMemberFunc add_member;
147   TpGroupMixinRemMemberFunc remove_member;
148   TpGroupMixinClassPrivate *priv;
149 };
150 
151 /* TYPE MACROS */
152 #define TP_GROUP_MIXIN_CLASS_OFFSET_QUARK \
153   (tp_group_mixin_class_get_offset_quark ())
154 #define TP_GROUP_MIXIN_CLASS_OFFSET(o) \
155   tp_mixin_class_get_offset (o, TP_GROUP_MIXIN_CLASS_OFFSET_QUARK)
156 #define TP_GROUP_MIXIN_CLASS(o) \
157   ((TpGroupMixinClass *) tp_mixin_offset_cast (o, \
158     TP_GROUP_MIXIN_CLASS_OFFSET (o)))
159 #define TP_HAS_GROUP_MIXIN_CLASS(cls) (TP_GROUP_MIXIN_CLASS_OFFSET (cls) != 0)
160 
161 #define TP_GROUP_MIXIN_OFFSET_QUARK (tp_group_mixin_get_offset_quark ())
162 #define TP_GROUP_MIXIN_OFFSET(o) \
163   tp_mixin_instance_get_offset (o, TP_GROUP_MIXIN_OFFSET_QUARK)
164 #define TP_GROUP_MIXIN(o) ((TpGroupMixin *) tp_mixin_offset_cast (o, \
165       TP_GROUP_MIXIN_OFFSET(o)))
166 #define TP_HAS_GROUP_MIXIN(o) (TP_GROUP_MIXIN_OFFSET (o) != 0)
167 
168 GQuark tp_group_mixin_class_get_offset_quark (void);
169 GQuark tp_group_mixin_get_offset_quark (void);
170 
171 void tp_group_mixin_class_init (GObjectClass *obj_cls,
172     glong offset, TpGroupMixinAddMemberFunc add_func,
173     TpGroupMixinRemMemberFunc rem_func);
174 void tp_group_mixin_class_allow_self_removal (GObjectClass *obj_cls);
175 
176 void tp_group_mixin_init (GObject *obj, glong offset,
177     TpHandleRepoIface *handle_repo, TpHandle self_handle);
178 void tp_group_mixin_finalize (GObject *obj);
179 
180 gboolean tp_group_mixin_get_self_handle (GObject *obj,
181     guint *ret, GError **error);
182 gboolean tp_group_mixin_get_group_flags (GObject *obj,
183     guint *ret, GError **error);
184 
185 gboolean tp_group_mixin_add_members (GObject *obj,
186     const GArray *contacts, const gchar *message, GError **error);
187 gboolean tp_group_mixin_remove_members (GObject *obj,
188     const GArray *contacts, const gchar *message, GError **error);
189 gboolean tp_group_mixin_remove_members_with_reason (GObject *obj,
190     const GArray *contacts, const gchar *message, guint reason,
191     GError **error);
192 
193 gboolean tp_group_mixin_get_members (GObject *obj,
194     GArray **ret, GError **error);
195 gboolean tp_group_mixin_get_local_pending_members (GObject *obj,
196     GArray **ret, GError **error);
197 gboolean tp_group_mixin_get_local_pending_members_with_info (GObject *obj,
198     GPtrArray **ret, GError **error);
199 gboolean tp_group_mixin_get_remote_pending_members (GObject *obj,
200     GArray **ret, GError **error);
201 gboolean tp_group_mixin_get_all_members (GObject *obj,
202     GArray **members, GArray **local_pending, GArray **remote_pending,
203     GError **error);
204 
205 gboolean tp_group_mixin_get_handle_owners (GObject *obj,
206     const GArray *handles, GArray **ret, GError **error);
207 
208 void tp_group_mixin_change_flags (GObject *obj,
209     TpChannelGroupFlags add, TpChannelGroupFlags del);
210 gboolean tp_group_mixin_change_members (GObject *obj,
211     const gchar *message, const TpIntset *add, const TpIntset *del,
212     const TpIntset *add_local_pending, const TpIntset *add_remote_pending,
213     TpHandle actor, TpChannelGroupChangeReason reason);
214 gboolean tp_group_mixin_change_members_detailed (GObject *obj,
215     const TpIntset *add, const TpIntset *del,
216     const TpIntset *add_local_pending, const TpIntset *add_remote_pending,
217     const GHashTable *details);
218 void tp_group_mixin_change_self_handle (GObject *obj,
219     TpHandle new_self_handle);
220 
221 void tp_group_mixin_add_handle_owner (GObject *obj,
222     TpHandle local_handle, TpHandle owner_handle);
223 void tp_group_mixin_add_handle_owners (GObject *obj,
224     GHashTable *local_to_owner_handle);
225 
226 void tp_group_mixin_get_dbus_property (GObject *object,
227     GQuark interface, GQuark name, GValue *value, gpointer unused);
228 void tp_group_mixin_init_dbus_properties (GObjectClass *cls);
229 
230 void tp_group_mixin_iface_init (gpointer g_iface, gpointer iface_data);
231 
232 void tp_external_group_mixin_init (GObject *obj, GObject *obj_with_mixin);
233 void tp_external_group_mixin_finalize (GObject *obj);
234 void tp_external_group_mixin_iface_init (gpointer g_iface,
235     gpointer iface_data);
236 
237 void tp_external_group_mixin_get_dbus_property (GObject *object,
238     GQuark interface, GQuark name, GValue *value, gpointer unused);
239 void tp_external_group_mixin_init_dbus_properties (GObjectClass *cls);
240 
241 G_END_DECLS
242 
243 #endif /* #ifndef __TP_GROUP_MIXIN_H__ */
244