[glibmm] Remove Glib::TimeVal
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm] Remove Glib::TimeVal
- Date: Tue, 13 Aug 2019 18:12:10 +0000 (UTC)
commit 85ad1c29f6b484cdf23b0422468032372e433eb9
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date: Tue Aug 13 20:04:23 2019 +0200
Remove Glib::TimeVal
GTimeVal has been deprecated in glib. Remove its wrapping in glibmm.
* examples/dbus/server_without_bus.cc:
* examples/dbus/session_bus_service.cc: Replace TimeVal by DateTime.
* gio/src/fileinfo.[ccg|hg]: Remove [set_]modification_time().
Add set/get_modification_date_time().
* glib/glibmm.h:
* glib/glibmm/filelist.am: Remove timeval.
* glib/glibmm/timeval.[cc|h]: Removed files.
* glib/src/date.[ccg|hg]: Remove set_time(const GTimeVal& timeval).
* glib/src/datetime.[ccg|hg]: Remove create_now_local/utc(const TimeVal& tv)
and to_timeval(). Add create_from_iso8601(), format_iso8601() and
operator bool().
* tools/m4/convert_glib.m4:
* tools/m4/convert_gio.m4: Remove conversions for GTimeVal.
examples/dbus/server_without_bus.cc | 10 +-
examples/dbus/session_bus_service.cc | 10 +-
gio/src/fileinfo.ccg | 8 --
gio/src/fileinfo.hg | 7 +-
glib/glibmm.h | 4 +-
glib/glibmm/filelist.am | 2 -
glib/glibmm/timeval.cc | 138 --------------------
glib/glibmm/timeval.h | 240 -----------------------------------
glib/src/date.ccg | 6 -
glib/src/date.hg | 12 --
glib/src/datetime.ccg | 11 +-
glib/src/datetime.hg | 16 ++-
tools/m4/convert_gio.m4 | 2 -
tools/m4/convert_glib.m4 | 5 +-
14 files changed, 35 insertions(+), 436 deletions(-)
---
diff --git a/examples/dbus/server_without_bus.cc b/examples/dbus/server_without_bus.cc
index 23e8bd5b..d97eed3d 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 25d3ae71..aee935b2 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 d18d926a..457aac81 100644
--- a/gio/src/fileinfo.ccg
+++ b/gio/src/fileinfo.ccg
@@ -27,12 +27,4 @@ FileAttributeMatcher::create(const std::string& attributes)
return Glib::wrap(g_file_attribute_matcher_new(attributes.c_str()));
}
-Glib::TimeVal
-FileInfo::modification_time() const
-{
- Glib::TimeVal result;
- g_file_info_get_modification_time(const_cast<GFileInfo*>(gobj()), (GTimeVal*)(&result));
- return result;
-}
-
} // namespace Gio
diff --git a/gio/src/fileinfo.hg b/gio/src/fileinfo.hg
index ae22d38b..d547cea2 100644
--- a/gio/src/fileinfo.hg
+++ b/gio/src/fileinfo.hg
@@ -16,7 +16,6 @@
#include <glibmm/datetime.h>
#include <glibmm/object.h>
-#include <glibmm/timeval.h>
#include <giomm/fileattributeinfolist.h>
#include <giomm/icon.h>
@@ -71,6 +70,7 @@ public:
class FileInfo : public Glib::Object
{
_CLASS_GOBJECT(FileInfo, GFileInfo, G_FILE_INFO, Glib::Object, GObject)
+ _IGNORE(g_file_info_get_modification_time, g_file_info_set_modification_time)dnl // deprecated
public:
_CTOR_DEFAULT()
@@ -165,8 +165,7 @@ public:
_WRAP_METHOD(goffset get_size() const, g_file_info_get_size)
- Glib::TimeVal modification_time() const;
- _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(std::string get_symlink_target() const, g_file_info_get_symlink_target)
@@ -195,7 +194,7 @@ public:
_WRAP_METHOD(void set_size(goffset size), g_file_info_set_size)
- _WRAP_METHOD(void set_modification_time(const Glib::TimeVal& mtime), g_file_info_set_modification_time)
+ _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.h b/glib/glibmm.h
index 20e7203a..2bd92bb5 100644
--- a/glib/glibmm.h
+++ b/glib/glibmm.h
@@ -39,12 +39,11 @@
* - Glib::Regex: Regular expression string matching.
* - Glib::KeyFile: Parsing and writing of key files (similar to .ini files)
* - Glib::Checksum
- * - Glib::Date, Glib::Timer, Glib::TimeVal
+ * - Glib::Date, Glib::DateTime, Glib::Timer
* - Glib::Dispatcher: Inter-thread communication
* - @ref FileUtils and @ref UriUtils
* - @ref MainLoop
* - @ref Spawn
- * - @ref Threads
* - @ref MiscUtils
*
* giomm (part of the glibmm project) also contains:
@@ -129,7 +128,6 @@
#include <glibmm/spawn.h>
#include <glibmm/stringutils.h>
#include <glibmm/timer.h>
-#include <glibmm/timeval.h>
#include <glibmm/timezone.h>
#include <glibmm/uriutils.h>
#include <glibmm/ustring.h>
diff --git a/glib/glibmm/filelist.am b/glib/glibmm/filelist.am
index 30c86a98..530c439f 100644
--- a/glib/glibmm/filelist.am
+++ b/glib/glibmm/filelist.am
@@ -27,7 +27,6 @@ glibmm_files_extra_cc = \
signalproxy_connectionnode.cc \
stringutils.cc \
timer.cc \
- timeval.cc \
ustring.cc \
utility.cc \
value.cc \
@@ -65,7 +64,6 @@ glibmm_files_extra_h = \
signalproxy_connectionnode.h \
stringutils.h \
timer.h \
- timeval.h \
ustring.h \
utility.h \
value.h \
diff --git a/glib/src/date.ccg b/glib/src/date.ccg
index 75f240ba..07f0812b 100644
--- a/glib/src/date.ccg
+++ b/glib/src/date.ccg
@@ -88,12 +88,6 @@ Date::set_time_current()
g_date_set_time_t(&gobject_, time(nullptr));
}
-void
-Date::set_time(const GTimeVal& timeval)
-{
- g_date_set_time_val(&gobject_, const_cast<GTimeVal*>(&timeval));
-}
-
void
Date::set_month(Date::Month month)
{
diff --git a/glib/src/date.hg b/glib/src/date.hg
index f3f9442f..1633d07a 100644
--- a/glib/src/date.hg
+++ b/glib/src/date.hg
@@ -118,18 +118,6 @@ public:
*/
void set_time(std::time_t timet);
- /** 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()
- *
- * @param timeval GTimeVal value to set
- *
- * Since: 2.10
- */
- void set_time(const GTimeVal& timeval);
-
/** Set this Glib::Date to the current time.
*/
void set_time_current();
diff --git a/glib/src/datetime.ccg b/glib/src/datetime.ccg
index 3295b3e4..dd6db94e 100644
--- a/glib/src/datetime.ccg
+++ b/glib/src/datetime.ccg
@@ -15,5 +15,14 @@
*/
#include <glibmm/utility.h>
-#include <glibmm/timeval.h>
#include <glibmm/wrap.h>
+
+namespace Glib
+{
+
+DateTime::operator bool() const
+{
+ return (gobject_ != nullptr);
+}
+
+} // namespace Glib
diff --git a/glib/src/datetime.hg b/glib/src/datetime.hg
index 8bd3711c..657efecf 100644
--- a/glib/src/datetime.hg
+++ b/glib/src/datetime.hg
@@ -29,8 +29,6 @@ typedef struct _GDateTime GDateTime;
namespace Glib
{
-struct TimeVal;
-
/** A value representing an interval of time, in microseconds. As GTimeSpan,
* its underlying type is gint64.
*/
@@ -65,6 +63,8 @@ class DateTime
// Glib::DateTime without Glib::RefPtr.
_CLASS_BOXEDTYPE(DateTime, GDateTime, NONE, g_date_time_ref, g_date_time_unref)
_IGNORE(g_date_time_ref, g_date_time_unref)
+ _IGNORE(g_date_time_new_from_timeval_local, g_date_time_new_from_timeval_utc,
+ g_date_time_to_timeval)dnl // deprecated
public:
_WRAP_METHOD(static DateTime create_now(const TimeZone& tz), g_date_time_new_now)
@@ -74,13 +74,17 @@ 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(static DateTime create_now_local(const TimeVal& tv), g_date_time_new_from_timeval_local)
- _WRAP_METHOD(static DateTime create_now_utc(const TimeVal& tv), g_date_time_new_from_timeval_utc)
-
+ _WRAP_METHOD(static DateTime create_from_iso8601(const Glib::ustring& text, const TimeZone&
default_tz{?}), g_date_time_new_from_iso8601)
_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.
+ */
+ 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)
@@ -142,7 +146,6 @@ public:
_WRAP_METHOD(int get_microsecond() const, g_date_time_get_microsecond)
_WRAP_METHOD(double get_seconds() const, g_date_time_get_seconds)
_WRAP_METHOD(gint64 to_unix() const, g_date_time_to_unix)
- _WRAP_METHOD(bool to_timeval(TimeVal& tv) const, g_date_time_to_timeval)
_WRAP_METHOD(TimeSpan get_utc_offset() const, g_date_time_get_utc_offset)
#m4 _CONVERSION(`GTimeZone*',`TimeZone',`Glib::wrap($3, true)')
_WRAP_METHOD(TimeZone get_timezone() const, g_date_time_get_timezone, newin "2,60")
@@ -152,6 +155,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_gio.m4 b/tools/m4/convert_gio.m4
index 36bf193d..7589cc58 100644
--- a/tools/m4/convert_gio.m4
+++ b/tools/m4/convert_gio.m4
@@ -204,8 +204,6 @@ _CONVERSION(`GFileEnumerator*',`Glib::RefPtr<FileEnumerator>',`Glib::wrap($3)')
_CONVERSION(`GFileInfo*',`Glib::RefPtr<FileInfo>',`Glib::wrap($3)')
_CONVERSION(`Glib::RefPtr<FileInfo>&',`GFileInfo*',__CONVERT_REFPTR_TO_P)
_CONVERSION(`const Glib::RefPtr<FileInfo>&',`GFileInfo*',__CONVERT_REFPTR_TO_P)
-_CONVERSION(`Glib::TimeVal&', `GTimeVal*', static_cast<$2>(&$3))
-_CONVERSION(`const Glib::TimeVal&', `GTimeVal*', const_cast<GTimeVal*>(static_cast<const GTimeVal*>(&$3)))
_CONVERSION(`const Glib::RefPtr<FileAttributeMatcher>&',`GFileAttributeMatcher*',__CONVERT_CONST_REFPTR_TO_P)
# FileInputStream
diff --git a/tools/m4/convert_glib.m4 b/tools/m4/convert_glib.m4
index f8bc1364..c7df34e9 100644
--- a/tools/m4/convert_glib.m4
+++ b/tools/m4/convert_glib.m4
@@ -107,6 +107,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(`const Glib::RefPtr<Glib::KeyFile>&',`GKeyFile*',__CONVERT_REFPTR_TO_P)
@@ -140,10 +141,6 @@ _CONVERSION(`GRegex*',`Glib::RefPtr<const Regex>',`Glib::wrap($3)')
#Source
_CONVERSION(`GSource*',`Glib::RefPtr<Glib::Source>',`Glib::wrap($3)')
-dnl TimeVal
-_CONVERSION(`const TimeVal&',`const GTimeVal*',`&($3)')
-_CONVERSION(`TimeVal&',`GTimeVal*',`&($3)')
-
dnl TimeZone
_CONVERSION(`GTimeZone*',`TimeZone',`Glib::wrap($3)')
_CONVERSION(`const TimeZone&',`GTimeZone*',`const_cast<$2>($3.gobj())')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]