566
620
(GDestroyNotify) g_object_unref);
624
collection_backend_authenticate_sync (EBackend *backend,
625
ESourceAuthenticator *auth,
626
GCancellable *cancellable,
629
ECollectionBackend *collection_backend;
630
ESourceRegistryServer *server;
631
EAuthenticationSession *session;
636
source = e_backend_get_source (backend);
637
uid = e_source_get_uid (source);
639
collection_backend = E_COLLECTION_BACKEND (backend);
640
server = e_collection_backend_ref_server (collection_backend);
641
session = e_authentication_session_new (server, auth, uid);
643
success = e_source_registry_server_authenticate_sync (
644
server, session, cancellable, error);
646
g_object_unref (session);
647
g_object_unref (server);
570
653
collection_backend_populate (ECollectionBackend *backend)
572
655
/* Placeholder so subclasses can safely chain up. */
659
collection_backend_dup_resource_id (ECollectionBackend *backend,
662
const gchar *extension_name;
663
gchar *resource_id = NULL;
665
extension_name = E_SOURCE_EXTENSION_RESOURCE;
667
if (e_source_has_extension (source, extension_name)) {
668
ESourceResource *extension;
670
extension = e_source_get_extension (source, extension_name);
671
resource_id = e_source_resource_dup_identity (extension);
576
678
collection_backend_child_added (ECollectionBackend *backend,
577
679
ESource *child_source)
681
collection_backend_children_insert (backend, child_source);
579
682
collection_backend_bind_child_enabled (backend, child_source);
582
&backend->priv->children,
583
g_object_ref (child_source));
585
684
/* Collection children are not removable. */
586
685
e_server_side_source_set_removable (
587
686
E_SERVER_SIDE_SOURCE (child_source), FALSE);
591
690
collection_backend_child_removed (ECollectionBackend *backend,
592
691
ESource *child_source)
594
if (g_queue_remove (&backend->priv->children, child_source))
595
g_object_unref (child_source);
693
collection_backend_children_remove (backend, child_source);
697
collection_backend_create_resource_sync (ECollectionBackend *backend,
699
GCancellable *cancellable,
702
EAsyncClosure *closure;
703
GAsyncResult *result;
706
closure = e_async_closure_new ();
708
e_collection_backend_create_resource (
709
backend, source, cancellable,
710
e_async_closure_callback, closure);
712
result = e_async_closure_wait (closure);
714
success = e_collection_backend_create_resource_finish (
715
backend, result, error);
717
e_async_closure_free (closure);
723
collection_backend_create_resource (ECollectionBackend *backend,
725
GCancellable *cancellable,
726
GAsyncReadyCallback callback,
729
GSimpleAsyncResult *simple;
731
simple = g_simple_async_result_new_error (
732
G_OBJECT (backend), callback, user_data,
733
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
734
_("%s does not support creating remote resources"),
735
G_OBJECT_TYPE_NAME (backend));
737
g_simple_async_result_complete_in_idle (simple);
739
g_object_unref (simple);
743
collection_backend_create_resource_finish (ECollectionBackend *backend,
744
GAsyncResult *result,
747
GSimpleAsyncResult *simple;
749
simple = G_SIMPLE_ASYNC_RESULT (result);
751
/* Assume success unless a GError is set. */
752
return !g_simple_async_result_propagate_error (simple, error);
756
collection_backend_delete_resource_sync (ECollectionBackend *backend,
758
GCancellable *cancellable,
761
EAsyncClosure *closure;
762
GAsyncResult *result;
765
closure = e_async_closure_new ();
767
e_collection_backend_delete_resource (
768
backend, source, cancellable,
769
e_async_closure_callback, closure);
771
result = e_async_closure_wait (closure);
773
success = e_collection_backend_delete_resource_finish (
774
backend, result, error);
776
e_async_closure_free (closure);
782
collection_backend_delete_resource (ECollectionBackend *backend,
784
GCancellable *cancellable,
785
GAsyncReadyCallback callback,
788
GSimpleAsyncResult *simple;
790
simple = g_simple_async_result_new_error (
791
G_OBJECT (backend), callback, user_data,
792
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
793
_("%s does not support deleting remote resources"),
794
G_OBJECT_TYPE_NAME (backend));
796
g_simple_async_result_complete_in_idle (simple);
798
g_object_unref (simple);
802
collection_backend_delete_resource_finish (ECollectionBackend *backend,
803
GAsyncResult *result,
806
GSimpleAsyncResult *simple;
808
simple = G_SIMPLE_ASYNC_RESULT (result);
810
/* Assume success unless a GError is set. */
811
return !g_simple_async_result_propagate_error (simple, error);
599
815
e_collection_backend_class_init (ECollectionBackendClass *class)
601
817
GObjectClass *object_class;
818
EBackendClass *backend_class;
603
820
g_type_class_add_private (class, sizeof (ECollectionBackendPrivate));
1023
* e_collection_backend_dup_resource_id:
1024
* @backend: an #ECollectionBackend
1025
* @child_source: an #ESource managed by @backend
1027
* Extracts the resource ID for @child_source, which is supposed to be a
1028
* stable and unique server-assigned identifier for the remote resource
1029
* described by @child_source. If @child_source is not actually a child
1030
* of the collection #EBackend:source owned by @backend, the function
1033
* The returned string should be freed with g_free() when no longer needed.
1035
* Returns: a newly-allocated resource ID for @child_source, or %NULL
1040
e_collection_backend_dup_resource_id (ECollectionBackend *backend,
1041
ESource *child_source)
1043
ECollectionBackend *backend_for_child_source;
1044
ECollectionBackendClass *class;
1045
ESourceRegistryServer *server;
1046
gboolean child_is_ours = FALSE;
1048
g_return_val_if_fail (E_IS_COLLECTION_BACKEND (backend), NULL);
1049
g_return_val_if_fail (E_IS_SOURCE (child_source), NULL);
1051
class = E_COLLECTION_BACKEND_GET_CLASS (backend);
1052
g_return_val_if_fail (class->dup_resource_id != NULL, NULL);
1054
/* Make sure the ESource belongs to the ECollectionBackend to
1055
* avoid accidentally creating a new extension while trying to
1056
* extract a resource ID that isn't there. Better to test this
1057
* up front than rely on ECollectionBackend subclasses to do it. */
1058
server = e_collection_backend_ref_server (backend);
1059
backend_for_child_source =
1060
e_source_registry_server_ref_backend (server, child_source);
1061
g_object_unref (server);
1063
if (backend_for_child_source != NULL) {
1064
child_is_ours = (backend_for_child_source == backend);
1065
g_object_unref (backend_for_child_source);
1071
return class->dup_resource_id (backend, child_source);
1075
* e_collection_backend_claim_all_resources:
1076
* @backend: an #ECollectionBackend
1078
* Claims all previously used sources that have not yet been claimed by
1079
* e_collection_backend_new_child() and returns them in a #GList. Note
1080
* that previously used sources can only be claimed once, so subsequent
1081
* calls to this function for @backend will return %NULL.
1083
* The @backend is then expected to compare the returned list with a
1084
* current list of resources from a remote server, create new #ESource
1085
* instances as needed with e_collection_backend_new_child(), discard
1086
* unneeded #ESource instances with e_source_remove(), and export the
1087
* remaining instances with e_source_registry_server_add_source().
1089
* The sources returned in the list are referenced for thread-safety.
1090
* They must each be unreferenced with g_object_unref() when finished
1091
* with them. Free the returned #GList itself with g_list_free().
1093
* An easy way to free the list properly in one step is as follows:
1096
* g_list_free_full (list, g_object_unref);
1099
* Returns: a list of previously used sources
1104
e_collection_backend_claim_all_resources (ECollectionBackend *backend)
1106
GHashTable *unclaimed_resources;
1109
g_return_val_if_fail (E_IS_COLLECTION_BACKEND (backend), NULL);
1111
g_mutex_lock (backend->priv->unclaimed_resources_lock);
1113
unclaimed_resources = backend->priv->unclaimed_resources;
1114
resources = g_hash_table_get_values (unclaimed_resources);
1115
g_list_foreach (resources, (GFunc) g_object_ref, NULL);
1116
g_hash_table_remove_all (unclaimed_resources);
1118
g_mutex_unlock (backend->priv->unclaimed_resources_lock);
786
1124
* e_collection_backend_list_calendar_sources:
787
1125
* @backend: an #ECollectionBackend
902
1244
result_list, g_object_ref (child_source));
1247
g_list_free_full (list, (GDestroyNotify) g_object_unref);
905
1249
return g_list_reverse (result_list);
1253
* e_collection_backend_create_resource_sync
1254
* @backend: an #ECollectionBackend
1255
* @source: an #ESource
1256
* @cancellable: optional #GCancellable object, or %NULL
1257
* @error: return location for a #GError, or %NULL
1259
* Creates a server-side resource described by @source. For example, if
1260
* @source describes a new calendar, an equivalent calendar is created on
1263
* It is the implementor's responsibility to examine @source and determine
1264
* what the equivalent server-side resource would be. If this cannot be
1265
* determined without ambiguity, the function must return an error.
1267
* After the server-side resource is successfully created, the implementor
1268
* must also add an #ESource to @backend's #ECollectionBackend:server. This
1269
* can either be done immediately or in response to some "resource created"
1270
* notification from the server. The added #ESource can be @source itself
1271
* or a different #ESource instance that describes the new resource.
1273
* If an error occurs, the function will set @error and return %FALSE.
1275
* Returns: %TRUE on success, %FALSE on failure
1280
e_collection_backend_create_resource_sync (ECollectionBackend *backend,
1282
GCancellable *cancellable,
1285
ECollectionBackendClass *class;
1287
g_return_val_if_fail (E_IS_COLLECTION_BACKEND (backend), FALSE);
1288
g_return_val_if_fail (E_IS_SOURCE (source), FALSE);
1290
class = E_COLLECTION_BACKEND_GET_CLASS (backend);
1291
g_return_val_if_fail (class->create_resource_sync != NULL, FALSE);
1293
return class->create_resource_sync (
1294
backend, source, cancellable, error);
1298
* e_collection_backend_create_resource:
1299
* @backend: an #ECollectionBackend
1300
* @source: an #ESource
1301
* @cancellable: optional #GCancellable object, or %NULL
1302
* @callback: a #GAsyncReadyCallback to call when the request is satisfied
1303
* @user_data: data to pass to the callback function
1305
* Asynchronously creates a server-side resource described by @source.
1306
* For example, if @source describes a new calendar, an equivalent calendar
1307
* is created on the server.
1309
* It is the implementor's responsibility to examine @source and determine
1310
* what the equivalent server-side resource would be. If this cannot be
1311
* determined without ambiguity, the function must return an error.
1313
* After the server-side resource is successfully created, the implementor
1314
* must also add an #ESource to @backend's #ECollectionBackend:server. This
1315
* can either be done immediately or in response to some "resource created"
1316
* notification from the server. The added #ESource can be @source itself
1317
* or a different #ESource instance that describes the new resource.
1319
* When the operation is finished, @callback will be called. You can then
1320
* call e_collection_backend_create_resource_finish() to get the result of
1326
e_collection_backend_create_resource (ECollectionBackend *backend,
1328
GCancellable *cancellable,
1329
GAsyncReadyCallback callback,
1332
ECollectionBackendClass *class;
1334
g_return_if_fail (E_IS_COLLECTION_BACKEND (backend));
1335
g_return_if_fail (E_IS_SOURCE (source));
1337
class = E_COLLECTION_BACKEND_GET_CLASS (backend);
1338
g_return_if_fail (class->create_resource != NULL);
1340
class->create_resource (
1341
backend, source, cancellable, callback, user_data);
1345
* e_collection_backend_create_resource_finish:
1346
* @backend: an #ECollectionBackend
1347
* @result: a #GAsyncResult
1348
* @error: return location for a #GError, or %NULL
1350
* Finishes the operation started with e_collection_backend_create_resource().
1352
* If an error occurred, the function will set @error and return %FALSE.
1354
* Returns: %TRUE on success, %FALSE on failure
1359
e_collection_backend_create_resource_finish (ECollectionBackend *backend,
1360
GAsyncResult *result,
1363
ECollectionBackendClass *class;
1365
g_return_val_if_fail (E_IS_COLLECTION_BACKEND (backend), FALSE);
1366
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
1368
class = E_COLLECTION_BACKEND_GET_CLASS (backend);
1369
g_return_val_if_fail (class->create_resource_finish != NULL, FALSE);
1371
return class->create_resource_finish (backend, result, error);
1375
* e_collection_backend_delete_resource_sync:
1376
* @backend: an #ECollectionBackend
1377
* @source: an #ESource
1378
* @cancellable: optional #GCancellable object, or %NULL
1379
* @error: return location for a #GError, or %NULL
1381
* Deletes a server-side resource described by @source. The @source must
1382
* be a child of @backend's collection #EBackend:source.
1384
* After the server-side resource is successfully deleted, the implementor
1385
* must also remove @source from the @backend's #ECollectionBackend:server.
1386
* This can either be done immediately or in response to some "resource
1387
* deleted" notification from the server.
1389
* If an error occurs, the function will set @error and return %FALSE.
1391
* Returns: %TRUE on success, %FALSE on failure
1396
e_collection_backend_delete_resource_sync (ECollectionBackend *backend,
1398
GCancellable *cancellable,
1401
ECollectionBackendClass *class;
1403
g_return_val_if_fail (E_IS_COLLECTION_BACKEND (backend), FALSE);
1404
g_return_val_if_fail (E_IS_SOURCE (source), FALSE);
1406
class = E_COLLECTION_BACKEND_GET_CLASS (backend);
1407
g_return_val_if_fail (class->delete_resource_sync != NULL, FALSE);
1409
return class->delete_resource_sync (
1410
backend, source, cancellable, error);
1414
* e_collection_backend_delete_resource:
1415
* @backend: an #ECollectionBackend
1416
* @source: an #ESource
1417
* @cancellable: optional #GCancellable object, or %NULL
1418
* @callback: a #GAsyncReadyCallback to call when the request is satisfied
1419
* @user_data: data to pass to the callback function
1421
* Asynchronously deletes a server-side resource described by @source.
1422
* The @source must be a child of @backend's collection #EBackend:source.
1424
* After the server-side resource is successfully deleted, the implementor
1425
* must also remove @source from the @backend's #ECollectionBackend:server.
1426
* This can either be done immediately or in response to some "resource
1427
* deleted" notification from the server.
1429
* When the operation is finished, @callback will be called. You can then
1430
* call e_collection_backend_delete_resource_finish() to get the result of
1436
e_collection_backend_delete_resource (ECollectionBackend *backend,
1438
GCancellable *cancellable,
1439
GAsyncReadyCallback callback,
1442
ECollectionBackendClass *class;
1444
g_return_if_fail (E_IS_COLLECTION_BACKEND (backend));
1445
g_return_if_fail (E_IS_SOURCE (source));
1447
class = E_COLLECTION_BACKEND_GET_CLASS (backend);
1448
g_return_if_fail (class->delete_resource != NULL);
1450
return class->delete_resource (
1451
backend, source, cancellable, callback, user_data);
1455
* e_collection_backend_delete_resource_finish:
1456
* @backend: an #ECollectionBackend
1457
* @result: a #GAsyncResult
1458
* @error: return location for a #GError, or %NULL
1460
* Finishes the operation started with e_collection_backend_delete_resource().
1462
* If an error occurred, the function will set @error and return %FALSE.
1464
* Returns: %TRUE on success, %FALSE on failure
1469
e_collection_backend_delete_resource_finish (ECollectionBackend *backend,
1470
GAsyncResult *result,
1473
ECollectionBackendClass *class;
1475
g_return_val_if_fail (E_IS_COLLECTION_BACKEND (backend), FALSE);
1476
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
1478
class = E_COLLECTION_BACKEND_GET_CLASS (backend);
1479
g_return_val_if_fail (class->delete_resource_finish != NULL, FALSE);
1481
return class->delete_resource_finish (backend, result, error);