[evolution] Kill more redundant save dialogs and related utilities.



commit 3dfdf087fc7657905fc7804b59414ecd3d74028e
Author: Matthew Barnes <mbarnes redhat com>
Date:   Tue Nov 10 12:14:07 2009 -0500

    Kill more redundant save dialogs and related utilities.

 addressbook/gui/widgets/eab-gui-util.c            |   12 +-
 addressbook/gui/widgets/eab-gui-util.h            |    3 +-
 calendar/gui/dialogs/Makefile.am                  |    3 -
 calendar/gui/dialogs/cal-attachment-select-file.c |  162 ---------------------
 calendar/gui/dialogs/cal-attachment-select-file.h |   36 -----
 calendar/gui/dialogs/comp-editor.c                |    1 -
 doc/reference/shell/tmpl/e-dialog-utils.sgml      |   31 ----
 doc/reference/shell/tmpl/eshell-unused.sgml       |   28 ++++
 e-util/e-dialog-utils.c                           |  115 ---------------
 e-util/e-dialog-utils.h                           |    7 -
 e-util/e-util.c                                   |   60 --------
 e-util/e-util.h                                   |    4 -
 mail/e-mail-reader.c                              |   40 +++++-
 mail/em-utils.c                                   |   76 ----------
 mail/em-utils.h                                   |    2 -
 modules/addressbook/e-book-shell-view-actions.c   |   12 +-
 modules/calendar/e-cal-shell-view-actions.c       |    2 +-
 modules/calendar/e-cal-shell-view-memopad.c       |    2 +-
 modules/calendar/e-cal-shell-view-taskpad.c       |    2 +-
 modules/calendar/e-memo-shell-view-actions.c      |    2 +-
 modules/calendar/e-task-shell-view-actions.c      |    2 +-
 plugins/backup-restore/backup-restore.c           |  159 +++++++++-----------
 plugins/itip-formatter/itip-formatter.c           |   14 +-
 shell/e-shell-utils.c                             |   88 +++++++++++-
 shell/e-shell-utils.h                             |    6 +
 25 files changed, 254 insertions(+), 615 deletions(-)
---
diff --git a/addressbook/gui/widgets/eab-gui-util.c b/addressbook/gui/widgets/eab-gui-util.c
index 24fce0a..cfdf587 100644
--- a/addressbook/gui/widgets/eab-gui-util.c
+++ b/addressbook/gui/widgets/eab-gui-util.c
@@ -281,14 +281,12 @@ eab_select_source (const gchar *title, const gchar *message, const gchar *select
 	return source;
 }
 
