aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--calendar/gui/e-day-view-main-item.c35
-rw-r--r--calendar/gui/e-day-view.c403
-rw-r--r--calendar/gui/e-day-view.h31
-rw-r--r--calendar/gui/gnome-cal.c87
-rw-r--r--modules/settings/e-settings-calendar-view.c34
5 files changed, 447 insertions, 143 deletions
diff --git a/calendar/gui/e-day-view-main-item.c b/calendar/gui/e-day-view-main-item.c
index 1492cdebd5..9d6b07aa13 100644
--- a/calendar/gui/e-day-view-main-item.c
+++ b/calendar/gui/e-day-view-main-item.c
@@ -1001,10 +1001,9 @@ day_view_main_item_draw (GnomeCanvasItem *canvas_item,
gint row, row_y, grid_x1, grid_x2;
gint day, grid_y1, grid_y2;
gint work_day_start_y, work_day_end_y;
- gint day_x, day_w, work_day;
+ gint day_x, day_w;
gint start_row, end_row, rect_x, rect_y, rect_width, rect_height;
struct icaltimetype day_start_tt, today_tt;
- gint weekday;
gboolean today = FALSE;
cairo_region_t *draw_region;
GdkRectangle rect;
@@ -1042,17 +1041,43 @@ day_view_main_item_draw (GnomeCanvasItem *canvas_item,
e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view)));
for (day = 0; day < day_view->days_shown; day++) {
+ GDateWeekday weekday;
+
day_start_tt = icaltime_from_timet_with_zone (
day_view->day_starts[day], FALSE,
e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view)));
- weekday = icaltime_day_of_week (day_start_tt) - 1;
- work_day = day_view->working_days & (1 << weekday);
+ switch (icaltime_day_of_week (day_start_tt)) {
+ case 1:
+ weekday = G_DATE_SUNDAY;
+ break;
+ case 2:
+ weekday = G_DATE_MONDAY;
+ break;
+ case 3:
+ weekday = G_DATE_TUESDAY;
+ break;
+ case 4:
+ weekday = G_DATE_WEDNESDAY;
+ break;
+ case 5:
+ weekday = G_DATE_THURSDAY;
+ break;
+ case 6:
+ weekday = G_DATE_FRIDAY;
+ break;
+ case 7:
+ weekday = G_DATE_SATURDAY;
+ break;
+ default:
+ weekday = G_DATE_BAD_WEEKDAY;
+ break;
+ }
day_x = day_view->day_offsets[day] - x;
day_w = day_view->day_widths[day];
- if (work_day) {
+ if (e_day_view_get_work_day (day_view, weekday)) {
if (can_draw_in_region (draw_region, day_x, 0 - y, day_w, work_day_start_y - (0 - y))) {
cairo_save (cr);
gdk_cairo_set_source_color (cr, &day_view->colors[E_DAY_VIEW_COLOR_BG_NOT_WORKING]);
diff --git a/calendar/gui/e-day-view.c b/calendar/gui/e-day-view.c
index 980c8ed990..1aa55155b1 100644
--- a/calendar/gui/e-day-view.c
+++ b/calendar/gui/e-day-view.c
@@ -410,7 +410,13 @@ enum {
PROP_MARCUS_BAINS_SHOW_LINE,
PROP_MARCUS_BAINS_DAY_VIEW_COLOR,
PROP_MARCUS_BAINS_TIME_BAR_COLOR,
- PROP_WORKING_DAYS
+ PROP_WORK_DAY_MONDAY,
+ PROP_WORK_DAY_TUESDAY,
+ PROP_WORK_DAY_WEDNESDAY,
+ PROP_WORK_DAY_THURSDAY,
+ PROP_WORK_DAY_FRIDAY,
+ PROP_WORK_DAY_SATURDAY,
+ PROP_WORK_DAY_SUNDAY
};
G_DEFINE_TYPE (EDayView, e_day_view, E_TYPE_CALENDAR_VIEW)
@@ -680,10 +686,53 @@ day_view_set_property (GObject *object,
g_value_get_string (value));
return;
- case PROP_WORKING_DAYS:
- e_day_view_set_working_days (
+ case PROP_WORK_DAY_MONDAY:
+ e_day_view_set_work_day (
E_DAY_VIEW (object),
- g_value_get_int (value));
+ G_DATE_MONDAY,
+ g_value_get_boolean (value));
+ return;
+
+ case PROP_WORK_DAY_TUESDAY:
+ e_day_view_set_work_day (
+ E_DAY_VIEW (object),
+ G_DATE_TUESDAY,
+ g_value_get_boolean (value));
+ return;
+
+ case PROP_WORK_DAY_WEDNESDAY:
+ e_day_view_set_work_day (
+ E_DAY_VIEW (object),
+ G_DATE_WEDNESDAY,
+ g_value_get_boolean (value));
+ return;
+
+ case PROP_WORK_DAY_THURSDAY:
+ e_day_view_set_work_day (
+ E_DAY_VIEW (object),
+ G_DATE_THURSDAY,
+ g_value_get_boolean (value));
+ return;
+
+ case PROP_WORK_DAY_FRIDAY:
+ e_day_view_set_work_day (
+ E_DAY_VIEW (object),
+ G_DATE_FRIDAY,
+ g_value_get_boolean (value));
+ return;
+
+ case PROP_WORK_DAY_SATURDAY:
+ e_day_view_set_work_day (
+ E_DAY_VIEW (object),
+ G_DATE_SATURDAY,
+ g_value_get_boolean (value));
+ return;
+
+ case PROP_WORK_DAY_SUNDAY:
+ e_day_view_set_work_day (
+ E_DAY_VIEW (object),
+ G_DATE_SUNDAY,
+ g_value_get_boolean (value));
return;
}
@@ -718,11 +767,60 @@ day_view_get_property (GObject *object,
E_DAY_VIEW (object)));
return;
- case PROP_WORKING_DAYS:
- g_value_set_int (
+ case PROP_WORK_DAY_MONDAY:
+ g_value_set_boolean (
value,
- e_day_view_get_working_days (
- E_DAY_VIEW (object)));
+ e_day_view_get_work_day (
+ E_DAY_VIEW (object),
+ G_DATE_MONDAY));
+ return;
+
+ case PROP_WORK_DAY_TUESDAY:
+ g_value_set_boolean (
+ value,
+ e_day_view_get_work_day (
+ E_DAY_VIEW (object),
+ G_DATE_TUESDAY));
+ return;
+
+ case PROP_WORK_DAY_WEDNESDAY:
+ g_value_set_boolean (
+ value,
+ e_day_view_get_work_day (
+ E_DAY_VIEW (object),
+ G_DATE_WEDNESDAY));
+ return;
+
+ case PROP_WORK_DAY_THURSDAY:
+ g_value_set_boolean (
+ value,
+ e_day_view_get_work_day (
+ E_DAY_VIEW (object),
+ G_DATE_THURSDAY));
+ return;
+
+ case PROP_WORK_DAY_FRIDAY:
+ g_value_set_boolean (
+ value,
+ e_day_view_get_work_day (
+ E_DAY_VIEW (object),
+ G_DATE_FRIDAY));
+ return;
+
+ case PROP_WORK_DAY_SATURDAY:
+ g_value_set_boolean (
+ value,
+ e_day_view_get_work_day (
+ E_DAY_VIEW (object),
+ G_DATE_SATURDAY));
+ return;
+
+ case PROP_WORK_DAY_SUNDAY:
+ g_value_set_boolean (
+ value,
+ e_day_view_get_work_day (
+ E_DAY_VIEW (object),
+ G_DATE_SUNDAY));
return;
}
@@ -1467,18 +1565,88 @@ e_day_view_class_init (EDayViewClass *class)
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
- /* FIXME Make this a real GFlags type. */
g_object_class_install_property (
object_class,
- PROP_WORKING_DAYS,
- g_param_spec_int (
- "working-days",
- "Working Days",
- NULL,
- 0x00,
- 0x7f,
- 0,
+ PROP_WORK_DAY_MONDAY,
+ g_param_spec_boolean (
+ "work-day-monday",
+ "Work Day: Monday",
+ "Whether Monday is a work day",
+ TRUE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (
+ object_class,
+ PROP_WORK_DAY_TUESDAY,
+ g_param_spec_boolean (
+ "work-day-tuesday",
+ "Work Day: Tuesday",
+ "Whether Tuesday is a work day",
+ TRUE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (
+ object_class,
+ PROP_WORK_DAY_WEDNESDAY,
+ g_param_spec_boolean (
+ "work-day-wednesday",
+ "Work Day: Wednesday",
+ "Whether Wednesday is a work day",
+ TRUE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (
+ object_class,
+ PROP_WORK_DAY_THURSDAY,
+ g_param_spec_boolean (
+ "work-day-thursday",
+ "Work Day: Thursday",
+ "Whether Thursday is a work day",
+ TRUE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (
+ object_class,
+ PROP_WORK_DAY_FRIDAY,
+ g_param_spec_boolean (
+ "work-day-friday",
+ "Work Day: Friday",
+ "Whether Friday is a work day",
+ TRUE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (
+ object_class,
+ PROP_WORK_DAY_SATURDAY,
+ g_param_spec_boolean (
+ "work-day-saturday",
+ "Work Day: Saturday",
+ "Whether Saturday is a work day",
+ FALSE,
G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (
+ object_class,
+ PROP_WORK_DAY_SUNDAY,
+ g_param_spec_boolean (
+ "work-day-sunday",
+ "Work Day: Sunday",
+ "Whether Sunday is a work day",
+ FALSE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
/* init the accessibility support for e_day_view */
@@ -1536,10 +1704,6 @@ e_day_view_init (EDayView *day_view)
e_day_view_recalc_num_rows (day_view);
- day_view->working_days = E_DAY_VIEW_MONDAY | E_DAY_VIEW_TUESDAY
- | E_DAY_VIEW_WEDNESDAY | E_DAY_VIEW_THURSDAY
- | E_DAY_VIEW_FRIDAY;
-
day_view->show_event_end_times = TRUE;
day_view->scroll_to_work_day = TRUE;
@@ -2874,48 +3038,42 @@ e_day_view_find_work_week_start (EDayView *day_view,
{
GDate date;
ECalModel *model;
- gint week_start_day;
- gint weekday, day, i;
guint offset;
+ GDateWeekday weekday;
+ GDateWeekday first_work_day;
struct icaltimetype tt = icaltime_null_time ();
+ icaltimezone *zone;
model = e_calendar_view_get_model (E_CALENDAR_VIEW (day_view));
- week_start_day = e_cal_model_get_week_start_day (model);
+ zone = e_cal_model_get_timezone (model);
- time_to_gdate_with_zone (&date, start_time, e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view)));
+ time_to_gdate_with_zone (&date, start_time, zone);
/* The start of the work-week is the first working day after the
* week start day. */
- /* Get the weekday corresponding to start_time, 0 (Mon) to 6 (Sun). */
- weekday = (g_date_get_weekday (&date) + 6) % 7;
+ /* Get the weekday corresponding to start_time. */
+ weekday = g_date_get_weekday (&date);
- /* Calculate the first working day of the week, 0 (Mon) to 6 (Sun).
- * It will automatically default to the week start day if no days
- * are set as working days. */
- day = week_start_day % 7;
- for (i = 0; i < 7; i++) {
- /* the working_days has stored 0 (Sun) to 6 (Sat) */
- if (day_view->working_days & (1 << ((day + 1) % 7)))
- break;
- day = (day + 1) % 7;
- }
+ /* Calculate the first working day of the week. */
+ first_work_day = e_day_view_get_first_work_day (day_view);
+ if (first_work_day == G_DATE_BAD_WEEKDAY)
+ first_work_day = e_cal_model_get_week_start_day (model) + 1;
/* Calculate how many days we need to go back to the first workday. */
- if (weekday < day) {
- offset = (7 - day + weekday) % 7;
- } else {
- offset = (weekday - day) % 7;
- }
+ if (weekday < first_work_day)
+ offset = (weekday + 7) - first_work_day;
+ else
+ offset = weekday - first_work_day;
- if (offset)
+ if (offset > 0)
g_date_subtract_days (&date, offset);
tt.year = g_date_get_year (&date);
tt.month = g_date_get_month (&date);
tt.day = g_date_get_day (&date);
- return icaltime_as_timet_with_zone (tt, e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view)));
+ return icaltime_as_timet_with_zone (tt, zone);
}
static void
@@ -3003,26 +3161,28 @@ e_day_view_set_days_shown (EDayView *day_view,
e_day_view_update_query (day_view);
}
-/* This specifies the working days in the week. The value is a bitwise
- * combination of day flags. Defaults to Mon-Fri. */
-EDayViewDays
-e_day_view_get_working_days (EDayView *day_view)
+gboolean
+e_day_view_get_work_day (EDayView *day_view,
+ GDateWeekday weekday)
{
- g_return_val_if_fail (E_IS_DAY_VIEW (day_view), 0);
+ g_return_val_if_fail (E_IS_DAY_VIEW (day_view), FALSE);
+ g_return_val_if_fail (g_date_valid_weekday (weekday), FALSE);
- return day_view->working_days;
+ return day_view->work_days[weekday];
}
void
-e_day_view_set_working_days (EDayView *day_view,
- EDayViewDays days)
+e_day_view_set_work_day (EDayView *day_view,
+ GDateWeekday weekday,
+ gboolean work_day)
{
g_return_if_fail (E_IS_DAY_VIEW (day_view));
+ g_return_if_fail (g_date_valid_weekday (weekday));
- if (day_view->working_days == days)
+ if (work_day == day_view->work_days[weekday])
return;
- day_view->working_days = days;
+ day_view->work_days[weekday] = work_day;
if (day_view->work_week_view)
e_day_view_recalc_work_week (day_view);
@@ -3031,43 +3191,124 @@ e_day_view_set_working_days (EDayView *day_view,
* the days shown, but we still want the background color to change. */
gtk_widget_queue_draw (day_view->main_canvas);
- g_object_notify (G_OBJECT (day_view), "working-days");
+ switch (weekday) {
+ case G_DATE_MONDAY:
+ g_object_notify (
+ G_OBJECT (day_view),
+ "work-day-monday");
+ break;
+ case G_DATE_TUESDAY:
+ g_object_notify (
+ G_OBJECT (day_view),
+ "work-day-tuesday");
+ break;
+ case G_DATE_WEDNESDAY:
+ g_object_notify (
+ G_OBJECT (day_view),
+ "work-day-wednesday");
+ break;
+ case G_DATE_THURSDAY:
+ g_object_notify (
+ G_OBJECT (day_view),
+ "work-day-thursday");
+ break;
+ case G_DATE_FRIDAY:
+ g_object_notify (
+ G_OBJECT (day_view),
+ "work-day-friday");
+ break;
+ case G_DATE_SATURDAY:
+ g_object_notify (
+ G_OBJECT (day_view),
+ "work-day-saturday");
+ break;
+ case G_DATE_SUNDAY:
+ g_object_notify (
+ G_OBJECT (day_view),
+ "work-day-sunday");
+ break;
+ default:
+ g_warn_if_reached ();
+ }
+}
+
+/**
+ * e_day_view_get_first_work_day:
+ * @day_view: an #EDayView
+ *
+ * Returns the first work day of the week with respect to the week start day.
+ * If no work days are set, the function returns %G_DATE_BAD_WEEKDAY.
+ *
+ * Returns: first work day of the week, or %G_DATE_BAD_WEEKDAY
+ **/
+GDateWeekday
+e_day_view_get_first_work_day (EDayView *day_view)
+{
+ ECalModel *model;
+ GDateWeekday weekday;
+ gint ii;
+
+ g_return_val_if_fail (E_IS_DAY_VIEW (day_view), G_DATE_BAD_WEEKDAY);
+
+ model = e_calendar_view_get_model (E_CALENDAR_VIEW (day_view));
+ weekday = e_cal_model_get_week_start_day (model) + 1;
+
+ for (ii = 0; ii < 7; ii++) {
+ if (e_day_view_get_work_day (day_view, weekday))
+ return weekday;
+ weekday = e_weekday_get_next (weekday);
+ }
+
+ return G_DATE_BAD_WEEKDAY;
}
-static void
-e_day_view_recalc_work_week_days_shown (EDayView *day_view)
+/**
+ * e_day_view_get_last_work_day:
+ * @day_view: an #EDayView
+ *
+ * Returns the last work day of the week with respect to the week start day.
+ * If no work days are set, the function returns %G_DATE_BAD_WEEKDAY.
+ *
+ * Returns: last work day of the week, or %G_DATE_BAD_WEEKDAY
+ **/
+GDateWeekday
+e_day_view_get_last_work_day (EDayView *day_view)
{
ECalModel *model;
- gint week_start_day;
- gint first_day, last_day, i, days_shown;
- gboolean has_working_days = FALSE;
+ GDateWeekday weekday;
+ gint ii;
+
+ g_return_val_if_fail (E_IS_DAY_VIEW (day_view), G_DATE_BAD_WEEKDAY);
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 (Mon) to 6 (Sun). */
- first_day = week_start_day % 7;
- for (i = 0; i < 7; i++) {
- /* the working_days has stored 0 (Sun) to 6 (Sat) */
- if (day_view->working_days & (1 << ((first_day + 1) % 7))) {
- has_working_days = TRUE;
- break;
- }
- first_day = (first_day + 1) % 7;
+ weekday = e_cal_model_get_week_start_day (model) + 1;
+
+ for (ii = 0; ii < 7; ii++) {
+ weekday = e_weekday_get_prev (weekday);
+ if (e_day_view_get_work_day (day_view, weekday))
+ return weekday;
}
- if (has_working_days) {
- /* Now find the last working day of the week, backwards. */
- last_day = (first_day + 6) % 7;
- for (i = 0; i < 7; i++) {
- /* the working_days has stored 0 (Sun) to 6 (Sat) */
- if (day_view->working_days & (1 << ((last_day + 1) % 7)))
- break;
- last_day = (last_day + 6) % 7;
- }
+ return G_DATE_BAD_WEEKDAY;
+}
+
+static void
+e_day_view_recalc_work_week_days_shown (EDayView *day_view)
+{
+ GDateWeekday first_work_day;
+ GDateWeekday last_work_day;
+ gint days_shown;
+
+ /* Find the first working day in the week. */
+ first_work_day = e_day_view_get_first_work_day (day_view);
+
+ if (first_work_day != G_DATE_BAD_WEEKDAY) {
+ last_work_day = e_day_view_get_last_work_day (day_view);
+
/* Now calculate the days we need to show to include all the
* working days in the week. Add 1 to make it inclusive. */
- days_shown = (last_day + 7 - first_day) % 7 + 1;
+ days_shown = e_weekday_get_days_between (
+ first_work_day, last_work_day) + 1;
} else {
/* If no working days are set, just use 7. */
days_shown = 7;
diff --git a/calendar/gui/e-day-view.h b/calendar/gui/e-day-view.h
index e359b838dc..665cae811d 100644
--- a/calendar/gui/e-day-view.h
+++ b/calendar/gui/e-day-view.h
@@ -115,19 +115,6 @@
G_BEGIN_DECLS
-/* These are used to get/set the working days in the week. The bit-flags are
- * combined together. The bits must be from 0 (Sun) to 6 (Sat) to match the
- * day values used by localtime etc. */
-typedef enum {
- E_DAY_VIEW_SUNDAY = 1 << 0,
- E_DAY_VIEW_MONDAY = 1 << 1,
- E_DAY_VIEW_TUESDAY = 1 << 2,
- E_DAY_VIEW_WEDNESDAY = 1 << 3,
- E_DAY_VIEW_THURSDAY = 1 << 4,
- E_DAY_VIEW_FRIDAY = 1 << 5,
- E_DAY_VIEW_SATURDAY = 1 << 6
-} EDayViewDays;
-
/* These are used to specify the type of an appointment. They match those
* used in EMeetingTimeSelector. */
typedef enum {
@@ -289,8 +276,9 @@ struct _EDayView {
gint last_hour_shown;
gint last_minute_shown;
- /* Bitwise combination of working days. Defaults to Mon-Fri. */
- EDayViewDays working_days;
+ /* Work days. Indices are based on GDateWeekday.
+ * The first element (G_DATE_BAD_WEEKDAY) is unused. */
+ gboolean work_days[G_DATE_SUNDAY + 1];
/* Whether we show the Marcus Bains Line in the main canvas and time canvas. */
gboolean marcus_bains_show_line;
@@ -493,11 +481,14 @@ gint e_day_view_get_days_shown (EDayView *day_view);
void e_day_view_set_days_shown (EDayView *day_view,
gint days_shown);
-/* This specifies the working days in the week. The value is a bitwise
- * combination of day flags. Defaults to Mon-Fri. */
-EDayViewDays e_day_view_get_working_days (EDayView *day_view);
-void e_day_view_set_working_days (EDayView *day_view,
- EDayViewDays days);
+/* This specifies the work days in the week. */
+gboolean e_day_view_get_work_day (EDayView *day_view,
+ GDateWeekday weekday);
+void e_day_view_set_work_day (EDayView *day_view,
+ GDateWeekday weekday,
+ gboolean work_day);
+GDateWeekday e_day_view_get_first_work_day (EDayView *day_view);
+GDateWeekday e_day_view_get_last_work_day (EDayView *day_view);
/* Whether we display the Marcus Bains Line in the main canvas and time
* canvas. */
diff --git a/calendar/gui/gnome-cal.c b/calendar/gui/gnome-cal.c
index c418c3241e..a16c782550 100644
--- a/calendar/gui/gnome-cal.c
+++ b/calendar/gui/gnome-cal.c
@@ -460,7 +460,31 @@ gnome_calendar_constructed (GObject *object)
g_object_ref_sink (calendar_view);
g_signal_connect_swapped (
- calendar_view, "notify::working-days",
+ calendar_view, "notify::working-day-monday",
+ G_CALLBACK (gnome_calendar_update_time_range), gcal);
+
+ g_signal_connect_swapped (
+ calendar_view, "notify::working-day-tuesday",
+ G_CALLBACK (gnome_calendar_update_time_range), gcal);
+
+ g_signal_connect_swapped (
+ calendar_view, "notify::working-day-wednesday",
+ G_CALLBACK (gnome_calendar_update_time_range), gcal);
+
+ g_signal_connect_swapped (
+ calendar_view, "notify::working-day-thursday",
+ G_CALLBACK (gnome_calendar_update_time_range), gcal);
+
+ g_signal_connect_swapped (
+ calendar_view, "notify::working-day-friday",
+ G_CALLBACK (gnome_calendar_update_time_range), gcal);
+
+ g_signal_connect_swapped (
+ calendar_view, "notify::working-day-saturday",
+ G_CALLBACK (gnome_calendar_update_time_range), gcal);
+
+ g_signal_connect_swapped (
+ calendar_view, "notify::working-day-sunday",
G_CALLBACK (gnome_calendar_update_time_range), gcal);
/* Week View */
@@ -902,9 +926,11 @@ get_times_for_views (GnomeCalendar *gcal,
EWeekView *week_view;
gint shown, display_start;
GDate date;
- gint week_start_day;
- gint weekday, first_day, last_day, days_shown, i;
- gboolean has_working_days = FALSE;
+ gint days_shown;
+ GDateWeekday week_start_day;
+ GDateWeekday first_work_day;
+ GDateWeekday last_work_day;
+ GDateWeekday weekday;
guint offset;
struct icaltimetype tt = icaltime_null_time ();
icaltimezone *timezone;
@@ -914,7 +940,7 @@ get_times_for_views (GnomeCalendar *gcal,
range_selected = gnome_calendar_get_range_selected (gcal);
timezone = e_cal_model_get_timezone (model);
- week_start_day = e_cal_model_get_week_start_day (model);
+ week_start_day = e_cal_model_get_week_start_day (model) + 1;
priv = gcal->priv;
@@ -933,44 +959,35 @@ get_times_for_views (GnomeCalendar *gcal,
/* The start of the work-week is the first working day after the
* week start day. */
- /* Get the weekday corresponding to start_time, 0 (Mon) to 6 (Sun). */
- weekday = (g_date_get_weekday (&date) + 6) % 7;
+ /* Get the weekday corresponding to start_time. */
+ weekday = g_date_get_weekday (&date);
- /* Find the first working day in the week, 0 (Mon) to 6 (Sun). */
- first_day = week_start_day % 7;
- for (i = 0; i < 7; i++) {
- /* the working_days has stored 0 (Sun) to 6 (Sat) */
- if (day_view->working_days & (1 << ((first_day + 1) % 7))) {
- has_working_days = TRUE;
- break;
- }
- first_day = (first_day + 1) % 7;
- }
+ /* Find the first working day of the week. */
+ first_work_day = e_day_view_get_first_work_day (day_view);
- if (has_working_days) {
- /* Now find the last working day of the week, backwards. */
- last_day = (first_day + 6) % 7;
- for (i = 0; i < 7; i++) {
- /* the working_days has stored 0 (Sun) to 6 (Sat) */
- if (day_view->working_days & (1 << ((last_day + 1) % 7)))
- break;
- last_day = (last_day + 6) % 7;
- }
- /* Now calculate the days we need to show to include all the
- * working days in the week. Add 1 to make it inclusive. */
- days_shown = (last_day + 7 - first_day) % 7 + 1;
+ if (first_work_day != G_DATE_BAD_WEEKDAY) {
+ last_work_day = e_day_view_get_last_work_day (day_view);
+
+ /* Now calculate the days we need to show to include
+ * all the working days in the week. Add 1 to make it
+ * inclusive. */
+ days_shown = e_weekday_get_days_between (
+ first_work_day, last_work_day) + 1;
} else {
/* If no working days are set, just use 7. */
days_shown = 7;
}
+ if (first_work_day == G_DATE_BAD_WEEKDAY)
+ first_work_day = week_start_day;
+
/* Calculate how many days we need to go back to the first workday. */
- if (weekday < first_day) {
- offset = (7 - first_day + weekday) % 7;
- } else {
- offset = (weekday - first_day) % 7;
- }
- if (offset)
+ if (weekday < first_work_day)
+ offset = (weekday + 7) - first_work_day;
+ else
+ offset = weekday - first_work_day;
+
+ if (offset > 0)
g_date_subtract_days (&date, offset);
tt.year = g_date_get_year (&date);
diff --git a/modules/settings/e-settings-calendar-view.c b/modules/settings/e-settings-calendar-view.c
index e1a0d47f2f..ced8a013cd 100644
--- a/modules/settings/e-settings-calendar-view.c
+++ b/modules/settings/e-settings-calendar-view.c
@@ -84,8 +84,38 @@ settings_calendar_view_constructed (GObject *object)
G_BINDING_SYNC_CREATE);
g_object_bind_property (
- shell_settings, "cal-working-days-bitset",
- extensible, "working-days",
+ shell_settings, "cal-working-days-monday",
+ extensible, "work-day-monday",
+ G_BINDING_SYNC_CREATE);
+
+ g_object_bind_property (
+ shell_settings, "cal-working-days-tuesday",
+ extensible, "work-day-tuesday",
+ G_BINDING_SYNC_CREATE);
+
+ g_object_bind_property (
+ shell_settings, "cal-working-days-wednesday",
+ extensible, "work-day-wednesday",
+ G_BINDING_SYNC_CREATE);
+
+ g_object_bind_property (
+ shell_settings, "cal-working-days-thursday",
+ extensible, "work-day-thursday",
+ G_BINDING_SYNC_CREATE);
+
+ g_object_bind_property (
+ shell_settings, "cal-working-days-friday",
+ extensible, "work-day-friday",
+ G_BINDING_SYNC_CREATE);
+
+ g_object_bind_property (
+ shell_settings, "cal-working-days-saturday",
+ extensible, "work-day-saturday",
+ G_BINDING_SYNC_CREATE);
+
+ g_object_bind_property (
+ shell_settings, "cal-working-days-sunday",
+ extensible, "work-day-sunday",
G_BINDING_SYNC_CREATE);
}