Commit Graph
102 Commits
Author SHA1 Message Date
Georges Basile Stavracas Neto e90c67a57d manager: Ensure default calendar property is always set 2021-08-16 15:26:59 -03:00
Sebastian Keller af7a17ef01 event: Fix multiday detection for all-day events
All-day events always use UTC, so when the multiday detection code was
converting them to the local timezone, they span an additional day if
the local timezone is not the same as UTC. This was leading to all-day
events always being considered multiday events.

Fix this by ignoring the timezone for all-day events, like all other
comparisons do. Also don't consider all-day events spanning 1 day to be
multiday since as per RFC 5545 the end date is non-inclusive and if
omitted to be start + 1 day.
2021-05-11 19:35:31 +00:00
Sebastian Keller 44e2420645 range: Handle zero-length ranges when calculating overlap
Zero length ranges, such as for events without a DTEND could be
considered to overlap a range if they were at exactly the end of the
range. The end of a range however is the first date that is supposed to
not overlap, so a zero-length range on exactly this point should not be
considered overlapping.

This fixes cases where all-day events from the next month could show up
on the same day of the current month if they did not have a DTEND.

This also adds tests for all possible cases of such zero-length events
overlapping.

Fixes https://gitlab.gnome.org/GNOME/gnome-calendar/-/issues/701
2021-04-21 13:59:26 +00:00
Sebastian Keller fb242dd109 time-zone-monitor: Use local timezone as fallback without dbus service
On systems without anything providing the org.freedesktop.timedate1
interface, the timezone returned by the monitor would always be NULL,
because it was never set. This can lead to crashes in places that expect
the monitor to always return a valid timezone. So in that case use the
local timezone from when the monitor got initialized.

Fixes https://gitlab.gnome.org/GNOME/gnome-calendar/-/issues/703
2021-04-11 00:27:08 +00:00
Sebastian Keller a0d24cd5d8 time-zone-monitor: Fix timezone leak on timezone changes
The old timezone was never being unref'ed before it got overwritten.
2021-04-11 00:27:08 +00:00
Georges Basile Stavracas Neto d1a0dbd8f5 event: Switch to g_time_zone_new_identifier()
And add the relevant NULL checks here.
2021-02-26 19:26:49 -03:00
Georges Basile Stavracas Neto 27c6d2c017 time-zone-monitor: Switch to g_time_zone_new_identifier()
We don't even need to check for NULL here because if the system timezone
is invalid, we're too screwed to have a fallback path anyway.
2021-02-26 19:26:49 -03:00
Georges Basile Stavracas Neto a146b9050d project: Silence CI warnings 2020-10-31 16:55:06 -03:00
Georges Basile Stavracas Neto eb954505e4 project: Split meson files in subdirs
It allows us to better control what each subdir does, etc. This is
only the first step; we want to also split GResources, etc.
2020-10-30 13:45:50 -03:00
Michael Catanzaro 9ac1528e54 gcal-timeline: completed_calendars should be unsigned
In on_calendar_monitor_completed_cb() we have this assert:

g_assert (self->completed_calendars <= g_hash_table_size (self->calendars));

That is comparing a signed integer to unsigned. This is dangerous. We
could add casts to say that we really want to do it, but
completed_calendars should never be negative, so might as well use
unsigned.
2020-10-14 09:14:34 -05:00
Michael Catanzaro c2c89b667e gcal-timeline: never reset completed_calendars
Since 78cb11c64d, GcalCalendarMonitor now
notifies when a completed calendar transitions to incomplete, and
GcalTimeline decrements its completed_calendars counter. But we forgot
to remove the code that resets completed_calendars when previously
needed. That's not required anymore, because we can trust
GcalCalendarMonitor to do the right thing.

In my case, I have 5 calendars enabled and 6 total. When starting
gnome-calendar, all 5 are successively completed, and
completed_calendars increments from 0 -> 1 -> 2 -> 3 -> 4 -> 5. Then,
when transitioning month view from January 2020 to December 2019, we
call reset_completed_calendars() and completed_calenders gets clobbered
to 0. Then it decrements from 0 -> -1 -> -2 -> -3 -> -4 -> -5 as the
GcalCalendarMonitors notify that they are no longer completed. Well,
that is what would happen, if it didn't crash when decrementing to -1.
We assert -1 <= 6 (the total number of calendars) and crash because -1
gets promoted to a huge unsigned int, since we're comparing signed to
unsigned. (That crash would have been avoided if we used
-Wsign-compare, although that warning would not have caught the logic
problem.)

