aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
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 /e-util
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 'e-util')
-rw-r--r--e-util/e-dialog-utils.c32
-rw-r--r--e-util/e-dialog-utils.h3
-rw-r--r--e-util/e-file-utils.c39
-rw-r--r--e-util/e-util.c59
-rw-r--r--e-util/e-util.h2
5 files changed, 37 insertions, 98 deletions
diff --git a/e-util/e-dialog-utils.c b/e-util/e-dialog-utils.c
index 952d73f303..df0d8f5129 100644
--- a/e-util/e-dialog-utils.c
+++ b/e-util/e-dialog-utils.c
@@ -72,38 +72,6 @@ e_notice (gpointer parent, GtkMessageType type, const gchar *format, ...)
gtk_widget_destroy (dialog);
}
-gchar *
-e_file_dialog_save (GtkWindow *parent,
- const gchar *title,
- const gchar *fname)
-{
- GtkWidget *dialog;
- gchar *filename = NULL;
- gchar *uri;
-
- g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
-
- dialog = e_file_get_save_filesel (
- parent, title, fname, GTK_FILE_CHOOSER_ACTION_SAVE);
-
- if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK)
- goto exit;
-
- uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
-
- if (e_file_can_save (GTK_WINDOW (dialog), uri)) {
- e_file_update_save_path (
- gtk_file_chooser_get_current_folder_uri (
- GTK_FILE_CHOOSER (dialog)), TRUE);
- filename = uri; /* FIXME This looks wrong. */
- }
-
-exit:
- gtk_widget_destroy (dialog);
-
- return filename;
-}
-
/**
* e_file_get_save_filesel:
* @parent: parent window
diff --git a/e-util/e-dialog-utils.h b/e-util/e-dialog-utils.h
index b4f305bdd5..2457f1c37a 100644
--- a/e-util/e-dialog-utils.h
+++ b/e-util/e-dialog-utils.h
@@ -29,9 +29,6 @@ void e_notice (gpointer parent,
GtkMessageType type,
const gchar *format,
...);
-gchar * e_file_dialog_save (GtkWindow *parent,
- const gchar *title,
- const gchar *fname);
GtkWidget * e_file_get_save_filesel (GtkWindow *parent,
const gchar *title,
const gchar *name,
diff --git a/e-util/e-file-utils.c b/e-util/e-file-utils.c
index f8adcc7a60..015da072f3 100644
--- a/e-util/e-file-utils.c
+++ b/e-util/e-file-utils.c
@@ -86,6 +86,24 @@ file_replace_contents_cb (GFile *file,
g_object_unref (activity);
}
+/**
+ * e_file_replace_contents_async:
+ * @file: input #GFile
+ * @contents: string of contents to replace the file with
+ * @length: the length of @contents in bytes
+ * @etag: a new entity tag for the @file, or %NULL
+ * @make_backup: %TRUE if a backup should be created
+ * @flags: a set of #GFileCreateFlags
+ * @callback: a #GAsyncReadyCallback to call when the request is satisfied
+ * @user_data: the data to pass to the callback function
+ *
+ * This is a wrapper for g_file_replace_contents_async() that also returns
+ * an #EActivity to track the file operation. Cancelling the activity will
+ * cancel the file operation. See g_file_replace_contents_async() for more
+ * details.
+ *
+ * Returns: an #EActivity for the file operation
+ **/
EActivity *
e_file_replace_contents_async (GFile *file,
const gchar *contents,
@@ -111,9 +129,12 @@ e_file_replace_contents_async (GFile *file,
uri = g_file_get_uri (file);
filename = g_filename_from_uri (uri, &hostname, NULL);
- basename = g_filename_display_basename (filename);
+ if (filename != NULL)
+ basename = g_filename_display_basename (filename);
+ else
+ basename = g_strdup (_("(Unknown Filename)"));
- if (hostname != NULL) {
+ if (hostname == NULL) {
/* Translators: The string value is the basename of a file. */
format = _("Writing \"%s\"");
description = g_strdup_printf (format, basename);
@@ -151,6 +172,20 @@ e_file_replace_contents_async (GFile *file,
return activity;
}
+/**
+ * e_file_replace_contents_finish:
+ * @file: input #GFile
+ * @result: a #GAsyncResult
+ * @new_etag: return location for a new entity tag
+ * @error: return location for a #GError, or %NULL
+ *
+ * Finishes an asynchronous replace of the given @file. See
+ * e_file_replace_contents_async(). Sets @new_etag to the new entity
+ * tag for the document, if present. Free it with g_free() when it is
+ * no longer needed.
+ *
+ * Returns: %TRUE on success, %FALSE on failure
+ **/
gboolean
e_file_replace_contents_finish (GFile *file,
GAsyncResult *result,
diff --git a/e-util/e-util.c b/e-util/e-util.c
index bf1f387d15..9ad252a37d 100644
--- a/e-util/e-util.c
+++ b/e-util/e-util.c
@@ -618,65 +618,6 @@ e_int_compare (gconstpointer x, gconstpointer y)
return (nx == ny) ? 0 : (nx < ny) ? -1 : 1;
}
-gboolean
-e_write_file_uri (const gchar *filename,
- const gchar *data)
-{
- gboolean res;
- gsize length;
- GFile *file;
- GOutputStream *stream;
- GError *error = NULL;
-
- g_return_val_if_fail (filename != NULL, FALSE);
- g_return_val_if_fail (data != NULL, FALSE);
-
- length = strlen (data);
-
- /* if it is uri, then create file for uri, otherwise for path */
- if (strstr (filename, "://"))
- file = g_file_new_for_uri (filename);
- else
- file = g_file_new_for_path (filename);
-
- if (!file) {
- g_warning ("Couldn't save item");
- return FALSE;
- }
-
- stream = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, &error));
- g_object_unref (file);
-
- if (!stream || error) {
- g_warning ("Couldn't save item%s%s", error ? ": " : "", error ? error->message : "");
-
- if (stream)
- g_object_unref (stream);
-
- if (error)
- g_error_free (error);
-
- return FALSE;
- }
-
- res = g_output_stream_write_all (stream, data, length, NULL, NULL, &error);
-
- if (error) {
- g_warning ("Couldn't save item: %s", error->message);
- g_clear_error (&error);
- }
-
- g_output_stream_close (stream, NULL, &error);
- g_object_unref (stream);
-
- if (error) {
- g_warning ("Couldn't close output stream: %s", error->message);
- g_error_free (error);
- }
-
- return res;
-}
-
/**
* e_color_to_value:
* color: a #GdkColor
diff --git a/e-util/e-util.h b/e-util/e-util.h
index 88ebaa2af7..81ca05327c 100644
--- a/e-util/e-util.h
+++ b/e-util/e-util.h
@@ -81,8 +81,6 @@ gint e_collate_compare (gconstpointer x,
gconstpointer y);
gint e_int_compare (gconstpointer x,
gconstpointer y);
-gboolean e_write_file_uri (const gchar *filename,
- const gchar *data);
guint32 e_color_to_value (GdkColor *color);
/* This only makes a filename safe for usage as a filename.