[evince/wip/gpoo/fix-warnings: 3/5] libdocument: Deprecate GTime usage in annotation's properties




commit dc7d8a7a826450a427b6ac470b4e65dd2e9bf8c1
Author: Germán Poo-Caamaño <gpoo gnome org>
Date:   Sun Oct 17 10:18:49 2021 -0300

    libdocument: Deprecate GTime usage in annotation's properties
    
    * Use time_t instead of GTime which is not 2038-year safe.
    * Add the deprecation information

 libdocument/ev-annotation.c | 46 +++++++++++++++++++++++++++++++++++++++++++--
 libdocument/ev-annotation.h |  5 ++++-
 2 files changed, 48 insertions(+), 3 deletions(-)
---
diff --git a/libdocument/ev-annotation.c b/libdocument/ev-annotation.c
index 1b466cb5..73962508 100644
--- a/libdocument/ev-annotation.c
+++ b/libdocument/ev-annotation.c
@@ -511,8 +511,8 @@ ev_annotation_get_modified (EvAnnotation *annot)
  * @modified: string with the last modification date.
  *
  * Set the last modification date of @annot to @modified. To
- * set the last modification date using a #GTime, use
- * ev_annotation_set_modified_from_time() instead. You can monitor
+ * set the last modification date using a #time_t, use
+ * ev_annotation_set_modified_from_time_t() instead. You can monitor
  * changes to the last modification date by connecting to the
  * notify::modified signal on @annot.
  *
@@ -547,7 +547,11 @@ ev_annotation_set_modified (EvAnnotation *annot,
  * For the time-format used, see ev_document_misc_format_date().
  *
  * Returns: %TRUE if the last modified date has been updated, %FALSE otherwise.
+ *
+ * Deprecated: 3.42: use ev_annotation_set_modified_from_time_t instead as GTime is
+ *                   deprecated because it is not year-2038 safe
  */
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
 gboolean
 ev_annotation_set_modified_from_time (EvAnnotation *annot,
                                      GTime         utime)
@@ -571,6 +575,44 @@ ev_annotation_set_modified_from_time (EvAnnotation *annot,
 
        return TRUE;
 }
+G_GNUC_END_IGNORE_DEPRECATIONS
+
+/**
+ * ev_annotation_set_modified_from_time_t:
+ * @annot: an #EvAnnotation
+ * @utime: a #time_t
+ *
+ * Set the last modification date of @annot to @utime.  You can
+ * monitor changes to the last modification date by connecting to the
+ * notify::modified sinal on @annot.
+ * For the time-format used, see ev_document_misc_format_datetime().
+ *
+ * Returns: %TRUE if the last modified date has been updated, %FALSE otherwise.
+ */
+gboolean
+ev_annotation_set_modified_from_time_t (EvAnnotation *annot,
+                                       time_t        utime)
+{
+       gchar *modified;
+       g_autoptr (GDateTime) dt = g_date_time_new_from_unix_utc ((gint64)utime);
+
+       g_return_val_if_fail (EV_IS_ANNOTATION (annot), FALSE);
+
+       modified = ev_document_misc_format_datetime (dt);
+
+       if (g_strcmp0 (annot->modified, modified) == 0) {
+               g_free (modified);
+               return FALSE;
+       }
+
+       if (annot->modified)
+               g_free (annot->modified);
+
+       annot->modified = modified;
+       g_object_notify (G_OBJECT (annot), "modified");
+
+       return TRUE;
+}
 
 /**
  * ev_annotation_get_color:
diff --git a/libdocument/ev-annotation.h b/libdocument/ev-annotation.h
index 69c6686f..fefbe62c 100644
--- a/libdocument/ev-annotation.h
+++ b/libdocument/ev-annotation.h
@@ -132,16 +132,19 @@ gboolean             ev_annotation_set_name                  (EvAnnotation
 const gchar         *ev_annotation_get_modified              (EvAnnotation           *annot);
 gboolean             ev_annotation_set_modified              (EvAnnotation           *annot,
                                                              const gchar            *modified);
+gboolean             ev_annotation_set_modified_from_time_t  (EvAnnotation           *annot,
+                                                             time_t                  utime);
 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+EV_DEPRECATED_FOR(ev_annotaion_set_modified_from_time_t)
 gboolean             ev_annotation_set_modified_from_time    (EvAnnotation           *annot,
                                                              GTime                   utime);
-G_GNUC_END_IGNORE_DEPRECATIONS
 EV_DEPRECATED_FOR(ev_annotaion_get_rgba)
 void                 ev_annotation_get_color                 (EvAnnotation           *annot,
                                                              GdkColor               *color);
 EV_DEPRECATED_FOR(ev_annotaion_set_rgba)
 gboolean             ev_annotation_set_color                 (EvAnnotation           *annot,
                                                              const GdkColor         *color);
+G_GNUC_END_IGNORE_DEPRECATIONS
 void                 ev_annotation_get_rgba                  (EvAnnotation           *annot,
                                                               GdkRGBA                *rgba);
 gboolean             ev_annotation_set_rgba                  (EvAnnotation           *annot,


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