Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GTasks: only show due date #204

Merged
merged 3 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
marbetschar marked this conversation as resolved.
Show resolved Hide resolved
} 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