summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Wilmet <swilmet@gnome.org>2016-05-07 17:36:57 +0200
committerSébastien Wilmet <swilmet@gnome.org>2016-05-07 17:36:57 +0200
commit4b916a8d62be3303ee77e4a99139917e975ad505 (patch)
treec4ad166de2a118f91027e10db760f873c4f5ad4d
parentc83d8ebb39125f17bbd9474e4a448369216523af (diff)
downloadgtksourceview-wip/better-use-gtask.tar.gz
FileSaver: move some of the instance variables to a TaskData structwip/better-use-gtask
Do the same as for the FileLoader, see: commit f2e49122492fa2a116fdaf2106edb6538f096856
-rw-r--r--gtksourceview/gtksourcefilesaver.c100
1 files changed, 54 insertions, 46 deletions
diff --git a/gtksourceview/gtksourcefilesaver.c b/gtksourceview/gtksourcefilesaver.c
index d754f5ea..a565de33 100644
--- a/gtksourceview/gtksourcefilesaver.c
+++ b/gtksourceview/gtksourcefilesaver.c
@@ -99,45 +99,75 @@ struct _GtkSourceFileSaverPrivate
GtkSourceFileSaverFlags flags;
GTask *task;
+};
- /* This field is used when cancelling the output stream: an error occurs
- * and is stored in this field, the output stream is cancelled
- * asynchronously, and then the error is reported to the task.
+typedef struct _TaskData TaskData;
+struct _TaskData
+{
+ /* The output_stream contains the required converter(s) for the encoding
+ * and the compression type.
+ * The two streams cannot be spliced directly, because:
+ * (1) We need to call the progress callback.
+ * (2) Sync methods must be used for the input stream, and async
+ * methods for the output stream.
*/
- GError *error;
+ GtkSourceBufferInputStream *input_stream;
+ GOutputStream *output_stream;
+
+ GFileInfo *info;
goffset total_size;
GFileProgressCallback progress_cb;
gpointer progress_cb_data;
GDestroyNotify progress_cb_notify;
- /* Warning: type instances' private data are limited to a total of 64 KiB.
- * See the GType documentation.
+ /* This field is used when cancelling the output stream: an error occurs
+ * and is stored in this field, the output stream is cancelled
+ * asynchronously, and then the error is reported to the task.
*/
- gchar chunk_buffer[WRITE_CHUNK_SIZE];
+ GError *error;
+
gssize chunk_bytes_read;
gssize chunk_bytes_written;
-
- /* The output_stream contains the required converter(s) for the encoding
- * and the compression type.
- * The two streams cannot be spliced directly, because
- * (1) we need to call the progress callback
- * (2) sync methods must be used for the input stream, and async
- * methods for the output stream.
- */
- GOutputStream *output_stream;
- GtkSourceBufferInputStream *input_stream;
-
- GFileInfo *info;
+ gchar chunk_buffer[WRITE_CHUNK_SIZE];
guint tried_mount : 1;
};
G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceFileSaver, gtk_source_file_saver, G_TYPE_OBJECT)
-static void read_file_chunk (GtkSourceFileSaver *saver);
-static void write_file_chunk (GtkSourceFileSaver *saver);
-static void recover_not_mounted (GtkSourceFileSaver *saver);
+static void read_file_chunk (GTask *task);
+static void write_file_chunk (GTask *task);
+static void recover_not_mounted (GTask *task);
+
+static TaskData *
+task_data_new (void)
+{
+ return g_new0 (TaskData, 1);
+}
+
+static void
+task_data_free (gpointer data)
+{
+ TaskData *task_data = data;
+
+ if (task_data == NULL)
+ {
+ return;
+ }
+
+ g_clear_object (&task_data->input_stream);
+ g_clear_object (&task_data->output_stream);
+ g_clear_object (&task_data->info);
+ g_clear_error (&task_data->error);
+
+ if (saver->priv->progress_cb_notify != NULL)
+ {
+ saver->priv->progress_cb_notify (saver->priv->progress_cb_data);
+ }
+
+ g_free (task_data);
+}
static void
gtk_source_file_saver_set_property (GObject *object,
@@ -235,31 +265,10 @@ gtk_source_file_saver_get_property (GObject *object,
}
static void
-reset (GtkSourceFileSaver *saver)
-{
- g_clear_object (&saver->priv->task);
- g_clear_object (&saver->priv->output_stream);
- g_clear_object (&saver->priv->input_stream);
- g_clear_object (&saver->priv->info);
- g_clear_error (&saver->priv->error);
-
- if (saver->priv->progress_cb_notify != NULL)
- {
- saver->priv->progress_cb_notify (saver->priv->progress_cb_data);
- saver->priv->progress_cb_notify = NULL;
- }
-
- saver->priv->progress_cb = NULL;
- saver->priv->progress_cb_data = NULL;
-}
-
-static void
gtk_source_file_saver_dispose (GObject *object)
{
GtkSourceFileSaver *saver = GTK_SOURCE_FILE_SAVER (object);
- reset (saver);
-
if (saver->priv->source_buffer != NULL)
{
g_object_remove_weak_pointer (G_OBJECT (saver->priv->source_buffer),
@@ -277,6 +286,7 @@ gtk_source_file_saver_dispose (GObject *object)
}
g_clear_object (&saver->priv->location);
+ g_clear_object (&saver->priv->task);
G_OBJECT_CLASS (gtk_source_file_saver_parent_class)->dispose (object);
}
@@ -1323,8 +1333,6 @@ gtk_source_file_saver_save_async (GtkSourceFileSaver *saver,
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
g_return_if_fail (saver->priv->task == NULL);
- reset (saver);
-
saver->priv->task = g_task_new (saver, cancellable, callback, user_data);
g_task_set_priority (saver->priv->task, io_priority);
@@ -1431,7 +1439,7 @@ gtk_source_file_saver_save_finish (GtkSourceFileSaver *saver,
FALSE);
}
- reset (saver);
+ g_clear_object (&saver->priv->task);
return ok;
}