From af1c2ceaef7d949e36a7680f463c5e25f79c43d6 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Sun, 13 Jan 2008 20:42:01 +0000 Subject: Drop gnome-vfs dependency. Now Epiphany depends on glib >= 2.15.1. Also, optional Zeroconf support depends on Avahi >= 0.6.22. Bug #507152. svn path=/trunk/; revision=7858 --- configure.ac | 19 +- embed/downloader-view.c | 5 +- embed/ephy-base-embed.c | 132 ++--- embed/ephy-download.c | 11 +- embed/ephy-favicon-cache.c | 118 +++-- embed/ephy-history.c | 25 +- embed/mozilla/ContentHandler.cpp | 19 +- embed/mozilla/ContentHandler.h | 4 +- embed/mozilla/EphyHeaderSniffer.cpp | 4 +- embed/mozilla/MozDownload.cpp | 16 +- embed/mozilla/MozDownload.h | 2 - embed/mozilla/mozilla-embed-single.cpp | 43 +- embed/webkit/webkit-embed-single.c | 1 - embed/webkit/webkit-embed.c | 2 - embed/xulrunner/components/ContentHandler.cpp | 17 +- embed/xulrunner/components/ContentHandler.h | 2 +- embed/xulrunner/components/MozDownload.cpp | 16 +- embed/xulrunner/embed/EphyHeaderSniffer.cpp | 3 +- embed/xulrunner/embed/mozilla-embed-single.cpp | 38 +- lib/Makefile.am | 1 + lib/egg/Makefile.am | 6 +- lib/ephy-file-chooser.c | 6 +- lib/ephy-file-helpers.c | 708 ++++--------------------- lib/ephy-file-helpers.h | 35 +- lib/ephy-node-db.c | 17 +- lib/ephy-string.c | 240 +++++++++ lib/ephy-string.h | 6 + src/bookmarks/Makefile.am | 9 + src/bookmarks/ephy-bookmark-action.c | 59 ++- src/bookmarks/ephy-bookmarks-export.c | 98 ++-- src/bookmarks/ephy-bookmarks-import.c | 20 +- src/bookmarks/ephy-bookmarks.c | 364 +++++++++---- src/bookmarks/ephy-topic-action.c | 1 - src/ephy-extensions-manager.c | 47 +- src/ephy-main.c | 31 +- src/ephy-session.c | 79 +-- src/ephy-window.c | 12 +- src/popup-commands.c | 41 +- src/prefs-dialog.c | 17 +- src/window-commands.c | 72 ++- 40 files changed, 1174 insertions(+), 1172 deletions(-) diff --git a/configure.ac b/configure.ac index 0f35bb677..9972b03a0 100644 --- a/configure.ac +++ b/configure.ac @@ -94,7 +94,7 @@ if test "$enable_maintainer_mode" = "yes"; then GECKO_WARN_CXXFLAGS="-Wall -Wconversion -Wpointer-arith -Wcast-align -Woverloaded-virtual -Wsynth $GECKO_WARN_CXXFLAGS" fi -GLIB_REQUIRED=2.13.4 +GLIB_REQUIRED=2.15.1 GTK_REQUIRED=2.11.6 LIBXML_REQUIRED=2.6.12 LIBXSLT_REQUIRED=1.1.7 @@ -118,6 +118,7 @@ fi PKG_CHECK_MODULES([DEPENDENCIES], [ glib-2.0 >= $GLIB_REQUIRED gmodule-2.0 + gio-unix-2.0 >= $GLIB_REQUIRED gtk+-2.0 >= $GTK_REQUIRED gtk+-unix-print-2.0 >= $GTK_REQUIRED libxml-2.0 >= $LIBXML_REQUIRED @@ -125,8 +126,6 @@ PKG_CHECK_MODULES([DEPENDENCIES], [ libgnome-2.0 >= $LIBGNOME_REQUIRED libgnomeui-2.0 >= $LIBGNOMEUI_REQUIRED libglade-2.0 >= $LIBGLADE_REQUIRED \ - gnome-vfs-2.0 >= $LIBGNOMEVFS_REQUIRED - gnome-vfs-module-2.0 gconf-2.0 gnome-desktop-2.0 >= $GNOME_DESKTOP_REQUIRED libstartup-notification-1.0 >= $LIBSTARTUP_NOTIFICATION_REQUIRED @@ -593,6 +592,12 @@ AC_ARG_ENABLE([zeroconf], AC_MSG_RESULT([$enable_zeroconf]) if test "$enable_zeroconf" = "yes"; then + AVAHI_REQUIRED=0.6.22 + + PKG_CHECK_MODULES(AVAHI, [avahi-gobject >= $AVAHI_REQUIRED]) + AC_SUBST(AVAHI_CFLAGS) + AC_SUBST(AVAHI_LIBS) + AC_DEFINE([ENABLE_ZEROCONF],[1],[Define to enable zeroconf bookmarks support]) fi @@ -792,18 +797,10 @@ po/Makefile.in PKG_CHECK_MODULES([GTK],[gtk+-2.0 >= $GTK_REQUIRED]) PKG_CHECK_MODULES([GTKPRINT],[gtk+-unix-print-2.0 >= $GTK_REQUIRED]) -PKG_CHECK_MODULES([GNOMEVFS],[gnome-vfs-2.0 >= $LIBGNOMEVFS_REQUIRED gnome-vfs-module-2.0]) PKG_CHECK_MODULES([GCONF],[gconf-2.0]) PKG_CHECK_MODULES([GLADE],[libglade-2.0 >= $LIBGLADE_REQUIRED]) PKG_CHECK_MODULES([GNOME],[libgnome-2.0 >= $LIBGNOME_REQUIRED libgnomeui-2.0 >= $LIBGNOMEUI_REQUIRED]) -PKG_CHECK_MODULES([GVFS],[gio-standalone],[have_gvfs=yes],[have_gvfs=no]) - -if test "$have_gvfs" = "yes"; then - AC_DEFINE([HAVE_GVFS],[1],[Define if GVFS is available]) -fi -AM_CONDITIONAL([HAVE_GVFS],[test "$have_gvfs" = "yes"]) - # Distributor name AC_ARG_WITH(distributor-name, diff --git a/embed/downloader-view.c b/embed/downloader-view.c index 0d6dbbf29..b0292fe0b 100644 --- a/embed/downloader-view.c +++ b/embed/downloader-view.c @@ -48,7 +48,6 @@ #include #include #include -#include #include @@ -465,7 +464,7 @@ update_download_row (DownloaderView *dv, EphyDownload *download) total = ephy_download_get_total_progress (download); current = ephy_download_get_current_progress (download); - cur_progress = gnome_vfs_format_file_size_for_display (current); + cur_progress = g_format_size_for_display (current); name = ephy_download_get_name (download); @@ -501,7 +500,7 @@ update_download_row (DownloaderView *dv, EphyDownload *download) { char *total_progress; - total_progress = gnome_vfs_format_file_size_for_display (total); + total_progress = g_format_size_for_display (total); /* translators: first %s is filename, "%s of %s" is current/total file size */ file = g_strdup_printf (_("%s\n%s of %s"), name, cur_progress, total_progress); diff --git a/embed/ephy-base-embed.c b/embed/ephy-base-embed.c index 2d695a0b8..4d57c496c 100644 --- a/embed/ephy-base-embed.c +++ b/embed/ephy-base-embed.c @@ -23,8 +23,7 @@ #include "config.h" #include -#include -#include +#include #include #include "eel-gconf-extensions.h" @@ -77,7 +76,8 @@ struct _EphyBaseEmbedPrivate { GdkPixbuf *icon; /* File watch */ - GnomeVFSMonitorHandle *monitor; + GFileMonitor *monitor; + gboolean monitor_directory; guint reload_scheduled_id; guint reload_delay_ticks; @@ -922,6 +922,7 @@ ephy_base_embed_init (EphyBaseEmbed *self) priv->address_expire = EPHY_EMBED_ADDRESS_EXPIRE_NOW; priv->is_blank = TRUE; priv->title = g_strdup (EMPTY_PAGE); + priv->monitor_directory = FALSE; } static void @@ -1000,27 +1001,13 @@ ephy_base_embed_set_address (EphyBaseEmbed *embed, g_object_notify (object, "address"); } -static char * +static char* get_title_from_address (const char *address) { - GnomeVFSURI *uri; - char *title; - - if (address == NULL) return NULL; - - uri = gnome_vfs_uri_new (address); - if (uri == NULL) return g_strdup (address); - - title = gnome_vfs_uri_to_string (uri, - (GnomeVFSURIHideOptions) - (GNOME_VFS_URI_HIDE_USER_NAME | - GNOME_VFS_URI_HIDE_PASSWORD | - GNOME_VFS_URI_HIDE_HOST_PORT | - GNOME_VFS_URI_HIDE_TOPLEVEL_METHOD | - GNOME_VFS_URI_HIDE_FRAGMENT_IDENTIFIER)); - gnome_vfs_uri_unref (uri); - - return title; + if (g_str_has_prefix (address, "file://")) + return g_strdup (address + 7); + else + return ephy_string_get_host_name (address); } void @@ -1069,19 +1056,13 @@ ensure_page_info (EphyBaseEmbed *embed, const char *address) static void update_net_state_message (EphyBaseEmbed *embed, const char *uri, EphyEmbedNetState flags) { - GnomeVFSURI *vfs_uri = NULL; const char *msg = NULL; - const char *host = NULL; - - if (uri != NULL) { - vfs_uri = gnome_vfs_uri_new (uri); - } + char *host = NULL; - if (vfs_uri != NULL) { - host = gnome_vfs_uri_get_host_name (vfs_uri); - } + if (uri != NULL) + host = ephy_string_get_host_name (uri); - if (host == NULL || host[0] == '\0') goto out; + if (host == NULL) goto out; /* IS_REQUEST and IS_NETWORK can be both set */ if (flags & EPHY_EMBED_STATE_IS_REQUEST) { @@ -1116,9 +1097,7 @@ update_net_state_message (EphyBaseEmbed *embed, const char *uri, EphyEmbedNetSta } out: - if (vfs_uri != NULL) { - gnome_vfs_uri_unref (vfs_uri); - } + g_free (host); } static void @@ -1288,8 +1267,8 @@ ephy_base_embed_file_monitor_cancel (EphyBaseEmbed *embed) if (priv->monitor != NULL) { LOG ("Cancelling file monitor"); - - gnome_vfs_monitor_cancel (priv->monitor); + + g_file_monitor_cancel (G_FILE_MONITOR (priv->monitor)); priv->monitor = NULL; } @@ -1334,39 +1313,32 @@ ephy_base_embed_file_monitor_reload_cb (EphyBaseEmbed *embed) } static void -ephy_base_embed_file_monitor_cb (GnomeVFSMonitorHandle *handle, - const gchar *monitor_uri, - const gchar *info_uri, - GnomeVFSMonitorEventType event_type, +ephy_base_embed_file_monitor_cb (GFileMonitor *monitor, + GFile *file, + GFile *other_file, + GFileMonitorEvent event_type, EphyBaseEmbed *embed) { - gboolean uri_is_directory; gboolean should_reload; - char *local_path; EphyBaseEmbedPrivate *priv = embed->priv; - LOG ("File '%s' has changed, scheduling reload", monitor_uri); - - local_path = gnome_vfs_get_local_path_from_uri (monitor_uri); - uri_is_directory = g_file_test (local_path, G_FILE_TEST_IS_DIR); - g_free (local_path); - switch (event_type) { /* These events will always trigger a reload: */ - case GNOME_VFS_MONITOR_EVENT_CHANGED: - case GNOME_VFS_MONITOR_EVENT_CREATED: + case G_FILE_MONITOR_EVENT_CHANGED: + case G_FILE_MONITOR_EVENT_CREATED: should_reload = TRUE; break; - /* These events will only trigger a reload for directories: */ - case GNOME_VFS_MONITOR_EVENT_DELETED: - case GNOME_VFS_MONITOR_EVENT_METADATA_CHANGED: - should_reload = uri_is_directory; + /* These events will only trigger a reload for directories: */ + case G_FILE_MONITOR_EVENT_DELETED: + case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED: + should_reload = priv->monitor_directory; break; - /* These events don't trigger a reload: */ - case GNOME_VFS_MONITOR_EVENT_STARTEXECUTING: - case GNOME_VFS_MONITOR_EVENT_STOPEXECUTING: + /* These events don't trigger a reload: */ + case G_FILE_MONITOR_EVENT_PRE_UNMOUNT: + case G_FILE_MONITOR_EVENT_UNMOUNTED: + case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT: default: should_reload = FALSE; break; @@ -1399,10 +1371,11 @@ ephy_base_embed_update_file_monitor (EphyBaseEmbed *embed, const gchar *address) { EphyBaseEmbedPrivate *priv = embed->priv; - GnomeVFSMonitorHandle *handle = NULL; gboolean local; - char *local_path; - GnomeVFSMonitorType monitor_type; + GFile *file; + GFileType file_type; + GFileInfo *file_info; + GFileMonitor *monitor = NULL; if (priv->monitor != NULL && priv->address != NULL && address != NULL && @@ -1415,21 +1388,32 @@ ephy_base_embed_update_file_monitor (EphyBaseEmbed *embed, local = g_str_has_prefix (address, "file://"); if (local == FALSE) return; - - local_path = gnome_vfs_get_local_path_from_uri (address); - monitor_type = g_file_test (local_path, G_FILE_TEST_IS_DIR) - ? GNOME_VFS_MONITOR_DIRECTORY - : GNOME_VFS_MONITOR_FILE; - g_free (local_path); - - if (gnome_vfs_monitor_add (&handle, address, - monitor_type, - (GnomeVFSMonitorCallback)ephy_base_embed_file_monitor_cb, - embed) == GNOME_VFS_OK) { + + file = g_file_new_for_uri (address); + file_info = g_file_query_info (file, + G_FILE_ATTRIBUTE_STANDARD_TYPE, + 0, NULL, NULL); + file_type = g_file_info_get_file_type (file_info); + g_object_unref (file_info); + + if (file_type == G_FILE_TYPE_DIRECTORY) { + monitor = g_file_monitor_directory (file, 0, NULL); + g_signal_connect (monitor, "changed", + G_CALLBACK (ephy_base_embed_file_monitor_cb), + embed); + priv->monitor_directory = TRUE; + LOG ("Installed monitor for directory '%s'", address); + } + else if (file_type == G_FILE_TYPE_REGULAR) { + monitor = g_file_monitor_file (file, 0, NULL); + g_signal_connect (monitor, "changed", + G_CALLBACK (ephy_base_embed_file_monitor_cb), + embed); + priv->monitor_directory = FALSE; LOG ("Installed monitor for file '%s'", address); - - priv->monitor = handle; } + priv->monitor = monitor; + g_object_unref (file); } void diff --git a/embed/ephy-download.c b/embed/ephy-download.c index a6f420a3d..fac8ce7ae 100644 --- a/embed/ephy-download.c +++ b/embed/ephy-download.c @@ -22,7 +22,7 @@ #include "ephy-download.h" -#include +#include #define EPHY_DOWNLOAD_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_DOWNLOAD, EphyDownloadPrivate)) @@ -115,21 +115,18 @@ ephy_download_new (void) char * ephy_download_get_name (EphyDownload *download) { - GnomeVFSURI *uri; char *target; char *result; target = ephy_download_get_target (download); - uri = gnome_vfs_uri_new (target); - if (uri) + if (target) { - result = gnome_vfs_uri_extract_short_name (uri); - gnome_vfs_uri_unref (uri); + result = g_path_get_basename (target); } else { - result = g_strdup ("Unknown"); + result = g_strdup (_("Unknown")); } g_free (target); diff --git a/embed/ephy-favicon-cache.c b/embed/ephy-favicon-cache.c index 06af26e56..35e3f0809 100644 --- a/embed/ephy-favicon-cache.c +++ b/embed/ephy-favicon-cache.c @@ -39,9 +39,8 @@ #include "ephy-glib-compat.h" #include +#include #include -#include -#include #define EPHY_FAVICON_CACHE_XML_ROOT (const xmlChar *)"ephy_favicons_cache" #define EPHY_FAVICON_CACHE_XML_VERSION (const xmlChar *)"1.1" @@ -250,7 +249,10 @@ remove_obsolete_icons (EphyFaviconCache *cache, (kid, EPHY_NODE_FAVICON_PROP_FILENAME); path = g_build_filename (priv->directory, filename, NULL); - gnome_vfs_unlink (path); + if (g_unlink (path) < 0) + { + g_warning ("Unable to delete %s", path); + } g_free (path); ephy_node_unref (kid); @@ -412,29 +414,28 @@ kill_download (const char *key, return TRUE; } -static gboolean -delete_file (const char *rel_path, - GnomeVFSFileInfo *info, - gboolean rec_will_loop, - EphyFaviconCache *cache, - gboolean *recurse) +static void +delete_file (GFile *dir, + GFileInfo *file_info) { - EphyFaviconCachePrivate *priv = cache->priv; - char *path; - - *recurse = FALSE; - - g_return_val_if_fail (info != NULL, TRUE); - - if ((info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_TYPE) == 0 || - info->type != GNOME_VFS_FILE_TYPE_REGULAR) return TRUE; - - path = g_build_filename (priv->directory, rel_path, NULL); - gnome_vfs_unlink (path); - g_free (path); - - /* continue with the visit */ - return TRUE; + GFileType type; + + type = g_file_info_get_file_type (file_info); + + if (type == G_FILE_TYPE_REGULAR) + { + char *path; + + path = g_build_filename (g_file_get_path (dir), + g_file_info_get_name (file_info), + NULL); + if (g_unlink (path) < 0) + { + g_warning ("Unable to delete %s", path); + } + + g_free (path); + } } static void @@ -509,8 +510,11 @@ favicon_download_cancelled_cb (EphyEmbedPersist *persist, g_hash_table_remove (cache->priv->downloads_hash, url); /* remove a partially downloaded file */ - dest = ephy_embed_persist_get_dest (persist); - gnome_vfs_unlink (dest); + dest = ephy_embed_persist_get_dest (persist); + if (g_unlink (dest) < 0) + { + g_warning ("Unable to delete %s", dest); + } /* FIXME: re-schedule to try again after n days? */ @@ -700,29 +704,35 @@ ephy_favicon_cache_get (EphyFaviconCache *cache, (int) checklevel); } - /* Now check the type. We renamed the file above, so gnome-vfs does NOT + /* Now check the type. We renamed the file above, so glib does NOT * fall back to extension checking if the slow mime check fails for * whatever reason */ if (checklevel & NEEDS_TYPE_CHECK) { - GnomeVFSFileInfo *info; - gboolean valid = FALSE, is_ao = FALSE;; - + GFile *file; + GFileInfo *file_info; + const char *mime_type; + gboolean valid = FALSE, is_ao = FALSE; + + file = g_file_new_for_path (pix_file); + /* Sniff mime type and check if it's safe to open */ - info = gnome_vfs_file_info_new (); - if (gnome_vfs_get_file_info (pix_file, info, - GNOME_VFS_FILE_INFO_GET_MIME_TYPE | - GNOME_VFS_FILE_INFO_FORCE_SLOW_MIME_TYPE) == GNOME_VFS_OK && - (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE) && - info->mime_type != NULL) + file_info = g_file_query_info (file, + G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, + 0, NULL, NULL); + mime_type = g_file_info_get_content_type (file_info); + if (file_info == NULL) { - valid = strcmp (info->mime_type, "image/x-ico") == 0 || - strcmp (info->mime_type, "image/png") == 0 || - strcmp (info->mime_type, "image/gif") == 0; - is_ao = strcmp (info->mime_type, "application/octet-stream") == 0; + return NULL; } - gnome_vfs_file_info_unref (info); + valid = strcmp (mime_type, "image/x-ico") == 0 || + strcmp (mime_type, "image/png") == 0 || + strcmp (mime_type, "image/gif") == 0; + is_ao = strcmp (mime_type, "application/octet-stream") == 0; + + g_object_unref (file_info); + g_object_unref (file); /* As a special measure, we try to load an application/octet-stream file * as an ICO file, since we cannot detect a ICO file without .ico extension @@ -835,6 +845,9 @@ ephy_favicon_cache_get (EphyFaviconCache *cache, void ephy_favicon_cache_clear (EphyFaviconCache *cache) { + GFileEnumerator *file_enum; + GFile *dir; + GFileInfo *file_info = NULL; EphyFaviconCachePrivate *priv = cache->priv; g_return_if_fail (EPHY_IS_FAVICON_CACHE (cache)); @@ -843,10 +856,19 @@ ephy_favicon_cache_clear (EphyFaviconCache *cache) ephy_favicon_cache_save (cache); /* Now remove any remaining files from the cache directory */ - gnome_vfs_directory_visit (priv->directory, - GNOME_VFS_FILE_INFO_DEFAULT, - GNOME_VFS_DIRECTORY_VISIT_SAMEFS | - GNOME_VFS_DIRECTORY_VISIT_LOOPCHECK, - (GnomeVFSDirectoryVisitFunc) delete_file, - cache); + dir = g_file_new_for_path (priv->directory); + file_enum = g_file_enumerate_children (dir, + G_FILE_ATTRIBUTE_STANDARD_TYPE "," + G_FILE_ATTRIBUTE_STANDARD_NAME "," + G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, + 0, NULL, NULL); + file_info = g_file_enumerator_next_file (file_enum, NULL, NULL); + while (file_info != NULL) + { + delete_file (dir, file_info); + file_info = g_file_enumerator_next_file (file_enum, NULL, NULL); + g_object_unref (file_info); + } + g_object_unref (dir); + g_file_enumerator_close (file_enum, NULL, NULL); } diff --git a/embed/ephy-history.c b/embed/ephy-history.c index f7fdcc669..127d97656 100644 --- a/embed/ephy-history.c +++ b/embed/ephy-history.c @@ -30,11 +30,11 @@ #include "eel-gconf-extensions.h" #include "ephy-prefs.h" #include "ephy-glib-compat.h" +#include "ephy-string.h" #include #include #include -#include #define EPHY_HISTORY_XML_ROOT (const xmlChar *)"ephy_history" #define EPHY_HISTORY_XML_VERSION (const xmlChar *)"1.0" @@ -658,11 +658,10 @@ ephy_history_host_visited (EphyHistory *eh, static EphyNode * internal_get_host (EphyHistory *eh, const char *url, gboolean create) { - GnomeVFSURI *vfs_uri = NULL; EphyNode *host = NULL; - const char *host_name = NULL; + char *host_name = NULL; GList *host_locations = NULL, *l; - const char *scheme = NULL; + char *scheme = NULL; GTime now; g_return_val_if_fail (url != NULL, NULL); @@ -674,24 +673,22 @@ internal_get_host (EphyHistory *eh, const char *url, gboolean create) now = time (NULL); - vfs_uri = gnome_vfs_uri_new (url); - - if (vfs_uri) + if (url) { - scheme = gnome_vfs_uri_get_scheme (vfs_uri); - host_name = gnome_vfs_uri_get_host_name (vfs_uri); + scheme = g_uri_get_scheme (url); + host_name = ephy_string_get_host_name (url); } /* Build an host name */ if (scheme == NULL || host_name == NULL) { - host_name = _("Others"); + host_name = g_strdup (_("Others")); host_locations = g_list_append (host_locations, g_strdup ("about:blank")); } else if (strcmp (scheme, "file") == 0) { - host_name = _("Local files"); + host_name = g_strdup (_("Local files")); host_locations = g_list_append (host_locations, g_strdup ("file:///")); } @@ -766,10 +763,8 @@ internal_get_host (EphyHistory *eh, const char *url, gboolean create) ephy_history_host_visited (eh, host, now); } - if (vfs_uri) - { - gnome_vfs_uri_unref (vfs_uri); - } + g_free (scheme); + g_free (host_name); g_list_foreach (host_locations, (GFunc)g_free, NULL); g_list_free (host_locations); diff --git a/embed/mozilla/ContentHandler.cpp b/embed/mozilla/ContentHandler.cpp index 0510aa3f1..5b7a5ac0e 100644 --- a/embed/mozilla/ContentHandler.cpp +++ b/embed/mozilla/ContentHandler.cpp @@ -25,14 +25,13 @@ #include "config.h" #include +#include #include #include #include #include #include #include -#include -#include #include @@ -254,7 +253,7 @@ NS_METHOD GContentHandler::MIMEConfirmAction () { GtkWidget *dialog, *button, *image; const char *action_label; - const char *mime_description; + char *mime_description; nsCString file_name; nsCOMPtr parentDOMWindow = do_GetInterface (mContext); @@ -264,12 +263,12 @@ NS_METHOD GContentHandler::MIMEConfirmAction () (mAction == CONTENT_ACTION_OPEN_TMP) ? GTK_STOCK_OPEN : STOCK_DOWNLOAD; - mime_description = gnome_vfs_mime_get_description (mMimeType.get()); + mime_description = g_content_type_get_description (mMimeType.get()); if (mime_description == NULL) { /* Translators: The text before the "|" is context to help you decide on * the correct translation. You MUST OMIT it in the translated string. */ - mime_description = Q_("File Type:|Unknown"); + mime_description = g_strdup (Q_("File Type:|Unknown")); } /* We have one tiny, minor issue, the filename can be empty (""), @@ -309,7 +308,7 @@ NS_METHOD GContentHandler::MIMEConfirmAction () Second %s is the file name, Third %s is the application used to open the file */ _("File Type: “%s”.\n\nYou can open “%s” using “%s” or save it."), - mime_description, file_name.get(), mHelperApp->name); + mime_description, file_name.get(), g_app_info_get_name (mHelperApp)); } else { @@ -327,6 +326,8 @@ NS_METHOD GContentHandler::MIMEConfirmAction () mime_description, file_name.get()); } + g_free (mime_description); + button = gtk_button_new_with_label (_("_Save As...")); image = gtk_image_new_from_stock (GTK_STOCK_SAVE_AS, GTK_ICON_SIZE_BUTTON); gtk_button_set_image (GTK_BUTTON (button), image); @@ -367,7 +368,7 @@ NS_METHOD GContentHandler::MIMEInitiateAction (void) auto_downloads = eel_gconf_get_boolean (CONF_AUTO_DOWNLOADS); - mHelperApp = gnome_vfs_mime_get_default_application (mMimeType.get()); + mHelperApp = g_app_info_get_default_for_type (mMimeType.get(), TRUE); mPermission = ephy_file_check_mime (mMimeType.get()); /* HACK! Check that this 'helper application' isn't Epiphany itself, @@ -375,7 +376,7 @@ NS_METHOD GContentHandler::MIMEInitiateAction (void) */ if (mHelperApp) { - const char *id = gnome_vfs_mime_application_get_desktop_id (mHelperApp); + const char *id = g_app_info_get_id (mHelperApp); /* FIXME! menu editing can make this check fail!!!! */ if (id && strcmp (id, "epiphany.desktop") == 0) @@ -426,7 +427,7 @@ NS_METHOD GContentHandler::MIMEDoAction (void) g_return_val_if_fail (mHelperApp, NS_ERROR_FAILURE); const char *id; - id = gnome_vfs_mime_application_get_desktop_id (mHelperApp); + id = g_app_info_get_id (mHelperApp); /* The current time is fine here as the user has just clicked * a button (it is used as the time for the application opening) diff --git a/embed/mozilla/ContentHandler.h b/embed/mozilla/ContentHandler.h index 113e29070..366aae482 100644 --- a/embed/mozilla/ContentHandler.h +++ b/embed/mozilla/ContentHandler.h @@ -22,7 +22,7 @@ #ifndef CONTENT_HANDLER_H #define CONTENT_HANDLER_H -#include +#include #include #include @@ -70,7 +70,7 @@ class GContentHandler : public nsIHelperAppLauncherDialog nsCOMPtr mLauncher; nsCOMPtr mContext; - GnomeVFSMimeApplication *mHelperApp; + GAppInfo *mHelperApp; EphyMimePermission mPermission; nsCString mUrl; diff --git a/embed/mozilla/EphyHeaderSniffer.cpp b/embed/mozilla/EphyHeaderSniffer.cpp index 3ba938254..f09a6ee0e 100644 --- a/embed/mozilla/EphyHeaderSniffer.cpp +++ b/embed/mozilla/EphyHeaderSniffer.cpp @@ -43,7 +43,6 @@ #include "config.h" #include -#include #include @@ -382,8 +381,7 @@ nsresult EphyHeaderSniffer::PerformSave (nsIURI* inOriginalURI) /* FIXME: do better here by using nsITextToSubURI service, like in * http://lxr.mozilla.org/seamonkey/source/xpfe/communicator/resources/content/contentAreaUtils.js#763 */ - char *filename; - filename = gnome_vfs_unescape_string (default_name, NULL); + char *filename = g_uri_unescape_string (default_name, NULL); if (!g_utf8_validate (filename, -1, NULL)) { diff --git a/embed/mozilla/MozDownload.cpp b/embed/mozilla/MozDownload.cpp index 254738f18..bdce1212f 100644 --- a/embed/mozilla/MozDownload.cpp +++ b/embed/mozilla/MozDownload.cpp @@ -47,6 +47,8 @@ #include #include +#include +#include #include @@ -351,7 +353,7 @@ MozDownload::OnStateChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest, #ifdef HAVE_GECKO_1_9 return NS_OK; #else - GnomeVFSMimeApplication *helperApp; + GDesktopAppInfo *helperApp; NS_ENSURE_TRUE (mMIMEInfo, NS_ERROR_FAILURE); nsString description; @@ -371,16 +373,22 @@ MozDownload::OnStateChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest, char *end; guint32 user_time = strtoul (str[1], &end, 0); - helperApp = gnome_vfs_mime_application_new_from_desktop_id (str[2]); + helperApp = g_desktop_app_info_new (str[2]); if (!helperApp) return NS_ERROR_FAILURE; nsCString aDest; rv = mDestination->GetSpec (aDest); NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); + + GFile* file; + GList* list = NULL; - ephy_file_launch_application (helperApp, destSpec.get (), user_time); + file = g_file_new_for_uri (destSpec.get ()); + list = g_list_append (list, file); + ephy_file_launch_application (G_APP_INFO (helperApp), list, user_time, NULL); - gnome_vfs_mime_application_free (helperApp); + g_list_free (list); + g_object_unref (file); g_strfreev (str); } else if (g_str_has_prefix (cDesc.get(), "gnome-browse-to-file:")) diff --git a/embed/mozilla/MozDownload.h b/embed/mozilla/MozDownload.h index 27fef41c7..411230bdb 100644 --- a/embed/mozilla/MozDownload.h +++ b/embed/mozilla/MozDownload.h @@ -42,8 +42,6 @@ #ifndef MozDownload_h__ #define MozDownload_h__ -#include - #include #include #include diff --git a/embed/mozilla/mozilla-embed-single.cpp b/embed/mozilla/mozilla-embed-single.cpp index 1d07ab548..05f081fac 100644 --- a/embed/mozilla/mozilla-embed-single.cpp +++ b/embed/mozilla/mozilla-embed-single.cpp @@ -29,7 +29,7 @@ #include #include -#include +#include #include @@ -79,10 +79,10 @@ #include "ephy-debug.h" #include "ephy-embed-prefs.h" #include "ephy-embed-shell.h" -#include "ephy-file-helpers.h" #include "ephy-langs.h" #include "ephy-password-manager.h" #include "ephy-permission-manager.h" +#include "ephy-string.h" #include "mozilla-embed.h" #include "mozilla-notifiers.h" #include "mozilla-x509-cert.h" @@ -114,7 +114,7 @@ struct MozillaEmbedSinglePrivate char *user_css_file; guint user_css_enabled_notifier_id; - EphyFileMonitor *user_css_file_monitor; + GFileMonitor *user_css_file_monitor; guint user_css_enabled : 1; guint online : 1; @@ -263,7 +263,8 @@ mozilla_init_plugin_add_unique_path (GList *list, if (path == NULL) return list; - canon = gnome_vfs_make_path_name_canonical (path); + canon = ephy_string_canonicalize_pathname (path); + for (l = list; l != NULL; l = l->next) { if (g_str_equal (list->data, canon) != FALSE) { /* The path is already in the list */ @@ -470,14 +471,15 @@ user_css_unregister (MozillaEmbedSingle *single) } static void -user_css_file_monitor_func (EphyFileMonitor *, - const char *, - GnomeVFSMonitorEventType event_type, - MozillaEmbedSingle *single) +user_css_file_monitor_changed_cb (GFileMonitor *file_monitor, + GFile *file, + GFile *other_file, + gint event_type, + MozillaEmbedSingle *single) { LOG ("Reregistering the user style sheet"); - if (event_type == GNOME_VFS_MONITOR_EVENT_DELETED) + if (event_type == G_FILE_MONITOR_EVENT_DELETED) { user_css_unregister (single); } @@ -505,27 +507,28 @@ user_css_enabled_notify (GConfClient *client, if (enabled) { - char *uri; + GFile *file; user_css_register (single); - uri = gnome_vfs_get_uri_from_local_path (priv->user_css_file); + file = g_file_new_for_path (priv->user_css_file); g_assert (priv->user_css_file_monitor == NULL); priv->user_css_file_monitor = - ephy_file_monitor_add (uri, - GNOME_VFS_MONITOR_FILE, - USER_CSS_LOAD_DELAY, - (EphyFileMonitorFunc) user_css_file_monitor_func, - NULL, - single); - g_free (uri); + g_file_monitor_file (file, + G_FILE_MONITOR_NONE, NULL); + g_file_monitor_set_rate_limit (priv->user_css_file_monitor, + USER_CSS_LOAD_DELAY); + g_signal_connect (priv->user_css_file_monitor, "changed", + G_CALLBACK (user_css_file_monitor_changed_cb), + single); + g_object_unref (file); } else { if (priv->user_css_file_monitor != NULL) { - ephy_file_monitor_cancel (priv->user_css_file_monitor); + g_file_monitor_cancel (priv->user_css_file_monitor); priv->user_css_file_monitor = NULL; } @@ -563,7 +566,7 @@ mozilla_stylesheet_shutdown (MozillaEmbedSingle *single) if (priv->user_css_file_monitor != NULL) { - ephy_file_monitor_cancel (priv->user_css_file_monitor); + g_file_monitor_cancel (priv->user_css_file_monitor); priv->user_css_file_monitor = NULL; } diff --git a/embed/webkit/webkit-embed-single.c b/embed/webkit/webkit-embed-single.c index 36cb29c2c..07c6a9729 100644 --- a/embed/webkit/webkit-embed-single.c +++ b/embed/webkit/webkit-embed-single.c @@ -21,7 +21,6 @@ #include "config.h" #include -#include #include diff --git a/embed/webkit/webkit-embed.c b/embed/webkit/webkit-embed.c index 82cb865ae..b99770693 100644 --- a/embed/webkit/webkit-embed.c +++ b/embed/webkit/webkit-embed.c @@ -27,8 +27,6 @@ #include "ephy-string.h" #include "ephy-embed-event.h" -#include - #include #include diff --git a/embed/xulrunner/components/ContentHandler.cpp b/embed/xulrunner/components/ContentHandler.cpp index 051f5e077..ef8ca62a8 100644 --- a/embed/xulrunner/components/ContentHandler.cpp +++ b/embed/xulrunner/components/ContentHandler.cpp @@ -25,14 +25,13 @@ #include "config.h" #include +#include #include #include #include #include #include #include -#include -#include #include @@ -254,7 +253,7 @@ NS_METHOD GContentHandler::MIMEConfirmAction () { GtkWidget *dialog, *button, *image; const char *action_label; - const char *mime_description; + char *mime_description; nsCString file_name; nsCOMPtr parentDOMWindow = do_GetInterface (mContext); @@ -264,12 +263,12 @@ NS_METHOD GContentHandler::MIMEConfirmAction () (mAction == CONTENT_ACTION_OPEN_TMP) ? GTK_STOCK_OPEN : STOCK_DOWNLOAD; - mime_description = gnome_vfs_mime_get_description (mMimeType.get()); + mime_description = g_content_type_get_description (mMimeType.get()); if (mime_description == NULL) { /* Translators: The text before the "|" is context to help you decide on * the correct translation. You MUST OMIT it in the translated string. */ - mime_description = Q_("File Type:|Unknown"); + mime_description = g_strdup (Q_("File Type:|Unknown")); } /* We have one tiny, minor issue, the filename can be empty (""), @@ -327,6 +326,8 @@ NS_METHOD GContentHandler::MIMEConfirmAction () mime_description, file_name.get()); } + g_free (mime_description); + button = gtk_button_new_with_label (_("_Save As...")); image = gtk_image_new_from_stock (GTK_STOCK_SAVE_AS, GTK_ICON_SIZE_BUTTON); gtk_button_set_image (GTK_BUTTON (button), image); @@ -367,7 +368,7 @@ NS_METHOD GContentHandler::MIMEInitiateAction (void) auto_downloads = eel_gconf_get_boolean (CONF_AUTO_DOWNLOADS); - mHelperApp = gnome_vfs_mime_get_default_application (mMimeType.get()); + mHelperApp = g_app_info_get_default_for_type (mMimeType.get(), TRUE); mPermission = ephy_file_check_mime (mMimeType.get()); /* HACK! Check that this 'helper application' isn't Epiphany itself, @@ -375,7 +376,7 @@ NS_METHOD GContentHandler::MIMEInitiateAction (void) */ if (mHelperApp) { - const char *id = gnome_vfs_mime_application_get_desktop_id (mHelperApp); + const char *id = g_app_info_get_id (mHelperApp); /* FIXME! menu editing can make this check fail!!!! */ if (id && strcmp (id, "epiphany.desktop") == 0) @@ -426,7 +427,7 @@ NS_METHOD GContentHandler::MIMEDoAction (void) g_return_val_if_fail (mHelperApp, NS_ERROR_FAILURE); const char *id; - id = gnome_vfs_mime_application_get_desktop_id (mHelperApp); + id = g_app_info_get_id (mHelperApp); /* The current time is fine here as the user has just clicked * a button (it is used as the time for the application opening) diff --git a/embed/xulrunner/components/ContentHandler.h b/embed/xulrunner/components/ContentHandler.h index 113e29070..52813e0c5 100644 --- a/embed/xulrunner/components/ContentHandler.h +++ b/embed/xulrunner/components/ContentHandler.h @@ -70,7 +70,7 @@ class GContentHandler : public nsIHelperAppLauncherDialog nsCOMPtr mLauncher; nsCOMPtr mContext; - GnomeVFSMimeApplication *mHelperApp; + GAppInfo *mHelperApp; EphyMimePermission mPermission; nsCString mUrl; diff --git a/embed/xulrunner/components/MozDownload.cpp b/embed/xulrunner/components/MozDownload.cpp index d6d28ec59..7b935f5aa 100644 --- a/embed/xulrunner/components/MozDownload.cpp +++ b/embed/xulrunner/components/MozDownload.cpp @@ -47,6 +47,8 @@ #include #include +#include +#include #include @@ -347,7 +349,7 @@ MozDownload::OnStateChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest, // FIXMEchpe fix this! return NS_OK; #else - GnomeVFSMimeApplication *helperApp; + GDesktopAppInfo *helperApp; NS_ENSURE_TRUE (mMIMEInfo, NS_ERROR_FAILURE); nsString description; @@ -367,16 +369,22 @@ MozDownload::OnStateChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest, char *end; guint32 user_time = strtoul (str[1], &end, 0); - helperApp = gnome_vfs_mime_application_new_from_desktop_id (str[2]); + helperApp = g_desktop_app_info_new (str[2]); if (!helperApp) return NS_ERROR_FAILURE; nsCString aDest; rv = mDestination->GetSpec (aDest); NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); + + GFile* file; + GList* list = NULL; - ephy_file_launch_application (helperApp, destSpec.get (), user_time); + file = g_file_new_for_uri (destSpec.get ()); + list = g_list_append (list, file); + ephy_file_launch_application (G_APP_INFO (helperApp), list, user_time, NULL); - gnome_vfs_mime_application_free (helperApp); + g_list_free (list); + g_object_unref (file); g_strfreev (str); } else if (g_str_has_prefix (cDesc.get(), "gnome-browse-to-file:")) diff --git a/embed/xulrunner/embed/EphyHeaderSniffer.cpp b/embed/xulrunner/embed/EphyHeaderSniffer.cpp index 263ec2e36..1429ef02e 100644 --- a/embed/xulrunner/embed/EphyHeaderSniffer.cpp +++ b/embed/xulrunner/embed/EphyHeaderSniffer.cpp @@ -43,7 +43,6 @@ #include "config.h" #include -#include #include @@ -377,7 +376,7 @@ nsresult EphyHeaderSniffer::PerformSave (nsIURI* inOriginalURI) * http://lxr.mozilla.org/seamonkey/source/xpfe/communicator/resources/content/contentAreaUtils.js#763 */ char *filename; - filename = gnome_vfs_unescape_string (default_name, NULL); + filename = g_uri_unescape_string (default_name, NULL); if (!g_utf8_validate (filename, -1, NULL)) { diff --git a/embed/xulrunner/embed/mozilla-embed-single.cpp b/embed/xulrunner/embed/mozilla-embed-single.cpp index ab0373085..437d656bf 100644 --- a/embed/xulrunner/embed/mozilla-embed-single.cpp +++ b/embed/xulrunner/embed/mozilla-embed-single.cpp @@ -29,7 +29,7 @@ #include #include -#include +#include #include @@ -87,6 +87,7 @@ #include "ephy-langs.h" #include "ephy-password-manager.h" #include "ephy-permission-manager.h" +#include "ephy-string.h" #include "mozilla-embed.h" #include "mozilla-notifiers.h" #include "mozilla-x509-cert.h" @@ -267,7 +268,8 @@ mozilla_init_plugin_add_unique_path (GList *list, if (path == NULL) return list; - canon = gnome_vfs_make_path_name_canonical (path); + canon = ephy_string_canonicalize_pathname (path); + for (l = list; l != NULL; l = l->next) { if (g_str_equal (list->data, canon) != FALSE) { /* The path is already in the list */ @@ -464,14 +466,15 @@ user_css_unregister (MozillaEmbedSingle *single) } static void -user_css_file_monitor_func (EphyFileMonitor *, - const char *, - GnomeVFSMonitorEventType event_type, - MozillaEmbedSingle *single) +user_css_file_monitor_changed_cb (GFileMonitor *file_monitor, + GFile *file, + GFile *other_file, + gint event_type, + MozillaEmbedSingle *single) { LOG ("Reregistering the user style sheet"); - if (event_type == GNOME_VFS_MONITOR_EVENT_DELETED) + if (event_type == G_FILE_MONITOR_EVENT_DELETED) { user_css_unregister (single); } @@ -499,27 +502,28 @@ user_css_enabled_notify (GConfClient *client, if (enabled) { - char *uri; + GFile *file; user_css_register (single); - uri = gnome_vfs_get_uri_from_local_path (priv->user_css_file); + file = g_file_new_for_path (priv->user_css_file); g_assert (priv->user_css_file_monitor == NULL); priv->user_css_file_monitor = - ephy_file_monitor_add (uri, - GNOME_VFS_MONITOR_FILE, - USER_CSS_LOAD_DELAY, - (EphyFileMonitorFunc) user_css_file_monitor_func, - NULL, - single); - g_free (uri); + g_file_monitor_file (file, + G_FILE_MONITOR_NONE, NULL); + g_file_monitor_set_rate_limit (priv->user_css_file_monitor, + USER_CSS_LOAD_DELAY); + g_signal_connect (priv->user_css_file_monitor, "changed", + G_CALLBACK (user_css_file_monitor_changed_cb), + single); + g_object_unref (file); } else { if (priv->user_css_file_monitor != NULL) { - ephy_file_monitor_cancel (priv->user_css_file_monitor); + g_file_monitor_cancel (priv->user_css_file_monitor); priv->user_css_file_monitor = NULL; } diff --git a/lib/Makefile.am b/lib/Makefile.am index 5c3236bb6..b576d0398 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -77,6 +77,7 @@ nodist_libephymisc_la_SOURCES = \ libephymisc_la_CPPFLAGS = \ -I$(top_builddir)/lib \ + -I$(top_builddir)/lib/egg \ -DSHARE_DIR=\"$(pkgdatadir)\" \ -DEXTENSIONS_DIR=\""$(libdir)/epiphany/$(EPIPHANY_MAJOR)/extensions"\" \ $(AM_CPPFLAGS) diff --git a/lib/egg/Makefile.am b/lib/egg/Makefile.am index ba0586033..206aa0184 100644 --- a/lib/egg/Makefile.am +++ b/lib/egg/Makefile.am @@ -2,13 +2,15 @@ EGGSOURCES = \ eggtreemultidnd.c \ egg-editable-toolbar.c \ egg-toolbars-model.c \ - egg-toolbar-editor.c + egg-toolbar-editor.c \ + eel-app-launch-context.c EGGHEADERS = \ eggtreemultidnd.h \ egg-editable-toolbar.h \ egg-toolbars-model.h \ - egg-toolbar-editor.h + egg-toolbar-editor.h \ + eel-app-launch-context.h noinst_HEADERS = \ $(EGGHEADERS) \ diff --git a/lib/ephy-file-chooser.c b/lib/ephy-file-chooser.c index 0bdc52f48..9b3fa7d38 100644 --- a/lib/ephy-file-chooser.c +++ b/lib/ephy-file-chooser.c @@ -28,10 +28,10 @@ #include "ephy-gui.h" #include "ephy-debug.h" #include "ephy-stock-icons.h" +#include "ephy-string.h" #include #include -#include #include #define EPHY_FILE_CHOOSER_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_FILE_CHOOSER, EphyFileChooserPrivate)) @@ -175,12 +175,14 @@ ephy_file_chooser_set_persist_key (EphyFileChooser *dialog, const char *key) dir = eel_gconf_get_string (key); if (dir != NULL) { + /* FIXME: Maybe we will find a better way to do this when the + * gio-filechooser will be in GTK+ */ converted = g_filename_from_utf8 (dir, -1, NULL, NULL, NULL); if (converted != NULL) { - expanded = gnome_vfs_expand_initial_tilde (converted); + expanded = ephy_string_expand_initial_tilde (converted); gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), expanded); diff --git a/lib/ephy-file-helpers.c b/lib/ephy-file-helpers.c index 8fb7b4970..65b74db8b 100644 --- a/lib/ephy-file-helpers.c +++ b/lib/ephy-file-helpers.c @@ -27,26 +27,22 @@ #include "ephy-prefs.h" #include "eel-gconf-extensions.h" +#include "eel-app-launch-context.h" #include "ephy-debug.h" +#include "ephy-string.h" #include #include +#include +#include #include -#include -#include -#include -#include -#include #include /* bug http://bugzilla.gnome.org/show_bug.cgi?id=156687 */ #undef GNOME_DISABLE_DEPRECATED #include -#define SN_API_NOT_YET_FROZEN -#include #include -#include #include #include @@ -162,7 +158,7 @@ ephy_file_get_downloads_dir (void) g_return_val_if_fail (download_dir != NULL, NULL); - expanded = gnome_vfs_expand_initial_tilde (download_dir); + expanded = ephy_string_expand_initial_tilde (download_dir); g_free (download_dir); return expanded; @@ -433,35 +429,46 @@ ephy_file_find (const char *path, } gboolean -ephy_file_switch_temp_file (const char *filename, - const char *filename_temp) +ephy_file_switch_temp_file (GFile *file, + GFile *file_temp) { - char *old_file; + char *file_path, *file_temp_path; + char *old_file_path; gboolean old_exist; gboolean retval = TRUE; + GFile *old_file; - old_file = g_strconcat (filename, ".old", NULL); + file_path = g_file_get_path (file); + file_temp_path = g_file_get_path (file_temp); + old_file_path = g_strconcat (file_path, ".old", NULL); - old_exist = g_file_test (filename, G_FILE_TEST_EXISTS); + old_file = g_file_new_for_path (old_file_path); + old_exist = g_file_test (file_path, G_FILE_TEST_EXISTS); if (old_exist) { - if (rename (filename, old_file) < 0) + if (g_file_move (file, old_file, + G_FILE_COPY_OVERWRITE, + NULL, NULL, NULL, NULL) == FALSE) { - g_warning ("Failed to rename %s to %s", filename, old_file); + g_warning ("Failed to rename %s to %s", file_path, old_file_path); retval = FALSE; goto failed; } } - if (rename (filename_temp, filename) < 0) + if (g_file_move (file_temp, file, + G_FILE_COPY_OVERWRITE, + NULL, NULL, NULL, NULL) == FALSE) { - g_warning ("Failed to rename %s to %s", filename_temp, filename); + g_warning ("Failed to rename %s to %s", file_temp_path, file_path); - if (rename (old_file, filename) < 0) + if (g_file_move (old_file, file, + G_FILE_COPY_OVERWRITE, + NULL, NULL, NULL, NULL) == FALSE) { g_warning ("Failed to restore %s from %s", - filename, filename_temp); + file_path, file_temp_path); } retval = FALSE; goto failed; @@ -469,20 +476,24 @@ ephy_file_switch_temp_file (const char *filename, if (old_exist) { - if (unlink (old_file) < 0) + if (g_file_delete (old_file, + NULL, NULL) == FALSE) { - g_warning ("Failed to delete old file %s", old_file); + g_warning ("Failed to delete old file %s", old_file_path); } } failed: - g_free (old_file); + g_free (old_file_path); + g_free (file_path); + g_free (file_temp_path); + g_object_unref (old_file); return retval; } void -ephy_file_delete_on_exit (const char *path) +ephy_file_delete_on_exit (GFile *file) { /* does nothing now */ } @@ -583,441 +594,110 @@ ephy_file_check_mime (const char *mime_type) return permission; } -/* Copied from nautilus-program-choosing.c */ - -extern char **environ; - -/* Cut and paste from gdkspawn-x11.c */ -static gchar ** -my_gdk_spawn_make_environment_for_screen (GdkScreen *screen, - gchar **envp) -{ - gchar **retval = NULL; - gchar *display_name; - gint i, j = 0, env_len; - - g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL); - - if (envp == NULL) - envp = environ; - - env_len = g_strv_length (envp); - retval = g_new (char *, env_len + 3); - - display_name = gdk_screen_make_display_name (screen); - - for (i = 0; envp[i] != NULL; i++) - if (!g_str_has_prefix (envp[i], "DISPLAY=") && - !g_str_has_prefix (envp[i], EPHY_UUID_ENVVAR "=")) - retval[j++] = g_strdup (envp[i]); - - retval[j++] = g_strconcat ("DISPLAY=", display_name, NULL); - retval[j++] = g_strdup (EPHY_UUID_ENVSTRING); - retval[j] = NULL; - - g_free (display_name); - - return retval; -} - -static void -sn_error_trap_push (SnDisplay *display, - Display *xdisplay) -{ - gdk_error_trap_push (); -} - -static void -sn_error_trap_pop (SnDisplay *display, - Display *xdisplay) -{ - gdk_error_trap_pop (); -} - -static char ** -make_spawn_environment_for_sn_context (SnLauncherContext *sn_context, - char **envp) -{ - char **retval; - int i, j, len; - - retval = NULL; - - if (envp == NULL) { - envp = environ; - } - - len = g_strv_length (envp); - retval = g_new (char *, len + 3); - - for (i = 0, j = 0; envp[i] != NULL; i++) { - if (!g_str_has_prefix (envp[i], "DESKTOP_STARTUP_ID=") && - !g_str_has_prefix (envp[i], EPHY_UUID_ENVVAR "=")) { - retval[j++] = g_strdup (envp[i]); - } - } - - retval[j++] = g_strdup_printf ("DESKTOP_STARTUP_ID=%s", - sn_launcher_context_get_startup_id (sn_context)); - retval[j++] = g_strdup (EPHY_UUID_ENVSTRING); - retval[j] = NULL; - - return retval; -} - -/* This should be fairly long, as it's confusing to users if a startup - * ends when it shouldn't (it appears that the startup failed, and - * they have to relaunch the app). Also the timeout only matters when - * there are bugs and apps don't end their own startup sequence. - * - * This timeout is a "last resort" timeout that ignores whether the - * startup sequence has shown activity or not. Metacity and the - * tasklist have smarter, and correspondingly able-to-be-shorter - * timeouts. The reason our timeout is dumb is that we don't monitor - * the sequence (don't use an SnMonitorContext) - */ -#define STARTUP_TIMEOUT_LENGTH (30 /* seconds */ * 1000) - -typedef struct -{ - GdkScreen *screen; - GSList *contexts; - guint timeout_id; -} StartupTimeoutData; - -static void -free_startup_timeout (void *data) -{ - StartupTimeoutData *std; - - std = data; - - g_slist_foreach (std->contexts, - (GFunc) sn_launcher_context_unref, - NULL); - g_slist_free (std->contexts); - - if (std->timeout_id != 0) { - g_source_remove (std->timeout_id); - std->timeout_id = 0; - } - - g_free (std); -} - -static gboolean -startup_timeout (void *data) -{ - StartupTimeoutData *std; - GSList *tmp; - GTimeVal now; - int min_timeout; - - std = data; - - min_timeout = STARTUP_TIMEOUT_LENGTH; - - g_get_current_time (&now); - - tmp = std->contexts; - while (tmp != NULL) { - SnLauncherContext *sn_context; - GSList *next; - long tv_sec, tv_usec; - double elapsed; - - sn_context = tmp->data; - next = tmp->next; - - sn_launcher_context_get_last_active_time (sn_context, - &tv_sec, &tv_usec); - - elapsed = - ((((double)now.tv_sec - tv_sec) * G_USEC_PER_SEC + - (now.tv_usec - tv_usec))) / 1000.0; - - if (elapsed >= STARTUP_TIMEOUT_LENGTH) { - std->contexts = g_slist_remove (std->contexts, - sn_context); - sn_launcher_context_complete (sn_context); - sn_launcher_context_unref (sn_context); - } else { - min_timeout = MIN (min_timeout, (STARTUP_TIMEOUT_LENGTH - elapsed)); - } - - tmp = next; - } - - if (std->contexts == NULL) { - std->timeout_id = 0; - } else { - std->timeout_id = g_timeout_add (min_timeout, - startup_timeout, - std); - } - - /* always remove this one, but we may have reinstalled another one. */ - return FALSE; -} - -static void -add_startup_timeout (GdkScreen *screen, - SnLauncherContext *sn_context) -{ - StartupTimeoutData *data; - - data = g_object_get_data (G_OBJECT (screen), "nautilus-startup-data"); - if (data == NULL) { - data = g_new (StartupTimeoutData, 1); - data->screen = screen; - data->contexts = NULL; - data->timeout_id = 0; - - g_object_set_data_full (G_OBJECT (screen), "nautilus-startup-data", - data, free_startup_timeout); - } - - sn_launcher_context_ref (sn_context); - data->contexts = g_slist_prepend (data->contexts, sn_context); - - if (data->timeout_id == 0) { - data->timeout_id = g_timeout_add (STARTUP_TIMEOUT_LENGTH, - startup_timeout, - data); - } -} - gboolean -ephy_file_launch_application (GnomeVFSMimeApplication *application, - const char *parameter, - guint32 user_time) +ephy_file_launch_application (GAppInfo *app, + GList *files, + guint32 user_time, + GtkWidget *widget) { - GdkScreen *screen; - GList *uris = NULL; - char *uri; - char **envp; - GnomeVFSResult result; - SnLauncherContext *sn_context; - SnDisplay *sn_display; - - g_return_val_if_fail (application != NULL, FALSE); - g_return_val_if_fail (parameter != NULL, FALSE); - - uri = gnome_vfs_make_uri_canonical (parameter); - if (uri == NULL) return FALSE; - - uris = g_list_prepend (NULL, uri); - - /* FIXME multihead! */ - screen = gdk_screen_get_default (); - envp = my_gdk_spawn_make_environment_for_screen (screen, NULL); - - sn_display = sn_display_new (gdk_display, - sn_error_trap_push, - sn_error_trap_pop); - + GAppLaunchContext *context; + GdkDisplay *display; + GdkScreen *screen; - /* Only initiate notification if application supports it. */ - if (gnome_vfs_mime_application_supports_startup_notification (application)) + context = G_APP_LAUNCH_CONTEXT (eel_app_launch_context_new ()); + if (widget) { - char *name; - - sn_context = sn_launcher_context_new (sn_display, - screen ? gdk_screen_get_number (screen) : - DefaultScreen (gdk_display)); - - name = g_filename_display_basename (uri); - if (name != NULL) { - char *description; - - sn_launcher_context_set_name (sn_context, name); - - /* FIXME: i18n after string freeze! */ - description = g_strdup_printf ("Opening %s", name); - - sn_launcher_context_set_description (sn_context, description); - - g_free (name); - g_free (description); - } - - if (!sn_launcher_context_get_initiated (sn_context)) { - const char *binary_name; - char **old_envp; - - binary_name = gnome_vfs_mime_application_get_binary_name (application); - - sn_launcher_context_set_binary_name (sn_context, - binary_name); - - sn_launcher_context_initiate (sn_context, - g_get_prgname () ? g_get_prgname () : "unknown", - binary_name, - (Time) user_time); - - old_envp = envp; - envp = make_spawn_environment_for_sn_context (sn_context, envp); - g_strfreev (old_envp); - } - } else { - sn_context = NULL; - } - - result = gnome_vfs_mime_application_launch_with_env (application, uris, envp); - - if (sn_context != NULL) { - if (result != GNOME_VFS_OK) { - sn_launcher_context_complete (sn_context); /* end sequence */ - } else { - add_startup_timeout (screen ? screen : - gdk_display_get_default_screen (gdk_display_get_default ()), - sn_context); - } - sn_launcher_context_unref (sn_context); + display = gtk_widget_get_display (widget); + screen = gtk_widget_get_screen (widget); } - - sn_display_unref (sn_display); - - g_strfreev (envp); - g_list_foreach (uris, (GFunc) g_free,NULL); - g_list_free (uris); - - if (result != GNOME_VFS_OK) + else { - g_warning ("Cannot launch application '%s'\n", - gnome_vfs_mime_application_get_name (application)); + display = gdk_display_get_default (); + screen = gdk_screen_get_default (); } - - return result == GNOME_VFS_OK; -} - -/* End cut-paste-adapt from nautilus */ - -static int -launch_desktop_item (const char *desktop_file, - const char *parameter, - guint32 user_time, - GError **error) -{ - GnomeDesktopItem *item = NULL; - GdkScreen *screen; - GList *uris = NULL; - char *canonical; - int ret = -1; - char **envp; - /* FIXME multihead! */ - screen = gdk_screen_get_default (); - envp = my_gdk_spawn_make_environment_for_screen (screen, NULL); - - item = gnome_desktop_item_new_from_file (desktop_file, 0, NULL); - if (item == NULL) return FALSE; - - if (parameter != NULL) - { - canonical = gnome_vfs_make_uri_canonical (parameter); - uris = g_list_append (uris, canonical); - } - - gnome_desktop_item_set_launch_time (item, user_time); - ret = gnome_desktop_item_launch_with_env (item, uris, 0, envp, error); - - g_list_foreach (uris, (GFunc) g_free, NULL); - g_list_free (uris); - g_strfreev (envp); - gnome_desktop_item_unref (item); - - return ret; + eel_app_launch_context_set_display (EEL_APP_LAUNCH_CONTEXT (context), + display); + eel_app_launch_context_set_screen (EEL_APP_LAUNCH_CONTEXT (context), + screen); + eel_app_launch_context_set_timestamp (EEL_APP_LAUNCH_CONTEXT (context), + user_time); + + return g_app_info_launch (app, files, context, NULL); } gboolean ephy_file_launch_desktop_file (const char *filename, const char *parameter, - guint32 user_time) + guint32 user_time, + GtkWidget *widget) { - GError *error = NULL; - const char * const *dirs; - char *path = NULL; - int i, ret = -1; - - dirs = g_get_system_data_dirs (); - if (dirs == NULL) return FALSE; - - for (i = 0; dirs[i] != NULL; i++) - { - path = g_build_filename (dirs[i], "applications", filename, NULL); - - if (g_file_test (path, G_FILE_TEST_IS_REGULAR)) break; - - g_free (path); - path = NULL; - } - - if (path != NULL) - { - ret = launch_desktop_item (path, parameter, user_time, &error); - - if (ret == -1 || error != NULL) - { - g_warning ("Cannot launch desktop item '%s': %s\n", - path, error ? error->message : "(unknown error)"); - g_clear_error (&error); - } - - g_free (path); - } + GDesktopAppInfo *app; + GFile *file; + GList *list = NULL; + gboolean ret; - return ret >= 0; + app = g_desktop_app_info_new (filename); + file = g_file_new_for_path (parameter); + list = g_list_append (list, file); + + ret = ephy_file_launch_application (G_APP_INFO (app), list, user_time, widget); + g_list_free (list); + g_object_unref (file); + return ret; } gboolean ephy_file_launch_handler (const char *mime_type, - const char *address, + GFile *file, guint32 user_time) { - GnomeVFSMimeApplication *app = NULL; - GnomeVFSFileInfo *info = NULL; - char *canonical; + GAppInfo *app = NULL; gboolean ret = FALSE; - g_return_val_if_fail (address != NULL, FALSE); - - canonical = gnome_vfs_make_uri_canonical (address); - if (canonical == NULL) return FALSE; + g_return_val_if_fail (file != NULL, FALSE); if (mime_type != NULL) { - app = gnome_vfs_mime_get_default_application (mime_type); + app = g_app_info_get_default_for_type (mime_type, + FALSE); } else { + GFileInfo *file_info; + char *type; + /* Sniff mime type and check if it's safe to open */ - info = gnome_vfs_file_info_new (); - if (gnome_vfs_get_file_info (canonical, info, - GNOME_VFS_FILE_INFO_GET_MIME_TYPE | - GNOME_VFS_FILE_INFO_FORCE_SLOW_MIME_TYPE) == GNOME_VFS_OK && - (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE) && - info->mime_type != NULL && - info->mime_type[0] != '\0' && - ephy_file_check_mime (info->mime_type) == EPHY_MIME_PERMISSION_SAFE) + file_info = g_file_query_info (file, + G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, + 0, NULL, NULL); + if (file_info == NULL) { + return FALSE; + } + type = g_strdup (g_file_info_get_content_type (file_info)); + + g_object_unref (file_info); + + if (type != NULL && type[0] != '\0' && + ephy_file_check_mime (type) == EPHY_MIME_PERMISSION_SAFE) { /* FIXME rename tmp file to right extension ? */ - app = gnome_vfs_mime_get_default_application (info->mime_type); + app = g_app_info_get_default_for_type (type, FALSE); } - gnome_vfs_file_info_unref (info); + g_free (type); } if (app != NULL) { - ret = ephy_file_launch_application (app, address, user_time); - - gnome_vfs_mime_application_free (app); + GList *list = NULL; + + list = g_list_append (list, file); + ret = ephy_file_launch_application (app, list, user_time, NULL); + g_list_free (list); } else ret = FALSE; - g_free (canonical); - return ret; } @@ -1025,197 +705,34 @@ gboolean ephy_file_browse_to (const char *parameter, guint32 user_time) { - GnomeVFSURI *uri, *parent_uri, *desktop; + GFile *file, *parent, *desktop; char *desktop_dir; gboolean ret; - uri = gnome_vfs_uri_new (parameter); - parent_uri = gnome_vfs_uri_get_parent (uri); - + file = g_file_new_for_path (parameter); desktop_dir = ephy_file_desktop_dir (); - desktop = gnome_vfs_uri_new (desktop_dir); + desktop = g_file_new_for_path (desktop_dir); /* Don't do anything if destination is the desktop */ - if (gnome_vfs_uri_equal (desktop, parent_uri)) + if (g_file_contains_file (desktop, file)) { ret = FALSE; } else { + parent = g_file_get_parent (file); /* TODO find a way to make nautilus scroll to the actual file */ ret = ephy_file_launch_handler ("x-directory/normal", - gnome_vfs_uri_get_path (parent_uri), + parent, user_time); } g_free (desktop_dir); - gnome_vfs_uri_unref (uri); - gnome_vfs_uri_unref (parent_uri); - gnome_vfs_uri_unref (desktop); + g_object_unref (file); return ret; } -struct _EphyFileMonitor -{ - GnomeVFSMonitorHandle *handle; - EphyFileMonitorFunc callback; - EphyFileMonitorDelayFunc delay_func; - gpointer user_data; - char *uri; - guint delay; - guint timeout_id; - guint ticks; - GnomeVFSMonitorEventType type; -}; - -static gboolean -ephy_file_monitor_timeout_cb (EphyFileMonitor *monitor) -{ - if (monitor->ticks > 0) - { - monitor->ticks--; - - /* Run again */ - return TRUE; - } - - if (monitor->delay_func && - monitor->delay_func (monitor, monitor->user_data)) - { - monitor->ticks = DELAY_MAX_TICKS / 2; - - /* Run again */ - return TRUE; - } - - monitor->timeout_id = 0; - - monitor->callback (monitor, monitor->uri, monitor->type, monitor->user_data); - - /* don't run again */ - return FALSE; -} - -static void -ephy_file_monitor_cb (GnomeVFSMonitorHandle *handle, - const char *monitor_uri, - const char *info_uri, - GnomeVFSMonitorEventType event_type, - EphyFileMonitor *monitor) -{ - LOG ("File '%s' has changed, scheduling reload", monitor_uri); - - switch (event_type) - { - case GNOME_VFS_MONITOR_EVENT_CHANGED: - monitor->ticks = INITIAL_TICKS; - /* fall-through */ - case GNOME_VFS_MONITOR_EVENT_CREATED: - /* We make a lot of assumptions here, but basically we know - * that we just have to reload, by construction. - * Delay the reload a little bit so we don't endlessly - * reload while a file is written. - */ - monitor->type = event_type; - - if (monitor->ticks == 0) - { - monitor->ticks = 1; - } - else - { - /* Exponential backoff */ - monitor->ticks = MIN (monitor->ticks * 2, - DELAY_MAX_TICKS); - } - - if (monitor->timeout_id == 0) - { - monitor->timeout_id = - g_timeout_add (monitor->delay, - (GSourceFunc) ephy_file_monitor_timeout_cb, - monitor); - } - - break; - - case GNOME_VFS_MONITOR_EVENT_DELETED: - if (monitor->timeout_id != 0) - { - g_source_remove (monitor->timeout_id); - monitor->timeout_id = 0; - } - monitor->ticks = 0; - - monitor->callback (monitor, monitor->uri, event_type, monitor->user_data); - break; - case GNOME_VFS_MONITOR_EVENT_STARTEXECUTING: - case GNOME_VFS_MONITOR_EVENT_STOPEXECUTING: - case GNOME_VFS_MONITOR_EVENT_METADATA_CHANGED: - default: - break; - } -} - -EphyFileMonitor * -ephy_file_monitor_add (const char *uri, - GnomeVFSMonitorType monitor_type, - guint delay, - EphyFileMonitorFunc callback, - EphyFileMonitorDelayFunc delay_func, - gpointer user_data) -{ - EphyFileMonitor *monitor; - - g_return_val_if_fail (uri != NULL, NULL); - g_return_val_if_fail (callback, NULL); - - monitor = g_new (EphyFileMonitor, 1); - monitor->callback = callback; - monitor->delay_func = delay_func; - monitor->user_data = user_data; - monitor->uri = g_strdup (uri); - monitor->delay = delay; - monitor->ticks = 0; - monitor->timeout_id = 0; - - if (gnome_vfs_monitor_add (&monitor->handle, uri, monitor_type, - (GnomeVFSMonitorCallback) ephy_file_monitor_cb, - monitor) != GNOME_VFS_OK) - { - LOG ("Failed to add file monitor for '%s'", uri); - - g_free (monitor->uri); - g_free (monitor); - return NULL; - } - - LOG ("File monitor for '%s' added", uri); - - return monitor; -} - -void -ephy_file_monitor_cancel (EphyFileMonitor *monitor) -{ - g_return_if_fail (monitor != NULL); - g_return_if_fail (monitor->handle != NULL); - g_return_if_fail (monitor->uri != NULL); - - LOG ("Cancelling file monitor for '%s'", monitor->uri); - - gnome_vfs_monitor_cancel (monitor->handle); - - if (monitor->timeout_id != 0) - { - g_source_remove (monitor->timeout_id); - } - - g_free (monitor->uri); - g_free (monitor); -} - /** * ephy_file_delete_directory: * @path: the path to remove @@ -1226,18 +743,14 @@ ephy_file_monitor_cancel (EphyFileMonitor *monitor) void ephy_file_delete_directory (const char *path) { - GList *list; - GnomeVFSResult ret; - - list = g_list_append (NULL, gnome_vfs_uri_new (path)); + GFile *file; + gboolean ret; - ret = gnome_vfs_xfer_delete_list (list, GNOME_VFS_XFER_ERROR_MODE_ABORT, - GNOME_VFS_XFER_EMPTY_DIRECTORIES, - NULL, NULL); + file = g_file_new_for_path (path); - gnome_vfs_uri_list_free (list); + ret = g_file_delete (file, NULL, NULL); - if (ret == GNOME_VFS_OK) + if (ret == TRUE) { LOG ("Deleted the profile dir '%s'", path); } @@ -1245,4 +758,5 @@ ephy_file_delete_directory (const char *path) { LOG ("Couldn't delete profile dir '%s'", path); } + g_object_unref (file); } diff --git a/lib/ephy-file-helpers.h b/lib/ephy-file-helpers.h index f7aa71281..408b975cb 100644 --- a/lib/ephy-file-helpers.h +++ b/lib/ephy-file-helpers.h @@ -24,8 +24,8 @@ #define EPHY_FILE_HELPERS_H #include -#include -#include +#include +#include extern GQuark ephy_file_helpers_error_quark; #define EPHY_FILE_HELPERS_ERROR_QUARK (ephy_file_helpers_error_quark) @@ -39,10 +39,6 @@ typedef enum EPHY_MIME_PERMISSION_UNKNOWN = 3 } EphyMimePermission; -typedef struct _EphyFileMonitor EphyFileMonitor; -typedef void (* EphyFileMonitorFunc) (EphyFileMonitor*, const char*, GnomeVFSMonitorEventType, gpointer); -typedef gboolean (* EphyFileMonitorDelayFunc) (EphyFileMonitor*, gpointer); - gboolean ephy_file_helpers_init (const char *profile_dir, gboolean private_profile, gboolean keep_temp_dir, @@ -72,10 +68,10 @@ GSList *ephy_file_find (const char *path, const char *fname, gint maxdepth); -gboolean ephy_file_switch_temp_file (const char *filename, - const char *filename_temp); +gboolean ephy_file_switch_temp_file (GFile *file, + GFile *file_temp); -void ephy_file_delete_on_exit (const char *path); +void ephy_file_delete_on_exit (GFile *file); void ephy_file_add_recent_item (const char *uri, const char *mime_type); @@ -84,28 +80,21 @@ EphyMimePermission ephy_file_check_mime (const char *mime_type); gboolean ephy_file_launch_desktop_file (const char *filename, const char *parameter, - guint32 user_time); + guint32 user_time, + GtkWidget *widget); -gboolean ephy_file_launch_application (GnomeVFSMimeApplication *application, - const char *parameter, - guint32 user_time); +gboolean ephy_file_launch_application (GAppInfo *app, + GList *files, + guint32 user_time, + GtkWidget *parent); gboolean ephy_file_launch_handler (const char *mime_type, - const char *address, + GFile *file, guint32 user_time); gboolean ephy_file_browse_to (const char *parameter, guint32 user_time); -EphyFileMonitor *ephy_file_monitor_add (const char *uri, - GnomeVFSMonitorType monitor_type, - guint delay, - EphyFileMonitorFunc callback, - EphyFileMonitorDelayFunc delay_func, - gpointer user_data); - -void ephy_file_monitor_cancel (EphyFileMonitor *monitor); - void ephy_file_delete_directory (const char *path); G_END_DECLS diff --git a/lib/ephy-node-db.c b/lib/ephy-node-db.c index ebc3e20b5..15a4593ab 100644 --- a/lib/ephy-node-db.c +++ b/lib/ephy-node-db.c @@ -482,30 +482,35 @@ ephy_node_db_write_to_xml_safe (EphyNodeDb *db, { va_list argptr; int ret = 0; - char *tmp_file; + GFile *tmp_file, *file; + char *tmp_file_path; - tmp_file = g_strconcat ((const gchar *)filename, ".tmp", NULL); + tmp_file_path = g_strconcat ((const gchar *) filename, ".tmp", NULL); + tmp_file = g_file_new_for_path (tmp_file_path); + file = g_file_new_for_path ((const char *) filename); va_start (argptr, node); ret = ephy_node_db_write_to_xml_valist - (db, (const xmlChar *)tmp_file, root, version, comment, node, argptr); + (db, (const xmlChar *)tmp_file_path, root, version, comment, node, argptr); va_end (argptr); if (ret < 0) { - g_warning ("Failed to write XML data to %s", tmp_file); + g_warning ("Failed to write XML data to %s", tmp_file_path); goto failed; } - if (ephy_file_switch_temp_file ((const char *)filename, tmp_file) == FALSE) + if (ephy_file_switch_temp_file (file, tmp_file) == FALSE) { ret = -1; } failed: - g_free (tmp_file); + g_free (tmp_file_path); + g_object_unref (file); + g_object_unref (tmp_file); return ret; } diff --git a/lib/ephy-string.c b/lib/ephy-string.c index 391ad9b39..4dc8d8e9a 100644 --- a/lib/ephy-string.c +++ b/lib/ephy-string.c @@ -26,6 +26,8 @@ #include #include #include +#include +#include #define ELLIPSIS "\xe2\x80\xa6" @@ -286,3 +288,241 @@ ephy_string_enum_to_string (GType type, return retval; } + +/* Following code copied from gnome-vfs-private-utils.c */ + +static int +find_next_slash (const char *path, int current_offset) +{ + const char *match; + + g_assert (current_offset <= strlen (path)); + + match = strchr (path + current_offset, G_DIR_SEPARATOR); + return match == NULL ? -1 : match - path; +} + +static int +find_slash_before_offset (const char *path, int to) +{ + int result; + int next_offset; + + result = -1; + next_offset = 0; + for (;;) { + next_offset = find_next_slash (path, next_offset); + if (next_offset < 0 || next_offset >= to) { + break; + } + result = next_offset; + next_offset++; + } + return result; +} + +static void +collapse_slash_runs (char *path, int from_offset) +{ + int i; + /* Collapse multiple `/'s in a row. */ + for (i = from_offset;; i++) { + if (path[i] != G_DIR_SEPARATOR) { + break; + } + } + + if (from_offset < i) { + memmove (path + from_offset, path + i, strlen (path + i) + 1); + i = from_offset + 1; + } +} + +/* Canonicalize path, and return a new path. Do everything in situ. The new + path differs from path in: + + Multiple `/'s are collapsed to a single `/'. + Leading `./'s and trailing `/.'s are removed. + Non-leading `../'s and trailing `..'s are handled by removing + portions of the path. */ +char * +ephy_string_canonicalize_pathname (const char *cpath) +{ + char *path; + int i, marker; + + path = g_strdup (cpath); + + if (path == NULL || strlen (path) == 0) { + return ""; + } + + /* Walk along path looking for things to compact. */ + for (i = 0, marker = 0;;) { + if (!path[i]) + break; + + /* Check for `../', `./' or trailing `.' by itself. */ + if (path[i] == '.') { + /* Handle trailing `.' by itself. */ + if (path[i + 1] == '\0') { + if (i > 1 && path[i - 1] == G_DIR_SEPARATOR) { + /* strip the trailing /. */ + path[i - 1] = '\0'; + } else { + /* convert path "/." to "/" */ + path[i] = '\0'; + } + break; + } + + /* Handle `./'. */ + if (path[i + 1] == G_DIR_SEPARATOR) { + memmove (path + i, path + i + 2, + strlen (path + i + 2) + 1); + if (i == 0) { + /* don't leave leading '/' for paths that started + * as relative (.//foo) + */ + collapse_slash_runs (path, i); + marker = 0; + } + continue; + } + + /* Handle `../' or trailing `..' by itself. + * Remove the previous xxx/ part + */ + if (path[i + 1] == '.' + && (path[i + 2] == G_DIR_SEPARATOR + || path[i + 2] == '\0')) { + + /* ignore ../ at the beginning of a path */ + if (i != 0) { + marker = find_slash_before_offset (path, i - 1); + + /* Either advance past '/' or point to the first character */ + marker ++; + if (path [i + 2] == '\0' && marker > 1) { + /* If we are looking at a /.. at the end of the uri and we + * need to eat the last '/' too. + */ + marker--; + } + g_assert(marker < i); + + if (path[i + 2] == G_DIR_SEPARATOR) { + /* strip the entire ../ string */ + i++; + } + + memmove (path + marker, path + i + 2, + strlen (path + i + 2) + 1); + i = marker; + } else { + i = 2; + if (path[i] == G_DIR_SEPARATOR) { + i++; + } + } + collapse_slash_runs (path, i); + continue; + } + } + + /* advance to the next '/' */ + i = find_next_slash (path, i); + + /* If we didn't find any slashes, then there is nothing left to do. */ + if (i < 0) { + break; + } + + marker = i++; + collapse_slash_runs (path, i); + } + return path; +} + +/* End of copied code */ + +char * +ephy_string_get_host_name (const char *url) +{ + const char *start; + const char *p; + + if (url == NULL || g_str_has_prefix (url, "file://")) return NULL; + + start = strstr (url, "//"); + if (start == NULL || start == '\0') + { + /* Not an URL */ + return NULL; + } + if (strlen (start) > 2) + { + /* Go past the protocol part */ + start = start + 2; + } + else + { + /* Not an URL again */ + return NULL; + } + p = strchr (start, '@'); + if (p != NULL) + { + /* We have a username:password@hostname scheme, skip it. */ + if (strlen (p) > 1) start = ++p; + } + p = strchr (start, ':'); + if (p != NULL) + { + /* hostname:port, skip port */ + return g_strndup (start, (p - start)); + } + p = strchr (start, '/'); + if (p == NULL) + { + /* No more slashes in the url, we assume it's a host name */ + return g_strdup (start); + } + + return g_strndup (start, (p - start)); +} + +char * +ephy_string_expand_initial_tilde (const char *path) +{ + char *slash_after_user_name, *user_name; + struct passwd *passwd_file_entry; + + g_return_val_if_fail (path != NULL, NULL); + + if (path[0] != '~') { + return g_strdup (path); + } + + if (path[1] == '/' || path[1] == '\0') { + return g_strconcat (g_get_home_dir (), &path[1], NULL); + } + + slash_after_user_name = strchr (&path[1], '/'); + if (slash_after_user_name == NULL) { + user_name = g_strdup (&path[1]); + } else { + user_name = g_strndup (&path[1], + slash_after_user_name - &path[1]); + } + passwd_file_entry = getpwnam (user_name); + g_free (user_name); + + if (passwd_file_entry == NULL || passwd_file_entry->pw_dir == NULL) { + return g_strdup (path); + } + + return g_strconcat (passwd_file_entry->pw_dir, + slash_after_user_name, + NULL); +} diff --git a/lib/ephy-string.h b/lib/ephy-string.h index cbf8ec776..de7ebe292 100644 --- a/lib/ephy-string.h +++ b/lib/ephy-string.h @@ -49,6 +49,12 @@ guint ephy_string_enum_from_string (GType type, char *ephy_string_enum_to_string (GType type, guint enum_value); +char *ephy_string_canonicalize_pathname (const char *cpath); + +char *ephy_string_get_host_name (const char *url); + +char *ephy_string_expand_initial_tilde (const char *path); + G_END_DECLS #endif diff --git a/src/bookmarks/Makefile.am b/src/bookmarks/Makefile.am index 1863fc55b..aceaeef13 100644 --- a/src/bookmarks/Makefile.am +++ b/src/bookmarks/Makefile.am @@ -113,6 +113,15 @@ libephybookmarks_la_CFLAGS = \ $(DEPENDENCIES_CFLAGS) \ $(AM_CFLAGS) +libephybookmarks_la_LIBADD = + +if ENABLE_ZEROCONF +libephybookmarks_la_CFLAGS += \ + $(AVAHI_CFLAGS) +libephybookmarks_la_LIBADD += \ + $(AVAHI_LIBS) +endif + CLEANFILES = $(stamp_files) $(BUILT_SOURCES) DISTCLEANFILES = $(stamp_files) $(BUILT_SOURCES) MAINTAINERCLEANFILES = $(stamp_files) $(BUILT_SOURCES) diff --git a/src/bookmarks/ephy-bookmark-action.c b/src/bookmarks/ephy-bookmark-action.c index 2958f0f09..242cd00aa 100644 --- a/src/bookmarks/ephy-bookmark-action.c +++ b/src/bookmarks/ephy-bookmark-action.c @@ -32,6 +32,7 @@ #include "ephy-gui.h" #include "ephy-debug.h" #include "ephy-dnd.h" +#include "ephy-string.h" #include #include @@ -46,7 +47,6 @@ #include #include #include -#include #include @@ -367,16 +367,17 @@ ephy_bookmark_action_activate (EphyBookmarkAction *action, /* The entered search term is empty, and we have a smart bookmark */ if ((text == NULL || text[0] == '\0') && strstr (location, "%s") != NULL) { - GnomeVFSURI *uri = gnome_vfs_uri_new (location); - if (uri != NULL) - { - address = g_strconcat ( - gnome_vfs_uri_get_scheme (uri), - "://", - gnome_vfs_uri_get_host_name (uri), - NULL); - gnome_vfs_uri_unref (uri); - } + char *scheme; + char *host_name; + + scheme = g_uri_get_scheme (location); + host_name = ephy_string_get_host_name (location); + address = g_strconcat (scheme, + "://", + host_name, + NULL); + g_free (scheme); + g_free (host_name); } if (address == NULL) @@ -511,24 +512,28 @@ query_tooltip_cb (GtkWidget *proxy, { if (strstr (location, "%s") != NULL) { - GnomeVFSURI *uri = gnome_vfs_uri_new (location); - if (uri != NULL) + char *scheme; + char *host_name; + + scheme = g_uri_get_scheme (location); + host_name = ephy_string_get_host_name (location); + + if (title[0] == '\0') { - if (title[0] == '\0') - { - text = g_markup_printf_escaped ("%s://%s", - gnome_vfs_uri_get_scheme (uri), - gnome_vfs_uri_get_host_name (uri)); - } - else - { - text = g_markup_printf_escaped ("%s\n%s://%s", - title, - gnome_vfs_uri_get_scheme (uri), - gnome_vfs_uri_get_host_name (uri)); - } - gnome_vfs_uri_unref (uri); + text = g_markup_printf_escaped ("%s://%s", + scheme, + host_name); } + else + { + text = g_markup_printf_escaped ("%s\n%s://%s", + title, + scheme, + host_name); + } + + g_free (scheme); + g_free (host_name); } if (text == NULL) { diff --git a/src/bookmarks/ephy-bookmarks-export.c b/src/bookmarks/ephy-bookmarks-export.c index a2af331a6..c220777fd 100644 --- a/src/bookmarks/ephy-bookmarks-export.c +++ b/src/bookmarks/ephy-bookmarks-export.c @@ -24,6 +24,7 @@ #include "ephy-bookmarks-export.h" #include "ephy-node-common.h" #include "ephy-file-helpers.h" +#include "ephy-string.h" #include "ephy-debug.h" #include @@ -32,8 +33,6 @@ #include #include #include -#include -#include static inline xmlChar * sanitise_string (const xmlChar *string) @@ -118,7 +117,7 @@ write_topics_list (EphyNode *topics, static int write_rdf (EphyBookmarks *bookmarks, - const char *filename, + GFile *file, xmlTextWriterPtr writer) { EphyNode *bmks, *topics, *smart_bmks; @@ -168,7 +167,7 @@ write_rdf (EphyBookmarks *bookmarks, if (ret < 0) goto out; /* FIXME: sanitise file_uri? */ - file_uri = gnome_vfs_get_uri_from_local_path (filename); + file_uri = g_file_get_uri (file); safeString = sanitise_string ((const xmlChar *) file_uri); g_free (file_uri); @@ -229,21 +228,20 @@ write_rdf (EphyBookmarks *bookmarks, smart_url = ephy_node_has_child (smart_bmks, kid); url = ephy_node_get_property_string (kid, EPHY_NODE_BMK_PROP_LOCATION); - if (smart_url) + if (smart_url && url) { - GnomeVFSURI *uri; - - uri = gnome_vfs_uri_new (url); - - if (uri) - { - link = g_strconcat (gnome_vfs_uri_get_scheme (uri), - "://", - gnome_vfs_uri_get_host_name (uri), - NULL); - - gnome_vfs_uri_unref (uri); - } + char *scheme; + char *host_name; + + scheme = g_uri_get_scheme (url); + host_name = ephy_string_get_host_name (url); + link = g_strconcat (scheme, + "://", + host_name, + NULL); + + g_free (scheme); + g_free (host_name); } safeLink = sanitise_string (link ? (const xmlChar *) link : (const xmlChar *) url); @@ -301,21 +299,20 @@ write_rdf (EphyBookmarks *bookmarks, title = ephy_node_get_property_string (kid, EPHY_NODE_BMK_PROP_TITLE); - if (smart_url) + if (smart_url && url) { - GnomeVFSURI *uri; - - uri = gnome_vfs_uri_new (url); - - if (uri) - { - link = g_strconcat (gnome_vfs_uri_get_scheme (uri), - "://", - gnome_vfs_uri_get_host_name (uri), - NULL); - - gnome_vfs_uri_unref (uri); - } + char *scheme; + char *host_name; + + scheme = g_uri_get_scheme (url); + host_name = ephy_string_get_host_name (url); + + link = g_strconcat (scheme, + "://", + host_name, + NULL); + g_free (scheme); + g_free (host_name); } if (link == NULL) @@ -391,20 +388,23 @@ out: void ephy_bookmarks_export_rdf (EphyBookmarks *bookmarks, - const char *filename) + const char *file_path) { xmlTextWriterPtr writer; - char *tmp_file; + GFile *file, *tmp_file; + char *tmp_file_path; int ret; LOG ("Exporting as RDF to %s", filename); START_PROFILER ("Exporting as RDF") - tmp_file = g_strconcat (filename, ".tmp", NULL); + tmp_file_path = g_strconcat (file_path, ".tmp", NULL); + file = g_file_new_for_path (file_path); + tmp_file = g_file_new_for_path (tmp_file_path); /* FIXME: do we want to turn on compression here? */ - writer = xmlNewTextWriterFilename (tmp_file, 0); + writer = xmlNewTextWriterFilename (tmp_file_path, 0); if (writer == NULL) { g_free (tmp_file); @@ -417,20 +417,22 @@ ephy_bookmarks_export_rdf (EphyBookmarks *bookmarks, ret = xmlTextWriterSetIndentString (writer, (xmlChar *) " "); if (ret < 0) goto out; - ret = write_rdf (bookmarks, filename, writer); + ret = write_rdf (bookmarks, file, writer); if (ret < 0) goto out; xmlFreeTextWriter (writer); out: if (ret >= 0) { - if (ephy_file_switch_temp_file (filename, tmp_file) == FALSE) + if (ephy_file_switch_temp_file (file, tmp_file) == FALSE) { ret = -1; } } - g_free (tmp_file); + g_object_unref (file); + g_object_unref (tmp_file); + g_free (tmp_file_path); STOP_PROFILER ("Exporting as RDF") @@ -439,31 +441,33 @@ out: void ephy_bookmarks_export_mozilla (EphyBookmarks *bookmarks, - const char *filename) + const char *filename) { xsltStylesheetPtr cur = NULL; xmlTextWriterPtr writer; xmlDocPtr doc = NULL, res; - char *tmp_file, *template; + char *tmp_file_path, *template; + GFile *tmp_file; int ret = -1; LOG ("Exporting as Mozilla to %s", filename); template = g_build_filename (g_get_tmp_dir (), "export-bookmarks-XXXXXX", NULL); - tmp_file = ephy_file_tmp_filename (template, "rdf"); + tmp_file_path = ephy_file_tmp_filename (template, "rdf"); g_free (template); - if (tmp_file == NULL) return; + if (tmp_file_path == NULL) return; writer = xmlNewTextWriterDoc (&doc, 0); if (writer == NULL || doc == NULL) { - g_free (tmp_file); + g_free (tmp_file_path); return; } - START_PROFILER ("Exporting as Mozilla") - + START_PROFILER ("Exporting as Mozilla"); + + tmp_file = g_file_new_for_path (tmp_file_path); ret = write_rdf (bookmarks, tmp_file, writer); if (ret < 0) goto out; @@ -492,7 +496,7 @@ ephy_bookmarks_export_mozilla (EphyBookmarks *bookmarks, out: xmlFreeTextWriter (writer); xmlFreeDoc (doc); - g_free (tmp_file); + g_free (tmp_file_path); STOP_PROFILER ("Exporting as Mozilla") diff --git a/src/bookmarks/ephy-bookmarks-import.c b/src/bookmarks/ephy-bookmarks-import.c index 56d9d628f..44f5fd63a 100644 --- a/src/bookmarks/ephy-bookmarks-import.c +++ b/src/bookmarks/ephy-bookmarks-import.c @@ -23,10 +23,10 @@ #include "config.h" #include +#include #include #include #include -#include #include @@ -71,14 +71,21 @@ ephy_bookmarks_import (EphyBookmarks *bookmarks, const char *type; char *basename; gboolean success = FALSE; + GFile *file; + GFileInfo *file_info; if (eel_gconf_get_boolean (CONF_LOCKDOWN_DISABLE_BOOKMARK_EDITING)) return FALSE; g_return_val_if_fail (filename != NULL, FALSE); + + file = g_file_new_for_path (filename); + file_info = g_file_query_info (file, + G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, + 0, NULL, NULL); + type = g_file_info_get_content_type (file_info); + g_object_unref (file_info); - type = gnome_vfs_get_file_mime_type (filename, NULL, FALSE); - - LOG ("Importing bookmarks of type %s", type ? type : "(null)"); + g_debug ("Importing bookmarks of type %s", type ? type : "(null)"); if (type != NULL && (strcmp (type, "application/rdf+xml") == 0 || strcmp (type, "text/rdf") == 0)) @@ -92,6 +99,7 @@ ephy_bookmarks_import (EphyBookmarks *bookmarks, success = ephy_bookmarks_import_xbel (bookmarks, filename); } else if ((type != NULL && strcmp (type, "application/x-mozilla-bookmarks") == 0) || + strcmp (type, "text/html") == 0 || strstr (filename, MOZILLA_BOOKMARKS_DIR) != NULL || strstr (filename, FIREFOX_BOOKMARKS_DIR_0) != NULL || strstr (filename, FIREFOX_BOOKMARKS_DIR_1) != NULL || @@ -101,7 +109,7 @@ ephy_bookmarks_import (EphyBookmarks *bookmarks, } else if (type == NULL) { - basename = g_path_get_basename (filename); + basename = g_file_get_basename (file); if (g_str_has_suffix (basename, ".rdf")) { @@ -124,6 +132,8 @@ ephy_bookmarks_import (EphyBookmarks *bookmarks, g_free (basename); } + g_object_unref (file); + return success; } diff --git a/src/bookmarks/ephy-bookmarks.c b/src/bookmarks/ephy-bookmarks.c index 121326874..535ac17f0 100644 --- a/src/bookmarks/ephy-bookmarks.c +++ b/src/bookmarks/ephy-bookmarks.c @@ -44,17 +44,19 @@ #include #include -#include -#include #include #include +#include +#include +#include +#include +#include #define EPHY_BOOKMARKS_XML_ROOT "ephy_bookmarks" #define EPHY_BOOKMARKS_XML_VERSION "1.03" #define BOOKMARKS_SAVE_DELAY 3 /* seconds */ #define MAX_FAVORITES_NUM 10 #define UPDATE_URI_DATA_KEY "updated-uri" -#define SD_RESOLVE_TIMEOUT 0 /* ms; 0 means no timeout */ #define EPHY_BOOKMARKS_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_BOOKMARKS, EphyBookmarksPrivate)) @@ -85,7 +87,8 @@ struct _EphyBookmarksPrivate #ifdef ENABLE_ZEROCONF /* Local sites */ EphyNode *local; - GnomeVFSDNSSDBrowseHandle *browse_handles[G_N_ELEMENTS (zeroconf_protos)]; + GaClient *ga_client; + GaServiceBrowser *browse_handles[G_N_ELEMENTS (zeroconf_protos)]; GHashTable *resolve_handles; #endif }; @@ -782,29 +785,96 @@ backup_file (const char *original_filename, const char *extension) #ifdef ENABLE_ZEROCONF +/* C&P adapted from gnome-vfs-dns-sd.c */ +static GHashTable * +decode_txt_record (AvahiStringList *input_text) +{ + GHashTable *hash; + int i; + int len; + char *key, *value, *end; + char *key_dup, *value_dup; + char *raw_txt; + size_t raw_txt_len; + + raw_txt_len = avahi_string_list_serialize (input_text, NULL, 0); + raw_txt = g_malloc (raw_txt_len); + raw_txt_len = avahi_string_list_serialize (input_text, raw_txt, raw_txt_len); + + if (raw_txt == NULL) + return NULL; + + hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + + i = 0; + while (i < raw_txt_len) { + len = raw_txt[i++]; + + if (i + len > raw_txt_len) { + break; + } + + if (len == 0) { + continue; + } + + key = &raw_txt[i]; + end = &raw_txt[i + len]; + i += len; + + if (*key == '=') { + /* 6.4 - silently ignore keys starting with = */ + continue; + } + + value = memchr (key, '=', len); + if (value) { + key_dup = g_strndup (key, value - key); + value++; /* Skip '=' */ + value_dup = g_strndup (value, end - value); + } else { + key_dup = g_strndup (key, len); + value_dup = NULL; + } + if (!g_hash_table_lookup_extended (hash, + key_dup, + NULL, NULL)) { + g_hash_table_insert (hash, + key_dup, + value_dup); + } else { + g_free (key_dup); + g_free (value_dup); + } + } + + return hash; +} + +/* End of copied code */ + static char * -get_id_for_service (const GnomeVFSDNSSDService *service) +get_id_for_response (const char *type, + const char *domain, + const char *name) { /* FIXME: limit length! */ return g_strdup_printf ("%s\1%s\1%s", - service->type, - service->domain, - service->name); + type, + domain, + name); } static EphyNode * -get_node_for_service (EphyBookmarks *bookmarks, - const GnomeVFSDNSSDService *service) +get_node_for_id (EphyBookmarks *bookmarks, + char *node_id) { EphyBookmarksPrivate *priv = bookmarks->priv; EphyNode *kid, *node = NULL; GPtrArray *children; - char *search_id; const char *id; guint i; - search_id = get_id_for_service (service); - children = ephy_node_get_children (priv->local); for (i = 0; i < children->len; i++) { @@ -813,14 +883,14 @@ get_node_for_service (EphyBookmarks *bookmarks, id = ephy_node_get_property_string (kid, EPHY_NODE_BMK_PROP_SERVICE_ID); - if (g_str_equal (id, search_id)) + if (g_str_equal (id, node_id)) { node = kid; break; } } - g_free (search_id); + g_free (node_id); return node; } @@ -833,21 +903,26 @@ typedef struct } ResolveData; static void -resolve_cb (GnomeVFSDNSSDResolveHandle *handle, - GnomeVFSResult result, - const GnomeVFSDNSSDService *service, - const char *host, - int port, - /* const */ GHashTable *text, - int text_raw_len, - const char *text_raw, - ResolveData *data) +resolver_found_cb (GaServiceResolver *resolver, + int interface, + GaProtocol protocol, + const char *name, + const char *type, + const char *domain, + const char *host_name, + const AvahiAddress *address, + guint16 port, + AvahiStringList *txt, + glong flags, + ResolveData *data) { EphyBookmarks *bookmarks = data->bookmarks; EphyBookmarksPrivate *priv = bookmarks->priv; EphyNode *node = data->node; GValue value = { 0, }; const char *path = NULL; + char host[128]; + GHashTable *text_table; char *url; gboolean was_immutable; guint i; @@ -856,39 +931,38 @@ resolve_cb (GnomeVFSDNSSDResolveHandle *handle, ephy_node_db_set_immutable (priv->db, FALSE); g_hash_table_steal (priv->resolve_handles, node); - - /* Error, don't add the service */ - if (result != GNOME_VFS_OK) - { - ephy_node_unref (node); - - ephy_node_db_set_immutable (priv->db, was_immutable); - - return; - } - + /* Find the protocol */ for (i = 0; i < G_N_ELEMENTS (zeroconf_protos); ++i) { char proto[20]; g_snprintf (proto, sizeof (proto), "_%s._tcp", zeroconf_protos[i]); - if (strcmp (service->type, proto) == 0) break; + if (strcmp (type, proto) == 0) break; } if (i == G_N_ELEMENTS (zeroconf_protos)) return; + + text_table = decode_txt_record (txt); - if (text != NULL) + if (text_table != NULL) { - path = g_hash_table_lookup (text, "path"); + path = g_hash_table_lookup (text_table, "path"); } if (path == NULL || path[0] == '\0') { path = "/"; } + + if (address == NULL) + { + g_warning ("Zeroconf failed to resolve host %s", name); + return; + } + avahi_address_snprint (host, sizeof (host), address); LOG ("0conf RESOLVED type=%s domain=%s name=%s => proto=%s host=%s port=%d path=%s\n", - service->type, service->domain, service->name, - zeroconf_protos[i], host, port, path); + type, domain, name, + zeroconf_protos[i], host, port, path); /* FIXME: limit length! */ url = g_strdup_printf ("%s://%s:%d%s", zeroconf_protos[i], host, port, path); @@ -908,39 +982,84 @@ resolve_cb (GnomeVFSDNSSDResolveHandle *handle, } static void -browse_cb (GnomeVFSDNSSDBrowseHandle *handle, - GnomeVFSDNSSDServiceStatus status, - const GnomeVFSDNSSDService *service, - EphyBookmarks *bookmarks) +resolver_failure_cb (GaServiceResolver *resolver, + GError *error, + ResolveData *data) { + EphyBookmarks *bookmarks = data->bookmarks; EphyBookmarksPrivate *priv = bookmarks->priv; - GnomeVFSDNSSDResolveHandle *reshandle = NULL; - ResolveData *data; - EphyNode *node; - GValue value = { 0, }; - gboolean new_node = FALSE; + EphyNode *node = data->node; + gboolean was_immutable; - if (service == NULL) return; + was_immutable = ephy_node_db_is_immutable (priv->db); + ephy_node_db_set_immutable (priv->db, FALSE); - node = get_node_for_service (bookmarks, service); + g_hash_table_steal (priv->resolve_handles, node); - if (status == GNOME_VFS_DNS_SD_SERVICE_REMOVED) - { - if (node != NULL) - { - g_hash_table_remove (priv->resolve_handles, node); - ephy_node_unref (node); - } + /* Error, don't add the service */ + ephy_node_unref (node); + ephy_node_db_set_immutable (priv->db, was_immutable); - return; - } + return; +} - /* status == GNOME_VFS_DNS_SD_SERVICE_ADDED */ +static void +free_resolve_cb_data (gpointer data) +{ + g_slice_free (ResolveData, data); +} - LOG ("0conf ADD: type=%s domain=%s name=%s\n", - service->type, service->domain, service->name); +static void +browser_removed_service_cb (GaServiceBrowser *browser, + int interface, + GaProtocol protocol, + const char *name, + const char *type, + const char *domain, + glong flags, + EphyBookmarks *bookmarks) +{ + EphyBookmarksPrivate *priv = bookmarks->priv; + EphyNode *node; + char *node_id; + + node_id = get_id_for_response (type, domain, name); + node = get_node_for_id (bookmarks, node_id); + + if (node != NULL) + { + g_hash_table_remove (priv->resolve_handles, node); + ephy_node_unref (node); + } + + return; +} - if (node != NULL && +static void +browser_new_service_cb (GaServiceBrowser *browser, + int interface, + GaProtocol protocol, + const char *name, + const char *type, + const char *domain, + glong flags, + EphyBookmarks *bookmarks) +{ + EphyBookmarksPrivate *priv = bookmarks->priv; + EphyNode *node; + GValue value = { 0, }; + gboolean new_node = FALSE; + GaServiceResolver *resolver = NULL; + ResolveData *data; + char *node_id; + + node_id = get_id_for_response (type, domain, name); + node = get_node_for_id (bookmarks, node_id); + + LOG ("0conf ADD: type=%s domain=%s name=%s\n", + type, domain, name); + + if (node != NULL && g_hash_table_lookup (priv->resolve_handles, node) != NULL) return; if (node == NULL) @@ -959,14 +1078,14 @@ browse_cb (GnomeVFSDNSSDBrowseHandle *handle, ephy_node_set_is_drag_source (node, FALSE); g_value_init (&value, G_TYPE_STRING); - g_value_take_string (&value, get_id_for_service (service)); + g_value_take_string (&value, get_id_for_response (type, domain, name)); ephy_node_set_property (node, EPHY_NODE_BMK_PROP_SERVICE_ID, &value); g_value_unset (&value); /* FIXME: limit length! */ ephy_node_set_property_string (node, EPHY_NODE_BMK_PROP_TITLE, - service->name); + name); ephy_node_set_property_boolean (node, EPHY_NODE_BMK_PROP_IMMUTABLE, @@ -975,57 +1094,109 @@ browse_cb (GnomeVFSDNSSDBrowseHandle *handle, ephy_node_db_set_immutable (priv->db, was_immutable); } - data = g_new (ResolveData, 1); + data = g_slice_new0 (ResolveData); data->bookmarks = bookmarks; data->node = node; data->new_node = new_node; - - if (gnome_vfs_dns_sd_resolve (&reshandle, - service->name, service->type, service->domain, - SD_RESOLVE_TIMEOUT, - (GnomeVFSDNSSDResolveCallback) resolve_cb, - data, - (GDestroyNotify) g_free) != GNOME_VFS_OK) + + resolver = ga_service_resolver_new (AVAHI_IF_UNSPEC, + AVAHI_PROTO_UNSPEC, + name, type, domain, + AVAHI_PROTO_UNSPEC, + GA_LOOKUP_USE_MULTICAST); + g_signal_connect_data (resolver, "found", + G_CALLBACK (resolver_found_cb), data, + (GClosureNotify) free_resolve_cb_data, 0); + g_signal_connect_data (resolver, "failure", + G_CALLBACK (resolver_failure_cb), data, + (GClosureNotify) free_resolve_cb_data, 0); + if (!ga_service_resolver_attach (resolver, + priv->ga_client, + NULL)) { + g_warning ("Unable to resolve Zeroconf service %s", name); ephy_node_unref (node); - g_free (data); - + free_resolve_cb_data (data); return; } - g_hash_table_insert (priv->resolve_handles, - node, reshandle); + node, resolver); } static void -ephy_local_bookmarks_init (EphyBookmarks *bookmarks) +start_browsing (GaClient *ga_client, + EphyBookmarks *bookmarks) { EphyBookmarksPrivate *priv = bookmarks->priv; guint i; - priv->resolve_handles = - g_hash_table_new_full (g_direct_hash, g_direct_equal, - NULL, - (GDestroyNotify) gnome_vfs_dns_sd_cancel_resolve); - for (i = 0; i < G_N_ELEMENTS (zeroconf_protos); ++i) { - GnomeVFSDNSSDBrowseHandle *handle = NULL; + GaServiceBrowser *browser = NULL; char proto[20]; g_snprintf (proto, sizeof (proto), "_%s._tcp", zeroconf_protos[i]); - if (gnome_vfs_dns_sd_browse (&handle, - "local", proto, - (GnomeVFSDNSSDBrowseCallback) browse_cb, - bookmarks, - NULL) == GNOME_VFS_OK) + browser = ga_service_browser_new (proto); + g_signal_connect (browser, "new-service", + G_CALLBACK (browser_new_service_cb), bookmarks); + g_signal_connect (browser, "removed-service", + G_CALLBACK (browser_removed_service_cb), bookmarks); + if (!ga_service_browser_attach (browser, + ga_client, + NULL)) { - priv->browse_handles[i] = handle; + g_warning ("Unable to start Zeroconf subsystem"); + return; } + + priv->browse_handles[i] = browser; } } +static void +ga_client_state_changed_cb (GaClient *ga_client, + GaClientState state, + EphyBookmarks *bookmarks) +{ + if (state == GA_CLIENT_STATE_FAILURE) + { + if (avahi_client_errno (ga_client->avahi_client) == AVAHI_ERR_DISCONNECTED) + { + /* Destroy and reconnect */ + avahi_client_free (ga_client->avahi_client); + ga_client->avahi_client = NULL; + if (!ga_client_start (ga_client, NULL)) + { + g_warning ("Unable to start Zeroconf subsystem"); + } + } + } + if (state == GA_CLIENT_STATE_S_RUNNING) + { + start_browsing (ga_client, bookmarks); + } +} + +static void +ephy_local_bookmarks_init (EphyBookmarks *bookmarks) +{ + EphyBookmarksPrivate *priv = bookmarks->priv; + GaClient *ga_client; + + ga_client = ga_client_new (GA_CLIENT_FLAG_NO_FAIL); + g_signal_connect (ga_client, "state-changed", + G_CALLBACK (ga_client_state_changed_cb), + bookmarks); + if (!ga_client_start (ga_client, NULL)) + { + g_warning ("Unable to start Zeroconf subsystem"); + return; + } + priv->ga_client = ga_client; + priv->resolve_handles = g_hash_table_new (g_direct_hash, g_direct_equal); +} + static void ephy_local_bookmarks_stop (EphyBookmarks *bookmarks) { @@ -1036,7 +1207,6 @@ ephy_local_bookmarks_stop (EphyBookmarks *bookmarks) { if (priv->browse_handles[i] != NULL) { - gnome_vfs_dns_sd_stop_browse (priv->browse_handles[i]); priv->browse_handles[i] = NULL; } } @@ -1051,6 +1221,12 @@ ephy_local_bookmarks_stop (EphyBookmarks *bookmarks) { ephy_node_remove_child (priv->keywords, priv->local); } + + if (priv->ga_client != NULL) + { + g_object_unref (priv->ga_client); + priv->ga_client = NULL; + } } #endif /* ENABLE_ZEROCONF */ @@ -1569,7 +1745,7 @@ impl_resolve_address (EphyBookmarks *eb, } else { - escaped_arg = gnome_vfs_escape_string (arg); + escaped_arg = g_uri_escape_string (arg, NULL, TRUE); g_string_append (result, escaped_arg); g_free (escaped_arg); g_free (arg); @@ -1579,7 +1755,7 @@ impl_resolve_address (EphyBookmarks *eb, } else { - arg = gnome_vfs_escape_string (content); + arg = g_uri_escape_string (content, NULL, TRUE); g_string_append (result, arg); g_free (arg); } diff --git a/src/bookmarks/ephy-topic-action.c b/src/bookmarks/ephy-topic-action.c index ad5eb9eef..34c9fc843 100644 --- a/src/bookmarks/ephy-topic-action.c +++ b/src/bookmarks/ephy-topic-action.c @@ -46,7 +46,6 @@ #include #include #include -#include #include static const GtkTargetEntry dest_drag_types[] = { diff --git a/src/ephy-extensions-manager.c b/src/ephy-extensions-manager.c index 9d489d1cb..10aa75f9c 100644 --- a/src/ephy-extensions-manager.c +++ b/src/ephy-extensions-manager.c @@ -49,11 +49,9 @@ #include #include -#include -#include - #include +#include #include #include #include @@ -998,35 +996,35 @@ schedule_load_from_monitor (EphyExtensionsManager *manager, } static void -dir_changed_cb (GnomeVFSMonitorHandle *handle, - const char *monitor_uri, - const char *info_uri, - GnomeVFSMonitorEventType event_type, +dir_changed_cb (GFileMonitor *monitor, + GFile *child, + GFile *other_child, + GFileMonitorEvent event_type, EphyExtensionsManager *manager) { char *path; + + path = g_file_get_path (child); /* * We only deal with XML and INI files: * Add them to the manager when created, remove them when deleted. */ - if (format_from_path (info_uri) == FORMAT_UNKNOWN) return; - - path = gnome_vfs_get_local_path_from_uri (info_uri); + if (format_from_path (path) == FORMAT_UNKNOWN) return; switch (event_type) { - case GNOME_VFS_MONITOR_EVENT_CREATED: - case GNOME_VFS_MONITOR_EVENT_CHANGED: + case G_FILE_MONITOR_EVENT_CREATED: + case G_FILE_MONITOR_EVENT_CHANGED: schedule_load_from_monitor (manager, path); break; - case GNOME_VFS_MONITOR_EVENT_DELETED: + case G_FILE_MONITOR_EVENT_DELETED: ephy_extensions_manager_unload_file (manager, path); break; default: break; } - + g_free (path); } @@ -1037,9 +1035,8 @@ ephy_extensions_manager_load_dir (EphyExtensionsManager *manager, DIR *d; struct dirent *e; char *file_path; - char *file_uri; - GnomeVFSMonitorHandle *monitor; - GnomeVFSResult res; + GFile *directory; + GFileMonitor *monitor; LOG ("Scanning directory '%s'", path); @@ -1061,16 +1058,14 @@ ephy_extensions_manager_load_dir (EphyExtensionsManager *manager, } closedir (d); - file_uri = gnome_vfs_get_uri_from_local_path (path); - res = gnome_vfs_monitor_add (&monitor, - path, - GNOME_VFS_MONITOR_DIRECTORY, - (GnomeVFSMonitorCallback) dir_changed_cb, - manager); - g_free (file_uri); + directory = g_file_new_for_path (path); + monitor = g_file_monitor_directory (directory, 0, NULL); - if (res == GNOME_VFS_OK) + if (monitor != NULL) { + g_signal_connect (monitor, "changed", + G_CALLBACK (dir_changed_cb), + manager); manager->priv->dir_monitors = g_list_prepend (manager->priv->dir_monitors, monitor); } @@ -1165,7 +1160,7 @@ ephy_extensions_manager_dispose (GObject *object) if (priv->dir_monitors != NULL) { - g_list_foreach (priv->dir_monitors, (GFunc) gnome_vfs_monitor_cancel, NULL); + g_list_foreach (priv->dir_monitors, (GFunc) g_file_monitor_cancel, NULL); g_list_free (priv->dir_monitors); priv->dir_monitors = NULL; } diff --git a/src/ephy-main.c b/src/ephy-main.c index ae473719b..f4bfec47e 100644 --- a/src/ephy-main.c +++ b/src/ephy-main.c @@ -47,8 +47,6 @@ #include #include -#include -#include #include #include @@ -203,11 +201,24 @@ handle_email (GtkAboutDialog *about, const char *link, gpointer data) { - char *address; + char *command, *handler; + GAppInfo *appinfo; - address = g_strdup_printf ("mailto:%s", link); - gnome_vfs_url_show (address); - g_free (address); + if (eel_gconf_get_boolean ("/desktop/gnome/url-handlers/mailto/enabled") == FALSE) + { + return; + } + /* FIXME: better use g_app_info_get_default_for_uri_scheme () when it is + * implemented. + */ + handler = eel_gconf_get_string ("/desktop/gnome/url-handlers/mailto/command"); + command = g_strconcat (handler, "mailto:", link, NULL); + appinfo = g_app_info_create_from_commandline (command, NULL, 0, NULL); + ephy_file_launch_application (appinfo, NULL, + gtk_get_current_event_time (), + GTK_WIDGET (about)); + g_free (handler); + g_free (command); } static void @@ -585,12 +596,15 @@ main (int argc, { g_free (arguments[i]); - /* If it's a file, use gnome_vfs_make_uri_from_shell_arg, + /* If it's a file, use g_file_new_for_commandline_arg, * so we get the right escaping. */ if (path != NULL) { - arguments[i] = gnome_vfs_make_uri_from_shell_arg (uri); + GFile *file; + file = g_file_new_for_commandline_arg (uri); + arguments[i] = g_file_get_uri (file); + g_object_unref (file); g_free (uri); } else @@ -727,7 +741,6 @@ main (int argc, gnome_accelerators_sync (); ephy_state_save (); ephy_file_helpers_shutdown (); - gnome_vfs_shutdown (); xmlCleanupParser (); _ephy_dbus_release (); diff --git a/src/ephy-session.c b/src/ephy-session.c index c1b79d25d..2342d2998 100644 --- a/src/ephy-session.c +++ b/src/ephy-session.c @@ -40,6 +40,7 @@ #include "ephy-notebook.h" #include +#include #include #include #include @@ -52,9 +53,6 @@ #include -#include -#include - #include #include @@ -391,10 +389,11 @@ die_cb (GnomeClient* client, /* Helper functions */ -static char * -get_session_filename (const char *filename) +static GFile * +get_session_file (const char *filename) { - char *save_to; + GFile *file; + char *path; if (filename == NULL) { @@ -403,29 +402,30 @@ get_session_filename (const char *filename) if (strcmp (filename, SESSION_CRASHED) == 0) { - save_to = g_build_filename (ephy_dot_dir (), - "session_crashed.xml", - NULL); + path = g_build_filename (ephy_dot_dir (), + "session_crashed.xml", + NULL); } else { - save_to = g_strdup (filename); + path = g_strdup (filename); } - return save_to; + file = g_file_new_for_path (path); + g_free (path); + + return file; } static void session_delete (EphySession *session, const char *filename) { - char *save_to; + GFile *file; - save_to = get_session_filename (filename); + file = get_session_file (filename); - gnome_vfs_unlink (save_to); - - g_free (save_to); + g_file_delete (file, NULL, NULL); } static void @@ -566,14 +566,17 @@ session_command_autoresume (EphySession *session, { EphySessionPrivate *priv = session->priv; GtkWidget *dialog; - char *saved_session; + GFile *saved_session_file; + char *saved_session_file_path; gboolean crashed_session; LOG ("ephy_session_autoresume"); - saved_session = get_session_filename (SESSION_CRASHED); - crashed_session = g_file_test (saved_session, G_FILE_TEST_EXISTS); - g_free (saved_session); + saved_session_file = get_session_file (SESSION_CRASHED); + saved_session_file_path = g_file_get_path (saved_session_file); + crashed_session = g_file_test (saved_session_file_path, G_FILE_TEST_EXISTS); + + g_free (saved_session_file_path); if (crashed_session == FALSE || priv->windows != NULL || @@ -1225,7 +1228,8 @@ ephy_session_save (EphySession *session, EphySessionPrivate *priv; xmlTextWriterPtr writer; GList *w; - char *save_to, *tmp_file; + GFile *save_to_file, *tmp_file; + char *tmp_file_path; int ret; g_return_val_if_fail (EPHY_IS_SESSION (session), FALSE); @@ -1245,15 +1249,15 @@ ephy_session_save (EphySession *session, return TRUE; } - save_to = get_session_filename (filename); - tmp_file = g_strconcat (save_to, ".tmp", NULL); + save_to_file = get_session_file (filename); + tmp_file_path = g_strconcat (g_file_get_path (save_to_file), ".tmp", NULL); + tmp_file = g_file_new_for_path (tmp_file_path); /* FIXME: do we want to turn on compression? */ - writer = xmlNewTextWriterFilename (tmp_file, 0); + writer = xmlNewTextWriterFilename (tmp_file_path, 0); if (writer == NULL) { - g_free (save_to); - g_free (tmp_file); + g_free (tmp_file_path); return FALSE; } @@ -1296,14 +1300,15 @@ out: if (ret >= 0) { - if (ephy_file_switch_temp_file (save_to, tmp_file) == FALSE) + if (ephy_file_switch_temp_file (save_to_file, tmp_file) == FALSE) { ret = -1; } } - g_free (save_to); - g_free (tmp_file); + g_free (tmp_file_path); + g_object_unref (save_to_file); + g_object_unref (tmp_file); STOP_PROFILER ("Saving session") @@ -1345,9 +1350,11 @@ parse_embed (xmlNodePtr child, char *escaped_url, *escaped_title; title = xmlGetProp (child, (const xmlChar *) "title"); - escaped_title = gnome_vfs_escape_string (title ? (const char*) title : _("Untitled")); + escaped_title = g_uri_escape_string (title ? (const char*) title : _("Untitled"), + NULL, TRUE); - escaped_url = gnome_vfs_escape_string ((const char *) url); + escaped_url = g_uri_escape_string ((const char *) url, + NULL, TRUE); freeme = recover_url = g_strconcat ("about:recover?u=", escaped_url, @@ -1452,14 +1459,16 @@ ephy_session_load (EphySession *session, xmlNodePtr child; EphyWindow *window; GtkWidget *widget = NULL; - char *save_to; + GFile *save_to_file; + char *save_to_path; LOG ("ephy_sesion_load %s", filename); - save_to = get_session_filename (filename); + save_to_file = get_session_file (filename); + save_to_path = g_file_get_path (save_to_file); - doc = xmlParseFile (save_to); - g_free (save_to); + doc = xmlParseFile (save_to_path); + g_free (save_to_path); if (doc == NULL) { diff --git a/src/ephy-window.c b/src/ephy-window.c index ef8935bea..7213d1315 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -60,7 +60,7 @@ #include #include -#include +#include #include #include #include @@ -1977,15 +1977,9 @@ embed_popup_deactivate_cb (GtkWidget *popup, static char * get_name_from_address_value (const GValue *value) { - GnomeVFSURI *uri; - char *name = NULL; + char *name; - uri = gnome_vfs_uri_new (g_value_get_string (value)); - if (uri) - { - name = gnome_vfs_uri_extract_short_name (uri); - gnome_vfs_uri_unref (uri); - } + name = g_path_get_basename (g_value_get_string (value)); return name != NULL ? name : g_strdup (""); } diff --git a/src/popup-commands.c b/src/popup-commands.c index 6e4d677a4..51b2fbfd5 100644 --- a/src/popup-commands.c +++ b/src/popup-commands.c @@ -35,10 +35,6 @@ #include #include #include -#include -#include -#include -#include void popup_cmd_link_in_new_window (GtkAction *action, @@ -279,7 +275,8 @@ popup_cmd_save_image_as (GtkAction *action, #define GNOME_APPEARANCE_PROPERTIES "gnome-appearance-properties.desktop" static void -background_download_completed (EphyEmbedPersist *persist) +background_download_completed (EphyEmbedPersist *persist, + GtkWidget *window) { const char *bg; guint32 user_time; @@ -289,15 +286,15 @@ background_download_completed (EphyEmbedPersist *persist) bg = ephy_embed_persist_get_dest (persist); /* open the Appearance Properties capplet on the Background tab */ - if (!ephy_file_launch_desktop_file (GNOME_APPEARANCE_PROPERTIES, bg, user_time)) + if (!ephy_file_launch_desktop_file (GNOME_APPEARANCE_PROPERTIES, bg, user_time, window)) { /* Fallback for <= 2.18 desktop: try to open the "Background Properties" capplet */ - if (!ephy_file_launch_desktop_file ("background.desktop", bg, user_time)) + if (!ephy_file_launch_desktop_file ("background.desktop", bg, user_time, window)) { /* If the above try didn't work, then we try the Fedora name. * This is a fix for #387206, but is actually a workaround for * bugzilla.redhat.com #201867 */ - ephy_file_launch_desktop_file ("gnome-background.desktop", bg, user_time); + ephy_file_launch_desktop_file ("gnome-background.desktop", bg, user_time, window); } } @@ -338,7 +335,7 @@ popup_cmd_set_image_as_background (GtkAction *action, g_signal_connect (persist, "completed", G_CALLBACK (background_download_completed), - NULL); + window); ephy_embed_persist_save (persist); @@ -383,13 +380,13 @@ popup_cmd_open_frame (GtkAction *action, * doesn't work, fallback to open the URI in a new browser window. */ static void -image_open_uri (const char *remote_address, - const char *local_address, +image_open_uri (GFile *file, + const char *remote_address, guint32 user_time) { gboolean success; - success = ephy_file_launch_handler (NULL, local_address, user_time); + success = ephy_file_launch_handler (NULL, file, user_time); if (!success) { @@ -398,12 +395,12 @@ image_open_uri (const char *remote_address, EPHY_NEW_TAB_IN_NEW_WINDOW); } - if (strcmp (remote_address, local_address) != 0) + if (strcmp (remote_address, g_file_get_uri (file)) != 0) { if (success) - ephy_file_delete_on_exit (local_address); + ephy_file_delete_on_exit (file); else - gnome_vfs_unlink (local_address); + g_file_delete (file, NULL, NULL); } } @@ -413,13 +410,17 @@ save_source_completed_cb (EphyEmbedPersist *persist) const char *dest; const char *source; guint32 user_time; + GFile *file; user_time = ephy_embed_persist_get_user_time (persist); dest = ephy_embed_persist_get_dest (persist); source = ephy_embed_persist_get_source (persist); g_return_if_fail (dest != NULL); + + file = g_file_new_for_path (dest); - image_open_uri (source, dest, user_time); + image_open_uri (file, source, user_time); + g_object_unref (file); } static void @@ -480,13 +481,17 @@ popup_cmd_open_image (GtkAction *action, value = ephy_embed_event_get_property (event, "image"); address = g_value_get_string (value); - scheme = gnome_vfs_get_uri_scheme (address); + scheme = g_uri_get_scheme (address); if (scheme == NULL) return; if (strcmp (scheme, "file") == 0) { - image_open_uri (address, address, + GFile *file; + + file = g_file_new_for_uri (address); + image_open_uri (file, address, gtk_get_current_event_time ()); + g_object_unref (file); } else { diff --git a/src/prefs-dialog.c b/src/prefs-dialog.c index 5c203ec92..8cc84507e 100644 --- a/src/prefs-dialog.c +++ b/src/prefs-dialog.c @@ -64,8 +64,6 @@ #include #include -#include - #define CONF_FONTS_FOR_LANGUAGE "/apps/epiphany/dialogs/preferences_font_language" #define DOWNLOAD_BUTTON_WIDTH 8 @@ -649,18 +647,15 @@ static void css_edit_button_clicked_cb (GtkWidget *button, PrefsDialog *pd) { - char *css_file, *uri; + GFile *css_file; - css_file = g_build_filename (ephy_dot_dir (), - USER_STYLESHEET_FILENAME, - NULL); - uri = gnome_vfs_get_uri_from_local_path (css_file); + css_file = g_file_new_for_path (g_build_filename (ephy_dot_dir (), + USER_STYLESHEET_FILENAME, + NULL)); - ephy_file_launch_handler ("text/plain", uri, + ephy_file_launch_handler ("text/plain", css_file, gtk_get_current_event_time ()); - - g_free (css_file); - g_free (uri); + g_object_unref (css_file); } static void diff --git a/src/window-commands.c b/src/window-commands.c index fb7438e58..9bc698a67 100644 --- a/src/window-commands.c +++ b/src/window-commands.c @@ -49,14 +49,13 @@ #include "ephy-bookmarks-ui.h" #include "ephy-link.h" #include "ephy-stock-icons.h" +#include "ephy-string.h" +#include "eel-app-launch-context.h" #include "pdm-dialog.h" #include #include -#include -#include -#include -#include +#include #include #include #include @@ -122,24 +121,38 @@ window_cmd_file_send_to (GtkAction *action, EphyWindow *window) { EphyEmbed *embed; - char *url, *location, *title; + char *handler, *command; + const char *location, *title; + GAppInfo *appinfo; + + if (eel_gconf_get_boolean ("/desktop/gnome/url-handlers/mailto/enabled") == FALSE) + { + /* FIXME: add some UI to inform the user? */ + return; + } embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window)); g_return_if_fail (embed != NULL); - location = gnome_vfs_escape_string (ephy_embed_get_address (embed)); - title = gnome_vfs_escape_string (ephy_embed_get_title (embed)); - - url = g_strconcat ("mailto:", - "?Subject=", title, - "&Body=", location, NULL); + location = ephy_embed_get_address (embed); + title = ephy_embed_get_title (embed); - gnome_vfs_url_show (url); + /* FIXME: better use g_app_info_get_default_for_uri_scheme () when it is + * implemented. + */ + handler = eel_gconf_get_string ("/desktop/gnome/url-handlers/mailto/command"); + command = g_strconcat (handler, "mailto:", + "?Subject=\"", title, + "\"&Body=\"", location, "\"", NULL); + + appinfo = g_app_info_create_from_commandline (command, NULL, 0, NULL); + ephy_file_launch_application (appinfo, NULL, + gtk_get_current_event_time (), + GTK_WIDGET (window)); - g_free (title); - g_free (location); - g_free (url); + g_free (handler); + g_free (command); } static gboolean @@ -564,14 +577,17 @@ save_source_completed_cb (EphyEmbedPersist *persist) { const char *dest; guint32 user_time; + GFile *file; user_time = ephy_embed_persist_get_user_time (persist); dest = ephy_embed_persist_get_dest (persist); g_return_if_fail (dest != NULL); - ephy_file_delete_on_exit (dest); + file = g_file_new_for_path (dest); + ephy_file_delete_on_exit (file); - ephy_file_launch_handler ("text/plain", dest, user_time); + ephy_file_launch_handler ("text/plain", file, user_time); + g_object_unref (file); } static void @@ -631,7 +647,12 @@ window_cmd_view_page_source (GtkAction *action, if (g_str_has_prefix (address, "file://")) { - ephy_file_launch_handler ("text/plain", address, user_time); + GFile *file; + + file = g_file_new_for_uri (address); + ephy_file_launch_handler ("text/plain", file, user_time); + + g_object_unref (file); } else { @@ -670,24 +691,21 @@ window_cmd_edit_personal_data (GtkAction *action, { PdmDialog *dialog; EphyEmbed *embed; - GnomeVFSURI *uri; - const char *host; + const char *address; + char *host; embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window)); if (embed == NULL) return; - uri = gnome_vfs_uri_new (ephy_embed_get_address (embed)); - - host = uri != NULL ? gnome_vfs_uri_get_host_name (uri) : NULL; + address = ephy_embed_get_address (embed); + + host = address != NULL ? ephy_string_get_host_name (address) : NULL; dialog = EPHY_PDM_DIALOG (ephy_shell_get_pdm_dialog (ephy_shell)); pdm_dialog_open (dialog, host); - if (uri != NULL) - { - gnome_vfs_uri_unref (uri); - } + g_free (host); } #ifdef ENABLE_CERTIFICATE_MANAGER -- cgit v1.2.3