[gtksourceview/wip/loader-saver] FileSaver: better names for input and output streams



commit e1c78b7cc7d7a5dfd20995f0d5586f788a6ac4f8
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Tue Dec 24 17:54:17 2013 +0100

    FileSaver: better names for input and output streams

 gtksourceview/gtksourcefilesaver.c |   61 ++++++++++++++++++++----------------
 1 files changed, 34 insertions(+), 27 deletions(-)
---
diff --git a/gtksourceview/gtksourcefilesaver.c b/gtksourceview/gtksourcefilesaver.c
index b3ef0a0..261f967 100644
--- a/gtksourceview/gtksourcefilesaver.c
+++ b/gtksourceview/gtksourcefilesaver.c
@@ -82,10 +82,14 @@ struct _GtkSourceFileSaverPrivate
 
        GCancellable *cancellable;
 
-       /* TODO find better names for these two fields */
-       GOutputStream *stream;
-       GInputStream *input;
+       /* The output_stream contains the required converter(s) for the encoding
+        * and the compression type. The input_stream is the
+        * GtkSourceBufferInputStream (thus in UTF-8, without compression).
+        */
+       GOutputStream *output_stream;
+       GInputStream *input_stream;
 
+       /* TODO use this in GtkSourceFile */
        GtkSourceMountOperationFactory mount_operation_factory;
        gpointer mount_operation_userdata;
 
@@ -199,8 +203,8 @@ gtk_source_file_saver_dispose (GObject *object)
 {
        GtkSourceFileSaverPrivate *priv = GTK_SOURCE_FILE_SAVER (object)->priv;
 
-       g_clear_object (&priv->stream);
-       g_clear_object (&priv->input);
+       g_clear_object (&priv->output_stream);
+       g_clear_object (&priv->input_stream);
        g_clear_object (&priv->location);
        g_clear_object (&priv->task);
 
@@ -375,7 +379,7 @@ cancel_output_stream (AsyncData *async)
        cancellable = g_cancellable_new ();
        g_cancellable_cancel (cancellable);
 
-       g_output_stream_close_async (async->saver->priv->stream,
+       g_output_stream_close_async (async->saver->priv->output_stream,
                                     G_PRIORITY_HIGH,
                                     cancellable,
                                     (GAsyncReadyCallback)cancel_output_stream_ready_cb,
@@ -445,7 +449,7 @@ write_complete (GtkSourceFileSaver *saver)
               g_print ("Close input stream\n");
        });
 
-       g_input_stream_close (saver->priv->input,
+       g_input_stream_close (saver->priv->input_stream,
                              g_task_get_cancellable (saver->priv->task),
                              &error);
 
@@ -467,7 +471,7 @@ write_complete (GtkSourceFileSaver *saver)
               g_print ("Close output stream\n");
        });
 
