From 2ef1cbc463af4f856d14f5d270a91d03f41d2b26 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Sat, 4 May 2019 10:15:35 -0300 Subject: [PATCH] manager: Toggle data model sources when changed Instead of other classes needing to manually set and unset whether a source is registered in the data model, we can now simply call GcalCalendar.set_visible() and have the model be updated for us. --- src/core/gcal-manager.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/core/gcal-manager.c b/src/core/gcal-manager.c index ce20978b..8ac27940 100644 --- a/src/core/gcal-manager.c +++ b/src/core/gcal-manager.c @@ -182,8 +182,27 @@ source_changed (GcalManager *self, calendar = g_hash_table_lookup (self->clients, source); - if (calendar) - g_signal_emit (self, signals[CALENDAR_CHANGED], 0, calendar); + if (!calendar) + GCAL_RETURN (); + + if (gcal_calendar_get_visible (calendar)) + { + ECalClient *client = gcal_calendar_get_client (calendar); + + e_cal_data_model_add_client (self->e_data_model, client); + if (self->shell_search_data_model) + e_cal_data_model_add_client (self->shell_search_data_model, client); + } + else + { + const gchar *id = gcal_calendar_get_id (calendar); + + e_cal_data_model_remove_client (self->e_data_model, id); + if (self->shell_search_data_model) + e_cal_data_model_remove_client (self->shell_search_data_model, id); + } + + g_signal_emit (self, signals[CALENDAR_CHANGED], 0, calendar); GCAL_EXIT; }