[gnome-commander] Use GIO functions to find and format the modification time of the file



commit 8ee51ed74b78ceb1ce83f04182ee031889b5b5ce
Author: Uwe Scholz <u scholz83 gmx de>
Date:   Sun Jul 11 21:45:00 2021 +0200

    Use GIO functions to find and format the modification time of the file

 doc/C/index.docbook              | 35 ++++++++---------------------------
 src/gnome-cmd-advrename-lexer.ll | 27 +++++++++++++++++----------
 2 files changed, 25 insertions(+), 37 deletions(-)
---
diff --git a/doc/C/index.docbook b/doc/C/index.docbook
index 8ef8c33e..2061cfb1 100644
--- a/doc/C/index.docbook
+++ b/doc/C/index.docbook
@@ -1584,7 +1584,7 @@
                         go into the new name without conversion. Conversion specifiers are introduced by a 
few
                         <link linkend="gnome-commander-advanced-rename-placeholders">placeholders</link>
                         (see below for the detailed list). Additionally
-                        <link linkend="gnome-commander-advanced-rename-strftime">strftime() format 
controls</link>
+                        <link 
linkend="gnome-commander-advanced-rename-g-date-time-format">g_date_time_format() format controls</link>
                         are also accepted - except for "%D", "%n" and "%t" for obvious reasons.
                         If found, they are left intact.</para>
               </listitem>
@@ -3971,8 +3971,8 @@
         </tip>
         </sect3>
 
-        <sect3 id="gnome-commander-advanced-rename-strftime">
-        <title>strftime() format controls</title>
+        <sect3 id="gnome-commander-advanced-rename-g-date-time-format">
+        <title>g_date_time_format() format controls</title>
         <informaltable frame="topbot">
             <tgroup cols="2">
                 <colspec colname="col1"/>
@@ -4016,10 +4016,6 @@
                         <entry><para>%e</para></entry>
                         <entry><para>Like %d, the day of the month as a decimal number, but a leading zero 
is replaced by a space</para></entry>
                     </row>
-                    <row valign="top">
-                        <entry><para>%E</para></entry>
-                        <entry><para>Modifier: use alternative format, see below</para></entry>
-                    </row>
                     <row valign="top">
                         <entry><para>%F</para></entry>
                         <entry><para>Equivalent to %Y-%m-%d (the ISO 8601 date format)</para></entry>
@@ -4105,12 +4101,6 @@
                         <entry><para>%u</para></entry>
                         <entry><para>The day of the week as a decimal, range 1 to 7, Monday being 1.  See 
also %w</para></entry>
                     </row>
-                    <row valign="top">
-                        <entry><para>%U</para></entry>
-                        <entry><para>The week number of the current year as a decimal number, range 00 to 53,
-                                     starting with the  first  Sunday as the first day of week 01.
-                                     See also %V and %W</para></entry>
-                    </row>
                     <row valign="top">
                         <entry><para>%V</para></entry>
                         <entry><para>The  ISO  8601:1988  week number of the current year as a decimal 
number, range 01 to 53, where week 1 is the
@@ -4121,11 +4111,6 @@
                         <entry><para>%w</para></entry>
                         <entry><para>The day of the week as a decimal, range 0 to 6, Sunday being 0.  See 
also %u</para></entry>
                     </row>
-                    <row valign="top">
-                        <entry><para>%W</para></entry>
-                        <entry><para>The  week  number  of the current year as a decimal number, range 00 to 
53,
-                                     starting with the first Monday as the first day of week 
01</para></entry>
-                    </row>
                     <row valign="top">
                         <entry><para>%x</para></entry>
                         <entry><para>The preferred date representation for the current locale without the 
time</para></entry>
@@ -4164,12 +4149,9 @@
         </informaltable>
 
         <note>
-            <para>Some conversion specifiers can be modified by preceding them by the E or O modifier to 
indicate that an alternative
+            <para>Some conversion specifiers can be modified by preceding them by the O modifier to indicate 
that an alternative
             format should be used. If the alternative format or specification does not exist for the current 
locale,
-            the behaviour will be as if the unmodified conversion specification were used. The Single Unix 
Specification
-            mentions %Ec, %EC, %Ex, %EX, %Ey, %EY, %Od, %Oe, %OH, %OI, %Om, %OM, %OS, %Ou, %OU, %OV, %Ow, 
%OW, %Oy,
-            where the effect of the O modifier is to use alternative numeric symbols (say, roman numerals),
-            and that of the E modifier is to use a locale-dependent alternative representation.</para>
+            the behaviour will be as if the unmodified conversion specification were used.</para>
         </note>
     </sect3>
     </sect2>
@@ -4891,10 +4873,9 @@
                 <para>Format</para>
               </entry>
               <entry>
-                <para>The date format is defined by strftime you can test it to
-                validate the string you enter there. For more information about
-                strftime please read the
-                <ulink url="http://linux.die.net/man/3/strftime";>man page</ulink>.
+                <para>The date format is defined by GIO's g_date_time_format() function.
+                For more information about g_date_time_format please read the
+                <ulink 
url="https://developer.gnome.org/glib/stable/glib-GDateTime.html#g-date-time-format";>documentation</ulink>.
                 </para>
               </entry>
             </row>
diff --git a/src/gnome-cmd-advrename-lexer.ll b/src/gnome-cmd-advrename-lexer.ll
index c2c2fc35..ca89b060 100644
--- a/src/gnome-cmd-advrename-lexer.ll
+++ b/src/gnome-cmd-advrename-lexer.ll
@@ -491,7 +491,7 @@ char *gnome_cmd_advrename_gen_fname (GnomeCmdFile *f, size_t new_fname_size)
   string fmt;
   fmt.reserve(256);
 
-  char *fname = get_utf8 (f->info->name);
+  char *fname = get_gfile_attribute_string (f->gFile, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
   const char *ext = g_utf8_strrchr (fname, -1, '.');
 
   int full_name_len = g_utf8_strlen (fname, -1);
@@ -598,15 +598,22 @@ char *gnome_cmd_advrename_gen_fname (GnomeCmdFile *f, size_t new_fname_size)
   gboolean new_fname_has_percent = convert ((char *) fmt.c_str(), '%', ESC);
   convert ((char *) fmt.c_str(), SUB, '%');
 
-#if defined (__GNUC__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wformat-nonliteral"
-#endif
-  if (!strftime(new_fname, new_fname_size+1, fmt.c_str(), localtime(&f->info->mtime)))      // if new_fname 
is not big enough...
-    new_fname[new_fname_size] = '\0';                                                       //      ... 
truncate
-#if defined (__GNUC__)
-#pragma GCC diagnostic pop
-#endif
+  auto dateTimeString = g_date_time_format (g_file_info_get_modification_date_time(f->gFileInfo), 
fmt.c_str());
+  if (dateTimeString)
+  {
+    if ((gulong) g_utf8_strlen(dateTimeString, -1) >= new_fname_size+1)
+    {
+      g_utf8_strncpy(new_fname, dateTimeString, new_fname_size+1);
+    }
+    else
+    {
+      new_fname = dateTimeString;
+    }
+  }
+  else //Rescue if something goes wrong...
+  {
+    new_fname = g_strdup(fmt.c_str());
+  }
 
   if (new_fname_has_percent)
     convert (new_fname, ESC, '%');


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