diff options
author | Christian Persch <chpe@cvs.gnome.org> | 2003-10-28 02:05:29 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2003-10-28 02:05:29 +0800 |
commit | e7226bd132c37ef89eb37f8a31b47c31b71ede8e (patch) | |
tree | bf37ad9653c25b3caa834e5fe8bf57c838285468 /embed/mozilla | |
parent | 7b0fe9305597ff7bd10c4dc468ae00eab155ca36 (diff) | |
download | gsoc2013-epiphany-e7226bd132c37ef89eb37f8a31b47c31b71ede8e.tar gsoc2013-epiphany-e7226bd132c37ef89eb37f8a31b47c31b71ede8e.tar.gz gsoc2013-epiphany-e7226bd132c37ef89eb37f8a31b47c31b71ede8e.tar.bz2 gsoc2013-epiphany-e7226bd132c37ef89eb37f8a31b47c31b71ede8e.tar.lz gsoc2013-epiphany-e7226bd132c37ef89eb37f8a31b47c31b71ede8e.tar.xz gsoc2013-epiphany-e7226bd132c37ef89eb37f8a31b47c31b71ede8e.tar.zst gsoc2013-epiphany-e7226bd132c37ef89eb37f8a31b47c31b71ede8e.zip |
Implement filechooser for ASK_DESTINATION.
2003-10-27 Christian Persch <chpe@cvs.gnome.org>
* embed/mozilla/EphyHeaderSniffer.cpp:
* embed/mozilla/EphyHeaderSniffer.h:
Implement filechooser for ASK_DESTINATION.
Diffstat (limited to 'embed/mozilla')
-rw-r--r-- | embed/mozilla/EphyHeaderSniffer.cpp | 90 | ||||
-rw-r--r-- | embed/mozilla/EphyHeaderSniffer.h | 5 |
2 files changed, 79 insertions, 16 deletions
diff --git a/embed/mozilla/EphyHeaderSniffer.cpp b/embed/mozilla/EphyHeaderSniffer.cpp index 76b71a53f..957f9cf19 100644 --- a/embed/mozilla/EphyHeaderSniffer.cpp +++ b/embed/mozilla/EphyHeaderSniffer.cpp @@ -51,6 +51,9 @@ #include "ephy-file-chooser.h" #include "ephy-prefs.h" +#include "ephy-gui.h" +#include "eel-gconf-extensions.h" +#include "ephy-debug.h" #include "nsReadableUtils.h" #include "nsIChannel.h" @@ -72,14 +75,18 @@ EphyHeaderSniffer::EphyHeaderSniffer (nsIWebBrowserPersist* aPersist, MozillaEmb , mEmbedPersist(aEmbedPersist) , mTmpFile(aFile) , mURL(aURL) +, mOriginalURI(nsnull) , mDocument(aDocument) , mPostData(aPostData) { mPrompt = do_GetService("@mozilla.org/embedcomp/prompt-service;1"); + + LOG ("EphyHeaderSniffer constructor") } EphyHeaderSniffer::~EphyHeaderSniffer() { + LOG ("EphyHeaderSniffer destructor") } NS_IMPL_ISUPPORTS2(EphyHeaderSniffer, nsIWebProgressListener, nsIAuthPrompt) @@ -164,15 +171,47 @@ EphyHeaderSniffer::OnSecurityChange (nsIWebProgress *aWebProgress, nsIRequest *a return NS_OK; } +static void +filechooser_response_cb (EphyFileChooser *dialog, gint response, EphyHeaderSniffer* sniffer) +{ + if (response == EPHY_RESPONSE_SAVE) + { + char *filename; + GtkWidget *parent = NULL; // FIXME! + + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); + + LOG ("Filename %s", filename) + + if (filename && + ephy_gui_confirm_overwrite_file (parent, filename) == TRUE) + { + nsCOMPtr<nsILocalFile> destFile = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID); + if (destFile) + { + destFile->InitWithNativePath (nsDependentCString (filename)); + + sniffer->InitiateDownload (destFile); + } + } + } + + // FIXME how to inform user of failed save ? + + gtk_widget_destroy (GTK_WIDGET (dialog)); +} + nsresult EphyHeaderSniffer::PerformSave (nsIURI* inOriginalURI) { nsresult rv; EmbedPersistFlags flags; PRBool askDownloadDest; + mOriginalURI = inOriginalURI; + flags = ephy_embed_persist_get_flags (EPHY_EMBED_PERSIST (mEmbedPersist)); askDownloadDest = flags & EMBED_PERSIST_ASK_DESTINATION; - + nsAutoString defaultFileName; if (defaultFileName.IsEmpty() && !mContentDisposition.IsEmpty()) @@ -236,29 +275,50 @@ nsresult EphyHeaderSniffer::PerformSave (nsIURI* inOriginalURI) } } + const char *key; + key = ephy_embed_persist_get_persist_key (EPHY_EMBED_PERSIST (mEmbedPersist)); + if (askDownloadDest) { - /* FIXME */ - } - else - { - /* FIXME build path from download dir */ - } - - if (defaultFileName.IsEmpty()) - { - defaultFileName.AssignWithConversion(_("Untitled")); + EphyFileChooser *dialog; + GtkWindow *window; + const char *title; + int response; + + title = ephy_embed_persist_get_fc_title (EPHY_EMBED_PERSIST (mEmbedPersist)); + window = ephy_embed_persist_get_fc_parent (EPHY_EMBED_PERSIST (mEmbedPersist)); + + dialog = ephy_file_chooser_new (title ? title: _("Save"), + GTK_WIDGET (window), + GTK_FILE_CHOOSER_ACTION_SAVE, + key ? key : CONF_STATE_DOWNLOADING_DIR); + + gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), + NS_ConvertUCS2toUTF8 (defaultFileName).get()); + + g_signal_connect (dialog, "response", + G_CALLBACK (filechooser_response_cb), this); + + gtk_widget_show (GTK_WIDGET (dialog)); + + return NS_OK; } - + /* FIXME ask user if overwriting ? */ /* FIXME: how to inform user of failed save ? */ nsCOMPtr<nsILocalFile> destFile; rv = NS_NewLocalFile(defaultFileName, PR_TRUE, getter_AddRefs(destFile)); - if (NS_FAILED(rv) || !destFile) return NS_ERROR_FAILURE; + if (NS_FAILED(rv) || !destFile) return NS_ERROR_FAILURE; + + return InitiateDownload (destFile); +} - return InitiateMozillaDownload (mDocument, mURL, destFile, - mContentType.get(), inOriginalURI, mEmbedPersist, +nsresult EphyHeaderSniffer::InitiateDownload (nsILocalFile *aDestFile) +{ + LOG ("Initiating download") + return InitiateMozillaDownload (mDocument, mURL, aDestFile, + mContentType.get(), mOriginalURI, mEmbedPersist, mBypassCache, mPostData); } diff --git a/embed/mozilla/EphyHeaderSniffer.h b/embed/mozilla/EphyHeaderSniffer.h index 3635593e8..c3790cec3 100644 --- a/embed/mozilla/EphyHeaderSniffer.h +++ b/embed/mozilla/EphyHeaderSniffer.h @@ -60,7 +60,9 @@ public: NS_DECL_ISUPPORTS NS_DECL_NSIWEBPROGRESSLISTENER NS_DECL_NSIAUTHPROMPT - + + nsresult InitiateDownload (nsILocalFile *aDestFile); + protected: nsresult PerformSave (nsIURI* inOriginalURI); @@ -69,6 +71,7 @@ private: MozillaEmbedPersist *mEmbedPersist; nsCOMPtr<nsIFile> mTmpFile; nsCOMPtr<nsIURI> mURL; + nsCOMPtr<nsIURI> mOriginalURI; nsCOMPtr<nsIDOMDocument> mDocument; nsCOMPtr<nsIInputStream> mPostData; PRBool mBypassCache; |