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.
This commit is contained in:
@@ -109,6 +109,7 @@ gcal_context_constructed (GObject *object)
|
|||||||
|
|
||||||
G_OBJECT_CLASS (gcal_context_parent_class)->constructed (object);
|
G_OBJECT_CLASS (gcal_context_parent_class)->constructed (object);
|
||||||
|
|
||||||
|
self->manager = gcal_manager_new (self);
|
||||||
self->search_engine = gcal_search_engine_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->clock = gcal_clock_new ();
|
||||||
self->goa_client = goa_client_new_sync (NULL, NULL);
|
self->goa_client = goa_client_new_sync (NULL, NULL);
|
||||||
self->manager = gcal_manager_new ();
|
|
||||||
self->settings = g_settings_new ("org.gnome.calendar");
|
self->settings = g_settings_new ("org.gnome.calendar");
|
||||||
self->weather_service = gcal_weather_service_new ();
|
self->weather_service = gcal_weather_service_new ();
|
||||||
|
|
||||||
|
|||||||
+38
-20
@@ -90,6 +90,8 @@ struct _GcalManager
|
|||||||
GCancellable *async_ops;
|
GCancellable *async_ops;
|
||||||
|
|
||||||
gint clients_synchronizing;
|
gint clients_synchronizing;
|
||||||
|
|
||||||
|
GcalContext *context;
|
||||||
};
|
};
|
||||||
|
|
||||||
G_DEFINE_TYPE (GcalManager, gcal_manager, G_TYPE_OBJECT)
|
G_DEFINE_TYPE (GcalManager, gcal_manager, G_TYPE_OBJECT)
|
||||||
@@ -97,6 +99,7 @@ G_DEFINE_TYPE (GcalManager, gcal_manager, G_TYPE_OBJECT)
|
|||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
PROP_0,
|
PROP_0,
|
||||||
|
PROP_CONTEXT,
|
||||||
PROP_DEFAULT_CALENDAR,
|
PROP_DEFAULT_CALENDAR,
|
||||||
PROP_SYNCHRONIZING,
|
PROP_SYNCHRONIZING,
|
||||||
NUM_PROPS
|
NUM_PROPS
|
||||||
@@ -643,6 +646,12 @@ gcal_manager_finalize (GObject *object)
|
|||||||
g_clear_object (&self->e_data_model);
|
g_clear_object (&self->e_data_model);
|
||||||
g_clear_object (&self->shell_search_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)
|
if (self->search_view_data)
|
||||||
{
|
{
|
||||||
g_clear_pointer (&self->search_view_data->query, g_free);
|
g_clear_pointer (&self->search_view_data->query, g_free);
|
||||||
@@ -666,6 +675,12 @@ gcal_manager_set_property (GObject *object,
|
|||||||
|
|
||||||
switch (property_id)
|
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:
|
case PROP_DEFAULT_CALENDAR:
|
||||||
gcal_manager_set_default_calendar (self, g_value_get_object (value));
|
gcal_manager_set_default_calendar (self, g_value_get_object (value));
|
||||||
break;
|
break;
|
||||||
@@ -693,6 +708,10 @@ gcal_manager_get_property (GObject *object,
|
|||||||
|
|
||||||
switch (property_id)
|
switch (property_id)
|
||||||
{
|
{
|
||||||
|
case PROP_CONTEXT:
|
||||||
|
g_value_set_object (value, self->context);
|
||||||
|
break;
|
||||||
|
|
||||||
case PROP_DEFAULT_CALENDAR:
|
case PROP_DEFAULT_CALENDAR:
|
||||||
g_value_set_object (value, gcal_manager_get_default_calendar (self));
|
g_value_set_object (value, gcal_manager_get_default_calendar (self));
|
||||||
break;
|
break;
|
||||||
@@ -717,6 +736,17 @@ gcal_manager_class_init (GcalManagerClass *klass)
|
|||||||
object_class->set_property = gcal_manager_set_property;
|
object_class->set_property = gcal_manager_set_property;
|
||||||
object_class->get_property = gcal_manager_get_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:
|
* GcalManager:default-calendar:
|
||||||
*
|
*
|
||||||
@@ -783,15 +813,18 @@ gcal_manager_init (GcalManager *self)
|
|||||||
/* Public API */
|
/* Public API */
|
||||||
/**
|
/**
|
||||||
* gcal_manager_new:
|
* gcal_manager_new:
|
||||||
|
* @context: a #GcalContext
|
||||||
*
|
*
|
||||||
* Creates a new #GcalManager.
|
* Creates a new #GcalManager.
|
||||||
*
|
*
|
||||||
* Returns: (transfer full): a newly created #GcalManager
|
* Returns: (transfer full): a newly created #GcalManager
|
||||||
*/
|
*/
|
||||||
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,
|
gcal_manager_setup_shell_search (GcalManager *self,
|
||||||
ECalDataModelSubscriber *subscriber)
|
ECalDataModelSubscriber *subscriber)
|
||||||
{
|
{
|
||||||
GcalApplication *application;
|
|
||||||
GcalContext *context;
|
|
||||||
GTimeZone *zone;
|
GTimeZone *zone;
|
||||||
|
|
||||||
g_return_if_fail (GCAL_IS_MANAGER (self));
|
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)
|
if (self->shell_search_data_model)
|
||||||
return;
|
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);
|
self->shell_search_data_model = e_cal_data_model_new (gcal_thread_submit_job);
|
||||||
g_signal_connect_object (self->shell_search_data_model,
|
g_signal_connect_object (self->shell_search_data_model,
|
||||||
"view-state-changed",
|
"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);
|
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));
|
e_cal_data_model_set_timezone (self->shell_search_data_model, gcal_timezone_to_icaltimezone (zone));
|
||||||
|
|
||||||
self->search_view_data = g_new0 (ViewStateData, 1);
|
self->search_view_data = g_new0 (ViewStateData, 1);
|
||||||
@@ -1431,8 +1459,6 @@ gcal_manager_get_events (GcalManager *self,
|
|||||||
ICalTime *start_date,
|
ICalTime *start_date,
|
||||||
ICalTime *end_date)
|
ICalTime *end_date)
|
||||||
{
|
{
|
||||||
GcalApplication *application;
|
|
||||||
GcalContext *context;
|
|
||||||
time_t range_start, range_end;
|
time_t range_start, range_end;
|
||||||
GTimeZone *zone;
|
GTimeZone *zone;
|
||||||
ICalTimezone *tz;
|
ICalTimezone *tz;
|
||||||
@@ -1443,12 +1469,9 @@ gcal_manager_get_events (GcalManager *self,
|
|||||||
|
|
||||||
GCAL_ENTRY;
|
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);
|
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);
|
tz = gcal_timezone_to_icaltimezone (zone);
|
||||||
range_start = i_cal_time_as_timet_with_zone (start_date, tz);
|
range_start = i_cal_time_as_timet_with_zone (start_date, tz);
|
||||||
range_end = i_cal_time_as_timet_with_zone (end_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;
|
GList *sources, *l;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
ESourceCredentialsProvider *credentials_provider;
|
ESourceCredentialsProvider *credentials_provider;
|
||||||
GcalApplication *application;
|
|
||||||
GcalContext *context;
|
|
||||||
GTimeZone *zone;
|
GTimeZone *zone;
|
||||||
|
|
||||||
GCAL_ENTRY;
|
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,
|
self->clients = g_hash_table_new_full ((GHashFunc) e_source_hash,
|
||||||
(GEqualFunc) e_source_equal,
|
(GEqualFunc) e_source_equal,
|
||||||
g_object_unref,
|
g_object_unref,
|
||||||
@@ -1648,7 +1666,7 @@ gcal_manager_startup (GcalManager *self)
|
|||||||
|
|
||||||
e_cal_data_model_set_expand_recurrences (self->e_data_model, TRUE);
|
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));
|
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);
|
sources = e_source_registry_list_enabled (self->source_registry, E_SOURCE_EXTENSION_CALENDAR);
|
||||||
|
|||||||
@@ -30,7 +30,9 @@ G_BEGIN_DECLS
|
|||||||
#define GCAL_TYPE_MANAGER (gcal_manager_get_type ())
|
#define GCAL_TYPE_MANAGER (gcal_manager_get_type ())
|
||||||
G_DECLARE_FINAL_TYPE (GcalManager, gcal_manager, GCAL, MANAGER, GObject)
|
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,
|
ESource* gcal_manager_get_source (GcalManager *self,
|
||||||
const gchar *uid);
|
const gchar *uid);
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ tests = [
|
|||||||
'server',
|
'server',
|
||||||
'discoverer',
|
'discoverer',
|
||||||
'event',
|
'event',
|
||||||
'manager',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
foreach test : tests
|
foreach test : tests
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
/* test-manager.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 2017 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <glib.h>
|
|
||||||
|
|
||||||
#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 ();
|
|
||||||
}
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user