Commit 1bc1302a authored by Matthias Clasen's avatar Matthias Clasen

Respect 12/24-hour clock setting in the file chooser

Based on a patch by Garrett Regier in bug 699224.
parent e4be5894
......@@ -3907,22 +3907,31 @@ stop_loading_and_clear_list_model (GtkFileChooserDefault *impl,
}
static char *
my_g_format_time_for_display (glong secs)
my_g_format_time_for_display (GtkFileChooserDefault *impl,
glong secs)
{
GDateTime *now, *time;
GTimeSpan time_diff;
gchar *clock_format;
gboolean use_24 = TRUE;
const gchar *format;
gchar *date_str;
GSettings *settings;
now = g_date_time_new_now_local ();
time = g_date_time_new_from_unix_local (secs);
time_diff = g_date_time_difference (now, time);
settings = _gtk_file_chooser_get_settings_for_widget (GTK_WIDGET (impl));
clock_format = g_settings_get_string (settings, "clock-format");
use_24 = g_strcmp0 (clock_format, "24h") == 0;
g_free (clock_format);
/* Translators: see g_date_time_format() for details on the format */
if (time_diff >= 0 && time_diff < G_TIME_SPAN_DAY)
format = _("%H:%M");
format = use_24 ? _("%H:%M") : _("%-I:%M %P");
else if (time_diff >= 0 && time_diff < 2 * G_TIME_SPAN_DAY)
format = _("Yesterday at %H:%M");
format = use_24 ? _("Yesterday at %H:%M") : _("Yesterday at %-I:%M %P");
else if (time_diff >= 0 && time_diff < 7 * G_TIME_SPAN_DAY)
format = "%A"; /* Days from last week */
else
......@@ -4113,7 +4122,7 @@ file_system_model_set (GtkFileSystemModel *model,
else if (tv.tv_sec == 0)
g_value_set_static_string (value, _("Unknown"));
else
g_value_take_string (value, my_g_format_time_for_display (tv.tv_sec));
g_value_take_string (value, my_g_format_time_for_display (impl, tv.tv_sec));
break;
}
case MODEL_COL_ELLIPSIZE:
......@@ -7496,6 +7505,10 @@ _gtk_file_chooser_default_init (GtkFileChooserDefault *impl)
set_file_system_backend (impl);
if (g_settings_schema_source_lookup (g_settings_schema_source_get_default (),
"org.gnome.desktop.interface",
TRUE) != NULL)
priv->bookmarks_manager = _gtk_bookmarks_manager_new (NULL, NULL);
/* Setup various attributes and callbacks in the UI
......
......@@ -38,6 +38,11 @@
<value nick='cwd' value='1'/>
</enum>
<enum id='org.gtk.Settings.FileChooser.ClockFormat'>
<value nick='24h' value='0'/>
<value nick='12h' value='1'/>
</enum>
<schema id='org.gtk.Settings.FileChooser' path='/org/gtk/settings/file-chooser/'>
<key name='last-folder-uri' type='s'>
<default>""</default>
......@@ -114,6 +119,12 @@
Width in pixels of the file chooser's places sidebar.
</description>
</key>
<key name="clock-format" enum="org.gtk.Settings.FileChooser.ClockFormat">
<default>'24h'</default>
<description>
Whether the time is shown in 24h or 12h format.
</description>
</key>
</schema>
</schemalist>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment