[gedit/wip/loader-saver] GeditDocument: fix bug with content type



commit 47ab5f0faaedc202e6d827dda3a5532b54a75675
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Jun 28 21:38:56 2014 +0200

    GeditDocument: fix bug with content type

 gedit/gedit-document.c |   32 ++++++++++++++++++++------------
 1 files changed, 20 insertions(+), 12 deletions(-)
---
diff --git a/gedit/gedit-document.c b/gedit/gedit-document.c
index cee76cd..da8680b 100644
--- a/gedit/gedit-document.c
+++ b/gedit/gedit-document.c
@@ -1047,7 +1047,6 @@ loaded_query_info_cb (GFile         *location,
        GFileInfo *info;
        const gchar *content_type = NULL;
        gboolean read_only = FALSE;
-       GTimeVal mtime = {0, 0};
        GError *error = NULL;
 
        info = g_file_query_info_finish (location, result, &error);
@@ -1059,6 +1058,8 @@ loaded_query_info_cb (GFile         *location,
                error = NULL;
        }
 
+       doc->priv->mtime_set = FALSE;
+
        if (info != NULL)
        {
                if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE))
@@ -1073,16 +1074,13 @@ loaded_query_info_cb (GFile         *location,
 
                if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED))
                {
-                       g_file_info_get_modification_time (info, &mtime);
+                       g_file_info_get_modification_time (info, &doc->priv->mtime);
+                       doc->priv->mtime_set = TRUE;
                }
-
-               g_object_unref (info);
        }
 
        set_readonly (doc, read_only);
 
-       doc->priv->mtime = mtime;
-       doc->priv->mtime_set = TRUE;
        g_get_current_time (&doc->priv->time_of_last_save_or_load);
 
        doc->priv->externally_modified = FALSE;
@@ -1090,6 +1088,12 @@ loaded_query_info_cb (GFile         *location,
 
        gedit_document_set_content_type (doc, content_type);
 
+       if (info != NULL)
+       {
+               /* content_type (owned by info) is no longer needed. */
+               g_object_unref (info);
+       }
+
        if (!doc->priv->language_set_by_user)
        {
                GtkSourceLanguage *language = guess_language (doc);
@@ -1130,7 +1134,6 @@ saved_query_info_cb (GFile         *location,
 {
        GFileInfo *info;
        const gchar *content_type = NULL;
-       GTimeVal mtime = {0, 0};
        GError *error = NULL;
 
        info = g_file_query_info_finish (location, result, &error);
@@ -1142,6 +1145,8 @@ saved_query_info_cb (GFile         *location,
                error = NULL;
        }
 
+       doc->priv->mtime_set = FALSE;
+
        if (info != NULL)
        {
                if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE))
@@ -1151,16 +1156,19 @@ saved_query_info_cb (GFile         *location,
 
                if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED))
                {
-                       g_file_info_get_modification_time (info, &mtime);
+                       g_file_info_get_modification_time (info, &doc->priv->mtime);
+                       doc->priv->mtime_set = TRUE;
                }
-
-               g_object_unref (info);
        }
 
        gedit_document_set_content_type (doc, content_type);
 
-       doc->priv->mtime = mtime;
-       doc->priv->mtime_set = TRUE;
+       if (info != NULL)
+       {
+               /* content_type (owned by info) is no longer needed. */
+               g_object_unref (info);
+       }
+
        g_get_current_time (&doc->priv->time_of_last_save_or_load);
 
        doc->priv->externally_modified = FALSE;


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