diff options
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | data/epiphany.schemas.in | 13 | ||||
-rw-r--r-- | data/glade/prefs-dialog.glade | 5 | ||||
-rw-r--r-- | embed/mozilla/ContentHandler.cpp | 247 | ||||
-rw-r--r-- | embed/mozilla/ContentHandler.h | 29 | ||||
-rw-r--r-- | embed/mozilla/MozDownload.cpp | 29 | ||||
-rw-r--r-- | lib/ephy-prefs.h | 2 | ||||
-rw-r--r-- | src/prefs-dialog.c | 10 |
8 files changed, 186 insertions, 163 deletions
@@ -1,3 +1,17 @@ +2004-01-19 Marco Pesenti Gritti <marco@gnome.org> + + * data/epiphany.schemas.in: + * data/glade/prefs-dialog.glade: + * embed/mozilla/ContentHandler.cpp: + * embed/mozilla/ContentHandler.h: + * embed/mozilla/MozDownload.cpp: + * lib/ephy-prefs.h: + * src/prefs-dialog.c: (get_download_button_label): + + Change default dir to /home/Downloads. Show the + pref about warning on files downloading. Cleanup + warning dialogs a bit. + 2004-01-18 Christian Persch <chpe@cvs.gnome.org> * lib/ephy-dialog.c: (ephy_dialog_hide): diff --git a/data/epiphany.schemas.in b/data/epiphany.schemas.in index 0d33cdc41..283901f71 100644 --- a/data/epiphany.schemas.in +++ b/data/epiphany.schemas.in @@ -132,15 +132,16 @@ </locale> </schema> <schema> - <key>/schemas/apps/epiphany/general/auto_open_downloads</key> - <applyto>/apps/epiphany/general/auto_open_downloads</applyto> + <key>/schemas/apps/epiphany/general/automatic_downloads</key> + <applyto>/apps/epiphany/general/automatic_downloads</applyto> <owner>epiphany</owner> <type>bool</type> <default>true</default> <locale name="C"> - <short>Auto open downloads</short> - <long>Automatically open downloaded files which are "safe" to open, - like videos, images, text documents, compressed files, etc.</long> + <short>Automatic downloads</short> + <long>When files cannot be opened by the browser they are + automatically downloaded to the download folder and opened + with the appropriate application.</long> </locale> </schema> <schema> @@ -404,7 +405,7 @@ <applyto>/apps/epiphany/directories/download</applyto> <owner>epiphany</owner> <type>string</type> - <default>Desktop</default> + <default>~/Downloads</default> <locale name="C"> </locale> </schema> diff --git a/data/glade/prefs-dialog.glade b/data/glade/prefs-dialog.glade index 5b5b809d4..4151244e4 100644 --- a/data/glade/prefs-dialog.glade +++ b/data/glade/prefs-dialog.glade @@ -379,9 +379,10 @@ </child> <child> - <widget class="GtkCheckButton" id="auto_open_downloads_checkbutton"> + <widget class="GtkCheckButton" id="automatic_downloads_checkbutton"> + <property name="visible">True</property> <property name="can_focus">True</property> - <property name="label" translatable="yes">Automatically open "safe" downloads</property> + <property name="label" translatable="yes">Automatically download and open files</property> <property name="use_underline">True</property> <property name="relief">GTK_RELIEF_NORMAL</property> <property name="focus_on_click">True</property> diff --git a/embed/mozilla/ContentHandler.cpp b/embed/mozilla/ContentHandler.cpp index 2b654a509..02f346bd2 100644 --- a/embed/mozilla/ContentHandler.cpp +++ b/embed/mozilla/ContentHandler.cpp @@ -42,6 +42,7 @@ #include "eel-gconf-extensions.h" #include "ephy-embed-single.h" #include "ephy-embed-shell.h" +#include "ephy-file-chooser.h" #include "ephy-debug.h" #include <gtk/gtkimage.h> @@ -76,98 +77,6 @@ GContentHandler::~GContentHandler() // begin nsIHelperAppLauncher impl //////////////////////////////////////////////////////////////////////////////// -/* This is copied verbatim from nsDocShell.h in Mozilla, we should keep it synced */ -/* http://lxr.mozilla.org/mozilla/source/docshell/base/nsDocShell.h */ - -#define MAKE_LOAD_TYPE(type, flags) ((type) | (flags << 16)) - -enum LoadType { - LOAD_NORMAL = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_NONE), - LOAD_NORMAL_REPLACE = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_REPLACE_HISTORY), - LOAD_HISTORY = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_HISTORY, nsIWebNavigation::LOAD_FLAGS_NONE), - LOAD_RELOAD_NORMAL = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_RELOAD, nsIWebNavigation::LOAD_FLAGS_NONE), - LOAD_RELOAD_BYPASS_CACHE = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_RELOAD, nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE), - LOAD_RELOAD_BYPASS_PROXY = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_RELOAD, nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY), - LOAD_RELOAD_BYPASS_PROXY_AND_CACHE = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_RELOAD, nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE | nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY), - LOAD_LINK = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_IS_LINK), - LOAD_REFRESH = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_IS_REFRESH), - LOAD_RELOAD_CHARSET_CHANGE = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_RELOAD, nsIWebNavigation::LOAD_FLAGS_CHARSET_CHANGE), - LOAD_BYPASS_HISTORY = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_BYPASS_HISTORY) -}; - -static GtkWidget* -ch_unrequested_dialog_construct (GtkWindow *parent, const char *title) -{ - GtkWidget *dialog; - GtkWidget *hbox, *vbox, *label, *image; - char *str, *tmp_str, *tmp_title; - - dialog = gtk_dialog_new_with_buttons ("", - GTK_WINDOW (parent), - GTK_DIALOG_NO_SEPARATOR, - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, - GTK_RESPONSE_OK, - NULL); - - gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); - gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); - gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 14); - - hbox = gtk_hbox_new (FALSE, 6); - gtk_widget_show (hbox); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, - TRUE, TRUE, 0); - - image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, - GTK_ICON_SIZE_DIALOG); - gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0); - gtk_widget_show (image); - gtk_box_pack_start (GTK_BOX (hbox), image, TRUE, TRUE, 0); - - vbox = gtk_vbox_new (FALSE, 6); - gtk_widget_show (vbox); - gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0); - - label = gtk_label_new (NULL); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); - tmp_title = g_strconcat ("<b>", title, "</b>", NULL); - tmp_str = g_strdup_printf (_("An unrequested download (%s) has been started.\n Would you like to continue it and open the file?"), - tmp_title); - str = g_strconcat ("<big>", tmp_str, "</big>", NULL); - gtk_label_set_markup (GTK_LABEL (label), str); - g_free (tmp_title); - g_free (tmp_str); - g_free (str); - gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0); - gtk_widget_show (label); - - return dialog; -} - -static void -ch_unrequested_dialog_cb (GtkWidget *dialog, - int response_id, - gpointer user_data) -{ - switch (response_id) - { - case GTK_RESPONSE_OK: - ((GContentHandler*)user_data)->MIMEAskAction (); - break; - case GTK_RESPONSE_CANCEL: - nsCOMPtr<nsIHelperAppLauncher> launcher; - - ((GContentHandler*)user_data)->GetLauncher (getter_AddRefs(launcher)); - launcher->Cancel (); - break; - } - - gtk_widget_destroy (GTK_WIDGET (dialog)); -} - #if MOZILLA_SNAPSHOT > 9 /* void show (in nsIHelperAppLauncher aLauncher, in nsISupports aContext); */ NS_IMETHODIMP GContentHandler::Show(nsIHelperAppLauncher *aLauncher, @@ -194,21 +103,9 @@ NS_IMETHODIMP GContentHandler::Show(nsIHelperAppLauncher *aLauncher, PRUint32 eLoadType; eDocShell->GetLoadType (&eLoadType); - /* We ask the user what to do if he has not explicitely started the download - * (LoadType == LOAD_LINK) */ - - if (eLoadType != LOAD_LINK) { - GtkWidget *dialog; - dialog = ch_unrequested_dialog_construct (NULL, mUrl.get()); - g_signal_connect (G_OBJECT (dialog), - "response", - G_CALLBACK (ch_unrequested_dialog_cb), - this); - gtk_widget_show (dialog); - } - else if (!handled) + if (!handled) { - MIMEAskAction (); + MIMEDoAction (); } else { @@ -228,8 +125,35 @@ NS_IMETHODIMP GContentHandler::PromptForSaveToFile( const PRUnichar *aSuggestedFileExtension, nsILocalFile **_retval) { - return BuildDownloadPath (NS_ConvertUCS2toUTF8 (aDefaultFile).get(), - _retval); + EphyFileChooser *dialog; + gint response; + char *filename; + + if (mAction != CONTENT_ACTION_SAVEAS) + { + return BuildDownloadPath (NS_ConvertUCS2toUTF8 (aDefaultFile).get(), + _retval); + } + + dialog = ephy_file_chooser_new (_("Save"), NULL, + GTK_FILE_CHOOSER_ACTION_SAVE, + CONF_STATE_DOWNLOAD_DIR); + gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), + NS_ConvertUCS2toUTF8 (aDefaultFile).get()); + response = gtk_dialog_run (GTK_DIALOG (dialog)); + + if (response == EPHY_RESPONSE_SAVE) + { + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); + BuildDownloadPath (filename, _retval); + g_free (filename); + + return NS_OK; + } + else + { + return NS_ERROR_FAILURE; + } } #if MOZILLA_SNAPSHOT < 10 @@ -432,32 +356,117 @@ NS_METHOD GContentHandler::ProcessMimeInfo (void) return NS_OK; } -NS_METHOD GContentHandler::MIMEAskAction (void) +NS_METHOD GContentHandler::MIMEConfirmAction () +{ + GtkWidget *dialog; + GtkWidget *hbox, *vbox, *label, *image; + char *text; + int response; + + dialog = gtk_dialog_new_with_buttons + ("", NULL, GTK_DIALOG_NO_SEPARATOR, + _("Save As..."), CONTENT_ACTION_SAVEAS, + GTK_STOCK_CANCEL, CONTENT_ACTION_NONE, + _("Open"), CONTENT_ACTION_OPEN, + NULL); + + gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); + gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); + gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 14); + + hbox = gtk_hbox_new (FALSE, 6); + gtk_widget_show (hbox); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, + TRUE, TRUE, 0); + + if (mPermission != EPHY_MIME_PERMISSION_SAFE) + { + text = g_strdup_printf ("<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s", + _("Do you really want to download the file?"), + _("This type of file could potentially damage your documents" + "or invade your privacy." + "It's not safe to open it directly. You" + "can save it instead.")); + } + if (mAction == CONTENT_ACTION_OPEN) + { + text = g_strdup_printf ("<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s", + _("Open the file in another application?"), + _("It's not possible to view this file type directly " + "in the browser. You can open it with another " + "application or save it.")); + } + else + { + text = g_strdup_printf ("<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s", + _("Download the file?"), + _("It's not possible to view this file because there is no" + "application installed that can open it." + "You can save it instead.")); + } + + image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, + GTK_ICON_SIZE_DIALOG); + gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0); + gtk_widget_show (image); + gtk_box_pack_start (GTK_BOX (hbox), image, TRUE, TRUE, 0); + + vbox = gtk_vbox_new (FALSE, 6); + gtk_widget_show (vbox); + gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0); + + label = gtk_label_new (NULL); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); + gtk_label_set_markup (GTK_LABEL (label), text); + g_free (text); + + gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0); + gtk_widget_show (label); + + mAction = (ContentAction) gtk_dialog_run (GTK_DIALOG (dialog)); + + gtk_widget_destroy (dialog); + + return NS_OK; +} + +NS_METHOD GContentHandler::MIMEDoAction (void) { nsresult rv; - gboolean auto_open; + gboolean auto_downloads; + + if (eel_gconf_get_boolean (CONF_LOCKDOWN_DISABLE_SAVE_TO_DISK)) return NS_OK; - auto_open = eel_gconf_get_boolean (CONF_AUTO_OPEN_DOWNLOADS); + auto_downloads = eel_gconf_get_boolean (CONF_AUTO_DOWNLOADS); GnomeVFSMimeApplication *DefaultApp = gnome_vfs_mime_get_default_application(mMimeType); - EphyMimePermission permission; - permission = ephy_embed_shell_check_mime (embed_shell, mMimeType); - - if (!auto_open || !DefaultApp || permission != EPHY_MIME_PERMISSION_SAFE) + mPermission = ephy_embed_shell_check_mime (embed_shell, mMimeType); + + mAction = CONTENT_ACTION_OPEN; + + if (mPermission != EPHY_MIME_PERMISSION_SAFE) { - if (eel_gconf_get_boolean (CONF_LOCKDOWN_DISABLE_SAVE_TO_DISK)) return NS_OK; + mAction = CONTENT_ACTION_DOWNLOAD; + } + if (!auto_downloads) + { + MIMEConfirmAction (); + } + + if (mAction == CONTENT_ACTION_DOWNLOAD || + mAction == CONTENT_ACTION_SAVEAS) + { nsCOMPtr<nsIHelperAppLauncher> launcher; GetLauncher (getter_AddRefs(launcher)); NS_ENSURE_TRUE (launcher, NS_ERROR_FAILURE); - launcher->SaveToDisk (nsnull,PR_FALSE); } - else + else if (mAction == CONTENT_ACTION_OPEN) { rv = SetHelperApp (DefaultApp, FALSE); NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); - rv = FindHelperApp (); NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); } diff --git a/embed/mozilla/ContentHandler.h b/embed/mozilla/ContentHandler.h index 6234ca584..d07bea0f7 100644 --- a/embed/mozilla/ContentHandler.h +++ b/embed/mozilla/ContentHandler.h @@ -40,6 +40,14 @@ #include "nsISupports.h" #include "nsError.h" +typedef enum +{ + CONTENT_ACTION_OPEN, + CONTENT_ACTION_DOWNLOAD, + CONTENT_ACTION_SAVEAS, + CONTENT_ACTION_NONE +} ContentAction; + #define G_CONTENTHANDLER_CID \ { /* 16072c4a-23a6-4996-9beb-9335c06bbeae */ \ 0x16072c4a, \ @@ -59,18 +67,19 @@ class GContentHandler : public nsIHelperAppLauncherDialog GContentHandler(); virtual ~GContentHandler(); - NS_METHOD FindHelperApp (void); - NS_METHOD LaunchHelperApp (void); + private: + + NS_METHOD Init (); + NS_METHOD ProcessMimeInfo (); + NS_METHOD FindHelperApp (); + NS_METHOD LaunchHelperApp (); NS_METHOD GetLauncher (nsIHelperAppLauncher * *_retval); NS_METHOD SetHelperApp(GnomeVFSMimeApplication *mHelperApp, PRBool alwaysUse); - NS_METHOD SynchroniseMIMEInfo (void); - NS_METHOD MIMEAskAction (void); - private: - /* additional members */ - NS_METHOD Init (void); - NS_METHOD ProcessMimeInfo (void); + NS_METHOD SynchroniseMIMEInfo (); + NS_METHOD MIMEConfirmAction (); + NS_METHOD MIMEDoAction (); nsCOMPtr<nsIHelperAppLauncher> mLauncher; @@ -80,7 +89,9 @@ class GContentHandler : public nsIHelperAppLauncherDialog char *mMimeType; PRBool mUrlHelper; GnomeVFSMimeApplication *mHelperApp; - + ContentAction mAction; + EphyMimePermission mPermission; + nsCString mUrl; nsCString mScheme; }; diff --git a/embed/mozilla/MozDownload.cpp b/embed/mozilla/MozDownload.cpp index 31847a3e1..53205702a 100644 --- a/embed/mozilla/MozDownload.cpp +++ b/embed/mozilla/MozDownload.cpp @@ -491,7 +491,7 @@ nsresult InitiateMozillaDownload (nsIDOMDocument *domDocument, nsIURI *sourceURI static char* GetFilePath (const char *filename) { - char *path, *download_dir; + char *path, *download_dir, *expanded; download_dir = eel_gconf_get_string (CONF_STATE_DOWNLOAD_DIR); if (!download_dir) @@ -500,31 +500,10 @@ GetFilePath (const char *filename) download_dir = g_strdup (g_get_home_dir ()); } - if (!strcmp (download_dir, "Desktop")) - { - if (eel_gconf_get_boolean (CONF_DESKTOP_IS_HOME_DIR)) - { - path = g_build_filename - (g_get_home_dir (), - filename, - NULL); - } - else - { - path = g_build_filename - (g_get_home_dir (), "Desktop", - filename, - NULL); - } - } - else - { - char *expanded; + expanded = gnome_vfs_expand_initial_tilde (download_dir); + path = g_build_filename (expanded, filename, NULL); + g_free (expanded); - expanded = gnome_vfs_expand_initial_tilde (download_dir); - path = g_build_filename (expanded, filename, NULL); - g_free (expanded); - } g_free (download_dir); return path; diff --git a/lib/ephy-prefs.h b/lib/ephy-prefs.h index 91ec12e51..578e97bb1 100644 --- a/lib/ephy-prefs.h +++ b/lib/ephy-prefs.h @@ -33,7 +33,7 @@ G_BEGIN_DECLS #define CONF_WINDOWS_SHOW_BOOKMARKS_BAR "/apps/epiphany/general/show_bookmarks_bar" #define CONF_WINDOWS_SHOW_STATUSBAR "/apps/epiphany/general/show_statusbar" #define CONF_INTERFACE_MIDDLE_CLICK_OPEN_URL "/apps/epiphany/general/middle_click_open_url" -#define CONF_AUTO_OPEN_DOWNLOADS "/apps/epiphany/general/auto_open_downloads" +#define CONF_AUTO_DOWNLOADS "/apps/epiphany/general/automatic_downloads" #define CONF_DESKTOP_IS_HOME_DIR "/apps/nautilus/preferences/desktop_is_home_dir" /* Directories */ diff --git a/src/prefs-dialog.c b/src/prefs-dialog.c index 76fc406ad..c58515dee 100644 --- a/src/prefs-dialog.c +++ b/src/prefs-dialog.c @@ -255,7 +255,7 @@ EphyDialogProperty properties [] = { "homepage_entry", CONF_GENERAL_HOMEPAGE, PT_AUTOAPPLY, G_TYPE_STRING }, { "homepage_current_button", NULL, PT_NORMAL, 0 }, { "homepage_blank_button", NULL, PT_NORMAL, 0 }, - { "auto_open_downloads_checkbutton", CONF_AUTO_OPEN_DOWNLOADS, PT_AUTOAPPLY, 0 }, + { "automatic_downloads_checkbutton", CONF_AUTO_DOWNLOADS, PT_AUTOAPPLY, 0 }, { "download_path_button", NULL, PT_NORMAL, 0 }, /* Fonts and Colors */ @@ -1081,6 +1081,7 @@ static char* get_download_button_label () { char *label, *key, *desktop_path, *home_path, *tmp; + char *downloads_path; key = eel_gconf_get_string (CONF_STATE_DOWNLOAD_DIR); @@ -1089,6 +1090,8 @@ get_download_button_label () home_path = g_filename_to_utf8 (g_get_home_dir (), -1, NULL, NULL, NULL); g_free (tmp); + downloads_path = g_build_filename (g_get_home_dir (), "Downloads", NULL); + if (g_utf8_collate (key, desktop_path) == 0) { g_free (key); @@ -1103,6 +1106,11 @@ get_download_button_label () * filechooser */ label = g_strdup (_("Home")); } + else if (g_utf8_collate (key, downloads_path) == 0) + { + g_free (key); + label = g_strdup (_("Downloads")); + } else { label = key; |