diff options
author | Chenthill Palanisamy <pchenthill@novell.com> | 2010-04-16 19:37:40 +0800 |
---|---|---|
committer | Chenthill Palanisamy <pchenthill@novell.com> | 2010-04-16 19:43:31 +0800 |
commit | dac959d85813debca9762eaf4c4cf8cebc1090fe (patch) | |
tree | fae1c75f4c6bc91e3174392ef8b83d557522bbd1 | |
parent | e9b64e499fe4abaea723820dcb8b591cf38804a6 (diff) | |
download | gsoc2013-evolution-dac959d85813debca9762eaf4c4cf8cebc1090fe.tar gsoc2013-evolution-dac959d85813debca9762eaf4c4cf8cebc1090fe.tar.gz gsoc2013-evolution-dac959d85813debca9762eaf4c4cf8cebc1090fe.tar.bz2 gsoc2013-evolution-dac959d85813debca9762eaf4c4cf8cebc1090fe.tar.lz gsoc2013-evolution-dac959d85813debca9762eaf4c4cf8cebc1090fe.tar.xz gsoc2013-evolution-dac959d85813debca9762eaf4c4cf8cebc1090fe.tar.zst gsoc2013-evolution-dac959d85813debca9762eaf4c4cf8cebc1090fe.zip |
Bug 596601 (bnc) - monitor system timezone changes in evolution
-rw-r--r-- | calendar/gui/e-cal-model.c | 15 | ||||
-rw-r--r-- | calendar/gui/e-cal-model.h | 3 | ||||
-rw-r--r-- | calendar/gui/e-day-view.c | 11 | ||||
-rw-r--r-- | calendar/gui/e-week-view.c | 14 | ||||
-rw-r--r-- | modules/calendar/e-cal-shell-view-private.c | 85 | ||||
-rw-r--r-- | modules/calendar/e-cal-shell-view-private.h | 4 |
6 files changed, 119 insertions, 13 deletions
diff --git a/calendar/gui/e-cal-model.c b/calendar/gui/e-cal-model.c index 5cf20941b8..cb1966fb17 100644 --- a/calendar/gui/e-cal-model.c +++ b/calendar/gui/e-cal-model.c @@ -141,6 +141,7 @@ enum { CAL_VIEW_PROGRESS, CAL_VIEW_DONE, STATUS_MESSAGE, + TIMEZONE_CHANGED, LAST_SIGNAL }; @@ -474,6 +475,16 @@ e_cal_model_class_init (ECalModelClass *class) e_marshal_VOID__STRING_DOUBLE, G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_DOUBLE); + signals[TIMEZONE_CHANGED] = g_signal_new ( + "timezone-changed", + G_TYPE_FROM_CLASS (class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (ECalModelClass, timezone_changed), + NULL, NULL, + e_marshal_VOID__POINTER_POINTER, + G_TYPE_NONE, 2, + G_TYPE_POINTER, + G_TYPE_POINTER); } static void @@ -1434,12 +1445,14 @@ void e_cal_model_set_timezone (ECalModel *model, icaltimezone *zone) { + icaltimezone *old_zone; g_return_if_fail (E_IS_CAL_MODEL (model)); if (model->priv->zone == zone) return; e_table_model_pre_change (E_TABLE_MODEL (model)); + old_zone = model->priv->zone; model->priv->zone = zone; /* the timezone affects the times shown for date fields, @@ -1447,6 +1460,8 @@ e_cal_model_set_timezone (ECalModel *model, e_table_model_changed (E_TABLE_MODEL (model)); g_object_notify (G_OBJECT (model), "timezone"); + g_signal_emit (G_OBJECT (model), signals[TIMEZONE_CHANGED], 0, + old_zone, zone); } void diff --git a/calendar/gui/e-cal-model.h b/calendar/gui/e-cal-model.h index 2d30f1877f..0b31ca34ec 100644 --- a/calendar/gui/e-cal-model.h +++ b/calendar/gui/e-cal-model.h @@ -167,6 +167,9 @@ struct _ECalModelClass { void (*status_message) (ECalModel *model, const gchar *message, gdouble percent); + void (*timezone_changed) (ECalModel *model, + icaltimezone *old_zone, + icaltimezone *new_zone); }; typedef time_t (*ECalModelDefaultTimeFunc) (ECalModel *model, gpointer user_data); diff --git a/calendar/gui/e-day-view.c b/calendar/gui/e-day-view.c index 3df599f5d7..9fb0a78ee4 100644 --- a/calendar/gui/e-day-view.c +++ b/calendar/gui/e-day-view.c @@ -992,12 +992,13 @@ model_comps_deleted_cb (ETableModel *etm, gpointer data, gpointer user_data) } static void -timezone_changed_cb (ECalendarView *cal_view, icaltimezone *old_zone, +timezone_changed_cb (ECalModel *cal_model, icaltimezone *old_zone, icaltimezone *new_zone, gpointer user_data) { struct icaltimetype tt; time_t lower; - EDayView *day_view = (EDayView *) cal_view; + EDayView *day_view = (EDayView *) user_data; + ECalendarView *cal_view = (ECalendarView *) day_view; g_return_if_fail (E_IS_DAY_VIEW (day_view)); @@ -1338,10 +1339,6 @@ e_day_view_init (EDayView *day_view) GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK); e_drag_dest_add_calendar_targets (day_view->main_canvas); - - /* connect to ECalendarView's signals */ - g_signal_connect (G_OBJECT (day_view), "timezone_changed", - G_CALLBACK (timezone_changed_cb), NULL); } static void @@ -1358,6 +1355,8 @@ init_model (EDayView *day_view, ECalModel *model) G_CALLBACK (model_rows_inserted_cb), day_view); g_signal_connect (G_OBJECT (model), "comps_deleted", G_CALLBACK (model_comps_deleted_cb), day_view); + g_signal_connect (G_OBJECT (model), "timezone_changed", + G_CALLBACK (timezone_changed_cb), day_view); } /* Turn off the background of the canvas windows. This reduces flicker diff --git a/calendar/gui/e-week-view.c b/calendar/gui/e-week-view.c index c319520924..b96ec7e093 100644 --- a/calendar/gui/e-week-view.c +++ b/calendar/gui/e-week-view.c @@ -422,11 +422,12 @@ week_view_time_range_changed_cb (EWeekView *week_view, } static void -timezone_changed_cb (ECalendarView *cal_view, +timezone_changed_cb (ECalModel *cal_model, icaltimezone *old_zone, icaltimezone *new_zone, gpointer user_data) { + ECalendarView *cal_view = (ECalendarView *) user_data; struct icaltimetype tt = icaltime_null_time (); time_t lower; EWeekView *week_view = (EWeekView *) cal_view; @@ -829,10 +830,6 @@ e_week_view_init (EWeekView *week_view) week_view->move_cursor = gdk_cursor_new (GDK_FLEUR); week_view->resize_width_cursor = gdk_cursor_new (GDK_SB_H_DOUBLE_ARROW); week_view->last_cursor_set = NULL; - - /* connect to ECalendarView's signals */ - g_signal_connect (G_OBJECT (week_view), "timezone_changed", - G_CALLBACK (timezone_changed_cb), NULL); } /** @@ -844,9 +841,14 @@ e_week_view_init (EWeekView *week_view) ECalendarView * e_week_view_new (ECalModel *model) { + ECalendarView *view; g_return_val_if_fail (E_IS_CAL_MODEL (model), NULL); - return g_object_new (E_TYPE_WEEK_VIEW, "model", model, NULL); + view = g_object_new (E_TYPE_WEEK_VIEW, "model", model, NULL); + + g_signal_connect (G_OBJECT (model), "timezone_changed", + G_CALLBACK (timezone_changed_cb), view); + return view; } static void diff --git a/modules/calendar/e-cal-shell-view-private.c b/modules/calendar/e-cal-shell-view-private.c index dc30897aab..c669c29b33 100644 --- a/modules/calendar/e-cal-shell-view-private.c +++ b/modules/calendar/e-cal-shell-view-private.c @@ -26,6 +26,16 @@ #include "calendar/gui/calendar-view-factory.h" #include "widgets/menus/gal-view-factory-etable.h" +#define CHECK_NB 5 + +static const gchar * files_to_check [CHECK_NB] = { + ETC_TIMEZONE, + ETC_TIMEZONE_MAJ, + ETC_SYSCONFIG_CLOCK, + ETC_CONF_D_CLOCK, + ETC_LOCALTIME +}; + static void cal_shell_view_process_completed_tasks (ECalShellView *cal_shell_view, gboolean config_changed) @@ -416,6 +426,72 @@ e_cal_shell_view_private_init (ECalShellView *cal_shell_view, G_CALLBACK (cal_shell_view_notify_view_id_cb), NULL); } + +static void +system_timezone_monitor_changed (GFileMonitor *handle, + GFile *file, + GFile *other_file, + GFileMonitorEvent event, + gpointer user_data) +{ + ECalShellView *view = E_CAL_SHELL_VIEW (user_data); + ECalShellViewPrivate *priv = view->priv; + ECalShellContent *cal_shell_content; + icaltimezone *timezone = NULL, *current_zone = NULL; + EShellSettings *settings; + EShellBackend *shell_backend; + EShell *shell; + ECalModel *model; + const gchar *location; + + if (event != G_FILE_MONITOR_EVENT_CHANGED && + event != G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT && + event != G_FILE_MONITOR_EVENT_DELETED && + event != G_FILE_MONITOR_EVENT_CREATED) + return; + + cal_shell_content = priv->cal_shell_content; + model = e_cal_shell_content_get_model (cal_shell_content); + current_zone = e_cal_model_get_timezone (model); + timezone = e_cal_util_get_system_timezone (); + + if (!g_strcmp0 (icaltimezone_get_tzid (timezone), icaltimezone_get_tzid (current_zone))) + return; + + shell_backend = e_shell_view_get_shell_backend ((EShellView *) view); + shell = e_shell_backend_get_shell (shell_backend); + settings = e_shell_get_shell_settings (shell); + location = icaltimezone_get_location (timezone); + if (location == NULL) + location = "UTC"; + + g_object_set (settings, "cal-timezone-string", location, NULL); + g_object_set (settings, "cal-timezone", timezone, NULL); +} + +static void +init_timezone_monitors (ECalShellView *view) +{ + ECalShellViewPrivate *priv = view->priv; + gint i; + + for (i = 0; i < CHECK_NB; i++) { + GFile *file; + + file = g_file_new_for_path (files_to_check[i]); + priv->monitors[i] = g_file_monitor_file (file, + G_FILE_MONITOR_NONE, + NULL, NULL); + g_object_unref (file); + + if (priv->monitors[i]) + g_signal_connect (G_OBJECT (priv->monitors[i]), + "changed", + G_CALLBACK (system_timezone_monitor_changed), + view); + } +} + void e_cal_shell_view_private_constructed (ECalShellView *cal_shell_view) { @@ -569,6 +645,7 @@ e_cal_shell_view_private_constructed (ECalShellView *cal_shell_view) (GHookFunc) e_cal_shell_view_update_search_filter, cal_shell_view); + init_timezone_monitors (cal_shell_view); e_cal_shell_view_actions_init (cal_shell_view); e_cal_shell_view_update_sidebar (cal_shell_view); e_cal_shell_view_update_search_filter (cal_shell_view); @@ -592,6 +669,7 @@ void e_cal_shell_view_private_dispose (ECalShellView *cal_shell_view) { ECalShellViewPrivate *priv = cal_shell_view->priv; + gint i; /* Calling calendar's save state from here, because it is too late in its dispose */ if (priv->cal_shell_content) @@ -621,6 +699,11 @@ e_cal_shell_view_private_dispose (ECalShellView *cal_shell_view) g_object_unref (priv->taskpad_activity); priv->taskpad_activity = NULL; } + + for (i = 0; i < CHECK_NB; i++) { + g_object_unref (priv->monitors[i]); + priv->monitors[i] = NULL; + } } void @@ -982,7 +1065,7 @@ e_cal_shell_view_update_timezone (ECalShellView *cal_shell_view) cal_shell_sidebar = cal_shell_view->priv->cal_shell_sidebar; clients = e_cal_shell_sidebar_get_clients (cal_shell_sidebar); - + for (iter = clients; iter != NULL; iter = iter->next) { ECal *client = iter->data; diff --git a/modules/calendar/e-cal-shell-view-private.h b/modules/calendar/e-cal-shell-view-private.h index c69ffc7605..71a191f332 100644 --- a/modules/calendar/e-cal-shell-view-private.h +++ b/modules/calendar/e-cal-shell-view-private.h @@ -27,6 +27,7 @@ #include <string.h> #include <glib/gi18n.h> #include <libecal/e-cal-time-util.h> +#include <libecal/e-cal-system-timezone.h> #include <libedataserver/e-categories.h> #include <libedataserver/e-data-server-util.h> #include <libedataserver/e-sexp.h> @@ -81,6 +82,7 @@ /* ETable Specifications */ #define ETSPEC_FILENAME "e-calendar-table.etspec" +#define CHECK_NB 5 G_BEGIN_DECLS @@ -114,6 +116,8 @@ struct _ECalShellViewPrivate { EActivity *calendar_activity; EActivity *memopad_activity; EActivity *taskpad_activity; + + GFileMonitor *monitors[CHECK_NB]; }; void e_cal_shell_view_private_init |