Merge lp:~jeremywootten/pantheon-files/fix-1633862-honor-24h-clock into lp:~elementary-apps/pantheon-files/trunk

Proposed by Jeremy Wootten
Status: Merged
Approved by: Cody Garver
Approved revision: 2523
Merged at revision: 2553
Proposed branch: lp:~jeremywootten/pantheon-files/fix-1633862-honor-24h-clock
Merge into: lp:~elementary-apps/pantheon-files/trunk
Diff against target: 406 lines (+76/-126)
10 files modified
libcore/FileUtils.vala (+49/-55)
libcore/gof-directory-async.vala (+7/-7)
libcore/gof-file.c (+4/-5)
libcore/gof-preferences.vala (+8/-47)
libcore/marlin-file-operations.c (+1/-1)
libwidgets/View/SearchResults.vala (+1/-1)
plugins/pantheon-files-ctags/plugin.vala (+1/-1)
src/Application.vala (+3/-0)
src/marlin-global-preferences.h (+1/-8)
src/marlin.vapi (+1/-1)
To merge this branch: bzr merge lp:~jeremywootten/pantheon-files/fix-1633862-honor-24h-clock
Reviewer Review Type Date Requested Status
Danielle Foré Approve
Review via email: mp+319476@code.launchpad.net

Commit message

* Display "iso" format when this is selected in settings
* Honor 12/24hr setting when "informal" is the date-time format
* clean up the code for gof-preferences and global-preferences

Description of the change

This branches fixes a couple of issues with the date-time formatting.

* Displays "iso" format when this is selected in settings
* Honors the gnome-interface setting of clock-format when "informal" is selected as the date-time format.

Also the opportunity was taken to clean up the code for gof-preferences and global-preferences.

To post a comment you must log in.
2523. By Jeremy Wootten

Use explicit translatable datetime formats

Revision history for this message
Danielle Foré (danrabbit) wrote :

