diff --git a/src/Application.vala b/src/Application.vala index 323efdc661..dd20a81ff6 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -20,6 +20,7 @@ public class Tasks.Application : Gtk.Application { public static GLib.Settings settings; + public static GLib.Settings h24_settings; public static Tasks.TaskModel model; public Application () { @@ -31,6 +32,7 @@ public class Tasks.Application : Gtk.Application { static construct { settings = new Settings ("io.elementary.tasks"); + h24_settings = new GLib.Settings ("org.gnome.desktop.interface"); model = new Tasks.TaskModel (); } diff --git a/src/Widgets/ScheduledTaskListGrid.vala b/src/Widgets/ScheduledTaskListGrid.vala index d591bcbdcf..ce1e350299 100644 --- a/src/Widgets/ScheduledTaskListGrid.vala +++ b/src/Widgets/ScheduledTaskListGrid.vala @@ -20,6 +20,7 @@ public class Tasks.Widgets.ScheduledTaskListGrid : Gtk.Grid { private Gee.Collection views; + private string h24_clock_format; /* * We need to pass a valid S-expression as query to guarantee the callback events are fired. @@ -65,6 +66,8 @@ public class Tasks.Widgets.ScheduledTaskListGrid : Gtk.Grid { construct { views = new Gee.ArrayList ((Gee.EqualDataFunc?) direct_equal); + h24_clock_format = Application.h24_settings.get_string ("clock-format"); + scheduled_title = new Gtk.Label (_("Scheduled")) { ellipsize = Pango.EllipsizeMode.END, margin_start = 24, @@ -161,7 +164,7 @@ public class Tasks.Widgets.ScheduledTaskListGrid : Gtk.Grid { private void on_tasks_added (Gee.Collection tasks, E.Source source) { tasks.foreach ((task) => { - var task_row = new Tasks.Widgets.TaskRow.for_component (task, source, true); + var task_row = new Tasks.Widgets.TaskRow.for_component (task, source, h24_clock_format, true); task_row.unselect.connect (on_row_unselect); task_row.task_completed.connect ((task) => { diff --git a/src/Widgets/TaskListGrid.vala b/src/Widgets/TaskListGrid.vala index 67c3a7e74a..4ca4a4cccb 100644 --- a/src/Widgets/TaskListGrid.vala +++ b/src/Widgets/TaskListGrid.vala @@ -26,12 +26,15 @@ public class Tasks.Widgets.TaskListGrid : Gtk.Grid { private Gtk.ListBox add_task_list; private Gtk.ListBox task_list; private bool is_gtasks; + private string h24_clock_format; public TaskListGrid (E.Source source) { Object (source: source); } construct { + h24_clock_format = Application.h24_settings.get_string ("clock-format"); + try { view = Tasks.Application.model.create_task_list_view ( source, @@ -85,7 +88,7 @@ public class Tasks.Widgets.TaskListGrid : Gtk.Grid { }; add_task_list.get_style_context ().add_class (Gtk.STYLE_CLASS_BACKGROUND); - var add_task_row = new Tasks.Widgets.TaskRow.for_source (source); + var add_task_row = new Tasks.Widgets.TaskRow.for_source (source, h24_clock_format); add_task_row.unselect.connect (on_row_unselect); add_task_row.task_changed.connect ((task) => { @@ -289,7 +292,7 @@ public class Tasks.Widgets.TaskListGrid : Gtk.Grid { private void on_tasks_added (Gee.Collection tasks, E.Source source) { tasks.foreach ((task) => { - var task_row = new Tasks.Widgets.TaskRow.for_component (task, source, false); + var task_row = new Tasks.Widgets.TaskRow.for_component (task, source, h24_clock_format, false); task_row.unselect.connect (on_row_unselect); task_row.task_completed.connect ((task) => { diff --git a/src/Widgets/TaskRow.vala b/src/Widgets/TaskRow.vala index 3114470cd3..d2f83811c7 100644 --- a/src/Widgets/TaskRow.vala +++ b/src/Widgets/TaskRow.vala @@ -28,6 +28,7 @@ public class Tasks.Widgets.TaskRow : Gtk.ListBoxRow { public bool completed { get; private set; } public E.Source source { get; construct; } public ECal.Component task { get; construct set; } + public string h24_clock_format { get; construct; } public bool is_scheduled_view { get; construct; } private bool created; @@ -52,19 +53,19 @@ public class Tasks.Widgets.TaskRow : Gtk.ListBoxRow { private static Gtk.CssProvider taskrow_provider; - private TaskRow (ECal.Component task, E.Source source) { - Object (task: task, source: source); + private TaskRow (ECal.Component task, E.Source source, string h24_clock_format) { + Object (task: task, source: source, h24_clock_format: h24_clock_format); } - public TaskRow.for_source (E.Source source) { + public TaskRow.for_source (E.Source source, string h24_clock_format) { var task = new ECal.Component (); task.set_new_vtype (ECal.ComponentVType.TODO); Object (task: task, source: source); } - public TaskRow.for_component (ECal.Component task, E.Source source, bool is_scheduled_view = false) { - Object (source: source, task: task, is_scheduled_view: is_scheduled_view); + public TaskRow.for_component (ECal.Component task, E.Source source, string h24_clock_format, bool is_scheduled_view = false) { + Object (source: source, task: task, h24_clock_format: h24_clock_format, is_scheduled_view: is_scheduled_view); } static construct { @@ -135,18 +136,15 @@ public class Tasks.Widgets.TaskRow : Gtk.ListBoxRow { return _("%s").printf (Tasks.Util.get_relative_date (value)); } } else { - var h24_settings = new GLib.Settings ("org.gnome.desktop.interface"); - var format = h24_settings.get_string ("clock-format"); - if (is_scheduled_view) { return _("%s").printf ( - value.format (Granite.DateTime.get_default_time_format (format.contains ("12h"))) + value.format (Granite.DateTime.get_default_time_format (h24_clock_format.contains ("12h"))) ); } else { ///TRANSLATORS: Represents due date and time of a task, e.g. "Tomorrow at 9:00 AM" return _("%s at %s").printf ( Tasks.Util.get_relative_date (value), - value.format (Granite.DateTime.get_default_time_format (format.contains ("12h"))) + value.format (Granite.DateTime.get_default_time_format (h24_clock_format.contains ("12h"))) ); } }