[glibmm/glibmm-2-62] Deprecate Glib::TimeVal



commit 6ce859f072f0affba7cc76ba7b1d455bc2f70ef7
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Tue Sep 17 13:12:15 2019 +0200

    Deprecate Glib::TimeVal
    
    GTimeVal has been deprecated in glib.
    
    * examples/dbus/server_without_bus.cc:
    * examples/dbus/session_bus_service.cc: Replace TimeVal by DateTime.
    * gio/src/fileinfo.[ccg|hg]: Deprecate [set_]modification_time().
    Add set/get_modification_date_time().
    * glib/glibmm/timeval.[cc|h]: Deprecate most of TimeVal.
    * glib/src/date.[ccg|hg]: Deprecate set_time(const GTimeVal& timeval).
    * glib/src/datetime.[ccg|hg]: Deprecate create_now_local/utc(const TimeVal& tv)
    and to_timeval(). Add create_from_iso8601(), format_iso8601() and
    operator bool().
    * tools/m4/convert_glib.m4: Add a conversion for DateTime.

 examples/dbus/server_without_bus.cc  | 10 +++++-----
 examples/dbus/session_bus_service.cc | 10 +++++-----
 gio/src/fileinfo.ccg                 |  7 ++-----
 gio/src/fileinfo.hg                  | 17 +++++++----------
 glib/glibmm/timeval.cc               |  2 ++
 glib/glibmm/timeval.h                | 14 ++++++++++----
 glib/src/date.ccg                    |  2 ++
 glib/src/date.hg                     |  6 +++---
 glib/src/datetime.ccg                | 15 ++-------------
 glib/src/datetime.hg                 | 34 ++++++++++++++++++----------------
 tools/m4/convert_glib.m4             |  1 +
 11 files changed, 57 insertions(+), 61 deletions(-)
---
diff --git a/examples/dbus/server_without_bus.cc b/examples/dbus/server_without_bus.cc
index 6474133b..8b84bf54 100644
--- a/examples/dbus/server_without_bus.cc
+++ b/examples/dbus/server_without_bus.cc
@@ -46,7 +46,7 @@ static Glib::ustring introspection_xml = "<node>"
                                          "</node>";
 
 // Stores the current alarm.
-static Glib::TimeVal curr_alarm;
+static Glib::DateTime curr_alarm;
 
 // This variable is used to keep an incoming connection active until it is
 // closed.
