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 | |
parent | 23b4037df07370ee9f2bf069db2256620c0a2f82 (diff) | |
download | gsoc2013-evolution-4a9bf4dffd98346f9eee848708df573df56ed1d6.tar gsoc2013-evolution-4a9bf4dffd98346f9eee848708df573df56ed1d6.tar.gz gsoc2013-evolution-4a9bf4dffd98346f9eee848708df573df56ed1d6.tar.bz2 gsoc2013-evolution-4a9bf4dffd98346f9eee848708df573df56ed1d6.tar.lz gsoc2013-evolution-4a9bf4dffd98346f9eee848708df573df56ed1d6.tar.xz gsoc2013-evolution-4a9bf4dffd98346f9eee848708df573df56ed1d6.tar.zst gsoc2013-evolution-4a9bf4dffd98346f9eee848708df573df56ed1d6.zip |
Bug #499322 - Use extension for "Save as" suggested file name
-rw-r--r-- | addressbook/gui/widgets/eab-gui-util.c | 7 | ||||
-rw-r--r-- | calendar/gui/comp-util.c | 19 | ||||
-rw-r--r-- | calendar/gui/comp-util.h | 2 | ||||
-rw-r--r-- | mail/e-mail-reader.c | 20 | ||||
-rw-r--r-- | modules/addressbook/e-book-shell-view-actions.c | 4 | ||||
-rw-r--r-- | modules/calendar/e-cal-shell-view-actions.c | 5 | ||||
-rw-r--r-- | modules/calendar/e-cal-shell-view-memopad.c | 5 | ||||
-rw-r--r-- | modules/calendar/e-cal-shell-view-taskpad.c | 5 | ||||
-rw-r--r-- | modules/calendar/e-memo-shell-view-actions.c | 5 | ||||
-rw-r--r-- | modules/calendar/e-task-shell-view-actions.c | 5 | ||||
-rw-r--r-- | plugins/backup-restore/backup-restore.c | 2 | ||||
-rw-r--r-- | plugins/itip-formatter/itip-formatter.c | 2 | ||||
-rw-r--r-- | shell/e-shell-utils.c | 55 | ||||
-rw-r--r-- | shell/e-shell-utils.h | 1 |
14 files changed, 121 insertions, 16 deletions
diff --git a/addressbook/gui/widgets/eab-gui-util.c b/addressbook/gui/widgets/eab-gui-util.c index 0faa1a14cf..4f84eed6e4 100644 --- a/addressbook/gui/widgets/eab-gui-util.c +++ b/addressbook/gui/widgets/eab-gui-util.c @@ -286,7 +286,7 @@ eab_select_source (const gchar *title, const gchar *message, const gchar *select gchar * eab_suggest_filename (GList *contact_list) { - gchar *current_name = NULL; + gchar *current_name = NULL, *res; g_return_val_if_fail (contact_list != NULL, NULL); @@ -305,7 +305,10 @@ eab_suggest_filename (GList *contact_list) if (current_name == NULL) current_name = make_safe_filename (_("list")); - return current_name; + res = g_strconcat (current_name, ".vcf", NULL); + g_free (current_name); + + return res; } typedef struct ContactCopyProcess_ ContactCopyProcess; diff --git a/calendar/gui/comp-util.c b/calendar/gui/comp-util.c index a745b61e12..c5254a427f 100644 --- a/calendar/gui/comp-util.c +++ b/calendar/gui/comp-util.c @@ -860,3 +860,22 @@ comp_util_sanitize_recurrence_master (ECalComponent *comp, ECal *client) g_object_unref (master); } + +gchar * +icalcomp_suggest_filename (icalcomponent *icalcomp, const gchar *default_name) +{ + icalproperty *prop; + const gchar *summary = NULL; + + if (!icalcomp) + return g_strconcat (default_name, ".ics", NULL); + + prop = icalcomponent_get_first_property (icalcomp, ICAL_SUMMARY_PROPERTY); + if (prop) + summary = icalproperty_get_summary (prop); + + if (!summary || !*summary) + summary = default_name; + + return g_strconcat (summary, ".ics", NULL); +} diff --git a/calendar/gui/comp-util.h b/calendar/gui/comp-util.h index 2faea3e217..d328627145 100644 --- a/calendar/gui/comp-util.h +++ b/calendar/gui/comp-util.h @@ -59,4 +59,6 @@ void cal_comp_set_dtend_with_oldzone (ECal *client, ECalComponent *comp, const E gboolean cal_comp_process_source_list_drop (ECal *destination, icalcomponent *comp, GdkDragAction action, const gchar *source_uid, ESourceList *source_list); void comp_util_sanitize_recurrence_master (ECalComponent *comp, ECal *client); +gchar *icalcomp_suggest_filename (icalcomponent *icalcomp, const gchar *default_name); + #endif diff --git a/mail/e-mail-reader.c b/mail/e-mail-reader.c index f9e5abd837..d33c1e52df 100644 --- a/mail/e-mail-reader.c +++ b/mail/e-mail-reader.c @@ -799,7 +799,7 @@ action_mail_save_as_cb (GtkAction *action, GPtrArray *uids; GFile *file; const gchar *title; - const gchar *suggestion; + gchar *suggestion = NULL; gchar *uri; folder = e_mail_reader_get_folder (reader); @@ -813,13 +813,23 @@ action_mail_save_as_cb (GtkAction *action, /* Suggest as a filename the subject of the first message. */ info = camel_folder_get_message_info (folder, uids->pdata[0]); if (info != NULL) { - suggestion = camel_message_info_subject (info); + const gchar *subject = camel_message_info_subject (info); + + if (subject) + suggestion = g_strconcat (subject, ".mbox", NULL); camel_message_info_free (info); - } else - suggestion = NULL; + } + + if (!suggestion) { + /* To Translators: This is a part of a suggested file name used when saving + a message or multiple messages to an mbox format, when the first message + doesn't have a Subject. The extension ".mbox" is appended to this string, + thus it will be something like "Message.mbox" at the end. */ + suggestion = g_strconcat (ngettext ("Message", "Messages", uids->len), ".mbox", NULL); + } shell = e_shell_backend_get_shell (shell_backend); - file = e_shell_run_save_dialog (shell, title, suggestion, NULL, NULL); + file = e_shell_run_save_dialog (shell, title, suggestion, "*.mbox:application/mbox,message/rfc822", NULL, NULL); if (file == NULL) { em_utils_uids_free (uids); diff --git a/modules/addressbook/e-book-shell-view-actions.c b/modules/addressbook/e-book-shell-view-actions.c index 92ef88c01a..5214f611d3 100644 --- a/modules/addressbook/e-book-shell-view-actions.c +++ b/modules/addressbook/e-book-shell-view-actions.c @@ -259,7 +259,7 @@ action_address_book_save_as_cb (GtkAction *action, string = eab_suggest_filename (list); file = e_shell_run_save_dialog ( - shell, _("Save as vCard"), string, NULL, NULL); + shell, _("Save as vCard"), string, "*.vcf:text/x-vcard,text/directory", NULL, NULL); g_free (string); if (file == NULL) @@ -560,7 +560,7 @@ action_contact_save_as_cb (GtkAction *action, string = eab_suggest_filename (list); file = e_shell_run_save_dialog ( - shell, _("Save as vCard"), string, NULL, NULL); + shell, _("Save as vCard"), string, "*.vcf:text/x-vcard,text/directory", NULL, NULL); g_free (string); if (file == NULL) diff --git a/modules/calendar/e-cal-shell-view-actions.c b/modules/calendar/e-cal-shell-view-actions.c index b5fd49bb83..b0408b6b5a 100644 --- a/modules/calendar/e-cal-shell-view-actions.c +++ b/modules/calendar/e-cal-shell-view-actions.c @@ -1101,8 +1101,11 @@ action_event_save_as_cb (GtkAction *action, client = event->comp_data->client; icalcomp = event->comp_data->icalcomp; + /* To Translators: Default filename part saving an event to a file when no summary is filed, the '.ics' extension is concatenated to it */ + string = icalcomp_suggest_filename (icalcomp, _("event")); file = e_shell_run_save_dialog ( - shell, _("Save as iCalendar"), NULL, NULL, NULL); + shell, _("Save as iCalendar"), string, "*.ics:text/calendar", NULL, NULL); + g_free (string); if (file == NULL) return; diff --git a/modules/calendar/e-cal-shell-view-memopad.c b/modules/calendar/e-cal-shell-view-memopad.c index 5f1ed972dd..3a92cbc777 100644 --- a/modules/calendar/e-cal-shell-view-memopad.c +++ b/modules/calendar/e-cal-shell-view-memopad.c @@ -258,8 +258,11 @@ action_calendar_memopad_save_as_cb (GtkAction *action, comp_data = list->data; g_slist_free (list); + /* To Translators: Default filename part saving a memo to a file when no summary is filed, the '.ics' extension is concatenated to it */ + string = icalcomp_suggest_filename (comp_data->icalcomp, _("memo")); file = e_shell_run_save_dialog ( - shell, _("Save as iCalendar"), NULL, NULL, NULL); + shell, _("Save as iCalendar"), string, "*.ics:text/calendar", NULL, NULL); + g_free (string); if (file == NULL) return; diff --git a/modules/calendar/e-cal-shell-view-taskpad.c b/modules/calendar/e-cal-shell-view-taskpad.c index e011568117..c88dee0d4c 100644 --- a/modules/calendar/e-cal-shell-view-taskpad.c +++ b/modules/calendar/e-cal-shell-view-taskpad.c @@ -326,8 +326,11 @@ action_calendar_taskpad_save_as_cb (GtkAction *action, comp_data = list->data; g_slist_free (list); + /* To Translators: Default filename part saving a task to a file when no summary is filed, the '.ics' extension is concatenated to it */ + string = icalcomp_suggest_filename (comp_data->icalcomp, _("task")); file = e_shell_run_save_dialog ( - shell, _("Save as iCalendar"), NULL, NULL, NULL); + shell, _("Save as iCalendar"), string, "*.ics:text/calendar", NULL, NULL); + g_free (string); if (file == NULL) return; diff --git a/modules/calendar/e-memo-shell-view-actions.c b/modules/calendar/e-memo-shell-view-actions.c index 78531fc8ba..394d6091a4 100644 --- a/modules/calendar/e-memo-shell-view-actions.c +++ b/modules/calendar/e-memo-shell-view-actions.c @@ -522,8 +522,11 @@ action_memo_save_as_cb (GtkAction *action, comp_data = list->data; g_slist_free (list); + /* To Translators: Default filename part saving a memo to a file when no summary is filed, the '.ics' extension is concatenated to it */ + string = icalcomp_suggest_filename (comp_data->icalcomp, _("memo")); file = e_shell_run_save_dialog ( - shell, _("Save as iCalendar"), NULL, NULL, NULL); + shell, _("Save as iCalendar"), string, "*.ics:text/calendar", NULL, NULL); + g_free (string); if (file == NULL) return; diff --git a/modules/calendar/e-task-shell-view-actions.c b/modules/calendar/e-task-shell-view-actions.c index f923a03f2b..6e79c23395 100644 --- a/modules/calendar/e-task-shell-view-actions.c +++ b/modules/calendar/e-task-shell-view-actions.c @@ -647,8 +647,11 @@ action_task_save_as_cb (GtkAction *action, comp_data = list->data; g_slist_free (list); + /* To Translators: Default filename part saving a task to a file when no summary is filed, the '.ics' extension is concatenated to it */ + string = icalcomp_suggest_filename (comp_data->icalcomp, _("task")); file = e_shell_run_save_dialog ( - shell, _("Save as iCalendar"), NULL, NULL, NULL); + shell, _("Save as iCalendar"), string, "*.ics:text/calendar", NULL, NULL); + g_free (string); if (file == NULL) return; diff --git a/plugins/backup-restore/backup-restore.c b/plugins/backup-restore/backup-restore.c index bc7766e861..80d0b76fcb 100644 --- a/plugins/backup-restore/backup-restore.c +++ b/plugins/backup-restore/backup-restore.c @@ -150,7 +150,7 @@ action_settings_backup_cb (GtkAction *action, file = e_shell_run_save_dialog ( e_shell_window_get_shell (shell_window), _("Select name of the Evolution backup file"), - "evolution-backup.tar.gz", (GtkCallback) + "evolution-backup.tar.gz", "*.tar.gz", (GtkCallback) set_local_only, NULL); if (file == NULL) diff --git a/plugins/itip-formatter/itip-formatter.c b/plugins/itip-formatter/itip-formatter.c index d1819b4b48..57e9bc2ad8 100644 --- a/plugins/itip-formatter/itip-formatter.c +++ b/plugins/itip-formatter/itip-formatter.c @@ -1519,7 +1519,7 @@ save_vcalendar_cb (GtkWidget *button, struct _itip_puri *pitip) shell = e_shell_get_default (); file = e_shell_run_save_dialog ( - shell, _("Save Calendar"), suggestion, NULL, NULL); + shell, _("Save Calendar"), suggestion, "*.ics:text/calendar", NULL, NULL); if (file == NULL) return; 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); |