Claim sources even when in offline
Partially addresses https://bugzilla.gnome.org/show_bug.cgi?id=678466
Milan Crha
11 years ago
187 | 187 | |
188 | 188 | g_error_free (*perror); |
189 | 189 | *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; | |
190 | 221 | } |
191 | 222 | |
192 | 223 | static gboolean |
960 | 991 | EwsCreateContact *create_contact; |
961 | 992 | EwsFolderId *fid; |
962 | 993 | EBookBackendEwsPrivate *priv; |
994 | GError *error = NULL; | |
963 | 995 | |
964 | 996 | if (vcards->next != NULL) { |
965 | 997 | e_data_book_respond_create_contacts ( |
983 | 1015 | return; |
984 | 1016 | } |
985 | 1017 | |
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); | |
988 | 1021 | return; |
989 | 1022 | } |
990 | 1023 | |
1077 | 1110 | EwsRemoveContact *remove_contact; |
1078 | 1111 | EBookBackendEwsPrivate *priv; |
1079 | 1112 | GSList *l, *copy = NULL; |
1113 | GError *error = NULL; | |
1080 | 1114 | |
1081 | 1115 | ebews = E_BOOK_BACKEND_EWS (backend); |
1082 | 1116 | |
1092 | 1126 | return; |
1093 | 1127 | } |
1094 | 1128 | |
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); | |
1097 | 1132 | return; |
1098 | 1133 | } |
1099 | 1134 | |
1267 | 1302 | return; |
1268 | 1303 | } |
1269 | 1304 | |
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); | |
1272 | 1308 | return; |
1273 | 1309 | } |
1274 | 1310 | |
1327 | 1363 | const gchar *id) |
1328 | 1364 | { |
1329 | 1365 | EBookBackendEws *ebews; |
1366 | GError *error = NULL; | |
1330 | 1367 | |
1331 | 1368 | ebews = E_BOOK_BACKEND_EWS (backend); |
1332 | 1369 | |
1333 | 1370 | 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); | |
1335 | 1372 | return; |
1336 | 1373 | } |
1337 | 1374 | |
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); | |
1340 | 1378 | return; |
1341 | 1379 | } |
1380 | ||
1342 | 1381 | e_data_book_respond_get_contact (book, opid, EDB_ERROR (CONTACT_NOT_FOUND), ""); |
1343 | 1382 | } |
1344 | 1383 | |
1381 | 1420 | return; |
1382 | 1421 | } |
1383 | 1422 | |
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); | |
1386 | 1426 | return; |
1387 | 1427 | } |
1388 | 1428 | |
2173 | 2213 | GSList *l; |
2174 | 2214 | GSList *contact_item_ids = NULL, *dl_ids = NULL; |
2175 | 2215 | GSList *new_items = NULL; |
2216 | ||
2217 | if (!book_backend_ews_ensure_connected (ebews, cancellable, error)) { | |
2218 | return FALSE; | |
2219 | } | |
2176 | 2220 | |
2177 | 2221 | priv = ebews->priv; |
2178 | 2222 | cnc = priv->cnc; |
2776 | 2820 | } |
2777 | 2821 | } else { |
2778 | 2822 | ebews->priv->cancellable = g_cancellable_new (); |
2823 | ebews->priv->is_writable = !ebews->priv->is_gal; | |
2779 | 2824 | |
2780 | 2825 | e_book_backend_set_writable (backend, ebews->priv->is_writable); |
2781 | 2826 | } |
216 | 216 | } |
217 | 217 | } |
218 | 218 | |
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 | ||
219 | 250 | static void |
220 | 251 | e_cal_backend_ews_add_timezone (ECalBackend *backend, |
221 | 252 | EDataCal *cal, |
324 | 355 | ECalBackendEwsPrivate *priv; |
325 | 356 | EwsDiscardAlarmData *edad; |
326 | 357 | ECalComponent *comp; |
358 | GError *local_error = NULL; | |
327 | 359 | |
328 | 360 | priv = cbews->priv; |
329 | 361 | |
339 | 371 | } |
340 | 372 | |
341 | 373 | 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 | } | |
342 | 380 | |
343 | 381 | /* FIXME: Can't there be multiple alarms for each event? Or does |
344 | 382 | * Exchange not support that? */ |
642 | 680 | |
643 | 681 | PRIV_LOCK (priv); |
644 | 682 | |
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 | } | |
650 | 690 | } |
651 | 691 | |
652 | 692 | /* search the object in the cache */ |
653 | 693 | comp = e_cal_backend_store_get_component (priv->store, uid, rid); |
654 | if (!comp) { | |
694 | if (!comp && e_backend_get_online (E_BACKEND (backend))) { | |
655 | 695 | /* maybe a meeting invitation, for which the calendar item is not downloaded yet, |
656 | 696 | * thus synchronize local cache first */ |
657 | 697 | ews_start_sync (cbews); |
905 | 945 | * This is actually an update event where an exception date will have to be appended to the master. |
906 | 946 | */ |
907 | 947 | 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 | } | |
908 | 954 | |
909 | 955 | priv = cbews->priv; |
910 | 956 | |
1666 | 1712 | goto exit; |
1667 | 1713 | } |
1668 | 1714 | |
1715 | if (!cal_backend_ews_ensure_connected (cbews, cancellable, &error)) { | |
1716 | goto exit; | |
1717 | } | |
1718 | ||
1669 | 1719 | /* parse ical data */ |
1670 | 1720 | comp = e_cal_component_new_from_string (calobj); |
1671 | 1721 | if (comp == NULL) { |
1672 | 1722 | g_propagate_error (&error, EDC_ERROR (InvalidObject)); |
1673 | return; | |
1723 | goto exit; | |
1674 | 1724 | } |
1675 | 1725 | icalcomp = e_cal_component_get_icalcomponent (comp); |
1676 | 1726 | |
2269 | 2319 | goto exit; |
2270 | 2320 | } |
2271 | 2321 | |
2322 | if (!cal_backend_ews_ensure_connected (cbews, cancellable, &error)) { | |
2323 | goto exit; | |
2324 | } | |
2325 | ||
2272 | 2326 | icalcomp = icalparser_parse_string (calobj); |
2273 | 2327 | if (!icalcomp) { |
2274 | 2328 | g_propagate_error (&error, EDC_ERROR (InvalidObject)); |
2581 | 2635 | /* make sure we're not offline */ |
2582 | 2636 | if (!e_backend_get_online (E_BACKEND (backend))) { |
2583 | 2637 | g_propagate_error (&error, EDC_ERROR (RepositoryOffline)); |
2638 | goto exit; | |
2639 | } | |
2640 | ||
2641 | if (!cal_backend_ews_ensure_connected (cbews, cancellable, &error)) { | |
2584 | 2642 | goto exit; |
2585 | 2643 | } |
2586 | 2644 | |
2892 | 2950 | goto exit; |
2893 | 2951 | } |
2894 | 2952 | |
2953 | if (!cal_backend_ews_ensure_connected (cbews, cancellable, &error)) { | |
2954 | goto exit; | |
2955 | } | |
2956 | ||
2895 | 2957 | icalcomp = icalparser_parse_string (calobj); |
2896 | 2958 | |
2897 | 2959 | /* make sure data was parsed properly */ |
3749 | 3811 | } |
3750 | 3812 | |
3751 | 3813 | ews_refreshing_inc (cbews); |
3814 | ||
3815 | if (!cbews->priv->cnc) { | |
3816 | ews_refreshing_dec (cbews); | |
3817 | PRIV_UNLOCK (cbews->priv); | |
3818 | return FALSE; | |
3819 | } | |
3752 | 3820 | PRIV_UNLOCK (cbews->priv); |
3753 | 3821 | |
3754 | 3822 | /* run the actual operation in thread, |
3968 | 4036 | /* make sure we're not offline */ |
3969 | 4037 | if (!e_backend_get_online (E_BACKEND (backend))) { |
3970 | 4038 | g_propagate_error (&error, EDC_ERROR (RepositoryOffline)); |
4039 | goto exit; | |
4040 | } | |
4041 | ||
4042 | if (!cal_backend_ews_ensure_connected (cbews, cancellable, &error)) { | |
3971 | 4043 | goto exit; |
3972 | 4044 | } |
3973 | 4045 |
544 | 544 | e_server_side_source_set_remote_deletable ( |
545 | 545 | E_SERVER_SIDE_SOURCE (source), TRUE); |
546 | 546 | e_source_registry_server_add_source (registry, source); |
547 | } else { | |
548 | e_source_registry_server_add_source (registry, source); | |
547 | 549 | } |
548 | 550 | } |
549 | 551 | |
643 | 645 | ews_backend->priv->need_update_folders = TRUE; |
644 | 646 | |
645 | 647 | /* 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)) | |
648 | 649 | return; |
649 | 650 | |
650 | 651 | /* For now at least, we don't need to know the |
1218 | 1219 | |
1219 | 1220 | g_return_val_if_fail (E_IS_EWS_BACKEND (backend), FALSE); |
1220 | 1221 | |
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 | ||
1221 | 1238 | connection = e_ews_backend_ref_connection_sync ( |
1222 | 1239 | backend, cancellable, error); |
1223 | 1240 |