aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/importers
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2010-12-04 02:01:31 +0800
committerMilan Crha <mcrha@redhat.com>2010-12-04 02:01:31 +0800
commit3a6932bd9f251d5faafc5dc0c419e7c80d5afcd0 (patch)
tree28a0f3313e4233b77c47655b02f604bcc9e47acc /addressbook/importers
parentd8999c79baa0385e1234eaa114b384cfef1d745f (diff)
downloadgsoc2013-evolution-3a6932bd9f251d5faafc5dc0c419e7c80d5afcd0.tar.gz
gsoc2013-evolution-3a6932bd9f251d5faafc5dc0c419e7c80d5afcd0.tar.zst
gsoc2013-evolution-3a6932bd9f251d5faafc5dc0c419e7c80d5afcd0.zip
Bug #635755 - Authenticate books in addressbook importers on open
Diffstat (limited to 'addressbook/importers')
-rw-r--r--addressbook/importers/evolution-csv-importer.c19
-rw-r--r--addressbook/importers/evolution-ldif-importer.c19
-rw-r--r--addressbook/importers/evolution-vcard-importer.c95
3 files changed, 91 insertions, 42 deletions
diff --git a/addressbook/importers/evolution-csv-importer.c b/addressbook/importers/evolution-csv-importer.c
index 970ada7fd6..9e15a58dee 100644
--- a/addressbook/importers/evolution-csv-importer.c
+++ b/addressbook/importers/evolution-csv-importer.c
@@ -37,6 +37,7 @@
#include <libebook/e-destination.h>
#include "e-util/e-import.h"
+#include "util/addressbook.h"
#include "evolution-addressbook-importers.h"
@@ -827,6 +828,20 @@ csv_import_done (CSVImporter *gci)
}
static void
+book_loaded_cb (EBook *book, const GError *error, gpointer closure)
+{
+ CSVImporter *gci = closure;
+
+ g_return_if_fail (gci != NULL);
+ g_return_if_fail (gci->book == book);
+
+ if (error)
+ csv_import_done (gci);
+ else
+ gci->idle_id = g_idle_add (csv_import_contacts, gci);
+}
+
+static void
csv_import (EImport *ei, EImportTarget *target, EImportImporter *im)
{
CSVImporter *gci;
@@ -870,9 +885,7 @@ csv_import (EImport *ei, EImportTarget *target, EImportImporter *im)
gci->size = ftell (file);
fseek (file, 0, SEEK_SET);
- e_book_open (gci->book, FALSE, NULL);
-
- gci->idle_id = g_idle_add (csv_import_contacts, gci);
+ addressbook_load (gci->book, book_loaded_cb, gci);
}
static void
diff --git a/addressbook/importers/evolution-ldif-importer.c b/addressbook/importers/evolution-ldif-importer.c
index 15627bad5a..f5fe14bd6b 100644
--- a/addressbook/importers/evolution-ldif-importer.c
+++ b/addressbook/importers/evolution-ldif-importer.c
@@ -47,6 +47,7 @@
#include <libebook/e-destination.h>
#include "e-util/e-import.h"
+#include "util/addressbook.h"
#include "evolution-addressbook-importers.h"
@@ -621,6 +622,20 @@ ldif_import_done (LDIFImporter *gci)
}
static void
+book_loaded_cb (EBook *book, const GError *error, gpointer closure)
+{
+ LDIFImporter *gci = closure;
+
+ g_return_if_fail (gci != NULL);
+ g_return_if_fail (gci->book == book);
+
+ if (error)
+ ldif_import_done (gci);
+ else
+ gci->idle_id = g_idle_add (ldif_import_contacts, gci);
+}
+
+static void
ldif_import (EImport *ei, EImportTarget *target, EImportImporter *im)
{
LDIFImporter *gci;
@@ -662,9 +677,7 @@ ldif_import (EImport *ei, EImportTarget *target, EImportImporter *im)
(GDestroyNotify) g_free,
(GDestroyNotify) NULL);
- e_book_open (gci->book, FALSE, NULL);
-
- gci->idle_id = g_idle_add (ldif_import_contacts, gci);
+ addressbook_load (gci->book, book_loaded_cb, gci);
}
static void
diff --git a/addressbook/importers/evolution-vcard-importer.c b/addressbook/importers/evolution-vcard-importer.c
index 5cad56a767..1610337036 100644
--- a/addressbook/importers/evolution-vcard-importer.c
+++ b/addressbook/importers/evolution-vcard-importer.c
@@ -44,9 +44,19 @@
#include "e-util/e-import.h"
#include "e-util/e-datetime-format.h"
#include "misc/e-web-view-preview.h"
+#include "util/addressbook.h"
#include "evolution-addressbook-importers.h"
+enum _VCardEncoding {
+ VCARD_ENCODING_NONE,
+ VCARD_ENCODING_UTF8,
+ VCARD_ENCODING_UTF16,
+ VCARD_ENCODING_LOCALE
+};
+
+typedef enum _VCardEncoding VCardEncoding;
+
typedef struct {
EImport *import;
EImportTarget *target;
@@ -62,6 +72,10 @@ typedef struct {
GList *contactlist;
GList *iterator;
EBook *book;
+
+ /* when opening book */
+ gchar *contents;
+ VCardEncoding encoding;
} VCardImporter;
static void vcard_import_done (VCardImporter *gci);
@@ -320,15 +334,6 @@ utf16_to_utf8 (gunichar2 *utf16)
return g_utf16_to_utf8 (utf16, -1, NULL, NULL, NULL);
}
-enum _VCardEncoding {
- VCARD_ENCODING_NONE,
- VCARD_ENCODING_UTF8,
- VCARD_ENCODING_UTF16,
- VCARD_ENCODING_LOCALE
-};
-
-typedef enum _VCardEncoding VCardEncoding;
-
/* Actually check the contents of this file */
static VCardEncoding
guess_vcard_encoding (const gchar *filename)
@@ -459,6 +464,7 @@ vcard_import_done (VCardImporter *gci)
if (gci->idle_id)
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);
@@ -469,14 +475,53 @@ vcard_import_done (VCardImporter *gci)
}
static void
+book_loaded_cb (EBook *book, const GError *error, gpointer closure)
+{
+ VCardImporter *gci = closure;
+
+ g_return_if_fail (gci != NULL);
+ g_return_if_fail (gci->book == book);
+
+ if (error) {
+ vcard_import_done (gci);
+ return;
+ }
+
+ if (gci->encoding == VCARD_ENCODING_UTF16) {
+ gchar *tmp;
+
+ gunichar2 *contents_utf16 = (gunichar2*) gci->contents;
+ tmp = utf16_to_utf8 (contents_utf16);
+ g_free (gci->contents);
+ gci->contents = tmp;
+ } else if (gci->encoding == VCARD_ENCODING_LOCALE) {
+ gchar *tmp;
+ tmp = g_locale_to_utf8 (gci->contents, -1, NULL, NULL, NULL);
+ g_free (gci->contents);
+ gci->contents = tmp;
+ }
+
+ gci->contactlist = eab_contact_list_from_string (gci->contents);
+ g_free (gci->contents);
+ gci->contents = NULL;
+ gci->iterator = gci->contactlist;
+ gci->total = g_list_length (gci->contactlist);
+
+ if (gci->iterator)
+ gci->idle_id = g_idle_add (vcard_import_contacts, gci);
+ else
+ vcard_import_done (gci);
+}
+
+static void
vcard_import (EImport *ei, EImportTarget *target, EImportImporter *im)
{
VCardImporter *gci;
- gchar *contents;
- VCardEncoding encoding;
EBook *book;
EImportTargetURI *s = (EImportTargetURI *)target;
gchar *filename;
+ gchar *contents;
+ VCardEncoding encoding;
filename = g_filename_from_uri (s->uri_src, NULL, NULL);
if (filename == NULL) {
@@ -515,32 +560,10 @@ vcard_import (EImport *ei, EImportTarget *target, EImportImporter *im)
gci->import = g_object_ref (ei);
gci->target = target;
gci->book = book;
+ gci->encoding = encoding;
+ gci->contents = contents;
- e_book_open (gci->book, FALSE, NULL);
-
- if (encoding == VCARD_ENCODING_UTF16) {
- gchar *tmp;
-
- gunichar2 *contents_utf16 = (gunichar2*)contents;
- tmp = utf16_to_utf8 (contents_utf16);
- g_free (contents);
- contents = tmp;
- } else if (encoding == VCARD_ENCODING_LOCALE) {
- gchar *tmp;
- tmp = g_locale_to_utf8 (contents, -1, NULL, NULL, NULL);
- g_free (contents);
- contents = tmp;
- }
-
- gci->contactlist = eab_contact_list_from_string (contents);
- g_free (contents);
- gci->iterator = gci->contactlist;
- gci->total = g_list_length (gci->contactlist);
-
- if (gci->iterator)
- gci->idle_id = g_idle_add (vcard_import_contacts, gci);
- else
- vcard_import_done (gci);
+ addressbook_load (book, book_loaded_cb, gci);
}
static void