aboutsummaryrefslogtreecommitdiffstats
path: root/shell
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2009-11-08 01:44:44 +0800
committerMatthew Barnes <mbarnes@redhat.com>2009-11-08 03:01:46 +0800
commit86ecfc50539ddef82205551c11a6a13b135bbab4 (patch)
treecc25ca582935748885a23d665a1d9e1bbc1d4d9c /shell
parentaa66a17e401d73cbe394ed7f99bf73350e9b938b (diff)
downloadgsoc2013-evolution-86ecfc50539ddef82205551c11a6a13b135bbab4.tar.gz
gsoc2013-evolution-86ecfc50539ddef82205551c11a6a13b135bbab4.tar.zst
gsoc2013-evolution-86ecfc50539ddef82205551c11a6a13b135bbab4.zip
Convert some "Save As" actions to run asynchronously.
This introduces e-shell-utils for miscellaneous utility functions that integrate with the shell or shell settings. First function is e_shell_run_save_dialog(), which automatically remembers the selected folder in the file chooser dialog. Also, kill some redundant save dialog functions, as well as some write-this-string-to-disk functions that block.
Diffstat (limited to 'shell')
-rw-r--r--shell/Makefile.am5
-rw-r--r--shell/apps_evolution_shell.schemas.in4
-rw-r--r--shell/e-shell-utils.c100
-rw-r--r--shell/e-shell-utils.h42
-rw-r--r--shell/e-shell.c14
5 files changed, 151 insertions, 14 deletions
diff --git a/shell/Makefile.am b/shell/Makefile.am
index d8eea3c5e3..608ecd314d 100644
--- a/shell/Makefile.am
+++ b/shell/Makefile.am
@@ -26,6 +26,7 @@ eshellinclude_HEADERS = \
e-shell-sidebar.h \
e-shell-switcher.h \
e-shell-taskbar.h \
+ e-shell-utils.h \
e-shell-view.h \
e-shell-window.h \
e-shell-window-actions.h \
@@ -59,7 +60,7 @@ libeshell_la_CPPFLAGS = \
libeshell_la_SOURCES = \
$(NM_SUPPORT_FILES) \
- $(IDL_GENERATED) \
+ $(eshellinclude_HEADERS) \
e-shell.c \
e-shell-backend.c \
e-shell-content.c \
@@ -67,11 +68,11 @@ libeshell_la_SOURCES = \
e-shell-sidebar.c \
e-shell-switcher.c \
e-shell-taskbar.c \
+ e-shell-utils.c \
e-shell-view.c \
e-shell-window.c \
e-shell-window-private.c \
e-shell-window-private.h \
- $(eshellinclude_HEADERS) \
e-shell-migrate.c \
e-shell-migrate.h \
e-shell-window-actions.c \
diff --git a/shell/apps_evolution_shell.schemas.in b/shell/apps_evolution_shell.schemas.in
index 157df8cb9e..b5aa3e6931 100644
--- a/shell/apps_evolution_shell.schemas.in
+++ b/shell/apps_evolution_shell.schemas.in
@@ -59,8 +59,8 @@
<!-- Initial GtkFileChooser Folder -->
<schema>
- <key>/schemas/apps/evolution/shell/current_folder</key>
- <applyto>/apps/evolution/shell/current_folder</applyto>
+ <key>/schemas/apps/evolution/shell/file_chooser_folder</key>
+ <applyto>/apps/evolution/shell/file_chooser_folder</applyto>
<owner>evolution</owner>
<type>string</type>
<locale name="C">
diff --git a/shell/e-shell-utils.c b/shell/e-shell-utils.c
new file mode 100644
index 0000000000..9d3d6f5fb4
--- /dev/null
+++ b/shell/e-shell-utils.c
@@ -0,0 +1,100 @@
+/*
+ * e-shell-utils.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ *
+ * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
+ *
+ */
+
+#include "e-shell-utils.h"
+
+#include <glib/gi18n-lib.h>
+
+/**
+ * e_shell_run_save_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 save 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 save to, or %NULL
+ **/
+GFile *
+e_shell_run_save_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_SAVE,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL);
+
+ file_chooser = GTK_FILE_CHOOSER (dialog);
+
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+
+ gtk_file_chooser_set_local_only (file_chooser, FALSE);
+ gtk_file_chooser_set_do_overwrite_confirmation (file_chooser, TRUE);
+
+ /* 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_OK)
+ 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;
+}
diff --git a/shell/e-shell-utils.h b/shell/e-shell-utils.h
new file mode 100644
index 0000000000..6fedca8a4a
--- /dev/null
+++ b/shell/e-shell-utils.h
@@ -0,0 +1,42 @@
+/*
+ * e-shell-utils.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ *
+ * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
+ *
+ */
+
+/**
+ * SECTION: e-shell-utils
+ * @short_description: high-level utilities with shell integration
+ * @include: shell/e-shell-utils.h
+ **/
+
+#ifndef E_SHELL_UTILS_H
+#define E_SHELL_UTILS_H
+
+#include <shell/e-shell.h>
+
+G_BEGIN_DECLS
+
+GFile * e_shell_run_save_dialog (EShell *shell,
+ const gchar *title,
+ GtkCallback customize_func,
+ gpointer customize_data);
+
+G_END_DECLS
+
+#endif /* E_SHELL_UTILS_H */
diff --git a/shell/e-shell.c b/shell/e-shell.c
index 61ce8d7c02..b0a1490148 100644
--- a/shell/e-shell.c
+++ b/shell/e-shell.c
@@ -903,16 +903,6 @@ shell_class_init (EShellClass *class)
0, NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
-
- /* Install some application-wide settings. */
-
- e_shell_settings_install_property (
- g_param_spec_string (
- "file-chooser-folder",
- NULL,
- NULL,
- NULL,
- G_PARAM_READWRITE));
}
static void
@@ -950,6 +940,10 @@ shell_init (EShell *shell)
* otherwise the GConf bindings will not get set up. */
e_shell_settings_install_property_for_key (
+ "file-chooser-folder",
+ "/apps/evolution/shell/file_chooser_folder");
+
+ e_shell_settings_install_property_for_key (
"start-offline",
"/apps/evolution/shell/start_offline");