1
0
mirror of https://gitlab.gnome.org/GNOME/nautilus synced 2024-06-30 23:46:35 +00:00

date-utilities: Add detailed date and time format option

The default time and date formats in Files are intended to be human
friendly and to avoid information overload. This works for most cases
and is an appropriate default. However, there are cases where people
need to be able to see a complete date and time for their files.

This adds a preference to show a numerical date and time format.

Part of #2874
This commit is contained in:
Ondrej Holy 2023-06-01 13:14:51 +02:00 committed by António Fernandes
parent 3f263a209e
commit ab4db18c49
3 changed files with 55 additions and 3 deletions

View File

@ -11,6 +11,11 @@
<value value="1" nick="double"/>
</enum>
<enum id="org.gnome.nautilus.DateTimeFormat">
<value value="0" nick="simple"/>
<value value="1" nick="detailed"/>
</enum>
<enum id="org.gnome.nautilus.ActivationChoice">
<value value="0" nick="launch"/>
<value value="1" nick="display"/>
@ -183,6 +188,11 @@
<summary>Whether to have full text search enabled by default when opening a new window/tab</summary>
<description>If set to true, Files will also match the file contents besides the name. This toggles the default active state, which can still be overridden in the search popover</description>
</key>
<key name="date-time-format" enum="org.gnome.nautilus.DateTimeFormat">
<default>'simple'</default>
<summary>How to display file timestamps in the views</summary>
<description>If set to 'simple', Files will show Today and Yesterday with time, otherwise the exact date without time. If set to 'detailed', it will always show the exact date and time.</description>
</key>
</schema>
<schema path="/org/gnome/nautilus/compression/" id="org.gnome.nautilus.compression" gettext-domain="nautilus">

View File

@ -18,6 +18,7 @@
G_DEFINE_AUTO_CLEANUP_FREE_FUNC (locale_t, freelocale, (locale_t) 0)
static gboolean use_24_hour;
static gboolean use_detailed_date_format;
static void
clock_format_changed_callback (gpointer)
@ -26,6 +27,14 @@ clock_format_changed_callback (gpointer)
use_24_hour = (clock_format == G_DESKTOP_CLOCK_FORMAT_24H);
}
static void
date_format_changed_callback (gpointer)
{
NautilusDateTimeFormat format = g_settings_get_enum (nautilus_preferences,
NAUTILUS_PREFERENCES_DATE_TIME_FORMAT);
use_detailed_date_format = (format == NAUTILUS_DATE_TIME_FORMAT_DETAILED);
}
void
nautilus_date_setup_preferences (void)
{
@ -34,11 +43,18 @@ nautilus_date_setup_preferences (void)
"changed::clock-format",
G_CALLBACK (clock_format_changed_callback),
NULL);
date_format_changed_callback (NULL);
g_signal_connect_swapped (nautilus_preferences,
"changed::" NAUTILUS_PREFERENCES_DATE_TIME_FORMAT,
G_CALLBACK (date_format_changed_callback),
NULL);
}
static char *
date_to_str (GDateTime *timestamp,
gboolean use_short_format)
gboolean use_short_format,
gboolean detailed_date)
{
const char *time_locale = setlocale (LC_TIME, NULL);
locale_t current_locale = uselocale ((locale_t) 0);
@ -57,7 +73,24 @@ date_to_str (GDateTime *timestamp,
forced_locale = newlocale (LC_MESSAGES_MASK, time_locale, duplocale (current_locale));
uselocale (forced_locale);
if (use_short_format)
if (use_short_format && detailed_date)
{
if (use_24_hour)
{
/* Translators: date and time in 24h format,
* i.e. "12/31/2023 23:59" */
/* xgettext:no-c-format */
format = _("%m/%d/%Y %H:%M");
}
else
{
/* Translators: date and time in 12h format,
* i.e. "12/31/2023 11:59 PM" */
/* xgettext:no-c-format */
format = _("%m/%d/%Y %I:%M %p");
}
}
else if (use_short_format)
{
/* Re-use local time zone, because every time a new local time zone is
* created, GLib needs to check if the time zone file has changed */
@ -156,5 +189,5 @@ char *
nautilus_date_to_str (GDateTime *timestamp,
gboolean use_short_format)
{
return date_to_str (timestamp, use_short_format);
return date_to_str (timestamp, use_short_format, use_detailed_date_format);
}

View File

@ -127,6 +127,15 @@ typedef enum
/* Gtk settings migration happened */
#define NAUTILUS_PREFERENCES_MIGRATED_GTK_SETTINGS "migrated-gtk-settings"
/* Date and time format in the view */
#define NAUTILUS_PREFERENCES_DATE_TIME_FORMAT "date-time-format"
typedef enum
{
NAUTILUS_DATE_TIME_FORMAT_SIMPLE = 0,
NAUTILUS_DATE_TIME_FORMAT_DETAILED,
} NautilusDateTimeFormat;
void nautilus_global_preferences_init (void);
extern GSettings *nautilus_preferences;