Skip to content

Commit

Permalink
GTasks: only show due date (#204)
Browse files Browse the repository at this point in the history
* TaskRow: don't show time on gtasks tasks

* DateTimePopover: hide timepicker on gtasks tasks

Co-authored-by: Marco Betschart <email@marco.betschart.name>
  • Loading branch information
Marukesu and marbetschar authored Mar 18, 2021
1 parent 1453a34 commit 7156c73
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/TaskModel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public class Tasks.TaskModel : Object {
return false;
}

private string get_collection_backend_name (E.Source source, E.SourceRegistry registry) {
public string get_collection_backend_name (E.Source source, E.SourceRegistry registry) {
string? backend_name = null;

var collection_source = registry.find_extension (source, E.SOURCE_EXTENSION_COLLECTION);
Expand Down
14 changes: 13 additions & 1 deletion src/Widgets/DateTimePopover.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
public class Tasks.DateTimePopover : Tasks.EntryPopover<GLib.DateTime?> {
private Gtk.Calendar calendar;
private Granite.Widgets.TimePicker timepicker;
private Gtk.Revealer timepicker_revealer;

public DateTimePopover () {
Object (
Expand All @@ -39,6 +40,13 @@ public class Tasks.DateTimePopover : Tasks.EntryPopover<GLib.DateTime?> {
margin_top = 0
};

timepicker_revealer = new Gtk.Revealer () {
reveal_child = true,
margin = 0
};

timepicker_revealer.add (timepicker);

var today_separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL) {
margin_bottom = 3,
margin_top = 3
Expand All @@ -54,7 +62,7 @@ public class Tasks.DateTimePopover : Tasks.EntryPopover<GLib.DateTime?> {
grid.attach (today_button, 0, 0);
grid.attach (today_separator, 0, 1);
grid.attach (calendar, 0, 2);
grid.attach (timepicker, 0, 3);
grid.attach (timepicker_revealer, 0, 3);
grid.show_all ();

popover.add (grid);
Expand All @@ -66,6 +74,10 @@ public class Tasks.DateTimePopover : Tasks.EntryPopover<GLib.DateTime?> {
timepicker.time_changed.connect (on_timepicker_time_changed);
}

public void hide_timepicker () {
timepicker_revealer.reveal_child = false;
}

private void on_popover_show () {
var selected_datetime = value;
if (selected_datetime == null) {
Expand Down
47 changes: 34 additions & 13 deletions src/Widgets/TaskRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ public class Tasks.TaskRow : Gtk.ListBoxRow {
can_focus = false;
created = calcomponent_created (task);

// GTasks tasks only have date on due time, so only show the date
bool is_gtask = false;
E.SourceRegistry? registry = null;
try {
registry = Application.model.get_registry_sync ();
is_gtask = Application.model.get_collection_backend_name (source, registry) == "google";
} catch (Error e) {
warning ("unable to get the registry, assuming task is not from gtask");
}

icon = new Gtk.Image.from_icon_name ("list-add-symbolic", Gtk.IconSize.MENU);
icon.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL);

Expand All @@ -96,6 +106,10 @@ public class Tasks.TaskRow : Gtk.ListBoxRow {

due_datetime_popover = new Tasks.DateTimePopover ();

if (is_gtask) {
due_datetime_popover.hide_timepicker ();
}

due_datetime_popover_revealer = new Gtk.Revealer () {
margin_end = 6,
reveal_child = false,
Expand All @@ -113,20 +127,27 @@ public class Tasks.TaskRow : Gtk.ListBoxRow {
due_datetime_popover.get_style_context ().add_class ("error");
}

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")))
);

if (is_gtask) {
if (is_scheduled_view) {
return null;
} else {
return _("%s").printf (Tasks.Util.get_relative_date (value));
}
} 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")))
);
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")))
);
} 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")))
);
}
}
});

Expand Down

0 comments on commit 7156c73

Please sign in to comment.