From 8c4e88539f47d6e1ccc44d80717cf0034cf887ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 26 Feb 2026 15:37:16 -0800 Subject: [PATCH 1/5] Clean up drag n drop events --- core/Services/Calendar/EventStore.vala | 39 ++++++++++++++++++++-- src/Grid/EventButton.vala | 46 ++++++++++++++++---------- src/Grid/GridDay.vala | 24 ++++++++++++-- 3 files changed, 86 insertions(+), 23 deletions(-) diff --git a/core/Services/Calendar/EventStore.vala b/core/Services/Calendar/EventStore.vala index 171fd5f94..3850e2e22 100644 --- a/core/Services/Calendar/EventStore.vala +++ b/core/Services/Calendar/EventStore.vala @@ -37,9 +37,6 @@ public class Calendar.EventStore : Object { /* The start of week, ie. Monday=1 or Sunday=7 */ public GLib.DateWeekday week_starts_on { get; set; default = GLib.DateWeekday.MONDAY; } - /* The event that is currently dragged */ - public ECal.Component drag_component {get; set;} - /* Notifies when events are added, updated, or removed */ public signal void events_added (E.Source source, Gee.Collection events); public signal void events_updated (E.Source source, Gee.Collection events); @@ -278,6 +275,42 @@ public class Calendar.EventStore : Object { return events; } + private static int search_rid (ECal.Component a, string? rid) { + string? a_rid = a.get_recurid_as_string (); + if (a_rid == null && rid == null) { + return 0; + } + + return GLib.strcmp (a_rid, rid); + } + + public ECal.Component? get_event (string uid, string? rid) { + List clients = source_client.get_values (); + foreach (unowned ECal.Client client in clients) { + GLib.SList ecalcomps; + try { + client.get_objects_for_uid_sync (uid, out ecalcomps, null); + if (ecalcomps.length () > 0) { + unowned GLib.SList results = ecalcomps.search (rid, search_rid); + + if (results.length () > 0) { + unowned ECal.Component comp = results.data; + comp.set_data ("source", client.source); + return comp; + } else { + unowned ECal.Component comp = ecalcomps.data; + comp.set_data ("source", client.source); + return comp; + } + } + } catch (Error e) { + debug (e.message); + } + } + + return null; + } + //--- Helper Methods ---// /** Set the week_starts_on property: the first day of the week. diff --git a/src/Grid/EventButton.vala b/src/Grid/EventButton.vala index 98ad7119e..2c60c7282 100644 --- a/src/Grid/EventButton.vala +++ b/src/Grid/EventButton.vala @@ -9,6 +9,9 @@ public class Maya.View.EventButton : Gtk.Bin { public ECal.Component comp { get; construct set; } + private const Gtk.TargetEntry DND = {"text/uri-list", 0, 1}; + private const Gtk.TargetEntry DND2 = {"text/calendar", 0, 2}; + private Gtk.Revealer revealer; private Gtk.Label label; private Gtk.StyleContext grid_style_context; @@ -84,24 +87,9 @@ public class Maya.View.EventButton : Gtk.Bin { long_press_gesture.reset (); }); - Gtk.TargetEntry dnd = {"binary/calendar", 0, 0}; - Gtk.TargetEntry dnd2 = {"text/uri-list", 0, 0}; - Gtk.drag_source_set (event_box, Gdk.ModifierType.BUTTON1_MASK, {dnd, dnd2}, Gdk.DragAction.MOVE); - - event_box.drag_data_get.connect ( (ctx, sel, info, time) => { - Calendar.EventStore.get_default ().drag_component = comp; - unowned ICal.Component icalcomp = comp.get_icalcomponent (); - var ical_str = icalcomp.as_ical_string (); - sel.set_text (ical_str, ical_str.length); - try { - var path = GLib.Path.build_filename (GLib.Environment.get_tmp_dir (), icalcomp.get_summary () + ".ics"); - var file = File.new_for_path (path); - if (file.replace_contents (ical_str.data, null, false, FileCreateFlags.PRIVATE, null)) - sel.set_uris ({file.get_uri ()}); - } catch (Error e) { - critical (e.message); - } - }); + Gtk.drag_source_set (event_box, Gdk.ModifierType.BUTTON1_MASK, {DND, DND2}, Gdk.DragAction.MOVE); + + event_box.drag_data_get.connect (on_drag_data_get); E.Source source = comp.get_data ("source"); @@ -114,6 +102,28 @@ public class Maya.View.EventButton : Gtk.Bin { }); } + private void on_drag_data_get (Gtk.Widget widget, Gdk.DragContext context, Gtk.SelectionData selection_data, uint target_type, uint time) { + unowned ICal.Component icalcomp = comp.get_icalcomponent (); + switch (target_type) { + case 0: + var ical_str = comp.get_as_string (); + try { + var path = GLib.Path.build_filename (GLib.Environment.get_tmp_dir (), icalcomp.get_summary () + ".ics"); + var file = File.new_for_path (path); + if (file.replace_contents (ical_str.data, null, false, FileCreateFlags.PRIVATE, null)) { + selection_data.set_uris ({file.get_uri ()}); + } + } catch (Error e) { + critical (e.message); + } + break; + case 1: + var ical_str = icalcomp.as_ical_string (); + selection_data.set_text (ical_str, ical_str.length); + break; + }; + } + public string get_uid () { return comp.get_id ().get_uid (); } diff --git a/src/Grid/GridDay.vala b/src/Grid/GridDay.vala index 419cccc1a..0e034940f 100644 --- a/src/Grid/GridDay.vala +++ b/src/Grid/GridDay.vala @@ -91,9 +91,29 @@ public class Maya.View.GridDay : Gtk.EventBox { } public override void drag_data_received (Gdk.DragContext context, int x, int y, Gtk.SelectionData selection_data, uint info, uint time_) { + string? compid = (string) selection_data.get_data (); + if (compid == null) { + return; + } + + string uid; + string? rid = null; + if ("\n" in compid) { + var parts = compid.split ("\n", 2); + uid = parts[0]; + rid = parts[1]; + } else { + uid = compid; + } + var calmodel = Calendar.EventStore.get_default (); - var comp = calmodel.drag_component; - unowned ICal.Component icalcomp = comp.get_icalcomponent (); + ECal.Component? comp = calmodel.get_event (uid, rid); + + if (comp == null) { + return; + } + + unowned var icalcomp = comp.get_icalcomponent (); E.Source src = comp.get_data ("source"); var start = icalcomp.get_dtstart (); var end = icalcomp.get_dtend (); From ad8d764524dd0e9e63a825c3c12ec9c47cce00f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 26 Feb 2026 15:42:06 -0800 Subject: [PATCH 2/5] Don't invert stuff --- src/Grid/EventButton.vala | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Grid/EventButton.vala b/src/Grid/EventButton.vala index 2c60c7282..2121f4032 100644 --- a/src/Grid/EventButton.vala +++ b/src/Grid/EventButton.vala @@ -9,8 +9,8 @@ public class Maya.View.EventButton : Gtk.Bin { public ECal.Component comp { get; construct set; } - private const Gtk.TargetEntry DND = {"text/uri-list", 0, 1}; - private const Gtk.TargetEntry DND2 = {"text/calendar", 0, 2}; + private const Gtk.TargetEntry DND = {"binary/calendar", 0, 0}; + private const Gtk.TargetEntry DND2 = {"text/uri-list", 0, 1}; private Gtk.Revealer revealer; private Gtk.Label label; @@ -106,6 +106,10 @@ public class Maya.View.EventButton : Gtk.Bin { unowned ICal.Component icalcomp = comp.get_icalcomponent (); switch (target_type) { case 0: + var ical_str = icalcomp.as_ical_string (); + selection_data.set_text (ical_str, ical_str.length); + break; + case 1: var ical_str = comp.get_as_string (); try { var path = GLib.Path.build_filename (GLib.Environment.get_tmp_dir (), icalcomp.get_summary () + ".ics"); @@ -117,10 +121,6 @@ public class Maya.View.EventButton : Gtk.Bin { critical (e.message); } break; - case 1: - var ical_str = icalcomp.as_ical_string (); - selection_data.set_text (ical_str, ical_str.length); - break; }; } From cd088d825aebd3eded45f5523d844d650d7b6bd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 26 Feb 2026 15:45:33 -0800 Subject: [PATCH 3/5] Fix duplicate ical_str --- src/Grid/EventButton.vala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Grid/EventButton.vala b/src/Grid/EventButton.vala index 2121f4032..e225b8217 100644 --- a/src/Grid/EventButton.vala +++ b/src/Grid/EventButton.vala @@ -104,13 +104,12 @@ public class Maya.View.EventButton : Gtk.Bin { private void on_drag_data_get (Gtk.Widget widget, Gdk.DragContext context, Gtk.SelectionData selection_data, uint target_type, uint time) { unowned ICal.Component icalcomp = comp.get_icalcomponent (); + var ical_str = icalcomp.as_ical_string (); switch (target_type) { case 0: - var ical_str = icalcomp.as_ical_string (); selection_data.set_text (ical_str, ical_str.length); break; case 1: - var ical_str = comp.get_as_string (); try { var path = GLib.Path.build_filename (GLib.Environment.get_tmp_dir (), icalcomp.get_summary () + ".ics"); var file = File.new_for_path (path); From e7a0ede748bfff13e4fddba3b88263974a25242f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 26 Feb 2026 15:48:18 -0800 Subject: [PATCH 4/5] Revert all the other stuff --- core/Services/Calendar/EventStore.vala | 39 ++------------------------ src/Grid/GridDay.vala | 24 ++-------------- 2 files changed, 5 insertions(+), 58 deletions(-) diff --git a/core/Services/Calendar/EventStore.vala b/core/Services/Calendar/EventStore.vala index 3850e2e22..171fd5f94 100644 --- a/core/Services/Calendar/EventStore.vala +++ b/core/Services/Calendar/EventStore.vala @@ -37,6 +37,9 @@ public class Calendar.EventStore : Object { /* The start of week, ie. Monday=1 or Sunday=7 */ public GLib.DateWeekday week_starts_on { get; set; default = GLib.DateWeekday.MONDAY; } + /* The event that is currently dragged */ + public ECal.Component drag_component {get; set;} + /* Notifies when events are added, updated, or removed */ public signal void events_added (E.Source source, Gee.Collection events); public signal void events_updated (E.Source source, Gee.Collection events); @@ -275,42 +278,6 @@ public class Calendar.EventStore : Object { return events; } - private static int search_rid (ECal.Component a, string? rid) { - string? a_rid = a.get_recurid_as_string (); - if (a_rid == null && rid == null) { - return 0; - } - - return GLib.strcmp (a_rid, rid); - } - - public ECal.Component? get_event (string uid, string? rid) { - List clients = source_client.get_values (); - foreach (unowned ECal.Client client in clients) { - GLib.SList ecalcomps; - try { - client.get_objects_for_uid_sync (uid, out ecalcomps, null); - if (ecalcomps.length () > 0) { - unowned GLib.SList results = ecalcomps.search (rid, search_rid); - - if (results.length () > 0) { - unowned ECal.Component comp = results.data; - comp.set_data ("source", client.source); - return comp; - } else { - unowned ECal.Component comp = ecalcomps.data; - comp.set_data ("source", client.source); - return comp; - } - } - } catch (Error e) { - debug (e.message); - } - } - - return null; - } - //--- Helper Methods ---// /** Set the week_starts_on property: the first day of the week. diff --git a/src/Grid/GridDay.vala b/src/Grid/GridDay.vala index 0e034940f..419cccc1a 100644 --- a/src/Grid/GridDay.vala +++ b/src/Grid/GridDay.vala @@ -91,29 +91,9 @@ public class Maya.View.GridDay : Gtk.EventBox { } public override void drag_data_received (Gdk.DragContext context, int x, int y, Gtk.SelectionData selection_data, uint info, uint time_) { - string? compid = (string) selection_data.get_data (); - if (compid == null) { - return; - } - - string uid; - string? rid = null; - if ("\n" in compid) { - var parts = compid.split ("\n", 2); - uid = parts[0]; - rid = parts[1]; - } else { - uid = compid; - } - var calmodel = Calendar.EventStore.get_default (); - ECal.Component? comp = calmodel.get_event (uid, rid); - - if (comp == null) { - return; - } - - unowned var icalcomp = comp.get_icalcomponent (); + var comp = calmodel.drag_component; + unowned ICal.Component icalcomp = comp.get_icalcomponent (); E.Source src = comp.get_data ("source"); var start = icalcomp.get_dtstart (); var end = icalcomp.get_dtend (); From 2ee89955a2532a1ae5f083211a41bd5ccb89eab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 26 Feb 2026 15:49:41 -0800 Subject: [PATCH 5/5] Fix broken drag comp --- src/Grid/EventButton.vala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Grid/EventButton.vala b/src/Grid/EventButton.vala index e225b8217..52a5a5cd6 100644 --- a/src/Grid/EventButton.vala +++ b/src/Grid/EventButton.vala @@ -103,7 +103,9 @@ public class Maya.View.EventButton : Gtk.Bin { } private void on_drag_data_get (Gtk.Widget widget, Gdk.DragContext context, Gtk.SelectionData selection_data, uint target_type, uint time) { - unowned ICal.Component icalcomp = comp.get_icalcomponent (); + Calendar.EventStore.get_default ().drag_component = comp; + + unowned var icalcomp = comp.get_icalcomponent (); var ical_str = icalcomp.as_ical_string (); switch (target_type) { case 0: