diff options
author | Christian Persch <chpe@cvs.gnome.org> | 2006-03-03 05:30:04 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2006-03-03 05:30:04 +0800 |
commit | fdb9695a63e0d25e9adffeb485962ee62e67f310 (patch) | |
tree | 08b1288995fccfe1e25c65595c3c2ac2b7d7ebad /src | |
parent | 8dc95a5c584d8fdb99afec102702bd8801b95266 (diff) | |
download | gsoc2013-epiphany-fdb9695a63e0d25e9adffeb485962ee62e67f310.tar gsoc2013-epiphany-fdb9695a63e0d25e9adffeb485962ee62e67f310.tar.gz gsoc2013-epiphany-fdb9695a63e0d25e9adffeb485962ee62e67f310.tar.bz2 gsoc2013-epiphany-fdb9695a63e0d25e9adffeb485962ee62e67f310.tar.lz gsoc2013-epiphany-fdb9695a63e0d25e9adffeb485962ee62e67f310.tar.xz gsoc2013-epiphany-fdb9695a63e0d25e9adffeb485962ee62e67f310.tar.zst gsoc2013-epiphany-fdb9695a63e0d25e9adffeb485962ee62e67f310.zip |
If we can't detect the mime type, fall back to checking the file
2006-03-02 Christian Persch <chpe@cvs.gnome.org>
* src/bookmarks/ephy-bookmarks-import.c: (ephy_bookmarks_import):
If we can't detect the mime type, fall back to checking the file
extension. Bug #331468.
* src/ephy-main.c: (main):
Don't pass NULL to realpath if PATH_MAX is defined. Bug #333051.
Diffstat (limited to 'src')
-rw-r--r-- | src/bookmarks/ephy-bookmarks-import.c | 50 | ||||
-rw-r--r-- | src/ephy-main.c | 70 |
2 files changed, 100 insertions, 20 deletions
diff --git a/src/bookmarks/ephy-bookmarks-import.c b/src/bookmarks/ephy-bookmarks-import.c index 098a96d9d..651fa2fa8 100644 --- a/src/bookmarks/ephy-bookmarks-import.c +++ b/src/bookmarks/ephy-bookmarks-import.c @@ -69,44 +69,60 @@ ephy_bookmarks_import (EphyBookmarks *bookmarks, const char *filename) { const char *type; + char *basename; gboolean success = FALSE; if (eel_gconf_get_boolean (CONF_LOCKDOWN_DISABLE_BOOKMARK_EDITING)) return FALSE; + g_return_val_if_fail (filename != NULL, FALSE); + type = gnome_vfs_get_file_mime_type (filename, NULL, FALSE); LOG ("Importing bookmarks of type %s", type ? type : "(null)"); - if (type == NULL) - { - g_warning ("Couldn't determine the type of the bookmarks file %s!\n", filename); - } - else if (strcmp (type, "application/x-mozilla-bookmarks") == 0) + if (type != NULL && (strcmp (type, "application/rdf+xml") == 0 || + strcmp (type, "text/rdf") == 0)) { - success = ephy_bookmarks_import_mozilla (bookmarks, filename); + success = ephy_bookmarks_import_rdf (bookmarks, filename); } - else if (strcmp (type, "application/x-xbel") == 0) + else if ((type != NULL && strcmp (type, "application/x-xbel") == 0) || + strstr (filename, GALEON_BOOKMARKS_DIR) != NULL || + strstr (filename, KDE_BOOKMARKS_DIR) != NULL) { success = ephy_bookmarks_import_xbel (bookmarks, filename); } - else if (strcmp (type, "application/rdf+xml") == 0 || - strcmp (type, "text/rdf") == 0) - { - success = ephy_bookmarks_import_rdf (bookmarks, filename); - } - else if (strstr (filename, MOZILLA_BOOKMARKS_DIR) != NULL || + else if ((type != NULL && strcmp (type, "application/x-mozilla-bookmarks") == 0) || + strstr (filename, MOZILLA_BOOKMARKS_DIR) != NULL || strstr (filename, FIREFOX_BOOKMARKS_DIR_0) != NULL || strstr (filename, FIREFOX_BOOKMARKS_DIR_1) != NULL || strstr (filename, FIREFOX_BOOKMARKS_DIR_2) != NULL) { success = ephy_bookmarks_import_mozilla (bookmarks, filename); } - else if (strstr (filename, GALEON_BOOKMARKS_DIR) != NULL || - strstr (filename, KDE_BOOKMARKS_DIR) != NULL) + else if (type == NULL) { - success = ephy_bookmarks_import_xbel (bookmarks, filename); + basename = g_path_get_basename (filename); + + if (g_str_has_suffix (basename, ".rdf")) + { + success = ephy_bookmarks_import_rdf (bookmarks, filename); + } + else if (g_str_has_suffix (basename, ".xbel")) + { + success = ephy_bookmarks_import_xbel (bookmarks, filename); + } + else if (g_str_has_suffix (basename, ".html")) + { + success = ephy_bookmarks_import_mozilla (bookmarks, filename); + } + else + { + /* else FIXME: put up some UI to warn user about unrecognised format? */ + g_warning ("Couldn't determine the type of the bookmarks file %s!\n", filename); + } + + g_free (basename); } - /* else FIXME: put up some UI to warn user about unrecognised format? */ return success; } diff --git a/src/ephy-main.c b/src/ephy-main.c index 9b97e1416..51a422f8b 100644 --- a/src/ephy-main.c +++ b/src/ephy-main.c @@ -449,7 +449,64 @@ main (int argc, /* check libxml2 API version epiphany was compiled with against the * version we're running with. */ - LIBXML_TEST_VERSION + LIBXML_TEST_VERSION; + + /* If we're given -remote arguments, translate them */ + if (argc >= 2 && + strcmp (argv[1], "-remote") == 0) + { + const char *opening, *closing; + char *command, *argument; + char **arguments; + + if (argc != 3) + { + g_print ("-remote allows exactly one argument\n"); + exit (1); + } + + opening = strchr (argv[2], '('); + closing = strchr (argv[2], ')'); + + if (opening == NULL || + closing == NULL || + opening == argv[2] || + opening + 1 >= closing) + { + g_print ("Invalid argument for -remote\n"); + exit (1); + } + + command = g_strstrip (g_strndup (argv[2], opening - argv[2])); + + /* See http://lxr.mozilla.org/seamonkey/source/xpfe/components/xremote/src/XRemoteService.cpp + * for the commands that mozilla supports; we'll just support openURL here. + */ + if (g_ascii_strcasecmp (command, "openURL") != 0) + { + g_print ("-remote command \"%s\" not supported\n", command); + g_free (command); + exit (1); + } + + g_free (command); + + argument = g_strstrip (g_strndup (opening + 1, closing - opening - 1)); + arguments = g_strsplit (argument, ",", -1); + g_free (argument); + if (arguments == NULL) + { + g_print ("Invalid argument for -remote\n"); + + exit (1); + } + + /* replace arguments */ + argv[1] = g_strstrip (g_strdup (arguments[0])); + argc = 2; + + g_strfreev (arguments); + } /* Initialise our debug helpers */ ephy_debug_init (); @@ -569,14 +626,21 @@ main (int argc, for (i = 0; arguments[i] != NULL; ++i) { - char *uri, *path = NULL; + char *uri, *path; +#ifdef PATH_MAX + char rpath[PATH_MAX]; +#else + char *rpath = NULL; +#endif - path = realpath (arguments[i], NULL); + path = realpath (arguments[i], rpath); if (path != NULL) { uri = g_locale_to_utf8 (path, -1, NULL, NULL, &error); +#ifndef PATH_MAX free (path); +#endif } else { |