Skip to content

Commit

Permalink
static h24 settings
Browse files Browse the repository at this point in the history
  • Loading branch information
marbetschar committed Sep 9, 2021
1 parent 6153822 commit 3eab0ad
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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 ();
}

Expand Down
5 changes: 4 additions & 1 deletion src/Widgets/ScheduledTaskListGrid.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

public class Tasks.Widgets.ScheduledTaskListGrid : Gtk.Grid {
private Gee.Collection<ECal.ClientView> views;
private string h24_clock_format;

/*
* We need to pass a valid S-expression as query to guarantee the callback events are fired.
Expand Down Expand Up @@ -65,6 +66,8 @@ public class Tasks.Widgets.ScheduledTaskListGrid : Gtk.Grid {
construct {
views = new Gee.ArrayList<ECal.ClientView> ((Gee.EqualDataFunc<ECal.ClientView>?) 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,
Expand Down Expand Up @@ -161,7 +164,7 @@ public class Tasks.Widgets.ScheduledTaskListGrid : Gtk.Grid {

private void on_tasks_added (Gee.Collection<ECal.Component> 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) => {
Expand Down
7 changes: 5 additions & 2 deletions src/Widgets/TaskListGrid.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -289,7 +292,7 @@ public class Tasks.Widgets.TaskListGrid : Gtk.Grid {

private void on_tasks_added (Gee.Collection<ECal.Component> 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) => {
Expand Down
18 changes: 8 additions & 10 deletions src/Widgets/TaskRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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")))
);
}
}
Expand Down

0 comments on commit 3eab0ad

Please sign in to comment.