summaryrefslogtreecommitdiff
path: root/libedataserver/e-client.h
blob: 4267e47558a0e9a1be624bf49738af30093b3c92 (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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
/*
 * e-client.h
 *
 * Copyright (C) 2011 Red Hat, Inc. (www.redhat.com)
 *
 * 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.
 *
 * 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, see <http://www.gnu.org/licenses/>.
 *
 */

#if !defined (__LIBEDATASERVER_H_INSIDE__) && !defined (LIBEDATASERVER_COMPILATION)
#error "Only <libedataserver/libedataserver.h> should be included directly."
#endif

#ifndef E_CLIENT_H
#define E_CLIENT_H

#include <gio/gio.h>

#include <libedataserver/e-source.h>

/* Standard GObject macros */
#define E_TYPE_CLIENT \
	(e_client_get_type ())
#define E_CLIENT(obj) \
	(G_TYPE_CHECK_INSTANCE_CAST \
	((obj), E_TYPE_CLIENT, EClient))
#define E_CLIENT_CLASS(cls) \
	(G_TYPE_CHECK_CLASS_CAST \
	((cls), E_TYPE_CLIENT, EClientClass))
#define E_IS_CLIENT(obj) \
	(G_TYPE_CHECK_INSTANCE_TYPE \
	((obj), E_TYPE_CLIENT))
#define E_IS_CLIENT_CLASS(cls) \
	(G_TYPE_CHECK_CLASS_TYPE \
	((cls), E_TYPE_CLIENT))
#define E_CLIENT_GET_CLASS(obj) \
	(G_TYPE_INSTANCE_GET_CLASS \
	((obj), E_TYPE_CLIENT, EClientClass))

/**
 * CLIENT_BACKEND_PROPERTY_ONLINE:
 *
 * The "online" property is "TRUE" when the client is fully opened and
 * online, "FALSE" at all other times.  See also e_client_is_online().
 *
 * Since: 3.2
 **/
#define CLIENT_BACKEND_PROPERTY_ONLINE			"online"

/**
 * CLIENT_BACKEND_PROPERTY_READONLY:
 *
 * The "online" property is "TRUE" if the backend has only read access
 * to its data, "FALSE" if the backend can modify its data.  See also
 * e_client_is_readonly().
 *
 * Since: 3.2
 **/
#define CLIENT_BACKEND_PROPERTY_READONLY		"readonly"

/**
 * CLIENT_BACKEND_PROPERTY_CACHE_DIR:
 *
 * The "cache-dir" property indicates the backend's local directory for
 * cached data.
 *
 * Since: 3.2
 **/
#define CLIENT_BACKEND_PROPERTY_CACHE_DIR		"cache-dir"

/**
 * CLIENT_BACKEND_PROPERTY_CAPABILITIES:
 *
 * The "capabilities" property is a comma-separated list of capabilities
 * supported by the backend.  The preferred method of retrieving and working
 * with capabilities is e_client_get_capabilities() and
 * e_client_check_capability().
 *
 * Since: 3.2
 **/
#define CLIENT_BACKEND_PROPERTY_CAPABILITIES		"capabilities"

/**
 * CLIENT_BACKEND_PROPERTY_REVISION:
 *
 * The current overall revision string, this can be used as
 * a quick check to see if data has changed at all since the
 * last time the revision was observed.
 *
 * Since: 3.4
 **/
#define CLIENT_BACKEND_PROPERTY_REVISION		"revision"

/**
 * E_CLIENT_ERROR:
 *
 * Error domain for #EClient operations.  Errors in this domain will be
 * from the #EClientError enumeration.  See #GError for more information
 * on error domains.
 *
 * Since: 3.2
 **/
#define E_CLIENT_ERROR		e_client_error_quark ()

G_BEGIN_DECLS

GQuark e_client_error_quark (void) G_GNUC_CONST;

/**
 * EClientError:
 * @E_CLIENT_ERROR_INVALID_ARG: Invalid argument was used
 * @E_CLIENT_ERROR_BUSY: The client is busy
 * @E_CLIENT_ERROR_SOURCE_NOT_LOADED: The source is not loaded
 * @E_CLIENT_ERROR_SOURCE_ALREADY_LOADED: The source is already loaded
 * @E_CLIENT_ERROR_AUTHENTICATION_FAILED: Authentication failed
 * @E_CLIENT_ERROR_AUTHENTICATION_REQUIRED: Authentication required
 * @E_CLIENT_ERROR_REPOSITORY_OFFLINE: The repository (client) is offline
 * @E_CLIENT_ERROR_OFFLINE_UNAVAILABLE: The operation is unavailable in offline mode
 * @E_CLIENT_ERROR_PERMISSION_DENIED: Permission denied for the operation
 * @E_CLIENT_ERROR_CANCELLED: The operation was cancelled
 * @E_CLIENT_ERROR_COULD_NOT_CANCEL: The operation cannot be cancelled
 * @E_CLIENT_ERROR_NOT_SUPPORTED: The operation is not supported
 * @E_CLIENT_ERROR_TLS_NOT_AVAILABLE: TLS is not available
 * @E_CLIENT_ERROR_UNSUPPORTED_AUTHENTICATION_METHOD: Requested authentication method is not supported
 * @E_CLIENT_ERROR_SEARCH_SIZE_LIMIT_EXCEEDED: Search size limit exceeded
 * @E_CLIENT_ERROR_SEARCH_TIME_LIMIT_EXCEEDED: Search time limit exceeded
 * @E_CLIENT_ERROR_INVALID_QUERY: The query was invalid
 * @E_CLIENT_ERROR_QUERY_REFUSED: The query was refused by the server side
 * @E_CLIENT_ERROR_DBUS_ERROR: A D-Bus error occurred
 * @E_CLIENT_ERROR_OTHER_ERROR: Other error
 * @E_CLIENT_ERROR_NOT_OPENED: The client is not opened
 * @E_CLIENT_ERROR_OUT_OF_SYNC: The clien tis out of sync
 *
 * Error codes for #EClient operations.
 *
 * Since: 3.2
 **/
typedef enum {
	E_CLIENT_ERROR_INVALID_ARG,
	E_CLIENT_ERROR_BUSY,
	E_CLIENT_ERROR_SOURCE_NOT_LOADED,
	E_CLIENT_ERROR_SOURCE_ALREADY_LOADED,
	E_CLIENT_ERROR_AUTHENTICATION_FAILED,
	E_CLIENT_ERROR_AUTHENTICATION_REQUIRED,
	E_CLIENT_ERROR_REPOSITORY_OFFLINE,
	E_CLIENT_ERROR_OFFLINE_UNAVAILABLE,
	E_CLIENT_ERROR_PERMISSION_DENIED,
	E_CLIENT_ERROR_CANCELLED,
	E_CLIENT_ERROR_COULD_NOT_CANCEL,
	E_CLIENT_ERROR_NOT_SUPPORTED,
	E_CLIENT_ERROR_TLS_NOT_AVAILABLE,
	E_CLIENT_ERROR_UNSUPPORTED_AUTHENTICATION_METHOD,
	E_CLIENT_ERROR_SEARCH_SIZE_LIMIT_EXCEEDED,
	E_CLIENT_ERROR_SEARCH_TIME_LIMIT_EXCEEDED,
	E_CLIENT_ERROR_INVALID_QUERY,
	E_CLIENT_ERROR_QUERY_REFUSED,
	E_CLIENT_ERROR_DBUS_ERROR,
	E_CLIENT_ERROR_OTHER_ERROR,
	E_CLIENT_ERROR_NOT_OPENED,
	E_CLIENT_ERROR_OUT_OF_SYNC
} EClientError;

const gchar *	e_client_error_to_string	(EClientError code);

/**
 * EClient:
 *
 * Contains only private data that should be read and manipulated using the
 * functions below.
 *
 * Since: 3.2
 **/
typedef struct _EClient EClient;
typedef struct _EClientClass EClientClass;
typedef struct _EClientPrivate EClientPrivate;

struct _EClient {
	/*< private >*/
	GObject parent;
	EClientPrivate *priv;
};

struct _EClientClass {
	/*< private >*/
	GObjectClass parent;

	/* This method is deprecated. */
	GDBusProxy *	(*get_dbus_proxy)	(EClient *client);

	/* This method is deprecated. */
	void		(*unwrap_dbus_error)	(EClient *client,
						 GError *dbus_error,
						 GError **out_error);

	/* This method is deprecated. */
	void		(*retrieve_capabilities)
						(EClient *client,
						 GCancellable *cancellable,
						 GAsyncReadyCallback callback,
						 gpointer user_data);
	gboolean	(*retrieve_capabilities_finish)
						(EClient *client,
						 GAsyncResult *result,
						 gchar **capabilities,
						 GError **error);
	gboolean	(*retrieve_capabilities_sync)
						(EClient *client,
						 gchar **capabilities,
						 GCancellable *cancellable,
						 GError **error);

	void		(*get_backend_property)	(EClient *client,
						 const gchar *prop_name,
						 GCancellable *cancellable,
						 GAsyncReadyCallback callback,
						 gpointer user_data);
	gboolean	(*get_backend_property_finish)
						(EClient *client,
						 GAsyncResult *result,
						 gchar **prop_value,
						 GError **error);
	gboolean	(*get_backend_property_sync)
						(EClient *client,
						 const gchar *prop_name,
						 gchar **prop_value,
						 GCancellable *cancellable,
						 GError **error);

	/* This method is deprecated. */
	void		(*set_backend_property)	(EClient *client,
						 const gchar *prop_name,
						 const gchar *prop_value,
						 GCancellable *cancellable,
						 GAsyncReadyCallback callback,
						 gpointer user_data);
	gboolean	(*set_backend_property_finish)
						(EClient *client,
						 GAsyncResult *result,
						 GError **error);
	gboolean	(*set_backend_property_sync)
						(EClient *client,
						 const gchar *prop_name,
						 const gchar *prop_value,
						 GCancellable *cancellable,
						 GError **error);

	void		(*open)			(EClient *client,
						 gboolean only_if_exists,
						 GCancellable *cancellable,
						 GAsyncReadyCallback callback,
						 gpointer user_data);
	gboolean	(*open_finish)		(EClient *client,
						 GAsyncResult *result,
						 GError **error);
	gboolean	(*open_sync)		(EClient *client,
						 gboolean only_if_exists,
						 GCancellable *cancellable,
						 GError **error);

	void		(*remove)		(EClient *client,
						 GCancellable *cancellable,
						 GAsyncReadyCallback callback,
						 gpointer user_data);
	gboolean	(*remove_finish)	(EClient *client,
						 GAsyncResult *result,
						 GError **error);
	gboolean	(*remove_sync)		(EClient *client,
						 GCancellable *cancellable,
						 GError **error);

	void		(*refresh)		(EClient *client,
						 GCancellable *cancellable,
						 GAsyncReadyCallback callback,
						 gpointer user_data);
	gboolean	(*refresh_finish)	(EClient *client,
						 GAsyncResult *result,
						 GError **error);
	gboolean	(*refresh_sync)		(EClient *client,
						 GCancellable *cancellable,
						 GError **error);
	gboolean	(*retrieve_properties_sync)
						(EClient *client,
						 GCancellable *cancellable,
						 GError **error);

	void		(*opened)		(EClient *client,
						 const GError *error);
	void		(*backend_error)	(EClient *client,
						 const gchar *error_msg);
	void		(*backend_died)		(EClient *client);
	void		(*backend_property_changed)
						(EClient *client,
						 const gchar *prop_name,
						 const gchar *prop_value);
};

GType		e_client_get_type		(void) G_GNUC_CONST;

ESource *	e_client_get_source		(EClient *client);
const GSList *	e_client_get_capabilities	(EClient *client);
GMainContext *	e_client_ref_main_context	(EClient *client);
gboolean	e_client_check_capability	(EClient *client,
						 const gchar *capability);
gboolean	e_client_check_refresh_supported
						(EClient *client);
gboolean	e_client_is_readonly		(EClient *client);
gboolean	e_client_is_online		(EClient *client);

void		e_client_get_backend_property	(EClient *client,
						 const gchar *prop_name,
						 GCancellable *cancellable,
						 GAsyncReadyCallback callback,
						 gpointer user_data);
gboolean	e_client_get_backend_property_finish
						(EClient *client,
						 GAsyncResult *result,
						 gchar **prop_value,
						 GError **error);
gboolean	e_client_get_backend_property_sync
						(EClient *client,
						 const gchar *prop_name,
						 gchar **prop_value,
						 GCancellable *cancellable,
						 GError **error);

void		e_client_refresh		(EClient *client,
						 GCancellable *cancellable,
						 GAsyncReadyCallback callback,
						 gpointer user_data);
gboolean	e_client_refresh_finish		(EClient *client,
						 GAsyncResult *result,
						 GError **error);
gboolean	e_client_refresh_sync		(EClient *client,
						 GCancellable *cancellable,
						 GError **error);

void		e_client_wait_for_connected	(EClient *client,
						 guint32 timeout_seconds,
						 GCancellable *cancellable,
						 GAsyncReadyCallback callback,
						 gpointer user_data);
gboolean	e_client_wait_for_connected_finish
						(EClient *client,
						 GAsyncResult *result,
						 GError **error);
gboolean	e_client_wait_for_connected_sync(EClient *client,
						 guint32 timeout_seconds,
						 GCancellable *cancellable,
						 GError **error);

GSList *	e_client_util_parse_comma_strings
						(const gchar *strings);

#ifndef EDS_DISABLE_DEPRECATED
/**
 * CLIENT_BACKEND_PROPERTY_OPENED:
 *
 * The "opened" property is "TRUE" when the client is fully opened,
 * "FALSE" at all other times.
 *
 * Since: 3.2
 *
 * Deprecated: 3.8: Clients don't need to care if they're fully opened
 *                  anymore.  This property will always return %TRUE.
 **/
#define CLIENT_BACKEND_PROPERTY_OPENED			"opened"

/**
 * CLIENT_BACKEND_PROPERTY_OPENING:
 *
 * The "opening" property is "TRUE" when the client is in the process of
 * opening, "FALSE" at all other times.
 *
 * Since: 3.2
 *
 * Deprecated: 3.8: Clients don't need to care if they're fully opened
 *                  anymore.  This property will always return %FALSE.
 **/
#define CLIENT_BACKEND_PROPERTY_OPENING			"opening"

GError *	e_client_error_create		(EClientError code,
						 const gchar *custom_msg);
gboolean	e_client_is_opened		(EClient *client);
void		e_client_cancel_all		(EClient *client);
void		e_client_unwrap_dbus_error	(EClient *client,
						 GError *dbus_error,
						 GError **out_error);
void		e_client_retrieve_capabilities	(EClient *client,
						 GCancellable *cancellable,
						 GAsyncReadyCallback callback,
						 gpointer user_data);
gboolean	e_client_retrieve_capabilities_finish
						(EClient *client,
						 GAsyncResult *result,
						 gchar **capabilities,
						 GError **error);
gboolean	e_client_retrieve_capabilities_sync
						(EClient *client,
						 gchar **capabilities,
						 GCancellable *cancellable,
						 GError **error);
void		e_client_set_backend_property	(EClient *client,
						 const gchar *prop_name,
						 const gchar *prop_value,
						 GCancellable *cancellable,
						 GAsyncReadyCallback callback,
						 gpointer user_data);
gboolean	e_client_set_backend_property_finish
						(EClient *client,
						 GAsyncResult *result,
						 GError **error);
gboolean	e_client_set_backend_property_sync
						(EClient *client,
						 const gchar *prop_name,
						 const gchar *prop_value,
						 GCancellable *cancellable,
						 GError **error);
void		e_client_open			(EClient *client,
						 gboolean only_if_exists,
						 GCancellable *cancellable,
						 GAsyncReadyCallback callback,
						 gpointer user_data);
gboolean	e_client_open_finish		(EClient *client,
						 GAsyncResult *result,
						 GError **error);
gboolean	e_client_open_sync		(EClient *client,
						 gboolean only_if_exists,
						 GCancellable *cancellable,
						 GError **error);
void		e_client_remove			(EClient *client,
						 GCancellable *cancellable,
						 GAsyncReadyCallback callback,
						 gpointer user_data);
gboolean	e_client_remove_finish		(EClient *client,
						 GAsyncResult *result,
						 GError **error);
gboolean	e_client_remove_sync		(EClient *client,
						 GCancellable *cancellable,
						 GError **error);
gboolean	e_client_retrieve_properties_sync
						(EClient *client,
						 GCancellable *cancellable,
						 GError **error);
void		e_client_retrieve_properties	(EClient *client,
						 GCancellable *cancellable,
						 GAsyncReadyCallback callback,
						 gpointer user_data);
gboolean	e_client_retrieve_properties_finish
						(EClient *client,
						 GAsyncResult *result,
						 GError **error);
gchar **	e_client_util_slist_to_strv	(const GSList *strings);
GSList *	e_client_util_strv_to_slist	(const gchar * const *strv);
GSList *	e_client_util_copy_string_slist	(GSList *copy_to,
						 const GSList *strings);
GSList *	e_client_util_copy_object_slist	(GSList *copy_to,
						 const GSList *objects);
void		e_client_util_free_string_slist	(GSList *strings);
void		e_client_util_free_object_slist	(GSList *objects);
gchar *		e_client_dup_bus_name		(EClient *client);
void		e_client_set_bus_name		(EClient *client,
						 const gchar *bus_name);


typedef struct _EClientErrorsList EClientErrorsList;

/**
 * EClientErrorsList:
 *
 * Since: 3.2
 *
 * Deprecated: 3.8: This structure is no longer used.
 **/
struct _EClientErrorsList {
	const gchar *name;
	gint err_code;
};

gboolean	e_client_util_unwrap_dbus_error	(GError *dbus_error,
						 GError **client_error,
						 const EClientErrorsList *known_errors,
						 guint known_errors_count,
						 GQuark known_errors_domain,
						 gboolean fail_when_none_matched);

#endif /* EDS_DISABLE_DEPRECATED */

G_END_DECLS

#endif /* E_CLIENT_H */