diff options
author | Matthias Clasen <mclasen@redhat.com> | 2014-01-24 18:04:51 -0500 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2014-01-24 18:05:26 -0500 |
commit | 1bc1302af0ae8d59d1bb3a2490c29d5a2c430128 (patch) | |
tree | 0752d20e307dd4a24f22a753779dc8f3eb4fd0f1 /gtk | |
parent | e4be589448ab13148a5543caa6fdb3857f751ed1 (diff) | |
download | gtk+-1bc1302af0ae8d59d1bb3a2490c29d5a2c430128.tar.gz |
Respect 12/24-hour clock setting in the file chooser
Based on a patch by Garrett Regier in bug 699224.
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/gtkfilechooserdefault.c | 21 | ||||
-rw-r--r-- | gtk/org.gtk.Settings.FileChooser.gschema.xml | 11 |
2 files changed, 28 insertions, 4 deletions
diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index e21a833ae8..447170be96 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -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 diff --git a/gtk/org.gtk.Settings.FileChooser.gschema.xml b/gtk/org.gtk.Settings.FileChooser.gschema.xml index 087b3c221f..12d718d64a 100644 --- a/gtk/org.gtk.Settings.FileChooser.gschema.xml +++ b/gtk/org.gtk.Settings.FileChooser.gschema.xml @@ -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> |