Move Shell search to GcalShellSearchProvider

Add a custom timeline to GcalShellSearchProvier and use
it to gather events.

Do a massive cleanup of unused APIs as well.
This commit is contained in:
Georges Basile Stavracas Neto
2020-04-01 21:06:51 -03:00
parent 06fbe2c2b9
commit 84eeb58804
6 changed files with 251 additions and 390 deletions
+69
View File
@@ -50,6 +50,8 @@ struct _GcalTimeline
gchar *filter;
GHashTable *calendars; /* GcalCalendar* -> GcalCalendarMonitor* */
gint completed_calendars;
GHashTable *subscribers; /* GcalTimelineSubscriber* -> SubscriberData* */
GcalRangeTree *subscriber_ranges;
@@ -63,6 +65,7 @@ G_DEFINE_TYPE (GcalTimeline, gcal_timeline, G_TYPE_OBJECT)
enum
{
PROP_0,
PROP_COMPLETE,
PROP_CONTEXT,
PROP_FILTER,
N_PROPS
@@ -75,6 +78,33 @@ static GParamSpec *properties [N_PROPS] = { NULL, };
* Auxiliary methods
*/
static inline gboolean
is_timeline_complete (GcalTimeline *self)
{
return self->completed_calendars == g_hash_table_size (self->calendars);
}
static void
reset_completed_calendars (GcalTimeline *self)
{
gboolean was_complete = is_timeline_complete (self);
self->completed_calendars = 0;
if (is_timeline_complete (self) != was_complete)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COMPLETE]);
}
static void
increase_completed_calendars (GcalTimeline *self)
{
self->completed_calendars++;
g_assert (self->completed_calendars <= g_hash_table_size (self->calendars));
if (is_timeline_complete (self))
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COMPLETE]);
}
static SubscriberData*
subscriber_data_new (GcalTimelineSubscriber *subscriber)
{
@@ -226,6 +256,8 @@ update_range (GcalTimeline *self)
{
GcalCalendarMonitor *monitor;
reset_completed_calendars (self);
g_hash_table_iter_init (&iter, self->calendars);
while (g_hash_table_iter_next (&iter, NULL, (gpointer*) &monitor))
gcal_calendar_monitor_set_range (monitor, self->range_start, self->range_end);
@@ -357,6 +389,8 @@ update_calendar_monitor_filters (GcalTimeline *self)
GcalCalendarMonitor *monitor;
GHashTableIter iter;
reset_completed_calendars (self);
g_hash_table_iter_init (&iter, self->calendars);
while (g_hash_table_iter_next (&iter, NULL, (gpointer*) &monitor))
gcal_calendar_monitor_set_filter (monitor, self->filter);
@@ -473,6 +507,17 @@ on_calendar_monitor_event_removed_cb (GcalCalendarMonitor *monitor,
GCAL_EXIT;
}
static void
on_calendar_monitor_completed_cb (GcalCalendarMonitor *monitor,
GcalTimeline *self)
{
GCAL_ENTRY;
increase_completed_calendars (self);
GCAL_EXIT;
}
static gboolean
update_timeline_range_in_idle_cb (gpointer user_data)
{
@@ -538,6 +583,10 @@ gcal_timeline_get_property (GObject *object,
switch (prop_id)
{
case PROP_COMPLETE:
g_value_set_boolean (value, is_timeline_complete (self));
break;
case PROP_CONTEXT:
g_value_set_object (value, self->context);
break;
@@ -584,6 +633,17 @@ gcal_timeline_class_init (GcalTimelineClass *klass)
object_class->get_property = gcal_timeline_get_property;
object_class->set_property = gcal_timeline_set_property;
/**
* GcalTimeline::complete:
*
* Whether all calendars in this timeline are completed.
*/
properties[PROP_COMPLETE] = g_param_spec_boolean ("complete",
"Complete",
"Complete",
FALSE,
G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
/**
* GcalSearchEngine::context:
*
@@ -664,6 +724,7 @@ gcal_timeline_add_calendar (GcalTimeline *self,
g_signal_connect (monitor, "event-added", G_CALLBACK (on_calendar_monitor_event_added_cb), self);
g_signal_connect (monitor, "event-updated", G_CALLBACK (on_calendar_monitor_event_updated_cb), self);
g_signal_connect (monitor, "event-removed", G_CALLBACK (on_calendar_monitor_event_removed_cb), self);
g_signal_connect (monitor, "completed", G_CALLBACK (on_calendar_monitor_completed_cb), self);
g_hash_table_insert (self->calendars, calendar, g_object_ref (monitor));
if (self->range_start && self->range_end)
@@ -789,3 +850,11 @@ gcal_timeline_set_filter (GcalTimeline *self,
GCAL_EXIT;
}
gboolean
gcal_timeline_is_complete (GcalTimeline *self)
{
g_return_val_if_fail (GCAL_IS_TIMELINE (self), FALSE);
return is_timeline_complete (self);
}