summaryrefslogtreecommitdiff
path: root/wocky/wocky-roster.h
blob: 6ca8d7a400b526a197ac88bd0c1282326a5dfc53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
 * wocky-roster.h - Header for WockyRoster
 * Copyright (C) 2009 Collabora Ltd.
 * @author Jonny Lamb <jonny.lamb@collabora.co.uk>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
#if !defined (WOCKY_H_INSIDE) && !defined (WOCKY_COMPILATION)
# error "Only <wocky/wocky.h> can be included directly."
#endif

#ifndef __WOCKY_ROSTER_H__
#define __WOCKY_ROSTER_H__

#include <glib-object.h>

#include "wocky-types.h"
#include "wocky-xmpp-connection.h"

G_BEGIN_DECLS

typedef struct _WockyRoster WockyRoster;

/**
 * WockyRosterClass:
 *
 * The class of a #WockyRoster.
 */
typedef struct _WockyRosterClass WockyRosterClass;
typedef struct _WockyRosterPrivate WockyRosterPrivate;

GQuark wocky_roster_error_quark (void);

struct _WockyRosterClass {
  /*<private>*/
  GObjectClass parent_class;
};

struct _WockyRoster {
  /*<private>*/
  GObject parent;

  WockyRosterPrivate *priv;
};

GType wocky_roster_get_type (void);

#define WOCKY_TYPE_ROSTER \
  (wocky_roster_get_type ())
#define WOCKY_ROSTER(obj) \
  (G_TYPE_CHECK_INSTANCE_CAST((obj), WOCKY_TYPE_ROSTER, \
   WockyRoster))
#define WOCKY_ROSTER_CLASS(klass) \
  (G_TYPE_CHECK_CLASS_CAST((klass), WOCKY_TYPE_ROSTER, \
   WockyRosterClass))
#define WOCKY_IS_ROSTER(obj) \
  (G_TYPE_CHECK_INSTANCE_TYPE((obj), WOCKY_TYPE_ROSTER))
#define WOCKY_IS_ROSTER_CLASS(klass) \
  (G_TYPE_CHECK_CLASS_TYPE((klass), WOCKY_TYPE_ROSTER))
#define WOCKY_ROSTER_GET_CLASS(obj) \
  (G_TYPE_INSTANCE_GET_CLASS ((obj), WOCKY_TYPE_ROSTER, \
   WockyRosterClass))

/**
 * WockyRosterSubscriptionFlags:
 * @WOCKY_ROSTER_SUBSCRIPTION_TYPE_NONE: the user does not have a
 *   subscription to the contact's presence information, and the
 *   contact does not have a subscription to the user's presence
 *   information
 * @WOCKY_ROSTER_SUBSCRIPTION_TYPE_TO: the user has a subscription to
 *   the contact's presence information, but the contact does not have
 *   a subscription to the user's presence information
 * @WOCKY_ROSTER_SUBSCRIPTION_TYPE_FROM: the contact has a
 *   subscription to the user's presence information, but the user
 *   does not have a subscription to the contact's presence
 *   information
 * @WOCKY_ROSTER_SUBSCRIPTION_TYPE_BOTH: both the user and the contact
 * have subscriptions to each other's presence information
 *
 * Flags to document the subscription information between contacts.
 */
typedef enum
{
  WOCKY_ROSTER_SUBSCRIPTION_TYPE_NONE = 0,
  WOCKY_ROSTER_SUBSCRIPTION_TYPE_TO   = 1 << 0,
  WOCKY_ROSTER_SUBSCRIPTION_TYPE_FROM = 1 << 1,
  WOCKY_ROSTER_SUBSCRIPTION_TYPE_BOTH =
    WOCKY_ROSTER_SUBSCRIPTION_TYPE_TO | WOCKY_ROSTER_SUBSCRIPTION_TYPE_FROM,
  /*< private >*/
  LAST_WOCKY_ROSTER_SUBSCRIPTION_TYPE = WOCKY_ROSTER_SUBSCRIPTION_TYPE_BOTH
} WockyRosterSubscriptionFlags;

/**
 * WockyRosterError:
 * @WOCKY_ROSTER_ERROR_INVALID_STANZA : received an invalid roster stanza
 * from the server
 * @WOCKY_ROSTER_ERROR_NOT_IN_ROSTER : the contact is not in the roster
 *
 * The #WockyRosterError specific errors.
 */
typedef enum {
  WOCKY_ROSTER_ERROR_INVALID_STANZA,
  WOCKY_ROSTER_ERROR_NOT_IN_ROSTER,
} WockyRosterError;

GQuark wocky_roster_error_quark (void);

/**
 * WOCKY_ROSTER_ERROR:
 *
 * Get access to the error quark of the roster.
 */
#define WOCKY_ROSTER_ERROR (wocky_roster_error_quark ())

WockyRoster * wocky_roster_new (WockySession *session);

void wocky_roster_fetch_roster_async (WockyRoster *self,
    GCancellable *cancellable, GAsyncReadyCallback callback,
    gpointer user_data);

gboolean wocky_roster_fetch_roster_finish (WockyRoster *self,
    GAsyncResult *result, GError **error);

WockyBareContact * wocky_roster_get_contact (WockyRoster *self,
    const gchar *jid);

GSList * wocky_roster_get_all_contacts (WockyRoster *self);

void wocky_roster_add_contact_async (WockyRoster *self,
    const gchar *jid,
    const gchar *name,
    const gchar * const * groups,
    GCancellable *cancellable,
    GAsyncReadyCallback callback,
    gpointer user_data);

gboolean wocky_roster_add_contact_finish (WockyRoster *self,
    GAsyncResult *result,
    GError **error);

void wocky_roster_remove_contact_async (WockyRoster *self,
    WockyBareContact *contact,
    GCancellable *cancellable,
    GAsyncReadyCallback callback,
    gpointer user_data);

gboolean wocky_roster_remove_contact_finish (WockyRoster *self,
    GAsyncResult *result,
    GError **error);

void wocky_roster_change_contact_name_async (WockyRoster *self,
    WockyBareContact *contact,
    const gchar *name,
    GCancellable *cancellable,
    GAsyncReadyCallback callback,
    gpointer user_data);

gboolean wocky_roster_change_contact_name_finish (WockyRoster *self,
    GAsyncResult *result,
    GError **error);

void wocky_roster_contact_add_group_async (WockyRoster *self,
    WockyBareContact *contact,
    const gchar *group,
    GCancellable *cancellable,
    GAsyncReadyCallback callback,
    gpointer user_data);

gboolean wocky_roster_contact_add_group_finish (WockyRoster *self,
    GAsyncResult *result,
    GError **error);

void wocky_roster_contact_remove_group_async (WockyRoster *self,
    WockyBareContact *contact,
    const gchar *group,
    GCancellable *cancellable,
    GAsyncReadyCallback callback,
    gpointer user_data);

gboolean wocky_roster_contact_remove_group_finish (WockyRoster *self,
    GAsyncResult *result,
    GError **error);

/* For debugging only */
const gchar * wocky_roster_subscription_to_string (
    WockyRosterSubscriptionFlags subscription);

G_END_DECLS

#endif /* #ifndef __WOCKY_ROSTER_H__*/