diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2009-08-19 00:59:50 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2009-08-19 00:59:50 +0800 |
commit | 4ffe29bdee5468655dadc306f2761e2ca5469c38 (patch) | |
tree | 28f5abf6ec354844815368c96125d1f5189ec656 /calendar/gui | |
parent | 947e43871f38e1eb87f7556cec7992acb231e842 (diff) | |
download | gsoc2013-evolution-4ffe29bdee5468655dadc306f2761e2ca5469c38.tar.gz gsoc2013-evolution-4ffe29bdee5468655dadc306f2761e2ca5469c38.tar.zst gsoc2013-evolution-4ffe29bdee5468655dadc306f2761e2ca5469c38.zip |
Centralize week-start-day tracking in calendar views.
Track the value in ECalModel instead of in GnomeCalendar, EDayView and
EWeekView.
Diffstat (limited to 'calendar/gui')
-rw-r--r-- | calendar/gui/e-cal-model.c | 98 | ||||
-rw-r--r-- | calendar/gui/e-cal-model.h | 3 | ||||
-rw-r--r-- | calendar/gui/e-day-view.c | 99 | ||||
-rw-r--r-- | calendar/gui/e-day-view.h | 8 | ||||
-rw-r--r-- | calendar/gui/e-week-view.c | 102 | ||||
-rw-r--r-- | calendar/gui/e-week-view.h | 5 | ||||
-rw-r--r-- | calendar/gui/gnome-cal.c | 100 | ||||
-rw-r--r-- | calendar/gui/gnome-cal.h | 6 |
8 files changed, 146 insertions, 275 deletions
diff --git a/calendar/gui/e-cal-model.c b/calendar/gui/e-cal-model.c index 377b7a6761..133f3a9234 100644 --- a/calendar/gui/e-cal-model.c +++ b/calendar/gui/e-cal-model.c @@ -88,6 +88,9 @@ struct _ECalModelPrivate { /* Whether we display dates in 24-hour format. */ gboolean use_24_hour_format; + /* First day of the week: 0 (Monday) to 6 (Sunday) */ + gint week_start_day; + /* callback, to retrieve start time for newly added rows by click-to-add */ ECalModelDefaultTimeFunc get_default_time; gpointer get_default_time_user_data; @@ -126,7 +129,8 @@ enum { PROP_0, PROP_SHELL_SETTINGS, PROP_TIMEZONE, - PROP_USE_24_HOUR_FORMAT + PROP_USE_24_HOUR_FORMAT, + PROP_WEEK_START_DAY }; enum { @@ -177,6 +181,12 @@ cal_model_set_property (GObject *object, E_CAL_MODEL (object), g_value_get_boolean (value)); return; + + case PROP_WEEK_START_DAY: + e_cal_model_set_week_start_day ( + E_CAL_MODEL (object), + g_value_get_int (value)); + return; } G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -209,6 +219,13 @@ cal_model_get_property (GObject *object, e_cal_model_get_use_24_hour_format ( E_CAL_MODEL (object))); return; + + case PROP_WEEK_START_DAY: + g_value_set_int ( + value, + e_cal_model_get_week_start_day ( + E_CAL_MODEL (object))); + return; } G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -293,12 +310,16 @@ cal_model_constructed (GObject *object) shell_settings = e_cal_model_get_shell_settings (model); e_binding_new ( + G_OBJECT (shell_settings), "cal-timezone", + G_OBJECT (model), "timezone"); + + e_binding_new ( G_OBJECT (shell_settings), "cal-use-24-hour-format", G_OBJECT (model), "use-24-hour-format"); e_binding_new ( - G_OBJECT (shell_settings), "cal-timezone", - G_OBJECT (model), "timezone"); + G_OBJECT (shell_settings), "cal-week-start-day", + G_OBJECT (model), "week-start-day"); } static void @@ -363,6 +384,18 @@ e_cal_model_class_init (ECalModelClass *class) TRUE, G_PARAM_READWRITE)); + g_object_class_install_property ( + object_class, + PROP_WEEK_START_DAY, + g_param_spec_int ( + "week-start-day", + "Week Start Day", + NULL, + 0, /* Monday */ + 6, /* Sunday */ + 0, + G_PARAM_READWRITE)); + signals[TIME_RANGE_CHANGED] = g_signal_new ("time_range_changed", G_TYPE_FROM_CLASS (class), @@ -1279,9 +1312,6 @@ e_cal_model_get_shell_settings (ECalModel *model) return model->priv->shell_settings; } -/** - * e_cal_model_get_component_kind - */ icalcomponent_kind e_cal_model_get_component_kind (ECalModel *model) { @@ -1293,9 +1323,6 @@ e_cal_model_get_component_kind (ECalModel *model) return priv->kind; } -/** - * e_cal_model_set_component_kind - */ void e_cal_model_set_component_kind (ECalModel *model, icalcomponent_kind kind) { @@ -1307,9 +1334,6 @@ e_cal_model_set_component_kind (ECalModel *model, icalcomponent_kind kind) priv->kind = kind; } -/** - * e_cal_model_get_flags - */ ECalModelFlags e_cal_model_get_flags (ECalModel *model) { @@ -1318,9 +1342,6 @@ e_cal_model_get_flags (ECalModel *model) return model->priv->flags; } -/** - * e_cal_model_set_flags - */ void e_cal_model_set_flags (ECalModel *model, ECalModelFlags flags) { @@ -1329,9 +1350,6 @@ e_cal_model_set_flags (ECalModel *model, ECalModelFlags flags) model->priv->flags = flags; } -/** - * e_cal_model_get_timezone - */ icaltimezone * e_cal_model_get_timezone (ECalModel *model) { @@ -1340,9 +1358,6 @@ e_cal_model_get_timezone (ECalModel *model) return model->priv->zone; } -/** - * e_cal_model_set_timezone - */ void e_cal_model_set_timezone (ECalModel *model, icaltimezone *zone) @@ -1362,9 +1377,6 @@ e_cal_model_set_timezone (ECalModel *model, g_object_notify (G_OBJECT (model), "timezone"); } -/** - * e_cal_model_set_default_category - */ void e_cal_model_set_default_category (ECalModel *model, const gchar *default_category) @@ -1375,9 +1387,6 @@ e_cal_model_set_default_category (ECalModel *model, model->priv->default_category = g_strdup (default_category); } -/** - * e_cal_model_get_use_24_hour_format - */ gboolean e_cal_model_get_use_24_hour_format (ECalModel *model) { @@ -1386,9 +1395,6 @@ e_cal_model_get_use_24_hour_format (ECalModel *model) return model->priv->use_24_hour_format; } -/** - * e_cal_model_set_use_24_hour_format - */ void e_cal_model_set_use_24_hour_format (ECalModel *model, gboolean use_24_hour_format) @@ -1407,9 +1413,30 @@ e_cal_model_set_use_24_hour_format (ECalModel *model, g_object_notify (G_OBJECT (model), "use-24-hour-format"); } -/** - * e_cal_model_get_default_client - */ +gint +e_cal_model_get_week_start_day (ECalModel *model) +{ + g_return_val_if_fail (E_IS_CAL_MODEL (model), 0); + + return model->priv->week_start_day; +} + +void +e_cal_model_set_week_start_day (ECalModel *model, + gint week_start_day) +{ + g_return_if_fail (E_IS_CAL_MODEL (model)); + g_return_if_fail (week_start_day >= 0); + g_return_if_fail (week_start_day < 7); + + if (model->priv->week_start_day == week_start_day) + return; + + model->priv->week_start_day = week_start_day; + + g_object_notify (G_OBJECT (model), "week-start-day"); +} + ECal * e_cal_model_get_default_client (ECalModel *model) { @@ -1465,9 +1492,6 @@ e_cal_model_set_default_client (ECalModel *model, ECal *client) priv->default_client = client_data->client; } -/** - * e_cal_model_get_client_list - */ GList * e_cal_model_get_client_list (ECalModel *model) { @@ -1485,7 +1509,7 @@ e_cal_model_get_client_list (ECalModel *model) } /** - * e_cal_model_get_client_for_uri + * e_cal_model_get_client_for_uri: * @model: A calendar model. * @uri: Uri for the client to get. */ diff --git a/calendar/gui/e-cal-model.h b/calendar/gui/e-cal-model.h index 16e256bece..f3a23da8ad 100644 --- a/calendar/gui/e-cal-model.h +++ b/calendar/gui/e-cal-model.h @@ -188,6 +188,9 @@ gboolean e_cal_model_get_use_24_hour_format void e_cal_model_set_use_24_hour_format (ECalModel *model, gboolean use24); +gint e_cal_model_get_week_start_day (ECalModel *model); +void e_cal_model_set_week_start_day (ECalModel *model, + gint week_start_day); ECal * e_cal_model_get_default_client (ECalModel *model); void e_cal_model_set_default_client (ECalModel *model, ECal *client); diff --git a/calendar/gui/e-day-view.c b/calendar/gui/e-day-view.c index ffd980e23a..cda3d1f92c 100644 --- a/calendar/gui/e-day-view.c +++ b/calendar/gui/e-day-view.c @@ -438,7 +438,6 @@ enum { PROP_MARCUS_BAINS_DAY_VIEW_COLOR, PROP_MARCUS_BAINS_TIME_BAR_COLOR, PROP_MINS_PER_ROW, - PROP_WEEK_START_DAY, PROP_WORK_DAY_END_HOUR, PROP_WORK_DAY_END_MINUTE, PROP_WORK_DAY_START_HOUR, @@ -449,6 +448,15 @@ enum { G_DEFINE_TYPE (EDayView, e_day_view, E_TYPE_CALENDAR_VIEW) static void +day_view_notify_week_start_day_cb (EDayView *day_view) +{ + /* XXX Write a EWorkWeekView subclass, like EMonthView. */ + + if (day_view->work_week_view) + e_day_view_recalc_work_week (day_view); +} + +static void day_view_set_property (GObject *object, guint property_id, const GValue *value, @@ -479,12 +487,6 @@ day_view_set_property (GObject *object, g_value_get_int (value)); return; - case PROP_WEEK_START_DAY: - e_day_view_set_week_start_day ( - E_DAY_VIEW (object), - g_value_get_int (value)); - return; - case PROP_WORK_DAY_END_HOUR: e_day_view_set_work_day_end_hour ( E_DAY_VIEW (object), @@ -554,13 +556,6 @@ day_view_get_property (GObject *object, E_DAY_VIEW (object))); return; - case PROP_WEEK_START_DAY: - g_value_set_int ( - value, - e_day_view_get_week_start_day ( - E_DAY_VIEW (object))); - return; - case PROP_WORK_DAY_END_HOUR: g_value_set_int ( value, @@ -632,10 +627,6 @@ day_view_constructed (GObject *object) G_OBJECT (day_view), "mins-per-row"); e_binding_new ( - G_OBJECT (shell_settings), "cal-week-start-day", - G_OBJECT (day_view), "week-start-day"); - - e_binding_new ( G_OBJECT (shell_settings), "cal-work-day-end-hour", G_OBJECT (day_view), "work-day-end-hour"); @@ -654,6 +645,10 @@ day_view_constructed (GObject *object) e_binding_new ( G_OBJECT (shell_settings), "cal-working-days-bitset", G_OBJECT (day_view), "working-days"); + + g_signal_connect_swapped ( + model, "notify::week-start-day", + G_CALLBACK (day_view_notify_week_start_day_cb), day_view); } static void @@ -736,18 +731,6 @@ e_day_view_class_init (EDayViewClass *class) g_object_class_install_property ( object_class, - PROP_WEEK_START_DAY, - g_param_spec_int ( - "week-start-day", - "Week Start Day", - NULL, - 0, /* Monday */ - 6, /* Sunday */ - 0, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, PROP_WORK_DAY_END_HOUR, g_param_spec_int ( "work-day-end-hour", @@ -1103,7 +1086,6 @@ e_day_view_init (EDayView *day_view) day_view->work_day_end_hour = 17; day_view->work_day_end_minute = 0; day_view->show_event_end_times = TRUE; - day_view->week_start_day = 0; day_view->scroll_to_work_day = TRUE; day_view->marcus_bains_show_line = TRUE; @@ -2459,10 +2441,15 @@ e_day_view_find_work_week_start (EDayView *day_view, time_t start_time) { GDate date; + ECalModel *model; + gint week_start_day; gint weekday, day, i; guint offset; struct icaltimetype tt = icaltime_null_time (); + model = e_calendar_view_get_model (E_CALENDAR_VIEW (day_view)); + week_start_day = e_cal_model_get_week_start_day (model); + time_to_gdate_with_zone (&date, start_time, e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view))); /* The start of the work-week is the first working day after the @@ -2474,7 +2461,7 @@ e_day_view_find_work_week_start (EDayView *day_view, /* Calculate the first working day of the week, 0 (Sun) to 6 (Sat). It will automatically default to the week start day if no days are set as working days. */ - day = (day_view->week_start_day + 1) % 7; + day = (week_start_day + 1) % 7; for (i = 0; i < 7; i++) { if (day_view->working_days & (1 << day)) break; @@ -2784,11 +2771,16 @@ e_day_view_set_working_days (EDayView *day_view, static void e_day_view_recalc_work_week_days_shown (EDayView *day_view) { + ECalModel *model; + gint week_start_day; gint first_day, last_day, i, days_shown; gboolean has_working_days = FALSE; + model = e_calendar_view_get_model (E_CALENDAR_VIEW (day_view)); + week_start_day = e_cal_model_get_week_start_day (model); + /* Find the first working day in the week, 0 (Sun) to 6 (Sat). */ - first_day = (day_view->week_start_day + 1) % 7; + first_day = (week_start_day + 1) % 7; for (i = 0; i < 7; i++) { if (day_view->working_days & (1 << first_day)) { has_working_days = TRUE; @@ -2799,7 +2791,7 @@ e_day_view_recalc_work_week_days_shown (EDayView *day_view) if (has_working_days) { /* Now find the last working day of the week, backwards. */ - last_day = day_view->week_start_day % 7; + last_day = week_start_day % 7; for (i = 0; i < 7; i++) { if (day_view->working_days & (1 << last_day)) break; @@ -3012,34 +3004,6 @@ e_day_view_set_show_times_cb (EDayView *day_view, return TRUE; } -/* The first day of the week, 0 (Monday) to 6 (Sunday). */ -gint -e_day_view_get_week_start_day (EDayView *day_view) -{ - g_return_val_if_fail (E_IS_DAY_VIEW (day_view), 0); - - return day_view->week_start_day; -} - -void -e_day_view_set_week_start_day (EDayView *day_view, - gint week_start_day) -{ - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - g_return_if_fail (week_start_day >= 0); - g_return_if_fail (week_start_day < 7); - - if (day_view->week_start_day == week_start_day) - return; - - day_view->week_start_day = week_start_day; - - if (day_view->work_week_view) - e_day_view_recalc_work_week (day_view); - - g_object_notify (G_OBJECT (day_view), "week-start-day"); -} - static void e_day_view_recalc_work_week (EDayView *day_view) { @@ -3738,22 +3702,11 @@ e_day_view_on_event_double_click (EDayView *day_view, } static void -popup_destroyed_cb (gpointer data, GObject *where_object_was) -{ - EDayView *day_view = data; - - day_view->popup_event_day = -1; - day_view->popup_event_num = -1; -} - -static void e_day_view_show_popup_menu (EDayView *day_view, GdkEventButton *event, gint day, gint event_num) { - GtkMenu *popup; - day_view->popup_event_day = day; day_view->popup_event_num = event_num; diff --git a/calendar/gui/e-day-view.h b/calendar/gui/e-day-view.h index 683e231d14..6729186b21 100644 --- a/calendar/gui/e-day-view.h +++ b/calendar/gui/e-day-view.h @@ -314,9 +314,6 @@ struct _EDayView { /* Whether we use show event end times in the main canvas. */ gboolean show_event_end_times; - /* The first day of the week, 0 (Monday) to 6 (Sunday). */ - gint week_start_day; - /* This is set to TRUE when the widget is created, so it scrolls to the start of the working day when first shown. */ gboolean scroll_to_work_day; @@ -559,11 +556,6 @@ gboolean e_day_view_get_show_event_end_times (EDayView *day_view); void e_day_view_set_show_event_end_times (EDayView *day_view, gboolean show); -/* The first day of the week, 0 (Monday) to 6 (Sunday). */ -gint e_day_view_get_week_start_day (EDayView *day_view); -void e_day_view_set_week_start_day (EDayView *day_view, - gint week_start_day); - void e_day_view_delete_occurrence (EDayView *day_view); /* Returns the number of selected events (0 or 1 at present). */ diff --git a/calendar/gui/e-week-view.c b/calendar/gui/e-week-view.c index 58f14b9acf..8cf36bc791 100644 --- a/calendar/gui/e-week-view.c +++ b/calendar/gui/e-week-view.c @@ -197,8 +197,7 @@ G_DEFINE_TYPE (EWeekView, e_week_view, E_TYPE_CALENDAR_VIEW) enum { PROP_0, PROP_COMPRESS_WEEKEND, - PROP_SHOW_EVENT_END_TIMES, - PROP_WEEK_START_DAY + PROP_SHOW_EVENT_END_TIMES }; static gint map_left[] = {0, 1, 2, 0, 1, 2, 2}; @@ -236,6 +235,23 @@ timezone_changed_cb (ECalendarView *cal_view, } static void +week_view_notify_week_start_day_cb (EWeekView *week_view) +{ + GDate *first_day_shown; + + first_day_shown = &week_view->first_day_shown; + + e_week_view_recalc_display_start_day (week_view); + + /* Recalculate the days shown and reload if necessary. */ + if (g_date_valid (first_day_shown)) + e_week_view_set_first_day_shown (week_view, first_day_shown); + + gtk_widget_queue_draw (week_view->titles_canvas); + gtk_widget_queue_draw (week_view->main_canvas); +} + +static void week_view_set_property (GObject *object, guint property_id, const GValue *value, @@ -253,12 +269,6 @@ week_view_set_property (GObject *object, E_WEEK_VIEW (object), g_value_get_boolean (value)); return; - - case PROP_WEEK_START_DAY: - e_week_view_set_week_start_day ( - E_WEEK_VIEW (object), - g_value_get_int (value)); - return; } G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -284,13 +294,6 @@ week_view_get_property (GObject *object, e_week_view_get_show_event_end_times ( E_WEEK_VIEW (object))); return; - - case PROP_WEEK_START_DAY: - g_value_set_int ( - value, - e_week_view_get_week_start_day ( - E_WEEK_VIEW (object))); - return; } G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -315,9 +318,9 @@ week_view_constructed (GObject *object) G_OBJECT (shell_settings), "cal-show-event-end-times", G_OBJECT (week_view), "show-event-end-times"); - e_binding_new ( - G_OBJECT (shell_settings), "cal-week-start-day", - G_OBJECT (week_view), "week-start-day"); + g_signal_connect_swapped ( + model, "notify::week-start-day", + G_CALLBACK (week_view_notify_week_start_day_cb), week_view); } static void @@ -442,18 +445,6 @@ e_week_view_class_init (EWeekViewClass *class) TRUE, G_PARAM_READWRITE)); - g_object_class_install_property ( - object_class, - PROP_WEEK_START_DAY, - g_param_spec_int ( - "week-start-day", - "Week Start Day", - NULL, - 0, /* Monday */ - 6, /* Sunday */ - 0, - G_PARAM_READWRITE)); - #if 0 /* KILL-BONOBO */ /* init the accessibility support for e_week_view */ e_week_view_a11y_init (); @@ -491,7 +482,6 @@ e_week_view_init (EWeekView *week_view) week_view->columns = 2; week_view->compress_weekend = TRUE; week_view->show_event_end_times = TRUE; - week_view->week_start_day = 0; /* Monday. */ week_view->display_start_day = 0; /* Monday. */ g_date_clear (&week_view->base_date, 1); @@ -2070,50 +2060,20 @@ e_week_view_set_show_event_end_times (EWeekView *week_view, g_object_notify (G_OBJECT (week_view), "show-event-end-times"); } -/* The first day of the week, 0 (Monday) to 6 (Sunday). */ -gint -e_week_view_get_week_start_day (EWeekView *week_view) -{ - g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), 0); - - return week_view->week_start_day; -} - -void -e_week_view_set_week_start_day (EWeekView *week_view, - gint week_start_day) -{ - g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - g_return_if_fail (week_start_day >= 0); - g_return_if_fail (week_start_day < 7); - - if (week_view->week_start_day == week_start_day) - return; - - week_view->week_start_day = week_start_day; - - e_week_view_recalc_display_start_day (week_view); - - /* Recalculate the days shown and reload if necessary. */ - if (g_date_valid (&week_view->first_day_shown)) - e_week_view_set_first_day_shown (week_view, - &week_view->first_day_shown); - - gtk_widget_queue_draw (week_view->titles_canvas); - gtk_widget_queue_draw (week_view->main_canvas); - - g_object_notify (G_OBJECT (week_view), "week-start-day"); -} - static gboolean e_week_view_recalc_display_start_day (EWeekView *week_view) { + ECalModel *model; + gint week_start_day; gint display_start_day; + model = e_calendar_view_get_model (E_CALENDAR_VIEW (week_view)); + week_start_day = e_cal_model_get_week_start_day (model); + /* The display start day defaults to week_start_day, but we have to use Saturday if the weekend is compressed and week_start_day is Sunday. */ - display_start_day = week_view->week_start_day; + display_start_day = week_start_day; if (display_start_day == 6 && (!week_view->multi_week_view || week_view->compress_weekend)) @@ -4312,14 +4272,6 @@ e_week_view_key_press (GtkWidget *widget, GdkEventKey *event) #endif } -static void -popup_destroyed_cb (gpointer data, GObject *where_object_was) -{ - EWeekView *week_view = data; - - week_view->popup_event_num = -1; -} - void e_week_view_show_popup_menu (EWeekView *week_view, GdkEventButton *bevent, diff --git a/calendar/gui/e-week-view.h b/calendar/gui/e-week-view.h index ef4a5c008d..0712e1ac6f 100644 --- a/calendar/gui/e-week-view.h +++ b/calendar/gui/e-week-view.h @@ -412,11 +412,6 @@ void e_week_view_set_show_event_end_times (EWeekView *week_view, gboolean show_event_end_times); -/* The first day of the week, 0 (Monday) to 6 (Sunday). */ -gint e_week_view_get_week_start_day (EWeekView *week_view); -void e_week_view_set_week_start_day (EWeekView *week_view, - gint week_start_day); - void e_week_view_delete_occurrence (EWeekView *week_view); /* Returns the number of selected events (0 or 1 at present). */ diff --git a/calendar/gui/gnome-cal.c b/calendar/gui/gnome-cal.c index 0f7c39d11d..3594ee3cbc 100644 --- a/calendar/gui/gnome-cal.c +++ b/calendar/gui/gnome-cal.c @@ -121,9 +121,6 @@ struct _GnomeCalendarPrivate { /* The signal handler id for our GtkCalendar "day_selected" handler. */ guint day_selected_id; - /* Our current week start */ - gint week_start_day; - /* The dates currently shown. If they are -1 then we have no dates shown. We only use these to check if we need to emit a 'dates-shown-changed' signal.*/ @@ -147,8 +144,7 @@ enum { PROP_0, PROP_DATE_NAVIGATOR, PROP_SHELL_SETTINGS, - PROP_VIEW, - PROP_WEEK_START_DAY + PROP_VIEW }; enum { @@ -318,6 +314,15 @@ view_done_cb (ECalModel *model, } static void +gnome_calendar_notify_week_start_day_cb (GnomeCalendar *gcal) +{ + time_t start_time; + + start_time = gcal->priv->base_view_time; + gnome_calendar_set_selected_time_range (gcal, start_time); +} + +static void gnome_calendar_update_time_range (GnomeCalendar *gcal) { time_t start_time; @@ -360,12 +365,6 @@ gnome_calendar_set_property (GObject *object, GNOME_CALENDAR (object), g_value_get_int (value)); return; - - case PROP_WEEK_START_DAY: - gnome_calendar_set_week_start_day ( - GNOME_CALENDAR (object), - g_value_get_int (value)); - return; } G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -395,12 +394,6 @@ gnome_calendar_get_property (GObject *object, value, gnome_calendar_get_view ( GNOME_CALENDAR (object))); return; - - case PROP_WEEK_START_DAY: - g_value_set_int ( - value, gnome_calendar_get_week_start_day ( - GNOME_CALENDAR (object))); - return; } G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -490,11 +483,9 @@ gnome_calendar_constructed (GObject *object) calendar_view, "selection-changed", G_CALLBACK (view_selection_changed_cb), gcal); - /* Bind to EShellSettings -after- the views are set up. */ - - e_binding_new ( - G_OBJECT (shell_settings), "cal-week-start-day", - G_OBJECT (gcal), "week-start-day"); + g_signal_connect_swapped ( + model, "notify::week-start-day", + G_CALLBACK (gnome_calendar_notify_week_start_day_cb), gcal); gnome_calendar_update_time_range (gcal); } @@ -555,18 +546,6 @@ gnome_calendar_class_init (GnomeCalendarClass *class) 0, G_PARAM_READWRITE)); - g_object_class_install_property ( - object_class, - PROP_WEEK_START_DAY, - g_param_spec_int ( - "week-start-day", - "Week Start Day", - NULL, - 0, /* Monday */ - 6, /* Sunday */ - 0, - G_PARAM_READWRITE)); - signals[DATES_SHOWN_CHANGED] = g_signal_new ("dates_shown_changed", G_TYPE_FROM_CLASS (object_class), @@ -831,7 +810,6 @@ gnome_calendar_get_calendar_view (GnomeCalendar *gcal, GnomeCalendarViewType view_type) { g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), NULL); - g_return_val_if_fail (view_type >= 0, NULL); g_return_val_if_fail (view_type < GNOME_CAL_LAST_VIEW, NULL); return gcal->priv->views[view_type]; @@ -844,6 +822,7 @@ get_times_for_views (GnomeCalendar *gcal, GnomeCalendarViewType view_type, time_ ECalModel *model; gint shown, display_start; GDate date; + gint week_start_day; gint weekday, first_day, last_day, days_shown, i; gboolean has_working_days = FALSE; guint offset; @@ -852,6 +831,7 @@ get_times_for_views (GnomeCalendar *gcal, GnomeCalendarViewType view_type, time_ model = gnome_calendar_get_calendar_model (gcal); timezone = e_cal_model_get_timezone (model); + week_start_day = e_cal_model_get_week_start_day (model); priv = gcal->priv; @@ -872,7 +852,7 @@ get_times_for_views (GnomeCalendar *gcal, GnomeCalendarViewType view_type, time_ weekday = g_date_get_weekday (&date) % 7; /* Find the first working day in the week, 0 (Sun) to 6 (Sat). */ - first_day = (E_DAY_VIEW (priv->views[view_type])->week_start_day + 1) % 7; + first_day = (week_start_day + 1) % 7; for (i = 0; i < 7; i++) { if (E_DAY_VIEW (priv->views[view_type])->working_days & (1 << first_day)) { has_working_days = TRUE; @@ -883,7 +863,7 @@ get_times_for_views (GnomeCalendar *gcal, GnomeCalendarViewType view_type, time_ if (has_working_days) { /* Now find the last working day of the week, backwards. */ - last_day = E_DAY_VIEW (priv->views[view_type])->week_start_day % 7; + last_day = week_start_day % 7; for (i = 0; i < 7; i++) { if (E_DAY_VIEW (priv->views[view_type])->working_days & (1 << last_day)) break; @@ -1534,12 +1514,14 @@ gnome_calendar_goto_date (GnomeCalendar *gcal, { ECalModel *model; time_t new_time = 0; + gint week_start_day; gboolean need_updating = FALSE; icaltimezone *timezone; g_return_if_fail (GNOME_IS_CALENDAR(gcal)); model = gnome_calendar_get_calendar_model (gcal); + week_start_day = e_cal_model_get_week_start_day (model); timezone = e_cal_model_get_timezone (model); switch (goto_date) { @@ -1564,14 +1546,12 @@ gnome_calendar_goto_date (GnomeCalendar *gcal, break; case GNOME_CAL_GOTO_FIRST_DAY_OF_WEEK: new_time = time_week_begin_with_zone ( - gcal->priv->base_view_time, - gcal->priv->week_start_day, timezone); + gcal->priv->base_view_time, week_start_day, timezone); need_updating = TRUE; break; case GNOME_CAL_GOTO_LAST_DAY_OF_WEEK: new_time = time_week_begin_with_zone ( - gcal->priv->base_view_time, - gcal->priv->week_start_day, timezone); + gcal->priv->base_view_time, week_start_day, timezone); if (gcal->priv->current_view_type == GNOME_CAL_DAY_VIEW || gcal->priv->current_view_type == GNOME_CAL_WORK_WEEK_VIEW) { /* FIXME Shouldn't hard code work week end */ @@ -2204,32 +2184,6 @@ gnome_calendar_set_date_navigator (GnomeCalendar *gcal, g_object_notify (G_OBJECT (gcal), "date-navigator"); } -gint -gnome_calendar_get_week_start_day (GnomeCalendar *gcal) -{ - g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), 0); - - return gcal->priv->week_start_day; -} - -void -gnome_calendar_set_week_start_day (GnomeCalendar *gcal, - gint week_start_day) -{ - time_t start_time; - - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - g_return_if_fail (week_start_day >= 0); - g_return_if_fail (week_start_day < 7); - - gcal->priv->week_start_day = week_start_day; - - start_time = gcal->priv->base_view_time; - gnome_calendar_set_selected_time_range (gcal, start_time); - - g_object_notify (G_OBJECT (gcal), "week-start-day"); -} - /** * gnome_calendar_get_calendar_model: * @gcal: A calendar view. @@ -2577,6 +2531,7 @@ gnome_calendar_update_date_navigator (GnomeCalendar *gcal) GnomeCalendarPrivate *priv; ECalModel *model; time_t start, end; + gint week_start_day; GDate start_date, end_date; icaltimezone *timezone; @@ -2594,14 +2549,15 @@ gnome_calendar_update_date_navigator (GnomeCalendar *gcal) return; model = gnome_calendar_get_calendar_model (gcal); - e_cal_model_get_time_range (model, &start, &end); timezone = e_cal_model_get_timezone (model); + week_start_day = e_cal_model_get_week_start_day (model); + e_cal_model_get_time_range (model, &start, &end); time_to_gdate_with_zone (&start_date, start, timezone); if (priv->current_view_type == GNOME_CAL_MONTH_VIEW) { EWeekView *week_view = E_WEEK_VIEW (priv->views[priv->current_view_type]); - if (priv->week_start_day == 0 + if (week_start_day == 0 && (!week_view->multi_week_view || week_view->compress_weekend)) g_date_add_days (&start_date, 1); } @@ -2621,6 +2577,7 @@ gnome_calendar_on_date_navigator_selection_changed (ECalendarItem *calitem, Gnom ECalModel *model; GDate start_date, end_date, new_start_date, new_end_date; gint new_days_shown; + gint week_start_day; gboolean starts_on_week_start_day; time_t new_time, start, end; struct icaltimetype tt; @@ -2633,6 +2590,7 @@ gnome_calendar_on_date_navigator_selection_changed (ECalendarItem *calitem, Gnom view_type = gnome_calendar_get_view (gcal); model = gnome_calendar_get_calendar_model (gcal); timezone = e_cal_model_get_timezone (model); + week_start_day = e_cal_model_get_week_start_day (model); e_cal_model_get_time_range (model, &start, &end); time_to_gdate_with_zone (&start_date, start, timezone); @@ -2643,7 +2601,7 @@ gnome_calendar_on_date_navigator_selection_changed (ECalendarItem *calitem, Gnom calendar_view = gnome_calendar_get_calendar_view (gcal, view_type); week_view = E_WEEK_VIEW (calendar_view); - if (priv->week_start_day == 0 && (!week_view->multi_week_view || week_view->compress_weekend)) + if (week_start_day == 0 && (!week_view->multi_week_view || week_view->compress_weekend)) g_date_add_days (&start_date, 1); } time_to_gdate_with_zone (&end_date, end, timezone); @@ -2663,7 +2621,7 @@ gnome_calendar_on_date_navigator_selection_changed (ECalendarItem *calitem, Gnom Note that if weekends are compressed and the week start day is set to Sunday we don't actually show complete weeks in the Week view, so this may need tweaking. */ - if (g_date_get_weekday (&new_start_date) % 7 == priv->week_start_day) + if (g_date_get_weekday (&new_start_date) % 7 == week_start_day) starts_on_week_start_day = TRUE; /* Update selection to be in the new time range */ diff --git a/calendar/gui/gnome-cal.h b/calendar/gui/gnome-cal.h index 90b1d8281c..40b0adc7e9 100644 --- a/calendar/gui/gnome-cal.h +++ b/calendar/gui/gnome-cal.h @@ -108,12 +108,6 @@ ECalendar * gnome_calendar_get_date_navigator void gnome_calendar_set_date_navigator (GnomeCalendar *gcal, ECalendar *date_navigator); -gint gnome_calendar_get_week_start_day - (GnomeCalendar *gcal); -void gnome_calendar_set_week_start_day - (GnomeCalendar *gcal, - gint week_start_day); - ECalModel *gnome_calendar_get_calendar_model (GnomeCalendar *gcal); ECal *gnome_calendar_get_default_client (GnomeCalendar *gcal); |