[evolution-data-server] Whitespace fixes for the Google Contacts addressbook backend
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Whitespace fixes for the Google Contacts addressbook backend
- Date: Mon, 19 Apr 2010 21:38:04 +0000 (UTC)
commit 182ba4f5d5e3f8bd27e3300430ecf0bf4bef0fb5
Author: Philip Withnall <philip tecnocode co uk>
Date: Mon Apr 19 22:37:38 2010 +0100
Whitespace fixes for the Google Contacts addressbook backend
.../backends/google/e-book-backend-google.c | 1102 +++++++-------
.../backends/google/e-book-backend-google.h | 16 +-
addressbook/backends/google/google-book.c | 1608 ++++++++++----------
addressbook/backends/google/google-book.h | 50 +-
addressbook/backends/google/util.c | 1329 ++++++++---------
addressbook/backends/google/util.h | 21 +-
6 files changed, 1972 insertions(+), 2154 deletions(-)
---
diff --git a/addressbook/backends/google/e-book-backend-google.c b/addressbook/backends/google/e-book-backend-google.c
index 7f31afe..6f498a1 100644
--- a/addressbook/backends/google/e-book-backend-google.c
+++ b/addressbook/backends/google/e-book-backend-google.c
@@ -36,766 +36,702 @@
G_DEFINE_TYPE (EBookBackendGoogle, e_book_backend_google, E_TYPE_BOOK_BACKEND_SYNC)
-struct _EBookBackendGooglePrivate
-{
- GNOME_Evolution_Addressbook_BookMode mode;
- GoogleBook *book;
- GList *bookviews;
+struct _EBookBackendGooglePrivate {
+ GNOME_Evolution_Addressbook_BookMode mode;
+ GoogleBook *book;
+ GList *bookviews;
};
-#define GET_PRIVATE(obj) \
- (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
- E_TYPE_BOOK_BACKEND_GOOGLE, \
- EBookBackendGooglePrivate))
+#define GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), E_TYPE_BOOK_BACKEND_GOOGLE, EBookBackendGooglePrivate))
gboolean __e_book_backend_google_debug__;
static EBookBackendSyncStatus e_book_backend_status_from_google_book_error (GError *error);
static EBookBackendSyncStatus
-e_book_backend_google_create_contact (EBookBackendSync *backend,
- EDataBook *book,
- guint32 opid,
- const gchar *vcard_str,
- EContact **out_contact)
+e_book_backend_google_create_contact (EBookBackendSync *backend, EDataBook *book, guint32 opid, const gchar *vcard_str, EContact **out_contact)
{
- EBookBackendGooglePrivate *priv;
- EBookBackendSyncStatus status = GNOME_Evolution_Addressbook_OtherError;
- EContact *contact;
- GError *error = NULL;
-
- __debug__ (G_STRFUNC);
- priv = GET_PRIVATE (backend);
-
- __debug__ ("Creating: %s", vcard_str);
- *out_contact = NULL;
-
- if (priv->mode != GNOME_Evolution_Addressbook_MODE_REMOTE) {
- return GNOME_Evolution_Addressbook_OfflineUnavailable;
- }
-
- contact = e_contact_new_from_vcard (vcard_str);
- google_book_add_contact (priv->book, contact, out_contact, &error);
- g_object_unref (contact);
- if (error) {
- status = e_book_backend_status_from_google_book_error (error);
- __debug__ ("Creating contact failed: %s", error->message);
- g_clear_error (&error);
+ EBookBackendGooglePrivate *priv;
+ EBookBackendSyncStatus status = GNOME_Evolution_Addressbook_OtherError;
+ EContact *contact;
+ GError *error = NULL;
+
+ __debug__ (G_STRFUNC);
+ priv = GET_PRIVATE (backend);
+
+ __debug__ ("Creating: %s", vcard_str);
*out_contact = NULL;
- return status;
- }
- return GNOME_Evolution_Addressbook_Success;
+ if (priv->mode != GNOME_Evolution_Addressbook_MODE_REMOTE)
+ return GNOME_Evolution_Addressbook_OfflineUnavailable;
+
+ contact = e_contact_new_from_vcard (vcard_str);
+ google_book_add_contact (priv->book, contact, out_contact, &error);
+ g_object_unref (contact);
+
+ if (error) {
+ status = e_book_backend_status_from_google_book_error (error);
+ __debug__ ("Creating contact failed: %s", error->message);
+ g_clear_error (&error);
+ *out_contact = NULL;
+ return status;
+ }
+
+ return GNOME_Evolution_Addressbook_Success;
}
static EBookBackendSyncStatus
-e_book_backend_google_remove_contacts (EBookBackendSync *backend,
- EDataBook *book,
- guint32 opid,
- GList *id_list,
- GList **ids)
+e_book_backend_google_remove_contacts (EBookBackendSync *backend, EDataBook *book, guint32 opid, GList *id_list, GList **ids)
{
- EBookBackendGooglePrivate *priv;
- EBookBackendSyncStatus status = GNOME_Evolution_Addressbook_OtherError;
- GList *id_iter;
+ EBookBackendGooglePrivate *priv;
+ EBookBackendSyncStatus status = GNOME_Evolution_Addressbook_OtherError;
+ GList *id_iter;
- __debug__ (G_STRFUNC);
- priv = GET_PRIVATE (backend);
+ __debug__ (G_STRFUNC);
+ priv = GET_PRIVATE (backend);
- *ids = NULL;
+ *ids = NULL;
- if (priv->mode != GNOME_Evolution_Addressbook_MODE_REMOTE) {
- return GNOME_Evolution_Addressbook_OfflineUnavailable;
- }
+ if (priv->mode != GNOME_Evolution_Addressbook_MODE_REMOTE)
+ return GNOME_Evolution_Addressbook_OfflineUnavailable;
- for (id_iter = id_list; id_iter; id_iter = id_iter->next) {
- GError *error = NULL;
- const gchar *uid;
+ for (id_iter = id_list; id_iter; id_iter = id_iter->next) {
+ GError *error = NULL;
+ const gchar *uid;
- uid = id_iter->data;
- google_book_remove_contact (priv->book, uid, &error);
- if (error) {
- /* Only last error will be reported */
- status = e_book_backend_status_from_google_book_error (error);
- __debug__ ("Deleting contact %s failed: %s", uid, error->message);
- g_clear_error (&error);
- } else {
- *ids = g_list_append (*ids, g_strdup (uid));
+ uid = id_iter->data;
+ google_book_remove_contact (priv->book, uid, &error);
+
+ if (error) {
+ /* Only last error will be reported */
+ status = e_book_backend_status_from_google_book_error (error);
+ __debug__ ("Deleting contact %s failed: %s", uid, error->message);
+ g_clear_error (&error);
+ } else {
+ *ids = g_list_append (*ids, g_strdup (uid));
+ }
}
- }
- if (NULL == *ids) {
- return status;
- }
- return GNOME_Evolution_Addressbook_Success;
+ if (!*ids)
+ return status;
+
+ return GNOME_Evolution_Addressbook_Success;
}
static EBookBackendSyncStatus
-e_book_backend_google_modify_contact (EBookBackendSync *backend,
- EDataBook *book,
- guint32 opid,
- const gchar *vcard_str,
- EContact **out_contact)
+e_book_backend_google_modify_contact (EBookBackendSync *backend, EDataBook *book, guint32 opid, const gchar *vcard_str, EContact **out_contact)
{
- EBookBackendGooglePrivate *priv;
- EBookBackendSyncStatus status = GNOME_Evolution_Addressbook_OtherError;
- EContact *contact;
- GError *error = NULL;
-
- __debug__ (G_STRFUNC);
- priv = GET_PRIVATE (backend);
-
- __debug__ ("Updating: %s", vcard_str);
- *out_contact = NULL;
-
- if (priv->mode != GNOME_Evolution_Addressbook_MODE_REMOTE) {
- return GNOME_Evolution_Addressbook_OfflineUnavailable;
- }
-
- contact = e_contact_new_from_vcard (vcard_str);
- google_book_update_contact (priv->book, contact, out_contact, &error);
- g_object_unref (contact);
- if (error) {
- status = e_book_backend_status_from_google_book_error (error);
- __debug__ ("Modifying contact failed: %s", error->message);
- g_clear_error (&error);
+ EBookBackendGooglePrivate *priv;
+ EBookBackendSyncStatus status = GNOME_Evolution_Addressbook_OtherError;
+ EContact *contact;
+ GError *error = NULL;
+
+ __debug__ (G_STRFUNC);
+ priv = GET_PRIVATE (backend);
+
+ __debug__ ("Updating: %s", vcard_str);
*out_contact = NULL;
- return status;
- }
- return GNOME_Evolution_Addressbook_Success;
+ if (priv->mode != GNOME_Evolution_Addressbook_MODE_REMOTE)
+ return GNOME_Evolution_Addressbook_OfflineUnavailable;
+
+ contact = e_contact_new_from_vcard (vcard_str);
+ google_book_update_contact (priv->book, contact, out_contact, &error);
+ g_object_unref (contact);
+
+ if (error) {
+ status = e_book_backend_status_from_google_book_error (error);
+ __debug__ ("Modifying contact failed: %s", error->message);
+ g_clear_error (&error);
+ *out_contact = NULL;
+ return status;
+ }
+
+ return GNOME_Evolution_Addressbook_Success;
}
static EBookBackendSyncStatus
-e_book_backend_google_get_contact (EBookBackendSync *backend,
- EDataBook *book,
- guint32 opid,
- const gchar *uid,
- gchar **vcard_str)
+e_book_backend_google_get_contact (EBookBackendSync *backend, EDataBook *book, guint32 opid, const gchar *uid, gchar **vcard_str)
{
- EBookBackendGooglePrivate *priv;
- EBookBackendSyncStatus status = GNOME_Evolution_Addressbook_OtherError;
- EContact *contact;
- GError *error = NULL;
-
- __debug__ (G_STRFUNC);
- priv = GET_PRIVATE (backend);
-
- contact = google_book_get_contact (priv->book, uid, &error);
- if (error) {
- status = e_book_backend_status_from_google_book_error (error);
- __debug__ ("Getting contact with uid %s failed: %s", uid, error->message);
- g_clear_error (&error);
- return status;
- }
- *vcard_str = e_vcard_to_string (E_VCARD (contact), EVC_FORMAT_VCARD_30);
- g_object_unref (contact);
+ EBookBackendGooglePrivate *priv;
+ EBookBackendSyncStatus status = GNOME_Evolution_Addressbook_OtherError;
+ EContact *contact;
+ GError *error = NULL;
+
+ __debug__ (G_STRFUNC);
+ priv = GET_PRIVATE (backend);
- return GNOME_Evolution_Addressbook_Success;
+ contact = google_book_get_contact (priv->book, uid, &error);
+
+ if (error) {
+ status = e_book_backend_status_from_google_book_error (error);
+ __debug__ ("Getting contact with uid %s failed: %s", uid, error->message);
+ g_clear_error (&error);
+ return status;
+ }
+
+ *vcard_str = e_vcard_to_string (E_VCARD (contact), EVC_FORMAT_VCARD_30);
+ g_object_unref (contact);
+
+ return GNOME_Evolution_Addressbook_Success;
}
static EBookBackendSyncStatus
-e_book_backend_google_get_contact_list (EBookBackendSync *backend,
- EDataBook *book,
- guint32 opid,
- const gchar *query,
- GList **contacts)
+e_book_backend_google_get_contact_list (EBookBackendSync *backend, EDataBook *book, guint32 opid, const gchar *query, GList **contacts)
{
- EBookBackendGooglePrivate *priv;
- EBookBackendSyncStatus status = GNOME_Evolution_Addressbook_OtherError;
- EBookBackendSExp *sexp;
- GError *error = NULL;
- GList *all_contacts;
-
- __debug__ (G_STRFUNC);
- priv = GET_PRIVATE (backend);
-
- *contacts = NULL;
-
- all_contacts = google_book_get_all_contacts (priv->book, &error);
- if (error) {
- status = e_book_backend_status_from_google_book_error (error);
- __debug__ ("Getting all contacts failed: %s", error->message);
- g_clear_error (&error);
- return status;
- }
+ EBookBackendGooglePrivate *priv;
+ EBookBackendSyncStatus status = GNOME_Evolution_Addressbook_OtherError;
+ EBookBackendSExp *sexp;
+ GError *error = NULL;
+ GList *all_contacts;
- sexp = e_book_backend_sexp_new (query);
- while (all_contacts) {
- EContact *contact;
+ __debug__ (G_STRFUNC);
+ priv = GET_PRIVATE (backend);
+
+ *contacts = NULL;
+
+ all_contacts = google_book_get_all_contacts (priv->book, &error);
- contact = all_contacts->data;
- if (e_book_backend_sexp_match_contact (sexp, contact)) {
- gchar *vcard_str;
- vcard_str = e_vcard_to_string (E_VCARD (contact), EVC_FORMAT_VCARD_30);
- *contacts = g_list_append (*contacts, vcard_str);
+ if (error) {
+ status = e_book_backend_status_from_google_book_error (error);
+ __debug__ ("Getting all contacts failed: %s", error->message);
+ g_clear_error (&error);
+ return status;
}
- g_object_unref (contact);
- all_contacts = g_list_delete_link (all_contacts, all_contacts);
- }
- g_object_unref (sexp);
- return GNOME_Evolution_Addressbook_Success;
+ sexp = e_book_backend_sexp_new (query);
+ while (all_contacts) {
+ EContact *contact;
+
+ contact = all_contacts->data;
+ if (e_book_backend_sexp_match_contact (sexp, contact)) {
+ gchar *vcard_str = e_vcard_to_string (E_VCARD (contact), EVC_FORMAT_VCARD_30);
+ *contacts = g_list_append (*contacts, vcard_str);
+ }
+ g_object_unref (contact);
+
+ all_contacts = g_list_delete_link (all_contacts, all_contacts);
+ }
+ g_object_unref (sexp);
+
+ return GNOME_Evolution_Addressbook_Success;
}
static void
on_google_book_contact_added (GoogleBook *book, EContact *contact, gpointer user_data)
{
- EBookBackendGooglePrivate *priv;
- GList *iter;
-
- priv = GET_PRIVATE (user_data);
- for (iter = priv->bookviews; iter; iter = iter->next) {
- g_object_ref (contact);
- e_data_book_view_notify_update (E_DATA_BOOK_VIEW (iter->data), contact);
- }
+ EBookBackendGooglePrivate *priv = GET_PRIVATE (user_data);
+ GList *iter;
+
+ for (iter = priv->bookviews; iter; iter = iter->next) {
+ g_object_ref (contact);
+ e_data_book_view_notify_update (E_DATA_BOOK_VIEW (iter->data), contact);
+ }
}
static void
on_google_book_contact_removed (GoogleBook *book, const gchar *uid, gpointer user_data)
{
- EBookBackendGooglePrivate *priv;
- GList *iter;
+ EBookBackendGooglePrivate *priv = GET_PRIVATE (user_data);
+ GList *iter;
- priv = GET_PRIVATE (user_data);
- for (iter = priv->bookviews; iter; iter = iter->next) {
- e_data_book_view_notify_remove (E_DATA_BOOK_VIEW (iter->data), g_strdup (uid));
- }
+ for (iter = priv->bookviews; iter; iter = iter->next)
+ e_data_book_view_notify_remove (E_DATA_BOOK_VIEW (iter->data), g_strdup (uid));
}
static void
on_google_book_contact_changed (GoogleBook *book, EContact *contact, gpointer user_data)
{
- EBookBackendGooglePrivate *priv;
- GList *iter;
-
- priv = GET_PRIVATE (user_data);
- for (iter = priv->bookviews; iter; iter = iter->next) {
- g_object_ref (contact);
- e_data_book_view_notify_update (E_DATA_BOOK_VIEW (iter->data), contact);
- }
+ EBookBackendGooglePrivate *priv = GET_PRIVATE (user_data);
+ GList *iter;
+
+ for (iter = priv->bookviews; iter; iter = iter->next) {
+ g_object_ref (contact);
+ e_data_book_view_notify_update (E_DATA_BOOK_VIEW (iter->data), contact);
+ }
}
static void
on_google_book_sequence_complete (GoogleBook *book, GError *error, gpointer user_data)
{
- EBookBackendGooglePrivate *priv;
- EBookBackendSyncStatus status = GNOME_Evolution_Addressbook_Success;
- GList *iter;
-
- priv = GET_PRIVATE (user_data);
- if (error) {
- status = e_book_backend_status_from_google_book_error (error);
- __debug__ ("Book-view query failed: %s", error->message);
- g_clear_error (&error);
- }
- for (iter = priv->bookviews; iter; iter = iter->next) {
- e_data_book_view_notify_complete (E_DATA_BOOK_VIEW (iter->data), GNOME_Evolution_Addressbook_Success);
- }
+ EBookBackendGooglePrivate *priv = GET_PRIVATE (user_data);
+ EBookBackendSyncStatus status = GNOME_Evolution_Addressbook_Success;
+ GList *iter;
+
+ if (error) {
+ status = e_book_backend_status_from_google_book_error (error);
+ __debug__ ("Book-view query failed: %s", error->message);
+ g_clear_error (&error);
+ }
+
+ for (iter = priv->bookviews; iter; iter = iter->next)
+ e_data_book_view_notify_complete (E_DATA_BOOK_VIEW (iter->data), GNOME_Evolution_Addressbook_Success);
}
static void
-e_book_backend_google_start_book_view (EBookBackend *backend,
- EDataBookView *bookview)
+e_book_backend_google_start_book_view (EBookBackend *backend, EDataBookView *bookview)
{
- EBookBackendGooglePrivate *priv;
- GList *cached_contacts;
+ EBookBackendGooglePrivate *priv;
+ GList *cached_contacts;
- g_return_if_fail (E_IS_BOOK_BACKEND_GOOGLE (backend));
- g_return_if_fail (E_IS_DATA_BOOK_VIEW (bookview));
+ g_return_if_fail (E_IS_BOOK_BACKEND_GOOGLE (backend));
+ g_return_if_fail (E_IS_DATA_BOOK_VIEW (bookview));
- __debug__ (G_STRFUNC);
- priv = GET_PRIVATE (backend);
+ __debug__ (G_STRFUNC);
+ priv = GET_PRIVATE (backend);
- priv->bookviews = g_list_append (priv->bookviews, bookview);
+ priv->bookviews = g_list_append (priv->bookviews, bookview);
- e_data_book_view_ref (bookview);
- e_data_book_view_notify_status_message (bookview, "Loading...");
+ e_data_book_view_ref (bookview);
+ e_data_book_view_notify_status_message (bookview, "Loading...");
- google_book_set_live_mode (priv->book, TRUE);
- cached_contacts = google_book_get_all_contacts_in_live_mode (priv->book);
- while (cached_contacts) {
- EContact *contact = cached_contacts->data;
+ google_book_set_live_mode (priv->book, TRUE);
+ cached_contacts = google_book_get_all_contacts_in_live_mode (priv->book);
+ while (cached_contacts) {
+ EContact *contact = cached_contacts->data;
- e_data_book_view_notify_update (bookview, contact);
- g_object_unref (contact);
- cached_contacts = g_list_delete_link (cached_contacts, cached_contacts);
- }
- e_data_book_view_notify_complete (bookview, GNOME_Evolution_Addressbook_Success);
+ e_data_book_view_notify_update (bookview, contact);
+ g_object_unref (contact);
+ cached_contacts = g_list_delete_link (cached_contacts, cached_contacts);
+ }
+ e_data_book_view_notify_complete (bookview, GNOME_Evolution_Addressbook_Success);
}
static void
-e_book_backend_google_stop_book_view (EBookBackend *backend,
- EDataBookView *bookview)
+e_book_backend_google_stop_book_view (EBookBackend *backend, EDataBookView *bookview)
{
- EBookBackendGooglePrivate *priv;
+ EBookBackendGooglePrivate *priv;
- __debug__ (G_STRFUNC);
- priv = GET_PRIVATE (backend);
+ __debug__ (G_STRFUNC);
+ priv = GET_PRIVATE (backend);
- priv->bookviews = g_list_remove (priv->bookviews, bookview);
- e_data_book_view_unref (bookview);
+ priv->bookviews = g_list_remove (priv->bookviews, bookview);
+ e_data_book_view_unref (bookview);
- if (NULL == priv->bookviews) {
- google_book_set_live_mode (priv->book, FALSE);
- }
+ if (!priv->bookviews)
+ google_book_set_live_mode (priv->book, FALSE);
}
static EBookBackendSyncStatus
-e_book_backend_google_authenticate_user (EBookBackendSync *backend,
- EDataBook *book,
- guint32 opid,
- const gchar *username,
- const gchar *password,
- const gchar *auth_method)
+e_book_backend_google_authenticate_user (EBookBackendSync *backend, EDataBook *book, guint32 opid,
+ const gchar *username, const gchar *password, const gchar *auth_method)
{
- EBookBackendGooglePrivate *priv;
- EBookBackendSyncStatus status = GNOME_Evolution_Addressbook_Success;
- GError *error = NULL;
- gchar *book_username;
- gboolean match;
+ EBookBackendGooglePrivate *priv;
+ EBookBackendSyncStatus status = GNOME_Evolution_Addressbook_Success;
+ GError *error = NULL;
+ gchar *book_username;
+ gboolean match;
- __debug__ (G_STRFUNC);
- priv = GET_PRIVATE (backend);
+ __debug__ (G_STRFUNC);
+ priv = GET_PRIVATE (backend);
- if (priv->mode != GNOME_Evolution_Addressbook_MODE_REMOTE) {
- return GNOME_Evolution_Addressbook_Success;
- }
-
- if (NULL == username || username[0] == 0) {
- return GNOME_Evolution_Addressbook_AuthenticationFailed;
- }
-
- g_object_get (G_OBJECT (priv->book),
- "username", &book_username,
- NULL);
-
- match = (0 == strcmp (username, book_username));
- g_free (book_username);
- if (FALSE == match) {
- g_warning ("Username given when loading source and on authentication did not match!");
- return GNOME_Evolution_Addressbook_AuthenticationRequired;
- }
-
- google_book_connect_to_google (priv->book, password, &error);
- if (error) {
- status = e_book_backend_status_from_google_book_error (error);
- __debug__ ("Authentication failed: %s", error->message);
- g_clear_error (&error);
- } else {
- e_book_backend_notify_writable (E_BOOK_BACKEND (backend), TRUE);
- }
-
- return status;
+ if (priv->mode != GNOME_Evolution_Addressbook_MODE_REMOTE)
+ return GNOME_Evolution_Addressbook_Success;
+
+ if (!username || username[0] == 0)
+ return GNOME_Evolution_Addressbook_AuthenticationFailed;
+
+ g_object_get (G_OBJECT (priv->book), "username", &book_username, NULL);
+
+ match = (0 == strcmp (username, book_username));
+ g_free (book_username);
+ if (FALSE == match) {
+ g_warning ("Username given when loading source and on authentication did not match!");
+ return GNOME_Evolution_Addressbook_AuthenticationRequired;
+ }
+
+ google_book_connect_to_google (priv->book, password, &error);
+ if (error) {
+ status = e_book_backend_status_from_google_book_error (error);
+ __debug__ ("Authentication failed: %s", error->message);
+ g_clear_error (&error);
+ } else {
+ e_book_backend_notify_writable (E_BOOK_BACKEND (backend), TRUE);
+ }
+
+ return status;
}
static EBookBackendSyncStatus
-e_book_backend_google_get_supported_auth_methods (EBookBackendSync *backend,
- EDataBook *book,
- guint32 opid,
- GList **methods)
+e_book_backend_google_get_supported_auth_methods (EBookBackendSync *backend, EDataBook *book, guint32 opid, GList **methods)
{
- gchar *auth_method;
+ gchar *auth_method;
- __debug__ (G_STRFUNC);
- auth_method = g_strdup_printf ("plain/password");
- *methods = g_list_append (NULL, auth_method);
+ __debug__ (G_STRFUNC);
+ auth_method = g_strdup_printf ("plain/password");
+ *methods = g_list_append (NULL, auth_method);
- return GNOME_Evolution_Addressbook_Success;
+ return GNOME_Evolution_Addressbook_Success;
}
static EBookBackendSyncStatus
-e_book_backend_google_get_required_fields (EBookBackendSync *backend,
- EDataBook *book,
- guint32 opid,
- GList **fields_out)
+e_book_backend_google_get_required_fields (EBookBackendSync *backend, EDataBook *book, guint32 opid, GList **fields_out)
{
- __debug__ (G_STRFUNC);
+ __debug__ (G_STRFUNC);
- *fields_out = NULL;
- return GNOME_Evolution_Addressbook_Success;
+ *fields_out = NULL;
+ return GNOME_Evolution_Addressbook_Success;
}
static EBookBackendSyncStatus
-e_book_backend_google_get_supported_fields (EBookBackendSync *backend,
- EDataBook *book,
- guint32 opid,
- GList **fields_out)
+e_book_backend_google_get_supported_fields (EBookBackendSync *backend, EDataBook *book, guint32 opid, GList **fields_out)
{
- const gint supported_fields[] =
- {
- E_CONTACT_FULL_NAME,
- E_CONTACT_EMAIL_1,
- E_CONTACT_EMAIL_2,
- E_CONTACT_EMAIL_3,
- E_CONTACT_EMAIL_4,
- E_CONTACT_ADDRESS_LABEL_HOME,
- E_CONTACT_ADDRESS_LABEL_WORK,
- E_CONTACT_ADDRESS_LABEL_OTHER,
- E_CONTACT_PHONE_HOME,
- E_CONTACT_PHONE_HOME_FAX,
- E_CONTACT_PHONE_BUSINESS,
- E_CONTACT_PHONE_BUSINESS_FAX,
- E_CONTACT_PHONE_MOBILE,
- E_CONTACT_PHONE_PAGER,
- E_CONTACT_IM_AIM,
- E_CONTACT_IM_JABBER,
- E_CONTACT_IM_YAHOO,
- E_CONTACT_IM_MSN,
- E_CONTACT_IM_ICQ,
- E_CONTACT_IM_SKYPE,
- E_CONTACT_IM_GADUGADU,
- E_CONTACT_IM_GROUPWISE,
- E_CONTACT_ADDRESS,
- E_CONTACT_ADDRESS_HOME,
- E_CONTACT_ADDRESS_WORK,
- E_CONTACT_ADDRESS_OTHER,
- E_CONTACT_NAME,
- E_CONTACT_GIVEN_NAME,
- E_CONTACT_FAMILY_NAME,
- E_CONTACT_PHONE_ASSISTANT,
- E_CONTACT_PHONE_BUSINESS_2,
- E_CONTACT_PHONE_CALLBACK,
- E_CONTACT_PHONE_CAR,
- E_CONTACT_PHONE_COMPANY,
- E_CONTACT_PHONE_HOME_2,
- E_CONTACT_PHONE_ISDN,
- E_CONTACT_PHONE_OTHER,
- E_CONTACT_PHONE_OTHER_FAX,
- E_CONTACT_PHONE_PRIMARY,
- E_CONTACT_PHONE_RADIO,
- E_CONTACT_PHONE_TELEX,
- E_CONTACT_PHONE_TTYTDD,
- E_CONTACT_IM_AIM_HOME_1,
- E_CONTACT_IM_AIM_HOME_2,
- E_CONTACT_IM_AIM_HOME_3,
- E_CONTACT_IM_AIM_WORK_1,
- E_CONTACT_IM_AIM_WORK_2,
- E_CONTACT_IM_AIM_WORK_3,
- E_CONTACT_IM_GROUPWISE_HOME_1,
- E_CONTACT_IM_GROUPWISE_HOME_2,
- E_CONTACT_IM_GROUPWISE_HOME_3,
- E_CONTACT_IM_GROUPWISE_WORK_1,
- E_CONTACT_IM_GROUPWISE_WORK_2,
- E_CONTACT_IM_GROUPWISE_WORK_3,
- E_CONTACT_IM_JABBER_HOME_1,
- E_CONTACT_IM_JABBER_HOME_2,
- E_CONTACT_IM_JABBER_HOME_3,
- E_CONTACT_IM_JABBER_WORK_1,
- E_CONTACT_IM_JABBER_WORK_2,
- E_CONTACT_IM_JABBER_WORK_3,
- E_CONTACT_IM_YAHOO_HOME_1,
- E_CONTACT_IM_YAHOO_HOME_2,
- E_CONTACT_IM_YAHOO_HOME_3,
- E_CONTACT_IM_YAHOO_WORK_1,
- E_CONTACT_IM_YAHOO_WORK_2,
- E_CONTACT_IM_YAHOO_WORK_3,
- E_CONTACT_IM_MSN_HOME_1,
- E_CONTACT_IM_MSN_HOME_2,
- E_CONTACT_IM_MSN_HOME_3,
- E_CONTACT_IM_MSN_WORK_1,
- E_CONTACT_IM_MSN_WORK_2,
- E_CONTACT_IM_MSN_WORK_3,
- E_CONTACT_IM_ICQ_HOME_1,
- E_CONTACT_IM_ICQ_HOME_2,
- E_CONTACT_IM_ICQ_HOME_3,
- E_CONTACT_IM_ICQ_WORK_1,
- E_CONTACT_IM_ICQ_WORK_2,
- E_CONTACT_IM_ICQ_WORK_3,
- E_CONTACT_EMAIL,
- E_CONTACT_IM_GADUGADU_HOME_1,
- E_CONTACT_IM_GADUGADU_HOME_2,
- E_CONTACT_IM_GADUGADU_HOME_3,
- E_CONTACT_IM_GADUGADU_WORK_1,
- E_CONTACT_IM_GADUGADU_WORK_2,
- E_CONTACT_IM_GADUGADU_WORK_3,
- E_CONTACT_TEL,
- E_CONTACT_IM_SKYPE_HOME_1,
- E_CONTACT_IM_SKYPE_HOME_2,
- E_CONTACT_IM_SKYPE_HOME_3,
- E_CONTACT_IM_SKYPE_WORK_1,
- E_CONTACT_IM_SKYPE_WORK_2,
- E_CONTACT_IM_SKYPE_WORK_3,
- E_CONTACT_SIP
- };
- GList *fields = NULL;
- guint i;
-
- __debug__ (G_STRFUNC);
-
- for (i = 0; i < G_N_ELEMENTS (supported_fields); i++) {
- const gchar *field_name;
-
- field_name = e_contact_field_name (supported_fields[i]);
- fields = g_list_append (fields, g_strdup (field_name));
- }
-
- *fields_out = fields;
- return GNOME_Evolution_Addressbook_Success;
+ GList *fields = NULL;
+ guint i;
+ const gint supported_fields[] = {
+ E_CONTACT_FULL_NAME,
+ E_CONTACT_EMAIL_1,
+ E_CONTACT_EMAIL_2,
+ E_CONTACT_EMAIL_3,
+ E_CONTACT_EMAIL_4,
+ E_CONTACT_ADDRESS_LABEL_HOME,
+ E_CONTACT_ADDRESS_LABEL_WORK,
+ E_CONTACT_ADDRESS_LABEL_OTHER,
+ E_CONTACT_PHONE_HOME,
+ E_CONTACT_PHONE_HOME_FAX,
+ E_CONTACT_PHONE_BUSINESS,
+ E_CONTACT_PHONE_BUSINESS_FAX,
+ E_CONTACT_PHONE_MOBILE,
+ E_CONTACT_PHONE_PAGER,
+ E_CONTACT_IM_AIM,
+ E_CONTACT_IM_JABBER,
+ E_CONTACT_IM_YAHOO,
+ E_CONTACT_IM_MSN,
+ E_CONTACT_IM_ICQ,
+ E_CONTACT_IM_SKYPE,
+ E_CONTACT_IM_GADUGADU,
+ E_CONTACT_IM_GROUPWISE,
+ E_CONTACT_ADDRESS,
+ E_CONTACT_ADDRESS_HOME,
+ E_CONTACT_ADDRESS_WORK,
+ E_CONTACT_ADDRESS_OTHER,
+ E_CONTACT_NAME,
+ E_CONTACT_GIVEN_NAME,
+ E_CONTACT_FAMILY_NAME,
+ E_CONTACT_PHONE_ASSISTANT,
+ E_CONTACT_PHONE_BUSINESS_2,
+ E_CONTACT_PHONE_CALLBACK,
+ E_CONTACT_PHONE_CAR,
+ E_CONTACT_PHONE_COMPANY,
+ E_CONTACT_PHONE_HOME_2,
+ E_CONTACT_PHONE_ISDN,
+ E_CONTACT_PHONE_OTHER,
+ E_CONTACT_PHONE_OTHER_FAX,
+ E_CONTACT_PHONE_PRIMARY,
+ E_CONTACT_PHONE_RADIO,
+ E_CONTACT_PHONE_TELEX,
+ E_CONTACT_PHONE_TTYTDD,
+ E_CONTACT_IM_AIM_HOME_1,
+ E_CONTACT_IM_AIM_HOME_2,
+ E_CONTACT_IM_AIM_HOME_3,
+ E_CONTACT_IM_AIM_WORK_1,
+ E_CONTACT_IM_AIM_WORK_2,
+ E_CONTACT_IM_AIM_WORK_3,
+ E_CONTACT_IM_GROUPWISE_HOME_1,
+ E_CONTACT_IM_GROUPWISE_HOME_2,
+ E_CONTACT_IM_GROUPWISE_HOME_3,
+ E_CONTACT_IM_GROUPWISE_WORK_1,
+ E_CONTACT_IM_GROUPWISE_WORK_2,
+ E_CONTACT_IM_GROUPWISE_WORK_3,
+ E_CONTACT_IM_JABBER_HOME_1,
+ E_CONTACT_IM_JABBER_HOME_2,
+ E_CONTACT_IM_JABBER_HOME_3,
+ E_CONTACT_IM_JABBER_WORK_1,
+ E_CONTACT_IM_JABBER_WORK_2,
+ E_CONTACT_IM_JABBER_WORK_3,
+ E_CONTACT_IM_YAHOO_HOME_1,
+ E_CONTACT_IM_YAHOO_HOME_2,
+ E_CONTACT_IM_YAHOO_HOME_3,
+ E_CONTACT_IM_YAHOO_WORK_1,
+ E_CONTACT_IM_YAHOO_WORK_2,
+ E_CONTACT_IM_YAHOO_WORK_3,
+ E_CONTACT_IM_MSN_HOME_1,
+ E_CONTACT_IM_MSN_HOME_2,
+ E_CONTACT_IM_MSN_HOME_3,
+ E_CONTACT_IM_MSN_WORK_1,
+ E_CONTACT_IM_MSN_WORK_2,
+ E_CONTACT_IM_MSN_WORK_3,
+ E_CONTACT_IM_ICQ_HOME_1,
+ E_CONTACT_IM_ICQ_HOME_2,
+ E_CONTACT_IM_ICQ_HOME_3,
+ E_CONTACT_IM_ICQ_WORK_1,
+ E_CONTACT_IM_ICQ_WORK_2,
+ E_CONTACT_IM_ICQ_WORK_3,
+ E_CONTACT_EMAIL,
+ E_CONTACT_IM_GADUGADU_HOME_1,
+ E_CONTACT_IM_GADUGADU_HOME_2,
+ E_CONTACT_IM_GADUGADU_HOME_3,
+ E_CONTACT_IM_GADUGADU_WORK_1,
+ E_CONTACT_IM_GADUGADU_WORK_2,
+ E_CONTACT_IM_GADUGADU_WORK_3,
+ E_CONTACT_TEL,
+ E_CONTACT_IM_SKYPE_HOME_1,
+ E_CONTACT_IM_SKYPE_HOME_2,
+ E_CONTACT_IM_SKYPE_HOME_3,
+ E_CONTACT_IM_SKYPE_WORK_1,
+ E_CONTACT_IM_SKYPE_WORK_2,
+ E_CONTACT_IM_SKYPE_WORK_3,
+ E_CONTACT_SIP
+ };
+
+ __debug__ (G_STRFUNC);
+
+ for (i = 0; i < G_N_ELEMENTS (supported_fields); i++) {
+ const gchar *field_name = e_contact_field_name (supported_fields[i]);
+ fields = g_list_append (fields, g_strdup (field_name));
+ }
+
+ *fields_out = fields;
+ return GNOME_Evolution_Addressbook_Success;
}
static EBookBackendSyncStatus
-e_book_backend_google_get_changes (EBookBackendSync *backend,
- EDataBook *book,
- guint32 opid,
- const gchar *change_id,
- GList **changes_out)
+e_book_backend_google_get_changes (EBookBackendSync *backend, EDataBook *book, guint32 opid, const gchar *change_id, GList **changes_out)
{
- __debug__ (G_STRFUNC);
- return GNOME_Evolution_Addressbook_OtherError;
+ __debug__ (G_STRFUNC);
+ return GNOME_Evolution_Addressbook_OtherError;
}
static EBookBackendSyncStatus
-e_book_backend_google_remove (EBookBackendSync *backend,
- EDataBook *book,
- guint32 opid)
+e_book_backend_google_remove (EBookBackendSync *backend, EDataBook *book, guint32 opid)
{
- __debug__ (G_STRFUNC);
- return GNOME_Evolution_Addressbook_Success;
+ __debug__ (G_STRFUNC);
+ return GNOME_Evolution_Addressbook_Success;
}
static void
on_google_book_auth_required (GoogleBook *book, gpointer user_data)
{
- __debug__ (G_STRFUNC);
- e_book_backend_notify_auth_required (E_BOOK_BACKEND (user_data));
+ __debug__ (G_STRFUNC);
+ e_book_backend_notify_auth_required (E_BOOK_BACKEND (user_data));
}
static GNOME_Evolution_Addressbook_CallStatus
-e_book_backend_google_load_source (EBookBackend *backend,
- ESource *source,
- gboolean only_if_exists)
+e_book_backend_google_load_source (EBookBackend *backend, ESource *source, gboolean only_if_exists)
{
- EBookBackendGooglePrivate *priv = GET_PRIVATE (backend);
- const gchar *refresh_interval_str, *use_ssl_str, *use_cache_str;
- guint refresh_interval;
- gboolean use_ssl, use_cache;
- const gchar *username;
-
- if (priv->book) {
- g_warning ("Source already loaded!");
- return GNOME_Evolution_Addressbook_OtherError;
- }
+ EBookBackendGooglePrivate *priv = GET_PRIVATE (backend);
+ const gchar *refresh_interval_str, *use_ssl_str, *use_cache_str;
+ guint refresh_interval;
+ gboolean use_ssl, use_cache;
+ const gchar *username;
+
+ if (priv->book) {
+ g_warning ("Source already loaded!");
+ return GNOME_Evolution_Addressbook_OtherError;
+ }
- username = e_source_get_property (source, "username");
+ username = e_source_get_property (source, "username");
- if (NULL == username || username[0] == '\0') {
- g_warning ("No or empty username!");
- return GNOME_Evolution_Addressbook_OtherError;
- }
+ if (!username || username[0] == '\0') {
+ g_warning ("No or empty username!");
+ return GNOME_Evolution_Addressbook_OtherError;
+ }
- refresh_interval_str = e_source_get_property (source, "refresh-interval");
- use_ssl_str = e_source_get_property (source, "ssl");
- use_cache_str = e_source_get_property (source, "offline_sync");
+ refresh_interval_str = e_source_get_property (source, "refresh-interval");
+ use_ssl_str = e_source_get_property (source, "ssl");
+ use_cache_str = e_source_get_property (source, "offline_sync");
- if (refresh_interval_str) {
- if (1 != sscanf (refresh_interval_str, "%u", &refresh_interval)) {
- g_warning ("Could not parse refresh-interval!");
- refresh_interval = 3600;
+ if (refresh_interval_str && sscanf (refresh_interval_str, "%u", &refresh_interval) != 1) {
+ g_warning ("Could not parse refresh-interval!");
+ refresh_interval = 3600;
}
- }
-
- use_ssl = TRUE;
- if (use_ssl_str) {
- if (0 == g_ascii_strcasecmp (use_ssl_str, "false") || 0 == strcmp (use_ssl_str, "0"))
- use_ssl = FALSE;
- }
-
- use_cache = TRUE;
- if (use_cache_str) {
- if (0 == g_ascii_strcasecmp (use_cache_str, "false") || 0 == strcmp (use_cache_str, "0"))
- use_cache = FALSE;
- }
-
- priv->book = google_book_new (username, use_cache);
-
- g_object_set (G_OBJECT (priv->book),
- "refresh-interval", refresh_interval,
- "use-ssl", use_ssl,
- NULL);
- g_object_connect (G_OBJECT (priv->book),
- "signal::contact-added", G_CALLBACK (on_google_book_contact_added), backend,
- "signal::contact-changed", G_CALLBACK (on_google_book_contact_changed), backend,
- "signal::contact-removed", G_CALLBACK (on_google_book_contact_removed), backend,
- "signal::sequence-complete", G_CALLBACK (on_google_book_sequence_complete), backend,
- "signal::auth-required", G_CALLBACK (on_google_book_auth_required), backend,
- NULL);
-
- __debug__ (G_STRFUNC);
-
- e_book_backend_set_is_loaded (backend, TRUE);
- e_book_backend_notify_connection_status (backend, TRUE);
- e_book_backend_set_is_writable (backend, FALSE);
- google_book_set_offline_mode (priv->book, (priv->mode == GNOME_Evolution_Addressbook_MODE_LOCAL));
-
- return GNOME_Evolution_Addressbook_Success;
+
+ use_ssl = TRUE;
+ if (use_ssl_str && (g_ascii_strcasecmp (use_ssl_str, "false") == 0 || strcmp (use_ssl_str, "0") == 0))
+ use_ssl = FALSE;
+
+ use_cache = TRUE;
+ if (use_cache_str && (g_ascii_strcasecmp (use_cache_str, "false") == 0 || strcmp (use_cache_str, "0") == 0))
+ use_cache = FALSE;
+
+ priv->book = google_book_new (username, use_cache);
+
+ g_object_set (G_OBJECT (priv->book),
+ "refresh-interval", refresh_interval,
+ "use-ssl", use_ssl,
+ NULL);
+ g_object_connect (G_OBJECT (priv->book),
+ "signal::contact-added", G_CALLBACK (on_google_book_contact_added), backend,
+ "signal::contact-changed", G_CALLBACK (on_google_book_contact_changed), backend,
+ "signal::contact-removed", G_CALLBACK (on_google_book_contact_removed), backend,
+ "signal::sequence-complete", G_CALLBACK (on_google_book_sequence_complete), backend,
+ "signal::auth-required", G_CALLBACK (on_google_book_auth_required), backend,
+ NULL);
+
+ __debug__ (G_STRFUNC);
+
+ e_book_backend_set_is_loaded (backend, TRUE);
+ e_book_backend_notify_connection_status (backend, TRUE);
+ e_book_backend_set_is_writable (backend, FALSE);
+ google_book_set_offline_mode (priv->book, (priv->mode == GNOME_Evolution_Addressbook_MODE_LOCAL));
+
+ return GNOME_Evolution_Addressbook_Success;
}
static gchar *
e_book_backend_google_get_static_capabilities (EBookBackend *backend)
{
- __debug__ (G_STRFUNC);
- return g_strdup("net,do-initial-query,contact-lists");
+ __debug__ (G_STRFUNC);
+ return g_strdup("net,do-initial-query,contact-lists");
}
static GNOME_Evolution_Addressbook_CallStatus
e_book_backend_google_cancel_operation (EBookBackend *backend, EDataBook *book)
{
- __debug__ (G_STRFUNC);
- return GNOME_Evolution_Addressbook_CouldNotCancel;
+ __debug__ (G_STRFUNC);
+ return GNOME_Evolution_Addressbook_CouldNotCancel;
}
static void
e_book_backend_google_set_mode (EBookBackend *backend, GNOME_Evolution_Addressbook_BookMode mode)
{
- EBookBackendGooglePrivate *priv = GET_PRIVATE (backend);
- gboolean online = (mode == GNOME_Evolution_Addressbook_MODE_REMOTE);
+ EBookBackendGooglePrivate *priv = GET_PRIVATE (backend);
+ gboolean online = (mode == GNOME_Evolution_Addressbook_MODE_REMOTE);
- __debug__ (G_STRFUNC);
+ __debug__ (G_STRFUNC);
- if (mode == priv->mode) {
- return;
- }
+ if (mode == priv->mode)
+ return;
- priv->mode = mode;
+ priv->mode = mode;
- if (priv->book)
- google_book_set_offline_mode (priv->book, !online);
- e_book_backend_notify_connection_status (backend, online);
+ if (priv->book)
+ google_book_set_offline_mode (priv->book, !online);
+ e_book_backend_notify_connection_status (backend, online);
- /* Mark the book as unwriteable if we're going offline, but don't do the inverse when we go online;
- * e_book_backend_google_authenticate_user() will mark us as writeable again once the user's authenticated again. */
- if (!online)
- e_book_backend_notify_writable (backend, FALSE);
+ /* Mark the book as unwriteable if we're going offline, but don't do the inverse when we go online;
+ * e_book_backend_google_authenticate_user() will mark us as writeable again once the user's authenticated again. */
+ if (!online)
+ e_book_backend_notify_writable (backend, FALSE);
}
static void
e_book_backend_google_dispose (GObject *object)
{
- EBookBackendGooglePrivate *priv = GET_PRIVATE (object);
+ EBookBackendGooglePrivate *priv = GET_PRIVATE (object);
- __debug__ (G_STRFUNC);
+ __debug__ (G_STRFUNC);
- while (priv->bookviews) {
- e_data_book_view_unref (priv->bookviews->data);
- priv->bookviews = g_list_delete_link (priv->bookviews,
- priv->bookviews);
- }
- if (priv->book) {
- g_object_unref (priv->book);
- priv->book = NULL;
- }
+ while (priv->bookviews) {
+ e_data_book_view_unref (priv->bookviews->data);
+ priv->bookviews = g_list_delete_link (priv->bookviews, priv->bookviews);
+ }
+
+ if (priv->book) {
+ g_object_unref (priv->book);
+ priv->book = NULL;
+ }
- G_OBJECT_CLASS (e_book_backend_google_parent_class)->dispose (object);
+ G_OBJECT_CLASS (e_book_backend_google_parent_class)->dispose (object);
}
static void
e_book_backend_google_finalize (GObject *object)
{
- __debug__ (G_STRFUNC);
+ __debug__ (G_STRFUNC);
- G_OBJECT_CLASS (e_book_backend_google_parent_class)->finalize (object);
+ G_OBJECT_CLASS (e_book_backend_google_parent_class)->finalize (object);
}
static void
e_book_backend_google_class_init (EBookBackendGoogleClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- EBookBackendClass *backend_class;
- EBookBackendSyncClass *sync_class;
-
- backend_class = E_BOOK_BACKEND_CLASS (klass);
- sync_class = E_BOOK_BACKEND_SYNC_CLASS (klass);
- g_type_class_add_private (klass, sizeof (EBookBackendGooglePrivate));
-
- /* Set the virtual methods. */
- backend_class->load_source = e_book_backend_google_load_source;
- backend_class->get_static_capabilities = e_book_backend_google_get_static_capabilities;
- backend_class->start_book_view = e_book_backend_google_start_book_view;
- backend_class->stop_book_view = e_book_backend_google_stop_book_view;
- backend_class->cancel_operation = e_book_backend_google_cancel_operation;
- backend_class->set_mode = e_book_backend_google_set_mode;
- sync_class->remove_sync = e_book_backend_google_remove;
- sync_class->create_contact_sync = e_book_backend_google_create_contact;
- sync_class->remove_contacts_sync = e_book_backend_google_remove_contacts;
- sync_class->modify_contact_sync = e_book_backend_google_modify_contact;
- sync_class->get_contact_sync = e_book_backend_google_get_contact;
- sync_class->get_contact_list_sync = e_book_backend_google_get_contact_list;
- sync_class->get_changes_sync = e_book_backend_google_get_changes;
- sync_class->authenticate_user_sync = e_book_backend_google_authenticate_user;
- sync_class->get_supported_fields_sync = e_book_backend_google_get_supported_fields;
- sync_class->get_required_fields_sync = e_book_backend_google_get_required_fields;
- sync_class->get_supported_auth_methods_sync = e_book_backend_google_get_supported_auth_methods;
-
- object_class->dispose = e_book_backend_google_dispose;
- object_class->finalize = e_book_backend_google_finalize;
-
- __e_book_backend_google_debug__ = g_getenv ("GOOGLE_BACKEND_DEBUG") ? TRUE : FALSE;
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ EBookBackendClass *backend_class;
+ EBookBackendSyncClass *sync_class;
+
+ backend_class = E_BOOK_BACKEND_CLASS (klass);
+ sync_class = E_BOOK_BACKEND_SYNC_CLASS (klass);
+ g_type_class_add_private (klass, sizeof (EBookBackendGooglePrivate));
+
+ /* Set the virtual methods. */
+ backend_class->load_source = e_book_backend_google_load_source;
+ backend_class->get_static_capabilities = e_book_backend_google_get_static_capabilities;
+ backend_class->start_book_view = e_book_backend_google_start_book_view;
+ backend_class->stop_book_view = e_book_backend_google_stop_book_view;
+ backend_class->cancel_operation = e_book_backend_google_cancel_operation;
+ backend_class->set_mode = e_book_backend_google_set_mode;
+ sync_class->remove_sync = e_book_backend_google_remove;
+ sync_class->create_contact_sync = e_book_backend_google_create_contact;
+ sync_class->remove_contacts_sync = e_book_backend_google_remove_contacts;
+ sync_class->modify_contact_sync = e_book_backend_google_modify_contact;
+ sync_class->get_contact_sync = e_book_backend_google_get_contact;
+ sync_class->get_contact_list_sync = e_book_backend_google_get_contact_list;
+ sync_class->get_changes_sync = e_book_backend_google_get_changes;
+ sync_class->authenticate_user_sync = e_book_backend_google_authenticate_user;
+ sync_class->get_supported_fields_sync = e_book_backend_google_get_supported_fields;
+ sync_class->get_required_fields_sync = e_book_backend_google_get_required_fields;
+ sync_class->get_supported_auth_methods_sync = e_book_backend_google_get_supported_auth_methods;
+
+ object_class->dispose = e_book_backend_google_dispose;
+ object_class->finalize = e_book_backend_google_finalize;
+
+ __e_book_backend_google_debug__ = g_getenv ("GOOGLE_BACKEND_DEBUG") ? TRUE : FALSE;
}
static void
e_book_backend_google_init (EBookBackendGoogle *backend)
{
- __debug__ (G_STRFUNC);
+ __debug__ (G_STRFUNC);
}
EBookBackend *
e_book_backend_google_new (void)
{
- EBookBackendGoogle *backend;
+ EBookBackendGoogle *backend;
- __debug__ (G_STRFUNC);
- backend = g_object_new (E_TYPE_BOOK_BACKEND_GOOGLE, NULL);
+ __debug__ (G_STRFUNC);
+ backend = g_object_new (E_TYPE_BOOK_BACKEND_GOOGLE, NULL);
- return E_BOOK_BACKEND (backend);
+ return E_BOOK_BACKEND (backend);
}
static EBookBackendSyncStatus
e_book_backend_status_from_google_book_error (GError *error)
{
- if (!error)
- return GNOME_Evolution_Addressbook_Success;
-
- if (error->domain == GDATA_AUTHENTICATION_ERROR) {
- /* Authentication errors */
- switch (error->code) {
- case GDATA_AUTHENTICATION_ERROR_BAD_AUTHENTICATION:
- return GNOME_Evolution_Addressbook_AuthenticationFailed;
- case GDATA_AUTHENTICATION_ERROR_NOT_VERIFIED:
- case GDATA_AUTHENTICATION_ERROR_TERMS_NOT_AGREED:
- case GDATA_AUTHENTICATION_ERROR_CAPTCHA_REQUIRED:
- case GDATA_AUTHENTICATION_ERROR_ACCOUNT_DELETED:
- case GDATA_AUTHENTICATION_ERROR_ACCOUNT_DISABLED:
- return GNOME_Evolution_Addressbook_PermissionDenied;
- case GDATA_AUTHENTICATION_ERROR_SERVICE_DISABLED:
- return GNOME_Evolution_Addressbook_RepositoryOffline;
- default:
- return GNOME_Evolution_Addressbook_OtherError;
- }
- } else if (error->domain == GDATA_SERVICE_ERROR) {
- /* General service errors */
- switch (error->code) {
- case GDATA_SERVICE_ERROR_UNAVAILABLE:
- return GNOME_Evolution_Addressbook_RepositoryOffline;
- case GDATA_SERVICE_ERROR_PROTOCOL_ERROR:
- return GNOME_Evolution_Addressbook_InvalidQuery;
- case GDATA_SERVICE_ERROR_ENTRY_ALREADY_INSERTED:
- return GNOME_Evolution_Addressbook_ContactIdAlreadyExists;
- case GDATA_SERVICE_ERROR_AUTHENTICATION_REQUIRED:
- return GNOME_Evolution_Addressbook_AuthenticationRequired;
- case GDATA_SERVICE_ERROR_NOT_FOUND:
- return GNOME_Evolution_Addressbook_ContactNotFound;
- case GDATA_SERVICE_ERROR_CONFLICT:
- return GNOME_Evolution_Addressbook_ContactIdAlreadyExists;
- case GDATA_SERVICE_ERROR_FORBIDDEN:
- return GNOME_Evolution_Addressbook_QueryRefused;
- case GDATA_SERVICE_ERROR_BAD_QUERY_PARAMETER:
- return GNOME_Evolution_Addressbook_InvalidQuery;
- default:
- return GNOME_Evolution_Addressbook_OtherError;
- }
- }
-
- return GNOME_Evolution_Addressbook_OtherError;
+ if (!error)
+ return GNOME_Evolution_Addressbook_Success;
+
+ if (error->domain == GDATA_AUTHENTICATION_ERROR) {
+ /* Authentication errors */
+ switch (error->code) {
+ case GDATA_AUTHENTICATION_ERROR_BAD_AUTHENTICATION:
+ return GNOME_Evolution_Addressbook_AuthenticationFailed;
+ case GDATA_AUTHENTICATION_ERROR_NOT_VERIFIED:
+ case GDATA_AUTHENTICATION_ERROR_TERMS_NOT_AGREED:
+ case GDATA_AUTHENTICATION_ERROR_CAPTCHA_REQUIRED:
+ case GDATA_AUTHENTICATION_ERROR_ACCOUNT_DELETED:
+ case GDATA_AUTHENTICATION_ERROR_ACCOUNT_DISABLED:
+ return GNOME_Evolution_Addressbook_PermissionDenied;
+ case GDATA_AUTHENTICATION_ERROR_SERVICE_DISABLED:
+ return GNOME_Evolution_Addressbook_RepositoryOffline;
+ default:
+ return GNOME_Evolution_Addressbook_OtherError;
+ }
+ } else if (error->domain == GDATA_SERVICE_ERROR) {
+ /* General service errors */
+ switch (error->code) {
+ case GDATA_SERVICE_ERROR_UNAVAILABLE:
+ return GNOME_Evolution_Addressbook_RepositoryOffline;
+ case GDATA_SERVICE_ERROR_PROTOCOL_ERROR:
+ return GNOME_Evolution_Addressbook_InvalidQuery;
+ case GDATA_SERVICE_ERROR_ENTRY_ALREADY_INSERTED:
+ return GNOME_Evolution_Addressbook_ContactIdAlreadyExists;
+ case GDATA_SERVICE_ERROR_AUTHENTICATION_REQUIRED:
+ return GNOME_Evolution_Addressbook_AuthenticationRequired;
+ case GDATA_SERVICE_ERROR_NOT_FOUND:
+ return GNOME_Evolution_Addressbook_ContactNotFound;
+ case GDATA_SERVICE_ERROR_CONFLICT:
+ return GNOME_Evolution_Addressbook_ContactIdAlreadyExists;
+ case GDATA_SERVICE_ERROR_FORBIDDEN:
+ return GNOME_Evolution_Addressbook_QueryRefused;
+ case GDATA_SERVICE_ERROR_BAD_QUERY_PARAMETER:
+ return GNOME_Evolution_Addressbook_InvalidQuery;
+ default:
+ return GNOME_Evolution_Addressbook_OtherError;
+ }
+ }
+
+ return GNOME_Evolution_Addressbook_OtherError;
}
diff --git a/addressbook/backends/google/e-book-backend-google.h b/addressbook/backends/google/e-book-backend-google.h
index 05de74e..63e201a 100644
--- a/addressbook/backends/google/e-book-backend-google.h
+++ b/addressbook/backends/google/e-book-backend-google.h
@@ -35,18 +35,16 @@ typedef struct _EBookBackendGoogle EBookBackendGoogle;
typedef struct _EBookBackendGoogleClass EBookBackendGoogleClass;
typedef struct _EBookBackendGooglePrivate EBookBackendGooglePrivate;
-struct _EBookBackendGoogle
-{
- EBookBackendSync parent_object;
- EBookBackendGooglePrivate *priv;
+struct _EBookBackendGoogle {
+ EBookBackendSync parent_object;
+ EBookBackendGooglePrivate *priv;
};
-struct _EBookBackendGoogleClass
-{
- EBookBackendSyncClass parent_class;
+struct _EBookBackendGoogleClass {
+ EBookBackendSyncClass parent_class;
};
-EBookBackend *e_book_backend_google_new (void);
-GType e_book_backend_google_get_type (void);
+EBookBackend *e_book_backend_google_new (void);
+GType e_book_backend_google_get_type (void);
#endif /* __E_BOOK_BACKEND_GOOGLE_H__ */
diff --git a/addressbook/backends/google/google-book.c b/addressbook/backends/google/google-book.c
index c3b9ce3..cc11ad6 100644
--- a/addressbook/backends/google/google-book.c
+++ b/addressbook/backends/google/google-book.c
@@ -36,363 +36,354 @@ G_DEFINE_TYPE (GoogleBook, google_book, G_TYPE_OBJECT)
#define URI_GET_CONTACTS "://www.google.com/m8/feeds/contacts/default/full"
-#define GET_PRIVATE(o) \
- (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_GOOGLE_BOOK, GoogleBookPrivate))
+#define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_GOOGLE_BOOK, GoogleBookPrivate))
typedef struct _GoogleBookPrivate GoogleBookPrivate;
-enum
-{
- PROP_NONE,
+enum {
+ PROP_NONE,
- PROP_USERNAME,
- PROP_USE_CACHE,
- PROP_REFRESH_INTERVAL,
- PROP_USE_SSL
+ PROP_USERNAME,
+ PROP_USE_CACHE,
+ PROP_REFRESH_INTERVAL,
+ PROP_USE_SSL
};
-enum
-{
- CONTACT_ADDED,
- CONTACT_CHANGED,
- CONTACT_REMOVED,
- SEQUENCE_COMPLETE,
- AUTH_REQUIRED,
+enum {
+ CONTACT_ADDED,
+ CONTACT_CHANGED,
+ CONTACT_REMOVED,
+ SEQUENCE_COMPLETE,
+ AUTH_REQUIRED,
- LAST_SIGNAL
+ LAST_SIGNAL
};
static guint google_book_signals [LAST_SIGNAL];
-typedef enum
-{
- NO_CACHE,
- ON_DISK_CACHE,
- IN_MEMORY_CACHE
+typedef enum {
+ NO_CACHE,
+ ON_DISK_CACHE,
+ IN_MEMORY_CACHE
} CacheType;
-struct _GoogleBookPrivate
-{
- gchar *username;
- CacheType cache_type;
- union {
- EBookBackendCache *on_disk;
- struct {
- GHashTable *contacts;
- GHashTable *gdata_entries;
- GTimeVal last_updated;
- } in_memory;
- } cache;
-
- gboolean offline;
- GDataService *service;
- EProxy *proxy;
- guint refresh_interval;
- gboolean use_ssl;
-
- gboolean live_mode;
-
- /* In live mode we will send out signals in an idle_handler */
- guint idle_id;
-
- guint refresh_id;
+struct _GoogleBookPrivate {
+ gchar *username;
+ CacheType cache_type;
+ union {
+ EBookBackendCache *on_disk;
+ struct {
+ GHashTable *contacts;
+ GHashTable *gdata_entries;
+ GTimeVal last_updated;
+ } in_memory;
+ } cache;
+
+ gboolean offline;
+ GDataService *service;
+ EProxy *proxy;
+ guint refresh_interval;
+ gboolean use_ssl;
+
+ gboolean live_mode;
+
+ /* In live mode we will send out signals in an idle_handler */
+ guint idle_id;
+
+ guint refresh_id;
};
-static gboolean
-google_book_get_new_contacts_in_chunks (GoogleBook *book,
- gint chunk_size,
- GError **error);
+static gboolean google_book_get_new_contacts_in_chunks (GoogleBook *book, gint chunk_size, GError **error);
static void
google_book_cache_init (GoogleBook *book, gboolean on_disk)
{
- GoogleBookPrivate *priv = GET_PRIVATE (book);
-
- if (on_disk) {
- priv->cache_type = ON_DISK_CACHE;
- priv->cache.on_disk = e_book_backend_cache_new (priv->username);
- } else {
- priv->cache_type = IN_MEMORY_CACHE;
- priv->cache.in_memory.contacts = g_hash_table_new_full (g_str_hash, g_str_equal,
- g_free, g_object_unref);
- priv->cache.in_memory.gdata_entries = g_hash_table_new_full (g_str_hash, g_str_equal,
- g_free, g_object_unref);
- memset (&priv->cache.in_memory.last_updated, 0, sizeof (GTimeVal));
- }
+ GoogleBookPrivate *priv = GET_PRIVATE (book);
+
+ if (on_disk) {
+ priv->cache_type = ON_DISK_CACHE;
+ priv->cache.on_disk = e_book_backend_cache_new (priv->username);
+ } else {
+ priv->cache_type = IN_MEMORY_CACHE;
+ priv->cache.in_memory.contacts = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
+ priv->cache.in_memory.gdata_entries = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
+ memset (&priv->cache.in_memory.last_updated, 0, sizeof (GTimeVal));
+ }
}
-static EContact*
+static EContact *
google_book_cache_add_contact (GoogleBook *book, GDataEntry *entry)
{
- GoogleBookPrivate *priv = GET_PRIVATE (book);
- EContact *contact;
- const gchar *uid;
-
- switch (priv->cache_type) {
- case ON_DISK_CACHE:
- contact = _e_contact_new_from_gdata_entry (entry);
- _e_contact_add_gdata_entry_xml (contact, entry);
- e_book_backend_cache_add_contact (priv->cache.on_disk, contact);
- _e_contact_remove_gdata_entry_xml (contact);
- return contact;
- case IN_MEMORY_CACHE:
- contact = _e_contact_new_from_gdata_entry (entry);
- uid = e_contact_get_const (contact, E_CONTACT_UID);
- g_hash_table_insert (priv->cache.in_memory.contacts,
- g_strdup (uid), g_object_ref (contact));
- g_hash_table_insert (priv->cache.in_memory.gdata_entries,
- g_strdup (uid), g_object_ref (entry));
- return contact;
- case NO_CACHE:
- default:
- break;
- }
- return NULL;
+ GoogleBookPrivate *priv = GET_PRIVATE (book);
+ EContact *contact;
+ const gchar *uid;
+
+ switch (priv->cache_type) {
+ case ON_DISK_CACHE:
+ contact = _e_contact_new_from_gdata_entry (entry);
+ _e_contact_add_gdata_entry_xml (contact, entry);
+ e_book_backend_cache_add_contact (priv->cache.on_disk, contact);
+ _e_contact_remove_gdata_entry_xml (contact);
+ return contact;
+ case IN_MEMORY_CACHE:
+ contact = _e_contact_new_from_gdata_entry (entry);
+ uid = e_contact_get_const (contact, E_CONTACT_UID);
+ g_hash_table_insert (priv->cache.in_memory.contacts, g_strdup (uid), g_object_ref (contact));
+ g_hash_table_insert (priv->cache.in_memory.gdata_entries, g_strdup (uid), g_object_ref (entry));
+ return contact;
+ case NO_CACHE:
+ default:
+ break;
+ }
+
+ return NULL;
}
static gboolean
google_book_cache_remove_contact (GoogleBook *book, const gchar *uid)
{
- GoogleBookPrivate *priv = GET_PRIVATE (book);
- gboolean success = TRUE;
-
- switch (priv->cache_type) {
- case ON_DISK_CACHE:
- return e_book_backend_cache_remove_contact (priv->cache.on_disk, uid);
- case IN_MEMORY_CACHE:
- success = g_hash_table_remove (priv->cache.in_memory.contacts, uid);
- return success && g_hash_table_remove (priv->cache.in_memory.gdata_entries, uid);
- case NO_CACHE:
- default:
- break;
- }
- return FALSE;
+ GoogleBookPrivate *priv = GET_PRIVATE (book);
+ gboolean success = TRUE;
+
+ switch (priv->cache_type) {
+ case ON_DISK_CACHE:
+ return e_book_backend_cache_remove_contact (priv->cache.on_disk, uid);
+ case IN_MEMORY_CACHE:
+ success = g_hash_table_remove (priv->cache.in_memory.contacts, uid);
+ return success && g_hash_table_remove (priv->cache.in_memory.gdata_entries, uid);
+ case NO_CACHE:
+ default:
+ break;
+ }
+
+ return FALSE;
}
static gboolean
google_book_cache_has_contact (GoogleBook *book, const gchar *uid)
{
- GoogleBookPrivate *priv = GET_PRIVATE (book);
-
- switch (priv->cache_type) {
- case ON_DISK_CACHE:
- return e_book_backend_cache_check_contact (priv->cache.on_disk, uid);
- case IN_MEMORY_CACHE:
- return g_hash_table_lookup (priv->cache.in_memory.contacts, uid) ? TRUE : FALSE;
- case NO_CACHE:
- default:
- break;
- }
- return FALSE;
+ GoogleBookPrivate *priv = GET_PRIVATE (book);
+
+ switch (priv->cache_type) {
+ case ON_DISK_CACHE:
+ return e_book_backend_cache_check_contact (priv->cache.on_disk, uid);
+ case IN_MEMORY_CACHE:
+ return g_hash_table_lookup (priv->cache.in_memory.contacts, uid) ? TRUE : FALSE;
+ case NO_CACHE:
+ default:
+ break;
+ }
+
+ return FALSE;
}
-static EContact*
+static EContact *
google_book_cache_get_contact (GoogleBook *book, const gchar *uid, GDataEntry **entry)
{
- GoogleBookPrivate *priv = GET_PRIVATE (book);
- EContact *contact;
-
- switch (priv->cache_type) {
- case ON_DISK_CACHE:
- contact = e_book_backend_cache_get_contact (priv->cache.on_disk, uid);
- if (contact) {
- if (entry) {
- const gchar *entry_xml, *edit_link;
-
- entry_xml = _e_contact_get_gdata_entry_xml (contact, &edit_link);
- *entry = GDATA_ENTRY (gdata_parsable_new_from_xml (GDATA_TYPE_CONTACTS_CONTACT, entry_xml, -1, NULL));
-
- if (*entry != NULL) {
- GDataLink *link = gdata_link_new (edit_link, GDATA_LINK_EDIT);
- gdata_entry_add_link (*entry, link);
- g_object_unref (link);
- }
- }
- _e_contact_remove_gdata_entry_xml (contact);
- }
- return contact;
- case IN_MEMORY_CACHE:
- contact = g_hash_table_lookup (priv->cache.in_memory.contacts, uid);
- if (entry) {
- *entry = g_hash_table_lookup (priv->cache.in_memory.gdata_entries, uid);
- if (*entry) {
- g_object_ref (*entry);
- }
- }
- if (contact) {
- g_object_ref (contact);
- }
- return contact;
- case NO_CACHE:
- default:
- break;
- }
- return NULL;
+ GoogleBookPrivate *priv = GET_PRIVATE (book);
+ EContact *contact;
+
+ switch (priv->cache_type) {
+ case ON_DISK_CACHE:
+ contact = e_book_backend_cache_get_contact (priv->cache.on_disk, uid);
+ if (contact) {
+ if (entry) {
+ const gchar *entry_xml, *edit_link;
+
+ entry_xml = _e_contact_get_gdata_entry_xml (contact, &edit_link);
+ *entry = GDATA_ENTRY (gdata_parsable_new_from_xml (GDATA_TYPE_CONTACTS_CONTACT, entry_xml, -1, NULL));
+
+ if (*entry) {
+ GDataLink *link = gdata_link_new (edit_link, GDATA_LINK_EDIT);
+ gdata_entry_add_link (*entry, link);
+ g_object_unref (link);
+ }
+ }
+
+ _e_contact_remove_gdata_entry_xml (contact);
+ }
+ return contact;
+ case IN_MEMORY_CACHE:
+ contact = g_hash_table_lookup (priv->cache.in_memory.contacts, uid);
+ if (entry) {
+ *entry = g_hash_table_lookup (priv->cache.in_memory.gdata_entries, uid);
+ if (*entry)
+ g_object_ref (*entry);
+ }
+
+ if (contact)
+ g_object_ref (contact);
+
+ return contact;
+ case NO_CACHE:
+ default:
+ break;
+ }
+
+ return NULL;
}
-static GList*
+static GList *
_g_hash_table_to_list (GHashTable *ht)
{
- GList *l = NULL;
- GHashTableIter iter;
- gpointer key, value;
+ GList *l = NULL;
+ GHashTableIter iter;
+ gpointer key, value;
- g_hash_table_iter_init (&iter, ht);
- while (g_hash_table_iter_next (&iter, &key, &value)) {
- l = g_list_prepend (l, g_object_ref (G_OBJECT (value)));
- }
+ g_hash_table_iter_init (&iter, ht);
+ while (g_hash_table_iter_next (&iter, &key, &value))
+ l = g_list_prepend (l, g_object_ref (G_OBJECT (value)));
- l = g_list_reverse (l);
+ l = g_list_reverse (l);
- return l;
+ return l;
}
-static GList*
+static GList *
google_book_cache_get_contacts (GoogleBook *book)
{
- GoogleBookPrivate *priv = GET_PRIVATE (book);
- GList *contacts, *iter;
-
- switch (priv->cache_type) {
- case ON_DISK_CACHE:
- contacts = e_book_backend_cache_get_contacts (priv->cache.on_disk,
- "(contains \"x-evolution-any-field\" \"\")");
- for (iter = contacts; iter; iter = iter->next) {
- _e_contact_remove_gdata_entry_xml (iter->data);
- }
- return contacts;
- case IN_MEMORY_CACHE:
- return _g_hash_table_to_list (priv->cache.in_memory.contacts);
- case NO_CACHE:
- default:
- break;
- }
- return NULL;
+ GoogleBookPrivate *priv = GET_PRIVATE (book);
+ GList *contacts, *iter;
+
+ switch (priv->cache_type) {
+ case ON_DISK_CACHE:
+ contacts = e_book_backend_cache_get_contacts (priv->cache.on_disk, "(contains \"x-evolution-any-field\" \"\")");
+ for (iter = contacts; iter; iter = iter->next)
+ _e_contact_remove_gdata_entry_xml (iter->data);
+
+ return contacts;
+ case IN_MEMORY_CACHE:
+ return _g_hash_table_to_list (priv->cache.in_memory.contacts);
+ case NO_CACHE:
+ default:
+ break;
+ }
+
+ return NULL;
}
static void
google_book_cache_freeze (GoogleBook *book)
{
- GoogleBookPrivate *priv = GET_PRIVATE (book);
+ GoogleBookPrivate *priv = GET_PRIVATE (book);
- if (priv->cache_type == ON_DISK_CACHE) {
- e_file_cache_freeze_changes (E_FILE_CACHE (priv->cache.on_disk));
- }
+ if (priv->cache_type == ON_DISK_CACHE)
+ e_file_cache_freeze_changes (E_FILE_CACHE (priv->cache.on_disk));
}
static void
google_book_cache_thaw (GoogleBook *book)
{
- GoogleBookPrivate *priv = GET_PRIVATE (book);
+ GoogleBookPrivate *priv = GET_PRIVATE (book);
- if (priv->cache_type == ON_DISK_CACHE) {
- e_file_cache_thaw_changes (E_FILE_CACHE (priv->cache.on_disk));
- }
+ if (priv->cache_type == ON_DISK_CACHE)
+ e_file_cache_thaw_changes (E_FILE_CACHE (priv->cache.on_disk));
}
static gchar *
google_book_cache_get_last_update (GoogleBook *book)
{
- GoogleBookPrivate *priv = GET_PRIVATE (book);
-
- switch (priv->cache_type) {
- case ON_DISK_CACHE:
- return e_book_backend_cache_get_time (priv->cache.on_disk);
- case IN_MEMORY_CACHE:
- if (priv->cache.in_memory.contacts)
- return g_time_val_to_iso8601 (&priv->cache.in_memory.last_updated);
- break;
- case NO_CACHE:
- default:
- break;
- }
- return NULL;
+ GoogleBookPrivate *priv = GET_PRIVATE (book);
+
+ switch (priv->cache_type) {
+ case ON_DISK_CACHE:
+ return e_book_backend_cache_get_time (priv->cache.on_disk);
+ case IN_MEMORY_CACHE:
+ if (priv->cache.in_memory.contacts)
+ return g_time_val_to_iso8601 (&priv->cache.in_memory.last_updated);
+ break;
+ case NO_CACHE:
+ default:
+ break;
+ }
+
+ return NULL;
}
static gboolean
google_book_cache_get_last_update_tv (GoogleBook *book, GTimeVal *tv)
{
- GoogleBookPrivate *priv = GET_PRIVATE (book);
- gchar *last_update;
- gint rv;
-
- switch (priv->cache_type) {
- case ON_DISK_CACHE:
- last_update = e_book_backend_cache_get_time (priv->cache.on_disk);
- rv = last_update ? g_time_val_from_iso8601 (last_update, tv) : FALSE;
- g_free (last_update);
- return rv;
- case IN_MEMORY_CACHE:
- memcpy (tv, &priv->cache.in_memory.last_updated, sizeof (GTimeVal));
- return priv->cache.in_memory.contacts != NULL;
- case NO_CACHE:
- default:
- break;
- }
- return FALSE;
+ GoogleBookPrivate *priv = GET_PRIVATE (book);
+ gchar *last_update;
+ gint rv;
+
+ switch (priv->cache_type) {
+ case ON_DISK_CACHE:
+ last_update = e_book_backend_cache_get_time (priv->cache.on_disk);
+ rv = last_update ? g_time_val_from_iso8601 (last_update, tv) : FALSE;
+ g_free (last_update);
+ return rv;
+ case IN_MEMORY_CACHE:
+ memcpy (tv, &priv->cache.in_memory.last_updated, sizeof (GTimeVal));
+ return priv->cache.in_memory.contacts != NULL;
+ case NO_CACHE:
+ default:
+ break;
+ }
+
+ return FALSE;
}
static void
google_book_cache_set_last_update (GoogleBook *book, GTimeVal *tv)
{
- GoogleBookPrivate *priv = GET_PRIVATE (book);
- gchar *_time;
-
- switch (priv->cache_type) {
- case ON_DISK_CACHE:
- _time = g_time_val_to_iso8601 (tv);
- /* Work around a bug in EBookBackendCache */
- e_file_cache_remove_object (E_FILE_CACHE (priv->cache.on_disk), "last_update_time");
- e_book_backend_cache_set_time (priv->cache.on_disk, _time);
- g_free (_time);
- return;
- case IN_MEMORY_CACHE:
- memcpy (&priv->cache.in_memory.last_updated, tv, sizeof (GTimeVal));
- case NO_CACHE:
- default:
- break;
- }
+ GoogleBookPrivate *priv = GET_PRIVATE (book);
+ gchar *_time;
+
+ switch (priv->cache_type) {
+ case ON_DISK_CACHE:
+ _time = g_time_val_to_iso8601 (tv);
+ /* Work around a bug in EBookBackendCache */
+ e_file_cache_remove_object (E_FILE_CACHE (priv->cache.on_disk), "last_update_time");
+ e_book_backend_cache_set_time (priv->cache.on_disk, _time);
+ g_free (_time);
+ return;
+ case IN_MEMORY_CACHE:
+ memcpy (&priv->cache.in_memory.last_updated, tv, sizeof (GTimeVal));
+ case NO_CACHE:
+ default:
+ break;
+ }
}
static gboolean
google_book_cache_needs_update (GoogleBook *book, guint *remaining_secs)
{
- GoogleBookPrivate *priv = GET_PRIVATE (book);
- GTimeVal last, current;
- guint diff;
- gboolean rv;
-
- if (remaining_secs) {
- *remaining_secs = G_MAXUINT;
- }
- /* We never want to update in offline mode */
- if (priv->offline) {
- return FALSE;
- }
-
- rv = google_book_cache_get_last_update_tv (book, &last);
-
- if (FALSE == rv) {
- return TRUE;
- }
- g_get_current_time (¤t);
- if (last.tv_sec > current.tv_sec) {
- g_warning ("last update is in the feature?");
-
- /* Do an update so we can fix this */
- return TRUE;
- }
- diff = current.tv_sec - last.tv_sec;
-
- if (diff >= priv->refresh_interval) {
- return TRUE;
- }
- if (remaining_secs) {
- *remaining_secs = priv->refresh_interval - diff;
- }
- __debug__ ("No update needed. Next update needed in %d secs", priv->refresh_interval - diff);
-
- return FALSE;
+ GoogleBookPrivate *priv = GET_PRIVATE (book);
+ GTimeVal last, current;
+ guint diff;
+ gboolean rv;
+
+ if (remaining_secs)
+ *remaining_secs = G_MAXUINT;
+
+ /* We never want to update in offline mode */
+ if (priv->offline)
+ return FALSE;
+
+ rv = google_book_cache_get_last_update_tv (book, &last);
+
+ if (!rv)
+ return TRUE;
+
+ g_get_current_time (¤t);
+ if (last.tv_sec > current.tv_sec) {
+ g_warning ("last update is in the feature?");
+
+ /* Do an update so we can fix this */
+ return TRUE;
+ }
+ diff = current.tv_sec - last.tv_sec;
+
+ if (diff >= priv->refresh_interval)
+ return TRUE;
+
+ if (remaining_secs)
+ *remaining_secs = priv->refresh_interval - diff;
+
+ __debug__ ("No update needed. Next update needed in %d secs", priv->refresh_interval - diff);
+
+ return FALSE;
}
static gboolean on_refresh_timeout (gpointer user_data);
@@ -400,340 +391,304 @@ static gboolean on_refresh_timeout (gpointer user_data);
static gboolean
google_book_cache_refresh_if_needed (GoogleBook *book, GError **error)
{
- GoogleBookPrivate *priv = GET_PRIVATE (book);
- guint remaining_secs;
- gint rv = TRUE;
- gboolean install_timeout;
-
- __debug__ (G_STRFUNC);
-
- if (priv->offline || NULL == priv->service) {
- __debug__ ("We are not connected to Google%s.",
- priv->offline ? " (offline mode)" : "");
- return TRUE;
- }
-
- install_timeout = (priv->live_mode) &&
- (priv->refresh_interval > 0) &&
- (0 == priv->refresh_id);
-
- if (google_book_cache_needs_update (book, &remaining_secs)) {
- rv = google_book_get_new_contacts_in_chunks (book, 32, error);
- if (install_timeout) {
- priv->refresh_id =
- g_timeout_add_seconds (priv->refresh_interval,
- on_refresh_timeout,
- book);
- }
- } else {
- if (install_timeout) {
- __debug__ ("Installing timeout with %d seconds",
- remaining_secs);
- priv->refresh_id =
- g_timeout_add_seconds (remaining_secs,
- on_refresh_timeout,
- book);
- }
- }
- return rv;
+ GoogleBookPrivate *priv = GET_PRIVATE (book);
+ guint remaining_secs;
+ gint rv = TRUE;
+ gboolean install_timeout;
+
+ __debug__ (G_STRFUNC);
+
+ if (priv->offline || !priv->service) {
+ __debug__ ("We are not connected to Google%s.", priv->offline ? " (offline mode)" : "");
+ return TRUE;
+ }
+
+ install_timeout = (priv->live_mode) && (priv->refresh_interval > 0) && (0 == priv->refresh_id);
+
+ if (google_book_cache_needs_update (book, &remaining_secs)) {
+ rv = google_book_get_new_contacts_in_chunks (book, 32, error);
+ if (install_timeout)
+ priv->refresh_id = g_timeout_add_seconds (priv->refresh_interval, on_refresh_timeout, book);
+ } else {
+ if (install_timeout) {
+ __debug__ ("Installing timeout with %d seconds", remaining_secs);
+ priv->refresh_id = g_timeout_add_seconds (remaining_secs, on_refresh_timeout, book);
+ }
+ }
+ return rv;
}
static gboolean
on_refresh_timeout (gpointer user_data)
{
- GoogleBook *book = user_data;
- GoogleBookPrivate *priv = GET_PRIVATE (book);
+ GoogleBook *book = user_data;
+ GoogleBookPrivate *priv = GET_PRIVATE (book);
- __debug__ (G_STRFUNC);
+ __debug__ (G_STRFUNC);
- priv->refresh_id = 0;
- if (priv->live_mode) {
- google_book_cache_refresh_if_needed (book, NULL);
- }
+ priv->refresh_id = 0;
+ if (priv->live_mode)
+ google_book_cache_refresh_if_needed (book, NULL);
- return FALSE;
+ return FALSE;
}
static void
google_book_cache_destroy (GoogleBook *book)
{
- GoogleBookPrivate *priv = GET_PRIVATE (book);
-
- switch (priv->cache_type) {
- case ON_DISK_CACHE:
- g_object_unref (priv->cache.on_disk);
- break;
- case IN_MEMORY_CACHE:
- g_hash_table_destroy (priv->cache.in_memory.contacts);
- g_hash_table_destroy (priv->cache.in_memory.gdata_entries);
- break;
- case NO_CACHE:
- default:
- break;
- }
- priv->cache_type = NO_CACHE;
+ GoogleBookPrivate *priv = GET_PRIVATE (book);
+
+ switch (priv->cache_type) {
+ case ON_DISK_CACHE:
+ g_object_unref (priv->cache.on_disk);
+ break;
+ case IN_MEMORY_CACHE:
+ g_hash_table_destroy (priv->cache.in_memory.contacts);
+ g_hash_table_destroy (priv->cache.in_memory.gdata_entries);
+ break;
+ case NO_CACHE:
+ default:
+ break;
+ }
+
+ priv->cache_type = NO_CACHE;
}
static void
-google_book_get_property (GObject *object, guint property_id,
- GValue *value, GParamSpec *pspec)
+google_book_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
- GoogleBookPrivate *priv = GET_PRIVATE (object);
-
- switch (property_id) {
- case PROP_USERNAME:
- g_value_set_string (value, priv->username);
- break;
- case PROP_USE_CACHE:
- g_value_set_boolean (value, (priv->cache_type == ON_DISK_CACHE));
- break;
- case PROP_REFRESH_INTERVAL:
- g_value_set_uint (value, priv->refresh_interval);
- break;
- case PROP_USE_SSL:
- g_value_set_boolean (value, priv->use_ssl);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- }
+ GoogleBookPrivate *priv = GET_PRIVATE (object);
+
+ switch (property_id) {
+ case PROP_USERNAME:
+ g_value_set_string (value, priv->username);
+ break;
+ case PROP_USE_CACHE:
+ g_value_set_boolean (value, (priv->cache_type == ON_DISK_CACHE));
+ break;
+ case PROP_REFRESH_INTERVAL:
+ g_value_set_uint (value, priv->refresh_interval);
+ break;
+ case PROP_USE_SSL:
+ g_value_set_boolean (value, priv->use_ssl);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
}
static void
-google_book_set_property (GObject *object, guint property_id,
- const GValue *value, GParamSpec *pspec)
+google_book_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
- GoogleBookPrivate *priv = GET_PRIVATE (object);
-
- switch (property_id) {
- case PROP_USERNAME:
- priv->username = g_value_dup_string (value);
- break;
- case PROP_USE_CACHE:
- google_book_cache_init (GOOGLE_BOOK (object), g_value_get_boolean (value));
- break;
- case PROP_REFRESH_INTERVAL:
- priv->refresh_interval = g_value_get_uint (value);
-
- /* Remove and re-add the timeout */
- if (priv->refresh_id != 0) {
- g_source_remove (priv->refresh_id);
- priv->refresh_id = g_timeout_add_seconds (priv->refresh_interval, on_refresh_timeout, GOOGLE_BOOK (object));
- }
- break;
- case PROP_USE_SSL:
- priv->use_ssl = g_value_get_boolean (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- }
+ GoogleBookPrivate *priv = GET_PRIVATE (object);
+
+ switch (property_id) {
+ case PROP_USERNAME:
+ priv->username = g_value_dup_string (value);
+ break;
+ case PROP_USE_CACHE:
+ google_book_cache_init (GOOGLE_BOOK (object), g_value_get_boolean (value));
+ break;
+ case PROP_REFRESH_INTERVAL:
+ priv->refresh_interval = g_value_get_uint (value);
+
+ /* Remove and re-add the timeout */
+ if (priv->refresh_id != 0) {
+ g_source_remove (priv->refresh_id);
+ priv->refresh_id = g_timeout_add_seconds (priv->refresh_interval, on_refresh_timeout, GOOGLE_BOOK (object));
+ }
+ break;
+ case PROP_USE_SSL:
+ priv->use_ssl = g_value_get_boolean (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
}
static void
google_book_dispose (GObject *object)
{
- GoogleBookPrivate *priv = GET_PRIVATE (object);
+ GoogleBookPrivate *priv = GET_PRIVATE (object);
- if (priv->idle_id) {
- g_source_remove (priv->idle_id);
- priv->idle_id = 0;
- }
+ if (priv->idle_id) {
+ g_source_remove (priv->idle_id);
+ priv->idle_id = 0;
+ }
- if (priv->service)
- g_object_unref (priv->service);
- priv->service = NULL;
+ if (priv->service)
+ g_object_unref (priv->service);
+ priv->service = NULL;
- if (priv->proxy)
- g_object_unref (priv->proxy);
- priv->proxy = NULL;
+ if (priv->proxy)
+ g_object_unref (priv->proxy);
+ priv->proxy = NULL;
- google_book_cache_destroy (GOOGLE_BOOK (object));
+ google_book_cache_destroy (GOOGLE_BOOK (object));
- if (G_OBJECT_CLASS (google_book_parent_class)->dispose)
- G_OBJECT_CLASS (google_book_parent_class)->dispose (object);
+ if (G_OBJECT_CLASS (google_book_parent_class)->dispose)
+ G_OBJECT_CLASS (google_book_parent_class)->dispose (object);
}
static void
google_book_finalize (GObject *object)
{
- GoogleBookPrivate *priv = GET_PRIVATE (object);
+ GoogleBookPrivate *priv = GET_PRIVATE (object);
- g_free (priv->username);
+ g_free (priv->username);
- if (G_OBJECT_CLASS (google_book_parent_class)->finalize)
- G_OBJECT_CLASS (google_book_parent_class)->finalize (object);
+ if (G_OBJECT_CLASS (google_book_parent_class)->finalize)
+ G_OBJECT_CLASS (google_book_parent_class)->finalize (object);
}
static void
google_book_emit_contact_added (GoogleBook *book, EContact *contact)
{
- GoogleBookPrivate *priv;
-
- priv = GET_PRIVATE (book);
+ GoogleBookPrivate *priv = GET_PRIVATE (book);
- __debug__ (G_STRFUNC);
- if (priv->live_mode) {
- g_signal_emit (book, google_book_signals [CONTACT_ADDED], 0, contact);
- }
+ __debug__ (G_STRFUNC);
+ if (priv->live_mode)
+ g_signal_emit (book, google_book_signals [CONTACT_ADDED], 0, contact);
}
static void
google_book_emit_contact_changed (GoogleBook *book, EContact *contact)
{
- GoogleBookPrivate *priv;
+ GoogleBookPrivate *priv = GET_PRIVATE (book);
- priv = GET_PRIVATE (book);
-
- __debug__ (G_STRFUNC);
- if (priv->live_mode) {
- g_signal_emit (book, google_book_signals [CONTACT_CHANGED], 0, contact);
- }
+ __debug__ (G_STRFUNC);
+ if (priv->live_mode)
+ g_signal_emit (book, google_book_signals [CONTACT_CHANGED], 0, contact);
}
static void
google_book_emit_contact_removed (GoogleBook *book, const gchar *uid)
{
- GoogleBookPrivate *priv;
-
- priv = GET_PRIVATE (book);
+ GoogleBookPrivate *priv = GET_PRIVATE (book);
- __debug__ (G_STRFUNC);
- if (priv->live_mode) {
- g_signal_emit (book, google_book_signals [CONTACT_REMOVED], 0, uid);
- }
+ __debug__ (G_STRFUNC);
+ if (priv->live_mode)
+ g_signal_emit (book, google_book_signals [CONTACT_REMOVED], 0, uid);
}
static void
google_book_emit_sequence_complete (GoogleBook *book, GError *error)
{
- GoogleBookPrivate *priv;
-
- priv = GET_PRIVATE (book);
+ GoogleBookPrivate *priv = GET_PRIVATE (book);
- __debug__ (G_STRFUNC);
- if (priv->live_mode) {
- g_signal_emit (book, google_book_signals [SEQUENCE_COMPLETE], 0, error);
- }
+ __debug__ (G_STRFUNC);
+ if (priv->live_mode)
+ g_signal_emit (book, google_book_signals [SEQUENCE_COMPLETE], 0, error);
}
static void
google_book_emit_auth_required (GoogleBook *book)
{
- GoogleBookPrivate *priv;
-
- priv = GET_PRIVATE (book);
-
- __debug__ (G_STRFUNC);
- g_signal_emit (book, google_book_signals [AUTH_REQUIRED], 0);
+ __debug__ (G_STRFUNC);
+ g_signal_emit (book, google_book_signals [AUTH_REQUIRED], 0);
}
static void
google_book_class_init (GoogleBookClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- g_type_class_add_private (klass, sizeof (GoogleBookPrivate));
-
- object_class->get_property = google_book_get_property;
- object_class->set_property = google_book_set_property;
- object_class->dispose = google_book_dispose;
- object_class->finalize = google_book_finalize;
-
- g_object_class_install_property (object_class,
- PROP_USERNAME,
- g_param_spec_string ("username",
- "Username",
- "The username.",
- NULL,
- G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
-
- g_object_class_install_property (object_class,
- PROP_USE_CACHE,
- g_param_spec_boolean ("use-cache",
- "Use Cache?",
- "Whether an on-disk cache should be used.",
- TRUE,
- G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
- g_object_class_install_property (object_class,
- PROP_REFRESH_INTERVAL,
- g_param_spec_uint ("refresh-interval",
- "Refresh Interval",
- "Specifies the number of seconds until "
- "the local cache is updated from the "
- "server. 0 means no updates.",
- 0, G_MAXUINT, 3600,
- G_PARAM_READWRITE));
- g_object_class_install_property (object_class,
- PROP_USE_SSL,
- g_param_spec_boolean ("use-ssl",
- "Use SSL?",
- "Whether SSL should be used.",
- TRUE,
- G_PARAM_READWRITE));
- google_book_signals [CONTACT_CHANGED] =
- g_signal_new ("contact-changed",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GoogleBookClass, contact_changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1,
- G_TYPE_POINTER);
-
- google_book_signals [CONTACT_ADDED] =
- g_signal_new ("contact-added",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GoogleBookClass, contact_added),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1,
- G_TYPE_POINTER);
-
- google_book_signals [CONTACT_REMOVED] =
- g_signal_new ("contact-removed",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GoogleBookClass, contact_removed),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1,
- G_TYPE_POINTER);
-
- google_book_signals [SEQUENCE_COMPLETE] =
- g_signal_new ("sequence-complete",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GoogleBookClass, sequence_complete),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1,
- G_TYPE_POINTER);
-
- google_book_signals [AUTH_REQUIRED] =
- g_signal_new ("auth-required",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GoogleBookClass, auth_required),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (GoogleBookPrivate));
+
+ object_class->get_property = google_book_get_property;
+ object_class->set_property = google_book_set_property;
+ object_class->dispose = google_book_dispose;
+ object_class->finalize = google_book_finalize;
+
+ g_object_class_install_property (object_class, PROP_USERNAME,
+ g_param_spec_string ("username",
+ "Username",
+ "The username.",
+ NULL,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
+
+ g_object_class_install_property (object_class, PROP_USE_CACHE,
+ g_param_spec_boolean ("use-cache",
+ "Use Cache?",
+ "Whether an on-disk cache should be used.",
+ TRUE,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
+
+ g_object_class_install_property (object_class, PROP_REFRESH_INTERVAL,
+ g_param_spec_uint ("refresh-interval",
+ "Refresh Interval",
+ "Specifies the number of seconds until the local cache is updated from the "
+ "server. 0 means no updates.",
+ 0, G_MAXUINT, 3600,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (object_class, PROP_USE_SSL,
+ g_param_spec_boolean ("use-ssl",
+ "Use SSL?",
+ "Whether SSL should be used.",
+ TRUE,
+ G_PARAM_READWRITE));
+
+ google_book_signals [CONTACT_CHANGED] = g_signal_new ("contact-changed",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GoogleBookClass, contact_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1,
+ G_TYPE_POINTER);
+
+ google_book_signals [CONTACT_ADDED] = g_signal_new ("contact-added",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GoogleBookClass, contact_added),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1,
+ G_TYPE_POINTER);
+
+ google_book_signals [CONTACT_REMOVED] = g_signal_new ("contact-removed",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GoogleBookClass, contact_removed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1,
+ G_TYPE_POINTER);
+
+ google_book_signals [SEQUENCE_COMPLETE] = g_signal_new ("sequence-complete",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GoogleBookClass, sequence_complete),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1,
+ G_TYPE_POINTER);
+
+ google_book_signals [AUTH_REQUIRED] = g_signal_new ("auth-required",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GoogleBookClass, auth_required),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
}
static void
google_book_init (GoogleBook *self)
{
- __debug__ (G_STRFUNC);
+ __debug__ (G_STRFUNC);
}
-GoogleBook*
+GoogleBook *
google_book_new (const gchar *username, gboolean use_cache)
{
- return g_object_new (TYPE_GOOGLE_BOOK,
- "username", username,
- "use-cache", use_cache,
- "use-ssl", TRUE,
- "refresh-interval", 3600,
- NULL);
+ return g_object_new (TYPE_GOOGLE_BOOK,
+ "username", username,
+ "use-cache", use_cache,
+ "use-ssl", TRUE,
+ "refresh-interval", 3600,
+ NULL);
}
static void
@@ -760,439 +715,424 @@ proxy_settings_changed (EProxy *proxy, gpointer user_data)
gboolean
google_book_connect_to_google (GoogleBook *book, const gchar *password, GError **error)
{
- GoogleBookPrivate *priv;
+ GoogleBookPrivate *priv;
- __debug__ (G_STRFUNC);
- g_return_val_if_fail (IS_GOOGLE_BOOK (book), FALSE);
- g_return_val_if_fail (NULL != password, FALSE);
+ __debug__ (G_STRFUNC);
+ g_return_val_if_fail (IS_GOOGLE_BOOK (book), FALSE);
+ g_return_val_if_fail (password, FALSE);
- priv = GET_PRIVATE (book);
+ priv = GET_PRIVATE (book);
- if (priv->service) {
- g_warning ("Connection to Google already established.");
- return TRUE;
- }
+ if (priv->service) {
+ g_warning ("Connection to Google already established.");
+ return TRUE;
+ }
- priv->service = GDATA_SERVICE (gdata_contacts_service_new ("evolution-client-0.0.1"));
- priv->proxy = e_proxy_new ();
- e_proxy_setup_proxy (priv->proxy);
- proxy_settings_changed (priv->proxy, priv);
+ priv->service = GDATA_SERVICE (gdata_contacts_service_new ("evolution-client-0.0.1"));
+ priv->proxy = e_proxy_new ();
+ e_proxy_setup_proxy (priv->proxy);
+ proxy_settings_changed (priv->proxy, priv);
- if (!gdata_service_authenticate (priv->service, priv->username, password, NULL, error)) {
- g_object_unref (priv->service);
- priv->service = NULL;
- g_object_unref (priv->proxy);
- priv->proxy = NULL;
- return FALSE;
- }
+ if (!gdata_service_authenticate (priv->service, priv->username, password, NULL, error)) {
+ g_object_unref (priv->service);
+ priv->service = NULL;
+ g_object_unref (priv->proxy);
+ priv->proxy = NULL;
+ return FALSE;
+ }
- g_signal_connect (priv->proxy, "changed", G_CALLBACK (proxy_settings_changed), priv);
+ g_signal_connect (priv->proxy, "changed", G_CALLBACK (proxy_settings_changed), priv);
- return google_book_cache_refresh_if_needed (book, error);
+ return google_book_cache_refresh_if_needed (book, error);
}
void
google_book_set_offline_mode (GoogleBook *book, gboolean offline)
{
- GoogleBookPrivate *priv;
-
- __debug__ (G_STRFUNC);
- g_return_if_fail (IS_GOOGLE_BOOK (book));
-
- priv = GET_PRIVATE (book);
-
- priv->offline = offline;
- if (offline) {
- /* Going offline, so we can free our service and proxy */
- if (priv->service)
- g_object_unref (priv->service);
- priv->service = NULL;
-
- if (priv->proxy)
- g_object_unref (priv->proxy);
- priv->proxy = NULL;
- } else {
- /* Going online, so we need to re-authenticate and re-create the service and proxy.
- * This is done in google_book_connect_to_google(), which is called by EBookBackendGoogle when it gets the authentication data. */
- google_book_emit_auth_required (book);
- }
+ GoogleBookPrivate *priv;
+
+ __debug__ (G_STRFUNC);
+ g_return_if_fail (IS_GOOGLE_BOOK (book));
+
+ priv = GET_PRIVATE (book);
+
+ priv->offline = offline;
+ if (offline) {
+ /* Going offline, so we can free our service and proxy */
+ if (priv->service)
+ g_object_unref (priv->service);
+ priv->service = NULL;
+
+ if (priv->proxy)
+ g_object_unref (priv->proxy);
+ priv->proxy = NULL;
+ } else {
+ /* Going online, so we need to re-authenticate and re-create the service and proxy.
+ * This is done in google_book_connect_to_google(), which is called by EBookBackendGoogle when it gets the authentication data. */
+ google_book_emit_auth_required (book);
+ }
}
gboolean
-google_book_add_contact (GoogleBook *book,
- EContact *contact,
- EContact **out_contact,
- GError **error)
+google_book_add_contact (GoogleBook *book, EContact *contact, EContact **out_contact, GError **error)
{
- GoogleBookPrivate *priv;
- GDataEntry *entry, *new_entry;
- gchar *xml;
+ GoogleBookPrivate *priv;
+ GDataEntry *entry, *new_entry;
+ gchar *xml;
- *out_contact = NULL;
+ *out_contact = NULL;
- __debug__ (G_STRFUNC);
- g_return_val_if_fail (IS_GOOGLE_BOOK (book), FALSE);
+ __debug__ (G_STRFUNC);
+ g_return_val_if_fail (IS_GOOGLE_BOOK (book), FALSE);
- priv = GET_PRIVATE (book);
+ priv = GET_PRIVATE (book);
- g_return_val_if_fail (priv->service, FALSE);
+ g_return_val_if_fail (priv->service, FALSE);
- entry = _gdata_entry_new_from_e_contact (contact);
- xml = gdata_parsable_get_xml (GDATA_PARSABLE (entry));
- __debug__ ("new entry with xml: %s", xml);
- g_free (xml);
+ entry = _gdata_entry_new_from_e_contact (contact);
+ xml = gdata_parsable_get_xml (GDATA_PARSABLE (entry));
+ __debug__ ("new entry with xml: %s", xml);
+ g_free (xml);
- new_entry = GDATA_ENTRY (gdata_contacts_service_insert_contact (GDATA_CONTACTS_SERVICE (priv->service), GDATA_CONTACTS_CONTACT (entry),
- NULL, error));
- g_object_unref (entry);
- if (!new_entry)
- return FALSE;
+ new_entry = GDATA_ENTRY (gdata_contacts_service_insert_contact (GDATA_CONTACTS_SERVICE (priv->service), GDATA_CONTACTS_CONTACT (entry),
+ NULL, error));
+ g_object_unref (entry);
+ if (!new_entry)
+ return FALSE;
- *out_contact = google_book_cache_add_contact (book, new_entry);
- g_object_unref (new_entry);
+ *out_contact = google_book_cache_add_contact (book, new_entry);
+ g_object_unref (new_entry);
- return TRUE;
+ return TRUE;
}
gboolean
-google_book_update_contact (GoogleBook *book,
- EContact *contact,
- EContact **out_contact,
- GError **error)
+google_book_update_contact (GoogleBook *book, EContact *contact, EContact **out_contact, GError **error)
{
- GoogleBookPrivate *priv;
- GDataEntry *entry, *new_entry;
- EContact *cached_contact;
- gchar *xml;
- const gchar *uid;
+ GoogleBookPrivate *priv;
+ GDataEntry *entry, *new_entry;
+ EContact *cached_contact;
+ gchar *xml;
+ const gchar *uid;
- *out_contact = NULL;
+ *out_contact = NULL;
- __debug__ (G_STRFUNC);
- g_return_val_if_fail (IS_GOOGLE_BOOK (book), FALSE);
+ __debug__ (G_STRFUNC);
+ g_return_val_if_fail (IS_GOOGLE_BOOK (book), FALSE);
- priv = GET_PRIVATE (book);
+ priv = GET_PRIVATE (book);
- g_return_val_if_fail (priv->service, FALSE);
+ g_return_val_if_fail (priv->service, FALSE);
- uid = e_contact_get (contact, E_CONTACT_UID);
+ uid = e_contact_get (contact, E_CONTACT_UID);
- entry = NULL;
- cached_contact = google_book_cache_get_contact (book, uid, &entry);
- if (NULL == cached_contact) {
- g_set_error (error,
- GDATA_SERVICE_ERROR,
- GDATA_SERVICE_ERROR_NOT_FOUND,
- "Contact with uid %s not found in cache.", uid);
- return FALSE;
- }
- g_object_unref (cached_contact);
- _gdata_entry_update_from_e_contact (entry, contact);
+ entry = NULL;
+ cached_contact = google_book_cache_get_contact (book, uid, &entry);
+ if (!cached_contact) {
+ g_set_error (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_NOT_FOUND, "Contact with uid %s not found in cache.", uid);
+ return FALSE;
+ }
+ g_object_unref (cached_contact);
+ _gdata_entry_update_from_e_contact (entry, contact);
- xml = gdata_parsable_get_xml (GDATA_PARSABLE (entry));
- __debug__ ("Before:\n%s", xml);
- g_free (xml);
+ xml = gdata_parsable_get_xml (GDATA_PARSABLE (entry));
+ __debug__ ("Before:\n%s", xml);
+ g_free (xml);
- new_entry = GDATA_ENTRY (gdata_contacts_service_update_contact (GDATA_CONTACTS_SERVICE (priv->service), GDATA_CONTACTS_CONTACT (entry),
- NULL, error));
- g_object_unref (entry);
+ new_entry = GDATA_ENTRY (gdata_contacts_service_update_contact (GDATA_CONTACTS_SERVICE (priv->service), GDATA_CONTACTS_CONTACT (entry),
+ NULL, error));
+ g_object_unref (entry);
- if (!new_entry)
- return FALSE;
+ if (!new_entry)
+ return FALSE;
- xml = NULL;
- if (new_entry)
- xml = gdata_parsable_get_xml (GDATA_PARSABLE (new_entry));
- __debug__ ("After:\n%s", xml);
- g_free (xml);
+ xml = NULL;
+ if (new_entry)
+ xml = gdata_parsable_get_xml (GDATA_PARSABLE (new_entry));
+ __debug__ ("After:\n%s", xml);
+ g_free (xml);
- *out_contact = google_book_cache_add_contact (book, new_entry);
- g_object_unref (new_entry);
+ *out_contact = google_book_cache_add_contact (book, new_entry);
+ g_object_unref (new_entry);
- return TRUE;
+ return TRUE;
}
gboolean
google_book_remove_contact (GoogleBook *book, const gchar *uid, GError **error)
{
- GoogleBookPrivate *priv;
- GDataEntry *entry = NULL;
- EContact *cached_contact;
- gboolean success;
+ GoogleBookPrivate *priv;
+ GDataEntry *entry = NULL;
+ EContact *cached_contact;
+ gboolean success;
- __debug__ (G_STRFUNC);
- g_return_val_if_fail (IS_GOOGLE_BOOK (book), FALSE);
+ __debug__ (G_STRFUNC);
+ g_return_val_if_fail (IS_GOOGLE_BOOK (book), FALSE);
- priv = GET_PRIVATE (book);
+ priv = GET_PRIVATE (book);
- g_return_val_if_fail (priv->service, FALSE);
+ g_return_val_if_fail (priv->service, FALSE);
- cached_contact = google_book_cache_get_contact (book, uid, &entry);
- if (NULL == cached_contact) {
- g_set_error (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_NOT_FOUND, "Contact with uid %s not found in cache.", uid);
- return FALSE;
- }
+ cached_contact = google_book_cache_get_contact (book, uid, &entry);
+ if (!cached_contact) {
+ g_set_error (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_NOT_FOUND, "Contact with uid %s not found in cache.", uid);
+ return FALSE;
+ }
- google_book_cache_remove_contact (book, uid);
- success = gdata_service_delete_entry (GDATA_SERVICE (priv->service), entry, NULL, error);
- g_object_unref (entry);
- g_object_unref (cached_contact);
+ google_book_cache_remove_contact (book, uid);
+ success = gdata_service_delete_entry (GDATA_SERVICE (priv->service), entry, NULL, error);
+ g_object_unref (entry);
+ g_object_unref (cached_contact);
- return success;
+ return success;
}
static void
process_subsequent_entry (gpointer list_data, gpointer user_data)
{
- GoogleBookPrivate *priv;
- GoogleBook *book = user_data;
- GDataEntry *entry;
- gboolean is_deleted, is_cached;
- const gchar *uid;
-
- __debug__ (G_STRFUNC);
- priv = GET_PRIVATE (book);
- entry = GDATA_ENTRY (list_data);
- uid = gdata_entry_get_id (entry);
- is_deleted = gdata_contacts_contact_is_deleted (GDATA_CONTACTS_CONTACT (entry));
-
- is_cached = google_book_cache_has_contact (book, uid);
- if (is_deleted) {
- /* Do we have this item in our cache? */
- if (is_cached) {
- google_book_cache_remove_contact (book, uid);
- google_book_emit_contact_removed (book, uid);
- }
- } else {
- EContact *contact;
-
- contact = google_book_cache_add_contact (book, entry);
-
- if (is_cached) {
- google_book_emit_contact_changed (book, contact);
- } else {
- google_book_emit_contact_added (book, contact);
- }
- g_object_unref (contact);
- }
+ GoogleBookPrivate *priv;
+ GoogleBook *book = user_data;
+ GDataEntry *entry;
+ gboolean is_deleted, is_cached;
+ const gchar *uid;
+
+ __debug__ (G_STRFUNC);
+ priv = GET_PRIVATE (book);
+ entry = GDATA_ENTRY (list_data);
+ uid = gdata_entry_get_id (entry);
+ is_deleted = gdata_contacts_contact_is_deleted (GDATA_CONTACTS_CONTACT (entry));
+
+ is_cached = google_book_cache_has_contact (book, uid);
+ if (is_deleted) {
+ /* Do we have this item in our cache? */
+ if (is_cached) {
+ google_book_cache_remove_contact (book, uid);
+ google_book_emit_contact_removed (book, uid);
+ }
+ } else {
+ EContact *contact = google_book_cache_add_contact (book, entry);
+
+ if (is_cached)
+ google_book_emit_contact_changed (book, contact);
+ else
+ google_book_emit_contact_added (book, contact);
+
+ g_object_unref (contact);
+ }
}
static void
process_initial_entry (gpointer list_data, gpointer user_data)
{
- GoogleBookPrivate *priv;
- GoogleBook *book = user_data;
- GDataEntry *entry;
- EContact *contact;
+ GoogleBookPrivate *priv;
+ GoogleBook *book = user_data;
+ GDataEntry *entry;
+ EContact *contact;
- __debug__ (G_STRFUNC);
- priv = GET_PRIVATE (book);
- entry = GDATA_ENTRY (list_data);
+ __debug__ (G_STRFUNC);
+ priv = GET_PRIVATE (book);
+ entry = GDATA_ENTRY (list_data);
- contact = google_book_cache_add_contact (book, entry);
+ contact = google_book_cache_add_contact (book, entry);
- google_book_emit_contact_added (GOOGLE_BOOK (book), contact);
- g_object_unref (contact);
+ google_book_emit_contact_added (GOOGLE_BOOK (book), contact);
+ g_object_unref (contact);
}
static gboolean
-google_book_get_new_contacts_in_chunks (GoogleBook *book,
- gint chunk_size,
- GError **error)
+google_book_get_new_contacts_in_chunks (GoogleBook *book, gint chunk_size, GError **error)
{
- GoogleBookPrivate *priv;
- GDataFeed *feed;
- GDataQuery *query;
- gchar *last_updated;
- GError *our_error = NULL;
- gboolean rv = TRUE;
- GTimeVal current_time;
- int results;
+ GoogleBookPrivate *priv;
+ GDataFeed *feed;
+ GDataQuery *query;
+ gchar *last_updated;
+ GError *our_error = NULL;
+ gboolean rv = TRUE;
+ GTimeVal current_time;
+ int results;
- priv = GET_PRIVATE (book);
+ priv = GET_PRIVATE (book);
- __debug__ (G_STRFUNC);
- g_return_val_if_fail (priv->service, FALSE);
+ __debug__ (G_STRFUNC);
+ g_return_val_if_fail (priv->service, FALSE);
- last_updated = google_book_cache_get_last_update (book);
+ last_updated = google_book_cache_get_last_update (book);
- google_book_cache_freeze (book);
+ google_book_cache_freeze (book);
- /* Build our query */
- query = GDATA_QUERY (gdata_contacts_query_new_with_limits (NULL, 1, chunk_size));
- if (last_updated) {
- GTimeVal updated;
+ /* Build our query */
+ query = GDATA_QUERY (gdata_contacts_query_new_with_limits (NULL, 1, chunk_size));
+ if (last_updated) {
+ GTimeVal updated;
- g_assert (g_time_val_from_iso8601 (last_updated, &updated) == TRUE);
- gdata_query_set_updated_min (query, &updated);
- gdata_contacts_query_set_show_deleted (GDATA_CONTACTS_QUERY (query), TRUE);
- }
+ g_assert (g_time_val_from_iso8601 (last_updated, &updated) == TRUE);
+ gdata_query_set_updated_min (query, &updated);
+ gdata_contacts_query_set_show_deleted (GDATA_CONTACTS_QUERY (query), TRUE);
+ }
- /* Get the paginated results */
- do {
- GList *entries;
+ /* Get the paginated results */
+ do {
+ GList *entries;
- /* Run the query */
- feed = gdata_contacts_service_query_contacts (GDATA_CONTACTS_SERVICE (priv->service), query, NULL, NULL, NULL, &our_error);
+ /* Run the query */
+ feed = gdata_contacts_service_query_contacts (GDATA_CONTACTS_SERVICE (priv->service), query, NULL, NULL, NULL, &our_error);
- if (our_error) {
- google_book_emit_sequence_complete (book, our_error);
- g_propagate_error (error, our_error);
+ if (our_error) {
+ google_book_emit_sequence_complete (book, our_error);
+ g_propagate_error (error, our_error);
- rv = FALSE;
- goto out;
- }
+ rv = FALSE;
+ goto out;
+ }
- entries = gdata_feed_get_entries (feed);
- results = entries ? g_list_length (entries) : 0;
- __debug__ ("Feed has %d entries", results);
+ entries = gdata_feed_get_entries (feed);
+ results = entries ? g_list_length (entries) : 0;
+ __debug__ ("Feed has %d entries", results);
- /* Process the entries from this page */
- if (last_updated)
- g_list_foreach (entries, process_subsequent_entry, book);
- else
- g_list_foreach (entries, process_initial_entry, book);
- g_object_unref (feed);
+ /* Process the entries from this page */
+ if (last_updated)
+ g_list_foreach (entries, process_subsequent_entry, book);
+ else
+ g_list_foreach (entries, process_initial_entry, book);
+ g_object_unref (feed);
- /* Move to the next page */
- gdata_query_next_page (query);
- } while (results == chunk_size);
+ /* Move to the next page */
+ gdata_query_next_page (query);
+ } while (results == chunk_size);
- /* Finish updating the cache */
- g_get_current_time (¤t_time);
- google_book_cache_set_last_update (book, ¤t_time);
- google_book_emit_sequence_complete (book, NULL);
+ /* Finish updating the cache */
+ g_get_current_time (¤t_time);
+ google_book_cache_set_last_update (book, ¤t_time);
+ google_book_emit_sequence_complete (book, NULL);
out:
- g_free (last_updated);
- google_book_cache_thaw (book);
+ g_free (last_updated);
+ google_book_cache_thaw (book);
- return rv;
+ return rv;
}
-EContact*
-google_book_get_contact (GoogleBook *book,
- const gchar *uid,
- GError **error)
+EContact *
+google_book_get_contact (GoogleBook *book, const gchar *uid, GError **error)
{
- GoogleBookPrivate *priv;
- EContact *contact;
- GError *child_error = NULL;
+ GoogleBookPrivate *priv;
+ EContact *contact;
+ GError *child_error = NULL;
+
+ priv = GET_PRIVATE (book);
- priv = GET_PRIVATE (book);
+ __debug__ (G_STRFUNC);
+ g_return_val_if_fail (IS_GOOGLE_BOOK (book), NULL);
- __debug__ (G_STRFUNC);
- g_return_val_if_fail (IS_GOOGLE_BOOK (book), NULL);
+ google_book_cache_refresh_if_needed (book, &child_error);
- google_book_cache_refresh_if_needed (book, &child_error);
+ contact = google_book_cache_get_contact (book, uid, NULL);
- contact = google_book_cache_get_contact (book, uid, NULL);
+ if (contact) {
+ /* We found the contact, so forget about errors during refresh */
+ if (child_error)
+ g_error_free (child_error);
- if (contact) {
- if (child_error) {
- /* We found the contact, so forget about errors during refresh */
- g_error_free (child_error);
- }
- return contact;
- }
+ return contact;
+ }
- if (!child_error)
- g_propagate_error (error, child_error);
- else
- g_set_error (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_NOT_FOUND, "Contact with uid %s not found in cache.", uid);
+ if (!child_error)
+ g_propagate_error (error, child_error);
+ else
+ g_set_error (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_NOT_FOUND, "Contact with uid %s not found in cache.", uid);
- return NULL;
+ return NULL;
}
-GList*
-google_book_get_all_contacts (GoogleBook *book,
- GError **error)
+GList *
+google_book_get_all_contacts (GoogleBook *book, GError **error)
{
- GoogleBookPrivate *priv;
- GList *contacts;
- GError *child_error = NULL;
+ GoogleBookPrivate *priv;
+ GList *contacts;
+ GError *child_error = NULL;
+
+ priv = GET_PRIVATE (book);
- priv = GET_PRIVATE (book);
+ __debug__ (G_STRFUNC);
+ g_return_val_if_fail (IS_GOOGLE_BOOK (book), NULL);
- __debug__ (G_STRFUNC);
- g_return_val_if_fail (IS_GOOGLE_BOOK (book), NULL);
+ google_book_cache_refresh_if_needed (book, &child_error);
- google_book_cache_refresh_if_needed (book, &child_error);
+ contacts = google_book_cache_get_contacts (book);
- contacts = google_book_cache_get_contacts (book);
+ if (contacts) {
+ /* We found the contact, so forget about errors during refresh */
+ if (child_error)
+ g_error_free (child_error);
- if (contacts) {
- if (child_error) {
- /* We found the contact, so forget about errors during refresh */
- g_error_free (child_error);
- }
- return contacts;
- }
+ return contacts;
+ }
- g_propagate_error (error, child_error);
- return NULL;
+ g_propagate_error (error, child_error);
+ return NULL;
}
static gboolean
on_refresh_idle (gpointer user_data)
{
- GoogleBook *book = user_data;
- GoogleBookPrivate *priv;
+ GoogleBook *book = user_data;
+ GoogleBookPrivate *priv;
- priv = GET_PRIVATE (book);
+ priv = GET_PRIVATE (book);
- priv->idle_id = 0;
+ priv->idle_id = 0;
- google_book_cache_refresh_if_needed (book, NULL);
+ google_book_cache_refresh_if_needed (book, NULL);
- return FALSE;
+ return FALSE;
}
-GList*
+GList *
google_book_get_all_contacts_in_live_mode (GoogleBook *book)
{
- GoogleBookPrivate *priv;
- gboolean need_update;
- GList *contacts;
+ GoogleBookPrivate *priv;
+ gboolean need_update;
+ GList *contacts;
- priv = GET_PRIVATE (book);
+ priv = GET_PRIVATE (book);
- __debug__ (G_STRFUNC);
- g_return_val_if_fail (IS_GOOGLE_BOOK (book), NULL);
+ __debug__ (G_STRFUNC);
+ g_return_val_if_fail (IS_GOOGLE_BOOK (book), NULL);
- priv->live_mode = TRUE;
+ priv->live_mode = TRUE;
- need_update = google_book_cache_needs_update (book, NULL);
+ need_update = google_book_cache_needs_update (book, NULL);
- if (need_update) {
- if (NULL == priv->service) {
- /* We need authorization first */
- google_book_emit_auth_required (book);
- } else {
- priv->idle_id = g_idle_add (on_refresh_idle, book);
- }
- }
- contacts = google_book_cache_get_contacts (book);
+ if (need_update) {
+ if (!priv->service) {
+ /* We need authorization first */
+ google_book_emit_auth_required (book);
+ } else {
+ priv->idle_id = g_idle_add (on_refresh_idle, book);
+ }
+ }
- __debug__ ("%d contacts found in cache", g_list_length (contacts));
- return contacts;
+ contacts = google_book_cache_get_contacts (book);
+ __debug__ ("%d contacts found in cache", g_list_length (contacts));
+
+ return contacts;
}
void
google_book_set_live_mode (GoogleBook *book, gboolean live_mode)
{
- GoogleBookPrivate *priv;
+ GoogleBookPrivate *priv;
+
+ priv = GET_PRIVATE (book);
- priv = GET_PRIVATE (book);
+ __debug__ (G_STRFUNC);
+ priv->live_mode = live_mode;
- __debug__ (G_STRFUNC);
- priv->live_mode = live_mode;
+ if (FALSE == live_mode && priv->refresh_id > 0) {
+ g_source_remove (priv->refresh_id);
+ priv->refresh_id = 0;
+ }
- if (FALSE == live_mode && priv->refresh_id > 0) {
- g_source_remove (priv->refresh_id);
- priv->refresh_id = 0;
- }
- if (priv->live_mode) {
- google_book_cache_refresh_if_needed (book, NULL);
- }
+ if (priv->live_mode)
+ google_book_cache_refresh_if_needed (book, NULL);
}
diff --git a/addressbook/backends/google/google-book.h b/addressbook/backends/google/google-book.h
index 09cc9b6..3fd4d21 100644
--- a/addressbook/backends/google/google-book.h
+++ b/addressbook/backends/google/google-book.h
@@ -27,40 +27,28 @@
G_BEGIN_DECLS
#define TYPE_GOOGLE_BOOK google_book_get_type()
-
-#define GOOGLE_BOOK(obj) \
- (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_GOOGLE_BOOK, GoogleBook))
-
-#define GOOGLE_BOOK_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_GOOGLE_BOOK, GoogleBookClass))
-
-#define IS_GOOGLE_BOOK(obj) \
- (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_GOOGLE_BOOK))
-
-#define IS_GOOGLE_BOOK_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_GOOGLE_BOOK))
-
-#define GOOGLE_BOOK_GET_CLASS(obj) \
- (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_GOOGLE_BOOK, GoogleBookClass))
+#define GOOGLE_BOOK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_GOOGLE_BOOK, GoogleBook))
+#define GOOGLE_BOOK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_GOOGLE_BOOK, GoogleBookClass))
+#define IS_GOOGLE_BOOK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_GOOGLE_BOOK))
+#define IS_GOOGLE_BOOK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_GOOGLE_BOOK))
+#define GOOGLE_BOOK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_GOOGLE_BOOK, GoogleBookClass))
typedef struct _GoogleBook GoogleBook;
typedef struct _GoogleBookClass GoogleBookClass;
-struct _GoogleBook
-{
- GObject parent;
+struct _GoogleBook {
+ GObject parent;
};
-struct _GoogleBookClass
-{
- GObjectClass parent_class;
+struct _GoogleBookClass {
+ GObjectClass parent_class;
- void (*contact_added) (EContact* contact);
- void (*contact_changed) (EContact* contact);
- void (*contact_removed) (const gchar *uid);
- void (*sequence_complete) (GError *error);
+ void (*contact_added) (EContact* contact);
+ void (*contact_changed) (EContact* contact);
+ void (*contact_removed) (const gchar *uid);
+ void (*sequence_complete) (GError *error);
- void (*auth_required) (void);
+ void (*auth_required) (void);
};
typedef void (*GoogleBookContactRetrievedCallback) (EContact *contact, gpointer user_data);
@@ -72,15 +60,15 @@ GoogleBook* google_book_new (const gchar *username, gboolean use_cache);
gboolean google_book_connect_to_google (GoogleBook *book, const gchar *password, GError **error);
void google_book_set_offline_mode (GoogleBook *book, gboolean offline);
-void google_book_set_live_mode (GoogleBook *book, gboolean live_mode);
+void google_book_set_live_mode (GoogleBook *book, gboolean live_mode);
-gboolean google_book_add_contact (GoogleBook *book, EContact *contact, EContact **out_contact, GError **error);
+gboolean google_book_add_contact (GoogleBook *book, EContact *contact, EContact **out_contact, GError **error);
gboolean google_book_update_contact (GoogleBook *book, EContact *contact, EContact **out_contact, GError **error);
gboolean google_book_remove_contact (GoogleBook *book, const gchar *uid, GError **error);
-EContact *google_book_get_contact (GoogleBook *book, const gchar * uid, GError **error);
-GList *google_book_get_all_contacts (GoogleBook *book, GError **error);
-GList *google_book_get_all_contacts_in_live_mode (GoogleBook *book);
+EContact *google_book_get_contact (GoogleBook *book, const gchar * uid, GError **error);
+GList *google_book_get_all_contacts (GoogleBook *book, GError **error);
+GList *google_book_get_all_contacts_in_live_mode (GoogleBook *book);
G_END_DECLS
diff --git a/addressbook/backends/google/util.c b/addressbook/backends/google/util.c
index 626a359..56e50f5 100644
--- a/addressbook/backends/google/util.c
+++ b/addressbook/backends/google/util.c
@@ -41,848 +41,809 @@ static GDataGDIMAddress *gdata_gd_im_address_from_attribute (EVCardAttribute *at
static GDataGDPhoneNumber *gdata_gd_phone_number_from_attribute (EVCardAttribute *attr, gboolean *primary);
static GDataGDPostalAddress *gdata_gd_postal_address_from_attribute (EVCardAttribute *attr, gboolean *primary);
-static gboolean
-is_known_google_im_protocol (const gchar *protocol);
+static gboolean is_known_google_im_protocol (const gchar *protocol);
-GDataEntry*
+GDataEntry *
_gdata_entry_new_from_e_contact (EContact *contact)
{
- GDataEntry *entry = GDATA_ENTRY (gdata_contacts_contact_new (NULL));
+ GDataEntry *entry = GDATA_ENTRY (gdata_contacts_contact_new (NULL));
- if (_gdata_entry_update_from_e_contact (entry, contact))
- return entry;
+ if (_gdata_entry_update_from_e_contact (entry, contact))
+ return entry;
- g_object_unref (entry);
+ g_object_unref (entry);
- return NULL;
+ return NULL;
}
gboolean
-_gdata_entry_update_from_e_contact (GDataEntry *entry,
- EContact *contact)
+_gdata_entry_update_from_e_contact (GDataEntry *entry, EContact *contact)
{
- GList *attributes, *iter;
- EContactName *name_struct = NULL;
- gboolean have_email_primary = FALSE;
- gboolean have_im_primary = FALSE;
- gboolean have_phone_primary = FALSE;
- gboolean have_postal_primary = FALSE;
-
- attributes = e_vcard_get_attributes (E_VCARD (contact));
-
- /* N and FN */
- name_struct = e_contact_get (contact, E_CONTACT_NAME);
- if (name_struct) {
- GDataGDName *name;
- const gchar *given = NULL, *family = NULL;
-
- if (name_struct->given && *(name_struct->given) != '\0')
- given = name_struct->given;
- if (name_struct->family && *(name_struct->family) != '\0')
- family = name_struct->family;
-
- name = gdata_gd_name_new (given, family);
- if (name_struct->additional && *(name_struct->additional) != '\0')
- gdata_gd_name_set_additional_name (name, name_struct->additional);
- if (name_struct->prefixes && *(name_struct->prefixes) != '\0')
- gdata_gd_name_set_prefix (name, name_struct->prefixes);
- if (name_struct->suffixes && *(name_struct->suffixes) != '\0')
- gdata_gd_name_set_suffix (name, name_struct->suffixes);
- gdata_gd_name_set_full_name (name, e_contact_get (contact, E_CONTACT_FULL_NAME));
-
- gdata_contacts_contact_set_name (GDATA_CONTACTS_CONTACT (entry), name);
- g_object_unref (name);
- }
-
- /* Clear out all the old attributes */
- gdata_contacts_contact_remove_all_email_addresses (GDATA_CONTACTS_CONTACT (entry));
- gdata_contacts_contact_remove_all_phone_numbers (GDATA_CONTACTS_CONTACT (entry));
- gdata_contacts_contact_remove_all_postal_addresses (GDATA_CONTACTS_CONTACT (entry));
- gdata_contacts_contact_remove_all_im_addresses (GDATA_CONTACTS_CONTACT (entry));
-
- /* We walk them in reverse order, so we can find
- * the correct primaries */
- iter = g_list_last (attributes);
- for (; iter; iter = iter->prev) {
- EVCardAttribute *attr;
- const gchar *name;
-
- attr = iter->data;
- name = e_vcard_attribute_get_name (attr);
-
- /* EMAIL */
-
- /* Ignore UID, VERSION, X-EVOLUTION-FILE-AS, N, FN, LABEL */
- if (0 == g_ascii_strcasecmp (name, EVC_UID) ||
- 0 == g_ascii_strcasecmp (name, EVC_N) ||
- 0 == g_ascii_strcasecmp (name, EVC_FN) ||
- 0 == g_ascii_strcasecmp (name, EVC_LABEL) ||
- 0 == g_ascii_strcasecmp (name, EVC_VERSION) ||
- 0 == g_ascii_strcasecmp (name, EVC_X_FILE_AS)) {
- } else
- if (0 == g_ascii_strcasecmp (name, EVC_EMAIL)) {
- GDataGDEmailAddress *email;
-
- email = gdata_gd_email_address_from_attribute
- (attr, &have_email_primary);
- if (email) {
- gdata_contacts_contact_add_email_address (GDATA_CONTACTS_CONTACT (entry), email);
- g_object_unref (email);
- }
- } else
-
- /* TEL */
- if (0 == g_ascii_strcasecmp (name, EVC_TEL)) {
- GDataGDPhoneNumber *number;
-
- number = gdata_gd_phone_number_from_attribute
- (attr, &have_phone_primary);
- if (number) {
- gdata_contacts_contact_add_phone_number (GDATA_CONTACTS_CONTACT (entry), number);
- g_object_unref (number);
- }
- } else
-
- /* ADR (we ignore LABEL, since it should be the same as ADR, and ADR is more structured) */
- if (0 == g_ascii_strcasecmp (name, EVC_ADR)) {
- GDataGDPostalAddress *address;
-
- address = gdata_gd_postal_address_from_attribute
- (attr, &have_postal_primary);
- if (address) {
- gdata_contacts_contact_add_postal_address (GDATA_CONTACTS_CONTACT (entry), address);
- g_object_unref (address);
- }
- } else
-
- /* X-IM */
- if (0 == g_ascii_strncasecmp (name, "X-", 2) &&
- is_known_google_im_protocol (name + 2)) {
- GDataGDIMAddress *im;
-
- im = gdata_gd_im_address_from_attribute
- (attr, &have_im_primary);
- if (im) {
- gdata_contacts_contact_add_im_address (GDATA_CONTACTS_CONTACT (entry), im);
- g_object_unref (im);
- }
- } else if (e_vcard_attribute_is_single_valued (attr)) {
- gchar *value;
-
- /* Add the attribute as an extended property */
- value = e_vcard_attribute_get_value (attr);
- gdata_contacts_contact_set_extended_property (GDATA_CONTACTS_CONTACT (entry), name, value);
- g_free (value);
- } else {
- GList *values;
-
- values = e_vcard_attribute_get_values (attr);
- if (values && values->data && ((gchar *)values->data)[0]) {
- __debug__ ("unsupported vcard field: %s: %s", name, (gchar *)values->data);
- }
- }
- }
-
- return TRUE;
+ GList *attributes, *iter;
+ EContactName *name_struct = NULL;
+ gboolean have_email_primary = FALSE;
+ gboolean have_im_primary = FALSE;
+ gboolean have_phone_primary = FALSE;
+ gboolean have_postal_primary = FALSE;
+
+ attributes = e_vcard_get_attributes (E_VCARD (contact));
+
+ /* N and FN */
+ name_struct = e_contact_get (contact, E_CONTACT_NAME);
+ if (name_struct) {
+ GDataGDName *name;
+ const gchar *given = NULL, *family = NULL;
+
+ if (name_struct->given && *(name_struct->given) != '\0')
+ given = name_struct->given;
+ if (name_struct->family && *(name_struct->family) != '\0')
+ family = name_struct->family;
+
+ name = gdata_gd_name_new (given, family);
+ if (name_struct->additional && *(name_struct->additional) != '\0')
+ gdata_gd_name_set_additional_name (name, name_struct->additional);
+ if (name_struct->prefixes && *(name_struct->prefixes) != '\0')
+ gdata_gd_name_set_prefix (name, name_struct->prefixes);
+ if (name_struct->suffixes && *(name_struct->suffixes) != '\0')
+ gdata_gd_name_set_suffix (name, name_struct->suffixes);
+ gdata_gd_name_set_full_name (name, e_contact_get (contact, E_CONTACT_FULL_NAME));
+
+ gdata_contacts_contact_set_name (GDATA_CONTACTS_CONTACT (entry), name);
+ g_object_unref (name);
+ }
+
+ /* Clear out all the old attributes */
+ gdata_contacts_contact_remove_all_email_addresses (GDATA_CONTACTS_CONTACT (entry));
+ gdata_contacts_contact_remove_all_phone_numbers (GDATA_CONTACTS_CONTACT (entry));
+ gdata_contacts_contact_remove_all_postal_addresses (GDATA_CONTACTS_CONTACT (entry));
+ gdata_contacts_contact_remove_all_im_addresses (GDATA_CONTACTS_CONTACT (entry));
+
+ /* We walk them in reverse order, so we can find
+ * the correct primaries */
+ iter = g_list_last (attributes);
+ for (; iter; iter = iter->prev) {
+ EVCardAttribute *attr;
+ const gchar *name;
+
+ attr = iter->data;
+ name = e_vcard_attribute_get_name (attr);
+
+ if (0 == g_ascii_strcasecmp (name, EVC_UID) ||
+ 0 == g_ascii_strcasecmp (name, EVC_N) ||
+ 0 == g_ascii_strcasecmp (name, EVC_FN) ||
+ 0 == g_ascii_strcasecmp (name, EVC_LABEL) ||
+ 0 == g_ascii_strcasecmp (name, EVC_VERSION) ||
+ 0 == g_ascii_strcasecmp (name, EVC_X_FILE_AS)) {
+ /* Ignore UID, VERSION, X-EVOLUTION-FILE-AS, N, FN, LABEL */
+ } else if (0 == g_ascii_strcasecmp (name, EVC_EMAIL)) {
+ /* EMAIL */
+ GDataGDEmailAddress *email;
+
+ email = gdata_gd_email_address_from_attribute (attr, &have_email_primary);
+ if (email) {
+ gdata_contacts_contact_add_email_address (GDATA_CONTACTS_CONTACT (entry), email);
+ g_object_unref (email);
+ }
+ } else if (0 == g_ascii_strcasecmp (name, EVC_TEL)) {
+ /* TEL */
+ GDataGDPhoneNumber *number;
+
+ number = gdata_gd_phone_number_from_attribute (attr, &have_phone_primary);
+ if (number) {
+ gdata_contacts_contact_add_phone_number (GDATA_CONTACTS_CONTACT (entry), number);
+ g_object_unref (number);
+ }
+ } else if (0 == g_ascii_strcasecmp (name, EVC_ADR)) {
+ /* ADR (we ignore LABEL, since it should be the same as ADR, and ADR is more structured) */
+ GDataGDPostalAddress *address;
+
+ address = gdata_gd_postal_address_from_attribute (attr, &have_postal_primary);
+ if (address) {
+ gdata_contacts_contact_add_postal_address (GDATA_CONTACTS_CONTACT (entry), address);
+ g_object_unref (address);
+ }
+ } else if (0 == g_ascii_strncasecmp (name, "X-", 2) && is_known_google_im_protocol (name + 2)) {
+ /* X-IM */
+ GDataGDIMAddress *im;
+
+ im = gdata_gd_im_address_from_attribute (attr, &have_im_primary);
+ if (im) {
+ gdata_contacts_contact_add_im_address (GDATA_CONTACTS_CONTACT (entry), im);
+ g_object_unref (im);
+ }
+ } else if (e_vcard_attribute_is_single_valued (attr)) {
+ gchar *value;
+
+ /* Add the attribute as an extended property */
+ value = e_vcard_attribute_get_value (attr);
+ gdata_contacts_contact_set_extended_property (GDATA_CONTACTS_CONTACT (entry), name, value);
+ g_free (value);
+ } else {
+ GList *values;
+
+ values = e_vcard_attribute_get_values (attr);
+ if (values && values->data && ((gchar *)values->data)[0])
+ __debug__ ("unsupported vcard field: %s: %s", name, (gchar *)values->data);
+ }
+ }
+
+ return TRUE;
}
static void
foreach_extended_props_cb (const gchar *name, const gchar *value, EVCard *vcard)
{
- EVCardAttribute *attr;
+ EVCardAttribute *attr;
- attr = e_vcard_attribute_new (NULL, name);
- e_vcard_add_attribute_with_value (vcard, attr, value);
+ attr = e_vcard_attribute_new (NULL, name);
+ e_vcard_add_attribute_with_value (vcard, attr, value);
}
-EContact*
+EContact *
_e_contact_new_from_gdata_entry (GDataEntry *entry)
{
- EVCard *vcard;
- EVCardAttribute *attr;
- GList *email_addresses, *im_addresses, *phone_numbers, *postal_addresses;
- const gchar *uid;
- GList *itr;
- GDataGDName *name;
- GDataGDEmailAddress *email;
- GDataGDIMAddress *im;
- GDataGDPhoneNumber *phone_number;
- GDataGDPostalAddress *postal_address;
- GHashTable *extended_props;
-
- uid = gdata_entry_get_id (entry);
- if (NULL == uid) {
- return NULL;
- }
-
- vcard = E_VCARD (e_contact_new ());
-
- /* UID */
- attr = e_vcard_attribute_new (NULL, EVC_UID);
- e_vcard_add_attribute_with_value (vcard, attr, uid);
-
- /* FN, N */
- name = gdata_contacts_contact_get_name (GDATA_CONTACTS_CONTACT (entry));
- if (name) {
- EContactName name_struct;
-
- /* Set the full name */
- e_contact_set (E_CONTACT (vcard), E_CONTACT_FULL_NAME, gdata_gd_name_get_full_name (name));
-
- /* We just need to set the E_CONTACT_NAME field, and all the other name attribute values
- * in the EContact will be populated automatically from that */
- name_struct.family = (gchar*) gdata_gd_name_get_family_name (name);
- name_struct.given = (gchar*) gdata_gd_name_get_given_name (name);
- name_struct.additional = (gchar*) gdata_gd_name_get_additional_name (name);
- name_struct.prefixes = (gchar*) gdata_gd_name_get_prefix (name);
- name_struct.suffixes = (gchar*) gdata_gd_name_get_suffix (name);
-
- e_contact_set (E_CONTACT (vcard), E_CONTACT_NAME, &name_struct);
- }
-
- /* EMAIL - primary first */
- email = gdata_contacts_contact_get_primary_email_address (GDATA_CONTACTS_CONTACT (entry));
- add_attribute_from_gdata_gd_email_address (vcard, email);
-
- email_addresses = gdata_contacts_contact_get_email_addresses (GDATA_CONTACTS_CONTACT (entry));
- for (itr = email_addresses; itr; itr = itr->next) {
- email = itr->data;
- if (gdata_gd_email_address_is_primary (email) == TRUE)
- continue;
- add_attribute_from_gdata_gd_email_address (vcard, email);
- }
-
- /* X-IM - primary first */
- im = gdata_contacts_contact_get_primary_im_address (GDATA_CONTACTS_CONTACT (entry));
- add_attribute_from_gdata_gd_im_address (vcard, im);
-
- im_addresses = gdata_contacts_contact_get_im_addresses (GDATA_CONTACTS_CONTACT (entry));
- for (itr = im_addresses; itr; itr = itr->next) {
- im = itr->data;
- if (gdata_gd_im_address_is_primary (im) == TRUE)
- continue;
- add_attribute_from_gdata_gd_im_address (vcard, im);
- }
-
- /* TEL - primary first */
- phone_number = gdata_contacts_contact_get_primary_phone_number (GDATA_CONTACTS_CONTACT (entry));
- add_attribute_from_gdata_gd_phone_number (vcard, phone_number);
-
- phone_numbers = gdata_contacts_contact_get_phone_numbers (GDATA_CONTACTS_CONTACT (entry));
- for (itr = phone_numbers; itr; itr = itr->next) {
- phone_number = itr->data;
- if (gdata_gd_phone_number_is_primary (phone_number) == TRUE)
- continue;
- add_attribute_from_gdata_gd_phone_number (vcard, phone_number);
- }
-
- /* LABEL and ADR - primary first */
- postal_address = gdata_contacts_contact_get_primary_postal_address (GDATA_CONTACTS_CONTACT (entry));
- add_attribute_from_gdata_gd_postal_address (vcard, postal_address);
-
- postal_addresses = gdata_contacts_contact_get_postal_addresses (GDATA_CONTACTS_CONTACT (entry));
- for (itr = postal_addresses; itr; itr = itr->next) {
- postal_address = itr->data;
- if (gdata_gd_postal_address_is_primary (postal_address) == TRUE)
- continue;
- add_attribute_from_gdata_gd_postal_address (vcard, postal_address);
- }
-
- /* Extended properties */
- extended_props = gdata_contacts_contact_get_extended_properties (GDATA_CONTACTS_CONTACT (entry));
- g_hash_table_foreach (extended_props, (GHFunc) foreach_extended_props_cb, vcard);
-
- return E_CONTACT (vcard);
+ EVCard *vcard;
+ EVCardAttribute *attr;
+ GList *email_addresses, *im_addresses, *phone_numbers, *postal_addresses;
+ const gchar *uid;
+ GList *itr;
+ GDataGDName *name;
+ GDataGDEmailAddress *email;
+ GDataGDIMAddress *im;
+ GDataGDPhoneNumber *phone_number;
+ GDataGDPostalAddress *postal_address;
+ GHashTable *extended_props;
+
+ uid = gdata_entry_get_id (entry);
+ if (NULL == uid)
+ return NULL;
+
+ vcard = E_VCARD (e_contact_new ());
+
+ /* UID */
+ attr = e_vcard_attribute_new (NULL, EVC_UID);
+ e_vcard_add_attribute_with_value (vcard, attr, uid);
+
+ /* FN, N */
+ name = gdata_contacts_contact_get_name (GDATA_CONTACTS_CONTACT (entry));
+ if (name) {
+ EContactName name_struct;
+
+ /* Set the full name */
+ e_contact_set (E_CONTACT (vcard), E_CONTACT_FULL_NAME, gdata_gd_name_get_full_name (name));
+
+ /* We just need to set the E_CONTACT_NAME field, and all the other name attribute values
+ * in the EContact will be populated automatically from that */
+ name_struct.family = (gchar*) gdata_gd_name_get_family_name (name);
+ name_struct.given = (gchar*) gdata_gd_name_get_given_name (name);
+ name_struct.additional = (gchar*) gdata_gd_name_get_additional_name (name);
+ name_struct.prefixes = (gchar*) gdata_gd_name_get_prefix (name);
+ name_struct.suffixes = (gchar*) gdata_gd_name_get_suffix (name);
+
+ e_contact_set (E_CONTACT (vcard), E_CONTACT_NAME, &name_struct);
+ }
+
+ /* EMAIL - primary first */
+ email = gdata_contacts_contact_get_primary_email_address (GDATA_CONTACTS_CONTACT (entry));
+ add_attribute_from_gdata_gd_email_address (vcard, email);
+
+ email_addresses = gdata_contacts_contact_get_email_addresses (GDATA_CONTACTS_CONTACT (entry));
+ for (itr = email_addresses; itr; itr = itr->next) {
+ email = itr->data;
+ if (gdata_gd_email_address_is_primary (email) == TRUE)
+ continue;
+ add_attribute_from_gdata_gd_email_address (vcard, email);
+ }
+
+ /* X-IM - primary first */
+ im = gdata_contacts_contact_get_primary_im_address (GDATA_CONTACTS_CONTACT (entry));
+ add_attribute_from_gdata_gd_im_address (vcard, im);
+
+ im_addresses = gdata_contacts_contact_get_im_addresses (GDATA_CONTACTS_CONTACT (entry));
+ for (itr = im_addresses; itr; itr = itr->next) {
+ im = itr->data;
+ if (gdata_gd_im_address_is_primary (im) == TRUE)
+ continue;
+ add_attribute_from_gdata_gd_im_address (vcard, im);
+ }
+
+ /* TEL - primary first */
+ phone_number = gdata_contacts_contact_get_primary_phone_number (GDATA_CONTACTS_CONTACT (entry));
+ add_attribute_from_gdata_gd_phone_number (vcard, phone_number);
+
+ phone_numbers = gdata_contacts_contact_get_phone_numbers (GDATA_CONTACTS_CONTACT (entry));
+ for (itr = phone_numbers; itr; itr = itr->next) {
+ phone_number = itr->data;
+ if (gdata_gd_phone_number_is_primary (phone_number) == TRUE)
+ continue;
+ add_attribute_from_gdata_gd_phone_number (vcard, phone_number);
+ }
+
+ /* LABEL and ADR - primary first */
+ postal_address = gdata_contacts_contact_get_primary_postal_address (GDATA_CONTACTS_CONTACT (entry));
+ add_attribute_from_gdata_gd_postal_address (vcard, postal_address);
+
+ postal_addresses = gdata_contacts_contact_get_postal_addresses (GDATA_CONTACTS_CONTACT (entry));
+ for (itr = postal_addresses; itr; itr = itr->next) {
+ postal_address = itr->data;
+ if (gdata_gd_postal_address_is_primary (postal_address) == TRUE)
+ continue;
+ add_attribute_from_gdata_gd_postal_address (vcard, postal_address);
+ }
+
+ /* Extended properties */
+ extended_props = gdata_contacts_contact_get_extended_properties (GDATA_CONTACTS_CONTACT (entry));
+ g_hash_table_foreach (extended_props, (GHFunc) foreach_extended_props_cb, vcard);
+
+ return E_CONTACT (vcard);
}
void
_e_contact_add_gdata_entry_xml (EContact *contact, GDataEntry *entry)
{
- EVCardAttribute *attr;
- gchar *entry_xml;
- GDataLink *link;
-
- /* Cache the XML representing the entry */
- entry_xml = gdata_parsable_get_xml (GDATA_PARSABLE (entry));
- attr = e_vcard_attribute_new ("", GDATA_ENTRY_XML_ATTR);
- e_vcard_attribute_add_value (attr, entry_xml);
- e_vcard_add_attribute (E_VCARD (contact), attr);
- g_free (entry_xml);
-
- /* Also add the update URI for the entry, since that's not serialised by gdata_parsable_get_xml */
- link = gdata_entry_look_up_link (entry, GDATA_LINK_EDIT);
- if (link != NULL) {
- attr = e_vcard_attribute_new ("", GDATA_ENTRY_LINK_ATTR);
- e_vcard_attribute_add_value (attr, gdata_link_get_uri (link));
- e_vcard_add_attribute (E_VCARD (contact), attr);
- }
+ EVCardAttribute *attr;
+ gchar *entry_xml;
+ GDataLink *link;
+
+ /* Cache the XML representing the entry */
+ entry_xml = gdata_parsable_get_xml (GDATA_PARSABLE (entry));
+ attr = e_vcard_attribute_new ("", GDATA_ENTRY_XML_ATTR);
+ e_vcard_attribute_add_value (attr, entry_xml);
+ e_vcard_add_attribute (E_VCARD (contact), attr);
+ g_free (entry_xml);
+
+ /* Also add the update URI for the entry, since that's not serialised by gdata_parsable_get_xml */
+ link = gdata_entry_look_up_link (entry, GDATA_LINK_EDIT);
+ if (link != NULL) {
+ attr = e_vcard_attribute_new ("", GDATA_ENTRY_LINK_ATTR);
+ e_vcard_attribute_add_value (attr, gdata_link_get_uri (link));
+ e_vcard_add_attribute (E_VCARD (contact), attr);
+ }
}
void
_e_contact_remove_gdata_entry_xml (EContact *contact)
{
- e_vcard_remove_attributes (E_VCARD (contact), NULL, GDATA_ENTRY_XML_ATTR);
- e_vcard_remove_attributes (E_VCARD (contact), NULL, GDATA_ENTRY_LINK_ATTR);
+ e_vcard_remove_attributes (E_VCARD (contact), NULL, GDATA_ENTRY_XML_ATTR);
+ e_vcard_remove_attributes (E_VCARD (contact), NULL, GDATA_ENTRY_LINK_ATTR);
}
const gchar *
_e_contact_get_gdata_entry_xml (EContact *contact, const gchar **edit_link)
{
- EVCardAttribute *attr;
- GList *values = NULL;
-
- /* Return the edit link if asked */
- if (edit_link != NULL) {
- attr = e_vcard_get_attribute (E_VCARD (contact), GDATA_ENTRY_LINK_ATTR);
- if (attr != NULL)
- values = e_vcard_attribute_get_values (attr);
- if (values != NULL)
- *edit_link = values->data;
- }
-
- /* Return the entry's XML */
- attr = e_vcard_get_attribute (E_VCARD (contact), GDATA_ENTRY_XML_ATTR);
- values = e_vcard_attribute_get_values (attr);
-
- return values ? values->data : NULL;
+ EVCardAttribute *attr;
+ GList *values = NULL;
+
+ /* Return the edit link if asked */
+ if (edit_link != NULL) {
+ attr = e_vcard_get_attribute (E_VCARD (contact), GDATA_ENTRY_LINK_ATTR);
+ if (attr != NULL)
+ values = e_vcard_attribute_get_values (attr);
+ if (values != NULL)
+ *edit_link = values->data;
+ }
+
+ /* Return the entry's XML */
+ attr = e_vcard_get_attribute (E_VCARD (contact), GDATA_ENTRY_XML_ATTR);
+ values = e_vcard_attribute_get_values (attr);
+
+ return values ? values->data : NULL;
}
struct RelTypeMap {
- const gchar *rel;
- const gchar *types[2];
+ const gchar *rel;
+ const gchar *types[2];
};
/* NOTE: These maps must be kept ordered with the one-to-many types first */
static const struct RelTypeMap rel_type_map_phone[] = {
- {"home", { "HOME", "VOICE"}},
- {"home_fax", { "HOME", "FAX"}},
- {"work", { "WORK", "VOICE"}},
- {"work_fax", { "WORK", "FAX"}},
- {"work_mobile", { "WORK", "CELL"}},
- {"work_pager", { "WORK", "PAGER"}},
- {"assistant", { EVC_X_ASSISTANT, NULL}},
- {"callback", { EVC_X_CALLBACK, NULL}},
- {"car", { "CAR", NULL}},
- {"company_main", {EVC_X_COMPANY, NULL}},
- {"fax", { "FAX", NULL}},
- {"isdn", { "ISDN", NULL}},
- {"main", { "PREF", NULL}},
- {"mobile", { "CELL", NULL}},
- {"other", { "VOICE", NULL}},
- {"other_fax", { "FAX", NULL}},
- {"pager", { "PAGER", NULL}},
- {"radio", { EVC_X_RADIO, NULL}},
- {"telex", { EVC_X_TELEX, NULL}},
- {"tty_tdd", { EVC_X_TTYTDD, NULL}}
+ { "home", { "HOME", "VOICE" }},
+ { "home_fax", { "HOME", "FAX" }},
+ { "work", { "WORK", "VOICE" }},
+ { "work_fax", { "WORK", "FAX" }},
+ { "work_mobile", { "WORK", "CELL" }},
+ { "work_pager", { "WORK", "PAGER" }},
+ { "assistant", { EVC_X_ASSISTANT, NULL }},
+ { "callback", { EVC_X_CALLBACK, NULL }},
+ { "car", { "CAR", NULL }},
+ { "company_main", {EVC_X_COMPANY, NULL }},
+ { "fax", { "FAX", NULL }},
+ { "isdn", { "ISDN", NULL }},
+ { "main", { "PREF", NULL }},
+ { "mobile", { "CELL", NULL }},
+ { "other", { "VOICE", NULL }},
+ { "other_fax", { "FAX", NULL }},
+ { "pager", { "PAGER", NULL }},
+ { "radio", { EVC_X_RADIO, NULL }},
+ { "telex", { EVC_X_TELEX, NULL }},
+ { "tty_tdd", { EVC_X_TTYTDD, NULL }}
};
static const struct RelTypeMap rel_type_map_im[] = {
- {"home", { "HOME", NULL}},
- {"netmeeting", { "NETMEETING", NULL}},
- {"other", { "OTHER", NULL}},
- {"work", { "WORK", NULL}},
+ { "home", { "HOME", NULL }},
+ { "netmeeting", { "NETMEETING", NULL }},
+ { "other", { "OTHER", NULL }},
+ { "work", { "WORK", NULL }},
};
static const struct RelTypeMap rel_type_map_others[] = {
- {"home", { "HOME", NULL}},
- {"other", { "OTHER", NULL}},
- {"work", { "WORK", NULL}},
+ { "home", { "HOME", NULL }},
+ { "other", { "OTHER", NULL }},
+ { "work", { "WORK", NULL }},
};
static gboolean
-_add_type_param_from_google_rel (EVCardAttribute *attr,
- const struct RelTypeMap rel_type_map[],
- guint map_len,
- const gchar *rel)
+_add_type_param_from_google_rel (EVCardAttribute *attr, const struct RelTypeMap rel_type_map[], guint map_len, const gchar *rel)
{
- const gchar * field;
- guint i;
-
- field = strstr (rel ? rel : "", "#");
- if (NULL == field)
- return FALSE;
-
- field++;
- for (i = 0; i < map_len; i++) {
- if (0 == g_ascii_strcasecmp (rel_type_map[i].rel, field)) {
- EVCardAttributeParam *param;
- param = e_vcard_attribute_param_new ("TYPE");
- e_vcard_attribute_param_add_value (param, rel_type_map[i].types[0]);
- if (rel_type_map[i].types[1])
- e_vcard_attribute_param_add_value (param, rel_type_map[i].types[1]);
- e_vcard_attribute_add_param (attr, param);
- return TRUE;
- }
- }
- g_warning ("Unknown relationship '%s'", rel);
-
- return TRUE;
+ const gchar * field;
+ guint i;
+
+ field = strstr (rel ? rel : "", "#");
+ if (NULL == field)
+ return FALSE;
+
+ field++;
+ for (i = 0; i < map_len; i++) {
+ if (0 == g_ascii_strcasecmp (rel_type_map[i].rel, field)) {
+ EVCardAttributeParam *param;
+ param = e_vcard_attribute_param_new ("TYPE");
+ e_vcard_attribute_param_add_value (param, rel_type_map[i].types[0]);
+ if (rel_type_map[i].types[1])
+ e_vcard_attribute_param_add_value (param, rel_type_map[i].types[1]);
+ e_vcard_attribute_add_param (attr, param);
+ return TRUE;
+ }
+ }
+ g_warning ("Unknown relationship '%s'", rel);
+
+ return TRUE;
}
static gboolean
add_type_param_from_google_rel_phone (EVCardAttribute *attr, const gchar *rel)
{
- return _add_type_param_from_google_rel (attr,
- rel_type_map_phone,
- G_N_ELEMENTS (rel_type_map_phone),
- rel);
+ return _add_type_param_from_google_rel (attr, rel_type_map_phone, G_N_ELEMENTS (rel_type_map_phone), rel);
}
static gboolean
add_type_param_from_google_rel_im (EVCardAttribute *attr, const gchar *rel)
{
- return _add_type_param_from_google_rel (attr,
- rel_type_map_im,
- G_N_ELEMENTS (rel_type_map_im),
- rel);
+ return _add_type_param_from_google_rel (attr, rel_type_map_im, G_N_ELEMENTS (rel_type_map_im), rel);
}
static gboolean
add_type_param_from_google_rel (EVCardAttribute *attr, const gchar *rel)
{
- return _add_type_param_from_google_rel (attr,
- rel_type_map_others,
- G_N_ELEMENTS (rel_type_map_others),
- rel);
+ return _add_type_param_from_google_rel (attr, rel_type_map_others, G_N_ELEMENTS (rel_type_map_others), rel);
}
static void
add_label_param (EVCardAttribute *attr, const gchar *label)
{
- if (label && label[0] != '\0') {
- EVCardAttributeParam *param;
- param = e_vcard_attribute_param_new (GOOGLE_LABEL_PARAM);
- e_vcard_attribute_add_param_with_value (attr, param, label);
- }
+ if (label && label[0] != '\0') {
+ EVCardAttributeParam *param;
+ param = e_vcard_attribute_param_new (GOOGLE_LABEL_PARAM);
+ e_vcard_attribute_add_param_with_value (attr, param, label);
+ }
}
static gchar *
-_google_rel_from_types (GList *types,
- const struct RelTypeMap rel_type_map[],
- guint map_len)
+_google_rel_from_types (GList *types, const struct RelTypeMap rel_type_map[], guint map_len)
{
- const gchar format[] = "http://schemas.google.com/g/2005#%s";
- guint i;
-
- /* For each of the entries in the map... */
- for (i = 0; i < map_len; i++) {
- GList *cur;
- gboolean first_matched = FALSE, second_matched = rel_type_map[i].types[1] ? FALSE : TRUE;
-
- /* ...iterate through all the vCard's types and see if two of them match the types in the current map entry. */
- for (cur = types; cur != NULL; cur = cur->next) {
- if (0 == g_ascii_strcasecmp (rel_type_map[i].types[0], cur->data))
- first_matched = TRUE;
- else if (!rel_type_map[i].types[1] || 0 == g_ascii_strcasecmp (rel_type_map[i].types[1], cur->data))
- second_matched = TRUE;
-
- /* If they do, return the rel value from that entry... */
- if (first_matched && second_matched)
- return g_strdup_printf (format, rel_type_map[i].rel);
- }
- }
-
- /* ...otherwise return an "other" result. */
- return g_strdup_printf (format, "other");
+ const gchar format[] = "http://schemas.google.com/g/2005#%s";
+ guint i;
+
+ /* For each of the entries in the map... */
+ for (i = 0; i < map_len; i++) {
+ GList *cur;
+ gboolean first_matched = FALSE, second_matched = rel_type_map[i].types[1] ? FALSE : TRUE;
+
+ /* ...iterate through all the vCard's types and see if two of them match the types in the current map entry. */
+ for (cur = types; cur != NULL; cur = cur->next) {
+ if (0 == g_ascii_strcasecmp (rel_type_map[i].types[0], cur->data))
+ first_matched = TRUE;
+ else if (!rel_type_map[i].types[1] || 0 == g_ascii_strcasecmp (rel_type_map[i].types[1], cur->data))
+ second_matched = TRUE;
+
+ /* If they do, return the rel value from that entry... */
+ if (first_matched && second_matched)
+ return g_strdup_printf (format, rel_type_map[i].rel);
+ }
+ }
+
+ /* ...otherwise return an "other" result. */
+ return g_strdup_printf (format, "other");
}
static gchar *
google_rel_from_types (GList *types)
{
- return _google_rel_from_types (types,
- rel_type_map_others,
- G_N_ELEMENTS (rel_type_map_others));
+ return _google_rel_from_types (types, rel_type_map_others, G_N_ELEMENTS (rel_type_map_others));
}
static gchar *
google_rel_from_types_phone (GList *types)
{
- return _google_rel_from_types (types,
- rel_type_map_phone,
- G_N_ELEMENTS (rel_type_map_phone));
+ return _google_rel_from_types (types, rel_type_map_phone, G_N_ELEMENTS (rel_type_map_phone));
}
static gboolean
is_known_google_im_protocol (const gchar *protocol)
{
- const gchar *known_protocols[] =
- {
- "AIM", "MSN", "YAHOO", "SKYPE", "QQ",
- "GOOGLE_TALK", "ICQ", "JABBER"
- };
- guint i;
-
- if (NULL == protocol)
- return FALSE;
-
- for (i = 0; i < G_N_ELEMENTS (known_protocols); i++) {
- if (0 == g_ascii_strcasecmp (known_protocols[i], protocol))
- return TRUE;
- }
- return FALSE;
+ const gchar *known_protocols[] = {
+ "AIM", "MSN", "YAHOO", "SKYPE", "QQ",
+ "GOOGLE_TALK", "ICQ", "JABBER"
+ };
+ guint i;
+
+ if (NULL == protocol)
+ return FALSE;
+
+ for (i = 0; i < G_N_ELEMENTS (known_protocols); i++) {
+ if (0 == g_ascii_strcasecmp (known_protocols[i], protocol))
+ return TRUE;
+ }
+
+ return FALSE;
}
static gchar *
field_name_from_google_im_protocol (const gchar *google_protocol)
{
- gchar *protocol;
- if (NULL == google_protocol)
- return NULL;
-
- protocol = g_strrstr (google_protocol, "#");
- if (NULL == protocol)
- return NULL;
- return g_strdup_printf ("X-%s", protocol + 1);
+ gchar *protocol;
+ if (!google_protocol)
+ return NULL;
+
+ protocol = g_strrstr (google_protocol, "#");
+ if (!protocol)
+ return NULL;
+
+ return g_strdup_printf ("X-%s", protocol + 1);
}
static gchar *
google_im_protocol_from_field_name (const gchar *field_name)
{
- const gchar format[] = "http://schemas.google.com/g/2005#%s";
+ const gchar format[] = "http://schemas.google.com/g/2005#%s";
- if (NULL == field_name ||
- strlen (field_name) < 3) {
- return NULL;
- }
+ if (!field_name || strlen (field_name) < 3)
+ return NULL;
- return g_strdup_printf (format, field_name + 2);
+ return g_strdup_printf (format, field_name + 2);
}
static void
add_primary_param (EVCardAttribute *attr, gboolean has_type)
{
- EVCardAttributeParam *param;
- param = e_vcard_attribute_param_new (GOOGLE_PRIMARY_PARAM);
- e_vcard_attribute_add_param_with_value (attr, param, "1");
- if (FALSE == has_type) {
- param = e_vcard_attribute_param_new ("TYPE");
- e_vcard_attribute_add_param_with_value (attr, param, "PREF");
- }
+ EVCardAttributeParam *param = e_vcard_attribute_param_new (GOOGLE_PRIMARY_PARAM);
+ e_vcard_attribute_add_param_with_value (attr, param, "1");
+
+ if (!has_type) {
+ param = e_vcard_attribute_param_new ("TYPE");
+ e_vcard_attribute_add_param_with_value (attr, param, "PREF");
+ }
}
-static GList*
-get_google_primary_type_label (EVCardAttribute *attr,
- gboolean *primary,
- const gchar **label)
+static GList *
+get_google_primary_type_label (EVCardAttribute *attr, gboolean *primary, const gchar **label)
{
- GList *params;
- GList *types = NULL;
-
- *primary = FALSE;
- *label = NULL;
- params = e_vcard_attribute_get_params (attr);
- while (params) {
- const gchar *name;
-
- name = e_vcard_attribute_param_get_name (params->data);
- if (0 == g_ascii_strcasecmp (name, GOOGLE_PRIMARY_PARAM)) {
- GList *values;
-
- values = e_vcard_attribute_param_get_values (params->data);
- if (values && values->data &&
- (((const gchar *)values->data)[0] == '1' ||
- 0 == g_ascii_strcasecmp (values->data, "yes"))) {
- *primary = TRUE;
- }
- }
- if (0 == g_ascii_strcasecmp (name, GOOGLE_LABEL_PARAM)) {
- GList *values;
-
- values = e_vcard_attribute_param_get_values (params->data);
- *label = values ? values->data : NULL;
- }
- if (0 == g_ascii_strcasecmp (name, "TYPE")) {
- types = e_vcard_attribute_param_get_values (params->data);
- }
- params = params->next;
- }
- return types;
+ GList *params;
+ GList *types = NULL;
+
+ *primary = FALSE;
+ *label = NULL;
+ params = e_vcard_attribute_get_params (attr);
+
+ while (params) {
+ const gchar *name;
+
+ name = e_vcard_attribute_param_get_name (params->data);
+ if (g_ascii_strcasecmp (name, GOOGLE_PRIMARY_PARAM) == 0) {
+ GList *values;
+
+ values = e_vcard_attribute_param_get_values (params->data);
+ if (values && values->data &&
+ (((const gchar *)values->data)[0] == '1' ||
+ 0 == g_ascii_strcasecmp (values->data, "yes"))) {
+ *primary = TRUE;
+ }
+ }
+
+ if (g_ascii_strcasecmp (name, GOOGLE_LABEL_PARAM) == 0) {
+ GList *values;
+
+ values = e_vcard_attribute_param_get_values (params->data);
+ *label = values ? values->data : NULL;
+ }
+
+ if (g_ascii_strcasecmp (name, "TYPE") == 0)
+ types = e_vcard_attribute_param_get_values (params->data);
+ params = params->next;
+ }
+
+ return types;
}
static void
add_attribute_from_gdata_gd_email_address (EVCard *vcard, GDataGDEmailAddress *email)
{
- EVCardAttribute *attr;
- gboolean has_type;
+ EVCardAttribute *attr;
+ gboolean has_type;
- if (NULL == email || NULL == gdata_gd_email_address_get_address (email))
- return;
+ if (!email || !gdata_gd_email_address_get_address (email))
+ return;
- attr = e_vcard_attribute_new (NULL, EVC_EMAIL);
- has_type = add_type_param_from_google_rel (attr, gdata_gd_email_address_get_relation_type (email));
- if (gdata_gd_email_address_is_primary (email) == TRUE)
- add_primary_param (attr, has_type);
- add_label_param (attr, gdata_gd_email_address_get_label (email));
+ attr = e_vcard_attribute_new (NULL, EVC_EMAIL);
+ has_type = add_type_param_from_google_rel (attr, gdata_gd_email_address_get_relation_type (email));
+ if (gdata_gd_email_address_is_primary (email))
+ add_primary_param (attr, has_type);
+ add_label_param (attr, gdata_gd_email_address_get_label (email));
- e_vcard_attribute_add_value (attr, gdata_gd_email_address_get_address (email));
+ e_vcard_attribute_add_value (attr, gdata_gd_email_address_get_address (email));
- if (attr)
- e_vcard_add_attribute (vcard, attr);
+ if (attr)
+ e_vcard_add_attribute (vcard, attr);
}
static void
add_attribute_from_gdata_gd_im_address (EVCard *vcard, GDataGDIMAddress *im)
{
- EVCardAttribute *attr;
- gboolean has_type;
- gchar *field_name;
+ EVCardAttribute *attr;
+ gboolean has_type;
+ gchar *field_name;
- if (NULL == im || NULL == gdata_gd_im_address_get_address (im))
- return;
+ if (!im || !gdata_gd_im_address_get_address (im))
+ return;
- field_name = field_name_from_google_im_protocol (gdata_gd_im_address_get_protocol (im));
- if (NULL == field_name)
- return;
+ field_name = field_name_from_google_im_protocol (gdata_gd_im_address_get_protocol (im));
+ if (!field_name)
+ return;
- attr = e_vcard_attribute_new (NULL, field_name);
- has_type = add_type_param_from_google_rel_im (attr, gdata_gd_im_address_get_relation_type (im));
- if (gdata_gd_im_address_is_primary (im))
- add_primary_param (attr, has_type);
- add_label_param (attr, gdata_gd_im_address_get_label (im));
+ attr = e_vcard_attribute_new (NULL, field_name);
+ has_type = add_type_param_from_google_rel_im (attr, gdata_gd_im_address_get_relation_type (im));
+ if (gdata_gd_im_address_is_primary (im))
+ add_primary_param (attr, has_type);
+ add_label_param (attr, gdata_gd_im_address_get_label (im));
- e_vcard_attribute_add_value (attr, gdata_gd_im_address_get_address (im));
+ e_vcard_attribute_add_value (attr, gdata_gd_im_address_get_address (im));
- if (attr)
- e_vcard_add_attribute (vcard, attr);
+ if (attr)
+ e_vcard_add_attribute (vcard, attr);
}
static void
add_attribute_from_gdata_gd_phone_number (EVCard *vcard, GDataGDPhoneNumber *number)
{
- EVCardAttribute *attr;
- gboolean has_type;
+ EVCardAttribute *attr;
+ gboolean has_type;
- if (NULL == number || NULL == gdata_gd_phone_number_get_number (number))
- return;
+ if (!number || !gdata_gd_phone_number_get_number (number))
+ return;
- attr = e_vcard_attribute_new (NULL, EVC_TEL);
- has_type = add_type_param_from_google_rel_phone (attr, gdata_gd_phone_number_get_relation_type (number));
- if (gdata_gd_phone_number_is_primary (number))
- add_primary_param (attr, has_type);
- add_label_param (attr, gdata_gd_phone_number_get_label (number));
+ attr = e_vcard_attribute_new (NULL, EVC_TEL);
+ has_type = add_type_param_from_google_rel_phone (attr, gdata_gd_phone_number_get_relation_type (number));
+ if (gdata_gd_phone_number_is_primary (number))
+ add_primary_param (attr, has_type);
+ add_label_param (attr, gdata_gd_phone_number_get_label (number));
- e_vcard_attribute_add_value (attr, gdata_gd_phone_number_get_number (number));
+ e_vcard_attribute_add_value (attr, gdata_gd_phone_number_get_number (number));
- if (attr)
- e_vcard_add_attribute (vcard, attr);
+ if (attr)
+ e_vcard_add_attribute (vcard, attr);
}
static void
add_attribute_from_gdata_gd_postal_address (EVCard *vcard, GDataGDPostalAddress *address)
{
- EVCardAttribute *attr;
- gboolean has_type;
-
- if (NULL == address || NULL == gdata_gd_postal_address_get_address (address))
- return;
-
- /* Add the LABEL */
- attr = e_vcard_attribute_new (NULL, EVC_LABEL);
- has_type = add_type_param_from_google_rel (attr, gdata_gd_postal_address_get_relation_type (address));
- if (gdata_gd_postal_address_is_primary (address))
- add_primary_param (attr, has_type);
- add_label_param (attr, gdata_gd_postal_address_get_label (address));
-
- e_vcard_attribute_add_value (attr, gdata_gd_postal_address_get_address (address));
-
- if (attr)
- e_vcard_add_attribute (vcard, attr);
-
- /* Add the ADR */
- attr = e_vcard_attribute_new (NULL, EVC_ADR);
- has_type = add_type_param_from_google_rel (attr, gdata_gd_postal_address_get_relation_type (address));
- if (gdata_gd_postal_address_is_primary (address))
- add_primary_param (attr, has_type);
- add_label_param (attr, gdata_gd_postal_address_get_label (address));
-
- e_vcard_attribute_add_value (attr, gdata_gd_postal_address_get_po_box (address));
- e_vcard_attribute_add_value (attr, gdata_gd_postal_address_get_house_name (address));
- e_vcard_attribute_add_value (attr, gdata_gd_postal_address_get_street (address));
- e_vcard_attribute_add_value (attr, gdata_gd_postal_address_get_city (address));
- e_vcard_attribute_add_value (attr, gdata_gd_postal_address_get_region (address));
- e_vcard_attribute_add_value (attr, gdata_gd_postal_address_get_postcode (address));
- e_vcard_attribute_add_value (attr, gdata_gd_postal_address_get_country (address));
-
- /* The following bits of data provided by the Google Contacts API can't be fitted into the vCard format:
- * gdata_gd_postal_address_get_mail_class
- * gdata_gd_postal_address_get_usage
- * gdata_gd_postal_address_get_agent
- * gdata_gd_postal_address_get_neighborhood
- * gdata_gd_postal_address_get_subregion
- * gdata_gd_postal_address_get_country_code */
-
- if (attr)
- e_vcard_add_attribute (vcard, attr);
+ EVCardAttribute *attr;
+ gboolean has_type;
+
+ if (!address || !gdata_gd_postal_address_get_address (address))
+ return;
+
+ /* Add the LABEL */
+ attr = e_vcard_attribute_new (NULL, EVC_LABEL);
+ has_type = add_type_param_from_google_rel (attr, gdata_gd_postal_address_get_relation_type (address));
+ if (gdata_gd_postal_address_is_primary (address))
+ add_primary_param (attr, has_type);
+ add_label_param (attr, gdata_gd_postal_address_get_label (address));
+
+ e_vcard_attribute_add_value (attr, gdata_gd_postal_address_get_address (address));
+
+ if (attr)
+ e_vcard_add_attribute (vcard, attr);
+
+ /* Add the ADR */
+ attr = e_vcard_attribute_new (NULL, EVC_ADR);
+ has_type = add_type_param_from_google_rel (attr, gdata_gd_postal_address_get_relation_type (address));
+ if (gdata_gd_postal_address_is_primary (address))
+ add_primary_param (attr, has_type);
+ add_label_param (attr, gdata_gd_postal_address_get_label (address));
+
+ e_vcard_attribute_add_value (attr, gdata_gd_postal_address_get_po_box (address));
+ e_vcard_attribute_add_value (attr, gdata_gd_postal_address_get_house_name (address));
+ e_vcard_attribute_add_value (attr, gdata_gd_postal_address_get_street (address));
+ e_vcard_attribute_add_value (attr, gdata_gd_postal_address_get_city (address));
+ e_vcard_attribute_add_value (attr, gdata_gd_postal_address_get_region (address));
+ e_vcard_attribute_add_value (attr, gdata_gd_postal_address_get_postcode (address));
+ e_vcard_attribute_add_value (attr, gdata_gd_postal_address_get_country (address));
+
+ /* The following bits of data provided by the Google Contacts API can't be fitted into the vCard format:
+ * gdata_gd_postal_address_get_mail_class
+ * gdata_gd_postal_address_get_usage
+ * gdata_gd_postal_address_get_agent
+ * gdata_gd_postal_address_get_neighborhood
+ * gdata_gd_postal_address_get_subregion
+ * gdata_gd_postal_address_get_country_code */
+
+ if (attr)
+ e_vcard_add_attribute (vcard, attr);
}
-static GDataGDEmailAddress*
+static GDataGDEmailAddress *
gdata_gd_email_address_from_attribute (EVCardAttribute *attr, gboolean *have_primary)
{
- GDataGDEmailAddress *email = NULL;
- GList *values;
-
- values = e_vcard_attribute_get_values (attr);
- if (values) {
- GList *types;
- gchar *rel;
- const gchar *label;
- gboolean primary;
-
- types = get_google_primary_type_label (attr, &primary, &label);
- if (FALSE == *have_primary) {
- *have_primary = primary;
- } else {
- primary = FALSE;
- }
-
- rel = google_rel_from_types (types);
- email = gdata_gd_email_address_new (values->data, rel, label, primary);
- g_free (rel);
-
- __debug__ ("New %semail entry %s (%s/%s)",
- gdata_gd_email_address_is_primary (email) ? "primary " : "",
- gdata_gd_email_address_get_address (email),
- gdata_gd_email_address_get_relation_type (email),
- gdata_gd_email_address_get_label (email));
- }
-
- return email;
+ GDataGDEmailAddress *email = NULL;
+ GList *values;
+
+ values = e_vcard_attribute_get_values (attr);
+ if (values) {
+ GList *types;
+ gchar *rel;
+ const gchar *label;
+ gboolean primary;
+
+ types = get_google_primary_type_label (attr, &primary, &label);
+ if (!*have_primary)
+ *have_primary = primary;
+ else
+ primary = FALSE;
+
+ rel = google_rel_from_types (types);
+ email = gdata_gd_email_address_new (values->data, rel, label, primary);
+ g_free (rel);
+
+ __debug__ ("New %semail entry %s (%s/%s)",
+ gdata_gd_email_address_is_primary (email) ? "primary " : "",
+ gdata_gd_email_address_get_address (email),
+ gdata_gd_email_address_get_relation_type (email),
+ gdata_gd_email_address_get_label (email));
+ }
+
+ return email;
}
-static GDataGDIMAddress*
+static GDataGDIMAddress *
gdata_gd_im_address_from_attribute (EVCardAttribute *attr, gboolean *have_primary)
{
- GDataGDIMAddress *im = NULL;
- GList *values;
- const gchar *name;
-
- name = e_vcard_attribute_get_name (attr);
-
- values = e_vcard_attribute_get_values (attr);
- if (values) {
- GList *types;
- gchar *protocol, *rel;
- const gchar *label;
- gboolean primary;
-
- types = get_google_primary_type_label (attr, &primary, &label);
- if (FALSE == *have_primary) {
- *have_primary = primary;
- } else {
- primary = FALSE;
- }
-
- rel = google_rel_from_types (types);
- protocol = google_im_protocol_from_field_name (name);
- im = gdata_gd_im_address_new (values->data, protocol, rel, label, primary);
- g_free (rel);
- g_free (protocol);
-
- __debug__ ("New %s%s entry %s (%s/%s)",
- gdata_gd_im_address_is_primary (im) ? "primary " : "",
- gdata_gd_im_address_get_protocol (im),
- gdata_gd_im_address_get_address (im),
- gdata_gd_im_address_get_relation_type (im),
- gdata_gd_im_address_get_label (im));
- }
-
- return im;
+ GDataGDIMAddress *im = NULL;
+ GList *values;
+ const gchar *name;
+
+ name = e_vcard_attribute_get_name (attr);
+
+ values = e_vcard_attribute_get_values (attr);
+ if (values) {
+ GList *types;
+ gchar *protocol, *rel;
+ const gchar *label;
+ gboolean primary;
+
+ types = get_google_primary_type_label (attr, &primary, &label);
+ if (!*have_primary)
+ *have_primary = primary;
+ else
+ primary = FALSE;
+
+ rel = google_rel_from_types (types);
+ protocol = google_im_protocol_from_field_name (name);
+ im = gdata_gd_im_address_new (values->data, protocol, rel, label, primary);
+ g_free (rel);
+ g_free (protocol);
+
+ __debug__ ("New %s%s entry %s (%s/%s)",
+ gdata_gd_im_address_is_primary (im) ? "primary " : "",
+ gdata_gd_im_address_get_protocol (im),
+ gdata_gd_im_address_get_address (im),
+ gdata_gd_im_address_get_relation_type (im),
+ gdata_gd_im_address_get_label (im));
+ }
+
+ return im;
}
-static GDataGDPhoneNumber*
+static GDataGDPhoneNumber *
gdata_gd_phone_number_from_attribute (EVCardAttribute *attr, gboolean *have_primary)
{
- GDataGDPhoneNumber *number = NULL;
- GList *values;
-
- values = e_vcard_attribute_get_values (attr);
- if (values) {
- GList *types;
- gboolean primary;
- gchar *rel;
- const gchar *label;
-
- types = get_google_primary_type_label (attr, &primary, &label);
- if (FALSE == *have_primary) {
- *have_primary = primary;
- } else {
- primary = FALSE;
- }
-
- rel = google_rel_from_types_phone (types);
- number = gdata_gd_phone_number_new (values->data, rel, label, NULL, primary);
- g_free (rel);
-
- __debug__ ("New %sphone-number entry %s (%s/%s)",
- gdata_gd_phone_number_is_primary (number) ? "primary " : "",
- gdata_gd_phone_number_get_number (number),
- gdata_gd_phone_number_get_relation_type (number),
- gdata_gd_phone_number_get_label (number));
- }
-
- return number;
+ GDataGDPhoneNumber *number = NULL;
+ GList *values;
+
+ values = e_vcard_attribute_get_values (attr);
+ if (values) {
+ GList *types;
+ gboolean primary;
+ gchar *rel;
+ const gchar *label;
+
+ types = get_google_primary_type_label (attr, &primary, &label);
+ if (!*have_primary)
+ *have_primary = primary;
+ else
+ primary = FALSE;
+
+ rel = google_rel_from_types_phone (types);
+ number = gdata_gd_phone_number_new (values->data, rel, label, NULL, primary);
+ g_free (rel);
+
+ __debug__ ("New %sphone-number entry %s (%s/%s)",
+ gdata_gd_phone_number_is_primary (number) ? "primary " : "",
+ gdata_gd_phone_number_get_number (number),
+ gdata_gd_phone_number_get_relation_type (number),
+ gdata_gd_phone_number_get_label (number));
+ }
+
+ return number;
}
-static GDataGDPostalAddress*
+static GDataGDPostalAddress *
gdata_gd_postal_address_from_attribute (EVCardAttribute *attr, gboolean *have_primary)
{
- GDataGDPostalAddress *address = NULL;
- GList *values;
-
- values = e_vcard_attribute_get_values (attr);
- if (values) {
- GList *types, *value;
- gchar *rel;
- const gchar *label;
- gboolean primary;
-
- types = get_google_primary_type_label (attr, &primary, &label);
- if (FALSE == *have_primary) {
- *have_primary = primary;
- } else {
- primary = FALSE;
- }
-
- rel = google_rel_from_types (types);
- address = gdata_gd_postal_address_new (rel, label, primary);
- g_free (rel);
-
- __debug__ ("New %spostal address entry %s (%s/%s)",
- gdata_gd_postal_address_is_primary (address) ? "primary " : "",
- gdata_gd_postal_address_get_address (address),
- gdata_gd_postal_address_get_relation_type (address),
- gdata_gd_postal_address_get_label (address));
-
- /* Set the components of the address from the vCard's attribute values */
- value = values;
- if (!value)
- return address;
- gdata_gd_postal_address_set_po_box (address, (*((gchar*) value->data) != '\0') ? value->data : NULL);
- value = value->next;
- if (!value)
- return address;
- gdata_gd_postal_address_set_house_name (address, (*((gchar*) value->data) != '\0') ? value->data : NULL);
- value = value->next;
- if (!value)
- return address;
- gdata_gd_postal_address_set_street (address, (*((gchar*) value->data) != '\0') ? value->data : NULL);
- value = value->next;
- if (!value)
- return address;
- gdata_gd_postal_address_set_city (address, (*((gchar*) value->data) != '\0') ? value->data : NULL);
- value = value->next;
- if (!value)
- return address;
- gdata_gd_postal_address_set_region (address, (*((gchar*) value->data) != '\0') ? value->data : NULL);
- value = value->next;
- if (!value)
- return address;
- gdata_gd_postal_address_set_postcode (address, (*((gchar*) value->data) != '\0') ? value->data : NULL);
- value = value->next;
- if (!value)
- return address;
- gdata_gd_postal_address_set_country (address, (*((gchar*) value->data) != '\0') ? value->data : NULL, NULL);
- }
-
- return address;
+ GDataGDPostalAddress *address = NULL;
+ GList *values;
+
+ values = e_vcard_attribute_get_values (attr);
+ if (values) {
+ GList *types, *value;
+ gchar *rel;
+ const gchar *label;
+ gboolean primary;
+
+ types = get_google_primary_type_label (attr, &primary, &label);
+ if (!*have_primary)
+ *have_primary = primary;
+ else
+ primary = FALSE;
+
+ rel = google_rel_from_types (types);
+ address = gdata_gd_postal_address_new (rel, label, primary);
+ g_free (rel);
+
+ __debug__ ("New %spostal address entry %s (%s/%s)",
+ gdata_gd_postal_address_is_primary (address) ? "primary " : "",
+ gdata_gd_postal_address_get_address (address),
+ gdata_gd_postal_address_get_relation_type (address),
+ gdata_gd_postal_address_get_label (address));
+
+ /* Set the components of the address from the vCard's attribute values */
+ value = values;
+ if (!value)
+ return address;
+ gdata_gd_postal_address_set_po_box (address, (*((gchar*) value->data) != '\0') ? value->data : NULL);
+ value = value->next;
+ if (!value)
+ return address;
+ gdata_gd_postal_address_set_house_name (address, (*((gchar*) value->data) != '\0') ? value->data : NULL);
+ value = value->next;
+ if (!value)
+ return address;
+ gdata_gd_postal_address_set_street (address, (*((gchar*) value->data) != '\0') ? value->data : NULL);
+ value = value->next;
+ if (!value)
+ return address;
+ gdata_gd_postal_address_set_city (address, (*((gchar*) value->data) != '\0') ? value->data : NULL);
+ value = value->next;
+ if (!value)
+ return address;
+ gdata_gd_postal_address_set_region (address, (*((gchar*) value->data) != '\0') ? value->data : NULL);
+ value = value->next;
+ if (!value)
+ return address;
+ gdata_gd_postal_address_set_postcode (address, (*((gchar*) value->data) != '\0') ? value->data : NULL);
+ value = value->next;
+ if (!value)
+ return address;
+ gdata_gd_postal_address_set_country (address, (*((gchar*) value->data) != '\0') ? value->data : NULL, NULL);
+ }
+
+ return address;
}
diff --git a/addressbook/backends/google/util.h b/addressbook/backends/google/util.h
index 3d74b3d..2959005 100644
--- a/addressbook/backends/google/util.h
+++ b/addressbook/backends/google/util.h
@@ -19,6 +19,7 @@
*
* Author: Joergen Scheibengruber <joergen.scheibengruber AT googlemail.com>
*/
+
#ifndef __UTIL_H__
#define __UTIL_H__
@@ -28,20 +29,14 @@
extern gboolean __e_book_backend_google_debug__;
-#define __debug__(...) (__e_book_backend_google_debug__ ? \
- g_log (G_LOG_DOMAIN, \
- G_LOG_LEVEL_DEBUG, \
- __VA_ARGS__) : (void) 0 )
+#define __debug__(...) (__e_book_backend_google_debug__ ? g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, __VA_ARGS__) : (void) 0)
-GDataEntry* _gdata_entry_new_from_e_contact (EContact *contact);
-gboolean _gdata_entry_update_from_e_contact (GDataEntry *entry,
- EContact *contact);
+GDataEntry *_gdata_entry_new_from_e_contact (EContact *contact);
+gboolean _gdata_entry_update_from_e_contact (GDataEntry *entry, EContact *contact);
-EContact* _e_contact_new_from_gdata_entry (GDataEntry *entry);
-void _e_contact_add_gdata_entry_xml (EContact *contact,
- GDataEntry *entry);
-void _e_contact_remove_gdata_entry_xml (EContact *contact);
-const gchar *_e_contact_get_gdata_entry_xml (EContact *contact,
- const gchar **edit_link);
+EContact *_e_contact_new_from_gdata_entry (GDataEntry *entry);
+void _e_contact_add_gdata_entry_xml (EContact *contact, GDataEntry *entry);
+void _e_contact_remove_gdata_entry_xml (EContact *contact);
+const gchar *_e_contact_get_gdata_entry_xml (EContact *contact, const gchar **edit_link);
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]