aboutsummaryrefslogtreecommitdiffstats
path: root/embed/mozilla/FilePicker.cpp
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/mozilla/FilePicker.cpp
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/mozilla/FilePicker.cpp')
-rw-r--r--embed/mozilla/FilePicker.cpp95
1 files changed, 27 insertions, 68 deletions
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;