[gnome-calendar/mcatanzaro/#419: 73/73] Stop using e_cal_util_get_system_timezone()
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/mcatanzaro/#419: 73/73] Stop using e_cal_util_get_system_timezone()
- Date: Thu, 19 Sep 2019 16:10:43 +0000 (UTC)
commit 279542e807b73e65ed44940113b20e8e68eff1e4
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Thu Sep 19 11:07:56 2019 -0500
Stop using e_cal_util_get_system_timezone()
Because its return value is nullable, which is inconvenient for us.
Instead, add and use gcal_context_get_icaltimezone() to supplement the
existing gcal_context_get_timezone().
We'll also need a function to convert from GTimeZone to ICalTimezone,
gcal_timezone_to_icaltimezone().
Finally, we have to initialize the GcalSearchEngine later when
constructing GcalContext, because with this change GcalSearchEngine now
needs GcalContext ready to initialize itself.
src/core/gcal-context.c | 31 ++++++++++++++++++++++++++++-
src/core/gcal-context.h | 1 +
src/core/gcal-event.c | 15 ++++++++------
src/core/gcal-manager.c | 42 +++++++++++++++++++++-------------------
src/search/gcal-search-engine.c | 6 +-----
src/utils/gcal-date-time-utils.c | 20 +++++++++++++++++++
src/utils/gcal-date-time-utils.h | 2 ++
src/utils/gcal-utils.c | 28 +++++++++++++++++----------
8 files changed, 103 insertions(+), 42 deletions(-)
---
diff --git a/src/core/gcal-context.c b/src/core/gcal-context.c
index cd8b441e..6d3f9249 100644
--- a/src/core/gcal-context.c
+++ b/src/core/gcal-context.c
@@ -21,6 +21,7 @@
#define G_LOG_DOMAIN "GcalContext"
#include "gcal-context.h"
+#include "gcal-date-time-utils.h"
#include "gcal-night-light-monitor.h"
#include "gcal-time-zone-monitor.h"
@@ -102,6 +103,16 @@ on_timezone_changed_cb (GcalTimeZoneMonitor *timezone_monitor,
* GObject overrides
*/
+static void
+gcal_context_constructed (GObject *object)
+{
+ GcalContext *self = (GcalContext *)object;
+
+ G_OBJECT_CLASS (gcal_context_parent_class)->constructed (object);
+
+ self->search_engine = gcal_search_engine_new (self);
+}
+
static void
gcal_context_finalize (GObject *object)
{
@@ -193,6 +204,7 @@ gcal_context_class_init (GcalContextClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->constructed = gcal_context_constructed;
object_class->finalize = gcal_context_finalize;
object_class->get_property = gcal_context_get_property;
object_class->set_property = gcal_context_set_property;
@@ -257,7 +269,6 @@ gcal_context_init (GcalContext *self)
self->manager = gcal_manager_new ();
self->settings = g_settings_new ("org.gnome.calendar");
self->weather_service = gcal_weather_service_new ();
- self->search_engine = gcal_search_engine_new (self);
self->timezone_monitor = gcal_time_zone_monitor_new ();
g_signal_connect_object (self->timezone_monitor,
@@ -395,6 +406,24 @@ gcal_context_get_timezone (GcalContext *self)
return gcal_time_zone_monitor_get_timezone (self->timezone_monitor);
}
+/**
+ * gcal_context_get_icaltimezone:
+ *
+ * Retrieves the system timezone.
+ *
+ * Returns: (transfer none): an #ICalTimezone
+ */
+ICalTimezone*
+gcal_context_get_icaltimezone (GcalContext *self)
+{
+ GTimeZone *tz;
+
+ g_return_val_if_fail (GCAL_IS_CONTEXT (self), NULL);
+
+ tz = gcal_time_zone_monitor_get_timezone (self->timezone_monitor);
+ return gcal_timezone_to_icaltimezone (tz);
+}
+
/**
* gcal_context_get_weather_service:
*
diff --git a/src/core/gcal-context.h b/src/core/gcal-context.h
index eeb6d651..cd6f7384 100644
--- a/src/core/gcal-context.h
+++ b/src/core/gcal-context.h
@@ -49,6 +49,7 @@ GSettings* gcal_context_get_settings (GcalContext
GcalTimeFormat gcal_context_get_time_format (GcalContext *self);
GTimeZone* gcal_context_get_timezone (GcalContext *self);
+ICalTimezone* gcal_context_get_icaltimezone (GcalContext *self);
GcalWeatherService* gcal_context_get_weather_service (GcalContext *self);
diff --git a/src/core/gcal-event.c b/src/core/gcal-event.c
index 5507720e..3e67e277 100644
--- a/src/core/gcal-event.c
+++ b/src/core/gcal-event.c
@@ -20,6 +20,7 @@
#include "gconstructor.h"
#include "gcal-application.h"
+#include "gcal-context.h"
#include "gcal-debug.h"
#include "gcal-event.h"
#include "gcal-utils.h"
@@ -223,12 +224,17 @@ static ECalComponentDateTime*
build_component_from_datetime (GcalEvent *self,
GDateTime *dt)
{
+ GcalApplication *application;
+ GcalContext *context;
ICalTime *itt;
gchar *tzid = NULL;
if (!dt)
return NULL;
+ application = GCAL_APPLICATION (g_application_get_default ());
+ context = gcal_application_get_context (application);
+
itt = gcal_date_time_to_icaltime (dt);
if (self->all_day)
@@ -240,12 +246,9 @@ build_component_from_datetime (GcalEvent *self,
{
ICalTimezone *zone;
- zone = e_cal_util_get_system_timezone ();
- if (zone != NULL)
- {
- i_cal_time_set_timezone (itt, zone);
- tzid = g_strdup (i_cal_timezone_get_tzid (zone));
- }
+ zone = gcal_context_get_icaltimezone (context);
+ i_cal_time_set_timezone (itt, zone);
+ tzid = g_strdup (i_cal_timezone_get_tzid (zone));
}
/* Call it after setting the timezone, because the DATE values do not let set the timezone */
diff --git a/src/core/gcal-manager.c b/src/core/gcal-manager.c
index 319ce188..084669e8 100644
--- a/src/core/gcal-manager.c
+++ b/src/core/gcal-manager.c
@@ -18,6 +18,8 @@
#define G_LOG_DOMAIN "GcalManager"
+#include "gcal-application.h"
+#include "gcal-context.h"
#include "gcal-debug.h"
#include "gcal-manager.h"
#include "gcal-utils.h"
@@ -877,13 +879,17 @@ void
gcal_manager_setup_shell_search (GcalManager *self,
ECalDataModelSubscriber *subscriber)
{
- ICalTimezone *tz;
+ GcalApplication *application;
+ GcalContext *context;
g_return_if_fail (GCAL_IS_MANAGER (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",
@@ -892,9 +898,7 @@ gcal_manager_setup_shell_search (GcalManager *self,
G_CONNECT_SWAPPED);
e_cal_data_model_set_expand_recurrences (self->shell_search_data_model, TRUE);
- tz = e_cal_util_get_system_timezone ();
- if (tz != NULL)
- e_cal_data_model_set_timezone (self->shell_search_data_model, tz);
+ e_cal_data_model_set_timezone (self->shell_search_data_model, gcal_context_get_icaltimezone (context));
self->search_view_data = g_new0 (ViewStateData, 1);
self->search_view_data->subscriber = subscriber;
@@ -1424,6 +1428,8 @@ gcal_manager_get_events (GcalManager *self,
ICalTime *start_date,
ICalTime *end_date)
{
+ GcalApplication *application;
+ GcalContext *context;
time_t range_start, range_end;
ICalTimezone *tz;
GatherEventData data = {
@@ -1433,20 +1439,14 @@ 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);
- tz = e_cal_util_get_system_timezone ();
-
- if (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);
- }
- else
- {
- range_start = i_cal_time_as_timet (start_date);
- range_end = i_cal_time_as_timet (end_date);
- }
+ tz = gcal_context_get_icaltimezone (context);
+ range_start = i_cal_time_as_timet_with_zone (start_date, tz);
+ range_end = i_cal_time_as_timet_with_zone (end_date, tz);
e_cal_data_model_foreach_component (self->e_data_model,
range_start,
@@ -1536,10 +1536,14 @@ gcal_manager_startup (GcalManager *self)
GList *sources, *l;
GError *error = NULL;
ESourceCredentialsProvider *credentials_provider;
- ICalTimezone *tz;
+ GcalApplication *application;
+ GcalContext *context;
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,
@@ -1637,9 +1641,7 @@ gcal_manager_startup (GcalManager *self)
self->e_data_model = e_cal_data_model_new (gcal_thread_submit_job);
e_cal_data_model_set_expand_recurrences (self->e_data_model, TRUE);
- tz = e_cal_util_get_system_timezone ();
- if (tz != NULL)
- e_cal_data_model_set_timezone (self->e_data_model, tz);
+ e_cal_data_model_set_timezone (self->e_data_model, gcal_context_get_icaltimezone (context));
sources = e_source_registry_list_enabled (self->source_registry, E_SOURCE_EXTENSION_CALENDAR);
diff --git a/src/search/gcal-search-engine.c b/src/search/gcal-search-engine.c
index afc241c5..353b5f76 100644
--- a/src/search/gcal-search-engine.c
+++ b/src/search/gcal-search-engine.c
@@ -177,17 +177,13 @@ gcal_search_engine_constructed (GObject *object)
{
GcalSearchEngine *self = (GcalSearchEngine *)object;
GcalManager *manager;
- ICalTimezone *tz;
G_OBJECT_CLASS (gcal_search_engine_parent_class)->constructed (object);
/* Setup the data model */
self->data_model = e_cal_data_model_new (gcal_thread_submit_job);
e_cal_data_model_set_expand_recurrences (self->data_model, TRUE);
- tz = e_cal_util_get_system_timezone ();
- if (tz != NULL)
- e_cal_data_model_set_timezone (self->data_model, tz);
-
+ e_cal_data_model_set_timezone (self->data_model, gcal_context_get_icaltimezone (self->context));
manager = gcal_context_get_manager (self->context);
g_signal_connect_object (manager, "calendar-added", G_CALLBACK (on_manager_calendar_added_cb), self, 0);
diff --git a/src/utils/gcal-date-time-utils.c b/src/utils/gcal-date-time-utils.c
index 45ea57a6..607394a3 100644
--- a/src/utils/gcal-date-time-utils.c
+++ b/src/utils/gcal-date-time-utils.c
@@ -230,3 +230,23 @@ gcal_date_time_from_icaltime (const ICalTime *date)
return g_steal_pointer (&dt);
}
+/**
+ * @tz: a #GTimezone
+ *
+ * Returns an #ICalTimezone corresponding to @tz.
+ *
+ * Returns: (transfer none): an #ICalTimezone.
+ */
+ICalTimezone*
+gcal_timezone_to_icaltimezone (GTimeZone *tz)
+{
+ const gchar *tzid;
+ ICalTimezone *ical_tz;
+
+ tzid = g_time_zone_get_identifier (tz);
+ ical_tz = i_cal_timezone_get_builtin_timezone (tzid);
+
+ g_assert (ical_tz != NULL);
+ return ical_tz;
+}
+
diff --git a/src/utils/gcal-date-time-utils.h b/src/utils/gcal-date-time-utils.h
index 369082b0..50d9707e 100644
--- a/src/utils/gcal-date-time-utils.h
+++ b/src/utils/gcal-date-time-utils.h
@@ -51,4 +51,6 @@ gboolean gcal_date_time_is_date (GDateTime
GDateTime* gcal_date_time_from_icaltime (const ICalTime *date);
+ICalTimezone* gcal_timezone_to_icaltimezone (GTimeZone *tz);
+
G_END_DECLS
diff --git a/src/utils/gcal-utils.c b/src/utils/gcal-utils.c
index 765c35f2..df7ee911 100644
--- a/src/utils/gcal-utils.c
+++ b/src/utils/gcal-utils.c
@@ -23,6 +23,8 @@
/* langinfo.h in glibc 2.27 defines ALTMON_* only if _GNU_SOURCE is defined. */
#define _GNU_SOURCE
+#include "gcal-application.h"
+#include "gcal-context.h"
#include "gcal-enums.h"
#include "gcal-utils.h"
#include "gcal-event-widget.h"
@@ -369,6 +371,8 @@ build_component_from_details (const gchar *summary,
GDateTime *initial_date,
GDateTime *final_date)
{
+ GcalApplication *application;
+ GcalContext *context;
ECalComponent *event;
ECalComponentDateTime *dt;
ECalComponentText *summ;
@@ -376,6 +380,9 @@ build_component_from_details (const gchar *summary,
ICalTime *itt;
gboolean all_day;
+ application = GCAL_APPLICATION (g_application_get_default ());
+ context = gcal_application_get_context (application);
+
event = e_cal_component_new ();
e_cal_component_set_new_vtype (event, E_CAL_COMPONENT_EVENT);
@@ -389,13 +396,13 @@ build_component_from_details (const gchar *summary,
* When the event is all day, we consider UTC timezone by default. Otherwise,
* we always use the system timezone to create new events
*/
- if (!all_day)
+ if (all_day)
{
- zone = e_cal_util_get_system_timezone ();
+ zone = i_cal_timezone_get_utc_timezone ();
}
- if (zone == NULL)
+ else
{
- zone = i_cal_timezone_get_utc_timezone ();
+ zone = gcal_context_get_icaltimezone (context);
}
/* Start date */
@@ -476,21 +483,22 @@ icaltime_compare_with_current (const ICalTime *date1,
const ICalTime *date2,
time_t *current_time_t)
{
+ GcalApplication *application;
+ GcalContext *context;
ICalTimezone *zone1, *zone2;
gint result = 0;
time_t start1, start2, diff1, diff2;
+ application = GCAL_APPLICATION (g_application_get_default ());
+ context = gcal_application_get_context (application);
+
zone1 = i_cal_time_get_timezone (date1);
if (!zone1)
- zone1 = e_cal_util_get_system_timezone ();
- if (!zone1)
- zone1 = i_cal_timezone_get_utc_timezone ();
+ zone1 = gcal_context_get_icaltimezone (context);
zone2 = i_cal_time_get_timezone (date2);
if (!zone2)
- zone2 = e_cal_util_get_system_timezone ();
- if (!zone2)
- zone2 = i_cal_timezone_get_utc_timezone ();
+ zone2 = gcal_context_get_icaltimezone (context);
start1 = i_cal_time_as_timet_with_zone (date1, zone1);
start2 = i_cal_time_as_timet_with_zone (date2, zone2);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]