-void
-eab_suggest_filename (GtkFileChooser *file_chooser,
-                      GList *contact_list)
+gchar *
+eab_suggest_filename (GList *contact_list)
 {
 	gchar *current_name = NULL;
 
-	g_return_if_fail (GTK_IS_FILE_CHOOSER (file_chooser));
-	g_return_if_fail (contact_list != NULL);
+	g_return_val_if_fail (contact_list != NULL, NULL);
 
 	if (g_list_length (contact_list) == 1) {
 		EContact *contact = E_CONTACT (contact_list->data);
@@ -305,9 +303,7 @@ eab_suggest_filename (GtkFileChooser *file_chooser,
 	if (current_name == NULL)
 		current_name = make_safe_filename (_("list"));
 
-	gtk_file_chooser_set_current_name (file_chooser, current_name);
-
-	g_free (current_name);
+	return current_name;
 }
 
 typedef struct ContactCopyProcess_ ContactCopyProcess;
diff --git a/addressbook/gui/widgets/eab-gui-util.h b/addressbook/gui/widgets/eab-gui-util.h
index 838343a..7a3da96 100644
--- a/addressbook/gui/widgets/eab-gui-util.h
+++ b/addressbook/gui/widgets/eab-gui-util.h
@@ -43,8 +43,7 @@ void                eab_transfer_contacts         (EBook       *source,
 						   gboolean     delete_from_source,
 						   GtkWindow   *parent_window);
 
-void                eab_suggest_filename          (GtkFileChooser *file_chooser,
-						   GList *contact_list);
+gchar *             eab_suggest_filename          (GList *contact_list);
 
 GtkWidget *eab_create_image_chooser_widget (gchar *name, gchar *string1, gchar *string2, gint int1, gint int2);
 
diff --git a/calendar/gui/dialogs/Makefile.am b/calendar/gui/dialogs/Makefile.am
index fb745fd..d09c906 100644
--- a/calendar/gui/dialogs/Makefile.am
+++ b/calendar/gui/dialogs/Makefile.am
@@ -24,7 +24,6 @@ ecalendarinclude_HEADERS =	\
 	comp-editor.h		\
 	alarm-dialog.h		\
 	alarm-list-dialog.h	\
-	cal-attachment-select-file.h \
 	cal-prefs-dialog.h	\
 	calendar-setup.h	\
 	cancel-comp.h		\
@@ -59,8 +58,6 @@ libcal_dialogs_la_SOURCES =	\
 	alarm-dialog.h		\
 	alarm-list-dialog.c	\
 	alarm-list-dialog.h	\
-	cal-attachment-select-file.c \
-	cal-attachment-select-file.h \
 	cal-prefs-dialog.c	\
 	cal-prefs-dialog.h	\
 	calendar-setup.c	\
diff --git a/calendar/gui/dialogs/comp-editor.c b/calendar/gui/dialogs/comp-editor.c
index 99dc3ea..9de8839 100644
--- a/calendar/gui/dialogs/comp-editor.c
+++ b/calendar/gui/dialogs/comp-editor.c
@@ -62,7 +62,6 @@
 #include "comp-editor.h"
 #include "comp-editor-util.h"
 #include "../calendar-config-keys.h"
-#include "cal-attachment-select-file.h"
 #include "widgets/misc/e-attachment-view.h"
 #include "widgets/misc/e-attachment-paned.h"
 
diff --git a/doc/reference/shell/tmpl/e-dialog-utils.sgml b/doc/reference/shell/tmpl/e-dialog-utils.sgml
index 233bac2..bdc02e8 100644
--- a/doc/reference/shell/tmpl/e-dialog-utils.sgml
+++ b/doc/reference/shell/tmpl/e-dialog-utils.sgml
@@ -28,37 +28,6 @@ Dialog Window Functions (Legacy)
 @Varargs: 
 
 
-<!-- ##### FUNCTION e_file_get_save_filesel ##### -->
-<para>
-
-</para>
-
- parent: 
- title: 
- name: 
- action: 
- Returns: 
-
-
-<!-- ##### FUNCTION e_file_can_save ##### -->
-<para>
-
-</para>
-
- parent: 
- uri: 
- Returns: 
-
-
-<!-- ##### FUNCTION e_file_check_local ##### -->
-<para>
-
-</para>
-
- name: 
- Returns: 
-
-
 <!-- ##### FUNCTION e_dialog_editable_set ##### -->
 <para>
 
diff --git a/doc/reference/shell/tmpl/eshell-unused.sgml b/doc/reference/shell/tmpl/eshell-unused.sgml
index d3c3dc5..8c8bcbd 100644
--- a/doc/reference/shell/tmpl/eshell-unused.sgml
+++ b/doc/reference/shell/tmpl/eshell-unused.sgml
@@ -1866,6 +1866,23 @@ intelligent
 @widget: 
 @cursor: 
 
+<!-- ##### FUNCTION e_file_can_save ##### -->
+<para>
+
+</para>
+
+ parent: 
+ uri: 
+ Returns: 
+
+<!-- ##### FUNCTION e_file_check_local ##### -->
+<para>
+
+</para>
+
+ name: 
+ Returns: 
+
 <!-- ##### FUNCTION e_file_dialog_save ##### -->
 <para>
 
@@ -1876,6 +1893,17 @@ intelligent
 @fname: 
 @Returns: 
 
+<!-- ##### FUNCTION e_file_get_save_filesel ##### -->
+<para>
+
+</para>
+
+ parent: 
+ title: 
+ name: 
+ action: 
+ Returns: 
+
 <!-- ##### FUNCTION e_shell_backend_get_filename ##### -->
 <para>
 
diff --git a/e-util/e-dialog-utils.c b/e-util/e-dialog-utils.c
index df0d8f5..19d9030 100644
--- a/e-util/e-dialog-utils.c
+++ b/e-util/e-dialog-utils.c
@@ -27,17 +27,6 @@
 
 #include "e-dialog-utils.h"
 
-#include <errno.h>
-#include <unistd.h>
-#include <glib/gstdio.h>
-
-#include <gconf/gconf-client.h>
-#include <glib/gi18n.h>
-
-#include "e-util/e-util.h"
-#include "e-util/e-error.h"
-
-
 /**
  * e_notice:
  * @parent: the dialog's parent window, or %NULL
@@ -71,107 +60,3 @@ e_notice (gpointer parent, GtkMessageType type, const gchar *format, ...)
 	gtk_dialog_run (GTK_DIALOG (dialog));
 	gtk_widget_destroy (dialog);
 }
-
-/**
- * e_file_get_save_filesel:
- * @parent: parent window
- * @title: dialog title
- * @name: filename; already in a proper form (suitable for file system)
- * @action: action for dialog
- *
- * Creates a save dialog, using the saved directory from gconf.   The dialog has
- * no signals connected and is not shown.
- **/
-GtkWidget *
-e_file_get_save_filesel (GtkWindow *parent,
-                         const gchar *title,
-                         const gchar *name,
-                         GtkFileChooserAction action)
-{
-	GtkWidget *filesel;
-	gchar *uri;
-
-	g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
-
-	filesel = gtk_file_chooser_dialog_new (
-		title, parent, action,
-		GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-		(action == GTK_FILE_CHOOSER_ACTION_OPEN) ?
-		GTK_STOCK_OPEN : GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL);
-	gtk_dialog_set_default_response (GTK_DIALOG (filesel), GTK_RESPONSE_OK);
-	gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (filesel), FALSE);
-
-	uri = e_file_get_save_path ();
-
-	gtk_file_chooser_set_current_folder_uri (
-		GTK_FILE_CHOOSER (filesel), uri);
-
-	if (name && name[0])
-		gtk_file_chooser_set_current_name (
-			GTK_FILE_CHOOSER (filesel), name);
-
-	g_free (uri);
-
-	return filesel;
-}
-
-/**
- * e_file_can_save:
- *
- * Return TRUE if the URI can be saved to, FALSE otherwise.  It checks local
- * files to see if they're regular and can be accessed.  If the file exists and
- * is writable, it pops up a dialog asking the user if they want to overwrite
- * it.  Returns the users choice.
- **/
-gboolean
-e_file_can_save(GtkWindow *parent, const gchar *uri)
-{
-	struct stat st;
-	gchar *path;
-	gboolean res;
-
-	if (!uri || uri[0] == 0)
-		return FALSE;
-
-	/* Assume remote files are writable; too costly to check */
-	if (!e_file_check_local(uri))
-		return TRUE;
-
-	path = g_filename_from_uri (uri, NULL, NULL);
-	if (!path)
-		return FALSE;
-
-	/* make sure we can actually save to it... */
-	if (g_stat (path, &st) != -1 && !S_ISREG (st.st_mode)) {
-		g_free(path);
-		return FALSE;
-	}
-
-	res = TRUE;
-	if (g_access (path, F_OK) == 0) {
-		if (g_access (path, W_OK) != 0) { e_error_run(parent, "mail:no-save-path", path, g_strerror(errno), NULL);
-			g_free(path);
-			return FALSE;
-		}
-
-		res = e_error_run(parent, E_ERROR_ASK_FILE_EXISTS_OVERWRITE, path, NULL) == GTK_RESPONSE_OK;
-
-	}
-
-	g_free(path);
-	return res;
-}
-
-gboolean
-e_file_check_local (const gchar *name)
-{
-	gchar *uri;
-
-	uri = g_filename_to_uri (name, NULL, NULL);
-	if (uri) {
-		g_free(uri);
-		return TRUE;
-	}
-
-	return FALSE;
-}
diff --git a/e-util/e-dialog-utils.h b/e-util/e-dialog-utils.h
index 2457f1c..d1e8b90 100644
--- a/e-util/e-dialog-utils.h
+++ b/e-util/e-dialog-utils.h
@@ -29,12 +29,5 @@ void		e_notice			(gpointer parent,
 						 GtkMessageType type,
 						 const gchar *format,
 						 ...);
-GtkWidget *	e_file_get_save_filesel		(GtkWindow *parent,
-						 const gchar *title,
-						 const gchar *name,
-						 GtkFileChooserAction action);
-gboolean	e_file_can_save			(GtkWindow *parent,
-						 const gchar *uri);
-gboolean	e_file_check_local		(const gchar *name);
 
 #endif /* E_DIALOG_UTILS_H */
diff --git a/e-util/e-util.c b/e-util/e-util.c
index 9ad252a..6a9ad6d 100644
--- a/e-util/e-util.c
+++ b/e-util/e-util.c
@@ -1283,66 +1283,6 @@ get_font_options (void)
 	return font_options;
 }
 