@@ -63,10 +63,9 @@ on_method_call(const Glib::RefPtr<Gio::DBus::Connection>& /* connection */,
 {
   if (method_name == "GetTime")
   {
-    Glib::TimeVal curr_time;
-    curr_time.assign_current_time();
+    Glib::DateTime curr_time = Glib::DateTime::create_now_local();
 
-    const Glib::ustring time_str = curr_time.as_iso8601();
+    const Glib::ustring time_str = curr_time.format_iso8601();
     const auto time_var = Glib::Variant<Glib::ustring>::create(time_str);
 
     // Create the tuple.
@@ -88,7 +87,8 @@ on_method_call(const Glib::RefPtr<Gio::DBus::Connection>& /* connection */,
     // Get the time string.
     const Glib::ustring time_str = param.get();
 
-    if (!curr_alarm.assign_from_iso8601(time_str))
+    curr_alarm = Glib::DateTime::create_from_iso8601(time_str);
+    if (!curr_alarm)
     {
       // If setting alarm was not successful, return an error.
       Gio::DBus::Error error(
diff --git a/examples/dbus/session_bus_service.cc b/examples/dbus/session_bus_service.cc
index 444b6e6e..fade31b5 100644
--- a/examples/dbus/session_bus_service.cc
+++ b/examples/dbus/session_bus_service.cc
@@ -48,7 +48,7 @@ static Glib::ustring introspection_xml = "<node>"
 guint registered_id = 0;
 
 // Stores the current alarm.
-static Glib::TimeVal curr_alarm;
+static Glib::DateTime curr_alarm;
 
 } // anonymous namespace
 
@@ -61,10 +61,9 @@ on_method_call(const Glib::RefPtr<Gio::DBus::Connection>& /* connection */,
 {
   if (method_name == "GetTime")
   {
-    Glib::TimeVal curr_time;
-    curr_time.assign_current_time();
+    Glib::DateTime curr_time = Glib::DateTime::create_now_local();
 
-    const Glib::ustring time_str = curr_time.as_iso8601();
+    const Glib::ustring time_str = curr_time.format_iso8601();
     const auto time_var = Glib::Variant<Glib::ustring>::create(time_str);
 
     // Create the tuple.
@@ -86,7 +85,8 @@ on_method_call(const Glib::RefPtr<Gio::DBus::Connection>& /* connection */,
     // Get the time string.
     const Glib::ustring time_str = param.get();
 
-    if (!curr_alarm.assign_from_iso8601(time_str))
+    curr_alarm = Glib::DateTime::create_from_iso8601(time_str);
+    if (!curr_alarm)
     {
       // If setting alarm was not successful, return an error.
       Gio::DBus::Error error(
diff --git a/gio/src/fileinfo.ccg b/gio/src/fileinfo.ccg
index d5862950..086cee13 100644
--- a/gio/src/fileinfo.ccg
+++ b/gio/src/fileinfo.ccg
@@ -27,6 +27,7 @@ FileAttributeMatcher::create(const std::string& attributes)
   return Glib::wrap(g_file_attribute_matcher_new(attributes.c_str()));
 }
 
+_DEPRECATE_IFDEF_START
 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
 Glib::TimeVal
 FileInfo::modification_time() const
@@ -35,11 +36,7 @@ FileInfo::modification_time() const
   g_file_info_get_modification_time(const_cast<GFileInfo*>(gobj()), (GTimeVal*)(&result));
   return result;
 }
-
-void FileInfo::set_modification_time(const Glib::TimeVal& mtime)
-{
-  g_file_info_set_modification_time(gobj(), const_cast<GTimeVal*>(static_cast<const GTimeVal*>(&mtime)));
-}
 G_GNUC_END_IGNORE_DEPRECATIONS
+_DEPRECATE_IFDEF_END
 
 } // namespace Gio
diff --git a/gio/src/fileinfo.hg b/gio/src/fileinfo.hg
index 9fb95946..9fe4e10e 100644
--- a/gio/src/fileinfo.hg
+++ b/gio/src/fileinfo.hg
@@ -181,11 +181,12 @@ public:
 
   _WRAP_METHOD(goffset get_size() const, g_file_info_get_size)
 
-  //TODO: In the next minor stable release (glibmm 2.62.0?), deprecate modification_time()
-  // and add get_modification_date_time().
+_DEPRECATE_IFDEF_START
+  /// @deprecated Use get_modification_date_time() instead.
   Glib::TimeVal modification_time() const;
+_DEPRECATE_IFDEF_END
   _IGNORE(g_file_info_get_modification_time)
-  //_WRAP_METHOD(Glib::DateTime get_modification_date_time() const, g_file_info_get_modification_date_time)
+  _WRAP_METHOD(Glib::DateTime get_modification_date_time() const, g_file_info_get_modification_date_time)
 
   _WRAP_METHOD(std::string get_symlink_target() const, g_file_info_get_symlink_target)
 
@@ -218,13 +219,9 @@ public:
 
   _WRAP_METHOD(void set_size(goffset size), g_file_info_set_size)
 
-  //TODO: In the next minor stable release (glibmm 2.62.0?), deprecate set_modification_time()
-  // and add set_modification_date_time().
-  _WRAP_METHOD_DOCS_ONLY(g_file_info_set_modification_time)
-  void set_modification_time(const Glib::TimeVal& mtime);
-  //_WRAP_METHOD(void set_modification_time(const Glib::TimeVal& mtime), g_file_info_set_modification_time,
-  //  deprecated "Use set_modification_date_time() instead.")
-  //_WRAP_METHOD(void set_modification_date_time(const Glib::DateTime& mtime), 
g_file_info_set_modification_date_time)
+  _WRAP_METHOD(void set_modification_time(const Glib::TimeVal& mtime), g_file_info_set_modification_time,
+    deprecated "Use set_modification_date_time() instead.")
+  _WRAP_METHOD(void set_modification_date_time(const Glib::DateTime& mtime), 
g_file_info_set_modification_date_time)
 
   _WRAP_METHOD(void set_symlink_target(const std::string& symlink_target), g_file_info_set_symlink_target)
   _WRAP_METHOD(void set_sort_order(gint32 sort_order), g_file_info_set_sort_order)
diff --git a/glib/glibmm/timeval.cc b/glib/glibmm/timeval.cc
index dcd39bab..1e2c079a 100644
--- a/glib/glibmm/timeval.cc
+++ b/glib/glibmm/timeval.cc
@@ -20,6 +20,7 @@
 
 namespace Glib
 {
+#ifndef GLIBMM_DISABLE_DEPRECATED
 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
 void
 TimeVal::assign_current_time()
@@ -137,5 +138,6 @@ TimeVal::as_iso8601() const
   return Glib::ustring();
 }
 G_GNUC_END_IGNORE_DEPRECATIONS
+#endif // GLIBMM_DISABLE_DEPRECATED
 
 } // namespace Glib
diff --git a/glib/glibmm/timeval.h b/glib/glibmm/timeval.h
index f13164c6..8cab311f 100644
--- a/glib/glibmm/timeval.h
+++ b/glib/glibmm/timeval.h
@@ -25,16 +25,18 @@
 namespace Glib
 {
 
-//TODO: Deprecate TimeVal in the next minor stable release (glibmm 2.62.0?).
 // GTimeVal is deprecated.
-// Note: Before TimeVal is deprecated, check what will happen with
-// Gdk::PixbufAnimationIter::advance(const Glib::TimeVal& current_time),
-// especially if GLIBMM_DISABLE_DEPRECATED is defined but GDKMM_DISABLE_DEPRECATED is not.
+// The deprecated GTimeVal is used in the non-deprecated gdk_pixbuf_animation_iter_advance().
+// That's why not all of struct Glib::TimeVal is surrounded by
+// #ifndef GLIBMM_DISABLE_DEPRECATED/#endif. It would result in compilation errors,
+// if you define GLIBMM_DISABLE_DEPRECATED and include gdkmm/pixbufanimationiter.h.
 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
 /** Glib::TimeVal is a wrapper around the glib structure GTimeVal.
  * The glib structure GTimeVal itself is equivalent to struct timeval,
  * which is returned by the gettimeofday() UNIX call. Additionally
  * this wrapper provides an assortment of time manipulation functions.
+ *
+ * @deprecated Use Glib::DateTime instead.
  */
 struct TimeVal : public GTimeVal
 {
@@ -44,6 +46,7 @@ struct TimeVal : public GTimeVal
   inline TimeVal(const GTimeVal& gtimeval);
   inline TimeVal& operator=(const GTimeVal& gtimeval);
 
+#ifndef GLIBMM_DISABLE_DEPRECATED
   /** Assigns the current time to the TimeVal instance.
    * Equivalent to the UNIX gettimeofday() function, but is portable and
    * works also on Win32.
@@ -93,6 +96,7 @@ struct TimeVal : public GTimeVal
    * Returns true if the stored time / time interval is positive.
    */
   inline bool valid() const;
+#endif // GLIBMM_DISABLE_DEPRECATED
 };
 
 inline TimeVal::TimeVal()
@@ -121,6 +125,7 @@ TimeVal::operator=(const GTimeVal& gtimeval)
   return *this;
 }
 
+#ifndef GLIBMM_DISABLE_DEPRECATED
 inline TimeVal&
 TimeVal::operator+=(const TimeVal& gtimeval)
 {
@@ -240,6 +245,7 @@ operator>=(const TimeVal& lhs, const TimeVal& rhs)
 {
   return ((lhs.tv_sec > rhs.tv_sec) || (lhs.tv_sec == rhs.tv_sec && lhs.tv_usec >= rhs.tv_usec));
 }
+#endif // GLIBMM_DISABLE_DEPRECATED
 G_GNUC_END_IGNORE_DEPRECATIONS
 
 } // namespace Glib
diff --git a/glib/src/date.ccg b/glib/src/date.ccg
index dc0cb37c..65f0d64e 100644
--- a/glib/src/date.ccg
+++ b/glib/src/date.ccg
@@ -106,6 +106,7 @@ Date::set_time_current()
   g_date_set_time_t(&gobject_, time(nullptr));
 }
 
+_DEPRECATE_IFDEF_START
 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
 void
 Date::set_time(const GTimeVal& timeval)
@@ -113,6 +114,7 @@ Date::set_time(const GTimeVal& timeval)
   g_date_set_time_val(&gobject_, const_cast<GTimeVal*>(&timeval));
 }
 G_GNUC_END_IGNORE_DEPRECATIONS
+_DEPRECATE_IFDEF_END
 
 void
 Date::set_month(Date::Month month)
diff --git a/glib/src/date.hg b/glib/src/date.hg
index 8b15ccb7..12728311 100644
--- a/glib/src/date.hg
+++ b/glib/src/date.hg
@@ -134,14 +134,13 @@ public:
    */
   void set_time(std::time_t timet);
 
-  //TODO: Deprecate set_time() in the next minor stable release (glibmm 2.62.0?).
-  // GTimeVal is deprecated.
+  _DEPRECATE_IFDEF_START
   G_GNUC_BEGIN_IGNORE_DEPRECATIONS
   /** Sets the value of a date from a GTimeVal value.  Note that the
    * tv_usec member is ignored, because Glib::Date can't make use of the
    * additional precision.
    *
-   * @see set_time_current()
+   * @deprecated Use set_time(std::time_t timet) instead.
    *
    * @param timeval GTimeVal value to set
    *
@@ -149,6 +148,7 @@ public:
    */
   void set_time(const GTimeVal& timeval);
   G_GNUC_END_IGNORE_DEPRECATIONS
+  _DEPRECATE_IFDEF_END
 
   /** Set this Glib::Date to the current time.
    */
diff --git a/glib/src/datetime.ccg b/glib/src/datetime.ccg
index 14b800ae..738d4f8f 100644
--- a/glib/src/datetime.ccg
+++ b/glib/src/datetime.ccg
@@ -20,21 +20,10 @@
 
 namespace Glib
 {
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-DateTime DateTime::create_now_local(const TimeVal& tv)
-{
-  return Glib::wrap(g_date_time_new_from_timeval_local(&(tv)));
-}
-
-DateTime DateTime::create_now_utc(const TimeVal& tv)
-{
-  return Glib::wrap(g_date_time_new_from_timeval_utc(&(tv)));
-}
 
-bool DateTime::to_timeval(TimeVal& tv) const
+DateTime::operator bool() const
 {
-  return g_date_time_to_timeval(const_cast<GDateTime*>(gobj()), &(tv));
+  return (gobject_ != nullptr);
 }
-G_GNUC_END_IGNORE_DEPRECATIONS
 
 } // namespace Glib
diff --git a/glib/src/datetime.hg b/glib/src/datetime.hg
index 730fcab6..0512d4a3 100644
--- a/glib/src/datetime.hg
+++ b/glib/src/datetime.hg
@@ -74,22 +74,26 @@ public:
   _WRAP_METHOD(static DateTime create_now_local(gint64 t), g_date_time_new_from_unix_local)
   _WRAP_METHOD(static DateTime create_now_utc(gint64 t), g_date_time_new_from_unix_utc)
 
-  _WRAP_METHOD_DOCS_ONLY(g_date_time_new_from_timeval_local)
-  static DateTime create_now_local(const TimeVal& tv);
-//TODO: Deprecate in the next minor stable release (glibmm 2.62.0?).
-//  _WRAP_METHOD(static DateTime create_now_local(const TimeVal& tv), g_date_time_new_from_timeval_local,
-//    deprecated "Use create_now_local(gint64 t) instead.")
-
-  _WRAP_METHOD_DOCS_ONLY(g_date_time_new_from_timeval_utc)
-  static DateTime create_now_utc(const TimeVal& tv);
-//TODO: Deprecate in the next minor stable release (glibmm 2.62.0?).
-//  _WRAP_METHOD(static DateTime create_now_utc(const TimeVal& tv), g_date_time_new_from_timeval_utc,
-//    deprecated "Use create_now_utc(gint64 t) instead.")
+  _WRAP_METHOD(static DateTime create_now_local(const TimeVal& tv), g_date_time_new_from_timeval_local,
+    deprecated "Use create_now_local(gint64 t) instead.")
 
+  _WRAP_METHOD(static DateTime create_now_utc(const TimeVal& tv), g_date_time_new_from_timeval_utc,
+    deprecated "Use create_now_utc(gint64 t) instead.")
+
+  _WRAP_METHOD(static DateTime create_from_iso8601(const Glib::ustring& text, const TimeZone& default_tz{?}),
+    g_date_time_new_from_iso8601, newin "2,62")
   _WRAP_METHOD(static DateTime create(const TimeZone& tz, int year, int month, int day, int hour, int 
minute, double seconds), g_date_time_new)
   _WRAP_METHOD(static DateTime create_local(int year, int month, int day, int hour, int minute, double 
seconds), g_date_time_new_local)
   _WRAP_METHOD(static DateTime create_utc(int year, int month, int day, int hour, int minute, double 
seconds), g_date_time_new_utc)
 
+  /** Returns true if the %DateTime object is valid.
+   * This will return false, for instance, if the @a text in create_from_iso8601()
+   * is not a valid ISO 8601 formatted string.
+   *
+   * @newin{2,62}
+   */
+  explicit operator bool() const;
+
   _WRAP_METHOD(DateTime add(TimeSpan timespan) const, g_date_time_add)
   _WRAP_METHOD(DateTime add_years(int years) const, g_date_time_add_years)
   _WRAP_METHOD(DateTime add_months(int months) const, g_date_time_add_months)
@@ -152,11 +156,8 @@ public:
   _WRAP_METHOD(double get_seconds() const, g_date_time_get_seconds)
   _WRAP_METHOD(gint64 to_unix() const, g_date_time_to_unix)
 
-  _WRAP_METHOD_DOCS_ONLY(g_date_time_to_timeval)
-  bool to_timeval(TimeVal& tv) const;
-//TODO: Deprecate in the next minor stable release (glibmm 2.62.0?).
-//  _WRAP_METHOD(bool to_timeval(TimeVal& tv) const, g_date_time_to_timeval,
-//    deprecated "Use to_unix() instead.")
+  _WRAP_METHOD(bool to_timeval(TimeVal& tv) const, g_date_time_to_timeval,
+    deprecated "Use to_unix() instead.")
 
   _WRAP_METHOD(TimeSpan get_utc_offset() const, g_date_time_get_utc_offset)
 #m4 _CONVERSION(`GTimeZone*',`TimeZone',`Glib::wrap($3, true)')
@@ -167,6 +168,7 @@ public:
   _WRAP_METHOD(DateTime to_local() const, g_date_time_to_local)
   _WRAP_METHOD(DateTime to_utc() const, g_date_time_to_utc)
   _WRAP_METHOD(Glib::ustring format(const Glib::ustring& format_str) const, g_date_time_format)
+  _WRAP_METHOD(Glib::ustring format_iso8601() const, g_date_time_format_iso8601)
 };
 
 } // namespace Glib
diff --git a/tools/m4/convert_glib.m4 b/tools/m4/convert_glib.m4
index 0c70cdf2..243255b9 100644
--- a/tools/m4/convert_glib.m4
+++ b/tools/m4/convert_glib.m4
@@ -108,6 +108,7 @@ dnl DateTime
 _CONVERSION(`GDateTime*',`DateTime',`Glib::wrap($3)')
 _CONVERSION(`GDateTime*',`Glib::DateTime',`Glib::wrap($3)')
 _CONVERSION(`const DateTime&',`GDateTime*',`const_cast<$2>($3.gobj())')
+_CONVERSION(`const Glib::DateTime&',`GDateTime*',`const_cast<$2>($3.gobj())')
 
 dnl KeyFile
 _CONVERSION(`Glib::KeyFile&',`GKeyFile*',`($3).gobj()')


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