diff options
author | Christian Persch <chpe@cvs.gnome.org> | 2005-02-27 06:01:48 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2005-02-27 06:01:48 +0800 |
commit | fbf4b15ed54be3abfe2c3c937c50b9c623804cb5 (patch) | |
tree | 27639ff5895028fd04bcc8c4ce800354b040fa73 /lib | |
parent | caba7f03132e463c48405eb602a8b77764c3ec75 (diff) | |
download | gsoc2013-epiphany-fbf4b15ed54be3abfe2c3c937c50b9c623804cb5.tar gsoc2013-epiphany-fbf4b15ed54be3abfe2c3c937c50b9c623804cb5.tar.gz gsoc2013-epiphany-fbf4b15ed54be3abfe2c3c937c50b9c623804cb5.tar.bz2 gsoc2013-epiphany-fbf4b15ed54be3abfe2c3c937c50b9c623804cb5.tar.lz gsoc2013-epiphany-fbf4b15ed54be3abfe2c3c937c50b9c623804cb5.tar.xz gsoc2013-epiphany-fbf4b15ed54be3abfe2c3c937c50b9c623804cb5.tar.zst gsoc2013-epiphany-fbf4b15ed54be3abfe2c3c937c50b9c623804cb5.zip |
Depend on gnome-desktop for gnome-desktop-item, and up the gnome-vfs
2005-02-26 Christian Persch <chpe@cvs.gnome.org>
* configure.ac:
Depend on gnome-desktop for gnome-desktop-item,
and up the gnome-vfs dependency version.
* embed/ephy-embed-persist.c: (ephy_embed_persist_set_user_time),
(ephy_embed_persist_get_user_time),
(ephy_embed_persist_set_property),
(ephy_embed_persist_get_property), (ephy_embed_persist_init),
(ephy_embed_persist_class_init):
* embed/ephy-embed-persist.h:
Add user time property.
* embed/mozilla/ContentHandler.cpp:
* embed/mozilla/ContentHandler.h:
Forward user time to MozDownload via a string. Not perfect,
but better than nothing.
* embed/mozilla/EphyHeaderSniffer.cpp:
Set user time on filechooser.
* embed/mozilla/MozDownload.cpp:
Get user time from content handler, and use it when
launching the external handler app.
* lib/ephy-file-helpers.c: (ephy_file_check_mime),
(launch_desktop_item), (ephy_file_launch_desktop_file),
(ephy_file_launch_application), (ephy_file_launch_handler):
* lib/ephy-file-helpers.h:
Convenience functions to launch an app, or a desktop item,
with user time.
* lib/ephy-gui.c: (ephy_gui_confirm_overwrite_file),
(ephy_gui_window_update_user_time), (ephy_gui_window_present):
* lib/ephy-gui.h:
Make our own gtk_window_present, to correctly update user time.
Check if the path is writable in ephy_gui_confirm_overwrite_file().
* src/ephy-session.c: (ephy_session_autoresume):
After showing the recovery dialogue, don't use the old user time
to launch the windows; use the current event time instead.
* src/popup-commands.c: (background_download_completed),
(image_open_uri), (save_source_completed_cb),
(popup_cmd_open_image):
* src/window-commands.c: (window_cmd_file_save_as),
(save_source_completed_cb), (save_temp_source),
(window_cmd_view_page_source):
Launch handlers with user time.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ephy-file-helpers.c | 171 | ||||
-rw-r--r-- | lib/ephy-file-helpers.h | 14 | ||||
-rw-r--r-- | lib/ephy-gui.c | 50 | ||||
-rw-r--r-- | lib/ephy-gui.h | 3 |
4 files changed, 230 insertions, 8 deletions
diff --git a/lib/ephy-file-helpers.c b/lib/ephy-file-helpers.c index f1f62bae5..f66d61312 100644 --- a/lib/ephy-file-helpers.c +++ b/lib/ephy-file-helpers.c @@ -22,6 +22,12 @@ #include "config.h" +#include "ephy-file-helpers.h" + +#include "ephy-prefs.h" +#include "eel-gconf-extensions.h" +#include "ephy-debug.h" + #include <string.h> #include <stdlib.h> #include <unistd.h> @@ -29,12 +35,14 @@ #include <glib.h> #include <glib/gi18n.h> #include <libgnome/gnome-init.h> +#include <libgnomevfs/gnome-vfs-utils.h> +#include <libgnomevfs/gnome-vfs-file-info.h> +#include <libgnomevfs/gnome-vfs-ops.h> #include <libxml/xmlreader.h> -#include "ephy-file-helpers.h" -#include "ephy-prefs.h" -#include "eel-gconf-extensions.h" -#include "ephy-debug.h" +/* bug http://bugzilla.gnome.org/show_bug.cgi?id=156687 */ +#undef GNOME_DISABLE_DEPRECATED +#include <libgnome/gnome-desktop-item.h> static GHashTable *files = NULL; static GHashTable *mime_table = NULL; @@ -449,3 +457,158 @@ ephy_file_check_mime (const char *mime_type) return permission; } + +static int +launch_desktop_item (const char *desktop_file, + const char *parameter, + guint32 user_time, + GError **error) +{ + GnomeDesktopItem *item = NULL; + GList *uris = NULL; + char *canonical; + int ret = -1; + + 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 (item, uris, 0, error); + + g_list_foreach (uris, (GFunc) g_free, NULL); + g_list_free (uris); + gnome_desktop_item_unref (item); + + return ret; +} + +gboolean +ephy_file_launch_desktop_file (const char *filename, + guint32 user_time) +{ + 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++) + { + g_print ("Looking in path: %s\n", dirs[i]); + + path = g_build_filename (dirs[i], "applications", filename, NULL); + + if (g_file_test (path, G_FILE_TEST_IS_REGULAR)) break; + + g_free (path); + } + + if (path != NULL) + { + ret = launch_desktop_item (path, NULL, 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); + } + + return ret >= 0; +} + +gboolean +ephy_file_launch_application (GnomeVFSMimeApplication *application, + const char *parameter, + guint32 user_time) +{ + GError *error = NULL; + const char *desktop_file; + int ret = -1; + + g_return_val_if_fail (application != NULL, FALSE); + g_return_val_if_fail (parameter != NULL, FALSE); + + desktop_file = gnome_vfs_mime_application_get_desktop_file_path (application); + if (desktop_file != NULL) + { + ret = launch_desktop_item (desktop_file, parameter, user_time, &error); + } + + if (ret == -1 || error != NULL) + { + /* FIXME We should really warn the user here */ + + g_warning ("Cannot launch application '%s': %s\n", + gnome_vfs_mime_application_get_name (application), + error ? error->message : "(unknown error)"); + g_clear_error (&error); + } + + return ret >= 0; +} + +gboolean +ephy_file_launch_handler (const char *mime_type, + const char *address, + guint32 user_time) +{ + GnomeVFSMimeApplication *app = NULL; + GnomeVFSFileInfo *info = NULL; + char *canonical; + gboolean ret = FALSE; + + g_return_val_if_fail (address != NULL, FALSE); + + canonical = gnome_vfs_make_uri_canonical (address); + g_return_val_if_fail (canonical != NULL, FALSE); + + if (mime_type != NULL) + { + app = gnome_vfs_mime_get_default_application (mime_type); + } + else + { + /* 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) + { + /* FIXME rename tmp file to right extension ? */ + app = gnome_vfs_mime_get_default_application (info->mime_type); + } + gnome_vfs_file_info_unref (info); + } + + if (app != NULL) + { + ret = ephy_file_launch_application (app, address, user_time); + + gnome_vfs_mime_application_free (app); + } + else + { + /* FIXME: warn user? */ + g_warning ("No handler for found or file type is unsafe!\n"); + } + + g_free (canonical); + + return ret; +} diff --git a/lib/ephy-file-helpers.h b/lib/ephy-file-helpers.h index 8b9a99c13..81fdd90f5 100644 --- a/lib/ephy-file-helpers.h +++ b/lib/ephy-file-helpers.h @@ -24,6 +24,7 @@ #define EPHY_FILE_HELPERS_H #include <glib.h> +#include <libgnomevfs/gnome-vfs-mime-handlers.h> G_BEGIN_DECLS @@ -44,7 +45,7 @@ void ephy_file_helpers_shutdown (void); char *ephy_file_downloads_dir (void); -char *ephy_file_desktop_dir (void); +char *ephy_file_desktop_dir (void); const char *ephy_file_tmp_dir (void); @@ -64,6 +65,17 @@ void ephy_file_delete_on_exit (const char *path); EphyMimePermission ephy_file_check_mime (const char *mime_type); +gboolean ephy_file_launch_desktop_file (const char *filename, + guint32 user_time); + +gboolean ephy_file_launch_application (GnomeVFSMimeApplication *application, + const char *parameter, + guint32 user_time); + +gboolean ephy_file_launch_handler (const char *mime_type, + const char *address, + guint32 user_time); + G_END_DECLS #endif /* EPHY_FILE_HELPERS_H */ diff --git a/lib/ephy-gui.c b/lib/ephy-gui.c index 6b8a18497..954f4c993 100644 --- a/lib/ephy-gui.c +++ b/lib/ephy-gui.c @@ -22,6 +22,7 @@ #include "ephy-gui.h" #include "eel-gconf-extensions.h" +#include "ephy-debug.h" #include <ctype.h> #include <string.h> @@ -37,6 +38,8 @@ #include <gtk/gtkmain.h> #include <gtk/gtktreeselection.h> +#include <unistd.h> + void ephy_gui_sanitise_popup_position (GtkMenu *menu, GtkWidget *widget, @@ -190,16 +193,26 @@ ephy_gui_confirm_overwrite_file (GtkWidget *parent, const char *filename) { GtkWidget *dialog; - char *display_name; - gboolean retval; + char *display_name, *path; + gboolean retval, writable; if (filename == NULL) return FALSE; if (!g_file_test (filename, G_FILE_TEST_EXISTS)) { - return TRUE; + /* check if path is writable to */ + path = g_path_get_dirname (filename); + writable = access (path, W_OK) == 0; + g_free (path); + + /* FIXME put up some UI to inform the user */ + return writable; } + /* check if file is writable */ + /* FIXME put up some UI to inform the user */ + if (access (filename, W_OK) != 0) return FALSE; + display_name = g_filename_display_basename (filename); dialog = gtk_message_dialog_new @@ -349,6 +362,8 @@ void ephy_gui_window_update_user_time (GtkWidget *window, guint32 user_time) { + LOG ("updating user time on window %p to %d", window, user_time); + if (user_time != 0) { gtk_widget_realize (window); @@ -357,3 +372,32 @@ ephy_gui_window_update_user_time (GtkWidget *window, } } + +/* gtk+ bug 166379 */ +/* adapted from gtk+/gtk/gtkwindow.c */ +void +ephy_gui_window_present (GtkWindow *window, + guint32 user_time) +{ + GtkWidget *widget; + + g_return_if_fail (GTK_IS_WINDOW (window)); + + widget = GTK_WIDGET (window); + + if (GTK_WIDGET_VISIBLE (window)) + { + g_assert (widget->window != NULL); + + gdk_window_show (widget->window); + + /* note that gdk_window_focus() will also move the window to + * the current desktop, for WM spec compliant window managers. + */ + gdk_window_focus (widget->window, user_time); + } + else + { + gtk_widget_show (widget); + } +} diff --git a/lib/ephy-gui.h b/lib/ephy-gui.h index 7a9847281..226f262f9 100644 --- a/lib/ephy-gui.h +++ b/lib/ephy-gui.h @@ -71,6 +71,9 @@ void ephy_gui_help (GtkWindow *parent, void ephy_gui_window_update_user_time (GtkWidget *window, guint32 user_time); +void ephy_gui_window_present (GtkWindow *window, + guint32 user_time); + G_END_DECLS #endif |