-/**
- * e_file_update_save_path:
- * @uri: URI to store
- * @free: If TRUE, free uri
- *
- * Save the save_dir path for evolution.  If free is TRUE, uri gets freed when
- * done.  Genearally, this should be called with the output of
- * gtk_file_chooser_get_current_folder_uri()  The URI must be a path URI, not a
- * file URI.
- **/
-void
-e_file_update_save_path (gchar *uri, gboolean free)
-{
-	GConfClient *gconf = gconf_client_get_default();
-	GError *error = NULL;
-
-	gconf_client_set_string(gconf, "/apps/evolution/mail/save_dir", uri, &error);
-	if (error != NULL) {
-		g_warning("%s (%s) %s", G_STRLOC, G_STRFUNC, error->message);
-		g_clear_error(&error);
-	}
-	g_object_unref(gconf);
-	if (free)
-		g_free(uri);
-}
-
-/**
- * e_file_get_save_path:
- *
- * Return the save_dir path for evolution.  If there isn't a save_dir, returns
- * the users home directory.  Returns an allocated URI that should be freed by
- * the caller.
- **/
-gchar *
-e_file_get_save_path (void)
-{
-	GConfClient *gconf = gconf_client_get_default();
-	GError *error = NULL;
-	gchar *uri;
-
-	uri = gconf_client_get_string(gconf, "/apps/evolution/mail/save_dir", &error);
-	if (error != NULL) {
-		g_warning("%s (%s) %s", G_STRLOC, G_STRFUNC, error->message);
-		g_clear_error(&error);
-	}
-	g_object_unref(gconf);
-
-	if (uri == NULL) {
-		GFile *file;
-
-		file = g_file_new_for_path (g_get_home_dir ());
-		if (file) {
-			uri = g_file_get_uri (file);
-			g_object_unref (file);
-		}
-	}
-
-	return (uri);
-}
-
 /* Evolution Locks for crash recovery */
 
 #define LOCK_FILE ".running"
