[goffice] GODoc: store last known modtime.



commit 6a7d4bb7ec77234d16270a691cae36b0854ad99c
Author: Morten Welinder <terra gnome org>
Date:   Sun Mar 25 14:26:36 2018 -0400

    GODoc: store last known modtime.
    
    This is support for detecting a file system changes between the time a
    file was loaded/saved an a newly-attempted save.

 NEWS                      |    1 +
 goffice/app/go-doc-impl.h |    1 +
 goffice/app/go-doc.c      |   59 ++++++++++++++++++++++++++++++++++++++++++++-
 goffice/app/go-doc.h      |    3 ++
 4 files changed, 63 insertions(+), 1 deletions(-)
---
diff --git a/NEWS b/NEWS
index cd5e6b4..9645298 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@ goffice 0.10.40:
 
 Morten:
        * Fixes required for running with musl.  [#794115]
+       * Store last-know modtime for GODoc.
 
 --------------------------------------------------------------------------
 goffice 0.10.39:
diff --git a/goffice/app/go-doc-impl.h b/goffice/app/go-doc-impl.h
index eab3801..54960d0 100644
--- a/goffice/app/go-doc-impl.h
+++ b/goffice/app/go-doc-impl.h
@@ -34,6 +34,7 @@ struct _GODoc {
        gint64           first_modification_time;
        gboolean         pristine;
        GHashTable      *images;
+       GDateTime       *modtime;
 
        /* <private> */
        struct _GODocPrivate *priv;
diff --git a/goffice/app/go-doc.c b/goffice/app/go-doc.c
index 1587c3b..55ebb07 100644
--- a/goffice/app/go-doc.c
+++ b/goffice/app/go-doc.c
@@ -54,7 +54,8 @@ enum {
        PROP_URI,
        PROP_DIRTY,
        PROP_DIRTY_TIME,
-       PROP_PRISTINE
+       PROP_PRISTINE,
+       PROP_MODTIME
 };
 enum {
        METADATA_CHANGED,
@@ -87,6 +88,10 @@ go_doc_get_property (GObject *obj, guint property_id,
                g_value_set_boolean (value, go_doc_is_pristine (doc));
                break;
 
+       case PROP_MODTIME:
+               g_value_set_boxed (value, go_doc_get_modtime (doc));
+               break;
+
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
                break;
@@ -116,6 +121,10 @@ go_doc_set_property (GObject *obj, guint property_id,
                go_doc_set_pristine (doc, g_value_get_boolean (value));
                break;
 
+       case PROP_MODTIME:
+               go_doc_set_modtime (doc, g_value_get_boxed (value));
+               break;
+
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
                break;
@@ -182,6 +191,13 @@ go_doc_class_init (GObjectClass *object_class)
                 g_param_spec_boolean ("pristine", _("Pristine"),
                        _("Whether the document is unchanged since it was created."),
                        FALSE, GSF_PARAM_STATIC | G_PARAM_READWRITE));
+        g_object_class_install_property (object_class, PROP_MODTIME,
+                g_param_spec_boxed ("modtime",
+                                    _("Modification time"),
+                                    _("The known file system modification time"),
+                                    G_TYPE_DATE_TIME,
+                                    GSF_PARAM_STATIC |
+                                    G_PARAM_READWRITE));
 
        signals [METADATA_UPDATE] = g_signal_new ("metadata-update",
                GO_TYPE_DOC,    G_SIGNAL_RUN_LAST,
@@ -397,6 +413,47 @@ go_doc_update_meta_data (GODoc *doc)
 }
 
 /**
+ * go_doc_set_modtime:
+ * @doc: #GODoc
+ * @modtime: (allow-none): new file system time stamp
+ *
+ * Sets the last known file system time stamp for the document, %NULL
+ * if unknown.
+ **/
+void
+go_doc_set_modtime (GODoc *doc, GDateTime *modtime)
+{
+       g_return_if_fail (GO_IS_DOC (doc));
+
+       if (modtime == doc->modtime)
+               return;
+
+       if (modtime)
+               g_date_time_ref (modtime);
+       if (doc->modtime)
+               g_date_time_unref (doc->modtime);
+       doc->modtime = modtime;
+
+       g_object_notify (G_OBJECT (doc), "modtime");
+}
+
+/**
+ * go_doc_get_modtime:
+ * @doc: #GODoc
+ *
+ * Returns: (transfer none): the last known file system time stamp for
+ * the document, or %NULL if unknown.
+ **/
+GDateTime *
+go_doc_get_modtime (GODoc const *doc)
+{
+       g_return_val_if_fail (GO_IS_DOC (doc), NULL);
+
+       return doc->modtime;
+}
+
+
+/**
  * go_doc_get_image:
  * @doc: a #GODoc
  * @id: the image name
diff --git a/goffice/app/go-doc.h b/goffice/app/go-doc.h
index 4d6a0db..ba5d49e 100644
--- a/goffice/app/go-doc.h
+++ b/goffice/app/go-doc.h
@@ -40,6 +40,9 @@ gboolean go_doc_is_dirty               (GODoc const *doc);
 void     go_doc_set_dirty_time           (GODoc *doc, gint64 t);
 gint64   go_doc_get_dirty_time           (GODoc const *doc);
 
+void     go_doc_set_modtime              (GODoc *doc, GDateTime *modtime);
+GDateTime *go_doc_get_modtime            (GODoc const *doc);
+
 gboolean        go_doc_set_uri          (GODoc *doc, char const *uri);
 char const     *go_doc_get_uri          (GODoc const *doc);
 


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