From 50b6d00784fb66bc297016f1cad5998a8f2eadb3 Mon Sep 17 00:00:00 2001 From: Michael Catanzaro Date: Thu, 19 Sep 2019 15:47:17 -0500 Subject: [PATCH] manager: add GcalContext property This improves access to the GcalContext inside GcalManager. Also, remove test-manager since it only tests that gcal_manager_new() returns non-NULL. --- src/core/gcal-context.c | 2 +- src/core/gcal-manager.c | 58 +++++++++++++++++++++++++++-------------- src/core/gcal-manager.h | 4 ++- tests/meson.build | 1 - tests/test-manager.c | 47 --------------------------------- 5 files changed, 42 insertions(+), 70 deletions(-) delete mode 100644 tests/test-manager.c diff --git a/src/core/gcal-context.c b/src/core/gcal-context.c index ea2e8fb2..e1503645 100644 --- a/src/core/gcal-context.c +++ b/src/core/gcal-context.c @@ -109,6 +109,7 @@ gcal_context_constructed (GObject *object) G_OBJECT_CLASS (gcal_context_parent_class)->constructed (object); + self->manager = gcal_manager_new (self); self->search_engine = gcal_search_engine_new (self); } @@ -265,7 +266,6 @@ gcal_context_init (GcalContext *self) { self->clock = gcal_clock_new (); self->goa_client = goa_client_new_sync (NULL, NULL); - self->manager = gcal_manager_new (); self->settings = g_settings_new ("org.gnome.calendar"); self->weather_service = gcal_weather_service_new (); diff --git a/src/core/gcal-manager.c b/src/core/gcal-manager.c index fbbb9fcf..2da93204 100644 --- a/src/core/gcal-manager.c +++ b/src/core/gcal-manager.c @@ -90,6 +90,8 @@ struct _GcalManager GCancellable *async_ops; gint clients_synchronizing; + + GcalContext *context; }; G_DEFINE_TYPE (GcalManager, gcal_manager, G_TYPE_OBJECT) @@ -97,6 +99,7 @@ G_DEFINE_TYPE (GcalManager, gcal_manager, G_TYPE_OBJECT) enum { PROP_0, + PROP_CONTEXT, PROP_DEFAULT_CALENDAR, PROP_SYNCHRONIZING, NUM_PROPS @@ -643,6 +646,12 @@ gcal_manager_finalize (GObject *object) g_clear_object (&self->e_data_model); g_clear_object (&self->shell_search_data_model); + if (self->context) + { + g_object_remove_weak_pointer (G_OBJECT (self->context), (gpointer *)&self->context); + self->context = NULL; + } + if (self->search_view_data) { g_clear_pointer (&self->search_view_data->query, g_free); @@ -666,6 +675,12 @@ gcal_manager_set_property (GObject *object, switch (property_id) { + case PROP_CONTEXT: + g_assert (self->context == NULL); + self->context = g_value_get_object (value); + g_object_add_weak_pointer (G_OBJECT (self->context), (gpointer *)&self->context); + break; + case PROP_DEFAULT_CALENDAR: gcal_manager_set_default_calendar (self, g_value_get_object (value)); break; @@ -693,6 +708,10 @@ gcal_manager_get_property (GObject *object, switch (property_id) { + case PROP_CONTEXT: + g_value_set_object (value, self->context); + break; + case PROP_DEFAULT_CALENDAR: g_value_set_object (value, gcal_manager_get_default_calendar (self)); break; @@ -717,6 +736,17 @@ gcal_manager_class_init (GcalManagerClass *klass) object_class->set_property = gcal_manager_set_property; object_class->get_property = gcal_manager_get_property; + /** + * GcalManager:context: + * + * The #GcalContext. + */ + properties[PROP_CONTEXT] = g_param_spec_object ("context", + "Data context", + "Data context", + GCAL_TYPE_CONTEXT, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); + /** * GcalManager:default-calendar: * @@ -783,15 +813,18 @@ gcal_manager_init (GcalManager *self) /* Public API */ /** * gcal_manager_new: + * @context: a #GcalContext * * Creates a new #GcalManager. * * Returns: (transfer full): a newly created #GcalManager */ GcalManager* -gcal_manager_new (void) +gcal_manager_new (GcalContext *context) { - return g_object_new (GCAL_TYPE_MANAGER, NULL); + return g_object_new (GCAL_TYPE_MANAGER, + "context", context, + NULL); } /** @@ -879,8 +912,6 @@ void gcal_manager_setup_shell_search (GcalManager *self, ECalDataModelSubscriber *subscriber) { - GcalApplication *application; - GcalContext *context; GTimeZone *zone; g_return_if_fail (GCAL_IS_MANAGER (self)); @@ -888,9 +919,6 @@ gcal_manager_setup_shell_search (GcalManager *self, if (self->shell_search_data_model) return; - application = GCAL_APPLICATION (g_application_get_default ()); - context = gcal_application_get_context (application); - self->shell_search_data_model = e_cal_data_model_new (gcal_thread_submit_job); g_signal_connect_object (self->shell_search_data_model, "view-state-changed", @@ -900,7 +928,7 @@ gcal_manager_setup_shell_search (GcalManager *self, e_cal_data_model_set_expand_recurrences (self->shell_search_data_model, TRUE); - zone = gcal_context_get_timezone (context); + zone = gcal_context_get_timezone (self->context); e_cal_data_model_set_timezone (self->shell_search_data_model, gcal_timezone_to_icaltimezone (zone)); self->search_view_data = g_new0 (ViewStateData, 1); @@ -1431,8 +1459,6 @@ gcal_manager_get_events (GcalManager *self, ICalTime *start_date, ICalTime *end_date) { - GcalApplication *application; - GcalContext *context; time_t range_start, range_end; GTimeZone *zone; ICalTimezone *tz; @@ -1443,12 +1469,9 @@ gcal_manager_get_events (GcalManager *self, GCAL_ENTRY; - application = GCAL_APPLICATION (g_application_get_default ()); - context = gcal_application_get_context (application); - g_return_val_if_fail (GCAL_IS_MANAGER (self), NULL); - zone = gcal_context_get_timezone (context); + zone = gcal_context_get_timezone (self->context); tz = gcal_timezone_to_icaltimezone (zone); range_start = i_cal_time_as_timet_with_zone (start_date, tz); range_end = i_cal_time_as_timet_with_zone (end_date, tz); @@ -1541,15 +1564,10 @@ gcal_manager_startup (GcalManager *self) GList *sources, *l; GError *error = NULL; ESourceCredentialsProvider *credentials_provider; - GcalApplication *application; - GcalContext *context; GTimeZone *zone; GCAL_ENTRY; - application = GCAL_APPLICATION (g_application_get_default ()); - context = gcal_application_get_context (application); - self->clients = g_hash_table_new_full ((GHashFunc) e_source_hash, (GEqualFunc) e_source_equal, g_object_unref, @@ -1648,7 +1666,7 @@ gcal_manager_startup (GcalManager *self) e_cal_data_model_set_expand_recurrences (self->e_data_model, TRUE); - zone = gcal_context_get_timezone (context); + zone = gcal_context_get_timezone (self->context); e_cal_data_model_set_timezone (self->e_data_model, gcal_timezone_to_icaltimezone (zone)); sources = e_source_registry_list_enabled (self->source_registry, E_SOURCE_EXTENSION_CALENDAR); diff --git a/src/core/gcal-manager.h b/src/core/gcal-manager.h index 0874372e..aaf43915 100644 --- a/src/core/gcal-manager.h +++ b/src/core/gcal-manager.h @@ -30,7 +30,9 @@ G_BEGIN_DECLS #define GCAL_TYPE_MANAGER (gcal_manager_get_type ()) G_DECLARE_FINAL_TYPE (GcalManager, gcal_manager, GCAL, MANAGER, GObject) -GcalManager* gcal_manager_new (void); +typedef struct _GcalContext GcalContext; + +GcalManager* gcal_manager_new (GcalContext *context); ESource* gcal_manager_get_source (GcalManager *self, const gchar *uid); diff --git a/tests/meson.build b/tests/meson.build index ec704dfd..c6510f1e 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -35,7 +35,6 @@ tests = [ 'server', 'discoverer', 'event', - 'manager', ] foreach test : tests diff --git a/tests/test-manager.c b/tests/test-manager.c deleted file mode 100644 index d97a16ab..00000000 --- a/tests/test-manager.c +++ /dev/null @@ -1,47 +0,0 @@ -/* test-manager.c - * - * Copyright (C) 2017 Georges Basile Stavracas Neto - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include - -#include "gcal-manager.h" - -/*********************************************************************************************************************/ - -static void -manager_new (void) -{ - g_autoptr (GcalManager) manager; - - manager = gcal_manager_new (); - - g_assert_nonnull (manager); -} - -/*********************************************************************************************************************/ - -gint -main (gint argc, - gchar *argv[]) -{ - g_test_init (&argc, &argv, NULL); - - g_test_add_func ("/manager/new", manager_new); - - return g_test_run (); -} -