diff options
author | Milan Crha <mcrha@redhat.com> | 2009-12-10 23:08:52 +0800 |
---|---|---|
committer | Milan Crha <mcrha@redhat.com> | 2009-12-10 23:08:52 +0800 |
commit | 4a9bf4dffd98346f9eee848708df573df56ed1d6 (patch) | |
tree | ff25e44e04c981f030fdbd734520dd6f0c9703cd /shell | |
parent | 23b4037df07370ee9f2bf069db2256620c0a2f82 (diff) | |
download | gsoc2013-evolution-4a9bf4dffd98346f9eee848708df573df56ed1d6.tar.gz gsoc2013-evolution-4a9bf4dffd98346f9eee848708df573df56ed1d6.tar.zst gsoc2013-evolution-4a9bf4dffd98346f9eee848708df573df56ed1d6.zip |
Bug #499322 - Use extension for "Save as" suggested file name
Diffstat (limited to 'shell')
-rw-r--r-- | shell/e-shell-utils.c | 55 | ||||
-rw-r--r-- | shell/e-shell-utils.h | 1 |
2 files changed, 56 insertions, 0 deletions
diff --git a/shell/e-shell-utils.c b/shell/e-shell-utils.c index c9c887c97a..1a8d7830f2 100644 --- a/shell/e-shell-utils.c +++ b/shell/e-shell-utils.c @@ -135,6 +135,7 @@ exit: * @shell: an #EShell * @title: file chooser dialog title * @suggestion: file name suggestion, or %NULL + * @filters: Possible filters for dialog, or %NULL * @customize_func: optional dialog customization function * @customize_data: optional data to pass to @customize_func * @@ -145,12 +146,18 @@ exit: * @customize_data is the second). If the user cancels the dialog the * function will return %NULL. * + * With non-%NULL @filters will be added also file filters to the dialog. + * The string format is "pat1:mt1;pat2:mt2:...", where 'pat' is a pattern + * and 'mt' is a MIME type for the pattern to be used. + * There can be more than one MIME type, those are separated by comma. + * * Returns: the #GFile to save to, or %NULL **/ GFile * e_shell_run_save_dialog (EShell *shell, const gchar *title, const gchar *suggestion, + const gchar *filters, GtkCallback customize_func, gpointer customize_data) { @@ -192,6 +199,54 @@ e_shell_run_save_dialog (EShell *shell, if (suggestion != NULL) gtk_file_chooser_set_current_name (file_chooser, suggestion); + if (filters != NULL) { + gchar **flts = g_strsplit (filters, ";", -1); + gint i; + + for (i = 0; flts [i]; i++) { + GtkFileFilter *filter = gtk_file_filter_new (); + gchar *flt = flts [i]; + gchar *delim = strchr (flt, ':'), *next = NULL; + + if (delim) { + *delim = 0; + next = strchr (delim + 1, ','); + } + + gtk_file_filter_add_pattern (filter, flt); + if (g_ascii_strcasecmp (flt, "*.mbox") == 0) + gtk_file_filter_set_name (filter, _("Berkeley Mailbox (mbox)")); + else if (g_ascii_strcasecmp (flt, "*.vcf") == 0) + gtk_file_filter_set_name (filter, _("vCard (.vcf)")); + else if (g_ascii_strcasecmp (flt, "*.ics") == 0) + gtk_file_filter_set_name (filter, _("iCalendar (.ics)")); + + while (delim) { + delim++; + if (next) + *next = 0; + + gtk_file_filter_add_mime_type (filter, delim); + + delim = next; + if (next) + next = strchr (next + 1, ','); + } + + gtk_file_chooser_add_filter (file_chooser, filter); + } + + if (flts && flts [0]) { + GtkFileFilter *filter = gtk_file_filter_new (); + + gtk_file_filter_add_pattern (filter, "*"); + gtk_file_filter_set_name (filter, _("All Files (*)")); + gtk_file_chooser_add_filter (file_chooser, filter); + } + + g_strfreev (flts); + } + /* Allow further customizations before running the dialog. */ if (customize_func != NULL) customize_func (dialog, customize_data); diff --git a/shell/e-shell-utils.h b/shell/e-shell-utils.h index 6e26256155..18e90aa5f2 100644 --- a/shell/e-shell-utils.h +++ b/shell/e-shell-utils.h @@ -44,6 +44,7 @@ GFile * e_shell_run_open_dialog (EShell *shell, GFile * e_shell_run_save_dialog (EShell *shell, const gchar *title, const gchar *suggestion, + const gchar *filters, GtkCallback customize_func, gpointer customize_data); |