Last modified file text missing for files like Comité.gnucash on Windows

This is down to the use of stat so changed to use GFile to get the last
modified date.
This commit is contained in:
Robert Fewell 2021-02-24 14:52:46 +00:00
parent 43c2b7e9d7
commit a9dcf0d81d

View File

@ -1737,40 +1737,41 @@ static gchar *generate_statusbar_lastmodified_message()
{ {
if (gnc_uri_targets_local_fs (uri)) if (gnc_uri_targets_local_fs (uri))
{ {
#ifdef HAVE_SYS_STAT_H
/* The filename is a true file. */ /* The filename is a true file. */
gchar *filepath = gnc_uri_get_path ( uri ); gchar *filepath = gnc_uri_get_path ( uri );
gchar *filename = g_path_get_basename ( filepath ); gchar *filename = g_path_get_basename ( filepath );
GFile *file = g_file_new_for_uri (uri);
GFileInfo *info = g_file_query_info (file,
G_FILE_ATTRIBUTE_TIME_MODIFIED,
G_FILE_QUERY_INFO_NONE,
NULL, NULL);
if (info && g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED))
{ {
// Access the mtime information through stat(2) guint64 modtime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
struct stat statbuf;
int r = stat(filepath, &statbuf); /* Translators: This is the date and time that is shown in
if (r == 0) the status bar after opening a file: The date and time of
{ last modification. The string is a format string using
/* Translators: This is the date and time that is shown in boost::date_time's format flags, see the boost docs for an
the status bar after opening a file: The date and time of explanation of the modifiers. */
last modification. The string is a format string using char *time_string = gnc_print_time64 (modtime,
boost::date_time's format flags, see the boost docs for an _("Last modified on %a, %b %d, %Y at %I:%M %p"));
explanation of the modifiers. */ //g_warning("got time %ld, str=%s\n", mtime, time_string);
char *time_string = gnc_print_time64(statbuf.st_mtime, /* Translators: This message appears in the status bar after opening the file. */
_("Last modified on %a, %b %d, %Y at %I:%M %p")); message = g_strdup_printf(_("File %s opened. %s"),
//g_warning("got time %ld, str=%s\n", mtime, time_string); filename, time_string);
/* Translators: This message appears in the status bar after opening the file. */ free(time_string);
message = g_strdup_printf(_("File %s opened. %s"), }
filename, time_string); else
free(time_string); {
} g_warning("Unable to read mtime for file %s\n", filepath);
else // message is still NULL
{
g_warning("Unable to read mtime for file %s\n", filepath);
// message is still NULL
}
} }
g_free(filename); g_free(filename);
g_free(filepath); g_free(filepath);
#else g_object_unref (info);
return NULL; g_object_unref (file);
#endif
} }
// If the URI is not a file but a database, we can maybe also show // If the URI is not a file but a database, we can maybe also show
// something useful, but I have no idea how to obtain this information. // something useful, but I have no idea how to obtain this information.