diff --git a/e-util/e-util.h b/e-util/e-util.h
index 81ca053..d673cfe 100644
--- a/e-util/e-util.h
+++ b/e-util/e-util.h
@@ -129,10 +129,6 @@ gchar *		e_ascii_dtostr			(gchar *buffer,
 cairo_font_options_t *
 		get_font_options		(void);
 
-void		e_file_update_save_path		(gchar *uri,
-						 gboolean free);
-gchar *		e_file_get_save_path		(void);
-
 gboolean	e_file_lock_create		(void);
 void		e_file_lock_destroy		(void);
 gboolean	e_file_lock_exists		(void);
diff --git a/mail/e-mail-reader.c b/mail/e-mail-reader.c
index d77fafc..02739f0 100644
--- a/mail/e-mail-reader.c
+++ b/mail/e-mail-reader.c
@@ -34,7 +34,7 @@
 #include "e-util/e-charset.h"
 #include "e-util/e-util.h"
 #include "e-util/gconf-bridge.h"
-#include "shell/e-shell.h"
+#include "shell/e-shell-utils.h"
 #include "widgets/misc/e-popup-action.h"
 #include "widgets/misc/e-menu-tool-action.h"
 
@@ -801,18 +801,50 @@ static void
 action_mail_save_as_cb (GtkAction *action,
                         EMailReader *reader)
 {
+	EShell *shell;
+	EShellBackend *shell_backend;
 	MessageList *message_list;
+	CamelMessageInfo *info;
 	CamelFolder *folder;
-	GtkWindow *window;
 	GPtrArray *uids;
+	GFile *file;
+	const gchar *title;
+	const gchar *suggestion;
+	gchar *uri;
 
 	message_list = e_mail_reader_get_message_list (reader);
-	window = e_mail_reader_get_window (reader);
+	shell_backend = e_mail_reader_get_shell_backend (reader);
+	shell = e_shell_backend_get_shell (shell_backend);
 
 	folder = message_list->folder;
 	uids = message_list_get_selected (message_list);
+	g_return_if_fail (uids->len > 0);
+
+	title = ngettext ("Save Message", "Save Messages", uids->len);
+
+	/* 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);
+		camel_message_info_free (info);
+	} else
+		suggestion = NULL;
+
+	file = e_shell_run_save_dialog (shell, title, suggestion, NULL, NULL);
+
+	if (file == NULL) {
+		em_utils_uids_free (uids);
+		return;
+	}
+
+	uri = g_file_get_uri (file);
+
+	/* This eats the UID array, so do not free it. */
+	mail_save_messages (folder, uids, uri, NULL, NULL);
+
+	g_free (uri);
 
-	em_utils_save_messages (window, folder, uids);
+	g_object_unref (file);
 }
 
 static void
diff --git a/mail/em-utils.c b/mail/em-utils.c
index 4f26495..ee547c4 100644
--- a/mail/em-utils.c
+++ b/mail/em-utils.c
@@ -343,82 +343,6 @@ em_filename_make_safe (gchar *string)
 	}
 }
 
-/* Saving messages... */
-
-struct _save_messages_data {
-	CamelFolder *folder;
-	GPtrArray *uids;
-};
-
-static void
-emu_save_messages_response(GtkWidget *filesel, gint response, struct _save_messages_data *data)
-{
-	gchar *uri;
-
-	if (response == GTK_RESPONSE_OK) {
-		uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (filesel));
-
-		if (!e_file_can_save((GtkWindow *)filesel, uri)) {
-			g_free(uri);
-			return;
-		}
-
-		e_file_update_save_path(gtk_file_chooser_get_current_folder_uri(
-					GTK_FILE_CHOOSER (filesel)), TRUE);
-		mail_save_messages(data->folder, data->uids, uri, NULL, NULL);
-		data->uids = NULL;
-		g_free(uri);
-	}
-
-	camel_object_unref(data->folder);
-	if (data->uids)
-		em_utils_uids_free(data->uids);
-	g_free(data);
-	gtk_widget_destroy((GtkWidget *)filesel);
-}
-
-/**
- * em_utils_save_messages:
- * @parent: parent window
- * @folder: folder containing messages to save
- * @uids: uids of messages to save
- *
- * Saves a group of messages to disk in mbox format (prompting the
- * user for filename).
- **/
-void
-em_utils_save_messages (GtkWindow *parent, CamelFolder *folder, GPtrArray *uids)
-{
-	struct _save_messages_data *data;
-	GtkWidget *filesel;
-	gchar *filename = NULL;
-	CamelMessageInfo *info = NULL;
-
-	g_return_if_fail (GTK_IS_WINDOW (parent));
-	g_return_if_fail (CAMEL_IS_FOLDER (folder));
-	g_return_if_fail (uids != NULL);
-
-	info = camel_folder_get_message_info (folder, uids->pdata[0]);
-	if (info) {
-		filename = g_strdup (camel_message_info_subject (info));
-		e_filename_make_safe (filename);
-		camel_message_info_free (info);
-	}
-
-	filesel = e_file_get_save_filesel (parent, _("Save Message..."), filename, GTK_FILE_CHOOSER_ACTION_SAVE);
-	if (filename)
-		g_free (filename);
-
-	camel_object_ref(folder);
-
-	data = g_malloc(sizeof(struct _save_messages_data));
-	data->folder = folder;
-	data->uids = uids;
-
-	g_signal_connect(filesel, "response", G_CALLBACK(emu_save_messages_response), data);
-	gtk_widget_show((GtkWidget *)filesel);
-}
-
 /* ********************************************************************** */
 /* Flag-for-Followup... */
 
