[goffice] GODoc: keep track of dirty time.



commit 3873c1c94d04b108c66a5ea6cea1205575111828
Author: Morten Welinder <terra gnome org>
Date:   Thu Jan 26 16:03:34 2012 -0500

    GODoc: keep track of dirty time.

 ChangeLog                 |    7 +++++
 goffice/app/go-doc-impl.h |    1 +
 goffice/app/go-doc.c      |   57 ++++++++++++++++++++++++++++++++++++++++++--
 goffice/app/go-doc.h      |    4 +++
 4 files changed, 66 insertions(+), 3 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index fbdada9..01956f7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2012-01-26  Morten Welinder  <terra gnome org>
+
+	* goffice/app/go-doc.c (go_doc_set_dirty_time)
+	(go_doc_get_dirty_time): New function.
+	(go_doc_set_dirty): Set dirty time.
+	(go_doc_class_init): Install new dirty-time property.
+
 2012-01-12  Jean Brefort  <jean brefort normalesup org>
 
 	* goffice/graph/gog-guru.c (graph_typeselect_minor): fixed selector
diff --git a/goffice/app/go-doc-impl.h b/goffice/app/go-doc-impl.h
index 2c7137f..5fb0798 100644
--- a/goffice/app/go-doc-impl.h
+++ b/goffice/app/go-doc-impl.h
@@ -31,6 +31,7 @@ struct _GODoc {
 	gchar		*uri;
 	GsfDocMetaData	*meta_data;
 	gboolean	 modified;
+	gint64           first_modification_time;
 	gboolean	 pristine;
 	GHashTable	*images;
 	GHashTable	*imagebuf; /* used when loading/saving images */
diff --git a/goffice/app/go-doc.c b/goffice/app/go-doc.c
index 3d44e88..45f2963 100644
--- a/goffice/app/go-doc.c
+++ b/goffice/app/go-doc.c
@@ -35,6 +35,7 @@ enum {
 	PROP_0,
 	PROP_URI,
 	PROP_DIRTY,
+	PROP_DIRTY_TIME,
 	PROP_PRISTINE
 };
 enum {
@@ -60,6 +61,10 @@ go_doc_get_property (GObject *obj, guint property_id,
 		g_value_set_boolean (value, go_doc_is_dirty (doc));
 		break;
 
+	case PROP_DIRTY_TIME:
+		g_value_set_int64 (value, go_doc_get_dirty_time (doc));
+		break;
+
 	case PROP_PRISTINE:
 		g_value_set_boolean (value, go_doc_is_pristine (doc));
 		break;
@@ -85,6 +90,10 @@ go_doc_set_property (GObject *obj, guint property_id,
 		go_doc_set_dirty (doc, g_value_get_boolean (value));
 		break;
 
+ 	case PROP_DIRTY_TIME:
+		go_doc_set_dirty_time (doc, g_value_get_int64 (value));
+		break;
+
  	case PROP_PRISTINE:
 		go_doc_set_pristine (doc, g_value_get_boolean (value));
 		break;
@@ -142,6 +151,12 @@ go_doc_class_init (GObjectClass *object_class)
 			_("Whether the document has been changed."),
 			FALSE, GSF_PARAM_STATIC | G_PARAM_READWRITE));
 
+        g_object_class_install_property (object_class, PROP_DIRTY_TIME,
+		 g_param_spec_int64 ("dirty-time", _("Dirty Time"),
+			_("When the document was first changed."),
+			G_MININT64, G_MAXINT64, 0,
+			GSF_PARAM_STATIC | G_PARAM_READWRITE));
+
         g_object_class_install_property (object_class, PROP_PRISTINE,
 		 g_param_spec_boolean ("pristine", _("Pristine"),
 			_("Whether the document is unchanged since it was created."),
@@ -216,11 +231,13 @@ go_doc_set_dirty (GODoc *doc, gboolean is_dirty)
 	if (is_dirty == doc->modified)
 		return;
 
-	/* Dirtiness changed so no longer pristine.  */
-	go_doc_set_pristine (doc, FALSE);
-
 	doc->modified = is_dirty;
 	g_object_notify (G_OBJECT (doc), "dirty");
+
+	go_doc_set_dirty_time (doc, is_dirty ? g_get_real_time () : 0);
+
+	/* Dirtiness changed so no longer pristine.  */
+	go_doc_set_pristine (doc, FALSE);
 }
 
 /**
@@ -238,6 +255,40 @@ go_doc_is_dirty (GODoc const *doc)
 }
 
 /**
+ * go_doc_set_dirty_time :
+ * @doc : #GODoc
+ * @t : a timestamp from g_get_real_time
+ *
+ * Changes the dirty time, i.e., the time the document was first marked
+ * dirty.
+ **/
+void
+go_doc_set_dirty_time (GODoc *doc, gint64 t)
+{
+	g_return_if_fail (GO_IS_DOC (doc));
+
+	if (doc->first_modification_time == t)
+		return;
+
+	doc->first_modification_time = t;
+	g_object_notify (G_OBJECT (doc), "dirty-time");
+}
+
+/**
+ * go_doc_get_dirty_time :
+ * @doc : #GODoc
+ *
+ * Returns: the time (as in g_get_real_time()) the document was first marked
+ * dirty.
+ **/
+gint64
+go_doc_get_dirty_time (GODoc const *doc)
+{
+	g_return_val_if_fail (GO_IS_DOC (doc), 0);
+	return doc->first_modification_time;
+}
+
+/**
  * go_doc_set_pristine:
  * @doc: #GODoc
  * @pristine: a gboolean.
diff --git a/goffice/app/go-doc.h b/goffice/app/go-doc.h
index a9c10ef..6082bc6 100644
--- a/goffice/app/go-doc.h
+++ b/goffice/app/go-doc.h
@@ -34,9 +34,13 @@ GType go_doc_get_type (void);
 
 void     go_doc_set_pristine             (GODoc *doc, gboolean pristine);
 gboolean go_doc_is_pristine		 (GODoc const *doc);
+
 void	 go_doc_set_dirty		 (GODoc *doc, gboolean is_dirty);
 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);
+
 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]