[gedit/wip/reusable-code] DocumentSaver: weaker dependency to Document and GSettings



commit 104e703101690098a80e3f24327311fffcd9cf74
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Sep 16 18:04:29 2013 +0200

    DocumentSaver: weaker dependency to Document and GSettings
    
    GSettings is still needed for another thing.

 gedit/gedit-document-saver.c |   31 +++++++------------------------
 gedit/gedit-document.c       |    9 +++++++++
 2 files changed, 16 insertions(+), 24 deletions(-)
---
diff --git a/gedit/gedit-document-saver.c b/gedit/gedit-document-saver.c
index 3653cd2..0d586f4 100644
--- a/gedit/gedit-document-saver.c
+++ b/gedit/gedit-document-saver.c
@@ -85,7 +85,6 @@ struct _GeditDocumentSaverPrivate
 
        GFileInfo                *info;
        GeditDocument            *document;
-       gboolean                  used;
 
        GFile                    *location;
        const GeditEncoding      *encoding;
@@ -94,7 +93,6 @@ struct _GeditDocumentSaverPrivate
 
        GeditDocumentSaveFlags    flags;
 
-       gboolean                  keep_backup;
 
        GTimeVal                  old_mtime;
 
@@ -106,6 +104,8 @@ struct _GeditDocumentSaverPrivate
        GInputStream             *input;
 
        GError                   *error;
+
+       guint                     used : 1;
 };
 
 G_DEFINE_TYPE_WITH_PRIVATE (GeditDocumentSaver, gedit_document_saver, G_TYPE_OBJECT)
@@ -718,7 +718,6 @@ async_replace_ready_callback (GFile        *source,
        GCharsetConverter *converter;
        GFileOutputStream *file_stream;
        GOutputStream *base_stream;
-       gchar *content_type;
        GError *error = NULL;
        gboolean ensure_trailing_newline;
 
@@ -747,8 +746,6 @@ async_replace_ready_callback (GFile        *source,
                return;
        }
 
-       content_type = gedit_document_get_content_type (saver->priv->document);
-
        if (saver->priv->compression_type == GEDIT_DOCUMENT_COMPRESSION_TYPE_GZIP)
        {
                GZlibCompressor *compressor;
@@ -771,8 +768,6 @@ async_replace_ready_callback (GFile        *source,
                base_stream = G_OUTPUT_STREAM (file_stream);
        }
 
-       g_free (content_type);
-
        /* FIXME: manage converter error? */
        DEBUG ({
               g_print ("Encoding charset: %s\n",
@@ -813,7 +808,7 @@ static void
 begin_write (AsyncData *async)
 {
        GeditDocumentSaver *saver;
-       gboolean backup;
+       gboolean make_backup;
 
        DEBUG ({
               g_print ("Start replacing file contents\n");
@@ -824,18 +819,17 @@ begin_write (AsyncData *async)
         */
        saver = async->saver;
 
-       /* Do not make backups for remote files so they do not clutter remote systems */
-       backup = (saver->priv->keep_backup && gedit_document_is_local (saver->priv->document));
+       make_backup = (saver->priv->flags & GEDIT_DOCUMENT_SAVE_IGNORE_BACKUP) == 0 &&
+                     (saver->priv->flags & GEDIT_DOCUMENT_SAVE_PRESERVE_BACKUP) == 0;
 
        DEBUG ({
               g_print ("File contents size: %" G_GINT64_FORMAT "\n", saver->priv->size);
-              g_print ("Calling replace_async\n");
-              g_print (backup ? "Keep backup\n" : "Discard backup\n");
+              g_print ("Make backup: %s\n", make_backup ? "yes" : "no");
        });
 
        g_file_replace_async (saver->priv->location,
                              NULL,
-                             backup,
+                             make_backup,
                              G_FILE_CREATE_NONE,
                              G_PRIORITY_HIGH,
                              async->cancellable,
@@ -1033,17 +1027,6 @@ gedit_document_saver_save (GeditDocumentSaver *saver,
         report async (in an idle handler) or sync (bool ret)
         async is extra work here, sync is special casing in the caller */
 
-       /* never keep backup of autosaves */
-       if ((saver->priv->flags & GEDIT_DOCUMENT_SAVE_PRESERVE_BACKUP) != 0)
-       {
-               saver->priv->keep_backup = FALSE;
-       }
-       else
-       {
-               saver->priv->keep_backup = g_settings_get_boolean (saver->priv->editor_settings,
-                                                                  GEDIT_SETTINGS_CREATE_BACKUP_COPY);
-       }
-
        saver->priv->old_mtime = *old_mtime;
 
        /* saving start */
diff --git a/gedit/gedit-document.c b/gedit/gedit-document.c
index b1d8aa7..f9e1b88 100644
--- a/gedit/gedit-document.c
+++ b/gedit/gedit-document.c
@@ -1815,6 +1815,15 @@ gedit_document_save_real (GeditDocument                *doc,
        }
        else
        {
+               /* Do not make backups for remote files so they do not clutter
+                * remote systems. */
+               if (!gedit_document_is_local (doc) ||
+                   !g_settings_get_boolean (doc->priv->editor_settings,
+                                            GEDIT_SETTINGS_CREATE_BACKUP_COPY))
+               {
+                       flags |= GEDIT_DOCUMENT_SAVE_IGNORE_BACKUP;
+               }
+
                /* create a saver, it will be destroyed once saving is complete */
                doc->priv->saver = gedit_document_saver_new (doc,
                                                             location,


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