diff --git a/mail/em-utils.h b/mail/em-utils.h
index 9bb35b1..b61dce3 100644
--- a/mail/em-utils.h
+++ b/mail/em-utils.h
@@ -52,8 +52,6 @@ void em_utils_edit_filters (GtkWidget *parent);
 void em_filename_make_safe (gchar *string);
 void em_utils_edit_vfolders (GtkWidget *parent);
 
-void em_utils_save_messages (GtkWindow *parent, CamelFolder *folder, GPtrArray *uids);
-
 void em_utils_flag_for_followup (EMailReader *reader, CamelFolder *folder, GPtrArray *uids);
 void em_utils_flag_for_followup_clear (GtkWindow *parent, CamelFolder *folder, GPtrArray *uids);
 void em_utils_flag_for_followup_completed (GtkWindow *parent, CamelFolder *folder, GPtrArray *uids);
diff --git a/modules/addressbook/e-book-shell-view-actions.c b/modules/addressbook/e-book-shell-view-actions.c
index 6882f29..0ec4eac 100644
--- a/modules/addressbook/e-book-shell-view-actions.c
+++ b/modules/addressbook/e-book-shell-view-actions.c
@@ -225,9 +225,11 @@ action_address_book_save_as_cb (GtkAction *action,
 	if (list == NULL)
 		goto exit;
 
+	string = eab_suggest_filename (list);
 	file = e_shell_run_save_dialog (
-		shell, _("Save as vCard"),
-		(GtkCallback) eab_suggest_filename, list);
+		shell, _("Save as vCard"), string, NULL, NULL);
+	g_free (string);
+
 	if (file == NULL)
 		goto exit;
 
@@ -540,9 +542,11 @@ action_contact_save_as_cb (GtkAction *action,
 	if (list == NULL)
 		goto exit;
 
+	string = eab_suggest_filename (list);
 	file = e_shell_run_save_dialog (
-		shell, _("Save as vCard"),
-		(GtkCallback) eab_suggest_filename, list);
+		shell, _("Save as vCard"), string, NULL, NULL);
+	g_free (string);
+
 	if (file == NULL)
 		goto exit;
 
diff --git a/modules/calendar/e-cal-shell-view-actions.c b/modules/calendar/e-cal-shell-view-actions.c
index f3a0f20..d0ab20d 100644
--- a/modules/calendar/e-cal-shell-view-actions.c
+++ b/modules/calendar/e-cal-shell-view-actions.c
@@ -1099,7 +1099,7 @@ action_event_save_as_cb (GtkAction *action,
 	icalcomp = event->comp_data->icalcomp;
 
 	file = e_shell_run_save_dialog (
-		shell, _("Save as iCalendar"), NULL, NULL);
+		shell, _("Save as iCalendar"), NULL, NULL, NULL);
 	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 88cb53f..d786f47 100644
--- a/modules/calendar/e-cal-shell-view-memopad.c
+++ b/modules/calendar/e-cal-shell-view-memopad.c
@@ -259,7 +259,7 @@ action_calendar_memopad_save_as_cb (GtkAction *action,
 	g_slist_free (list);
 
 	file = e_shell_run_save_dialog (
-		shell, _("Save as iCalendar"), NULL, NULL);
+		shell, _("Save as iCalendar"), NULL, NULL, NULL);
 	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 5f2fd3a..a00474a 100644
--- a/modules/calendar/e-cal-shell-view-taskpad.c
+++ b/modules/calendar/e-cal-shell-view-taskpad.c
@@ -327,7 +327,7 @@ action_calendar_taskpad_save_as_cb (GtkAction *action,
 	g_slist_free (list);
 
 	file = e_shell_run_save_dialog (
-		shell, _("Save as iCalendar"), NULL, NULL);
+		shell, _("Save as iCalendar"), NULL, NULL, NULL);
 	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 31f12b3..4ffaa51 100644
