~ubuntu-branches/ubuntu/saucy/evolution-data-server/saucy

« back to all changes in this revision

Viewing changes to libedataserver/e-source.c

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2012-10-08 12:58:16 UTC
  • mfrom: (181.1.7 quantal)
  • Revision ID: package-import@ubuntu.com-20121008125816-i3n76e8c0m64e7xp
Tags: 3.6.0-0ubuntu2
* Fix LP: #1038047 part 1 - Don't abort in e_source_registry_new* when a
  problem occurs connecting to the Dbus service
  - add debian/patches/dont-abort-in-e_source_registry_new.patch
  - update debian/patches/series
* Fix LP: #1038047 part 2 - libedataserver depends on
  evolution-data-server-common to ensure that the GSettings schemas are
  present
  - update debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
92
92
#include "e-source-offline.h"
93
93
#include "e-source-openpgp.h"
94
94
#include "e-source-refresh.h"
 
95
#include "e-source-resource.h"
95
96
#include "e-source-security.h"
96
97
#include "e-source-selectable.h"
97
98
#include "e-source-smime.h"
108
109
 
109
110
#define PRIMARY_GROUP_NAME      "Data Source"
110
111
 
 
112
typedef struct _AsyncContext AsyncContext;
 
113
 
111
114
struct _ESourcePrivate {
112
115
        GDBusObject *dbus_object;
113
116
        GMainContext *main_context;
129
132
        GHashTable *extensions;
130
133
 
131
134
        gboolean enabled;
 
135
        gboolean initialized;
 
136
};
 
137
 
 
138
struct _AsyncContext {
 
139
        ESource *scratch_source;
132
140
};
133
141
 
134
142
enum {
138
146
        PROP_ENABLED,
139
147
        PROP_MAIN_CONTEXT,
140
148
        PROP_PARENT,
 
149
        PROP_REMOTE_CREATABLE,
 
150
        PROP_REMOTE_DELETABLE,
141
151
        PROP_REMOVABLE,
142
152
        PROP_UID,
143
153
        PROP_WRITABLE
162
172
                e_source_initable_init))
163
173
 
164
174
static void
 
175
async_context_free (AsyncContext *async_context)
 
176
{
 
177
        if (async_context->scratch_source != NULL)
 
178
                g_object_unref (async_context->scratch_source);
 
179
 
 
180
        g_slice_free (AsyncContext, async_context);
 
181
}
 
182
 
 
183
static void
165
184
source_find_extension_classes_rec (GType parent_type,
166
185
                                   GHashTable *hash_table)
167
186
{
647
666
{
648
667
        ESource *source = E_SOURCE (user_data);
649
668
 
 
669
        /* If the ESource is still initializing itself in a different
 
670
         * thread, skip the signal emission and try again on the next
 
671
         * main loop iteration.  This is a busy wait but it should be
 
672
         * a very short wait. */
 
673
        if (!source->priv->initialized)
 
674
                return TRUE;
 
675
 
650
676
        g_mutex_lock (source->priv->changed_lock);
651
677
        if (source->priv->changed != NULL) {
652
678
                g_source_unref (source->priv->changed);
686
712
}
687
713
 
688
714
static void
 
715
source_set_uid (ESource *source,
 
716
                const gchar *uid)
 
717
{
 
718
        /* The "uid" argument will usually be NULL unless called
 
719
         * from e_source_new_with_uid().  If NULL, we'll pick up
 
720
         * a UID in source_initable_init(). */
 
721
 
 
722
        g_return_if_fail (source->priv->uid == NULL);
 
723
 
 
724
        source->priv->uid = g_strdup (uid);
 
725
}
 
726
 
 
727
static void
689
728
source_set_property (GObject *object,
690
729
                     guint property_id,
691
730
                     const GValue *value,
721
760
                                E_SOURCE (object),
722
761
                                g_value_get_string (value));
723
762
                        return;
 
763
 
 
764
                case PROP_UID:
 
765
                        source_set_uid (
 
766
                                E_SOURCE (object),
 
767
                                g_value_get_string (value));
 
768
                        return;
724
769
        }
725
770
 
726
771
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
763
808
                                E_SOURCE (object)));
764
809
                        return;
765
810
 
 
811
                case PROP_REMOTE_CREATABLE:
 
812
                        g_value_set_boolean (
 
813
                                value, e_source_get_remote_creatable (
 
814
                                E_SOURCE (object)));
 
815
                        return;
 
