From fbf4b15ed54be3abfe2c3c937c50b9c623804cb5 Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Sat, 26 Feb 2005 22:01:48 +0000 Subject: Depend on gnome-desktop for gnome-desktop-item, and up the gnome-vfs 2005-02-26 Christian Persch * 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. --- embed/ephy-embed-persist.c | 62 ++++++++++++++++++++++++++++++++++++- embed/ephy-embed-persist.h | 4 +++ embed/mozilla/ContentHandler.cpp | 41 ++++++++++++++++++++---- embed/mozilla/ContentHandler.h | 1 + embed/mozilla/EphyHeaderSniffer.cpp | 8 +++++ embed/mozilla/MozDownload.cpp | 52 +++++++++++++++++-------------- 6 files changed, 138 insertions(+), 30 deletions(-) (limited to 'embed') diff --git a/embed/ephy-embed-persist.c b/embed/ephy-embed-persist.c index 92d7a99c8..cd065d628 100644 --- a/embed/ephy-embed-persist.c +++ b/embed/ephy-embed-persist.c @@ -25,6 +25,8 @@ #include "mozilla-embed-persist.h" #include "ephy-debug.h" +#include + enum { PROP_0, @@ -36,7 +38,8 @@ enum PROP_HANDLER, PROP_MAX_SIZE, PROP_PERSISTKEY, - PROP_SOURCE, + PROP_SOURCE, + PROP_USER_TIME }; #define EPHY_EMBED_PERSIST_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_EMBED_PERSIST, EphyEmbedPersistPrivate)) @@ -51,6 +54,7 @@ struct _EphyEmbedPersistPrivate long max_size; EphyEmbedPersistFlags flags; GtkWindow *fc_parent; + guint32 user_time; }; static void ephy_embed_persist_class_init (EphyEmbedPersistClass *klass); @@ -238,6 +242,26 @@ ephy_embed_persist_set_source (EphyEmbedPersist *persist, persist->priv->source = g_strdup (value); } +/** + * ephy_embed_persist_set_user_time: + * @persist: an #EphyEmbedPersist + * @user_time: a timestamp, or 0 + * + * Sets the time stamp of the user action which created @persist. + * Defaults to gtk_get_current_event_time() when @persist is created. + **/ +void +ephy_embed_persist_set_user_time (EphyEmbedPersist *persist, + guint32 user_time) +{ + g_return_if_fail (EPHY_IS_EMBED_PERSIST (persist)); + + LOG ("ephy_embed_persist_set_user_time persist %p user-time %d", + persist, user_time); + + persist->priv->user_time = user_time; +} + /** * ephy_embed_persist_get_dest: * @persist: an #EphyEmbedPersist @@ -367,6 +391,24 @@ ephy_embed_persist_get_source (EphyEmbedPersist *persist) return persist->priv->source; } +/** + * ephy_embed_persist_get_user_time: + * @persist: an #EphyEmbedPersist + * + * Returns the timestamp of the user action which created @persist. + * If not set explicitly, defaults to gtk_get_current_event_time () + * at the time of creation of @persist. + * + * Return value: a timestamp, or 0 + **/ +guint32 +ephy_embed_persist_get_user_time (EphyEmbedPersist *persist) +{ + g_return_val_if_fail (EPHY_IS_EMBED_PERSIST (persist), 0); + + return persist->priv->user_time; +} + static void ephy_embed_persist_set_property (GObject *object, guint prop_id, @@ -401,6 +443,9 @@ ephy_embed_persist_set_property (GObject *object, case PROP_SOURCE: ephy_embed_persist_set_source (persist, g_value_get_string (value)); break; + case PROP_USER_TIME: + ephy_embed_persist_set_user_time (persist, g_value_get_uint (value)); + break; } } @@ -438,6 +483,9 @@ ephy_embed_persist_get_property (GObject *object, case PROP_SOURCE: g_value_set_string (value, ephy_embed_persist_get_source (persist)); break; + case PROP_USER_TIME: + g_value_set_uint (value, ephy_embed_persist_get_user_time (persist)); + break; } } @@ -449,6 +497,8 @@ ephy_embed_persist_init (EphyEmbedPersist *persist) LOG ("EphyEmbedPersist initialising %p", persist); persist->priv->max_size = -1; + + ephy_embed_persist_set_user_time (persist, gtk_get_current_event_time ()); } static void @@ -585,6 +635,16 @@ ephy_embed_persist_class_init (EphyEmbedPersistClass *klass) NULL, G_PARAM_READWRITE)); + g_object_class_install_property (object_class, + PROP_USER_TIME, + g_param_spec_uint ("user-time", + "User Time", + "User Time", + 0, + G_MAXUINT, + 0, + G_PARAM_READWRITE)); + g_type_class_add_private (object_class, sizeof(EphyEmbedPersistPrivate)); } diff --git a/embed/ephy-embed-persist.h b/embed/ephy-embed-persist.h index d8969e341..a0ea180c8 100644 --- a/embed/ephy-embed-persist.h +++ b/embed/ephy-embed-persist.h @@ -105,6 +105,8 @@ void ephy_embed_persist_set_persist_key (EphyEmbedPersist *persist, void ephy_embed_persist_set_source (EphyEmbedPersist *persist, const char *value); +void ephy_embed_persist_set_user_time (EphyEmbedPersist *persist, + guint32 user_time); const char *ephy_embed_persist_get_dest (EphyEmbedPersist *persist); @@ -122,6 +124,8 @@ const char *ephy_embed_persist_get_persist_key (EphyEmbedPersist *persist); const char *ephy_embed_persist_get_source (EphyEmbedPersist *persist); +guint32 ephy_embed_persist_get_user_time (EphyEmbedPersist *persist); + char *ephy_embed_persist_to_string (EphyEmbedPersist *persist); G_END_DECLS diff --git a/embed/mozilla/ContentHandler.cpp b/embed/mozilla/ContentHandler.cpp index 91c9d081d..ef2e07b6b 100644 --- a/embed/mozilla/ContentHandler.cpp +++ b/embed/mozilla/ContentHandler.cpp @@ -25,11 +25,14 @@ #include "config.h" +#include "ContentHandler.h" + #include #include #include #include #include +#include #include #include #include @@ -55,17 +58,22 @@ #include "ephy-debug.h" #include "eel-gconf-extensions.h" -#include "ContentHandler.h" #include "MozDownload.h" #include "EphyUtils.h" +/* FIXME: we don't generally have a timestamp for the user action which initiated this + * content handler. + */ #ifdef MOZ_NSIMIMEINFO_NSACSTRING_ GContentHandler::GContentHandler() +: mUserTime(0) { LOG ("GContentHandler ctor (%p)", this); } #else -GContentHandler::GContentHandler() : mMimeType(nsnull) +GContentHandler::GContentHandler() +: mMimeType(nsnull) +, mUserTime(0) { LOG ("GContentHandler ctor (%p)", this); } @@ -156,6 +164,9 @@ NS_IMETHODIMP GContentHandler::PromptForSaveToFile( GTK_WINDOW (dialog)); } + /* FIXME: this will only be the real user time if we came from ::Show */ + ephy_gui_window_update_user_time (GTK_WIDGET (dialog), (guint32) mUserTime); + /* FIXME: modal -- mozilla sucks! */ do { @@ -267,7 +278,7 @@ NS_METHOD GContentHandler::MIMEConfirmAction () { dialog = gtk_message_dialog_new (parentWindow, GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE, + GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, /* translators: %s is the name of the application */ _("Open this file with \"%s\"?"), mHelperApp->name); @@ -283,7 +294,7 @@ NS_METHOD GContentHandler::MIMEConfirmAction () { dialog = gtk_message_dialog_new (parentWindow, GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE, + GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, _("Download the file?")); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), @@ -312,6 +323,10 @@ NS_METHOD GContentHandler::MIMEConfirmAction () g_signal_connect_data (dialog, "response", G_CALLBACK (response_cb), this, (GClosureNotify) release_cb, (GConnectFlags) 0); + + /* FIXME: should find a way to get the user time of the user action which + * initiated this content handler + */ gtk_window_present (GTK_WINDOW (dialog)); return NS_OK; @@ -361,16 +376,30 @@ NS_METHOD GContentHandler::MIMEInitiateAction (void) NS_METHOD GContentHandler::MIMEDoAction (void) { + /* This is okay, since we either clicked on a button, or we get 0 */ + mUserTime = gtk_get_current_event_time (); + nsCOMPtr mimeInfo; mLauncher->GetMIMEInfo(getter_AddRefs(mimeInfo)); NS_ENSURE_TRUE (mimeInfo, NS_ERROR_FAILURE); if (mAction == CONTENT_ACTION_OPEN) { - nsEmbedString desc; + g_return_val_if_fail (mHelperApp, NS_ERROR_FAILURE); + + const char *id; + id = gnome_vfs_mime_application_get_desktop_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) + */ + char *info; + info = g_strdup_printf ("gnome-default:%d:%s", gtk_get_current_event_time(), id); - NS_CStringToUTF16 (nsEmbedCString ("gnome-default"), + nsEmbedString desc; + NS_CStringToUTF16 (nsEmbedCString (info), NS_CSTRING_ENCODING_UTF8, desc); + g_free (info); /* HACK we use the application description to ask MozDownload to open the file when download diff --git a/embed/mozilla/ContentHandler.h b/embed/mozilla/ContentHandler.h index 3401a68cb..6a8c58472 100644 --- a/embed/mozilla/ContentHandler.h +++ b/embed/mozilla/ContentHandler.h @@ -84,6 +84,7 @@ class GContentHandler : public nsIHelperAppLauncherDialog #else char *mMimeType; #endif + PRUint32 mUserTime; }; #endif /* CONTENT_HANDLER_H */ diff --git a/embed/mozilla/EphyHeaderSniffer.cpp b/embed/mozilla/EphyHeaderSniffer.cpp index 293416b28..7676c245f 100644 --- a/embed/mozilla/EphyHeaderSniffer.cpp +++ b/embed/mozilla/EphyHeaderSniffer.cpp @@ -351,10 +351,17 @@ nsresult EphyHeaderSniffer::PerformSave (nsIURI* inOriginalURI) EphyFileChooser *dialog; GtkWindow *window; const char *title; + guint32 user_time; title = ephy_embed_persist_get_fc_title (EPHY_EMBED_PERSIST (mEmbedPersist)); window = ephy_embed_persist_get_fc_parent (EPHY_EMBED_PERSIST (mEmbedPersist)); + user_time = ephy_embed_persist_get_user_time (EPHY_EMBED_PERSIST (mEmbedPersist)); + if (user_time == 0) + { + g_warning ("EphyHeaderSniffer::PerformSave without valid user time!\n"); + } + dialog = ephy_file_chooser_new (title ? title: _("Save"), GTK_WIDGET (window), GTK_FILE_CHOOSER_ACTION_SAVE, @@ -367,6 +374,7 @@ nsresult EphyHeaderSniffer::PerformSave (nsIURI* inOriginalURI) g_signal_connect (dialog, "response", G_CALLBACK (filechooser_response_cb), this); + ephy_gui_window_update_user_time (GTK_WIDGET (dialog), user_time); gtk_widget_show (GTK_WIDGET (dialog)); g_free (filename); diff --git a/embed/mozilla/MozDownload.cpp b/embed/mozilla/MozDownload.cpp index 8160f2715..140eb98fc 100644 --- a/embed/mozilla/MozDownload.cpp +++ b/embed/mozilla/MozDownload.cpp @@ -61,6 +61,9 @@ #include #undef MOZILLA_STRICT_API +#include +#include + const char* const persistContractID = "@mozilla.org/embedding/browser/nsWebBrowserPersist;1"; MozDownload::MozDownload() : @@ -365,58 +368,61 @@ MozDownload::OnStateChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest, else if (NS_SUCCEEDED (aStatus)) { GnomeVFSMimeApplication *helperApp; -#ifdef MOZ_NSIMIMEINFO_NSACSTRING_ nsEmbedCString mimeType; +#ifdef MOZ_NSIMIMEINFO_NSACSTRING_ rv = mMIMEInfo->GetMIMEType (mimeType); NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); - helperApp = gnome_vfs_mime_get_default_application (mimeType.get()); - nsEmbedString description; mMIMEInfo->GetApplicationDescription (description); nsEmbedCString cDesc; NS_UTF16ToCString (description, NS_CSTRING_ENCODING_UTF8, cDesc); - - /* HACK we use the application description to decide - if we have to open the saved file */ - if ((strcmp (cDesc.get(), "gnome-default") == 0) && - helperApp) #else char *mimeType; rv = mMIMEInfo->GetMIMEType (&mimeType); NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); - helperApp = gnome_vfs_mime_get_default_application (mimeType); + if (mime) + { + mimeType.Assign (mime); + nsMemory::Free (mime); + } PRUnichar *description; mMIMEInfo->GetApplicationDescription (&description); + NS_ENSURE_TRUE (description, NS_ERROR_FAILURE); nsEmbedCString cDesc; NS_UTF16ToCString (nsEmbedString(description), NS_CSTRING_ENCODING_UTF8, cDesc); + nsMemory::Free (description); +#endif + /* HACK we use the application description to decide if we have to open the saved file */ - if (strcmp (cDesc.get(), "gnome-default") == 0 && - helperApp) -#endif + if (g_str_has_suffix (cDesc.get(), "gnome-default:")) { - GList *params = NULL; - char *param; - nsEmbedCString aDest; + /* Format gnome-default:: */ + char **str = g_strsplit (cDesc.get(), ":", -1); + g_return_val_if_fail (g_strv_length (str) != 3, NS_ERROR_FAILURE); - mDestination->GetSpec (aDest); + char *end; + guint32 user_time = strtoul (str[1], &end, 0); - param = gnome_vfs_make_uri_canonical (aDest.get ()); - params = g_list_append (params, param); - gnome_vfs_mime_application_launch (helperApp, params); - g_free (param); + helperApp = gnome_vfs_mime_application_new_from_desktop_id (str[2]); + if (!helperApp) return NS_ERROR_FAILURE; - g_list_free (params); - } + nsEmbedCString aDest; + rv = mDestination->GetSpec (aDest); + NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); - gnome_vfs_mime_application_free (helperApp); + ephy_file_launch_application (helperApp, aDest.get (), user_time); + + gnome_vfs_mime_application_free (helperApp); + g_strfreev (str); + } } } -- cgit v1.2.3