Anyway, since GcalMonitor now notifies when calendars are no longer
complete, it is safe to simply remove reset_completed_calendars().
GcalTimeline will still notify if it needs to change its own complete
property (in on_calendar_monitor_completed_cb).

Fixes #567
Fixes #636
Fixes #638
Fixes #647
Fixes #650
2020-10-14 09:13:12 -05:00
Yuri Edward 78cb11c64d calendar-monitor: Turn "completed" signal into a boolean property
And make GcalTimeline decrease the completed calendars counter when
any GcalCalendarMonitor goes from complete to incomplete.

Fixes https://gitlab.gnome.org/GNOME/gnome-calendar/-/issues/625
2020-08-17 15:59:33 -03:00
Georges Basile Stavracas Neto 158c65db4b event: Trivial cleanup
We can avoid a lookup by simply checking if the alarm id
isn't NULL.
2020-06-17 21:24:36 -03:00
Georges Basile Stavracas Neto 4b6a559924 manager: Assert that cloning was successful
Cloning an ECalComponent can fail, and we need to be able to
catch these failures.

Assert that cloning was successful before procceeding with
the move.
2020-06-17 21:24:36 -03:00
Georges Basile Stavracas Neto c1ec9e734b event: Commit component more often
GcalEvent was mising many points where committing the component
is required. Commit the component more often.

https://gitlab.gnome.org/GNOME/gnome-calendar/-/issues/620
2020-06-17 21:24:36 -03:00
Georges Basile Stavracas Neto dbd81f401c event: Add API to clone events
This will be useful for updating events without having
to keep track of the event states.

Add the new API, and also a unit test.
2020-06-15 13:07:48 -03:00
Georges Basile Stavracas Neto e5986a05c1 calendar-monitor: Use inclusive end date for ECalClientView
May prevent a few events from being transmitted.
2020-04-16 16:31:36 -03:00
Georges Basile Stavracas Neto d2da70fb28 range: Properly compare ranges
The behavior of gcal_range_compare(), and the 'position' argument
of gcal_range_calculate_overlap(), should be the same. However,
because we were comparing the end dates in the wrong order, they
didn't match.

Fix that by properly comparing the end of the ranges.
2020-04-16 16:15:34 -03:00
Georges Basile Stavracas Neto a790f30176 timeline: Add sentinel events to the queue
Moving to have one subscriber per event made us face an interesting
problem: when removing an event, there may be no subscribers that
contain this event, in which case we never queue any REMOVE_EVENT
and the range tree isn't updated.

Add sentinel events (that update the range tree) and subscriber events
(that update subscribers, but not the range tree).
2020-04-16 16:10:33 -03:00
Georges Basile Stavracas Neto 494bd187d8 timeline: Cancel additions and removals
When we add an event to the queue, and later remove it, if the
event is still in the queue, we can just cancel both out and
save the timeline some processing time.
2020-04-16 15:11:53 -03:00
Georges Basile Stavracas Neto 61815ddccf timeline: Trivial code cleanup 2020-04-16 13:47:09 -03:00
Georges Basile Stavracas Neto 381ae0046a timeline: Protect against NULL arrays 2020-04-15 20:49:47 -03:00
Georges Basile Stavracas Neto 3073b6b6d8 timeline: Also queue remove events 2020-04-15 20:35:17 -03:00
Georges Basile Stavracas Neto b5cdc0bd38 timeline: Only diff when ranges intersect
When the old and the new range of the subscribers don't
overlap entirely, we can't use the regular diff algorithm.
It fails quite spectacularly.

Do a full cleanup when ranges don't overlap.
2020-04-15 20:35:04 -03:00
Georges Basile Stavracas Neto a1a4804315 timeline: Only modify event tree once
Now that we queue one event per subscriber, we need to
make sure to update the range tree only once.
2020-04-15 19:16:00 -03:00
Georges Basile Stavracas Neto 678d0acc00 timeline: Remove subscriber from range tree as well
update_range() does not remove any subscriber. They must be
removed manually.
2020-04-15 18:49:36 -03:00
Georges Basile Stavracas Neto e9812b2f28 timeline: Don't try to use removed subscribers
Because the timeline is essentially asynchronous, it may
try and process events after their subscribers were removed.

Protect against that.

