From abd85b71acd21eb3c7d20b4d04c0d77511cc09c8 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Thu, 26 Nov 2026 10:23:59 +0100 Subject: feat(calendar): a dropped .ics opens the event editor, filled in A lone .ics dropped on the island's sliver goes to the calendar rather than the assistant canvas: the panel opens on the event's month with the new-event form filled from the file, for review before Save. The bubble says where the drop will go while the drag is over it. calctl gains `read FILE`, which returns the file's master VEVENT in the same shape as `get`, with no UID so saving creates a new event in the default calendar. A rule or alarm the form cannot express reads `none`: `custom` would tell apply() to keep what is there, and a new event has nothing there to keep. The drop no longer needs the assistant to be present for .ics files. Co-Authored-By: Claude Opus 5.5 --- desktop/island/ClockPill.qml | 1 + desktop/island/Island.qml | 20 +++++++++++++++----- desktop/island/README.md | 6 ++++++ desktop/island/calendar/Calendar.qml | 1 + desktop/island/calendar/CalendarPanel.qml | 13 +++++++++++++ desktop/island/calendar/calctl | 27 ++++++++++++++++++++++++++- desktop/island/calendar/test_calctl.py | 25 +++++++++++++++++++++++++ 7 files changed, 87 insertions(+), 6 deletions(-) diff --git a/desktop/island/ClockPill.qml b/desktop/island/ClockPill.qml index 1d18503..9677508 100644 --- a/desktop/island/ClockPill.qml +++ b/desktop/island/ClockPill.qml @@ -40,6 +40,7 @@ Capsule { // Escape asks the panel before closing it. function focusPanel() { calendarPanel.reset(); calendarPanel.forceActiveFocus(); } function back() { return calendarPanel.back(); } + function importFile(path) { calendarPanel.importFile(path); } readonly property var entry: flickApp ? DesktopEntries.heuristicLookup(flickApp) : null readonly property string wsIcon: Workspaces.icon(flickWs) diff --git a/desktop/island/Island.qml b/desktop/island/Island.qml index f11225b..decde30 100644 --- a/desktop/island/Island.qml +++ b/desktop/island/Island.qml @@ -233,10 +233,13 @@ PanelWindow { // --- file drop --------------------------------------------------------- // A file dragged onto the sliver opens a bubble to drop it on; the drop - // hands it to the assistant canvas. Wayland reports a drag only once it + // hands it to the assistant canvas, or a lone .ics to the calendar's + // editor, filled in for review. Wayland reports a drag only once it // enters an input region, so the receptor is the sliver's width at rest // and grows to hold the bubble while a drag is over it. property bool dropHold: false + property bool dropIcs: false // a lone .ics: the calendar takes it + function isIcs(urls) { return urls.length === 1 && /\.ics$/i.test(String(urls[0])); } // Why the last drop was refused, shown in the bubble for a moment. property string dropNote: "" Timer { id: noteTimer; interval: 2500; onTriggered: win.dropNote = "" } @@ -252,9 +255,10 @@ PanelWindow { DropArea { anchors.fill: parent - enabled: win.asst !== null onEntered: drag => { - drag.accepted = drag.hasUrls && (drag.supportedActions & Qt.CopyAction); + win.dropIcs = win.isIcs(drag.urls); + drag.accepted = drag.hasUrls && (drag.supportedActions & Qt.CopyAction) + && (win.dropIcs || win.asst !== null); if (drag.accepted) { win.dropHold = true; drag.accept(Qt.CopyAction); } } onExited: win.dropHold = false @@ -275,7 +279,13 @@ PanelWindow { drop.accepted = false; return; } - win.asst.attach(paths); + if (win.isIcs(paths)) { + win.shown = true; + win.panel = "calendar"; + clock.importFile(paths[0]); + } else { + win.asst.attach(paths); + } drop.accept(Qt.CopyAction); } } @@ -291,7 +301,7 @@ PanelWindow { border.color: Qt.alpha(win.dropHold ? Theme.accent : Theme.red, 0.6) Text { anchors.centerIn: parent - text: win.dropHold ? "Drop for the assistant" : win.dropNote + text: !win.dropHold ? win.dropNote : win.dropIcs ? "Drop to add to the calendar" : "Drop for the assistant" color: win.dropHold ? Theme.text : Theme.red font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 2 } } diff --git a/desktop/island/README.md b/desktop/island/README.md index 1b1a3f2..03f7201 100644 --- a/desktop/island/README.md +++ b/desktop/island/README.md @@ -184,3 +184,9 @@ width at rest and grows to hold the bubble while a drag is over it. Only `file://` URLs are taken; a refused drop says why in the bubble for a moment. The file manager offers a trashed file as a `trash:` URL, which has no path to read: restore it first. + +A lone `.ics` file goes to the calendar instead, and the bubble says so: +the panel opens on the event's month with the editor filled from the file +by `calctl read`, in the default calendar, and nothing is written until +Save. A repeat rule or alarm the form cannot show reads `none`, since a new +event has nothing of its own to keep. diff --git a/desktop/island/calendar/Calendar.qml b/desktop/island/calendar/Calendar.qml index 4a5e7d4..5431ad1 100644 --- a/desktop/island/calendar/Calendar.qml +++ b/desktop/island/calendar/Calendar.qml @@ -53,6 +53,7 @@ Singleton { // `cal` is the calendar the event is in now: one UID can be in two. function get(uid, cal, cb) { root.run(["get", uid, cal], cb); } + function read(file, cb) { root.run(["read", file], cb); } function create(event, cb) { root.run(["new", JSON.stringify(event)], cb); } function update(uid, cal, event, cb) { root.run(["edit", uid, cal, JSON.stringify(event)], cb); } function remove(uid, cal, cb) { root.run(["delete", uid, cal], cb); } diff --git a/desktop/island/calendar/CalendarPanel.qml b/desktop/island/calendar/CalendarPanel.qml index fef672c..cea3898 100644 --- a/desktop/island/calendar/CalendarPanel.qml +++ b/desktop/island/calendar/CalendarPanel.qml @@ -86,6 +86,19 @@ Item { panel.editing = true; } + // A dropped .ics: the editor, filled from it, on its month. Nothing is + // saved until Save. + function importFile(path) { + Calendar.read(path, r => { + if (!r.ok) { panel.agendaError = r.error; return; } + const d = Cal.fromEvent(r.data); + panel.selected = d.startDay; + panel.show(+d.startDay.slice(0, 4), +d.startDay.slice(5, 7) - 1); + editor.load(d); + panel.editing = true; + }); + } + function closeEditor() { panel.editing = false; panel.forceActiveFocus(); diff --git a/desktop/island/calendar/calctl b/desktop/island/calendar/calctl index ce98098..a28b20a 100755 --- a/desktop/island/calendar/calctl +++ b/desktop/island/calendar/calctl @@ -18,6 +18,7 @@ # calctl calendars {default, calendars: [{name, color, path}]} # calctl list FROM TO occurrences in [FROM, TO), local time # calctl get UID CAL the series itself, for the editor +# calctl read FILE an outside .ics as a new event, for the editor # calctl new EVENT-JSON {uid} # calctl edit UID CAL EVENT-JSON {uid}; CAL is where it is now # calctl delete UID CAL {} @@ -61,7 +62,7 @@ COLORS = { "cyan": "teal", "dark cyan": "teal", "light cyan": "teal", } -USAGE = ("usage: calctl calendars | list FROM TO | get UID CAL | new JSON" +USAGE = ("usage: calctl calendars | list FROM TO | get UID CAL | read FILE | new JSON" " | edit UID CAL JSON | delete UID CAL") @@ -293,6 +294,28 @@ def cmd_get(uid, cal_name): return to_json(cal, ev, start, end, all_day, overrides()) +def cmd_read(file): + """A dropped .ics (an invite, a booking) as a draft for the editor: no + UID, so saving creates a new event in the default calendar. A rule or + alarm the form cannot show reads `none`: a new event has nothing to keep.""" + try: + ev = master(icalendar.Calendar.from_ical(Path(file).read_bytes())) + except OSError as e: + raise Fail(f"cannot read {file}: {e.strerror}") + except ValueError as e: + raise Fail(f"not a calendar file: {e}") + if ev is None or "DTSTART" not in ev: + raise Fail("no event in that file") + cals, default = calendars() + cal = next(c for c in cals if c["name"] == default) + d = to_json(cal, ev, *span(ev), set()) + d["uid"] = "" + for key in ("repeat", "alarm"): + if d[key] == "custom": + d[key] = "none" + return d + + def parse_payload(text, cals): """The form's JSON, checked. Dates become date/datetime; an all-day end becomes exclusive.""" @@ -470,6 +493,8 @@ def main(argv): data = cmd_list(*args) elif cmd == "get" and len(args) == 2: data = cmd_get(*args) + elif cmd == "read" and len(args) == 1: + data = cmd_read(*args) elif cmd == "new" and len(args) == 1: data = cmd_new(*args) elif cmd == "edit" and len(args) == 3: diff --git a/desktop/island/calendar/test_calctl.py b/desktop/island/calendar/test_calctl.py index 91ad384..e6b3da2 100644 --- a/desktop/island/calendar/test_calctl.py +++ b/desktop/island/calendar/test_calctl.py @@ -290,5 +290,30 @@ assert "json" in run("new", "{not json", ok=False) assert sorted(p.name for p in tmp.rglob("*.ics")) == before no_temp() +# read: an outside .ics as a new draft in the default calendar, nothing written. +put(tmp / "invite.ics", """ +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//test//EN +BEGIN:VEVENT +UID:invite-1 +DTSTAMP:20260101T000000Z +DTSTART:20261203T140000Z +DTEND:20261203T153000Z +SUMMARY:Dentist +LOCATION:Main St 1 +RRULE:FREQ=WEEKLY;BYDAY=TH +END:VEVENT +END:VCALENDAR +""") +before = sorted(p.name for p in tmp.rglob("*.ics")) +r = run("read", str(tmp / "invite.ics")) +assert (r["uid"], r["calendar"], r["title"], r["location"]) == ("", "home", "Dentist", "Main St 1"), r +assert (r["start"], r["end"], r["allDay"], r["repeat"]) == ("2026-12-03T15:00", "2026-12-03T16:30", False, "none"), r +assert sorted(p.name for p in tmp.rglob("*.ics")) == before +put(tmp / "bad.ics", "hello") +assert "not a calendar" in run("read", str(tmp / "bad.ics"), ok=False) +assert "cannot read" in run("read", str(tmp / "missing.ics"), ok=False) + shutil.rmtree(tmp) print("test_calctl: ok") -- cgit v1.2.3