[gnome-commander] Access time will be readable through defined method in glib-2.70
- From: Uwe Scholz <uwescholz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander] Access time will be readable through defined method in glib-2.70
- Date: Sat, 15 May 2021 21:00:56 +0000 (UTC)
commit 5eccc4a6c892df41ebe845eb80fbd6b4ff9b99fb
Author: Uwe Scholz <u scholz83 gmx de>
Date: Fri May 14 12:57:11 2021 +0200
Access time will be readable through defined method in glib-2.70
Migration time2string method to accept GDateTime objects
configure.ac | 7 ++++++-
src/dialogs/gnome-cmd-file-props-dialog.cc | 3 ++-
src/gnome-cmd-file.cc | 13 +++++++------
src/gnome-cmd-file.h | 2 ++
src/gnome-cmd-xfer.cc | 18 +++++++++++++-----
src/utils.cc | 22 ++++++----------------
src/utils.h | 4 ++--
7 files changed, 38 insertions(+), 31 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 58b16718..f7afb6d2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -61,7 +61,12 @@ GTEST_REQ=1.7.0
AC_SUBST(GTEST_REQ)
dnl Check for glib
-PKG_CHECK_MODULES([GLIB], [glib-2.0 >= ${GLIB_REQ}])
+PKG_CHECK_MODULES([GLIB], [glib-2.0 >= ${GLIB_REQ}], have_glib_req=yes, have_glib_req=no)
+if test "x$have_glib_req" = "xyes"; then
+ PKG_CHECK_MODULES(GLIB_2_70, glib-2.0 >= 2.70.0,
+ AC_DEFINE(GLIB_2_70, 1, [Defined to 1 if you have glib >= 2.70]),
+ have_glib_2_70=no)
+fi
dnl Check for gobject
PKG_CHECK_MODULES([GOBJECT],[gobject-2.0])
diff --git a/src/dialogs/gnome-cmd-file-props-dialog.cc b/src/dialogs/gnome-cmd-file-props-dialog.cc
index ea873227..e376c554 100644
--- a/src/dialogs/gnome-cmd-file-props-dialog.cc
+++ b/src/dialogs/gnome-cmd-file-props-dialog.cc
@@ -454,12 +454,13 @@ static GtkWidget *create_properties_tab (GnomeCmdFilePropsDialogPrivate *data)
label = create_label (dialog, data->f->get_mdate(TRUE));
table_add (table, label, 1, y++, GTK_FILL);
+#ifdef GLIB_2_70
label = create_bold_label (dialog, _("Accessed:"));
table_add (table, label, 0, y, GTK_FILL);
label = create_label (dialog, data->f->get_adate(TRUE));
table_add (table, label, 1, y++, GTK_FILL);
-
+#endif
add_sep (table, y++);
diff --git a/src/gnome-cmd-file.cc b/src/gnome-cmd-file.cc
index 7f5285f4..c1542d90 100644
--- a/src/gnome-cmd-file.cc
+++ b/src/gnome-cmd-file.cc
@@ -757,25 +757,26 @@ const gchar *GnomeCmdFile::get_group()
}
-inline const gchar *date2string (time_t date, gboolean overide_disp_setting)
+inline const gchar *date2string (GDateTime *date, gboolean overide_disp_setting)
{
- return time2string (date, overide_disp_setting?"%c":gnome_cmd_data.options.date_format);
+ return time2string (date, overide_disp_setting ? "%c" : gnome_cmd_data.options.date_format);
}
+#ifdef GLIB_2_70
const gchar *GnomeCmdFile::get_adate(gboolean overide_disp_setting)
{
g_return_val_if_fail (info != nullptr, nullptr);
- return date2string (info->atime, overide_disp_setting);
+ return date2string (g_file_info_get_access_date_time(gFileInfo), overide_disp_setting);
}
-
+#endif
const gchar *GnomeCmdFile::get_mdate(gboolean overide_disp_setting)
{
- g_return_val_if_fail (info != nullptr, nullptr);
+ g_return_val_if_fail (gFileInfo != nullptr, nullptr);
- return date2string (info->mtime, overide_disp_setting);
+ return date2string (g_file_info_get_modification_date_time(gFileInfo), overide_disp_setting);
}
diff --git a/src/gnome-cmd-file.h b/src/gnome-cmd-file.h
index 2aa2be60..42769612 100644
--- a/src/gnome-cmd-file.h
+++ b/src/gnome-cmd-file.h
@@ -73,7 +73,9 @@ struct GnomeCmdFile
const gchar *get_extension();
const gchar *get_owner();
const gchar *get_group();
+#ifdef GLIB_2_70
const gchar *get_adate(gboolean overide_disp_setting);
+#endif
const gchar *get_mdate(gboolean overide_disp_setting);
const gchar *get_size();
guint64 get_tree_size();
diff --git a/src/gnome-cmd-xfer.cc b/src/gnome-cmd-xfer.cc
index f95fc476..aecd2623 100644
--- a/src/gnome-cmd-xfer.cc
+++ b/src/gnome-cmd-xfer.cc
@@ -145,12 +145,20 @@ create_xfer_data (GnomeVFSXferOptions xferOptions, GList *src_uri_list, GList *d
inline gchar *file_details(const gchar *text_uri)
{
- GnomeVFSFileInfo *info = gnome_vfs_file_info_new ();
- GnomeVFSResult result = gnome_vfs_get_file_info (text_uri, info, GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
- gchar *size = create_nice_size_str (info->size);
- gchar *details = result==GNOME_VFS_OK ? g_strdup_printf ("%s, %s", size, time2string (info->mtime,
gnome_cmd_data.options.date_format)) : g_strdup ("");
- gnome_vfs_file_info_unref (info);
+ auto gFileTmp = g_file_new_for_uri(text_uri);
+ auto gFileInfoTmp = g_file_query_info(gFileTmp,
+ G_FILE_ATTRIBUTE_STANDARD_SIZE "," G_FILE_ATTRIBUTE_TIME_MODIFIED,
+ G_FILE_QUERY_INFO_NONE, nullptr, nullptr);
+ gchar *size = create_nice_size_str (g_file_info_get_attribute_uint64(gFileInfoTmp,
G_FILE_ATTRIBUTE_STANDARD_SIZE));
+
+ gchar *details =
+ gFileInfoTmp != nullptr
+ ? g_strdup_printf ("%s, %s", size,
+ time2string (g_file_info_get_modification_date_time(gFileInfoTmp),
+ gnome_cmd_data.options.date_format))
+ : g_strdup ("");
g_free (size);
+ g_object_unref(gFileInfoTmp);
return details;
}
diff --git a/src/utils.cc b/src/utils.cc
index bdf9f3a7..b951b7fe 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -382,29 +382,19 @@ const gchar *size2string (guint64 size, GnomeCmdSizeDispMode size_disp_mode)
}
-const gchar *time2string (time_t t, const gchar *date_format)
+const gchar *time2string (GDateTime *gDateTime, const gchar *date_format)
{
// NOTE: date_format is passed in current locale format
+ g_return_val_if_fail (gDateTime != nullptr, nullptr);
+
static gchar buf[64];
- struct tm lt;
- localtime_r (&t, <);
-#if defined (__GNUC__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wformat-nonliteral"
-#endif
- strftime (buf, sizeof(buf), date_format, <);
-#if defined (__GNUC__)
-#pragma GCC diagnostic pop
-#endif
+ auto dateString = g_date_time_format (gDateTime, date_format);
- // convert formatted date from current locale to UTF8
- gchar *loc_date = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL);
- if (loc_date)
- strncpy (buf, loc_date, sizeof(buf)-1);
+ strncpy (buf, dateString, sizeof(buf)-1);
- g_free (loc_date);
+ g_free (dateString);
return buf;
}
diff --git a/src/utils.h b/src/utils.h
index 365b461d..2ba5ce62 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -1,5 +1,5 @@
/**
- * @file utils.h
+ * @file utils.h
* @copyright (C) 2001-2006 Marcus Bjurman\n
* @copyright (C) 2007-2012 Piotr Eljasiak\n
* @copyright (C) 2013-2021 Uwe Scholz\n
@@ -138,7 +138,7 @@ const gchar *perm2string (guint32 permissions, gchar *buf, guint max);
const gchar *perm2textstring (guint32 permissions, gchar *buf, guint max);
const gchar *perm2numstring (guint32 permissions, gchar *buf, guint max);
const gchar *size2string (guint64 size, GnomeCmdSizeDispMode size_disp_mode);
-const gchar *time2string (time_t t, const gchar *date_format);
+const gchar *time2string (GDateTime *gDateTime, const gchar *date_format);
void clear_event_key (GdkEventKey *event);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]