--- a/modules/calendar/e-memo-shell-view-actions.c
+++ b/modules/calendar/e-memo-shell-view-actions.c
@@ -497,7 +497,7 @@ action_memo_save_as_cb (GtkAction *action,
 	g_slist_free (list);
 
 	file = e_shell_run_save_dialog (
-		shell, _("Save as iCalendar"), NULL, NULL);
+		shell, _("Save as iCalendar"), NULL, NULL, NULL);
 	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 282d5a3..07558bf 100644
--- a/modules/calendar/e-task-shell-view-actions.c
+++ b/modules/calendar/e-task-shell-view-actions.c
@@ -624,7 +624,7 @@ action_task_save_as_cb (GtkAction *action,
 	g_slist_free (list);
 
 	file = e_shell_run_save_dialog (
-		shell, _("Save as iCalendar"), NULL, NULL);
+		shell, _("Save as iCalendar"), NULL, NULL, NULL);
 	if (file == NULL)
 		return;
 
diff --git a/plugins/backup-restore/backup-restore.c b/plugins/backup-restore/backup-restore.c
index 50db1bb..f02e0d8 100644
--- a/plugins/backup-restore/backup-restore.c
+++ b/plugins/backup-restore/backup-restore.c
@@ -36,6 +36,7 @@
 #include "e-util/e-error.h"
 #include "e-util/e-util.h"
 #include "e-util/e-dialog-utils.h"
+#include "shell/e-shell-utils.h"
 #include "shell/e-shell-window.h"
 
 gboolean	e_plugin_ui_init		(GtkUIManager *ui_manager,
@@ -124,118 +125,108 @@ dialog_prompt_user(GtkWindow *parent, const gchar *string, const gchar *tag, con
 	return mask;
 }
 
-static gboolean
-epbr_perform_pre_backup_checks (gchar * dir)
+static void
+set_local_only (GtkFileChooser *file_chooser)
 {
-#ifdef G_OS_WIN32
-	return TRUE;
-#else
-	return (g_access (dir, W_OK) == 0);
-#endif
+	/* XXX Has to be a local file, since the backup utility
+	 *     takes a filename argument, not a URI. */
+	gtk_file_chooser_set_local_only (file_chooser, TRUE);
 }
 
 static void
 action_settings_backup_cb (GtkAction *action,
                            EShellWindow *shell_window)
 {
-	GtkWidget *dlg;
-	GtkWidget *vbox;
-	GtkWindow *parent;
-	gint response;
-
-	parent = GTK_WINDOW (shell_window);
-
-	dlg = e_file_get_save_filesel (
-		parent, _("Select name of the Evolution backup file"),
-		NULL, GTK_FILE_CHOOSER_ACTION_SAVE);
-
-	gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dlg), "evolution-backup.tar.gz");
+	GFile *file;
+	GFile *parent;
+	GFileInfo *file_info;
+	const gchar *attribute;
+	GError *error = NULL;
+
+	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)
+		set_local_only, NULL);
+
+	if (file == NULL)
+		return;
 
-	vbox = gtk_vbox_new (FALSE, 6);
-	gtk_widget_show (vbox);
+	/* Make sure the parent directory can be written to. */
 
-	response = gtk_dialog_run (GTK_DIALOG (dlg));
-	if (response == GTK_RESPONSE_OK) {
-		gchar *filename;
-		guint32 mask;
-		gchar *uri = NULL;
-		gchar *dir;
+	parent = g_file_get_parent (file);
+	attribute = G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE;
 
-		uri = gtk_file_chooser_get_current_folder_uri(GTK_FILE_CHOOSER (dlg));
-		e_file_update_save_path(uri, TRUE);
+	/* XXX The query operation blocks the main loop but we
+	 *     know it's a local file, so let it slide for now. */
+	file_info = g_file_query_info (
+		parent, attribute, G_FILE_QUERY_INFO_NONE, NULL, &error);
 
-		filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dlg));
-		dir = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dlg));
-		gtk_widget_destroy (dlg);
+	g_object_unref (parent);
 
