aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ephy-file-chooser.c
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 /lib/ephy-file-chooser.c
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 'lib/ephy-file-chooser.c')
-rw-r--r--lib/ephy-file-chooser.c109
1 files changed, 107 insertions, 2 deletions
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),