static gpointer book_view_thread (gpointer data) { EDataBookView *book_view = data; VCFBackendSearchClosure *closure = get_closure (book_view); const gchar *query; GList *l; /* ref the book view because it'll be removed and unrefed when/if it's stopped */ e_data_book_view_ref (book_view); query = e_data_book_view_get_card_query (book_view); if ( !strcmp (query, "(contains \"x-evolution-any-field\" \"\")")) e_data_book_view_notify_status_message (book_view, _("Loading...")); else e_data_book_view_notify_status_message (book_view, _("Searching...")); d(printf ("signalling parent thread\n")); e_flag_set (closure->running); for (l = closure->bvcf->priv->contact_list; l; l = l->next) { gchar *vcard_string = l->data; EContact *contact = e_contact_new_from_vcard (vcard_string); e_data_book_view_notify_update (closure->view, contact); g_object_unref (contact); if (!e_flag_is_set (closure->running)) break; } if (e_flag_is_set (closure->running)) e_data_book_view_notify_complete (closure->view, NULL /* Success */); /* unref the book view */ e_data_book_view_unref (book_view); d(printf ("finished initial population of book view\n")); return NULL; }
static void e_book_backend_vcf_stop_book_view (EBookBackend *backend, EDataBookView *book_view) { VCFBackendSearchClosure *closure = get_closure (book_view); gboolean need_join; d(printf ("stopping query\n")); need_join = e_flag_is_set (closure->running); e_flag_clear (closure->running); if (need_join) g_thread_join (closure->thread); }
static void e_book_backend_webdav_stop_view (EBookBackend *backend, EDataBookView *book_view) { WebdavBackendSearchClosure *closure; gboolean need_join; if (!e_backend_get_online (E_BACKEND (backend))) return; closure = get_closure (book_view); if (closure == NULL) return; need_join = e_flag_is_set (closure->running); e_flag_clear (closure->running); if (need_join) { g_thread_join (closure->thread); closure->thread = NULL; } }
static void ep_msg_send (EPassMsg *msg) { gint needidle = 0; G_LOCK (passwords); g_queue_push_tail (&message_queue, msg); if (!idle_id) { if (!msg->ismain) idle_id = g_idle_add (ep_idle_dispatch, NULL); else needidle = 1; } G_UNLOCK (passwords); if (msg->ismain) { if (needidle) ep_idle_dispatch (NULL); while (!e_flag_is_set (msg->done)) g_main_context_iteration (NULL, TRUE); } else e_flag_wait (msg->done); }
static GError * download_contacts (EBookBackendWebdav *webdav, EFlag *running, EDataBookView *book_view, GCancellable *cancellable) { EBookBackendWebdavPrivate *priv = webdav->priv; EBookBackend *book_backend; SoupMessage *message; guint status; xmlTextReaderPtr reader; response_element_t *elements; response_element_t *element; response_element_t *next; gint count; gint i; gchar *new_ctag = NULL; g_mutex_lock (&priv->update_lock); if (!check_addressbook_changed (webdav, &new_ctag, cancellable)) { g_free (new_ctag); g_mutex_unlock (&priv->update_lock); return EDB_ERROR (SUCCESS); } book_backend = E_BOOK_BACKEND (webdav); if (book_view != NULL) { e_data_book_view_notify_progress (book_view, -1, _("Loading Addressbook summary...")); } message = send_propfind (webdav, cancellable); status = message->status_code; if (status == 401 || status == 407) { g_object_unref (message); g_free (new_ctag); if (book_view) e_data_book_view_notify_progress (book_view, -1, NULL); g_mutex_unlock (&priv->update_lock); return webdav_handle_auth_request (webdav); } if (status != 207) { GError *error; error = e_data_book_create_error_fmt ( E_DATA_BOOK_STATUS_OTHER_ERROR, _("PROPFIND on webdav failed with HTTP status %d (%s)"), status, message->reason_phrase && *message->reason_phrase ? message->reason_phrase : (soup_status_get_phrase (message->status_code) ? soup_status_get_phrase (message->status_code) : _("Unknown error"))); g_object_unref (message); g_free (new_ctag); if (book_view) e_data_book_view_notify_progress (book_view, -1, NULL); g_mutex_unlock (&priv->update_lock); return error; } if (message->response_body == NULL) { g_warning ("No response body in webdav PROPFIND result"); g_object_unref (message); g_free (new_ctag); if (book_view) e_data_book_view_notify_progress (book_view, -1, NULL); g_mutex_unlock (&priv->update_lock); return e_data_book_create_error_fmt (E_DATA_BOOK_STATUS_OTHER_ERROR, _("No response body in webdav PROPFIND result")); } /* parse response */ reader = xmlReaderForMemory ( message->response_body->data, message->response_body->length, NULL, NULL, XML_PARSE_NOWARNING); elements = parse_propfind_response (reader); /* count contacts */ count = 0; for (element = elements; element != NULL; element = element->next) { ++count; } /* download contacts */ i = 0; for (element = elements; element != NULL; element = element->next, ++i) { const gchar *uri; const gchar *etag; EContact *contact; gchar *complete_uri; /* stop downloading if search was aborted */ if (running != NULL && !e_flag_is_set (running)) break; if (book_view != NULL) { gfloat percent = 100.0 / count * i; gchar buf[100]; snprintf (buf, sizeof (buf), _("Loading Contacts (%d%%)"), (gint) percent); e_data_book_view_notify_progress (book_view, -1, buf); } /* skip collections */ uri = (const gchar *) element->href; if (uri[strlen (uri) - 1] == '/') continue; /* uri might be relative, construct complete one */ if (uri[0] == '/') { SoupURI *soup_uri = soup_uri_new (priv->uri); soup_uri->path = g_strdup (uri); complete_uri = soup_uri_to_string (soup_uri, 0); soup_uri_free (soup_uri); } else { complete_uri = g_strdup (uri); } etag = (const gchar *) element->etag; g_mutex_lock (&priv->cache_lock); contact = e_book_backend_cache_get_contact (priv->cache, complete_uri); g_mutex_unlock (&priv->cache_lock); /* download contact if it is not cached or its ETag changed */ if (contact == NULL || etag == NULL || strcmp (e_contact_get_const (contact, E_CONTACT_REV), etag) != 0) { contact = download_contact (webdav, complete_uri, cancellable); if (contact != NULL) { g_mutex_lock (&priv->cache_lock); if (e_book_backend_cache_remove_contact (priv->cache, complete_uri)) e_book_backend_notify_remove (book_backend, complete_uri); e_book_backend_cache_add_contact (priv->cache, contact); g_mutex_unlock (&priv->cache_lock); e_book_backend_notify_update (book_backend, contact); } } g_free (complete_uri); } /* free element list */ for (element = elements; element != NULL; element = next) { next = element->next; xmlFree (element->href); xmlFree (element->etag); g_free (element); } xmlFreeTextReader (reader); g_object_unref (message); if (new_ctag) { g_mutex_lock (&priv->cache_lock); if (!e_file_cache_replace_object (E_FILE_CACHE (priv->cache), WEBDAV_CTAG_KEY, new_ctag)) e_file_cache_add_object (E_FILE_CACHE (priv->cache), WEBDAV_CTAG_KEY, new_ctag); g_mutex_unlock (&priv->cache_lock); } g_free (new_ctag); if (book_view) e_data_book_view_notify_progress (book_view, -1, NULL); g_mutex_unlock (&priv->update_lock); return EDB_ERROR (SUCCESS); }