-		if (epbr_perform_pre_backup_checks (dir)) {
+	if (error != NULL) {
+		g_warning ("%s", error->message);
+		g_error_free (error);
+		return;
+	}
 
-			mask = dialog_prompt_user (
-				parent, _("_Restart Evolution after backup"),
-				"org.gnome.backup-restore:backup-confirm", NULL);
-			if (mask & BR_OK)
-				backup (filename, (mask & BR_START) ? TRUE: FALSE);
-		} else {
-			e_error_run (parent, "org.gnome.backup-restore:insufficient-permissions", NULL);
+	if (g_file_info_get_attribute_boolean (file_info, attribute)) {
+		guint32 mask;
+		gchar *path;
+
+		mask = dialog_prompt_user (
+			GTK_WINDOW (shell_window),
+			_("_Restart Evolution after backup"),
+			"org.gnome.backup-restore:backup-confirm", NULL);
+		if (mask & BR_OK) {
+			path = g_file_get_path (file);
+			backup (path, (mask & BR_START) ? TRUE: FALSE);
+			g_free (path);
 		}
-
-		g_free (filename);
-		g_free (dir);
-
-		return;
+	} else {
+		e_error_run (
+			GTK_WINDOW (shell_window),
+			"org.gnome.backup-restore:insufficient-permissions", NULL);
 	}
 
-	gtk_widget_destroy (dlg);
+	g_object_unref (file_info);
+	g_object_unref (file);
 }
 
 static void
 action_settings_restore_cb (GtkAction *action,
                             EShellWindow *shell_window)
 {
-	GtkWidget *dlg;
-	GtkWidget *vbox;
-	GtkWindow *parent;
-	gint response;
-
-	parent = GTK_WINDOW (shell_window);
+	GFile *file;
+	gchar *path;
 
-	dlg = e_file_get_save_filesel (
-		parent,
+	file = e_shell_run_open_dialog (
+		e_shell_window_get_shell (shell_window),
 		_("Select name of the Evolution backup file to restore"),
-		NULL, GTK_FILE_CHOOSER_ACTION_OPEN);
-
-	vbox = gtk_vbox_new (FALSE, 6);
-	gtk_widget_show (vbox);
-
-	response = gtk_dialog_run (GTK_DIALOG (dlg));
-	if (response == GTK_RESPONSE_OK) {
-		gchar *filename;
-		gchar *uri = NULL;
-
-		uri = gtk_file_chooser_get_current_folder_uri(GTK_FILE_CHOOSER (dlg));
-		e_file_update_save_path(uri, TRUE);
+		(GtkCallback) set_local_only, NULL);
 
-		filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dlg));
-		gtk_widget_destroy (dlg);
-
-		if (sanity_check (filename)) {
-			guint32 mask;
+	if (file == NULL)
+		return;
 
-			mask = dialog_prompt_user (
-				parent, _("_Restart Evolution after restore"),
-				"org.gnome.backup-restore:restore-confirm", NULL);
-			if (mask & BR_OK)
-				restore (filename, mask & BR_START);
-		} else {
-			e_error_run (parent, "org.gnome.backup-restore:invalid-backup", NULL);
-		}
+	path = g_file_get_path (file);
 
-		g_free (filename);
+	if (sanity_check (path)) {
+		guint32 mask;
 
-		return;
+		mask = dialog_prompt_user (
+			GTK_WINDOW (shell_window),
+			_("_Restart Evolution after restore"),
+			"org.gnome.backup-restore:restore-confirm", NULL);
+		if (mask & BR_OK)
+			restore (path, mask & BR_START);
+	} else {
+		e_error_run (
+			GTK_WINDOW (shell_window),
+			"org.gnome.backup-restore:invalid-backup", NULL);
 	}
 
-	gtk_widget_destroy (dlg);
+	g_object_unref (file);
+	g_free (path);
 }
 
 static void
@@ -255,10 +246,6 @@ static void
 file_changed (GtkFileChooser *chooser, GtkAssistant *assistant)
 {
 	gchar *file = NULL, *prevfile = NULL;
-	gchar *uri = NULL;
-
-	uri = gtk_file_chooser_get_current_folder_uri (GTK_FILE_CHOOSER (chooser));
-	e_file_update_save_path (uri, TRUE);
 
 	file = gtk_file_chooser_get_filename (chooser);
 	prevfile = g_object_get_data ((GObject *)assistant, "restore-file");
diff --git a/plugins/itip-formatter/itip-formatter.c b/plugins/itip-formatter/itip-formatter.c
index 658acc0..32fdf23 100644
--- a/plugins/itip-formatter/itip-formatter.c
+++ b/plugins/itip-formatter/itip-formatter.c
@@ -1502,22 +1502,24 @@ save_vcalendar_cb (GtkWidget *button, struct _itip_puri *pitip)
 	EAttachment *attachment;
 	EShell *shell;
 	GFile *file;
+	const gchar *suggestion;
 
 	g_return_if_fail (pitip != NULL);
 	g_return_if_fail (pitip->vcalendar != NULL);
 	g_return_if_fail (pitip->part != NULL);
 
+	suggestion = camel_mime_part_get_filename (pitip->part);
+	if (suggestion == NULL) {
+		/* Translators: This is a default filename for a calendar. */
+		suggestion = _("calendar.ics");
+	}
+
 	shell = e_shell_get_default ();
 	file = e_shell_run_save_dialog (
-		shell, _("Save Calendar"), NULL, NULL);
+		shell, _("Save Calendar"), suggestion, NULL, NULL);
 	if (file == NULL)
 		return;
 
-	if (!camel_mime_part_get_filename (pitip->part)) {
-		/* Translators: This is a default filename for a calendar. */
-		camel_mime_part_set_filename (pitip->part, _("calendar.ics"));
-	}
-
 	attachment = e_attachment_new ();
 	e_attachment_set_mime_part (attachment, pitip->part);
 
