Codebase list evolution-ews / ed4a49d
Claim sources even when in offline Partially addresses https://bugzilla.gnome.org/show_bug.cgi?id=678466 Milan Crha 11 years ago
3 changed file(s) with 154 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
187187
188188 g_error_free (*perror);
189189 *perror = error;
190 }
191
192 static gboolean
193 book_backend_ews_ensure_connected (EBookBackendEws *bbews,
194 GCancellable *cancellable,
195 GError **perror)
196 {
197 GError *local_error = NULL;
198
199 g_return_val_if_fail (E_IS_BOOK_BACKEND_EWS (bbews), FALSE);
200
201 PRIV_LOCK (bbews->priv);
202
203 if (bbews->priv->cnc) {
204 PRIV_UNLOCK (bbews->priv);
205 return TRUE;
206 }
207
208 PRIV_UNLOCK (bbews->priv);
209
210 e_backend_authenticate_sync (
211 E_BACKEND (bbews),
212 E_SOURCE_AUTHENTICATOR (bbews),
213 cancellable, &local_error);
214
215 if (!local_error)
216 return TRUE;
217
218 g_propagate_error (perror, local_error);
219
220 return FALSE;
190221 }
191222
192223 static gboolean
960991 EwsCreateContact *create_contact;
961992 EwsFolderId *fid;
962993 EBookBackendEwsPrivate *priv;
994 GError *error = NULL;
963995
964996 if (vcards->next != NULL) {
965997 e_data_book_respond_create_contacts (
9831015 return;
9841016 }
9851017
986 if (ebews->priv->cnc == NULL) {
987 e_data_book_respond_create_contacts (book, opid, EDB_ERROR (AUTHENTICATION_REQUIRED), NULL);
1018 if (!book_backend_ews_ensure_connected (ebews, cancellable, &error)) {
1019 convert_error_to_edb_error (&error);
1020 e_data_book_respond_create_contacts (book, opid, error, NULL);
9881021 return;
9891022 }
9901023
10771110 EwsRemoveContact *remove_contact;
10781111 EBookBackendEwsPrivate *priv;
10791112 GSList *l, *copy = NULL;
1113 GError *error = NULL;
10801114
10811115 ebews = E_BOOK_BACKEND_EWS (backend);
10821116
10921126 return;
10931127 }
10941128
1095 if (ebews->priv->cnc == NULL) {
1096 e_data_book_respond_remove_contacts (book, opid, EDB_ERROR (AUTHENTICATION_REQUIRED), NULL);
1129 if (!book_backend_ews_ensure_connected (ebews, cancellable, &error)) {
1130 convert_error_to_edb_error (&error);
1131 e_data_book_respond_remove_contacts (book, opid, error, NULL);
10971132 return;
10981133 }
10991134
12671302 return;
12681303 }
12691304
1270 if (priv->cnc == NULL) {
1271 e_data_book_respond_modify_contacts (book, opid, EDB_ERROR (AUTHENTICATION_REQUIRED), NULL);
1305 if (!book_backend_ews_ensure_connected (ebews, cancellable, &error)) {
1306 convert_error_to_edb_error (&error);
1307 e_data_book_respond_modify_contacts (book, opid, error, NULL);
12721308 return;
12731309 }
12741310
13271363 const gchar *id)
13281364 {
13291365 EBookBackendEws *ebews;
1366 GError *error = NULL;
13301367
13311368 ebews = E_BOOK_BACKEND_EWS (backend);
13321369
13331370 if (!e_backend_get_online (E_BACKEND (backend))) {
1334 e_data_book_respond_get_contact (book, opid, EDB_ERROR (CONTACT_NOT_FOUND), "");
1371 e_data_book_respond_get_contact (book, opid, EDB_ERROR (REPOSITORY_OFFLINE), NULL);
13351372 return;
13361373 }
13371374
1338 if (ebews->priv->cnc == NULL) {
1339 e_data_book_respond_get_contact (book, opid, e_data_book_create_error_fmt (E_DATA_BOOK_STATUS_OTHER_ERROR, "Not connected"), NULL);
1375 if (!book_backend_ews_ensure_connected (ebews, cancellable, &error)) {
1376 convert_error_to_edb_error (&error);
1377 e_data_book_respond_get_contact (book, opid, error, NULL);
13401378 return;
13411379 }
1380
13421381 e_data_book_respond_get_contact (book, opid, EDB_ERROR (CONTACT_NOT_FOUND), "");
13431382 }
13441383
13811420 return;
13821421 }
13831422
1384 if (priv->cnc == NULL) {
1385 e_data_book_respond_get_contact_list (book, opid, EDB_ERROR (AUTHENTICATION_REQUIRED), NULL);
1423 if (!book_backend_ews_ensure_connected (ebews, cancellable, &error)) {
1424 convert_error_to_edb_error (&error);
1425 e_data_book_respond_get_contact_list (book, opid, error, NULL);
13861426 return;
13871427 }
13881428
21732213 GSList *l;
21742214 GSList *contact_item_ids = NULL, *dl_ids = NULL;
21752215 GSList *new_items = NULL;
2216
2217 if (!book_backend_ews_ensure_connected (ebews, cancellable, error)) {
2218 return FALSE;
2219 }
21762220
21772221 priv = ebews->priv;
21782222 cnc = priv->cnc;
27762820 }
27772821 } else {
27782822 ebews->priv->cancellable = g_cancellable_new ();
2823 ebews->priv->is_writable = !ebews->priv->is_gal;
27792824
27802825 e_book_backend_set_writable (backend, ebews->priv->is_writable);
27812826 }
216216 }
217217 }
218218
219 static gboolean
220 cal_backend_ews_ensure_connected (ECalBackendEws *cbews,
221 GCancellable *cancellable,
222 GError **perror)
223 {
224 GError *local_error = NULL;
225
226 g_return_val_if_fail (E_IS_CAL_BACKEND_EWS (cbews), FALSE);
227
228 PRIV_LOCK (cbews->priv);
229
230 if (cbews->priv->cnc) {
231 PRIV_UNLOCK (cbews->priv);
232 return TRUE;
233 }
234
235 PRIV_UNLOCK (cbews->priv);
236
237 e_backend_authenticate_sync (
238 E_BACKEND (cbews),
239 E_SOURCE_AUTHENTICATOR (cbews),
240 cancellable, &local_error);
241
242 if (!local_error)
243 return TRUE;
244
245 g_propagate_error (perror, local_error);
246
247 return FALSE;
248 }
249
219250 static void
220251 e_cal_backend_ews_add_timezone (ECalBackend *backend,
221252 EDataCal *cal,
324355 ECalBackendEwsPrivate *priv;
325356 EwsDiscardAlarmData *edad;
326357 ECalComponent *comp;
358 GError *local_error = NULL;
327359
328360 priv = cbews->priv;
329361
339371 }
340372
341373 PRIV_UNLOCK (priv);
374
375 if (!cal_backend_ews_ensure_connected (cbews, cancellable, &local_error)) {
376 convert_error_to_edc_error (&local_error);
377 e_data_cal_respond_discard_alarm (cal, context, local_error);
378 return;
379 }
342380
343381 /* FIXME: Can't there be multiple alarms for each event? Or does
344382 * Exchange not support that? */
642680
643681 PRIV_LOCK (priv);
644682
645 /* make sure any pending refreshing is done */
646 while (priv->refreshing) {
647 PRIV_UNLOCK (priv);
648 e_flag_wait (priv->refreshing_done);
649 PRIV_LOCK (priv);
683 if (e_backend_get_online (E_BACKEND (backend))) {
684 /* make sure any pending refreshing is done */
685 while (priv->refreshing) {
686 PRIV_UNLOCK (priv);
687 e_flag_wait (priv->refreshing_done);
688 PRIV_LOCK (priv);
689 }
650690 }
651691
652692 /* search the object in the cache */
653693 comp = e_cal_backend_store_get_component (priv->store, uid, rid);
654 if (!comp) {
694 if (!comp && e_backend_get_online (E_BACKEND (backend))) {
655695 /* maybe a meeting invitation, for which the calendar item is not downloaded yet,
656696 * thus synchronize local cache first */
657697 ews_start_sync (cbews);
905945 * This is actually an update event where an exception date will have to be appended to the master.
906946 */
907947 e_data_cal_error_if_fail (E_IS_CAL_BACKEND_EWS (cbews), InvalidArg);
948
949 if (!cal_backend_ews_ensure_connected (cbews, cancellable, &error)) {
950 convert_error_to_edc_error (&error);
951 e_data_cal_respond_remove_objects (cal, context, error, NULL, NULL, NULL);
952 return;
953 }
908954
909955 priv = cbews->priv;
910956
16661712 goto exit;
16671713 }
16681714
1715 if (!cal_backend_ews_ensure_connected (cbews, cancellable, &error)) {
1716 goto exit;
1717 }
1718
16691719 /* parse ical data */
16701720 comp = e_cal_component_new_from_string (calobj);
16711721 if (comp == NULL) {
16721722 g_propagate_error (&error, EDC_ERROR (InvalidObject));
1673 return;
1723 goto exit;
16741724 }
16751725 icalcomp = e_cal_component_get_icalcomponent (comp);
16761726
22692319 goto exit;
22702320 }
22712321
2322 if (!cal_backend_ews_ensure_connected (cbews, cancellable, &error)) {
2323 goto exit;
2324 }
2325
22722326 icalcomp = icalparser_parse_string (calobj);
22732327 if (!icalcomp) {
22742328 g_propagate_error (&error, EDC_ERROR (InvalidObject));
25812635 /* make sure we're not offline */
25822636 if (!e_backend_get_online (E_BACKEND (backend))) {
25832637 g_propagate_error (&error, EDC_ERROR (RepositoryOffline));
2638 goto exit;
2639 }
2640
2641 if (!cal_backend_ews_ensure_connected (cbews, cancellable, &error)) {
25842642 goto exit;
25852643 }
25862644
28922950 goto exit;
28932951 }
28942952
2953 if (!cal_backend_ews_ensure_connected (cbews, cancellable, &error)) {
2954 goto exit;
2955 }
2956
28952957 icalcomp = icalparser_parse_string (calobj);
28962958
28972959 /* make sure data was parsed properly */
37493811 }
37503812
37513813 ews_refreshing_inc (cbews);
3814
3815 if (!cbews->priv->cnc) {
3816 ews_refreshing_dec (cbews);
3817 PRIV_UNLOCK (cbews->priv);
3818 return FALSE;
3819 }
37523820 PRIV_UNLOCK (cbews->priv);
37533821
37543822 /* run the actual operation in thread,
39684036 /* make sure we're not offline */
39694037 if (!e_backend_get_online (E_BACKEND (backend))) {
39704038 g_propagate_error (&error, EDC_ERROR (RepositoryOffline));
4039 goto exit;
4040 }
4041
4042 if (!cal_backend_ews_ensure_connected (cbews, cancellable, &error)) {
39714043 goto exit;
39724044 }
39734045
544544 e_server_side_source_set_remote_deletable (
545545 E_SERVER_SIDE_SOURCE (source), TRUE);
546546 e_source_registry_server_add_source (registry, source);
547 } else {
548 e_source_registry_server_add_source (registry, source);
547549 }
548550 }
549551
643645 ews_backend->priv->need_update_folders = TRUE;
644646
645647 /* do not do anything, if account is disabled */
646 if (!e_source_get_enabled (source) ||
647 !e_backend_get_online (E_BACKEND (backend)))
648 if (!e_source_get_enabled (source))
648649 return;
649650
650651 /* For now at least, we don't need to know the
12181219
12191220 g_return_val_if_fail (E_IS_EWS_BACKEND (backend), FALSE);
12201221
1222 if (!e_backend_get_online (E_BACKEND (backend))) {
1223 SyncFoldersClosure *closure;
1224
1225 /* This takes ownership of the folder lists. */
1226 closure = g_slice_new0 (SyncFoldersClosure);
1227 closure->backend = g_object_ref (backend);
1228
1229 /* Process the results from an idle callback. */
1230 g_idle_add_full (
1231 G_PRIORITY_DEFAULT_IDLE,
1232 ews_backend_sync_folders_idle_cb, closure,
1233 (GDestroyNotify) sync_folders_closure_free);
1234
1235 return TRUE;
1236 }
1237
12211238 connection = e_ews_backend_ref_connection_sync (
12221239 backend, cancellable, error);
12231240