Skip to content

Commit

Permalink
CalDAV repeat support
Browse files Browse the repository at this point in the history
  • Loading branch information
alainm23 committed Feb 17, 2024
1 parent 94414f6 commit cb4d6de
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 38 deletions.
38 changes: 16 additions & 22 deletions core/Objects/Item.vala
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@ public class Objects.Item : Objects.BaseObject {
GXml.DomElement propstat = element.get_elements_by_tag_name ("d:propstat").get_element (0);
GXml.DomElement prop = propstat.get_elements_by_tag_name ("d:prop").get_element (0);
string data = prop.get_elements_by_tag_name ("cal:calendar-data").get_element (0).text_content;
string etag = prop.get_elements_by_tag_name ("d:getetag").get_element (0).text_content;

patch_from_caldav_xml (element);

Expand All @@ -376,7 +375,6 @@ public class Objects.Item : Objects.BaseObject {
GXml.DomElement propstat = element.get_elements_by_tag_name ("d:propstat").get_element (0);
GXml.DomElement prop = propstat.get_elements_by_tag_name ("d:prop").get_element (0);
string data = prop.get_elements_by_tag_name ("cal:calendar-data").get_element (0).text_content;
string etag = prop.get_elements_by_tag_name ("d:getetag").get_element (0).text_content;

patch_from_caldav_xml (element);

Expand Down Expand Up @@ -420,19 +418,7 @@ public class Objects.Item : Objects.BaseObject {

var rrules = Util.find_string_value ("RRULE", data);
if (rrules != "") {
ICal.Recurrence recurrence = new ICal.Recurrence.from_string (rrules);
ICal.RecurrenceFrequency freq = recurrence.get_freq ();
short interval = recurrence.get_interval ();
int count = recurrence.get_count ();
GLib.Array<short> get_by_day_array = recurrence.get_by_day_array ();

print ("freq: %s\n".printf (freq.to_string ()));
print ("interval: %s\n".printf (interval.to_string ()));
print ("count: %d\n".printf (count));

foreach (short day in get_by_day_array) {
print ("Short: %s\n", day.to_string ());
}
Utils.Datetime.recurrence_to_due (rrules, due);
}

parent_id = Util.find_string_value ("RELATED-TO", data);
Expand Down Expand Up @@ -1005,34 +991,42 @@ public class Objects.Item : Objects.BaseObject {
rrule.set_freq (ICal.RecurrenceFrequency.WEEKLY_RECURRENCE);

Array<short> values = new Array<short> ();
short val;

if (due.recurrency_weeks.split (",").length > 0) {
if (due.recurrency_weeks.contains ("1")) {
values.append_val (((short) "TU"));
val = (short) 2;
values.append_val (val);
}

if (due.recurrency_weeks.contains ("2")) {
// values.append_val ((short) "TU");
val = (short) 3;
values.append_val (val);
}

if (due.recurrency_weeks.contains ("3")) {
// values.append_val ((short) "WE");
val = (short) 4;
values.append_val (val);
}

if (due.recurrency_weeks.contains ("4")) {
// values.append_val ((short) "TH");
val = (short) 5;
values.append_val (val);
}

if (due.recurrency_weeks.contains ("5")) {
// values.append_val ((short) "FR");
val = (short) 6;
values.append_val (val);
}

if (due.recurrency_weeks.contains ("6")) {
// values.append_val ((short) "SA");
val = (short) 7;
values.append_val (val);
}

if (due.recurrency_weeks.contains ("7")) {
// values.append_val ((short) "SU");
val = (short) 1;
values.append_val (val);
}
}

Expand Down
6 changes: 6 additions & 0 deletions core/Objects/Project.vala
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ public class Objects.Project : Objects.BaseObject {
}
}

public bool is_deck {
get {
return id.contains ("deck--board");
}
}

public signal void loading_changed (bool value);
public signal void project_count_updated ();
public signal void show_multi_select_change ();
Expand Down
86 changes: 86 additions & 0 deletions core/Util/Datetime.vala
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,90 @@ public class Utils.Datetime {
public static GLib.DateTime get_date_from_string (string date) {
return new GLib.DateTime.from_iso8601 (date, new GLib.TimeZone.local ());
}

public static void recurrence_to_due (string rrules, Objects.DueDate due) {
ICal.Recurrence recurrence = new ICal.Recurrence.from_string (rrules);

due.is_recurring = true;

ICal.RecurrenceFrequency freq = recurrence.get_freq ();
if (freq == ICal.RecurrenceFrequency.MINUTELY_RECURRENCE) {
due.recurrency_type = RecurrencyType.MINUTELY;
} else if (freq == ICal.RecurrenceFrequency.HOURLY_RECURRENCE) {
due.recurrency_type = RecurrencyType.HOURLY;
} else if (freq == ICal.RecurrenceFrequency.DAILY_RECURRENCE) {
due.recurrency_type = RecurrencyType.EVERY_DAY;
} else if (freq == ICal.RecurrenceFrequency.WEEKLY_RECURRENCE) {
due.recurrency_type = RecurrencyType.EVERY_WEEK;
} else if (freq == ICal.RecurrenceFrequency.MONTHLY_RECURRENCE) {
due.recurrency_type = RecurrencyType.EVERY_MONTH;
} else if (freq == ICal.RecurrenceFrequency.YEARLY_RECURRENCE) {
due.recurrency_type = RecurrencyType.EVERY_YEAR;
}

short interval = recurrence.get_interval ();
due.recurrency_interval = (int) interval;

int count = recurrence.get_count ();
due.recurrency_count = count;

ICal.Time until = recurrence.get_until ();
if (!until.is_null_time ()) {
due.recurrency_end = Util.ical_to_date_time_local (until).to_string ();
}

if (due.recurrency_type == RecurrencyType.EVERY_WEEK) {
string recurrency_weeks = "";
GLib.Array<short> day_array = recurrence.get_by_day_array ();

if (check_by_day ("1", day_array)) {
recurrency_weeks += "7,";
}

if (check_by_day ("2", day_array)) {
recurrency_weeks += "1,";
}


if (check_by_day ("3", day_array)) {
recurrency_weeks += "2,";
}


if (check_by_day ("4", day_array)) {
recurrency_weeks += "3,";
}


if (check_by_day ("5", day_array)) {
recurrency_weeks += "4,";
}


if (check_by_day ("6", day_array)) {
recurrency_weeks += "5,";
}


if (check_by_day ("7", day_array)) {
recurrency_weeks += "6,";
}

if (recurrency_weeks.split (",").length > 0) {
recurrency_weeks.slice (0, -1);
}

due.recurrency_weeks = recurrency_weeks;
}
}

private static bool check_by_day (string day, GLib.Array<short> day_array) {
foreach (var _day in day_array) {
if (_day.to_string () == day) {
return true;
}
}

return false;
}
}
1 change: 1 addition & 0 deletions src/Dialogs/RepeatConfig.vala
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public class Dialogs.RepeatConfig : Adw.Window {
hexpand = true,
selected = 0,
valign = CENTER,
selected = 2
};

var repeat_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6) {
Expand Down
20 changes: 10 additions & 10 deletions src/Layouts/ItemRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public class Layouts.ItemRow : Layouts.ItemBase {
content_textview = new Widgets.TextView ();
content_textview.wrap_mode = Gtk.WrapMode.WORD;
content_textview.buffer.text = item.content;
content_textview.editable = !item.completed;
content_textview.editable = !item.completed && !item.project.is_deck;
content_textview.remove_css_class ("view");
content_textview.add_css_class ("font-bold");

Expand Down Expand Up @@ -353,7 +353,7 @@ public class Layouts.ItemRow : Layouts.ItemBase {
bottom_margin = 12,
wrap_mode = Gtk.WrapMode.WORD_CHAR,
hexpand = true,
editable = !item.completed
editable = !item.completed && !item.project.is_deck
};

description_textview.remove_css_class ("view");
Expand All @@ -368,7 +368,7 @@ public class Layouts.ItemRow : Layouts.ItemBase {

item_labels = new Widgets.ItemLabels (item) {
margin_start = 24,
sensitive = !item.completed
sensitive = !item.completed && !item.project.is_deck
};

schedule_button = new Widgets.ScheduleButton ();
Expand Down Expand Up @@ -401,7 +401,7 @@ public class Layouts.ItemRow : Layouts.ItemBase {
margin_start = 16,
margin_top = 6,
hexpand = true,
sensitive = !item.completed
sensitive = !item.completed && !item.project.is_deck
};

var action_box_right = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0) {
Expand Down Expand Up @@ -495,7 +495,7 @@ public class Layouts.ItemRow : Layouts.ItemBase {
child = main_revealer;
update_request ();

if (!item.checked) {
if (!item.checked && !item.project.is_deck) {
build_drag_and_drop ();
}

Expand Down Expand Up @@ -614,7 +614,7 @@ public class Layouts.ItemRow : Layouts.ItemBase {
menu_handle_gesture.set_button (3);
itemrow_box.add_controller (menu_handle_gesture);
menu_handle_gesture.pressed.connect ((n_press, x, y) => {
if (!item.completed) {
if (!item.completed && !item.project.is_deck) {
build_handle_context_menu (x, y);
}
});
Expand Down Expand Up @@ -740,10 +740,10 @@ public class Layouts.ItemRow : Layouts.ItemBase {
}

if (edit) {
content_textview.editable = !item.completed;
description_textview.editable = !item.completed;
item_labels.sensitive = !item.completed;
action_box.sensitive = !item.completed;
content_textview.editable = !item.completed && !item.project.is_deck;
description_textview.editable = !item.completed && !item.project.is_deck;
item_labels.sensitive = !item.completed && !item.project.is_deck;
action_box.sensitive = !item.completed && !item.project.is_deck;
}
}

Expand Down
12 changes: 9 additions & 3 deletions src/Layouts/ProjectRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,11 @@ public class Layouts.ProjectRow : Gtk.ListBoxRow {
var menu_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
menu_box.margin_top = menu_box.margin_bottom = 3;
menu_box.append (favorite_item);
menu_box.append (edit_item);

if (!project.is_deck) {
menu_box.append (edit_item);
}

if (project.backend_type == BackendType.CALDAV) {
menu_box.append (refresh_item);
}
Expand All @@ -618,8 +622,10 @@ public class Layouts.ProjectRow : Gtk.ListBoxRow {

if (project.id != Services.Settings.get_default ().settings.get_string ("todoist-inbox-project-id") &&
project.id != Services.Settings.get_default ().settings.get_string ("local-inbox-project-id")) {
menu_box.append (new Widgets.ContextMenu.MenuSeparator ());
menu_box.append (delete_item);
if (!project.is_deck) {
menu_box.append (new Widgets.ContextMenu.MenuSeparator ());
menu_box.append (delete_item);
}
}

menu_popover = new Gtk.Popover () {
Expand Down
15 changes: 12 additions & 3 deletions src/Views/Project/Project.vala
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ public class Views.Project : Gtk.Grid {
var headerbar = new Layouts.HeaderBar ();
headerbar.title = project.name;

headerbar.pack_end (menu_button);
if (!project.is_deck) {
headerbar.pack_end (menu_button);
}

headerbar.pack_end (view_setting_overlay);

view_stack = new Gtk.Stack () {
Expand All @@ -101,7 +104,10 @@ public class Views.Project : Gtk.Grid {
};

content_overlay.child = content_box;
content_overlay.add_overlay (magic_button);

if (!project.is_deck) {
content_overlay.add_overlay (magic_button);
}

multiselect_toolbar = new Widgets.MultiSelectToolbar (project);

Expand Down Expand Up @@ -196,6 +202,10 @@ public class Views.Project : Gtk.Grid {
}

public void prepare_new_item (string content = "") {
if (project.is_deck) {
return;
}

if (project.view_style == ProjectViewStyle.LIST) {
Views.List? list_view;
list_view = (Views.List) view_stack.get_child_by_name (project.view_style.to_string ());
Expand Down Expand Up @@ -226,7 +236,6 @@ public class Views.Project : Gtk.Grid {

var menu_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
menu_box.margin_top = menu_box.margin_bottom = 3;

if (!project.is_inbox_project) {
menu_box.append (edit_item);
menu_box.append (schedule_item);
Expand Down

0 comments on commit cb4d6de

Please sign in to comment.