diff --git a/shell/e-shell-utils.c b/shell/e-shell-utils.c
index 9d3d6f5..4d4f0fd 100644
--- a/shell/e-shell-utils.c
+++ b/shell/e-shell-utils.c
@@ -24,9 +24,86 @@
 #include <glib/gi18n-lib.h>
 
 /**
+ * e_shell_run_open_dialog:
+ * @shell: an #EShell
+ * @title: file chooser dialog title
+ * @customize_func: optional dialog customization function
+ * @customize_data: optional data to pass to @customize_func
+ *
+ * Runs a #GtkFileChooserDialog in open mode with the given title and
+ * returns the selected #GFile.  It automatically remembers the selected
+ * folder.  If @customize_func is provided, the function is called just
+ * prior to running the dialog (the file chooser is the first argument,
+ * @customize data is the second).  If the user cancels the dialog the
+ * function will return %NULL.
+ *
+ * Returns: the #GFile to open, or %NULL
+ **/
+GFile *
+e_shell_run_open_dialog (EShell *shell,
+                         const gchar *title,
+                         GtkCallback customize_func,
+                         gpointer customize_data)
+{
+	EShellSettings *shell_settings;
+	GtkFileChooser *file_chooser;
+	GFile *chosen_file = NULL;
+	GtkWidget *dialog;
+	GtkWindow *parent;
+	const gchar *property_name;
+	gchar *uri;
+
+	g_return_val_if_fail (E_IS_SHELL (shell), NULL);
+
+	property_name = "file-chooser-folder";
+	shell_settings = e_shell_get_shell_settings (shell);
+
+	parent = e_shell_get_active_window (shell);
+
+	dialog = gtk_file_chooser_dialog_new (
+		title, parent,
+		GTK_FILE_CHOOSER_ACTION_OPEN,
+		GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+		GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
+
+	file_chooser = GTK_FILE_CHOOSER (dialog);
+
+	gtk_dialog_set_default_response (
+		GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
+
+	gtk_file_chooser_set_local_only (file_chooser, FALSE);
+
+	/* Restore the current folder from the previous file chooser. */
+	uri = e_shell_settings_get_string (shell_settings, property_name);
+	if (uri != NULL)
+		gtk_file_chooser_set_current_folder_uri (file_chooser, uri);
+	g_free (uri);
+
+	/* Allow further customizations before running the dialog. */
+	if (customize_func != NULL)
+		customize_func (dialog, customize_data);
+
+	if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_ACCEPT)
+		goto exit;
+
+	chosen_file = gtk_file_chooser_get_file (file_chooser);
+
+	/* Save the current folder for subsequent file choosers. */
+	uri = gtk_file_chooser_get_current_folder_uri (file_chooser);
+	e_shell_settings_set_string (shell_settings, property_name, uri);
+	g_free (uri);
+
+exit:
+	gtk_widget_destroy (dialog);
+
+	return chosen_file;
+}
+
+/**
  * e_shell_run_save_dialog:
  * @shell: an #EShell
  * @title: file chooser dialog title
+ * @suggestion: file name suggestion, or %NULL
  * @customize_func: optional dialog customization function
  * @customize_data: optional data to pass to @customize_func
  *
@@ -42,6 +119,7 @@
 GFile *
 e_shell_run_save_dialog (EShell *shell,
                          const gchar *title,
+                         const gchar *suggestion,
                          GtkCallback customize_func,
                          gpointer customize_data)
 {
@@ -64,11 +142,12 @@ e_shell_run_save_dialog (EShell *shell,
 		title, parent,
 		GTK_FILE_CHOOSER_ACTION_SAVE,
 		GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-		GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL);
+		GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL);
 
 	file_chooser = GTK_FILE_CHOOSER (dialog);
 
-	gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+	gtk_dialog_set_default_response (
+		GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
 
 	gtk_file_chooser_set_local_only (file_chooser, FALSE);
 	gtk_file_chooser_set_do_overwrite_confirmation (file_chooser, TRUE);
@@ -79,11 +158,14 @@ e_shell_run_save_dialog (EShell *shell,
 		gtk_file_chooser_set_current_folder_uri (file_chooser, uri);
 	g_free (uri);
 
+	if (suggestion != NULL)
+		gtk_file_chooser_set_current_name (file_chooser, suggestion);
+
 	/* Allow further customizations before running the dialog. */
 	if (customize_func != NULL)
 		customize_func (dialog, customize_data);
 
-	if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK)
+	if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_ACCEPT)
 		goto exit;
 
 	chosen_file = gtk_file_chooser_get_file (file_chooser);
diff --git a/shell/e-shell-utils.h b/shell/e-shell-utils.h
index 6fedca8..24ca617 100644
--- a/shell/e-shell-utils.h
+++ b/shell/e-shell-utils.h
@@ -32,8 +32,14 @@
 
 G_BEGIN_DECLS
 
+GFile *		e_shell_run_open_dialog		(EShell *shell,
+						 const gchar *title,
+						 GtkCallback customize_func,
+						 gpointer customize_data);
+
 GFile *		e_shell_run_save_dialog		(EShell *shell,
 						 const gchar *title,
+						 const gchar *suggestion,
 						 GtkCallback customize_func,
 						 gpointer customize_data);
 



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