aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/importers/evolution-ldif-importer.c
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2010-05-19 04:47:29 +0800
committerMilan Crha <mcrha@redhat.com>2010-05-19 04:47:29 +0800
commitef7690c3845e3c1cebcf3caba7f7667a10e7123d (patch)
treeab4a5bfa25bc5e25e0fed851c25226ce1930ec52 /addressbook/importers/evolution-ldif-importer.c
parent0f92771be57383e5d6e7d0f3e05743d192066eb3 (diff)
downloadgsoc2013-evolution-ef7690c3845e3c1cebcf3caba7f7667a10e7123d.tar
gsoc2013-evolution-ef7690c3845e3c1cebcf3caba7f7667a10e7123d.tar.gz
gsoc2013-evolution-ef7690c3845e3c1cebcf3caba7f7667a10e7123d.tar.bz2
gsoc2013-evolution-ef7690c3845e3c1cebcf3caba7f7667a10e7123d.tar.lz
gsoc2013-evolution-ef7690c3845e3c1cebcf3caba7f7667a10e7123d.tar.xz
gsoc2013-evolution-ef7690c3845e3c1cebcf3caba7f7667a10e7123d.tar.zst
gsoc2013-evolution-ef7690c3845e3c1cebcf3caba7f7667a10e7123d.zip
Bug #499320 - Preview before import from command line
Diffstat (limited to 'addressbook/importers/evolution-ldif-importer.c')
-rw-r--r--addressbook/importers/evolution-ldif-importer.c63
1 files changed, 58 insertions, 5 deletions
diff --git a/addressbook/importers/evolution-ldif-importer.c b/addressbook/importers/evolution-ldif-importer.c
index 41dda05a40..52ce90e212 100644
--- a/addressbook/importers/evolution-ldif-importer.c
+++ b/addressbook/importers/evolution-ldif-importer.c
@@ -221,7 +221,7 @@ populate_contact_address (EContactAddress *address, gchar *attr, gchar *value)
}
static gboolean
-parseLine (LDIFImporter *gci, EContact *contact,
+parseLine (GHashTable *dn_contact_hash, EContact *contact,
EContactAddress *work_address, EContactAddress *home_address,
gchar **buf)
{
@@ -307,7 +307,7 @@ parseLine (LDIFImporter *gci, EContact *contact,
if (!field_handled) {
if (!g_ascii_strcasecmp (ptr, "dn"))
g_hash_table_insert (
- gci->dn_contact_hash,
+ dn_contact_hash,
g_strdup (ldif_value->str), contact);
else if (!g_ascii_strcasecmp (ptr, "objectclass") &&
!g_ascii_strcasecmp (ldif_value->str, "groupofnames")) {
@@ -342,7 +342,7 @@ parseLine (LDIFImporter *gci, EContact *contact,
}
static EContact *
-getNextLDIFEntry(LDIFImporter *gci, FILE *f )
+getNextLDIFEntry(GHashTable *dn_contact_hash, FILE *f )
{
EContact *contact;
EContactAddress *work_address, *home_address;
@@ -372,7 +372,7 @@ getNextLDIFEntry(LDIFImporter *gci, FILE *f )
buf = str->str;
while (buf) {
- if (!parseLine (gci, contact, work_address, home_address, &buf)) {
+ if (!parseLine (dn_contact_hash, contact, work_address, home_address, &buf)) {
/* parsing error */
g_string_free (str, TRUE);
e_contact_address_free (work_address);
@@ -480,7 +480,7 @@ ldif_import_contacts(gpointer d)
ones till the end */
if (gci->state == 0) {
- while (count < 50 && (contact = getNextLDIFEntry(gci, gci->file))) {
+ while (count < 50 && (contact = getNextLDIFEntry(gci->dn_contact_hash, gci->file))) {
if (e_contact_get (contact, E_CONTACT_IS_LIST)) {
gci->list_contacts = g_slist_prepend(gci->list_contacts, contact);
} else {
@@ -674,6 +674,58 @@ ldif_cancel(EImport *ei, EImportTarget *target, EImportImporter *im)
gci->state = 2;
}
+static GtkWidget *
+ldif_get_preview (EImport *ei, EImportTarget *target, EImportImporter *im)
+{
+ GtkWidget *preview;
+ GList *contacts = NULL;
+ EContact *contact;
+ EImportTargetURI *s = (EImportTargetURI *)target;
+ gchar *filename;
+ GHashTable *dn_contact_hash;
+ FILE *file;
+
+ filename = g_filename_from_uri (s->uri_src, NULL, NULL);
+ if (filename == NULL) {
+ g_message (G_STRLOC ": Couldn't get filename from URI '%s'", s->uri_src);
+ return NULL;
+ }
+
+ file = g_fopen(filename, "r");
+ g_free (filename);
+
+ if (file == NULL) {
+ g_message (G_STRLOC ": Can't open .ldif file");
+ return NULL;
+ }
+
+ dn_contact_hash = g_hash_table_new_full (
+ g_str_hash, g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) NULL);
+
+ while (contact = getNextLDIFEntry (dn_contact_hash, file), contact != NULL) {
+ if (!e_contact_get (contact, E_CONTACT_IS_LIST)) {
+ add_to_notes(contact, E_CONTACT_OFFICE);
+ add_to_notes(contact, E_CONTACT_SPOUSE);
+ add_to_notes(contact, E_CONTACT_BLOG_URL);
+ }
+
+ contacts = g_list_prepend (contacts, contact);
+ }
+
+ g_hash_table_destroy (dn_contact_hash);
+
+ contacts = g_list_reverse (contacts);
+ preview = evolution_contact_importer_get_preview_widget (contacts);
+
+ g_list_foreach (contacts, (GFunc) g_object_unref, NULL);
+ g_list_free (contacts);
+ fclose (file);
+
+ return preview;
+}
+
static EImportImporter ldif_importer = {
E_IMPORT_TARGET_URI,
0,
@@ -681,6 +733,7 @@ static EImportImporter ldif_importer = {
ldif_getwidget,
ldif_import,
ldif_cancel,
+ ldif_get_preview,
};
EImportImporter *