Looks like some good cleanup and I can confirm that the 12/24hr time setting is now respected. Nice work :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libcore/FileUtils.vala'
2--- libcore/FileUtils.vala 2017-02-26 04:50:36 +0000
3+++ libcore/FileUtils.vala 2017-03-10 17:31:58 +0000
4@@ -357,52 +357,46 @@
5 });
6 }
7
8- public string get_formatted_time_attribute_from_info (GLib.FileInfo info, string attr, string format = "locale") {
9+ public string get_formatted_time_attribute_from_info (GLib.FileInfo info, string attr) {
10+ DateTime? dt = null;
11+
12 switch (attr) {
13 case FileAttribute.TIME_MODIFIED:
14 case FileAttribute.TIME_CREATED:
15 case FileAttribute.TIME_ACCESS:
16 case FileAttribute.TIME_CHANGED:
17 uint64 t = info.get_attribute_uint64 (attr);
18- if (t == 0) {
19- return "";
20- }
21-
22- DateTime dt = new DateTime.from_unix_local ((int64)t);
23-
24- if (dt == null) {
25- return "";
26- }
27-
28- return get_formatted_date_time (dt, format);
29+ if (t > 0) {
30+ dt = new DateTime.from_unix_local ((int64)t);
31+ }
32+
33+ break;
34
35 case FileAttribute.TRASH_DELETION_DATE:
36 var deletion_date = info.get_attribute_string (attr);
37 var tv = TimeVal ();
38- if (deletion_date == null || !tv.from_iso8601 (deletion_date)) {
39- return "";
40- }
41-
42- DateTime dt = new DateTime.from_timeval_local (tv);
43-
44- if (dt == null) {
45- return "";
46- }
47-
48- return get_formatted_date_time (dt, format);
49+ if (deletion_date != null && !tv.from_iso8601 (deletion_date)) {
50+ dt = new DateTime.from_timeval_local (tv);
51+ }
52+
53+ break;
54
55 default:
56 break;
57 }
58
59- return "";
60+ return get_formatted_date_time (dt);
61 }
62
63- public string get_formatted_date_time (DateTime dt, string format = "locale") {
64- switch (format) {
65+ public string get_formatted_date_time (DateTime? dt) {
66+ if (dt == null) {
67+ return "";
68+ }
69+
70+ switch (GOF.Preferences.get_default ().date_format.down ()) {
71 case "locale":
72 return dt.format ("%c");
73- case "ISO" :
74+ case "iso" :
75 return dt.format ("%Y-%m-%d %H:%M:%S");
76 default:
77 return get_informal_date_time (dt);
78@@ -430,39 +424,39 @@
79 int now_weekday = now.get_day_of_week ();
80 int disp_weekday = dt.get_day_of_week ();
81
82+ bool clock_is_24h = GOF.Preferences.get_default ().clock_format.has_prefix ("24");
83+
84+ string format_string = "";
85+
86 switch (now_weekday - disp_weekday) {
87 case 0:
88- /* TRANSLATORS: This string determines the format and order in which the day and time
89- * are shown informally for a time that occurred today.
90- * %-I expands to the numeric hour in 12 hour clock.
91- * %M expands to the numeric minute.
92- * %p expands to "am" or "pm" according to the locale.
93- * These components must not be altered, but their order may be changed to accord with
94- * the informal custom for the locale.
95- */
96- return dt.format (_("Today at %-I:%M %p"));
97+ if (clock_is_24h) {
98+ format_string = _("Today at %-H:%M"); ///TRANSLATORS Used when 24h clock has been selected
99+ } else {
100+ format_string = _("Today at %-I:%M %p"); ///TRANSLATORS Used when 12h clock has been selected (if available))
101+ }
102+
103+ break;
104 case 1:
105- /* TRANSLATORS: This string determines the format and order in which the day and time
106- * are shown informally for a time that occurred yesterday.
107- * %-I expands to the numeric hour in 12 hour clock.
108- * %M expands to the numeric minute.
109- * %p expands to "am" or "pm" according to the locale.
110- * These components must not be altered, but their order may be changed to accord with
111- * the informal custom for the locale.
112- */
113- return dt.format (_("Yesterday at %-I:%M %p"));
114+ if (clock_is_24h) {
115+ format_string = _("Yesterday at %-H:%M"); ///TRANSLATORS Used when 24h clock has been selected
116+ } else {
117+ format_string = _("Yesterday at %-I:%M %p"); ///TRANSLATORS Used when 12h clock has been selected (if available))
118+ }
119+
120+ break;
121+
122 default:
123- /* TRANSLATORS: This string determines the format and order in which the day and time
124- * are shown informally for a time that occurred in the past week.
125- * %-I expands to the numeric hour in 12 hour clock.
126- * %M expands to the numeric minute.
127- * %p expands to "am" or "pm" according to the locale.
128- * %A expands to the abbreviated name of the weekday according to the locale.
129- * These components must not be altered, but their order may be changed to accord with
130- * the informal custom for the locale.
131- */
132- return dt.format (_("%A at %-I:%M %p"));
133+ if (clock_is_24h) {
134+ format_string = _("%A at %-H:%M"); ///TRANSLATORS Used when 24h clock has been selected
135+ } else {
136+ format_string = _("%A at %-I:%M %p"); ///TRANSLATORS Used when 12h clock has been selected (if available))
137+ }
138+
139+ break;
140 }
141+
142+ return dt.format (format_string);
143 }
144
145 private bool can_browse_scheme (string scheme) {
146
147=== modified file 'libcore/gof-directory-async.vala'
148--- libcore/gof-directory-async.vala 2017-02-26 04:50:36 +0000
149+++ libcore/gof-directory-async.vala 2017-03-10 17:31:58 +0000
150@@ -533,7 +533,7 @@
151 debug ("Listing cached files"); /* Required for ctest */
152
153 state = State.LOADING;
154- bool show_hidden = is_trash || Preferences.get_default ().pref_show_hidden_files;
155+ bool show_hidden = is_trash || Preferences.get_default ().show_hidden_files;
156 foreach (GOF.File gof in file_hash.get_values ()) {
157 if (gof != null) {
158 after_load_file (gof, show_hidden, file_loaded_func);
159@@ -571,7 +571,7 @@
160 can_load = true;
161 files_count = 0;
162 state = State.LOADING;
163- bool show_hidden = is_trash || Preferences.get_default ().pref_show_hidden_files;
164+ bool show_hidden = is_trash || Preferences.get_default ().show_hidden_files;
165 bool server_responding = false;
166
167 debug ("(Re)loading folder children"); /* Required for ctest */
168@@ -712,7 +712,7 @@
169 public void update_files () {
170 foreach (GOF.File gof in file_hash.get_values ()) {
171 if (gof != null && gof.info != null
172- && (!gof.is_hidden || Preferences.get_default ().pref_show_hidden_files))
173+ && (!gof.is_hidden || Preferences.get_default ().show_hidden_files))
174
175 gof.update ();
176 }
177@@ -721,7 +721,7 @@
178 public void update_desktop_files () {
179 foreach (GOF.File gof in file_hash.get_values ()) {
180 if (gof != null && gof.info != null
181- && (!gof.is_hidden || Preferences.get_default ().pref_show_hidden_files)
182+ && (!gof.is_hidden || Preferences.get_default ().show_hidden_files)
183 && gof.is_desktop)
184
185 gof.update_desktop_file ();
186@@ -793,7 +793,7 @@
187
188 gof.update ();
189
190- if (!gof.is_hidden || Preferences.get_default ().pref_show_hidden_files) {
191+ if (!gof.is_hidden || Preferences.get_default ().show_hidden_files) {
192 file_changed (gof);
193 gof.changed ();
194 }
195@@ -811,7 +811,7 @@
196
197 gof.update ();
198
199- if ((!gof.is_hidden || Preferences.get_default ().pref_show_hidden_files)) {
200+ if ((!gof.is_hidden || Preferences.get_default ().show_hidden_files)) {
201 file_added (gof);
202 }
203
204@@ -838,7 +838,7 @@
205 }
206
207 private void notify_file_removed (GOF.File gof) {
208- if (!gof.is_hidden || Preferences.get_default ().pref_show_hidden_files) {
209+ if (!gof.is_hidden || Preferences.get_default ().show_hidden_files) {
210 file_deleted (gof);
211 }
212
213
214=== modified file 'libcore/gof-file.c'
215--- libcore/gof-file.c 2017-02-26 04:50:36 +0000
216+++ libcore/gof-file.c 2017-03-10 17:31:58 +0000
217@@ -144,8 +144,9 @@
218 if (file->directory != NULL) {
219 dir = gof_directory_async_cache_lookup (file->directory);
220 if (dir != NULL) {
221- if (!file->is_hidden || gof_preferences_get_default ()->pref_show_hidden_files)
222+ if (!file->is_hidden || gof_preferences_get_show_hidden_files (gof_preferences_get_default ())) {
223 g_signal_emit_by_name (dir, "icon_changed", file);
224+ }
225
226 g_object_unref (dir);
227 }
228@@ -695,7 +696,7 @@
229 _g_object_unref0 (file->pix);
230 /* make sure we always got a non null pixbuf of the specified size */
231 file->pix = gof_file_get_icon_pixbuf (file, size,
232- gof_preferences_get_default ()->pref_force_icon_size,
233+ gof_preferences_get_force_icon_size (gof_preferences_get_default ()),
234 GOF_FILE_ICON_FLAGS_USE_THUMBNAILS);
235 file->pix_size = size;
236 }
237@@ -1409,9 +1410,7 @@
238 g_return_val_if_fail (file != NULL, NULL);
239 g_return_val_if_fail (file->info != NULL, NULL);
240
241- return pf_file_utils_get_formatted_time_attribute_from_info (file->info,
242- attr,
243- gof_preferences_get_default ()->pref_date_format);
244+ return pf_file_utils_get_formatted_time_attribute_from_info (file->info, attr);
245 }
246
247
248
249=== modified file 'libcore/gof-preferences.vala'
250--- libcore/gof-preferences.vala 2017-02-10 19:35:18 +0000
251+++ libcore/gof-preferences.vala 2017-03-10 17:31:58 +0000
252@@ -23,57 +23,18 @@
253
254 public const string TAGS_COLORS[10] = { null, "#fce94f", "#fcaf3e", "#997666", "#8ae234", "#729fcf", "#ad7fa8", "#ef2929", "#d3d7cf", "#888a85" };
255
256- public bool pref_show_hidden_files = false;
257- public bool show_hidden_files {
258- get {
259- return pref_show_hidden_files;
260- }
261- set {
262- pref_show_hidden_files = value;
263- }
264- }
265-
266+ public bool show_hidden_files {get; set; default=false;}
267 public bool show_remote_thumbnails {set; get; default=false;}
268-
269- public bool pref_confirm_trash = true;
270- public bool confirm_trash {
271- get {
272- return pref_confirm_trash;
273- }
274- set {
275- pref_confirm_trash = value;
276- }
277- }
278-
279- public bool pref_force_icon_size = true;
280- public bool force_icon_size {
281- get {
282- return pref_force_icon_size;
283- }
284- set {
285- pref_force_icon_size = value;
286- }
287- }
288-
289- public string pref_date_format = "iso";
290- public string date_format {
291- get {
292- return pref_date_format;
293- }
294- set {
295- pref_date_format = value;
296- }
297- }
298-
299- public class Preferences () {
300-
301- }
302+ public bool confirm_trash {set; get; default=true;}
303+ public bool force_icon_size {set; get; default=true;}
304+ public string date_format {set; get; default="iso";}
305+ public string clock_format {set; get; default="24h";}
306
307 public static Preferences get_default () {
308- if (preferences != null)
309- return preferences;
310+ if (preferences == null) {
311+ preferences = new Preferences ();
312+ }
313
314- preferences = new Preferences ();
315 return preferences;
316 }
317 }
318
319=== modified file 'libcore/marlin-file-operations.c'
320--- libcore/marlin-file-operations.c 2017-02-10 19:35:18 +0000
321+++ libcore/marlin-file-operations.c 2017-03-10 17:31:58 +0000
322@@ -1361,7 +1361,7 @@
323 static gboolean
324 should_confirm_trash (void)
325 {
326- return gof_preferences_get_default ()->pref_confirm_trash;
327+ return gof_preferences_get_confirm_trash (gof_preferences_get_default ());
328 }
329
330 static gboolean
331
332=== modified file 'libwidgets/View/SearchResults.vala'
333--- libwidgets/View/SearchResults.vala 2017-01-13 13:31:06 +0000
334+++ libwidgets/View/SearchResults.vala 2017-03-10 17:31:58 +0000
335@@ -241,7 +241,7 @@
336 return;
337 }
338
339- var include_hidden = GOF.Preferences.get_default ().pref_show_hidden_files;
340+ var include_hidden = GOF.Preferences.get_default ().show_hidden_files;
341
342 display_count = 0;
343 directory_queue = new Gee.LinkedList<File> ();
344
345=== modified file 'plugins/pantheon-files-ctags/plugin.vala'
346--- plugins/pantheon-files-ctags/plugin.vala 2017-01-14 13:09:47 +0000
347+++ plugins/pantheon-files-ctags/plugin.vala 2017-03-10 17:31:58 +0000
348@@ -287,7 +287,7 @@
349 return_if_fail (file != null);
350
351 if (!ignore_dir && file.info != null &&
352- (!file.is_hidden || GOF.Preferences.get_default ().pref_show_hidden_files)) {
353+ (!file.is_hidden || GOF.Preferences.get_default ().show_hidden_files)) {
354
355 if (file.location.has_uri_scheme ("recent")) {
356 rreal_update_file_info_for_recent.begin (file, file.get_display_target_uri ());
357
358=== modified file 'src/Application.vala'
359--- src/Application.vala 2017-02-02 11:37:26 +0000
360+++ src/Application.vala 2017-03-10 17:31:58 +0000
361@@ -252,6 +252,7 @@
362 Preferences.marlin_icon_view_settings = new Settings ("org.pantheon.files.icon-view");
363 Preferences.marlin_list_view_settings = new Settings ("org.pantheon.files.list-view");
364 Preferences.marlin_column_view_settings = new Settings ("org.pantheon.files.column-view");
365+ Preferences.gnome_interface_settings = new Settings ("org.gnome.desktop.interface");
366
367 /* Bind settings with GOFPreferences */
368 Preferences.settings.bind ("show-hiddenfiles",
369@@ -264,6 +265,8 @@
370 GOF.Preferences.get_default (), "date-format", GLib.SettingsBindFlags.DEFAULT);
371 Preferences.settings.bind ("force-icon-size",
372 GOF.Preferences.get_default (), "force-icon-size", GLib.SettingsBindFlags.DEFAULT);
373+ Preferences.gnome_interface_settings.bind ("clock-format",
374+ GOF.Preferences.get_default (), "clock-format", GLib.SettingsBindFlags.GET);
375 }
376
377 private void open_windows (File[]? files) {
378
379=== modified file 'src/marlin-global-preferences.h'
380--- src/marlin-global-preferences.h 2017-02-10 19:35:18 +0000
381+++ src/marlin-global-preferences.h 2017-03-10 17:31:58 +0000
382@@ -21,12 +21,5 @@
383 GSettings *marlin_icon_view_settings;
384 GSettings *marlin_list_view_settings;
385 GSettings *marlin_column_view_settings;
386-GSettings *gnome_mouse_settings;
387-
388-#define MARLIN_PREFERENCES_DATE_FORMAT "date-format"
389-#define MARLIN_PREFERENCES_SIDEBAR_CAT_PERSONAL_EXPANDER "sidebar-cat-personal-expander"
390-#define MARLIN_PREFERENCES_SIDEBAR_CAT_DEVICES_EXPANDER "sidebar-cat-devices-expander"
391-#define MARLIN_PREFERENCES_SIDEBAR_CAT_NETWORK_EXPANDER "sidebar-cat-network-expander"
392-#define MARLIN_PREFERENCES_CONFIRM_TRASH "confirm-trash"
393-
394+GSettings *gnome_interface_settings;
395 #endif
396
397=== modified file 'src/marlin.vapi'
398--- src/marlin.vapi 2016-12-19 16:46:47 +0000
399+++ src/marlin.vapi 2017-03-10 17:31:58 +0000
400@@ -6,7 +6,7 @@
401 public GLib.Settings marlin_icon_view_settings;
402 public GLib.Settings marlin_list_view_settings;
403 public GLib.Settings marlin_column_view_settings;
404- public GLib.Settings gnome_mouse_settings;
405+ public GLib.Settings gnome_interface_settings;
406 }
407
408

Subscribers

People subscribed via source and target branches

to all changes: