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
This commit is contained in:
Yuri Edward
2020-08-17 15:59:33 -03:00
committed by Georges Basile Stavracas Neto
parent 41a3e0a853
commit 78cb11c64d
3 changed files with 59 additions and 26 deletions
+46 -13
View File
@@ -33,6 +33,7 @@ typedef struct
GcalCalendarMonitor *monitor; GcalCalendarMonitor *monitor;
GcalEvent *event; GcalEvent *event;
gchar *event_id; gchar *event_id;
gboolean complete;
} IdleData; } IdleData;
typedef enum typedef enum
@@ -58,6 +59,7 @@ struct _GcalCalendarMonitor
GAsyncQueue *messages; GAsyncQueue *messages;
GcalCalendar *calendar; GcalCalendar *calendar;
gboolean complete;
/* /*
* These fields are only accessed on the monitor thread, and * These fields are only accessed on the monitor thread, and
@@ -92,7 +94,6 @@ enum
EVENT_ADDED, EVENT_ADDED,
EVENT_UPDATED, EVENT_UPDATED,
EVENT_REMOVED, EVENT_REMOVED,
COMPLETED,
N_SIGNALS, N_SIGNALS,
}; };
@@ -100,6 +101,7 @@ enum
{ {
PROP_0, PROP_0,
PROP_CALENDAR, PROP_CALENDAR,
PROP_COMPLETE,
N_PROPS N_PROPS
}; };
@@ -244,12 +246,14 @@ remove_event_in_idle (GcalCalendarMonitor *self,
} }
static void static void
complete_in_idle (GcalCalendarMonitor *self) set_complete_in_idle (GcalCalendarMonitor *self,
gboolean complete)
{ {
IdleData *idle_data; IdleData *idle_data;
idle_data = g_new0 (IdleData, 1); idle_data = g_new0 (IdleData, 1);
idle_data->monitor = g_object_ref (self); idle_data->monitor = g_object_ref (self);
idle_data->complete = complete;
g_main_context_invoke_full (self->main_context, g_main_context_invoke_full (self->main_context,
G_PRIORITY_DEFAULT_IDLE, G_PRIORITY_DEFAULT_IDLE,
@@ -584,7 +588,7 @@ on_client_view_complete_cb (ECalClientView *view,
self->monitor_thread.populated = TRUE; self->monitor_thread.populated = TRUE;
complete_in_idle (self); set_complete_in_idle (self, TRUE);
g_debug ("Finished initial loading of calendar '%s'", gcal_calendar_get_name (self->calendar)); g_debug ("Finished initial loading of calendar '%s'", gcal_calendar_get_name (self->calendar));
@@ -652,6 +656,8 @@ create_view (GcalCalendarMonitor *self)
self->monitor_thread.view = g_steal_pointer (&view); self->monitor_thread.view = g_steal_pointer (&view);
set_complete_in_idle (self, FALSE);
GCAL_EXIT; GCAL_EXIT;
} }
@@ -857,6 +863,19 @@ remove_all_events (GcalCalendarMonitor *self)
} }
} }
static void
set_complete (GcalCalendarMonitor *self,
gboolean complete)
{
if (self->complete == complete)
return;
GCAL_TRACE_MSG ("Setting complete to %s", complete ? "TRUE" : "FALSE");
self->complete = complete;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COMPLETE]);
}
/* /*
* Callbacks * Callbacks
@@ -959,7 +978,6 @@ on_calendar_visible_changed_cb (GcalCalendar *calendar,
static gboolean static gboolean
complete_in_idle_cb (gpointer user_data) complete_in_idle_cb (gpointer user_data)
{ {
g_autoptr (GcalEvent) event = NULL;
GcalCalendarMonitor *self; GcalCalendarMonitor *self;
IdleData *idle_data; IdleData *idle_data;
@@ -970,7 +988,8 @@ complete_in_idle_cb (gpointer user_data)
g_assert (idle_data->event == NULL); g_assert (idle_data->event == NULL);
g_assert (idle_data->event_id == NULL); g_assert (idle_data->event_id == NULL);
g_signal_emit (self, signals[COMPLETED], 0, event); set_complete (self, idle_data->complete);
GCAL_RETURN (G_SOURCE_REMOVE); GCAL_RETURN (G_SOURCE_REMOVE);
} }
@@ -1015,6 +1034,10 @@ gcal_calendar_monitor_get_property (GObject *object,
g_value_set_object (value, self->calendar); g_value_set_object (value, self->calendar);
break; break;
case PROP_COMPLETE:
g_value_set_boolean (value, self->complete);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
} }
@@ -1039,6 +1062,7 @@ gcal_calendar_monitor_set_property (GObject *object,
self); self);
break; break;
case PROP_COMPLETE:
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
} }
@@ -1078,19 +1102,19 @@ gcal_calendar_monitor_class_init (GcalCalendarMonitorClass *klass)
1, 1,
GCAL_TYPE_EVENT); GCAL_TYPE_EVENT);
signals[COMPLETED] = g_signal_new ("completed",
GCAL_TYPE_CALENDAR_MONITOR,
G_SIGNAL_RUN_FIRST,
0, NULL, NULL, NULL,
G_TYPE_NONE,
0);
properties[PROP_CALENDAR] = g_param_spec_object ("calendar", properties[PROP_CALENDAR] = g_param_spec_object ("calendar",
"Calendar", "Calendar",
"Calendar to be monitores", "Calendar to be monitored",
GCAL_TYPE_CALENDAR, GCAL_TYPE_CALENDAR,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
properties[PROP_COMPLETE] = g_param_spec_boolean ("complete",
"Complete",
"Whether",
FALSE,
G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPS, properties); g_object_class_install_properties (object_class, N_PROPS, properties);
} }
@@ -1101,6 +1125,7 @@ gcal_calendar_monitor_init (GcalCalendarMonitor *self)
self->thread_context = g_main_context_new (); self->thread_context = g_main_context_new ();
self->main_context = g_main_context_ref_thread_default (); self->main_context = g_main_context_ref_thread_default ();
self->messages = g_async_queue_new (); self->messages = g_async_queue_new ();
self->complete = FALSE;
} }
GcalCalendarMonitor* GcalCalendarMonitor*
@@ -1198,3 +1223,11 @@ gcal_calendar_monitor_set_filter (GcalCalendarMonitor *self,
if (gcal_calendar_get_visible (self->calendar)) if (gcal_calendar_get_visible (self->calendar))
notify_view_thread (self, FILTER_UPDATED); notify_view_thread (self, FILTER_UPDATED);
} }
gboolean
gcal_calendar_monitor_is_complete (GcalCalendarMonitor *self)
{
g_return_val_if_fail (GCAL_IS_CALENDAR_MONITOR (self), FALSE);
return self->complete;
}
+2
View File
@@ -41,4 +41,6 @@ GcalEvent* gcal_calendar_monitor_get_cached_event (GcalCalendarMo
void gcal_calendar_monitor_set_filter (GcalCalendarMonitor *self, void gcal_calendar_monitor_set_filter (GcalCalendarMonitor *self,
const gchar *filter); const gchar *filter);
gboolean gcal_calendar_monitor_is_complete (GcalCalendarMonitor *self);
G_END_DECLS G_END_DECLS
+11 -13
View File
@@ -204,17 +204,6 @@ reset_completed_calendars (GcalTimeline *self)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_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 void static void
add_event_to_subscriber (GcalTimelineSubscriber *subscriber, add_event_to_subscriber (GcalTimelineSubscriber *subscriber,
GcalEvent *event) GcalEvent *event)
@@ -591,11 +580,20 @@ on_calendar_monitor_event_removed_cb (GcalCalendarMonitor *monitor,
static void static void
on_calendar_monitor_completed_cb (GcalCalendarMonitor *monitor, on_calendar_monitor_completed_cb (GcalCalendarMonitor *monitor,
GParamSpec *pspec,
GcalTimeline *self) GcalTimeline *self)
{ {
GCAL_ENTRY; GCAL_ENTRY;
increase_completed_calendars (self); if (gcal_calendar_monitor_is_complete (monitor))
self->completed_calendars++;
else
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]);
GCAL_EXIT; GCAL_EXIT;
} }
@@ -953,7 +951,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-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-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, "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_signal_connect (monitor, "notify::complete", G_CALLBACK (on_calendar_monitor_completed_cb), self);
g_hash_table_insert (self->calendars, calendar, g_object_ref (monitor)); g_hash_table_insert (self->calendars, calendar, g_object_ref (monitor));
if (self->range) if (self->range)