aboutsummaryrefslogtreecommitdiffstats
path: root/embed/mozilla
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2003-10-26 18:45:56 +0800
committerChristian Persch <chpe@src.gnome.org>2003-10-26 18:45:56 +0800
commiteb6b2cdb2e89e41759cf3b1cd136cfca42e6e42b (patch)
tree9c1ae176d61be345a8d3295aa9e43e48a43464da /embed/mozilla
parenta34a545dbe35d250c5f5743634909ad2a45f423b (diff)
downloadgsoc2013-epiphany-eb6b2cdb2e89e41759cf3b1cd136cfca42e6e42b.tar
gsoc2013-epiphany-eb6b2cdb2e89e41759cf3b1cd136cfca42e6e42b.tar.gz
gsoc2013-epiphany-eb6b2cdb2e89e41759cf3b1cd136cfca42e6e42b.tar.bz2
gsoc2013-epiphany-eb6b2cdb2e89e41759cf3b1cd136cfca42e6e42b.tar.lz
gsoc2013-epiphany-eb6b2cdb2e89e41759cf3b1cd136cfca42e6e42b.tar.xz
gsoc2013-epiphany-eb6b2cdb2e89e41759cf3b1cd136cfca42e6e42b.tar.zst
gsoc2013-epiphany-eb6b2cdb2e89e41759cf3b1cd136cfca42e6e42b.zip
Port to new gtk+ file chooser.
2003-10-26 Christian Persch <chpe@cvs.gnome.org> Port to new gtk+ file chooser. * data/epiphany.schemas.in: * lib/ephy-prefs.h: Add key for remembering upload path. * embed /Makefile.am: * embed/downloader-view.c: * embed/ephy-embed-persist.c: (ephy_embed_persist_get_type), (ephy_embed_persist_set_dest), (ephy_embed_persist_set_embed), (ephy_embed_persist_set_fc_title), (ephy_embed_persist_set_fc_parent), (ephy_embed_persist_set_flags), (ephy_embed_persist_set_max_size), (ephy_embed_persist_set_persist_key), (ephy_embed_persist_set_source), (ephy_embed_persist_get_dest), (ephy_embed_persist_get_embed), (ephy_embed_persist_get_fc_title), (ephy_embed_persist_get_fc_parent), (ephy_embed_persist_get_flags), (ephy_embed_persist_get_max_size), (ephy_embed_persist_get_persist_key), (ephy_embed_persist_get_source), (ephy_embed_persist_set_property), (ephy_embed_persist_get_property), (ephy_embed_persist_init), (ephy_embed_persist_finalize), (ephy_embed_persist_class_init), (ephy_embed_persist_cancel), (ephy_embed_persist_save), (ephy_embed_persist_new): * embed/ephy-embed-persist.h: * embed/ephy-embed-popup-control.c: (save_url), (save_property_url), (background_download_completed), (embed_popup_set_image_as_background_cmd), (embed_popup_copy_image_location_cmd): * src/popup-commands.c: (save_property_url), (background_download_completed), (popup_cmd_set_image_as_background): * src/window-commands.c: (open_response_cb), (window_cmd_file_open), (window_cmd_file_save_as): * src/window-commands.h: * embed/ephy-favicon-cache.c: (ephy_favicon_cache_get_type), (ephy_favicon_cache_new), (icon_is_obsolete), (icons_added_cb), (remove_obsolete_icons), (ephy_favicon_cache_init), (favicon_download_completed_cb), (ephy_favicon_cache_download), (ephy_favicon_cache_get): * embed/mozilla/MozDownload.cpp: * embed/mozilla/EphyHeaderSniffer.cpp: * embed/mozilla/mozilla-embed-persist.cpp: * embed/mozilla/mozilla-embed-single.cpp: * src/popup-commands.c: (save_property_url), (background_download_completed), (popup_cmd_set_image_as_background): * src/window-commands.c: (open_response_cb), (window_cmd_file_open), (window_cmd_file_save_as): * src/window-commands.h: Simplify EphyEmbedPersist implementation. Augment it with properties for showing a file chooser to select persist destination. Port all callers to new interfaces. * embed/ephy-embed-single.c: (ephy_embed_single_remove_passwords): * embed/ephy-embed-single.h: * embed/ephy-embed-utils.c: * embed/ephy-embed-utils.h: Obsolete and removed. * embed/mozilla/ContentHandler.cpp: * embed/mozilla/ContentHandler.h: Misc cleanups. * embed/mozilla/FilePicker.cpp: * embed/mozilla/FilePicker.h: Port to new file chooser class. * embed/mozilla/Makefile.am: * lib/Makefile.am: * lib/ephy-file-chooser.c: (ephy_file_chooser_get_type), (current_folder_changed_cb), (ephy_file_chooser_init), (ephy_file_chooser_finalize), (ephy_file_chooser_set_persist_key), (ephy_file_chooser_set_property), (ephy_file_chooser_get_property), (ephy_file_chooser_class_init), (ephy_file_chooser_new): * lib/ephy-file-chooser.h: * src/bookmarks/ephy-bookmarks-editor.c: (import_from_file_response_cb), (import_dialog_response_cb): New file chooser wrapper class; ported file chooser callers to it.
Diffstat (limited to 'embed/mozilla')
-rw-r--r--embed/mozilla/ContentHandler.cpp74
-rw-r--r--embed/mozilla/ContentHandler.h5
-rw-r--r--embed/mozilla/EphyHeaderSniffer.cpp26
-rw-r--r--embed/mozilla/FilePicker.cpp503
-rw-r--r--embed/mozilla/FilePicker.h55
-rw-r--r--embed/mozilla/Makefile.am1
-rw-r--r--embed/mozilla/MozDownload.cpp7
-rw-r--r--embed/mozilla/mozilla-embed-persist.cpp9
-rw-r--r--embed/mozilla/mozilla-embed-single.cpp72
9 files changed, 307 insertions, 445 deletions
diff --git a/embed/mozilla/ContentHandler.cpp b/embed/mozilla/ContentHandler.cpp
index 519bff738..7da5ae25c 100644
--- a/embed/mozilla/ContentHandler.cpp
+++ b/embed/mozilla/ContentHandler.cpp
@@ -14,6 +14,8 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Id$
*/
/*
@@ -144,41 +146,17 @@
*/
#ifdef HAVE_CONFIG_H
-#include <config.h>
+#include "config.h"
#endif
-extern "C" {
-#include "libgnomevfs/gnome-vfs-mime-handlers.h"
-}
-
-#include "ephy-embed-shell.h"
-#include "ephy-prefs.h"
-#include "eel-gconf-extensions.h"
-#include "ephy-glade.h"
-#include "ephy-string.h"
-#include "ephy-gui.h"
-#include "ephy-embed-utils.h"
-#include "ephy-file-helpers.h"
#include "ContentHandler.h"
-#include <gtk/gtkentry.h>
-#include <gtk/gtktogglebutton.h>
-#include <gtk/gtkprogress.h>
-#include <gtk/gtkoptionmenu.h>
-#include <libgnome/gnome-exec.h>
-#include <libgnome/gnome-i18n.h>
-#include <libgnome/gnome-config.h>
-#include <libgnome/gnome-util.h>
-#include <libgnomevfs/gnome-vfs-mime.h>
-
#include "FilePicker.h"
#include "MozillaPrivate.h"
-#include "nsCRT.h"
#include "nsCOMPtr.h"
#include "nsISupportsArray.h"
#include "nsIServiceManager.h"
-#include "nsWeakReference.h"
#include "nsString.h"
#include "nsIURI.h"
@@ -190,8 +168,28 @@ extern "C" {
#include "nsIDOMWindowInternal.h"
#include "nsIMIMEInfo.h"
+#include "ephy-embed-shell.h"
+#include "ephy-prefs.h"
+#include "eel-gconf-extensions.h"
+#include "ephy-glade.h"
+#include "ephy-string.h"
+#include "ephy-gui.h"
+#include "ephy-file-helpers.h"
+
+#include <gtk/gtkentry.h>
+#include <gtk/gtktogglebutton.h>
+#include <gtk/gtkprogress.h>
+#include <gtk/gtkoptionmenu.h>
+#include <gtk/gtkdialog.h>
+#include <gtk/gtkmessagedialog.h>
+#include <libgnome/gnome-exec.h>
+#include <libgnome/gnome-i18n.h>
+#include <libgnome/gnome-config.h>
+#include <libgnome/gnome-util.h>
+#include <libgnomevfs/gnome-vfs-mime.h>
+#include <bonobo/bonobo-i18n.h>
+
class GContentHandler;
-//class GDownloadProgressListener;
struct MimeAskActionDialog;
struct HelperAppChooserDialog;
@@ -562,7 +560,7 @@ MimeAskActionDialog::MimeAskActionDialog(GContentHandler *aContentHandler,
GtkWidget *label;
GtkWidget *dialogWidget;
const char *description;
- char ltext[255]; //philipl: Fixed length buffer == potential security problem...
+ char *ltext;
mGXml = ephy_glade_widget_new ("epiphany.glade", "mime_ask_action_dialog",
&dialogWidget, this);
@@ -579,9 +577,10 @@ MimeAskActionDialog::MimeAskActionDialog(GContentHandler *aContentHandler,
description = gnome_vfs_mime_get_description (aMimeType);
if (!description) description = aMimeType;
- g_snprintf (ltext, 255, "<b>%s</b>", description);
+ ltext = g_strdup_printf ("<b>%s</b>", description);
label = glade_xml_get_widget (mGXml, "mime_ask_action_description");
gtk_label_set_markup (GTK_LABEL (label), ltext);
+ g_free (ltext);
gtk_window_set_transient_for (GTK_WINDOW (dialogWidget),
GTK_WINDOW (aParentWidget));
@@ -646,9 +645,24 @@ mime_ask_dialog_open (MimeAskActionDialog *dialog)
delete dialog;
}
else
- {
+ {
+ GtkWidget *message_dialog;
+
mime_ask_dialog_cancel (dialog);
- ephy_embed_utils_nohandler_dialog_run (dialog->mParent);
+
+ /* FIXME mime db shortcut */
+
+ message_dialog = gtk_message_dialog_new
+ (GTK_WINDOW (dialog->mParent),
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ _("No available applications to open "
+ "the specified file."));
+ gtk_dialog_run (GTK_DIALOG (message_dialog));
+ gtk_widget_destroy (message_dialog);
+
+ /* FIXME where is dialog deleted ? */
}
}
diff --git a/embed/mozilla/ContentHandler.h b/embed/mozilla/ContentHandler.h
index d08cf6cbd..3c8a6225f 100644
--- a/embed/mozilla/ContentHandler.h
+++ b/embed/mozilla/ContentHandler.h
@@ -14,6 +14,8 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Id$
*/
#ifndef __ContentHandler_h
@@ -31,6 +33,9 @@
#include "nsIURI.h"
#include "nsILocalFile.h"
+#include "nsCRT.h"
+#include "nsWeakReference.h"
+
#include "nsCOMPtr.h"
#include "nsISupports.h"
#include "nsError.h"
diff --git a/embed/mozilla/EphyHeaderSniffer.cpp b/embed/mozilla/EphyHeaderSniffer.cpp
index 483f0fd01..76b71a53f 100644
--- a/embed/mozilla/EphyHeaderSniffer.cpp
+++ b/embed/mozilla/EphyHeaderSniffer.cpp
@@ -34,7 +34,10 @@
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
- * ***** END LICENSE BLOCK ***** */
+ * ***** END LICENSE BLOCK *****
+ *
+ * $Id$
+ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -46,6 +49,9 @@
#include "EphyHeaderSniffer.h"
#include "netCore.h"
+#include "ephy-file-chooser.h"
+#include "ephy-prefs.h"
+
#include "nsReadableUtils.h"
#include "nsIChannel.h"
#include "nsIHttpChannel.h"
@@ -164,7 +170,7 @@ nsresult EphyHeaderSniffer::PerformSave (nsIURI* inOriginalURI)
EmbedPersistFlags flags;
PRBool askDownloadDest;
- ephy_embed_persist_get_flags (EPHY_EMBED_PERSIST (mEmbedPersist), &flags);
+ flags = ephy_embed_persist_get_flags (EPHY_EMBED_PERSIST (mEmbedPersist));
askDownloadDest = flags & EMBED_PERSIST_ASK_DESTINATION;
nsAutoString defaultFileName;
@@ -176,7 +182,7 @@ nsresult EphyHeaderSniffer::PerformSave (nsIURI* inOriginalURI)
if (index >= 0)
{
/* Take the substring following the prefix. */
- index += 9;
+ index += strlen ("filename=");
nsCAutoString filename;
mContentDisposition.Right(filename, mContentDisposition.Length() - index);
defaultFileName = NS_ConvertUTF8toUCS2(filename);
@@ -232,16 +238,24 @@ nsresult EphyHeaderSniffer::PerformSave (nsIURI* inOriginalURI)
if (askDownloadDest)
{
- /* FIXME show the file selector here */
+ /* FIXME */
}
else
{
/* FIXME build path from download dir */
}
-
+
+ if (defaultFileName.IsEmpty())
+ {
+ defaultFileName.AssignWithConversion(_("Untitled"));
+ }
+
+ /* 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 G_FAILED;
+ if (NS_FAILED(rv) || !destFile) return NS_ERROR_FAILURE;
return InitiateMozillaDownload (mDocument, mURL, destFile,
mContentType.get(), inOriginalURI, mEmbedPersist,
diff --git a/embed/mozilla/FilePicker.cpp b/embed/mozilla/FilePicker.cpp
index 42c17be06..74b3e7bec 100644
--- a/embed/mozilla/FilePicker.cpp
+++ b/embed/mozilla/FilePicker.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2001 Philip Langdale
+ * Copyright (C) 2003 Christian Persch
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -14,45 +15,15 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-/* Things to be aware of:
- *
- * This filepicker, like the mozilla one, does not make an attempt
- * to verify the validity of the initial directory you pass it.
- * It does check that the user doesn't give it a garbage path
- * during use, but it is the caller's responsibility to give a
- * sensible initial path.
*
- * At the current moment, we instantiate the filepicker directly
- * in our contenthandler where there is path verification code
- * and else where through our C wrapper, which also does verification.
- * If, at a future date, you need to instantiate filepicker without
- * using the C wrapper, please verify the initial path. See
- * ContentHandler for a way to do this.
+ * $Id$
*/
#ifdef HAVE_CONFIG_H
-#include <config.h>
+#include "config.h"
#endif
-#include "ephy-string.h"
-#include "ephy-gui.h"
-
-#include <glib/gconvert.h>
-#include <gtk/gtkmain.h>
-#include <gtk/gtksignal.h>
-#include <gtk/gtkmenu.h>
-#include <gtk/gtkmenuitem.h>
-#include <gtk/gtkcheckbutton.h>
-#include <gtk/gtktogglebutton.h>
-#include <gtk/gtkfilesel.h>
-#include <gtk/gtkhbbox.h>
-#include <gtk/gtkoptionmenu.h>
-#include <gtk/gtkmessagedialog.h>
-#include <libgnome/gnome-i18n.h>
-
-#include "nsIFilePicker.h"
+#include "FilePicker.h"
#include "nsCRT.h"
#include "nsCOMPtr.h"
@@ -70,364 +41,308 @@
#include "nsILocalFile.h"
#include "nsIPromptService.h"
#include "nsReadableUtils.h"
+#include "nsIDOMWindow.h"
+#include "nsIDOMWindowInternal.h"
+#include "nsCOMPtr.h"
+#include "nsString.h"
+#include "nsILocalFile.h"
+#include "MozillaPrivate.h"
-#include <libgnome/gnome-util.h>
+#include "ephy-string.h"
+#include "ephy-prefs.h"
+#include "ephy-gui.h"
+#include "ephy-debug.h"
-#include "FilePicker.h"
-#include "MozillaPrivate.h"
+#include <glib/gconvert.h>
+#include <gtk/gtkfilefilter.h>
+#include <gtk/gtkstock.h>
+#include <gtk/gtkmessagedialog.h>
+#include <bonobo/bonobo-i18n.h>
+#include <libgnome/gnome-util.h>
-/* Implementation file */
NS_IMPL_ISUPPORTS1(GFilePicker, nsIFilePicker)
GFilePicker::GFilePicker()
{
NS_INIT_ISUPPORTS();
- /* member initializers and constructor code */
- mFile = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID);
- mDisplayDirectory = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID);
- mDisplayDirectory->InitWithNativePath(nsDependentCString(g_get_home_dir()));
+ LOG ("GFilePicker constructor")
+
+ mDialog = EPHY_FILE_CHOOSER (g_object_new (EPHY_TYPE_FILE_CHOOSER,
+ "persist-key", CONF_STATE_UPLOAD_DIR,
+ NULL));
+
+ mMode = nsIFilePicker::modeOpen;
}
GFilePicker::~GFilePicker()
{
- /* destructor code */
-}
+ LOG ("GFilePicker destructor")
-////////////////////////////////////////////////////////////////////////////////
-// begin nsIFilePicker impl
-////////////////////////////////////////////////////////////////////////////////
+ if (mDialog)
+ {
+ gtk_widget_destroy (GTK_WIDGET (mDialog));
+ }
+}
/* void init (in nsIDOMWindowInternal parent, in wstring title, in short mode); */
-NS_IMETHODIMP GFilePicker::Init(nsIDOMWindowInternal *aParent,
- const PRUnichar *aTitle, PRInt16 aMode)
+NS_IMETHODIMP GFilePicker::Init(nsIDOMWindowInternal *parent, const PRUnichar *title, PRInt16 mode)
{
- mParent = do_QueryInterface(aParent);
- mParentWidget = MozillaFindGtkParent(mParent);
- mTitle = NS_ConvertUCS2toUTF8(aTitle);
- mMode = aMode;
+ nsCOMPtr<nsIDOMWindow> dw = do_QueryInterface (parent);
+ if (!dw) return NS_ERROR_FAILURE;
+
+ GtkWidget *pwin = MozillaFindGtkParent (dw);
+
+ gtk_window_set_transient_for (GTK_WINDOW (mDialog), GTK_WINDOW (pwin));
+
+ gtk_window_set_title (GTK_WINDOW (mDialog), NS_ConvertUCS2toUTF8 (title).get());
+
+ mMode = mode;
+
+ switch (mode)
+ {
+ case nsIFilePicker::modeOpen:
+ case nsIFilePicker::modeGetFolder:
+ case nsIFilePicker::modeOpenMultiple:
+ gtk_file_chooser_set_action (GTK_FILE_CHOOSER (mDialog),
+ GTK_FILE_CHOOSER_ACTION_OPEN);
+
+ gtk_dialog_add_buttons (GTK_DIALOG (mDialog),
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, EPHY_RESPONSE_OPEN,
+ NULL);
+ break;
+ case nsIFilePicker::modeSave:
+ gtk_file_chooser_set_action (GTK_FILE_CHOOSER (mDialog),
+ GTK_FILE_CHOOSER_ACTION_SAVE);
+ gtk_dialog_add_buttons (GTK_DIALOG (mDialog),
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_SAVE, EPHY_RESPONSE_SAVE,
+ NULL);
+ break;
+ }
+
+ gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (mDialog),
+ mode == nsIFilePicker::modeOpenMultiple);
+
+ gtk_file_chooser_set_folder_mode (GTK_FILE_CHOOSER (mDialog),
+ mode == nsIFilePicker::modeGetFolder);
+
return NS_OK;
}
/* void appendFilters (in long filterMask); */
-NS_IMETHODIMP GFilePicker::AppendFilters(PRInt32 aFilterMask)
+NS_IMETHODIMP GFilePicker::AppendFilters(PRInt32 filterMask)
{
- //This function cannot be implemented due to the crippled
- //nature of GtkFileSelection, but NS_ERROR_NOT_IMPLEMENTED
- //is interpreted as a terminal error by some callers.
+ // http://lxr.mozilla.org/seamonkey/source/xpfe/components/filepicker/res/locale/en-US/filepicker.properties
+ // http://lxr.mozilla.org/seamonkey/source/xpfe/components/filepicker/src/nsFilePicker.js line 131 ff
+
+ // FIXME: use filters with mimetypes instead of extensions
+
+ if (filterMask & nsIFilePicker::filterAll)
+ {
+ AppendFilter (NS_ConvertUTF8toUCS2 (_("All files")).get(),
+ NS_LITERAL_STRING ("*").get());
+ }
+ if (filterMask & nsIFilePicker::filterHTML)
+ {
+ AppendFilter (NS_ConvertUTF8toUCS2 (_("HTML files")).get(),
+ NS_LITERAL_STRING ("*.html; *.htm; *.shtml; *.xhtml").get());
+ }
+ if (filterMask & nsIFilePicker::filterText)
+ {
+ AppendFilter (NS_ConvertUTF8toUCS2 (_("Text files")).get(),
+ NS_LITERAL_STRING ("*.txt; *.text").get());
+ }
+ if (filterMask & nsIFilePicker::filterImages)
+ {
+ AppendFilter (NS_ConvertUTF8toUCS2 (_("Image files")).get(),
+ NS_LITERAL_STRING ("*.png; *.gif; *.jpeg; *.jpg").get());
+ }
+ if (filterMask & nsIFilePicker::filterXML)
+ {
+ AppendFilter (NS_ConvertUTF8toUCS2 (_("XML files")).get(),
+ NS_LITERAL_STRING ("*.xml").get());
+ }
+ if (filterMask & nsIFilePicker::filterXUL)
+ {
+ AppendFilter (NS_ConvertUTF8toUCS2 (_("XUL files")).get(),
+ NS_LITERAL_STRING ("*.xul").get());
+ }
+
return NS_OK;
}
/* void appendFilter (in wstring title, in wstring filter); */
-NS_IMETHODIMP GFilePicker::AppendFilter(const PRUnichar *aTitle,
- const PRUnichar *aFilter)
+NS_IMETHODIMP GFilePicker::AppendFilter(const PRUnichar *title, const PRUnichar *filter)
{
- //GtkFileSelection is crippled, so we can't provide a short-list
- //of filters to choose from. We provide minimal functionality
- //by using the most recent AppendFilter call as the active filter.
- mFilter = NS_ConvertUCS2toUTF8(aFilter);
- return NS_OK;
-}
+ GtkFileFilter *filth;
+
+ filth = gtk_file_filter_new ();
+
+ gtk_file_filter_set_name (filth, NS_ConvertUCS2toUTF8(title).get());
+ gtk_file_filter_add_pattern (filth, NS_ConvertUCS2toUTF8(filter).get());
+
+ gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (mDialog), filth);
-/* attribute long filterIndex; */
-NS_IMETHODIMP GFilePicker::GetFilterIndex(PRInt32 *aFilterIndex)
-{
- return NS_ERROR_NOT_IMPLEMENTED;
-}
-NS_IMETHODIMP GFilePicker::SetFilterIndex(PRInt32 aFilterIndex)
-{
return NS_OK;
}
/* attribute wstring defaultString; */
-NS_IMETHODIMP GFilePicker::GetDefaultString(PRUnichar * *aDefaultString)
+NS_IMETHODIMP GFilePicker::GetDefaultString(PRUnichar **aDefaultString)
{
- gsize bytesWritten;
- gchar *utf8DefaultString = g_filename_to_utf8(mDefaultString.get(), -1,
- NULL,
- &bytesWritten, NULL);
+ char *filename, *converted;
- *aDefaultString = ToNewUnicode(NS_ConvertUTF8toUCS2(utf8DefaultString));
- g_free(utf8DefaultString);
+ filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (mDialog));
+ if (filename != NULL)
+ {
+ converted = g_filename_to_utf8(filename, -1, NULL, NULL, NULL);
+
+ *aDefaultString = ToNewUnicode (NS_ConvertUTF8toUCS2 (converted));
+
+ g_free (filename);
+ g_free (converted);
+ }
return NS_OK;
}
+
NS_IMETHODIMP GFilePicker::SetDefaultString(const PRUnichar *aDefaultString)
{
if (aDefaultString)
{
- gsize bytesWritten;
- gchar *localeDefaultString =
- g_filename_from_utf8(NS_ConvertUCS2toUTF8(aDefaultString).get(),
- -1, NULL,
- &bytesWritten, NULL);
- mDefaultString = localeDefaultString;
- g_free(localeDefaultString);
+ /* set_current_name takes UTF-8, not a filename */
+ gtk_file_chooser_set_current_name
+ (GTK_FILE_CHOOSER (mDialog),
+ NS_ConvertUCS2toUTF8 (aDefaultString).get());
}
- else
- mDefaultString = "";
+
return NS_OK;
}
/* attribute wstring defaultExtension; */
-// Again, due to the crippled file selector, we can't really
-// do anything here.
-NS_IMETHODIMP GFilePicker::GetDefaultExtension(PRUnichar * *aDefaultExtension)
-{
- return NS_ERROR_NOT_IMPLEMENTED;
-}
-NS_IMETHODIMP GFilePicker::SetDefaultExtension(const PRUnichar *aDefaultExtension)
-{
- return NS_OK;
-}
-
-/* attribute nsILocalFile displayDirectory; */
-NS_IMETHODIMP GFilePicker::GetDisplayDirectory(nsILocalFile * *aDisplayDirectory)
+NS_IMETHODIMP GFilePicker::GetDefaultExtension(PRUnichar **aDefaultExtension)
{
- NS_IF_ADDREF(*aDisplayDirectory = mDisplayDirectory);
- return NS_OK;
-}
-NS_IMETHODIMP GFilePicker::SetDisplayDirectory(nsILocalFile * aDisplayDirectory)
-{
- mDisplayDirectory = aDisplayDirectory;
- return NS_OK;
+ return NS_ERROR_NOT_IMPLEMENTED;
}
-/* readonly attribute nsILocalFile file; */
-NS_IMETHODIMP GFilePicker::GetFile(nsILocalFile * *aFile)
+NS_IMETHODIMP GFilePicker::SetDefaultExtension(const PRUnichar *aDefaultExtension)
{
- NS_IF_ADDREF(*aFile = mFile);
- return NS_OK;
+ return NS_ERROR_NOT_IMPLEMENTED;
}
-/* readonly attribute nsIFileURL fileURL; */
-NS_IMETHODIMP GFilePicker::GetFileURL(nsIFileURL * *aFileURL)
+/* attribute long filterIndex; */
+NS_IMETHODIMP GFilePicker::GetFilterIndex(PRInt32 *aFilterIndex)
{
- nsCOMPtr<nsIFileURL> fileURL =
- do_CreateInstance(NS_STANDARDURL_CONTRACTID);
- fileURL->SetFile(mFile);
- NS_IF_ADDREF(*aFileURL = fileURL);
- return NS_OK;
+ return NS_ERROR_NOT_IMPLEMENTED;
}
-/* readonly attribute nsISimpleEnumerator files; */
-NS_IMETHODIMP GFilePicker::GetFiles(nsISimpleEnumerator * *aFiles)
+NS_IMETHODIMP GFilePicker::SetFilterIndex(PRInt32 aFilterIndex)
{
- return NS_ERROR_NOT_IMPLEMENTED;
+ return NS_ERROR_NOT_IMPLEMENTED;
}
-/* short show (); */
-NS_IMETHODIMP GFilePicker::Show(PRInt16 *_retval)
+/* attribute nsILocalFile displayDirectory; */
+NS_IMETHODIMP GFilePicker::GetDisplayDirectory(nsILocalFile **aDisplayDirectory)
{
- mFileSelector = gtk_file_selection_new(mTitle.get());
+ char *dir = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (mDialog));
- nsCAutoString cFileName;
- if(mMode == nsIFilePicker::modeGetFolder)
- cFileName.Assign("");
- else
- cFileName = mDefaultString;
-
- nsCAutoString cDirName;
- mDisplayDirectory->GetNativePath(cDirName);
-
- nsCAutoString cFullPath;
- cFullPath.Assign(cDirName + NS_LITERAL_CSTRING("/") + cFileName);
- gtk_file_selection_set_filename(GTK_FILE_SELECTION(mFileSelector),
- cFullPath.get());
-
- if (!mFilter.IsEmpty())
- {
- gtk_file_selection_complete(GTK_FILE_SELECTION(mFileSelector),
- mFilter.get());
- }
-
- if (mParentWidget)
- gtk_window_set_transient_for(GTK_WINDOW(mFileSelector),
- GTK_WINDOW(mParentWidget));
-
- if (mMode == nsIFilePicker::modeGetFolder)
+ if (dir != NULL)
{
- gtk_widget_set_sensitive(GTK_FILE_SELECTION(mFileSelector)
- ->file_list, FALSE);
- }
-
- gtk_window_set_modal(GTK_WINDOW(mFileSelector), TRUE);
-
- gint retVal = gtk_dialog_run(GTK_DIALOG(mFileSelector));
+ nsCOMPtr<nsILocalFile> file = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID);
+ file->InitWithNativePath (nsDependentCString (dir));
+ NS_IF_ADDREF (*aDisplayDirectory = file);
- HandleFilePickerResult();
-
- if (retVal != GTK_RESPONSE_OK)
- {
- *_retval = returnCancel;
- }
- else
- {
- ValidateFilePickerResult(_retval);
+ g_free (dir);
}
- gtk_widget_destroy(mFileSelector);
-
return NS_OK;
}
-////////////////////////////////////////////////////////////////////////////////
-// begin local public methods impl
-////////////////////////////////////////////////////////////////////////////////
-
-NS_METHOD GFilePicker::InitWithGtkWidget (GtkWidget *aParentWidget,
- const char *aTitle, PRInt16 aMode)
+NS_IMETHODIMP GFilePicker::SetDisplayDirectory(nsILocalFile *aDisplayDirectory)
{
- mParentWidget = aParentWidget;
+ nsCAutoString dir;
+ aDisplayDirectory->GetNativePath (dir);
- mTitle = nsDependentCString(aTitle);
-
- mMode = aMode;
-
- mFile = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID);
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (mDialog),
+ dir.get());
return NS_OK;
}
-NS_METHOD GFilePicker::SanityCheck (PRBool *retIsSane)
+/* readonly attribute nsILocalFile file; */
+NS_IMETHODIMP GFilePicker::GetFile(nsILocalFile **aFile)
{
- *retIsSane = PR_TRUE;
-
- nsresult rv;
- PRBool dirExists, fileExists = PR_TRUE;
+ char *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (mDialog));
- if (mDisplayDirectory)
+ if (filename != NULL)
{
- rv = mDisplayDirectory->Exists (&dirExists);
- g_return_val_if_fail (NS_SUCCEEDED(rv), rv);
- }
- else
- {
- dirExists = PR_FALSE;
- }
-
- if (mMode != nsIFilePicker::modeGetFolder)
- {
- rv = mFile->Exists (&fileExists);
- g_return_val_if_fail (NS_SUCCEEDED(rv), rv);
- }
-
- if (mMode == nsIFilePicker::modeSave && !fileExists)
- {
- return NS_OK;
- }
+ nsCOMPtr<nsILocalFile> file = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID);
+ file->InitWithNativePath (nsDependentCString (filename));
+ NS_IF_ADDREF (*aFile = file);
- if (!dirExists || !fileExists)
- {
- GtkWidget *errorDialog = gtk_message_dialog_new (
- NULL,
- GTK_DIALOG_MODAL,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- _("The specified path does not exist."));
-
- if (mParentWidget)
- gtk_window_set_transient_for(GTK_WINDOW(errorDialog),
- GTK_WINDOW(mFileSelector));
-
- gtk_window_set_modal (GTK_WINDOW(errorDialog), TRUE);
- gtk_dialog_run (GTK_DIALOG(errorDialog));
- gtk_widget_destroy (errorDialog);
- *retIsSane = PR_FALSE;
- return NS_OK;
+ g_free (filename);
}
- PRBool correctType;
- char *errorText;
- if (mMode == nsIFilePicker::modeGetFolder)
- {
- rv = mDisplayDirectory->IsDirectory (&correctType);
- g_return_val_if_fail (NS_SUCCEEDED(rv), rv);
- errorText = g_strdup (_("A file was selected when a "
- "folder was expected."));
- }
- else
- {
- rv = mFile->IsFile (&correctType);
- g_return_val_if_fail (NS_SUCCEEDED(rv), rv);
- errorText = g_strdup (_("A folder was selected when a "
- "file was expected."));
- }
+ return NS_OK;
+}
+
+/* readonly attribute nsIFileURL fileURL; */
+NS_IMETHODIMP GFilePicker::GetFileURL(nsIFileURL **aFileURL)
+{
+ nsCOMPtr<nsILocalFile> file;
+ GetFile (getter_AddRefs(file));
- if(!correctType)
- {
- GtkWidget *errorDialog = gtk_message_dialog_new (
- NULL,
- GTK_DIALOG_MODAL,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- errorText);
-
- if (mParentWidget)
- gtk_window_set_transient_for(GTK_WINDOW(errorDialog),
- GTK_WINDOW(mFileSelector));
-
- gtk_window_set_modal (GTK_WINDOW(errorDialog), TRUE);
- gtk_dialog_run (GTK_DIALOG(errorDialog));
- gtk_widget_destroy (errorDialog);
- *retIsSane = PR_FALSE;
- }
- g_free (errorText);
+ nsCOMPtr<nsIFileURL> fileURL = do_CreateInstance (NS_STANDARDURL_CONTRACTID);
+ fileURL->SetFile(file);
+ NS_IF_ADDREF(*aFileURL = fileURL);
return NS_OK;
}
-////////////////////////////////////////////////////////////////////////////////
-// begin local private methods impl
-////////////////////////////////////////////////////////////////////////////////
+/* readonly attribute nsISimpleEnumerator files; */
+NS_IMETHODIMP GFilePicker::GetFiles(nsISimpleEnumerator * *aFiles)
+{
+ // Not sure if we need to implement it at all, it's used nowhere
+ // in mozilla, but I guess a javascript might call it?
+
+ return NS_ERROR_NOT_IMPLEMENTED;
+}
-NS_METHOD GFilePicker::HandleFilePickerResult()
+/* short show (); */
+NS_IMETHODIMP GFilePicker::Show(PRInt16 *_retval)
{
- const char *fileName = gtk_file_selection_get_filename(GTK_FILE_SELECTION(mFileSelector));
+ gtk_window_set_modal (GTK_WINDOW (mDialog), TRUE);
- if (!fileName || strlen(fileName) == 0) return NS_ERROR_FAILURE;
+ gtk_widget_show (GTK_WIDGET (mDialog));
- const nsACString &cFileName = nsDependentCString(fileName);
- mFile->InitWithNativePath(cFileName);
+ int response = gtk_dialog_run (GTK_DIALOG (mDialog));
- if (mMode == nsIFilePicker::modeGetFolder)
+ switch (response)
{
- mDisplayDirectory->InitWithNativePath(cFileName);
- mDefaultString = "";
- }
- else
- {
- nsCOMPtr<nsIFile> directory;
- mFile->GetParent(getter_AddRefs(directory));
- mDisplayDirectory = do_QueryInterface(directory);
- mFile->GetNativeLeafName(mDefaultString);
+ case EPHY_RESPONSE_OPEN:
+ case EPHY_RESPONSE_SAVE:
+ *_retval = nsIFilePicker::returnOK;
+ break;
+ default:
+ *_retval = nsIFilePicker::returnCancel;
+ break;
}
- return NS_OK;
-}
-
-NS_METHOD GFilePicker::ValidateFilePickerResult(PRInt16 *retval)
-{
- nsresult rv;
- const char *fileName = gtk_file_selection_get_filename(GTK_FILE_SELECTION(mFileSelector));
+ char *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (mDialog));
- *retval = returnCancel;
-
- PRBool passesSanityCheck;
- rv = SanityCheck(&passesSanityCheck);
- if (NS_SUCCEEDED(rv) && !passesSanityCheck) return NS_ERROR_FAILURE;
-
- if (mMode == nsIFilePicker::modeSave)
+ if (filename == NULL)
+ {
+ *_retval = nsIFilePicker::returnCancel;
+ }
+ else if (mMode == nsIFilePicker::modeSave
+ && ephy_gui_confirm_overwrite_file (GTK_WIDGET (mDialog), filename) == FALSE)
{
- if (!ephy_gui_confirm_overwrite_file (mFileSelector,
- fileName))
- {
- return NS_OK;
- }
+ *_retval = nsIFilePicker::returnCancel;
}
- *retval = returnOK;
+ g_free (filename);
return NS_OK;
}
diff --git a/embed/mozilla/FilePicker.h b/embed/mozilla/FilePicker.h
index 430e8d854..cf6a7f68f 100644
--- a/embed/mozilla/FilePicker.h
+++ b/embed/mozilla/FilePicker.h
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2001 Philip Langdale
+ * Copyright (C) 2003 Christian Persch
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -14,20 +15,17 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Id$
*/
-#ifndef __FilePicker_h
-#define __FilePicker_h
+#ifndef EPHY_FILEPICKER_H
+#define EPHY_FILEPICKER_H
+
+#include <nsIFilePicker.h>
+#include <nsISupports.h>
-#include "nsIFilePicker.h"
-#include "nsError.h"
-#include "nsIDOMWindow.h"
-#include "nsIDOMWindowInternal.h"
-#include "nsCOMPtr.h"
-#include "nsString.h"
-#include "nsILocalFile.h"
-#include <gtk/gtktogglebutton.h>
-#include "ephy-embed-shell.h"
+#include "ephy-file-chooser.h"
#define G_FILEPICKER_CID \
{ /* 3636dc79-0b42-4bad-8a3f-ae15d3671d17 */ \
@@ -37,48 +35,25 @@
{0x8a, 0x3f, 0xae, 0x15, 0xd3, 0x67, 0x1d, 0x17} \
}
-#define G_FILEPICKER_CONTRACTID "@mozilla.org/filepicker;1"
-#define G_FILEPICKER_CLASSNAME "Epiphany's File Picker Implementation"
+#define G_FILEPICKER_CONTRACTID "@mozilla.org/filepicker;1"
+#define G_FILEPICKER_CLASSNAME "Epiphany File Picker Implementation"
class nsIFactory;
extern nsresult NS_NewFilePickerFactory(nsIFactory** aFactory);
-/* Header file */
class GFilePicker : public nsIFilePicker
{
- public:
+public:
NS_DECL_ISUPPORTS
NS_DECL_NSIFILEPICKER
- enum { returnOK = nsIFilePicker::returnOK,
- returnCancel = nsIFilePicker::returnCancel,
- returnReplace = nsIFilePicker::returnReplace };
-
+
GFilePicker();
virtual ~GFilePicker();
- /* additional members */
- NS_METHOD InitWithGtkWidget(GtkWidget *aParentWidget,
- const char *aTitle, PRInt16 aMode);
- NS_METHOD SanityCheck(PRBool *retIsSane);
-
- private:
- NS_METHOD HandleFilePickerResult();
- NS_METHOD ValidateFilePickerResult(PRInt16 *retval);
-
- nsCOMPtr<nsIDOMWindow> mParent;
-
- nsCString mTitle;
- nsCString mFilter;
- nsCString mDefaultString;
-
- nsCOMPtr<nsILocalFile> mFile;
- nsCOMPtr<nsILocalFile> mDisplayDirectory;
-
+private:
+ EphyFileChooser *mDialog;
PRInt16 mMode;
-
- GtkWidget *mParentWidget;
- GtkWidget *mFileSelector;
};
#endif
diff --git a/embed/mozilla/Makefile.am b/embed/mozilla/Makefile.am
index 9f80eb1c1..d73ef4794 100644
--- a/embed/mozilla/Makefile.am
+++ b/embed/mozilla/Makefile.am
@@ -35,6 +35,7 @@ INCLUDES = \
-I$(MOZILLA_INCLUDE_ROOT)/webshell \
-I$(MOZILLA_INCLUDE_ROOT)/widget \
-I$(MOZILLA_INCLUDE_ROOT)/windowwatcher \
+ -I$(MOZILLA_INCLUDE_ROOT)/xpcom \
$(GCONF_CFLAGS) \
$(EPIPHANY_DEPENDENCY_CFLAGS) \
-DG_DISABLE_DEPRECATED \
diff --git a/embed/mozilla/MozDownload.cpp b/embed/mozilla/MozDownload.cpp
index e6ee3d0eb..63901ee35 100644
--- a/embed/mozilla/MozDownload.cpp
+++ b/embed/mozilla/MozDownload.cpp
@@ -36,7 +36,10 @@
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
- * ***** END LICENSE BLOCK ***** */
+ * ***** END LICENSE BLOCK *****
+ *
+ * $Id$
+ */
#include "MozDownload.h"
#include "mozilla-download.h"
@@ -85,7 +88,7 @@ MozDownload::Init(nsIURI *aSource, nsILocalFile *aTarget, const PRUnichar *aDisp
{
EmbedPersistFlags flags;
- ephy_embed_persist_get_flags (EPHY_EMBED_PERSIST (mEmbedPersist), &flags);
+ flags = ephy_embed_persist_get_flags (EPHY_EMBED_PERSIST (mEmbedPersist));
addToView = !(flags & EMBED_PERSIST_NO_VIEW);
}
diff --git a/embed/mozilla/mozilla-embed-persist.cpp b/embed/mozilla/mozilla-embed-persist.cpp
index 8ba3596e8..53443246f 100644
--- a/embed/mozilla/mozilla-embed-persist.cpp
+++ b/embed/mozilla/mozilla-embed-persist.cpp
@@ -18,11 +18,15 @@
* $Id$
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "mozilla-embed-persist.h"
+#include "mozilla-embed.h"
#include "EphyWrapper.h"
#include "EphyHeaderSniffer.h"
#include "MozDownload.h"
-#include "mozilla-embed.h"
-#include "mozilla-embed-persist.h"
#include <stddef.h>
#include <nsIWebBrowserPersist.h>
@@ -49,7 +53,6 @@ impl_cancel (EphyEmbedPersist *persist);
struct MozillaEmbedPersistPrivate
{
nsCOMPtr<nsIWebBrowserPersist> mPersist;
-// GProgressListener *mProgress;
};
static GObjectClass *parent_class = NULL;
diff --git a/embed/mozilla/mozilla-embed-single.cpp b/embed/mozilla/mozilla-embed-single.cpp
index 8f1ce3939..5c1f83040 100644
--- a/embed/mozilla/mozilla-embed-single.cpp
+++ b/embed/mozilla/mozilla-embed-single.cpp
@@ -33,7 +33,6 @@
#include "eel-gconf-extensions.h"
#include "ephy-embed-prefs.h"
#include "MozRegisterComponents.h"
-#include "FilePicker.h"
#include <time.h>
#include <libgnome/gnome-i18n.h>
@@ -55,6 +54,8 @@
#include <nsICookie.h>
#include <nsCCookieManager.h>
#include <nsCPasswordManager.h>
+#include <nsString.h>
+#include <nsILocalFile.h>
// FIXME: For setting the locale. hopefully gtkmozembed will do itself soon
#include <nsIChromeRegistry.h>
@@ -98,16 +99,6 @@ static gresult
impl_remove_passwords (EphyEmbedSingle *shell,
GList *passwords,
PasswordType type);
-static gresult
-impl_show_file_picker (EphyEmbedSingle *shell,
- GtkWidget *parentWidget,
- const char *title,
- const char *directory,
- const char *file,
- FilePickerMode mode,
- char **ret_fullpath,
- FileFormat *file_formats,
- int *ret_file_format);
static void mozilla_embed_single_new_window_orphan_cb (GtkMozEmbedSingle *embed,
GtkMozEmbed **retval,
@@ -172,7 +163,6 @@ mozilla_embed_single_class_init (MozillaEmbedSingleClass *klass)
shell_class->remove_cookies = impl_remove_cookies;
shell_class->list_passwords = impl_list_passwords;
shell_class->remove_passwords = impl_remove_passwords;
- shell_class->show_file_picker = impl_show_file_picker;
g_type_class_add_private (object_class, sizeof(MozillaEmbedSinglePrivate));
}
@@ -779,61 +769,3 @@ impl_remove_passwords (EphyEmbedSingle *shell,
return G_OK;
}
-
-static gresult
-impl_show_file_picker (EphyEmbedSingle *shell,
- GtkWidget *parentWidget,
- const char *title,
- const char *directory,
- const char *file,
- FilePickerMode mode,
- char **ret_fullpath,
- FileFormat *file_formats,
- int *ret_file_format)
-{
- char *expanded_directory = NULL;
- gresult result;
-
- GFilePicker *filePicker = new GFilePicker ();
-
- if (directory != NULL)
- {
- expanded_directory = gnome_vfs_expand_initial_tilde (directory);
- }
-
- /* make sure the directory exists, and use the home directory
- * otherwise */
- if (!expanded_directory ||
- !g_file_test (expanded_directory, G_FILE_TEST_IS_DIR))
- {
- g_free (expanded_directory);
- expanded_directory = g_strdup (g_get_home_dir());
- }
-
- nsCOMPtr<nsILocalFile> dir =
- do_CreateInstance (NS_LOCAL_FILE_CONTRACTID);
- dir->InitWithNativePath (nsDependentCString(expanded_directory));
- g_free (expanded_directory);
-
- filePicker->InitWithGtkWidget (parentWidget, title, mode);
- if (file)
- {
- filePicker->SetDefaultString (NS_ConvertUTF8toUCS2(file).get());
- }
- filePicker->SetDisplayDirectory (dir);
-
- PRInt16 retval;
- filePicker->Show (&retval);
-
- nsCOMPtr<nsILocalFile> local_file;
- filePicker->GetFile (getter_AddRefs(local_file));
- nsCAutoString tempFullPathStr;
- local_file->GetNativePath (tempFullPathStr);
- *ret_fullpath = g_strdup (tempFullPathStr.get());
-
- result = (retval == nsIFilePicker::returnCancel) ? G_FAILED : G_OK;
-
- delete filePicker;
-
- return result;
-}