Fixes https://gitlab.gnome.org/GNOME/gnome-calendar/-/issues/576
2020-04-15 18:49:36 -03:00
Georges Basile Stavracas Neto db668a0b90 timeline: Queue one event per subscriber
Right now, GcalTimeline queues one event per N subscribers. Queue
one event per subscriber instead.
2020-04-15 18:49:36 -03:00
Michael Catanzaro 60c3c26ad6 timeline: fix leak of timeline source
g_source_destroy doesn't free memory, just removes the source from its
main context. We have to do both. (g_source_unref() might call
g_source_destroy() if it has the last ref, but if something else has
another ref, then disaster could result if we don't call it manually.)
2020-04-15 21:18:16 +00:00
Georges Basile Stavracas Neto 98e6ac28e7 event: Remove unused method
Comparing ranges is so easy now that we don't need this
helper anymore.
2020-04-14 19:08:06 +00:00
Georges Basile Stavracas Neto fd32492053 timeline, calendar-monitor: Remove useless event range checks
GcalRange is now smart enough to compare correctly with other ranges.
2020-04-14 19:08:06 +00:00
Georges Basile Stavracas Neto d4a6cd0e61 timeline: Process events in batches
A batch size of 5 doesn't seem to impact the mainloop
any more than a batch of size 1, but it reduces the
amount of time spinning the loop quite considerably.
2020-04-14 19:08:06 +00:00
Georges Basile Stavracas Neto 16c156914a calendar-monitor: Use GcalRange 2020-04-14 19:08:06 +00:00
Georges Basile Stavracas Neto f3c3bbf5ab event: Use GcalRange in public API 2020-04-14 19:08:06 +00:00
Georges Basile Stavracas Neto 12fd607d56 utils: Make date comparison follow time comparison semantics
Right now, comparing dates with gcal_date_time_compare_date() gives
the exact opposite result of when comparing using g_date_time_compare().

As shown by this patch, this was a source of *many* bugs.
2020-04-14 19:08:06 +00:00
Georges Basile Stavracas Neto bed8e10609 range-tree: Add print utility
Useful for debugging
2020-04-14 19:08:05 +00:00
Georges Basile Stavracas Neto 3efbc2436c range-tree: Use GcalRange 2020-04-14 19:08:05 +00:00
Georges Basile Stavracas Neto b97c4a27e0 range-tree: Cleanup header 2020-04-14 19:08:05 +00:00
Georges Basile Stavracas Neto 923e3b7b71 project: Move range tree to core/ 2020-04-14 19:08:05 +00:00
Georges Basile Stavracas Neto 0935a67558 event: Add helper API to return a GcalRange 2020-04-14 19:08:05 +00:00
Georges Basile Stavracas Neto d9733aee27 event: Simplify some code 2020-04-14 19:08:05 +00:00
Georges Basile Stavracas Neto dbfebc85fa Introduce GcalRange
GcalRange is a new structure that represents a time range. It is
always inclusive at the start, and exclusive at the end.
2020-04-14 19:08:05 +00:00
Michael Catanzaro 2bf6cfe289 Avoid critical on startup when a calendar is broken
This is a workaround for evolution-data-server#205. Depending on the
resolution of that bug, this might even be the correct fix.
2020-04-02 15:59:32 -05:00
Georges Basile Stavracas Neto aaab4af282 timeline: Respond well to subscriber removal 2020-04-01 23:10:01 -03:00
Georges Basile Stavracas Neto 93542e8853 timeline: Add already cached events to new subscribers 2020-04-01 23:10:01 -03:00
Michael Catanzaro 164ec8620b calendar-monitor: Fix critical in finalize
self->thread can be NULL if gcal_calendar_monitor_set_range() was never
called prior to finalize. This is fine, so just check for NULL here
using g_clear_pointer().
2020-04-02 01:54:33 +00:00
Michael Catanzaro e816657116 calendar-monitor: fix unused variable warning
Fixes:

[43/52] Compiling C object 'src/25a6634@@gcal-private@sta/core_gcal-calendar-monitor.c.o'
../../../../Projects/gnome-calendar/src/core/gcal-calendar-monitor.c: In function ‘on_client_view_objects_added_cb’:
../../../../Projects/gnome-calendar/src/core/gcal-calendar-monitor.c:402:16: warning: variable ‘old_size’ set but not used [-Wunused-but-set-variable]
  402 |           gint old_size;
      |                ^~~~~~~~
2020-04-01 20:30:06 -05:00
Georges Basile Stavracas Neto d606bafd15 calendar-monitor: Properly cleanup ECalComponents
Unfortunately, they do not have autoptr functions.
2020-04-01 21:08:21 -03:00
Georges Basile Stavracas Neto a65a370317 time-zone-monitor: Clear GTimeZone with g_time_zone_unref
GTimeZone is not an object, and it cannot be cleared with g_clear_object().
2020-04-01 21:06:51 -03:00
Georges Basile Stavracas Neto cfa4b56a05 timeline: Implement processing changes in idle 2020-04-01 21:06:51 -03:00