-       g_output_stream_close_async (saver->priv->stream,
+       g_output_stream_close_async (saver->priv->output_stream,
                                     g_task_get_priority (saver->priv->task),
                                     g_task_get_cancellable (saver->priv->task),
                                     (GAsyncReadyCallback) close_output_stream_cb,
@@ -520,7 +524,7 @@ write_file_chunk_cb (GOutputStream      *output_stream,
                GtkSourceBufferInputStream *buffer_stream;
                gsize total_chars_written;
 
-               buffer_stream = GTK_SOURCE_BUFFER_INPUT_STREAM (saver->priv->input);
+               buffer_stream = GTK_SOURCE_BUFFER_INPUT_STREAM (saver->priv->input_stream);
                total_chars_written = _gtk_source_buffer_input_stream_tell (buffer_stream);
 
                saver->priv->progress_cb (total_chars_written,
@@ -541,7 +545,7 @@ write_file_chunk (GtkSourceFileSaver *saver)
        /* FIXME check if a thread is created each time this function is called.
         * If so, this is a performance problem and should be fixed.
         */
-       g_output_stream_write_async (G_OUTPUT_STREAM (saver->priv->stream),
+       g_output_stream_write_async (saver->priv->output_stream,
                                     saver->priv->chunk_buffer + saver->priv->chunk_bytes_written,
                                     saver->priv->chunk_bytes_read - saver->priv->chunk_bytes_written,
                                     g_task_get_priority (saver->priv->task),
@@ -564,7 +568,7 @@ read_file_chunk (GtkSourceFileSaver *saver)
        /* We use sync methods on doc stream since it is in memory. Using async
         * would be racy and we can end up with invalid iters.
         */
-       saver->priv->chunk_bytes_read = g_input_stream_read (saver->priv->input,
+       saver->priv->chunk_bytes_read = g_input_stream_read (saver->priv->input_stream,
                                                             saver->priv->chunk_buffer,
                                                             WRITE_CHUNK_SIZE,
                                                             g_task_get_cancellable (saver->priv->task),
@@ -595,16 +599,16 @@ replace_file_cb (GFile              *location,
                 GAsyncResult       *result,
                 GtkSourceFileSaver *saver)
 {
-       GFileOutputStream *file_stream;
-       GCharsetConverter *converter;
-       GOutputStream *base_stream;
+       GFileOutputStream *file_output_stream;
+       GOutputStream *output_stream;
+       GtkSourceBufferInputStream *buffer_stream;
        GError *error = NULL;
 
        DEBUG ({
               g_print ("%s\n", G_STRFUNC);
        });
 
-       file_stream = g_file_replace_finish (location, result, &error);
+       file_output_stream = g_file_replace_finish (location, result, &error);
 
        if (error != NULL)
        {
@@ -628,15 +632,15 @@ replace_file_cb (GFile              *location,
 
                compressor = g_zlib_compressor_new (G_ZLIB_COMPRESSOR_FORMAT_GZIP, -1);
 
-               base_stream = g_converter_output_stream_new (G_OUTPUT_STREAM (file_stream),
-                                                            G_CONVERTER (compressor));
+               output_stream = g_converter_output_stream_new (G_OUTPUT_STREAM (file_output_stream),
+                                                              G_CONVERTER (compressor));
 
                g_object_unref (compressor);
-               g_object_unref (file_stream);
+               g_object_unref (file_output_stream);
        }
        else
        {
-               base_stream = G_OUTPUT_STREAM (file_stream);
+               output_stream = G_OUTPUT_STREAM (file_output_stream);
        }
 
        /* FIXME: manage converter error? */
@@ -648,26 +652,29 @@ replace_file_cb (GFile              *location,
 
        if (saver->priv->encoding != gtk_source_encoding_get_utf8 ())
        {
+               GCharsetConverter *converter;
+
                converter = g_charset_converter_new (gtk_source_encoding_get_charset (saver->priv->encoding),
                                                     "UTF-8",
                                                     NULL);
 
-               saver->priv->stream = g_converter_output_stream_new (base_stream,
-                                                                    G_CONVERTER (converter));
+               saver->priv->output_stream = g_converter_output_stream_new (output_stream,
+                                                                           G_CONVERTER (converter));
 
                g_object_unref (converter);
-               g_object_unref (base_stream);
+               g_object_unref (output_stream);
        }
        else
        {
-               saver->priv->stream = G_OUTPUT_STREAM (base_stream);
+               saver->priv->output_stream = G_OUTPUT_STREAM (output_stream);
        }
 
-       saver->priv->input = _gtk_source_buffer_input_stream_new (saver->priv->buffer,
-                                                                 saver->priv->newline_type,
-                                                                 saver->priv->ensure_trailing_newline);
+       saver->priv->input_stream = _gtk_source_buffer_input_stream_new (saver->priv->buffer,
+                                                                        saver->priv->newline_type,
+                                                                        
saver->priv->ensure_trailing_newline);
 
-       saver->priv->total_size = _gtk_source_buffer_input_stream_get_total_size 
(GTK_SOURCE_BUFFER_INPUT_STREAM (saver->priv->input));
+       buffer_stream = GTK_SOURCE_BUFFER_INPUT_STREAM (saver->priv->input_stream);
+       saver->priv->total_size = _gtk_source_buffer_input_stream_get_total_size (buffer_stream);
 
        read_file_chunk (saver);
 }


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