diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2009-11-11 01:14:07 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2009-11-11 07:18:11 +0800 |
commit | 3dfdf087fc7657905fc7804b59414ecd3d74028e (patch) | |
tree | 45a5bb547ca73ebaea9c3276860f93df6d417006 /plugins | |
parent | f70ecb0406903e0fdc09bbf1c9a3367c7ba55ec2 (diff) | |
download | gsoc2013-evolution-3dfdf087fc7657905fc7804b59414ecd3d74028e.tar gsoc2013-evolution-3dfdf087fc7657905fc7804b59414ecd3d74028e.tar.gz gsoc2013-evolution-3dfdf087fc7657905fc7804b59414ecd3d74028e.tar.bz2 gsoc2013-evolution-3dfdf087fc7657905fc7804b59414ecd3d74028e.tar.lz gsoc2013-evolution-3dfdf087fc7657905fc7804b59414ecd3d74028e.tar.xz gsoc2013-evolution-3dfdf087fc7657905fc7804b59414ecd3d74028e.tar.zst gsoc2013-evolution-3dfdf087fc7657905fc7804b59414ecd3d74028e.zip |
Kill more redundant save dialogs and related utilities.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/backup-restore/backup-restore.c | 159 | ||||
-rw-r--r-- | plugins/itip-formatter/itip-formatter.c | 14 |
2 files changed, 81 insertions, 92 deletions
diff --git a/plugins/backup-restore/backup-restore.c b/plugins/backup-restore/backup-restore.c index 50db1bbf76..f02e0d8565 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 658acc07dc..32fdf23e7d 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); |