aboutsummaryrefslogtreecommitdiffstats
path: root/embed
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2004-05-09 04:11:17 +0800
committerChristian Persch <chpe@src.gnome.org>2004-05-09 04:11:17 +0800
commitb3fed7cc16e2f03970776e0f874e94c112f4b240 (patch)
treeb54e3d04e84efa3b1df7b32f42b879c3e03d7609 /embed
parent9e4d594ee6ccc51bf5dca17b8f790d7fa1a917c2 (diff)
downloadgsoc2013-epiphany-b3fed7cc16e2f03970776e0f874e94c112f4b240.tar
gsoc2013-epiphany-b3fed7cc16e2f03970776e0f874e94c112f4b240.tar.gz
gsoc2013-epiphany-b3fed7cc16e2f03970776e0f874e94c112f4b240.tar.bz2
gsoc2013-epiphany-b3fed7cc16e2f03970776e0f874e94c112f4b240.tar.lz
gsoc2013-epiphany-b3fed7cc16e2f03970776e0f874e94c112f4b240.tar.xz
gsoc2013-epiphany-b3fed7cc16e2f03970776e0f874e94c112f4b240.tar.zst
gsoc2013-epiphany-b3fed7cc16e2f03970776e0f874e94c112f4b240.zip
Add convenience functions for creating a filter with a bunch of mime types
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.
Diffstat (limited to 'embed')
-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
4 files changed, 39 insertions, 71 deletions
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),