aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/importers
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2011-06-14 14:54:20 +0800
committerMilan Crha <mcrha@redhat.com>2011-06-14 14:54:20 +0800
commit38790d8478e906a5c59d0c4a5216f297f305bfeb (patch)
tree0f9a96db2765901f2a27b68c84815a491214ecc1 /addressbook/importers
parent08af0d1f81a4e983bb49d8fb8fe74e670adbb8f6 (diff)
downloadgsoc2013-evolution-38790d8478e906a5c59d0c4a5216f297f305bfeb.tar
gsoc2013-evolution-38790d8478e906a5c59d0c4a5216f297f305bfeb.tar.gz
gsoc2013-evolution-38790d8478e906a5c59d0c4a5216f297f305bfeb.tar.bz2
gsoc2013-evolution-38790d8478e906a5c59d0c4a5216f297f305bfeb.tar.lz
gsoc2013-evolution-38790d8478e906a5c59d0c4a5216f297f305bfeb.tar.xz
gsoc2013-evolution-38790d8478e906a5c59d0c4a5216f297f305bfeb.tar.zst
gsoc2013-evolution-38790d8478e906a5c59d0c4a5216f297f305bfeb.zip
Do not use deprecated EBook/ECal API
Diffstat (limited to 'addressbook/importers')
-rw-r--r--addressbook/importers/evolution-addressbook-importers.h2
-rw-r--r--addressbook/importers/evolution-csv-importer.c44
-rw-r--r--addressbook/importers/evolution-ldif-importer.c52
-rw-r--r--addressbook/importers/evolution-vcard-importer.c55
4 files changed, 94 insertions, 59 deletions
diff --git a/addressbook/importers/evolution-addressbook-importers.h b/addressbook/importers/evolution-addressbook-importers.h
index 8278e67b12..e4579cbc4e 100644
--- a/addressbook/importers/evolution-addressbook-importers.h
+++ b/addressbook/importers/evolution-addressbook-importers.h
@@ -25,4 +25,4 @@ struct _EImportImporter *evolution_csv_mozilla_importer_peek (void);
struct _EImportImporter *evolution_csv_evolution_importer_peek (void);
/* private utility function for importers only */
-struct _GtkWidget *evolution_contact_importer_get_preview_widget (const GList *contacts);
+struct _GtkWidget *evolution_contact_importer_get_preview_widget (const GSList *contacts);
diff --git a/addressbook/importers/evolution-csv-importer.c b/addressbook/importers/evolution-csv-importer.c
index 358b8198ab..76607f342e 100644
--- a/addressbook/importers/evolution-csv-importer.c
+++ b/addressbook/importers/evolution-csv-importer.c
@@ -34,8 +34,8 @@
#include <glib/gi18n.h>
#include <glib/gstdio.h>
-#include <libebook/e-book.h>
-#include <libedataserverui/e-book-auth-util.h>
+#include <libebook/e-book-client.h>
+#include <libedataserverui/e-client-utils.h>
#include <libedataserverui/e-source-selector.h>
#include <libebook/e-destination.h>
@@ -66,7 +66,7 @@ typedef struct {
* file to an index in the known fields array. */
GHashTable *fields_map;
- EBook *book;
+ EBookClient *book_client;
GSList *contacts;
} CSVImporter;
@@ -721,7 +721,11 @@ csv_import_contacts (gpointer d) {
EContact *contact = NULL;
while ((contact = getNextCSVEntry (gci, gci->file))) {
- e_book_add_contact (gci->book, contact, NULL);
+ gchar *uid = NULL;
+ if (e_book_client_add_contact_sync (gci->book_client, contact, &uid, NULL, NULL) && uid) {
+ e_contact_set (contact, E_CONTACT_UID, uid);
+ g_free (uid);
+ }
gci->contacts = g_slist_prepend (gci->contacts, contact);
}
if (contact == NULL) {
@@ -755,7 +759,7 @@ csv_getwidget (EImport *ei, EImportTarget *target, EImportImporter *im)
ESourceList *source_list;
/* FIXME Better error handling */
- if (!e_book_get_addressbooks (&source_list, NULL))
+ if (!e_book_client_get_sources (&source_list, NULL))
return NULL;
vbox = gtk_vbox_new (FALSE, FALSE);
@@ -829,7 +833,7 @@ csv_import_done (CSVImporter *gci)
g_source_remove (gci->idle_id);
fclose (gci->file);
- g_object_unref (gci->book);
+ g_object_unref (gci->book_client);
g_slist_foreach (gci->contacts, (GFunc) g_object_unref, NULL);
g_slist_free (gci->contacts);
@@ -843,13 +847,20 @@ csv_import_done (CSVImporter *gci)
}
static void
-book_loaded_cb (ESource *source,
+book_loaded_cb (GObject *source_object,
GAsyncResult *result,
- CSVImporter *gci)
+ gpointer user_data)
{
- gci->book = e_load_book_source_finish (source, result, NULL);
+ ESource *source = E_SOURCE (source_object);
+ CSVImporter *gci = user_data;
+ EClient *client = NULL;
+
+ if (!e_client_utils_open_new_finish (source, result, &client, NULL))
+ client = NULL;
+
+ gci->book_client = client ? E_BOOK_CLIENT (client) : NULL;
- if (gci->book == NULL) {
+ if (gci->book_client == NULL) {
csv_import_done (gci);
return;
}
@@ -893,8 +904,8 @@ csv_import (EImport *ei, EImportTarget *target, EImportImporter *im)
source = g_datalist_get_data (&target->data, "csv-source");
- e_load_book_source_async (
- source, NULL, NULL, (GAsyncReadyCallback)
+ e_client_utils_open_new (source, E_CLIENT_SOURCE_TYPE_CONTACTS, FALSE, NULL,
+ e_client_utils_authenticate_handler, NULL,
book_loaded_cb, gci);
}
@@ -931,7 +942,7 @@ static GtkWidget *
csv_get_preview (EImport *ei, EImportTarget *target, EImportImporter *im)
{
GtkWidget *preview;
- GList *contacts = NULL;
+ GSList *contacts = NULL;
EContact *contact;
EImportTargetURI *s = (EImportTargetURI *) target;
gchar *filename;
@@ -960,14 +971,13 @@ csv_get_preview (EImport *ei, EImportTarget *target, EImportImporter *im)
fseek (file, 0, SEEK_SET);
while (contact = getNextCSVEntry (gci, gci->file), contact != NULL) {
- contacts = g_list_prepend (contacts, contact);
+ contacts = g_slist_prepend (contacts, contact);
}
- contacts = g_list_reverse (contacts);
+ contacts = g_slist_reverse (contacts);
preview = evolution_contact_importer_get_preview_widget (contacts);
- g_list_foreach (contacts, (GFunc) g_object_unref, NULL);
- g_list_free (contacts);
+ e_client_util_free_object_slist (contacts);
fclose (file);
g_free (gci);
diff --git a/addressbook/importers/evolution-ldif-importer.c b/addressbook/importers/evolution-ldif-importer.c
index 85e46923d1..79d446cdaa 100644
--- a/addressbook/importers/evolution-ldif-importer.c
+++ b/addressbook/importers/evolution-ldif-importer.c
@@ -41,8 +41,8 @@
#include <glib/gi18n.h>
#include <glib/gstdio.h>
-#include <libebook/e-book.h>
-#include <libedataserverui/e-book-auth-util.h>
+#include <libebook/e-book-client.h>
+#include <libedataserverui/e-client-utils.h>
#include <libedataserverui/e-source-selector.h>
#include <libebook/e-destination.h>
@@ -63,7 +63,7 @@ typedef struct {
FILE *file;
gulong size;
- EBook *book;
+ EBookClient *book_client;
GSList *contacts;
GSList *list_contacts;
@@ -497,10 +497,15 @@ ldif_import_contacts (gpointer d)
gci->list_contacts = g_slist_prepend (
gci->list_contacts, contact);
} else {
+ gchar *uid = NULL;
+
add_to_notes (contact, E_CONTACT_OFFICE);
add_to_notes (contact, E_CONTACT_SPOUSE);
add_to_notes (contact, E_CONTACT_BLOG_URL);
- e_book_add_contact (gci->book, contact, NULL);
+ if (e_book_client_add_contact_sync (gci->book_client, contact, &uid, NULL, NULL) && uid) {
+ e_contact_set (contact, E_CONTACT_UID, uid);
+ g_free (uid);
+ }
gci->contacts = g_slist_prepend (gci->contacts, contact);
}
count++;
@@ -512,9 +517,14 @@ ldif_import_contacts (gpointer d)
}
if (gci->state == 1) {
for (iter = gci->list_iterator;count < 50 && iter;iter=iter->next) {
+ gchar *uid = NULL;
+
contact = iter->data;
resolve_list_card (gci, contact);
- e_book_add_contact (gci->book, contact, NULL);
+ if (e_book_client_add_contact_sync (gci->book_client, contact, &uid, NULL, NULL) && uid) {
+ e_contact_set (contact, E_CONTACT_UID, uid);
+ g_free (uid);
+ }
count++;
}
gci->list_iterator = iter;
@@ -548,7 +558,7 @@ ldif_getwidget (EImport *ei, EImportTarget *target, EImportImporter *im)
ESourceList *source_list;
/* FIXME Better error handling */
- if (!e_book_get_addressbooks (&source_list, NULL))
+ if (!e_book_client_get_sources (&source_list, NULL))
return NULL;
vbox = gtk_vbox_new (FALSE, FALSE);
@@ -618,7 +628,7 @@ ldif_import_done (LDIFImporter *gci)
g_source_remove (gci->idle_id);
fclose (gci->file);
- g_object_unref (gci->book);
+ g_object_unref (gci->book_client);
g_slist_foreach (gci->contacts, (GFunc) g_object_unref, NULL);
g_slist_foreach (gci->list_contacts, (GFunc) g_object_unref, NULL);
g_slist_free (gci->contacts);
@@ -632,13 +642,20 @@ ldif_import_done (LDIFImporter *gci)
}
static void
-book_loaded_cb (ESource *source,
+book_loaded_cb (GObject *source_object,
GAsyncResult *result,
- LDIFImporter *gci)
+ gpointer user_data)
{
- gci->book = e_load_book_source_finish (source, result, NULL);
+ ESource *source = E_SOURCE (source_object);
+ LDIFImporter *gci = user_data;
+ EClient *client = NULL;
+
+ if (!e_client_utils_open_new_finish (source, result, &client, NULL))
+ client = NULL;
+
+ gci->book_client = client ? E_BOOK_CLIENT (client) : NULL;
- if (gci->book == NULL) {
+ if (gci->book_client == NULL) {
ldif_import_done (gci);
return;
}
@@ -681,8 +698,8 @@ ldif_import (EImport *ei, EImportTarget *target, EImportImporter *im)
source = g_datalist_get_data (&target->data, "ldif-source");
- e_load_book_source_async (
- source, NULL, NULL, (GAsyncReadyCallback)
+ e_client_utils_open_new (source, E_CLIENT_SOURCE_TYPE_CONTACTS, FALSE, NULL,
+ e_client_utils_authenticate_handler, NULL,
book_loaded_cb, gci);
}
@@ -699,7 +716,7 @@ static GtkWidget *
ldif_get_preview (EImport *ei, EImportTarget *target, EImportImporter *im)
{
GtkWidget *preview;
- GList *contacts = NULL;
+ GSList *contacts = NULL;
EContact *contact;
EImportTargetURI *s = (EImportTargetURI *) target;
gchar *filename;
@@ -732,16 +749,15 @@ ldif_get_preview (EImport *ei, EImportTarget *target, EImportImporter *im)
add_to_notes (contact, E_CONTACT_BLOG_URL);
}
- contacts = g_list_prepend (contacts, contact);
+ contacts = g_slist_prepend (contacts, contact);
}
g_hash_table_destroy (dn_contact_hash);
- contacts = g_list_reverse (contacts);
+ contacts = g_slist_reverse (contacts);
preview = evolution_contact_importer_get_preview_widget (contacts);
- g_list_foreach (contacts, (GFunc) g_object_unref, NULL);
- g_list_free (contacts);
+ e_client_util_free_object_slist (contacts);
fclose (file);
return preview;
diff --git a/addressbook/importers/evolution-vcard-importer.c b/addressbook/importers/evolution-vcard-importer.c
index 04f81b222c..09ad3d1f7f 100644
--- a/addressbook/importers/evolution-vcard-importer.c
+++ b/addressbook/importers/evolution-vcard-importer.c
@@ -35,8 +35,8 @@
#include <glib/gi18n.h>
#include <glib/gstdio.h>
-#include <libebook/e-book.h>
-#include <libedataserverui/e-book-auth-util.h>
+#include <libebook/e-book-client.h>
+#include <libedataserverui/e-client-utils.h>
#include <libedataserverui/e-source-selector.h>
#include <util/eab-book-util.h>
@@ -69,9 +69,9 @@ typedef struct {
ESource *primary;
- GList *contactlist;
- GList *iterator;
- EBook *book;
+ GSList *contactlist;
+ GSList *iterator;
+ EBookClient *book_client;
/* when opening book */
gchar *contents;
@@ -109,6 +109,7 @@ vcard_import_contact (VCardImporter *gci, EContact *contact)
{
EContactPhoto *photo;
GList *attrs, *attr;
+ gchar *uid = NULL;
/* Apple's addressbook.app exports PHOTO's without a TYPE
param, so let's figure out the format here if there's a
@@ -249,7 +250,10 @@ vcard_import_contact (VCardImporter *gci, EContact *contact)
add_to_notes (contact, E_CONTACT_BLOG_URL);
/* FIXME Error checking */
- e_book_add_contact (gci->book, contact, NULL);
+ if (e_book_client_add_contact_sync (gci->book_client, contact, &uid, NULL, NULL) && uid) {
+ e_contact_set (contact, E_CONTACT_UID, uid);
+ g_free (uid);
+ }
}
static gboolean
@@ -257,7 +261,7 @@ vcard_import_contacts (gpointer data)
{
VCardImporter *gci = data;
gint count = 0;
- GList *iterator = gci->iterator;
+ GSList *iterator = gci->iterator;
if (gci->state == 0) {
while (count < 50 && iterator) {
@@ -402,7 +406,7 @@ vcard_getwidget (EImport *ei, EImportTarget *target, EImportImporter *im)
ESourceList *source_list;
/* FIXME Better error handling */
- if (!e_book_get_addressbooks (&source_list, NULL))
+ if (!e_book_client_get_sources (&source_list, NULL))
return NULL;
vbox = gtk_vbox_new (FALSE, FALSE);
@@ -465,9 +469,8 @@ vcard_import_done (VCardImporter *gci)
g_source_remove (gci->idle_id);
g_free (gci->contents);
- g_object_unref (gci->book);
- g_list_foreach (gci->contactlist, (GFunc) g_object_unref, NULL);
- g_list_free (gci->contactlist);
+ g_object_unref (gci->book_client);
+ e_client_util_free_object_slist (gci->contactlist);
e_import_complete (gci->import, gci->target);
g_object_unref (gci->import);
@@ -475,13 +478,20 @@ vcard_import_done (VCardImporter *gci)
}
static void
-book_loaded_cb (ESource *source,
+book_loaded_cb (GObject *source_object,
GAsyncResult *result,
- VCardImporter *gci)
+ gpointer user_data)
{
- gci->book = e_load_book_source_finish (source, result, NULL);
+ ESource *source = E_SOURCE (source_object);
+ VCardImporter *gci = user_data;
+ EClient *client = NULL;
+
+ if (!e_client_utils_open_new_finish (source, result, &client, NULL))
+ client = NULL;
+
+ gci->book_client = client ? E_BOOK_CLIENT (client) : NULL;
- if (gci->book == NULL) {
+ if (gci->book_client == NULL) {
vcard_import_done (gci);
return;
}
@@ -504,7 +514,7 @@ book_loaded_cb (ESource *source,
g_free (gci->contents);
gci->contents = NULL;
gci->iterator = gci->contactlist;
- gci->total = g_list_length (gci->contactlist);
+ gci->total = g_slist_length (gci->contactlist);
if (gci->iterator)
gci->idle_id = g_idle_add (vcard_import_contacts, gci);
@@ -554,8 +564,8 @@ vcard_import (EImport *ei, EImportTarget *target, EImportImporter *im)
source = g_datalist_get_data (&target->data, "vcard-source");
- e_load_book_source_async (
- source, NULL, NULL, (GAsyncReadyCallback)
+ e_client_utils_open_new (source, E_CLIENT_SOURCE_TYPE_CONTACTS, FALSE, NULL,
+ e_client_utils_authenticate_handler, NULL,
book_loaded_cb, gci);
}
@@ -572,7 +582,7 @@ static GtkWidget *
vcard_get_preview (EImport *ei, EImportTarget *target, EImportImporter *im)
{
GtkWidget *preview;
- GList *contacts;
+ GSList *contacts;
gchar *contents;
VCardEncoding encoding;
EImportTargetURI *s = (EImportTargetURI *) target;
@@ -617,8 +627,7 @@ vcard_get_preview (EImport *ei, EImportTarget *target, EImportImporter *im)
preview = evolution_contact_importer_get_preview_widget (contacts);
- g_list_foreach (contacts, (GFunc) g_object_unref, NULL);
- g_list_free (contacts);
+ e_client_util_free_object_slist (contacts);
return preview;
}
@@ -904,14 +913,14 @@ preview_selection_changed_cb (GtkTreeSelection *selection, EWebViewPreview *prev
}
GtkWidget *
-evolution_contact_importer_get_preview_widget (const GList *contacts)
+evolution_contact_importer_get_preview_widget (const GSList *contacts)
{
GtkWidget *preview;
GtkTreeView *tree_view;
GtkTreeSelection *selection;
GtkListStore *store;
GtkTreeIter iter;
- const GList *c;
+ const GSList *c;
if (!contacts)
return NULL;