816
 
 
817
                case PROP_REMOTE_DELETABLE:
 
818
                        g_value_set_boolean (
 
819
                                value, e_source_get_remote_deletable (
 
820
                                E_SOURCE (object)));
 
821
                        return;
 
822
 
766
823
                case PROP_REMOVABLE:
767
824
                        g_value_set_boolean (
768
825
                                value, e_source_get_removable (
1029
1086
}
1030
1087
 
1031
1088
static gboolean
 
1089
source_remote_create_sync (ESource *source,
 
1090
                           ESource *scratch_source,
 
1091
                           GCancellable *cancellable,
 
1092
                           GError **error)
 
1093
{
 
1094
        EDBusSourceRemoteCreatable *dbus_interface = NULL;
 
1095
        GDBusObject *dbus_object;
 
1096
        gchar *uid, *data;
 
1097
        gboolean success;
 
1098
 
 
1099
        dbus_object = e_source_ref_dbus_object (source);
 
1100
        if (dbus_object != NULL) {
 
1101
                dbus_interface =
 
1102
                        e_dbus_object_get_source_remote_creatable (
 
1103
                        E_DBUS_OBJECT (dbus_object));
 
1104
                g_object_unref (dbus_object);
 
1105
        }
 
1106
 
 
1107
        if (dbus_interface == NULL) {
 
1108
                g_set_error (
 
1109
                        error, G_IO_ERROR,
 
1110
                        G_IO_ERROR_NOT_SUPPORTED,
 
1111
                        _("Data source '%s' does not "
 
1112
                        "support creating remote resources"),
 
1113
                        e_source_get_display_name (source));
 
1114
                return FALSE;
 
1115
        }
 
1116
 
 
1117
        uid = e_source_dup_uid (scratch_source);
 
1118
        data = e_source_to_string (scratch_source, NULL);
 
1119
 
 
1120
        success = e_dbus_source_remote_creatable_call_create_sync (
 
1121
                dbus_interface, uid, data, cancellable, error);
 
1122
 
 
1123
        g_free (data);
 
1124
        g_free (uid);
 
1125
 
 
1126
        g_object_unref (dbus_interface);
 
1127
 
 
1128
        return success;
 
1129
}
 
1130
 
 
1131
/* Helper for source_remote_create() */
 
1132
static void
 
1133
source_remote_create_thread (GSimpleAsyncResult *simple,
 
1134
                             GObject *object,
 
1135
                             GCancellable *cancellable)
 
1136
{
 
1137
        AsyncContext *async_context;
 
1138
        GError *error = NULL;
 
1139
 
 
1140
        async_context = g_simple_async_result_get_op_res_gpointer (simple);
 
1141
 
 
1142
        e_source_remote_create_sync (
 
1143
                E_SOURCE (object),
 
1144
                async_context->scratch_source,
 
1145
                cancellable, &error);
 
1146
 
 
1147
        if (error != NULL)
 
1148
                g_simple_async_result_take_error (simple, error);
 
1149
}
 
1150
 
 
1151
static void
 
1152
source_remote_create (ESource *source,
 
1153
                      ESource *scratch_source,
 
1154
                      GCancellable *cancellable,
 
1155
                      GAsyncReadyCallback callback,
 
1156
                      gpointer user_data)
 
1157
{
 
1158
        GSimpleAsyncResult *simple;
 
1159
        AsyncContext *async_context;
 
1160
 
 
1161
        async_context = g_slice_new0 (AsyncContext);
 
1162
        async_context->scratch_source = g_object_ref (scratch_source);
 
1163
 
 
1164
        simple = g_simple_async_result_new (
 
1165
                G_OBJECT (source), callback,
 
1166
                user_data, source_remote_create);
 
1167
 
 
1168
        g_simple_async_result_set_check_cancellable (simple, cancellable);
 
1169
 
 
1170
        g_simple_async_result_set_op_res_gpointer (
 
1171
                simple, async_context, (GDestroyNotify) async_context_free);
 
1172
 
 
1173
        g_simple_async_result_run_in_thread (
 
1174
                simple, source_remote_create_thread,
 
1175
                G_PRIORITY_DEFAULT, cancellable);
 
1176
 
 
1177
        g_object_unref (simple);
 
1178
}
 
1179
 
 
1180
static gboolean
 
1181
source_remote_create_finish (ESource *source,
 
1182
                             GAsyncResult *result,
 
1183
                             GError **error)
 
1184
{
 
1185
        GSimpleAsyncResult *simple;
 
1186
 
 
1187
        g_return_val_if_fail (
 
1188
                g_simple_async_result_is_valid (
 
1189
                result, G_OBJECT (source), source_remote_create), FALSE);
 
1190
 
 
1191
        simple = G_SIMPLE_ASYNC_RESULT (result);
 
1192
 
 
1193
        /* Assume success unless a GError is set. */
 
1194
        return !g_simple_async_result_propagate_error (simple, error);
 
1195
}
 
1196
 
 
1197
static gboolean
 
1198
source_remote_delete_sync (ESource *source,
 
1199
                           GCancellable *cancellable,
 
1200
                           GError **error)
 
1201
{
 
1202
        EDBusSourceRemoteDeletable *dbus_interface = NULL;
 
1203
        GDBusObject *dbus_object;
 
1204
        gboolean success;
 
1205
 
 
1206
        g_return_val_if_fail (E_IS_SOURCE (source), FALSE);
 
1207
 
 
1208
        dbus_object = e_source_ref_dbus_object (source);
 
1209
        if (dbus_object != NULL) {
 
1210
                dbus_interface =
 
1211
                        e_dbus_object_get_source_remote_deletable (
 
1212
                        E_DBUS_OBJECT (dbus_object));
 
1213
                g_object_unref (dbus_object);
 
1214
        }
 
1215
 
 
1216
        if (dbus_interface == NULL) {
 
1217
                g_set_error (
 
1218
                        error, G_IO_ERROR,
 
1219
                        G_IO_ERROR_NOT_SUPPORTED,
 
1220
                        _("Data source '%s' does not "
 
1221
                        "support deleting remote resources"),
 
1222
                        e_source_get_display_name (source));
 
1223
                return FALSE;
 
1224
        }
 
1225
 
 
1226
        success = e_dbus_source_remote_deletable_call_delete_sync (
 
1227
                dbus_interface, cancellable, error);
 
1228
 
 
1229
        g_object_unref (dbus_interface);
 
1230
 
 
1231
        return success;
 
1232
}
 
1233
 
 
1234
/* Helper for source_remote_delete() */
 
1235
static void
 
1236
source_remote_delete_thread (GSimpleAsyncResult *simple,
 
1237
                             GObject *object,
 
1238
                             GCancellable *cancellable)
 
1239
{
 
1240
        GError *error = NULL;
 
1241
 
 
1242
        e_source_remote_delete_sync (
 
1243
                E_SOURCE (object), cancellable, &error);
 
1244
 
 
1245
        if (error != NULL)
 
1246
                g_simple_async_result_take_error (simple, error);
 
1247
}
 
1248
 
 
1249
static void
 
1250
source_remote_delete (ESource *source,
 
1251
                      GCancellable *cancellable,
 
1252
                      GAsyncReadyCallback callback,
 
1253
                      gpointer user_data)
 
1254
{
 
1255
        GSimpleAsyncResult *simple;
 
1256
 
 
1257
        simple = g_simple_async_result_new (
 
1258
                G_OBJECT (source), callback,
 
1259
                user_data, source_remote_delete);
 
1260
 
 
1261
        g_simple_async_result_set_check_cancellable (simple, cancellable);
 
1262
 
 
1263
        g_simple_async_result_run_in_thread (
 
1264
                simple, source_remote_delete_thread,
 
1265
                G_PRIORITY_DEFAULT, cancellable);
 
1266
 
 
1267
        g_object_unref (simple);
 
1268
}
 
1269
 
 
1270
static gboolean
 
1271
source_remote_delete_finish (ESource *source,
 
1272
                             GAsyncResult *result,
 
1273
                             GError **error)
 
1274
{
 
1275
        GSimpleAsyncResult *simple;
 
1276
 
 
1277
        g_return_val_if_fail (
 
1278
                g_simple_async_result_is_valid (
 
1279
                result, G_OBJECT (source), source_remote_delete), FALSE);
 
1280
 
 
1281
        simple = G_SIMPLE_ASYNC_RESULT (result);
 
1282
 
 
1283
        /* Assume success unless a GError is set. */
 
1284
        return !g_simple_async_result_propagate_error (simple, error);
 
1285
}
 
1286
 
 
1287
static gboolean
1032
1288
source_initable_init (GInitable *initable,
1033
1289
                      GCancellable *cancellable,
1034
1290
                      GError **error)
1065
1321
                        e_dbus_source_call_allow_auth_prompt_sync (
1066
1322
                                dbus_source, cancellable, NULL);
1067
1323
 
1068
 
                /* The UID never changes, so we can cache a copy. */
 
1324
                /* The UID never changes, so we can cache a copy.
 
1325
                 *
 
1326
                 * XXX Note, EServerSideSource may have already set this
 
1327
                 *     by way of the "uid" construct-only property, hence
 
1328
                 *     the g_free() call.  Not a problem, we'll just free
 
1329
                 *     our UID string and set it to the same value again. */
 
1330
                g_free (source->priv->uid);
1069
1331
                source->priv->uid = e_dbus_source_dup_uid (dbus_source);
1070
1332
 
1071
1333
                g_signal_connect (
1074
1336
 
1075
1337
                success = source_parse_dbus_data (source, error);
1076
1338
 
1077
 
                /* Avoid a spurious "changed" emission. */
1078
 
                g_mutex_lock (source->priv->changed_lock);
1079
 
                if (source->priv->changed != NULL) {
1080
 
                        g_source_destroy (source->priv->changed);
1081
 
                        g_source_unref (source->priv->changed);
1082
 
                        source->priv->changed = NULL;
1083
 
                }
1084
 
                g_mutex_unlock (source->priv->changed_lock);
1085
 
 
1086
1339
                g_object_unref (dbus_source);
1087
1340
 
1088
1341
        /* No D-Bus object implies we're configuring a new source,
1089
 
         * so generate a new unique identifier (UID) for it. */
1090
 
        } else {
 
1342
         * so generate a new unique identifier (UID) unless one was
 
1343
         * explicitly provided through e_source_new_with_uid(). */
 
1344
        } else if (source->priv->uid == NULL) {
1091
1345
                source->priv->uid = e_uid_new ();
1092
1346
        }
1093
1347
 
 
1348
        /* Try to avoid a spurious "changed" emission. */
 
1349
        g_mutex_lock (source->priv->changed_lock);
 
1350
        if (source->priv->changed != NULL) {
 
1351
                g_source_destroy (source->priv->changed);
 
1352
                g_source_unref (source->priv->changed);
 
1353
                source->priv->changed = NULL;
 
1354
        }
 
1355
        g_mutex_unlock (source->priv->changed_lock);
 
1356
 
 
1357
        source->priv->initialized = TRUE;
 
1358
 
1094
1359
        return success;
1095
1360
}
1096
1361
 
