[evolution] Bug #499322 - Use extension for "Save as" suggested file name



commit 4a9bf4dffd98346f9eee848708df573df56ed1d6
Author: Milan Crha <mcrha redhat com>
Date:   Thu Dec 10 16:08:52 2009 +0100

    Bug #499322 - Use extension for "Save as" suggested file name

 addressbook/gui/widgets/eab-gui-util.c          |    7 ++-
 calendar/gui/comp-util.c                        |   19 ++++++++
 calendar/gui/comp-util.h                        |    2 +
 mail/e-mail-reader.c                            |   20 ++++++--
 modules/addressbook/e-book-shell-view-actions.c |    4 +-
 modules/calendar/e-cal-shell-view-actions.c     |    5 ++-
 modules/calendar/e-cal-shell-view-memopad.c     |    5 ++-
 modules/calendar/e-cal-shell-view-taskpad.c     |    5 ++-
 modules/calendar/e-memo-shell-view-actions.c    |    5 ++-
 modules/calendar/e-task-shell-view-actions.c    |    5 ++-
 plugins/backup-restore/backup-restore.c         |    2 +-
 plugins/itip-formatter/itip-formatter.c         |    2 +-
 shell/e-shell-utils.c                           |   55 +++++++++++++++++++++++
 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 0faa1a1..4f84eed 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 a745b61..c5254a4 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 2faea3e..d328627 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 f9e5abd..d33c1e5 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 92ef88c..5214f61 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 b5fd49b..b0408b6 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 5f1ed97..3a92cbc 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 e011568..c88dee0 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 78531fc..394d609 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 f923a03..6e79c23 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 bc7766e..80d0b76 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 d1819b4..57e9bc2 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 c9c887c..1a8d783 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 6e26256..18e90aa 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);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]