aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Lillqvist <tml@novell.com>2005-12-17 20:02:26 +0800
committerTor Lillqvist <tml@src.gnome.org>2005-12-17 20:02:26 +0800
commitafa42c2e1ce90b49561a9aa7cb75b692a2cdcd7c (patch)
tree8f3a567d9d0ba2ee9ffbce1c70e86f9ead35ceb2
parent172ad11003eec1e4d49ba262853f11910d47616f (diff)
downloadgsoc2013-evolution-afa42c2e1ce90b49561a9aa7cb75b692a2cdcd7c.tar.gz
gsoc2013-evolution-afa42c2e1ce90b49561a9aa7cb75b692a2cdcd7c.tar.zst
gsoc2013-evolution-afa42c2e1ce90b49561a9aa7cb75b692a2cdcd7c.zip
Use gstdio wrappers. Use GDir API instead of dirent. Use GLib to convert
2005-12-17 Tor Lillqvist <tml@novell.com> * 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
-rw-r--r--addressbook/ChangeLog7
-rw-r--r--addressbook/importers/evolution-vcard-importer.c30
2 files changed, 28 insertions, 9 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog
index 44ad248567..ded8704283 100644
--- a/addressbook/ChangeLog
+++ b/addressbook/ChangeLog
@@ -1,8 +1,9 @@
2005-12-17 Tor Lillqvist <tml@novell.com>
- * gui/component/addressbook-migrate.c: Use gstdio wrappers. Use
- GDir API instead of dirent. Use GLib API to convert file names to
- URIs and back. Open files in binary mode.
+ * gui/component/addressbook-migrate.c
+ * 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.
2005-12-15 Srinivasa Ragavan <sragavan@novell.com>
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 <gtk/gtkvbox.h>
#include <glib/gi18n.h>
+#include <glib/gstdio.h>
#include <libebook/e-book.h>
#include <libedataserverui/e-source-selector.h>
@@ -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);