1114
1379
        class->write_sync = source_write_sync;
1115
1380
        class->write = source_write;
1116
1381
        class->write_finish = source_write_finish;
 
1382
        class->remote_create_sync = source_remote_create_sync;
 
1383
        class->remote_create = source_remote_create;
 
1384
        class->remote_create_finish = source_remote_create_finish;
 
1385
        class->remote_delete_sync = source_remote_delete_sync;
 
1386
        class->remote_delete = source_remote_delete;
 
1387
        class->remote_delete_finish = source_remote_delete_finish;
1117
1388
 
1118
1389
        g_object_class_install_property (
1119
1390
                object_class,
1179
1450
 
1180
1451
        g_object_class_install_property (
1181
1452
                object_class,
 
1453
                PROP_REMOTE_CREATABLE,
 
1454
                g_param_spec_boolean (
 
1455
                        "remote-creatable",
 
1456
                        "Remote Creatable",
 
1457
                        "Whether the data source "
 
1458
                        "can create remote resources",
 
1459
                        FALSE,
 
1460
                        G_PARAM_READABLE |
 
1461
                        G_PARAM_STATIC_STRINGS));
 
1462
 
 
1463
        g_object_class_install_property (
 
1464
                object_class,
 
1465
                PROP_REMOTE_DELETABLE,
 
1466
                g_param_spec_boolean (
 
1467
                        "remote-deletable",
 
1468
                        "Remote Deletable",
 
1469
                        "Whether the data source "
 
1470
                        "can delete remote resources",
 
1471
                        FALSE,
 
1472
                        G_PARAM_READABLE |
 
1473
                        G_PARAM_STATIC_STRINGS));
 
1474
 
 
1475
        g_object_class_install_property (
 
1476
                object_class,
1182
1477
                PROP_REMOVABLE,
1183
1478
                g_param_spec_boolean (
1184
1479
                        "removable",
1196
1491
                        "UID",
1197
1492
                        "The unique identity of the data source",
1198
1493
                        NULL,
1199
 
                        G_PARAM_READABLE |
 
1494
                        G_PARAM_READWRITE |
 
1495
                        G_PARAM_CONSTRUCT_ONLY |
1200
1496
                        G_PARAM_STATIC_STRINGS));
1201
1497
 
1202
1498
        g_object_class_install_property (
1247
1543
        REGISTER_TYPE (E_TYPE_SOURCE_OFFLINE);
1248
1544
        REGISTER_TYPE (E_TYPE_SOURCE_OPENPGP);
1249
1545
        REGISTER_TYPE (E_TYPE_SOURCE_REFRESH);
 
1546
        REGISTER_TYPE (E_TYPE_SOURCE_RESOURCE);
1250
1547
        REGISTER_TYPE (E_TYPE_SOURCE_SECURITY);
1251
1548
        REGISTER_TYPE (E_TYPE_SOURCE_SELECTABLE);
1252
1549
        REGISTER_TYPE (E_TYPE_SOURCE_SMIME);
1323
1620
}
1324
1621
 
1325
1622
/**
 
1623
 * e_source_new_with_uid:
 
1624
 * @uid: a new unique identifier string
 
1625
 * @main_context: (allow-none): a #GMainContext or %NULL
 
1626
 * @error: return location for a #GError, or %NULL
 
1627
 *
 
1628
 * Creates a new "scratch" #ESource with a predetermined unique identifier.
 
1629
 *
 
1630
 * The #ESource::changed signal will be emitted from @main_context if given,
 
1631
 * or else from the thread-default #GMainContext at the time this function is
 
1632
 * called.
 
1633
 *
 
1634
 * Returns: a new scratch #ESource, or %NULL on error
 
1635
 *
 
1636
 * Since: 3.6
 
1637
 **/
 
1638
ESource *
 
1639
e_source_new_with_uid (const gchar *uid,
 
1640
                       GMainContext *main_context,
 
1641
                       GError **error)
 
1642
{
 
1643
        g_return_val_if_fail (uid != NULL, NULL);
 
1644
 
 
1645
        return g_initable_new (
 
1646
                E_TYPE_SOURCE, NULL, error,
 
1647
                "main-context", main_context,
 
1648
                "uid", uid, NULL);
 
1649
}
 
1650
 
 
1651
/**
1326
1652
 * e_source_hash:
1327
1653
 * @source: an #ESource
1328
1654
 *
1584
1910
{
1585
1911
        g_return_if_fail (E_IS_SOURCE (source));
1586
1912
 
1587
 
        if ((enabled ? 1 : 0) == (source->priv->enabled ? 1 : 0))
 
1913
        if (source->priv->enabled == enabled)
1588
1914
                return;
1589
1915
 
1590
1916
        source->priv->enabled = enabled;
1643
1969
}
1644
1970
 
1645
1971
/**
 
1972
 * e_source_get_remote_creatable:
 
1973
 * @source: an #ESource
 
1974
 *
 
1975
 * Returns whether new resources can be created on a remote server by
 
1976
 * calling e_source_remote_create() on @source.
 
1977
 *
 
1978
 * Generally this is only %TRUE if @source has an #ESourceCollection
 
1979
 * extension, which means there is an #ECollectionBackend in the D-Bus
 
1980
 * service that can handle create requests.  If @source does not have
 
1981
 * this capability, calls to e_source_remote_create() will fail.
 
1982
 *
 
1983
 * Returns: whether @source can create remote resources
 
1984
 *
 
1985
 * Since: 3.6
 
1986
 **/
 
1987
gboolean
 
1988
e_source_get_remote_creatable (ESource *source)
 
1989
{
 
1990
        EDBusObject *dbus_object;
 
1991
        EDBusSourceRemoteCreatable *dbus_source;
 
1992
 
 
1993
        g_return_val_if_fail (E_IS_SOURCE (source), FALSE);
 
1994
 
 
1995
        dbus_object = E_DBUS_OBJECT (source->priv->dbus_object);
 
1996
        dbus_source = e_dbus_object_peek_source_remote_creatable (dbus_object);
 
1997
 
 
1998
        return (dbus_source != NULL);
 
1999
}
 
2000
 
 
2001
/**
 
2002
 * e_source_get_remote_deletable:
 
2003
 * @source: an #ESource
 
2004
 *
 
2005
 * Returns whether the resource represented by @source can be deleted
 
2006
 * from a remote server by calling e_source_remote_delete().
 
2007
 *
 
2008
 * Generally this is only %TRUE if @source is a child of an #ESource
 
2009
 * which has an #ESourceCollection extension, which means there is an
 
2010
 * #ECollectionBackend in the D-Bus service that can handle delete
 
2011
 * requests.  If @source does not have this capability, calls to
 
2012
 * e_source_remote_delete() will fail.
 
2013
 *
 
2014
 * Returns: whether @source can delete remote resources
 
2015
 *
 
2016
 * Since: 3.6
 
2017
 **/
 
2018
gboolean
 
2019
e_source_get_remote_deletable (ESource *source)
 
2020
{
 
2021
        EDBusObject *dbus_object;
 
2022
        EDBusSourceRemoteDeletable *dbus_source;
 
2023
 
 
2024
        g_return_val_if_fail (E_IS_SOURCE (source), FALSE);
 
2025
 
 
2026
        dbus_object = E_DBUS_OBJECT (source->priv->dbus_object);
 
2027
        dbus_source = e_dbus_object_peek_source_remote_deletable (dbus_object);
 
2028
 
 
2029
        return (dbus_source != NULL);
 
2030
}
 
2031
 
 
2032
/**
1646
2033
 * e_source_get_extension:
1647
2034
 * @source: an #ESource
1648
2035
 * @extension_name: an extension name
2013
2400
 * @error: return location for a #GError, or %NULL
2014
2401
 *
2015
2402
 * Requests the D-Bus service to delete the key files for @source and all of
2016
 
 * its descendants and broadcast their removal to all clients.  If an error
2017
 
 * occurs, the functon will set @error and return %FALSE.
 
2403
 * its descendants and broadcast their removal to all clients.  The @source
 
2404
 * must be #ESource:removable.
 
2405
 *
 
2406
 * If an error occurs, the functon will set @error and return %FALSE.
2018
2407
 *
2019
2408
 * Returns: %TRUE on success, %FALSE on failure
2020
2409
 *
2044
2433
 * @user_data: (closure): data to pass to the callback function
2045
2434
 *
2046
2435
 * Asynchronously requests the D-Bus service to delete the key files for
2047
 
 * @source all of its descendants and broadcast their removal to all clients.
 
2436
 * @source and all of its descendants and broadcast their removal to all
 
2437
 * clients.  The @source must be #ESource:removable.
2048
2438
 *
2049
2439
 * When the operation is finished, @callback will be called.  You can then
2050
2440
 * call e_source_remove_finish() to get the result of the operation.
2074
2464
 * @error: return location for a #GError, or %NULL
2075
2465
 *
2076
2466
 * Finishes the operation started with e_source_remove().  If an
2077
 
 * error occured, the function will set @error and return %FALSE.
 
2467
 * error occurred, the function will set @error and return %FALSE.
2078
2468
 *
2079
2469
 * Returns: %TRUE on success, %FALSE of failure
2080
2470
 *
2103
2493
 * @error: return location for a #GError, or %NULL
2104
2494
 *
2105
2495
 * Submits the current contents of @source to the D-Bus service to be
2106
 
 * written to disk and broadcast to other clients.  This can only be
2107
 
 * called on #ESource:writable data sources.
 
2496
 * written to disk and broadcast to other clients.  The @source must
 
2497
 * be #ESource:writable.
 
2498
 *
 
2499
 * If an error occurs, the functon will set @error and return %FALSE.
2108
2500
 *
2109
2501
 * Returns: %TRUE on success, %FALSE on failure
2110
2502
 *
2134
2526
 * @user_data: (closure): data to pass to the callback function
2135
2527
 *
2136
2528
 * Asynchronously submits the current contents of @source to the D-Bus
2137
 
 * service to be written to disk and broadcast to other clients.  This
2138
 
 * can only be called on #ESource:writable data sources.
 
2529
 * service to be written to disk and broadcast to other clients.  The
 
2530
 * @source must be #ESource:writable.
2139
2531
 *
2140
2532
 * When the operation is finished, @callback will be called.  You can then
2141
2533
 * call e_source_write_finish() to get the result of the operation.
2187
2579
        return class->write_finish (source, result, error);
2188
2580
}
2189
2581
 
 
2582
/**
 
2583
 * e_source_remote_create_sync:
 
2584
 * @source: an #ESource
 
2585
 * @scratch_source: an #ESource describing the resource to create
 
2586
 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
 
2587
 * @error: return location for a #GError, or %NULL
 
2588
 *
 
2589
 * Creates a new remote resource by picking out relevant details from
 
2590
 * @scratch_source.  The @scratch_source must be an #ESource with no
 
2591
 * #GDBusObject.  The @source must be #ESource:remote-creatable.
 
2592
 *
 
2593
 * The details required to create the resource vary by #ECollectionBackend,
 
2594
 * but in most cases the @scratch_source need only define the resource type
 
2595
 * (address book, calendar, etc.), a display name for the resource, and
 
2596
 * possibly a server-side path or ID for the resource.
 
2597
 *
 
2598
 * If an error occurs, the function will set @error and return %FALSE.
 
2599
 *
 
2600
 * Returns: %TRUE on success, %FALSE on failure
 
2601
 *
 
2602
 * Since: 3.6
 
2603
 **/
 
2604
gboolean
 
2605
e_source_remote_create_sync (ESource *source,
 
2606
                             ESource *scratch_source,
 
2607
                             GCancellable *cancellable,
 
2608
                             GError **error)
 
2609
{
 
2610
        ESourceClass *class;
 
2611
 
 
2612
        g_return_val_if_fail (E_IS_SOURCE (source), FALSE);
 
2613
        g_return_val_if_fail (E_IS_SOURCE (scratch_source), FALSE);
 
2614
 
 
2615
        class = E_SOURCE_GET_CLASS (source);
 
2616
        g_return_val_if_fail (class->remote_create_sync != NULL, FALSE);
 
2617
 
 
2618
        return class->remote_create_sync (
 
2619
                source, scratch_source, cancellable, error);
 
2620
}
 
2621
 
 
2622
/**
 
2623
 * e_source_remote_create:
 
2624
 * @source: an #ESource
 
2625
 * @scratch_source: an #ESource describing the resource to create
 
2626
 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
 
2627
 * @callback: (scope async): a #GAsyncReadyCallback to call when the request
 
2628
 *            is satisfied
 
2629
 * @user_data: (closure): data to pass to the callback function
 
2630
 *
 
2631
 * Asynchronously creates a new remote resource by picking out relevant
 
2632
 * details from @scratch_source.  The @scratch_source must be an #ESource
 
2633
 * with no #GDBusObject.  The @source must be #ESource:remote-creatable.
 
2634
 *
 
2635
 * The details required to create the resource vary by #ECollectionBackend,
 
2636
 * but in most cases the @scratch_source need only define the resource type
 
2637
 * (address book, calendar, etc.), a display name for the resource, and
 
2638
 * possibly a server-side path or ID for the resource.
 
2639
 *
 
2640
 * When the operation is finished, @callback will be called.  You can then
 
2641
 * call 3_source_remote_create_finish() to get the result of the operation.
 
2642
 *
 
2643
 * Since: 3.6
 
2644
 **/
 
2645
void
 
2646
e_source_remote_create (ESource *source,
 
2647
                        ESource *scratch_source,
 
2648
                        GCancellable *cancellable,
 
2649
                        GAsyncReadyCallback callback,
 
2650
                        gpointer user_data)
 
2651
{
 
2652
        ESourceClass *class;
 
2653
 
 
2654
        g_return_if_fail (E_IS_SOURCE (source));
 
2655
        g_return_if_fail (E_IS_SOURCE (scratch_source));
 
2656
 
 
2657
        class = E_SOURCE_GET_CLASS (source);
 
2658
        g_return_if_fail (class->remote_create != NULL);
 
2659
 
 
2660
        class->remote_create (
 
2661
                source, scratch_source,
 
2662
                cancellable, callback, user_data);
 
2663
}
 
2664
 
 
2665
/**
 
2666
 * e_source_remote_create_finish:
 
2667
 * @source: an #ESource
 
2668
 * @result: a #GAsyncResult
 
2669
 * @error: return location for a #GError, or %NULL
 
2670
 *
 
2671
 * Finishes the operation started with e_source_remote_create().  If
 
2672
 * an error occurred, the function will set @error and return %FALSE.
 
2673
 *
 
2674
 * Returns: %TRUE on success, %FALSE on failure
 
2675
 *
 
2676
 * Since: 3.6
 
2677
 **/
 
2678
gboolean
 
2679
e_source_remote_create_finish (ESource *source,
 
2680
                               GAsyncResult *result,
 
2681
                               GError **error)
 
2682
{
 
2683
        ESourceClass *class;
 
2684
 
 
2685
        g_return_val_if_fail (E_IS_SOURCE (source), FALSE);
 
2686
 
 
2687
        class = E_SOURCE_GET_CLASS (source);
 
2688
        g_return_val_if_fail (class->remote_create_finish != NULL, FALSE);
 
2689
 
 
2690
        return class->remote_create_finish (source, result, error);
 
2691
}
 
2692
 
 
2693
/**
 
2694
 * e_source_remote_delete_sync:
 
2695
 * @source: an #ESource
 
2696
 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
 
2697
 * @error: return location for a #GError, or %NULL
 
2698
 *
 
2699
 * Deletes the resource represented by @source from a remote server.
 
2700
 * The @source must be #ESource:remote-deletable.  This will also delete
 
2701
 * the key file for @source and broadcast its removal to all clients,
 
2702
 * similar to e_source_remove_sync().
 
2703
 *
 
2704
 * If an error occurs, the function will set @error and return %FALSE.
 
2705
 *
 
2706
 * Returns: %TRUE on success, %FALSE on failure
 
2707
 *
 
2708
 * Since: 3.6
 
2709
 **/
 
2710
gboolean
 
2711
e_source_remote_delete_sync (ESource *source,
 
2712
                             GCancellable *cancellable,
 
2713
                             GError **error)
 
2714
{
 
2715
        ESourceClass *class;
 
2716
 
 
2717
        g_return_val_if_fail (E_IS_SOURCE (source), FALSE);
 
2718
 
 
2719
        class = E_SOURCE_GET_CLASS (source);
 
2720
        g_return_val_if_fail (class->remote_delete_sync != NULL, FALSE);
 
2721
 
 
2722
        return class->remote_delete_sync (source, cancellable, error);
 
2723
}
 
2724
 
 
2725
/**
 
2726
 * e_source_remote_delete:
 
2727
 * @source: an #ESource
 
2728
 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
 
2729
 * @callback: (scope async): a #GAsyncReadyCallback to call when the request
 
2730
 *            is satisfied
 
2731
 * @user_data: (closure): data to pass to the callback function
 
2732
 *
 
2733
 * Asynchronously deletes the resource represented by @source from a remote
 
2734
 * server.  The @source must be #ESource:remote-deletable.  This will also
 
2735
 * delete the key file for @source and broadcast its removal to all clients,
 
2736
 * similar to e_source_remove().
 
2737
 *
 
2738
 * When the operation is finished, @callback will be called.  You can then
 
2739
 * call e_source_remote_delete_finish() to get the result of the operation.
 
2740
 *
 
2741
 * Since: 3.6
 
2742
 **/
 
2743
void
 
2744
e_source_remote_delete (ESource *source,
 
2745
                        GCancellable *cancellable,
 
2746
                        GAsyncReadyCallback callback,
 
2747
                        gpointer user_data)
 
2748
{
 
2749
        ESourceClass *class;
 
2750
 
 
2751
        g_return_if_fail (E_IS_SOURCE (source));
 
2752
 
 
2753
        class = E_SOURCE_GET_CLASS (source);
 
2754
        g_return_if_fail (class->remote_delete != NULL);
 
2755
 
 
2756
        class->remote_delete (source, cancellable, callback, user_data);
 
2757
}
 
2758
 
 
2759
/**
 
2760
 * e_source_remote_delete_finish:
 
2761
 * @source: an #ESource
 
2762
 * @result: a #GAsyncResult
 
2763
 * @error: return location for a #GError, or %NULL
 
2764
 *
 
2765
 * Finishes the operation started with e_source_remote_delete().  If
 
2766
 * an error occurred, the function will set @error and return %FALSE.
 
2767
 *
 
2768
 * Returns: %TRUE on success, %FALSE on failure
 
2769
 *
 
2770
 * Since: 3.6
 
2771
 **/
 
2772
gboolean
 
2773
e_source_remote_delete_finish (ESource *source,
 
2774
                               GAsyncResult *result,
 
2775
                               GError **error)
 
2776
{
 
2777
        ESourceClass *class;
 
2778
 
 
2779
        g_return_val_if_fail (E_IS_SOURCE (source), FALSE);
 
2780
 
 
2781
        class = E_SOURCE_GET_CLASS (source);
 
2782
        g_return_val_if_fail (class->remote_delete_finish != NULL, FALSE);
 
2783
 
 
2784
        return class->remote_delete_finish (source, result, error);
 
2785
}
 
2786