From afa42c2e1ce90b49561a9aa7cb75b692a2cdcd7c Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Sat, 17 Dec 2005 12:02:26 +0000 Subject: Use gstdio wrappers. Use GDir API instead of dirent. Use GLib to convert 2005-12-17 Tor Lillqvist * importers/evolution-vcard-importer.c: Use gstdio wrappers. Use GDir API instead of dirent. Use GLib to convert file names to URIs and back. Open files in binary mode. svn path=/trunk/; revision=30799 --- addressbook/importers/evolution-vcard-importer.c | 30 +++++++++++++++++++----- 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'addressbook/importers/evolution-vcard-importer.c') diff --git a/addressbook/importers/evolution-vcard-importer.c b/addressbook/importers/evolution-vcard-importer.c index 6aebdbd49c..ec63ed07a0 100644 --- a/addressbook/importers/evolution-vcard-importer.c +++ b/addressbook/importers/evolution-vcard-importer.c @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -323,7 +324,7 @@ guess_vcard_encoding (const char *filename) char *line_utf8; VCardEncoding encoding = VCARD_ENCODING_NONE; - handle = fopen (filename, "r"); + handle = g_fopen (filename, "r"); if (handle == NULL) { g_print ("\n"); return VCARD_ENCODING_NONE; @@ -411,6 +412,8 @@ static gboolean vcard_supported(EImport *ei, EImportTarget *target, EImportImporter *im) { EImportTargetURI *s; + gchar *filename; + gboolean retval; if (target->type != E_IMPORT_TARGET_URI) return FALSE; @@ -422,8 +425,13 @@ vcard_supported(EImport *ei, EImportTarget *target, EImportImporter *im) if (strncmp(s->uri_src, "file:///", 8) != 0) return FALSE; - /* FIXME: need to parse the url properly */ - return guess_vcard_encoding(s->uri_src+7) != VCARD_ENCODING_NONE; + filename = g_filename_from_uri (s->uri_src, NULL, NULL); + if (filename == NULL) + return FALSE; + retval = (guess_vcard_encoding(filename) != VCARD_ENCODING_NONE); + g_free (filename); + + return retval; } static void @@ -449,10 +457,17 @@ vcard_import(EImport *ei, EImportTarget *target, EImportImporter *im) VCardEncoding encoding; EBook *book; EImportTargetURI *s = (EImportTargetURI *)target; + gchar *filename; - /* FIXME: get filename properly */ - encoding = guess_vcard_encoding(s->uri_src+7); + 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); + e_import_complete(ei, target); + return; + } + encoding = guess_vcard_encoding(filename); if (encoding == VCARD_ENCODING_NONE) { + g_free (filename); /* this check is superfluous, we've already checked otherwise we can't get here ... */ e_import_complete(ei, target); return; @@ -461,6 +476,7 @@ vcard_import(EImport *ei, EImportTarget *target, EImportImporter *im) book = e_book_new(g_datalist_get_data(&target->data, "vcard-source"), NULL); if (book == NULL) { g_message(G_STRLOC ":Couldn't create EBook."); + g_free (filename); e_import_complete(ei, target); return; } @@ -472,13 +488,15 @@ vcard_import(EImport *ei, EImportTarget *target, EImportImporter *im) return; } - if (!g_file_get_contents (s->uri_src+7, &contents, NULL, NULL)) { + if (!g_file_get_contents (filename, &contents, NULL, NULL)) { g_message (G_STRLOC ":Couldn't read file."); + g_free (filename); e_import_complete(ei, target); g_object_unref(book); return; } + g_free (filename); gci = g_malloc0(sizeof(*gci)); g_datalist_set_data(&target->data, "vcard-data", gci); gci->import = g_object_ref(ei); -- cgit v1.2.3