aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog20
-rw-r--r--embed/mozilla/ContentHandler.cpp3
-rw-r--r--embed/mozilla/EphyHeaderSniffer.cpp2
-rw-r--r--embed/mozilla/FilePicker.cpp95
-rwxr-xr-xembed/print-dialog.c10
-rw-r--r--lib/ephy-file-chooser.c109
-rw-r--r--lib/ephy-file-chooser.h26
-rw-r--r--src/bookmarks/ephy-bookmarks-editor.c25
-rw-r--r--src/prefs-dialog.c4
-rw-r--r--src/window-commands.c3
10 files changed, 217 insertions, 80 deletions
diff --git a/ChangeLog b/ChangeLog
index 75e7593ad..33f6cbdf0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,24 @@
2004-05-08 Christian Persch <chpe@cvs.gnome.org>
+ * lib/ephy-file-chooser.c: (ephy_file_chooser_add_pattern_filter),
+ (ephy_file_chooser_add_mime_filter), (ephy_file_chooser_new):
+ * lib/ephy-file-chooser.h:
+
+ Add convenience functions for creating a filter with a bunch of mime
+ types or patterns and add it to a file chooser. Those should really
+ be in gtk+; see bug #142142.
+
+ * embed/mozilla/ContentHandler.cpp:
+ * embed/mozilla/EphyHeaderSniffer.cpp:
+ * embed/mozilla/FilePicker.cpp:
+ * embed/print-dialog.c: (ephy_print_dialog_browse_button_cb):
+ * src/bookmarks/ephy-bookmarks-editor.c:
+ (import_dialog_response_cb):
+ * src/prefs-dialog.c: (prefs_download_path_button_clicked_cb):
+ * src/window-commands.c: (window_cmd_file_open):
+
+ Add some filters to the file chooser dialogues.
+
+2004-05-08 Christian Persch <chpe@cvs.gnome.org>
* embed/mozilla/EphyHeaderSniffer.cpp:
* embed/mozilla/EphyHeaderSniffer.h:
diff --git a/embed/mozilla/ContentHandler.cpp b/embed/mozilla/ContentHandler.cpp
index 8e46348fb..8a6a6a6d3 100644
--- a/embed/mozilla/ContentHandler.cpp
+++ b/embed/mozilla/ContentHandler.cpp
@@ -140,7 +140,8 @@ NS_IMETHODIMP GContentHandler::PromptForSaveToFile(
dialog = ephy_file_chooser_new (_("Save"), parentWindow,
GTK_FILE_CHOOSER_ACTION_SAVE,
- CONF_STATE_SAVE_DIR);
+ CONF_STATE_SAVE_DIR,
+ EPHY_FILE_FILTER_ALL);
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog),
NS_ConvertUTF16toUTF8 (aDefaultFile).get());
response = gtk_dialog_run (GTK_DIALOG (dialog));
diff --git a/embed/mozilla/EphyHeaderSniffer.cpp b/embed/mozilla/EphyHeaderSniffer.cpp
index b16b0f30f..c4be6e98f 100644
--- a/embed/mozilla/EphyHeaderSniffer.cpp
+++ b/embed/mozilla/EphyHeaderSniffer.cpp
@@ -349,7 +349,7 @@ nsresult EphyHeaderSniffer::PerformSave (nsIURI* inOriginalURI)
GTK_WIDGET (window),
GTK_FILE_CHOOSER_ACTION_SAVE,
key ? key : CONF_STATE_SAVE_DIR,
- TRUE);
+ EPHY_FILE_FILTER_ALL_SUPPORTED);
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog),
filename);
diff --git a/embed/mozilla/FilePicker.cpp b/embed/mozilla/FilePicker.cpp
index 80a0cbf3a..29756b15b 100644
--- a/embed/mozilla/FilePicker.cpp
+++ b/embed/mozilla/FilePicker.cpp
@@ -157,69 +157,43 @@ NS_IMETHODIMP GFilePicker::AppendFilters(PRInt32 filterMask)
// 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
-
LOG ("GFilePicker::AppendFilters mask=%d", filterMask)
if (filterMask & nsIFilePicker::filterAll)
{
-#if MOZILLA_SNAPSHOT < 18
- AppendFilter (NS_ConvertUTF8toUTF16 (_("All files")).get(),
- NS_LITERAL_STRING ("*").get());
-#else
- AppendFilter (NS_ConvertUTF8toUTF16 (_("All files")),
- NS_LITERAL_STRING ("*"));
-#endif
+ ephy_file_chooser_add_pattern_filter (mDialog, _("All files"),
+ "*", NULL);
}
if (filterMask & nsIFilePicker::filterHTML)
{
-#if MOZILLA_SNAPSHOT < 18
- AppendFilter (NS_ConvertUTF8toUTF16 (_("HTML files")).get(),
- NS_LITERAL_STRING ("*.html; *.htm; *.shtml; *.xhtml").get());
-#else
- AppendFilter (NS_ConvertUTF8toUTF16 (_("HTML files")),
- NS_LITERAL_STRING ("*.html; *.htm; *.shtml; *.xhtml"));
-#endif
+ ephy_file_chooser_add_mime_filter (mDialog, _("Web pages"),
+ "text/html",
+ "application/xhtml+xml",
+ "text/xml",
+ NULL);
}
if (filterMask & nsIFilePicker::filterText)
{
-#if MOZILLA_SNAPSHOT < 18
- AppendFilter (NS_ConvertUTF8toUTF16 (_("Text files")).get(),
- NS_LITERAL_STRING ("*.txt; *.text").get());
-#else
- AppendFilter (NS_ConvertUTF8toUTF16 (_("Text files")),
- NS_LITERAL_STRING ("*.txt; *.text"));
-#endif
+ ephy_file_chooser_add_pattern_filter (mDialog, _("Text files"),
+ "*.txt", "*.text", NULL);
}
if (filterMask & nsIFilePicker::filterImages)
{
-#if MOZILLA_SNAPSHOT < 18
- AppendFilter (NS_ConvertUTF8toUTF16 (_("Image files")).get(),
- NS_LITERAL_STRING ("*.png; *.gif; *.jpeg; *.jpg").get());
-#else
- AppendFilter (NS_ConvertUTF8toUTF16 (_("Image files")),
- NS_LITERAL_STRING ("*.png; *.gif; *.jpeg; *.jpg"));
-#endif
+ ephy_file_chooser_add_mime_filter (mDialog, _("Images"),
+ "image/png",
+ "image/jpeg",
+ "image/gif",
+ NULL);
}
if (filterMask & nsIFilePicker::filterXML)
{
-#if MOZILLA_SNAPSHOT < 18
- AppendFilter (NS_ConvertUTF8toUTF16 (_("XML files")).get(),
- NS_LITERAL_STRING ("*.xml").get());
-#else
- AppendFilter (NS_ConvertUTF8toUTF16 (_("XML files")),
- NS_LITERAL_STRING ("*.xml"));
-#endif
+ ephy_file_chooser_add_pattern_filter (mDialog, _("XML files"),
+ "*.xml", NULL);
}
if (filterMask & nsIFilePicker::filterXUL)
{
-#if MOZILLA_SNAPSHOT < 18
- AppendFilter (NS_ConvertUTF8toUTF16 (_("XUL files")).get(),
- NS_LITERAL_STRING ("*.xul").get());
-#else
- AppendFilter (NS_ConvertUTF8toUTF16 (_("XUL files")),
- NS_LITERAL_STRING ("*.xul"));
-#endif
+ ephy_file_chooser_add_pattern_filter (mDialog, _("XUL files"),
+ "*.xul", NULL);
}
return NS_OK;
@@ -232,38 +206,29 @@ NS_IMETHODIMP GFilePicker::AppendFilter(const PRUnichar *title, const PRUnichar
NS_IMETHODIMP GFilePicker::AppendFilter(const nsAString& title, const nsAString& filter)
#endif
{
-#if MOZILLA_SNAPHOST < 16
LOG ("GFilePicker::AppendFilter title '%s' for '%s'",
NS_ConvertUTF16toUTF8 (title).get(),
NS_ConvertUTF16toUTF8 (filter).get())
-#else
- LOG ("GFilePicker::AppendFilter title '%s' for '%s'",
- NS_ConvertUCS2toUTF8 (title),
- NS_ConvertUCS2toUTF8 (filter))
-#endif
-#if MOZILLA_SNAPHOST < 16
NS_ConvertUTF16toUTF8 pattern(filter);
-#else
- NS_ConvertUCS2toUTF8 pattern(filter);
-#endif
+
pattern.StripWhitespace();
if (pattern.IsEmpty()) return NS_ERROR_FAILURE;
- char **patterns = g_strsplit (pattern.get(), ";", -1);
+ char **patterns;
+ patterns = g_strsplit (pattern.get(), ";", -1);
+ if (!patterns) return NS_ERROR_FAILURE;
- GtkFileFilter *filth = gtk_file_filter_new ();
+ GtkFileFilter *filth;
+ filth = gtk_file_filter_new ();
for (int i = 0; patterns[i] != NULL; i++)
{
gtk_file_filter_add_pattern (filth, patterns[i]);
}
-#if MOZILLA_SNAPHOST < 16
- gtk_file_filter_set_name (filth, NS_ConvertUTF16toUTF8(title).get());
-#else
- gtk_file_filter_set_name (filth, NS_ConvertUCS2toUTF8(title).get());
-#endif
+ gtk_file_filter_set_name (filth, NS_ConvertUTF16toUTF8 (title).get());
+
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (mDialog), filth);
g_strfreev (patterns);
@@ -290,7 +255,7 @@ NS_IMETHODIMP GFilePicker::GetDefaultString(nsAString& aDefaultString)
#if MOZILLA_SNAPSHOT < 18
*aDefaultString = ToNewUnicode (NS_ConvertUTF8toUTF16 (converted));
#else
- aDefaultString = NS_ConvertUTF8toUTF16 (converted);
+ CopyUTF8toUTF16 (converted, aDefaultString);
#endif
g_free (filename);
@@ -321,15 +286,9 @@ NS_IMETHODIMP GFilePicker::SetDefaultString(const nsAString& aDefaultString)
#endif
{
/* set_current_name takes UTF-8, not a filename */
-#if MOZILLA_SNAPSHOT < 18
gtk_file_chooser_set_current_name
(GTK_FILE_CHOOSER (mDialog),
NS_ConvertUTF16toUTF8 (aDefaultString).get());
-#else
- gtk_file_chooser_set_current_name
- (GTK_FILE_CHOOSER (mDialog),
- NS_ConvertUCS2toUTF8 (aDefaultString).get());
-#endif
}
return NS_OK;
diff --git a/embed/print-dialog.c b/embed/print-dialog.c
index ddc8192d5..238be4d98 100755
--- a/embed/print-dialog.c
+++ b/embed/print-dialog.c
@@ -287,13 +287,21 @@ ephy_print_dialog_browse_button_cb (GtkWidget *widget,
{
GtkWidget *parent;
EphyFileChooser *fc;
+ GtkFileFilter *filter;
parent = ephy_dialog_get_control (dialog, print_props[WINDOW_PROP].id);
fc = ephy_file_chooser_new (_("Print to"),
GTK_WIDGET (parent),
GTK_FILE_CHOOSER_ACTION_SAVE,
- CONF_PRINT_DIR);
+ CONF_PRINT_DIR, EPHY_FILE_FILTER_NONE);
+
+ filter = ephy_file_chooser_add_mime_filter (fc, _("Postscript files"),
+ "application/postscript", NULL);
+
+ ephy_file_chooser_add_pattern_filter (fc, _("All Files"), "*", NULL);
+
+ gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (fc), filter);
g_signal_connect (GTK_DIALOG (fc), "response",
G_CALLBACK (print_filechooser_response_cb),
diff --git a/lib/ephy-file-chooser.c b/lib/ephy-file-chooser.c
index 72d265230..2494c9e38 100644
--- a/lib/ephy-file-chooser.c
+++ b/lib/ephy-file-chooser.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2003 Marco Pesenti Gritti
- * Copyright (C) 2003 Christian Persch
+ * Copyright (C) 2003, 2004 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
@@ -31,6 +31,7 @@
#include <gtk/gtkstock.h>
#include <libgnomevfs/gnome-vfs-utils.h>
+#include <glib/gi18n.h>
#define EPHY_FILE_CHOOSER_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_FILE_CHOOSER, EphyFileChooserPrivate))
@@ -174,6 +175,68 @@ ephy_file_chooser_get_persist_key (EphyFileChooser *dialog)
return dialog->priv->persist_key;
}
+/* This function should really be in gtk+, see bug 142142 */
+
+GtkFileFilter *
+ephy_file_chooser_add_pattern_filter (EphyFileChooser *dialog,
+ const char *title,
+ const char *first_pattern,
+ ...)
+{
+ GtkFileFilter *filth;
+ va_list args;
+ const char *pattern;
+
+ filth = gtk_file_filter_new ();
+
+ va_start (args, first_pattern);
+
+ pattern = first_pattern;
+ while (pattern != NULL)
+ {
+ gtk_file_filter_add_pattern (filth, pattern);
+ pattern = va_arg (args, const char *);
+ }
+ va_end (args);
+
+ gtk_file_filter_set_name (filth, title);
+
+ gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filth);
+
+ return filth;
+}
+
+/* This function should really be in gtk+, see bug 142142 */
+
+GtkFileFilter *
+ephy_file_chooser_add_mime_filter (EphyFileChooser *dialog,
+ const char *title,
+ const char *first_mimetype,
+ ...)
+{
+ GtkFileFilter *filth;
+ va_list args;
+ const char *mimetype;
+
+ filth = gtk_file_filter_new ();
+
+ va_start (args, first_mimetype);
+
+ mimetype = first_mimetype;
+ while (mimetype != NULL)
+ {
+ gtk_file_filter_add_mime_type (filth, mimetype);
+ mimetype = va_arg (args, const char *);
+ }
+ va_end (args);
+
+ gtk_file_filter_set_name (filth, title);
+
+ gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filth);
+
+ return filth;
+}
+
static void
ephy_file_chooser_set_property (GObject *object,
guint prop_id,
@@ -233,9 +296,13 @@ EphyFileChooser *
ephy_file_chooser_new (const char *title,
GtkWidget *parent,
GtkFileChooserAction action,
- const char *persist_key)
+ const char *persist_key,
+ EphyFileFilterDefault default_filter)
{
EphyFileChooser *dialog;
+ GtkFileFilter *filter[EPHY_FILE_FILTER_LAST];
+
+ g_return_val_if_fail (default_filter >= 0 && default_filter <= EPHY_FILE_FILTER_LAST, NULL);
dialog = EPHY_FILE_CHOOSER (g_object_new (EPHY_TYPE_FILE_CHOOSER,
"title", title,
@@ -274,6 +341,44 @@ ephy_file_chooser_new (const char *title,
GTK_RESPONSE_ACCEPT);
}
+ if (default_filter != EPHY_FILE_FILTER_NONE)
+ {
+ filter[EPHY_FILE_FILTER_ALL_SUPPORTED] =
+ ephy_file_chooser_add_mime_filter
+ (dialog,
+ _("All supported types"),
+ "text/html",
+ "application/xhtml+xml",
+ "text/xml",
+ "image/png",
+ "image/jpeg",
+ "image/gif",
+ NULL);
+
+ filter[EPHY_FILE_FILTER_WEBPAGES] =
+ ephy_file_chooser_add_mime_filter
+ (dialog, _("Web pages"),
+ "text/html",
+ "application/xhtml+xml",
+ "text/xml",
+ NULL);
+
+ filter[EPHY_FILE_FILTER_IMAGES] =
+ ephy_file_chooser_add_mime_filter
+ (dialog, _("Images"),
+ "image/png",
+ "image/jpeg",
+ "image/gif",
+ NULL);
+
+ filter[EPHY_FILE_FILTER_ALL] =
+ ephy_file_chooser_add_pattern_filter
+ (dialog, _("All files"), "*", NULL);
+
+ gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog),
+ filter[default_filter]);
+ }
+
if (parent != NULL)
{
gtk_window_set_transient_for (GTK_WINDOW (dialog),
diff --git a/lib/ephy-file-chooser.h b/lib/ephy-file-chooser.h
index d3d729ca6..5b576728a 100644
--- a/lib/ephy-file-chooser.h
+++ b/lib/ephy-file-chooser.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003 Christian Persch
+ * Copyright (C) 2003, 2004 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
@@ -24,6 +24,7 @@
#include <glib-object.h>
#include <gtk/gtkwidget.h>
+#include <gtk/gtkfilefilter.h>
#include <gtk/gtkfilechooserdialog.h>
G_BEGIN_DECLS
@@ -37,6 +38,16 @@ G_BEGIN_DECLS
typedef struct EphyFileChooserPrivate EphyFileChooserPrivate;
+typedef enum
+{
+ EPHY_FILE_FILTER_ALL_SUPPORTED,
+ EPHY_FILE_FILTER_WEBPAGES,
+ EPHY_FILE_FILTER_IMAGES,
+ EPHY_FILE_FILTER_ALL,
+ EPHY_FILE_FILTER_NONE,
+ EPHY_FILE_FILTER_LAST = EPHY_FILE_FILTER_NONE
+} EphyFileFilterDefault;
+
typedef struct
{
GtkFileChooserDialog parent;
@@ -55,13 +66,24 @@ GType ephy_file_chooser_get_type (void);
EphyFileChooser *ephy_file_chooser_new (const char *title,
GtkWidget *parent,
GtkFileChooserAction action,
- const char *persist_key);
+ const char *persist_key,
+ EphyFileFilterDefault default_filter);
void ephy_file_chooser_set_persist_key (EphyFileChooser *dialog,
const char *key);
const char *ephy_file_chooser_get_persist_key (EphyFileChooser *dialog);
+GtkFileFilter *ephy_file_chooser_add_pattern_filter (EphyFileChooser *dialog,
+ const char *title,
+ const char *first_pattern,
+ ...);
+
+GtkFileFilter *ephy_file_chooser_add_mime_filter (EphyFileChooser *dialog,
+ const char *title,
+ const char *first_mimetype,
+ ...);
+
G_END_DECLS
#endif
diff --git a/src/bookmarks/ephy-bookmarks-editor.c b/src/bookmarks/ephy-bookmarks-editor.c
index f789922a2..2bf909e8d 100644
--- a/src/bookmarks/ephy-bookmarks-editor.c
+++ b/src/bookmarks/ephy-bookmarks-editor.c
@@ -554,12 +554,33 @@ import_dialog_response_cb (GtkDialog *dialog, gint response,
if (filename == NULL)
{
EphyFileChooser *dialog;
+ GtkFileFilter *filter;
dialog = ephy_file_chooser_new (_("Import bookmarks from file"),
GTK_WIDGET (editor),
GTK_FILE_CHOOSER_ACTION_OPEN,
- NULL);
- /* FIXME: set up some filters perhaps ? */
+ NULL, EPHY_FILE_FILTER_NONE);
+
+ ephy_file_chooser_add_mime_filter
+ (dialog,
+ _("Firefox/Firebird/Mozilla bookmarks"),
+ "application/x-mozilla-bookmarks", NULL);
+
+ ephy_file_chooser_add_mime_filter
+ (dialog, _("Galeon/Konqueror bookmarks"),
+ "application/x-xbel", NULL);
+
+ ephy_file_chooser_add_mime_filter
+ (dialog, _("Epiphany bookmarks"),
+ "text/rdf", NULL);
+
+ filter = ephy_file_chooser_add_pattern_filter (dialog,
+ _("All Files"),
+ "*", NULL);
+
+ gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog),
+ filter);
+
g_signal_connect (dialog, "response",
G_CALLBACK (import_from_file_response_cb), editor);
diff --git a/src/prefs-dialog.c b/src/prefs-dialog.c
index 087f061d8..161c5663b 100644
--- a/src/prefs-dialog.c
+++ b/src/prefs-dialog.c
@@ -1321,8 +1321,8 @@ prefs_download_path_button_clicked_cb (GtkWidget *button,
fc = ephy_file_chooser_new (_("Select a directory"),
GTK_WIDGET (parent),
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
- NULL);
-
+ NULL, EPHY_FILE_FILTER_NONE);
+
g_signal_connect (GTK_DIALOG (fc), "response",
G_CALLBACK (download_path_response_cb),
dialog);
diff --git a/src/window-commands.c b/src/window-commands.c
index af9d26ef2..4c4d72372 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -396,7 +396,8 @@ window_cmd_file_open (GtkAction *action,
dialog = ephy_file_chooser_new (_("Open"),
GTK_WIDGET (window),
GTK_FILE_CHOOSER_ACTION_OPEN,
- CONF_STATE_OPEN_DIR);
+ CONF_STATE_OPEN_DIR,
+ EPHY_FILE_FILTER_ALL_SUPPORTED);
g_signal_connect (dialog, "response",
G_CALLBACK (open_response_cb), window);