aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2013-03-07 09:27:31 +0800
committerMatthew Barnes <mbarnes@redhat.com>2013-03-17 20:49:12 +0800
commit3b205698762afcd86ac79595960253d84aff5487 (patch)
treef0f1ae05b5bd7fbd0008dbd8dbdd10908ebc1c6c /calendar/gui
parent5a7097278a6f6eb2a984d9e0c742342135971c35 (diff)
downloadgsoc2013-evolution-3b205698762afcd86ac79595960253d84aff5487.tar.gz
gsoc2013-evolution-3b205698762afcd86ac79595960253d84aff5487.tar.zst
gsoc2013-evolution-3b205698762afcd86ac79595960253d84aff5487.zip
Convert all "week-start-day" properties to GDateWeekday.
Diffstat (limited to 'calendar/gui')
-rw-r--r--calendar/gui/dialogs/comp-editor.c19
-rw-r--r--calendar/gui/dialogs/comp-editor.h4
-rw-r--r--calendar/gui/dialogs/recurrence-page.c126
-rw-r--r--calendar/gui/e-cal-model.c31
-rw-r--r--calendar/gui/e-cal-model.h4
-rw-r--r--calendar/gui/e-day-view.c2
-rw-r--r--calendar/gui/e-week-view-layout.c38
-rw-r--r--calendar/gui/e-week-view-layout.h50
-rw-r--r--calendar/gui/e-week-view-titles-item.c19
-rw-r--r--calendar/gui/e-week-view.c85
-rw-r--r--calendar/gui/e-week-view.h9
-rw-r--r--calendar/gui/e-weekday-chooser.c274
-rw-r--r--calendar/gui/e-weekday-chooser.h22
-rw-r--r--calendar/gui/ea-week-view-cell.c37
-rw-r--r--calendar/gui/gnome-cal.c34
-rw-r--r--calendar/gui/print.c108
16 files changed, 496 insertions, 366 deletions
diff --git a/calendar/gui/dialogs/comp-editor.c b/calendar/gui/dialogs/comp-editor.c
index cb7de1f881..f36bebc694 100644
--- a/calendar/gui/dialogs/comp-editor.c
+++ b/calendar/gui/dialogs/comp-editor.c
@@ -108,7 +108,7 @@ struct _CompEditorPrivate {
icaltimezone *zone;
gboolean use_24_hour_format;
- gint week_start_day;
+ GDateWeekday week_start_day;
gint work_day_end_hour;
gint work_day_end_minute;
@@ -1428,7 +1428,7 @@ comp_editor_set_property (GObject *object,
case PROP_WEEK_START_DAY:
comp_editor_set_week_start_day (
COMP_EDITOR (object),
- g_value_get_int (value));
+ g_value_get_enum (value));
return;
case PROP_WORK_DAY_END_HOUR:
@@ -1515,7 +1515,7 @@ comp_editor_get_property (GObject *object,
return;
case PROP_WEEK_START_DAY:
- g_value_set_int (
+ g_value_set_enum (
value, comp_editor_get_week_start_day (
COMP_EDITOR (object)));
return;
@@ -1909,13 +1909,12 @@ comp_editor_class_init (CompEditorClass *class)
g_object_class_install_property (
object_class,
PROP_WEEK_START_DAY,
- g_param_spec_int (
+ g_param_spec_enum (
"week-start-day",
"Week Start Day",
NULL,
- 0, /* Monday */
- 6, /* Sunday */
- 0,
+ E_TYPE_DATE_WEEKDAY,
+ G_DATE_MONDAY,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
@@ -2557,7 +2556,7 @@ comp_editor_set_use_24_hour_format (CompEditor *editor,
g_object_notify (G_OBJECT (editor), "use-24-hour-format");
}
-gint
+GDateWeekday
comp_editor_get_week_start_day (CompEditor *editor)
{
g_return_val_if_fail (IS_COMP_EDITOR (editor), 0);
@@ -2567,10 +2566,10 @@ comp_editor_get_week_start_day (CompEditor *editor)
void
comp_editor_set_week_start_day (CompEditor *editor,
- gint week_start_day)
+ GDateWeekday week_start_day)
{
g_return_if_fail (IS_COMP_EDITOR (editor));
- g_return_if_fail (week_start_day >= 0 && week_start_day < 7);
+ g_return_if_fail (g_date_valid_weekday (week_start_day));
if (week_start_day == editor->priv->week_start_day)
return;
diff --git a/calendar/gui/dialogs/comp-editor.h b/calendar/gui/dialogs/comp-editor.h
index b343081dcc..6721a87978 100644
--- a/calendar/gui/dialogs/comp-editor.h
+++ b/calendar/gui/dialogs/comp-editor.h
@@ -134,9 +134,9 @@ gboolean comp_editor_get_use_24_hour_format
void comp_editor_set_use_24_hour_format
(CompEditor *editor,
gboolean use_24_hour_format);
-gint comp_editor_get_week_start_day (CompEditor *editor);
+GDateWeekday comp_editor_get_week_start_day (CompEditor *editor);
void comp_editor_set_week_start_day (CompEditor *editor,
- gint week_start_day);
+ GDateWeekday week_start_day);
gint comp_editor_get_work_day_end_hour
(CompEditor *editor);
void comp_editor_set_work_day_end_hour
diff --git a/calendar/gui/dialogs/recurrence-page.c b/calendar/gui/dialogs/recurrence-page.c
index 3dd6d7ce2c..3ceb08476e 100644
--- a/calendar/gui/dialogs/recurrence-page.c
+++ b/calendar/gui/dialogs/recurrence-page.c
@@ -748,8 +748,33 @@ simple_recur_to_comp (RecurrencePage *rpage,
r.freq = e_dialog_combo_box_get (priv->interval_unit_combo, freq_map);
r.interval = gtk_spin_button_get_value_as_int (
GTK_SPIN_BUTTON (priv->interval_value));
- r.week_start = ICAL_SUNDAY_WEEKDAY +
- comp_editor_get_week_start_day (editor);
+
+ switch (comp_editor_get_week_start_day (editor)) {
+ case G_DATE_MONDAY:
+ r.week_start = ICAL_MONDAY_WEEKDAY;
+ break;
+ case G_DATE_TUESDAY:
+ r.week_start = ICAL_TUESDAY_WEEKDAY;
+ break;
+ case G_DATE_WEDNESDAY:
+ r.week_start = ICAL_WEDNESDAY_WEEKDAY;
+ break;
+ case G_DATE_THURSDAY:
+ r.week_start = ICAL_THURSDAY_WEEKDAY;
+ break;
+ case G_DATE_FRIDAY:
+ r.week_start = ICAL_FRIDAY_WEEKDAY;
+ break;
+ case G_DATE_SATURDAY:
+ r.week_start = ICAL_SATURDAY_WEEKDAY;
+ break;
+ case G_DATE_SUNDAY:
+ r.week_start = ICAL_SUNDAY_WEEKDAY;
+ break;
+ default:
+ g_warn_if_reached ();
+ break;
+ }
/* Frequency-specific data */
@@ -759,36 +784,35 @@ simple_recur_to_comp (RecurrencePage *rpage,
break;
case ICAL_WEEKLY_RECURRENCE: {
- guint8 day_mask;
+ EWeekdayChooser *chooser;
gint i;
g_return_if_fail (gtk_bin_get_child (GTK_BIN (priv->special)) != NULL);
g_return_if_fail (E_IS_WEEKDAY_CHOOSER (priv->weekday_chooser));
- day_mask = e_weekday_chooser_get_days (
- E_WEEKDAY_CHOOSER (priv->weekday_chooser));
+ chooser = E_WEEKDAY_CHOOSER (priv->weekday_chooser);
i = 0;
- if (day_mask & (1 << 0))
+ if (e_weekday_chooser_get_selected (chooser, E_DATE_SUNDAY))
r.by_day[i++] = ICAL_SUNDAY_WEEKDAY;
- if (day_mask & (1 << 1))
+ if (e_weekday_chooser_get_selected (chooser, E_DATE_MONDAY))
r.by_day[i++] = ICAL_MONDAY_WEEKDAY;
- if (day_mask & (1 << 2))
+ if (e_weekday_chooser_get_selected (chooser, E_DATE_TUESDAY))
r.by_day[i++] = ICAL_TUESDAY_WEEKDAY;
- if (day_mask & (1 << 3))
+ if (e_weekday_chooser_get_selected (chooser, E_DATE_WEDNESDAY))
r.by_day[i++] = ICAL_WEDNESDAY_WEEKDAY;
- if (day_mask & (1 << 4))
+ if (e_weekday_chooser_get_selected (chooser, E_DATE_THURSDAY))
r.by_day[i++] = ICAL_THURSDAY_WEEKDAY;
- if (day_mask & (1 << 5))
+ if (e_weekday_chooser_get_selected (chooser, E_DATE_FRIDAY))
r.by_day[i++] = ICAL_FRIDAY_WEEKDAY;
- if (day_mask & (1 << 6))
+ if (e_weekday_chooser_get_selected (chooser, E_DATE_SATURDAY))
r.by_day[i] = ICAL_SATURDAY_WEEKDAY;
break;
@@ -1058,7 +1082,27 @@ make_weekly_special (RecurrencePage *rpage)
/* Set the weekdays */
- e_weekday_chooser_set_days (chooser, priv->weekday_day_mask);
+ e_weekday_chooser_set_selected (
+ chooser, G_DATE_SUNDAY,
+ (priv->weekday_day_mask & (1 << 0)) != 0);
+ e_weekday_chooser_set_selected (
+ chooser, G_DATE_MONDAY,
+ (priv->weekday_day_mask & (1 << 1)) != 0);
+ e_weekday_chooser_set_selected (
+ chooser, G_DATE_TUESDAY,
+ (priv->weekday_day_mask & (1 << 2)) != 0);
+ e_weekday_chooser_set_selected (
+ chooser, G_DATE_WEDNESDAY,
+ (priv->weekday_day_mask & (1 << 3)) != 0);
+ e_weekday_chooser_set_selected (
+ chooser, G_DATE_THURSDAY,
+ (priv->weekday_day_mask & (1 << 4)) != 0);
+ e_weekday_chooser_set_selected (
+ chooser, G_DATE_FRIDAY,
+ (priv->weekday_day_mask & (1 << 5)) != 0);
+ e_weekday_chooser_set_selected (
+ chooser, G_DATE_SATURDAY,
+ (priv->weekday_day_mask & (1 << 6)) != 0);
g_signal_connect_swapped (
chooser, "changed",
@@ -2086,12 +2130,56 @@ recurrence_page_set_dates (CompEditorPage *page,
priv->weekday_blocked_day_mask = mask;
if (priv->weekday_chooser != NULL) {
- e_weekday_chooser_set_days (
- E_WEEKDAY_CHOOSER (priv->weekday_chooser),
- priv->weekday_day_mask);
- e_weekday_chooser_set_blocked_days (
- E_WEEKDAY_CHOOSER (priv->weekday_chooser),
- priv->weekday_blocked_day_mask);
+ EWeekdayChooser *chooser;
+ guint8 mask;
+
+ chooser = E_WEEKDAY_CHOOSER (priv->weekday_chooser);
+
+ mask = priv->weekday_day_mask;
+ e_weekday_chooser_set_selected (
+ chooser, G_DATE_SUNDAY,
+ (mask & (1 << 0)) != 0);
+ e_weekday_chooser_set_selected (
+ chooser, G_DATE_MONDAY,
+ (mask & (1 << 1)) != 0);
+ e_weekday_chooser_set_selected (
+ chooser, G_DATE_TUESDAY,
+ (mask & (1 << 2)) != 0);
+ e_weekday_chooser_set_selected (
+ chooser, G_DATE_WEDNESDAY,
+ (mask & (1 << 3)) != 0);
+ e_weekday_chooser_set_selected (
+ chooser, G_DATE_THURSDAY,
+ (mask & (1 << 4)) != 0);
+ e_weekday_chooser_set_selected (
+ chooser, G_DATE_FRIDAY,
+ (mask & (1 << 5)) != 0);
+ e_weekday_chooser_set_selected (
+ chooser, G_DATE_SATURDAY,
+ (mask & (1 << 6)) != 0);
+
+ mask = priv->weekday_blocked_day_mask;
+ e_weekday_chooser_set_blocked (
+ chooser, G_DATE_SUNDAY,
+ (mask & (1 << 0)) != 0);
+ e_weekday_chooser_set_blocked (
+ chooser, G_DATE_MONDAY,
+ (mask & (1 << 1)) != 0);
+ e_weekday_chooser_set_blocked (
+ chooser, G_DATE_TUESDAY,
+ (mask & (1 << 2)) != 0);
+ e_weekday_chooser_set_blocked (
+ chooser, G_DATE_WEDNESDAY,
+ (mask & (1 << 3)) != 0);
+ e_weekday_chooser_set_blocked (
+ chooser, G_DATE_THURSDAY,
+ (mask & (1 << 4)) != 0);
+ e_weekday_chooser_set_blocked (
+ chooser, G_DATE_FRIDAY,
+ (mask & (1 << 5)) != 0);
+ e_weekday_chooser_set_blocked (
+ chooser, G_DATE_SATURDAY,
+ (mask & (1 << 6)) != 0);
}
}
diff --git a/calendar/gui/e-cal-model.c b/calendar/gui/e-cal-model.c
index 1213ff190d..a13e6fe5ef 100644
--- a/calendar/gui/e-cal-model.c
+++ b/calendar/gui/e-cal-model.c
@@ -94,8 +94,8 @@ struct _ECalModelPrivate {
/* Whether to compress weekends into one cell. */
gboolean compress_weekend;
- /* First day of the week: 0 (Monday) to 6 (Sunday) */
- gint week_start_day;
+ /* First day of the week */
+ GDateWeekday week_start_day;
/* Work days. Indices are based on GDateWeekday.
* The first element (G_DATE_BAD_WEEKDAY) is unused. */
@@ -273,7 +273,7 @@ cal_model_set_property (GObject *object,
case PROP_WEEK_START_DAY:
e_cal_model_set_week_start_day (
E_CAL_MODEL (object),
- g_value_get_int (value));
+ g_value_get_enum (value));
return;
case PROP_WORK_DAY_MONDAY:
@@ -424,7 +424,7 @@ cal_model_get_property (GObject *object,
return;
case PROP_WEEK_START_DAY:
- g_value_set_int (
+ g_value_set_enum (
value,
e_cal_model_get_week_start_day (
E_CAL_MODEL (object)));
@@ -732,14 +732,14 @@ e_cal_model_class_init (ECalModelClass *class)
g_object_class_install_property (
object_class,
PROP_WEEK_START_DAY,
- g_param_spec_int (
+ g_param_spec_enum (
"week-start-day",
"Week Start Day",
NULL,
- 0, /* Monday */
- 6, /* Sunday */
- 0,
- G_PARAM_READWRITE));
+ E_TYPE_DATE_WEEKDAY,
+ G_DATE_MONDAY,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT));
g_object_class_install_property (
object_class,
@@ -2186,21 +2186,20 @@ e_cal_model_set_use_default_reminder (ECalModel *model,
g_object_notify (G_OBJECT (model), "use-default-reminder");
}
-gint
+GDateWeekday
e_cal_model_get_week_start_day (ECalModel *model)
{
- g_return_val_if_fail (E_IS_CAL_MODEL (model), 0);
+ g_return_val_if_fail (E_IS_CAL_MODEL (model), G_DATE_BAD_WEEKDAY);
return model->priv->week_start_day;
}
void
e_cal_model_set_week_start_day (ECalModel *model,
- gint week_start_day)
+ GDateWeekday 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);
+ g_return_if_fail (g_date_valid_weekday (week_start_day));
if (model->priv->week_start_day == week_start_day)
return;
@@ -2281,7 +2280,7 @@ e_cal_model_get_work_day_first (ECalModel *model)
g_return_val_if_fail (E_IS_CAL_MODEL (model), G_DATE_BAD_WEEKDAY);
- weekday = e_cal_model_get_week_start_day (model) + 1;
+ weekday = e_cal_model_get_week_start_day (model);
for (ii = 0; ii < 7; ii++) {
if (e_cal_model_get_work_day (model, weekday))
@@ -2309,7 +2308,7 @@ e_cal_model_get_work_day_last (ECalModel *model)
g_return_val_if_fail (E_IS_CAL_MODEL (model), G_DATE_BAD_WEEKDAY);
- weekday = e_cal_model_get_week_start_day (model) + 1;
+ weekday = e_cal_model_get_week_start_day (model);
for (ii = 0; ii < 7; ii++) {
weekday = e_weekday_get_prev (weekday);
diff --git a/calendar/gui/e-cal-model.h b/calendar/gui/e-cal-model.h
index 610b227f2f..f9eebad035 100644
--- a/calendar/gui/e-cal-model.h
+++ b/calendar/gui/e-cal-model.h
@@ -220,9 +220,9 @@ gboolean e_cal_model_get_use_default_reminder
void e_cal_model_set_use_default_reminder
(ECalModel *model,
gboolean use_def_reminder);
-gint e_cal_model_get_week_start_day (ECalModel *model);
+GDateWeekday e_cal_model_get_week_start_day (ECalModel *model);
void e_cal_model_set_week_start_day (ECalModel *model,
- gint week_start_day);
+ GDateWeekday week_start_day);
gboolean e_cal_model_get_work_day (ECalModel *model,
GDateWeekday weekday);
void e_cal_model_set_work_day (ECalModel *model,
diff --git a/calendar/gui/e-day-view.c b/calendar/gui/e-day-view.c
index d96decd6be..4f0ca4e2bd 100644
--- a/calendar/gui/e-day-view.c
+++ b/calendar/gui/e-day-view.c
@@ -3016,7 +3016,7 @@ e_day_view_find_work_week_start (EDayView *day_view,
/* Calculate the first working day of the week. */
first_work_day = e_cal_model_get_work_day_first (model);
if (first_work_day == G_DATE_BAD_WEEKDAY)
- first_work_day = e_cal_model_get_week_start_day (model) + 1;
+ first_work_day = e_cal_model_get_week_start_day (model);
/* Calculate how many days we need to go back to the first workday. */
if (weekday < first_work_day)
diff --git a/calendar/gui/e-week-view-layout.c b/calendar/gui/e-week-view-layout.c
index d725ec0c59..7c39e8c459 100644
--- a/calendar/gui/e-week-view-layout.c
+++ b/calendar/gui/e-week-view-layout.c
@@ -44,7 +44,7 @@ static gint e_week_view_find_day (time_t time_to_find,
time_t *day_starts);
static gint e_week_view_find_span_end (gboolean multi_week_view,
gboolean compress_weekend,
- gint display_start_day,
+ GDateWeekday display_start_day,
gint day);
GArray *
@@ -259,7 +259,7 @@ e_week_view_find_day (time_t time_to_find,
static gint
e_week_view_find_span_end (gboolean multi_week_view,
gboolean compress_weekend,
- gint display_start_day,
+ GDateWeekday display_start_day,
gint day)
{
gint week, col, sat_col, end_col;
@@ -274,7 +274,8 @@ e_week_view_find_span_end (gboolean multi_week_view,
/* If the weekend is compressed we must end any spans on
* Saturday and Sunday. */
if (compress_weekend) {
- sat_col = (5 + 7 - display_start_day) % 7;
+ sat_col = e_weekday_get_days_between (
+ display_start_day, G_DATE_SATURDAY);
if (col <= sat_col)
end_col = sat_col;
else if (col == sat_col + 1)
@@ -291,13 +292,14 @@ void
e_week_view_layout_get_day_position (gint day,
gboolean multi_week_view,
gint weeks_shown,
- gint display_start_day,
+ GDateWeekday display_start_day,
gboolean compress_weekend,
gint *day_x,
gint *day_y,
gint *rows)
{
- gint week, day_of_week, col, weekend_col;
+ GDateWeekday day_of_week;
+ gint week, col, weekend_col;
*day_x = *day_y = *rows = 0;
g_return_if_fail (day >= 0);
@@ -307,12 +309,12 @@ e_week_view_layout_get_day_position (gint day,
week = day / 7;
col = day % 7;
- day_of_week = (display_start_day + day) % 7;
- if (compress_weekend && day_of_week >= 5) {
+ day_of_week = e_weekday_add_days (display_start_day, day);
+ if (compress_weekend && day_of_week >= G_DATE_SATURDAY) {
/* In the compressed view Saturday is above Sunday and
* both have just one row as opposed to 2 for all the
* other days. */
- if (day_of_week == 5) {
+ if (day_of_week == G_DATE_SATURDAY) {
*day_y = week * 2;
*rows = 1;
} else {
@@ -326,9 +328,9 @@ e_week_view_layout_get_day_position (gint day,
/* If the weekend is compressed and the day is after
* the weekend we have to move back a column. */
if (compress_weekend) {
- /* Calculate where the weekend column is.
- * Note that 5 is Saturday. */
- weekend_col = (5 + 7 - display_start_day) % 7;
+ /* Calculate where the weekend column is. */
+ weekend_col = e_weekday_get_days_between (
+ display_start_day, G_DATE_SATURDAY);
if (col > weekend_col)
col--;
}
@@ -445,18 +447,20 @@ e_week_view_layout_get_span_position (EWeekViewEvent *event,
EWeekViewEventSpan *span,
gint rows_per_cell,
gint rows_per_compressed_cell,
- gint display_start_day,
+ GDateWeekday display_start_day,
gboolean multi_week_view,
gboolean compress_weekend,
gint *span_num_days)
{
- gint end_day_of_week;
+ GDateWeekday end_day_of_week;
+ guint n_days;
if (multi_week_view && span->row >= rows_per_cell)
return FALSE;
- end_day_of_week = (display_start_day + span->start_day
- + span->num_days - 1) % 7;
+ n_days = span->start_day + span->num_days - 1;
+ end_day_of_week = e_weekday_add_days (display_start_day, n_days);
+
*span_num_days = span->num_days;
/* Check if the row will not be visible in compressed cells. */
if (span->row >= rows_per_compressed_cell) {
@@ -466,13 +470,13 @@ e_week_view_layout_get_span_position (EWeekViewEvent *event,
* we skip it, else we shorten it. If it ends
* on a Sunday it must be 1 day long and we
* skip it. */
- if (end_day_of_week == 5) { /* Sat */
+ if (end_day_of_week == G_DATE_SATURDAY) {
if (*span_num_days == 1) {
return FALSE;
} else {
(*span_num_days)--;
}
- } else if (end_day_of_week == 6) { /* Sun */
+ } else if (end_day_of_week == G_DATE_SUNDAY) {
return FALSE;
}
}
diff --git a/calendar/gui/e-week-view-layout.h b/calendar/gui/e-week-view-layout.h
index 5f1e2870d4..a4a87773d6 100644
--- a/calendar/gui/e-week-view-layout.h
+++ b/calendar/gui/e-week-view-layout.h
@@ -31,35 +31,37 @@ G_BEGIN_DECLS
/* I've split these functions away from EWeekView so we can use them for
* printing. */
-GArray * e_week_view_layout_events (GArray *events,
- GArray *old_spans,
- gboolean multi_week_view,
- gint weeks_shown,
- gboolean compress_weekend,
- gint start_weekday,
- time_t *day_starts,
- gint *rows_per_day);
+GArray * e_week_view_layout_events (GArray *events,
+ GArray *old_spans,
+ gboolean multi_week_view,
+ gint weeks_shown,
+ gboolean compress_weekend,
+ gint start_weekday,
+ time_t *day_starts,
+ gint *rows_per_day);
/* Returns which 'cell' in the table the day appears in. Note that most days
* have a height of 2 rows, but Sat/Sun are sometimes compressed so they have
* a height of only 1 row. */
-void e_week_view_layout_get_day_position (gint day,
- gboolean multi_week_view,
- gint weeks_shown,
- gint display_start_day,
- gboolean compress_weekend,
- gint *cell_x,
- gint *cell_y,
- gint *rows);
+void e_week_view_layout_get_day_position
+ (gint day,
+ gboolean multi_week_view,
+ gint weeks_shown,
+ GDateWeekday display_start_day,
+ gboolean compress_weekend,
+ gint *cell_x,
+ gint *cell_y,
+ gint *rows);
-gboolean e_week_view_layout_get_span_position (EWeekViewEvent *event,
- EWeekViewEventSpan *span,
- gint rows_per_cell,
- gint rows_per_compressed_cell,
- gint display_start_day,
- gboolean multi_week_view,
- gboolean compress_weekend,
- gint *span_num_days);
+gboolean e_week_view_layout_get_span_position
+ (EWeekViewEvent *event,
+ EWeekViewEventSpan *span,
+ gint rows_per_cell,
+ gint rows_per_compressed_cell,
+ GDateWeekday display_start_day,
+ gboolean multi_week_view,
+ gboolean compress_weekend,
+ gint *span_num_days);
G_END_DECLS
diff --git a/calendar/gui/e-week-view-titles-item.c b/calendar/gui/e-week-view-titles-item.c
index 3081c5ed5d..49bbe48647 100644
--- a/calendar/gui/e-week-view-titles-item.c
+++ b/calendar/gui/e-week-view-titles-item.c
@@ -133,7 +133,7 @@ week_view_titles_item_draw (GnomeCanvasItem *canvas_item,
GtkAllocation allocation;
gboolean abbreviated;
gboolean compress_weekend;
- gint weekday;
+ GDateWeekday weekday;
PangoLayout *layout;
titles_item = E_WEEK_VIEW_TITLES_ITEM (canvas_item);
@@ -173,9 +173,9 @@ week_view_titles_item_draw (GnomeCanvasItem *canvas_item,
/* Draw the date. Set a clipping rectangle so we don't draw over the
* next day. */
- weekday = week_view->display_start_day;
+ weekday = e_week_view_get_display_start_day (week_view);
for (col = 0; col < week_view->columns; col++) {
- if (weekday == 5 && compress_weekend)
+ if (weekday == G_DATE_SATURDAY && compress_weekend)
g_snprintf (
buffer, sizeof (buffer), "%s/%s",
e_get_weekday_name (G_DATE_SATURDAY, TRUE),
@@ -183,7 +183,7 @@ week_view_titles_item_draw (GnomeCanvasItem *canvas_item,
else
g_snprintf (
buffer, sizeof (buffer), "%s",
- e_get_weekday_name (weekday + 1, abbreviated));
+ e_get_weekday_name (weekday, abbreviated));
cairo_save (cr);
@@ -193,7 +193,7 @@ week_view_titles_item_draw (GnomeCanvasItem *canvas_item,
week_view->col_widths[col], allocation.height - 2);
cairo_clip (cr);
- if (weekday == 5 && compress_weekend)
+ if (weekday == G_DATE_SATURDAY && compress_weekend)
date_width = week_view->abbr_day_widths[5]
+ week_view->slash_width
+ week_view->abbr_day_widths[6];
@@ -234,12 +234,9 @@ week_view_titles_item_draw (GnomeCanvasItem *canvas_item,
cairo_fill (cr);
}
- if (weekday == 5 && compress_weekend)
- weekday += 2;
- else
- weekday++;
-
- weekday = weekday % 7;
+ weekday = e_weekday_get_next (weekday);
+ if (weekday == G_DATE_SUNDAY && compress_weekend)
+ weekday = e_weekday_get_next (weekday);
}
g_object_unref (layout);
diff --git a/calendar/gui/e-week-view.c b/calendar/gui/e-week-view.c
index c80d9f3a57..7af4d8590c 100644
--- a/calendar/gui/e-week-view.c
+++ b/calendar/gui/e-week-view.c
@@ -98,6 +98,11 @@ struct _EWeekViewPrivate {
/* Whether to update the base date when the time range changes. */
gboolean update_base_date;
+
+ /* The first day of the week we display. This will usually be
+ * week_start_day, but if the Sat & Sun are compressed and the
+ * week starts on Sunday then we have to use Saturday. */
+ GDateWeekday display_start_day;
};
typedef struct {
@@ -373,7 +378,9 @@ week_view_time_range_changed_cb (EWeekView *week_view,
ECalModel *model)
{
GDate date, base_date;
- gint day_offset, weekday, week_start_offset;
+ GDateWeekday weekday;
+ GDateWeekday display_start_day;
+ guint day_offset, week_start_offset;
gint num_days;
gboolean update_adjustment_value = FALSE;
@@ -381,11 +388,12 @@ week_view_time_range_changed_cb (EWeekView *week_view,
time_to_gdate_with_zone (&date, start_time, e_calendar_view_get_timezone (E_CALENDAR_VIEW (week_view)));
- /* Calculate the weekday of the given date, 0 = Mon. */
- weekday = g_date_get_weekday (&date) - 1;
+ weekday = g_date_get_weekday (&date);
+ display_start_day = e_week_view_get_display_start_day (week_view);
/* Convert it to an offset from the start of the display. */
- week_start_offset = (weekday + 7 - week_view->display_start_day) % 7;
+ week_start_offset = e_weekday_get_days_between (
+ display_start_day, weekday);
/* Set the day_offset to the result, so we move back to the
* start of the week. */
@@ -408,7 +416,7 @@ week_view_time_range_changed_cb (EWeekView *week_view,
|| g_date_compare (&week_view->priv->first_day_shown, &base_date)) {
week_view->priv->first_day_shown = base_date;
start_time = time_add_day_with_zone (
- start_time, -day_offset,
+ start_time, -((gint) day_offset),
e_calendar_view_get_timezone (E_CALENDAR_VIEW (week_view)));
start_time = time_day_begin_with_zone (
start_time,
@@ -1477,6 +1485,7 @@ e_week_view_init (EWeekView *week_view)
week_view->priv->compress_weekend = TRUE;
week_view->priv->show_event_end_times = TRUE;
week_view->priv->update_base_date = TRUE;
+ week_view->priv->display_start_day = G_DATE_MONDAY;
gtk_widget_set_can_focus (GTK_WIDGET (week_view), TRUE);
@@ -1496,7 +1505,6 @@ e_week_view_init (EWeekView *week_view)
week_view->scroll_by_week_notif_id = 0;
week_view->rows = 6;
week_view->columns = 2;
- week_view->display_start_day = 0; /* Monday. */
g_date_clear (&week_view->base_date, 1);
g_date_clear (&week_view->priv->first_day_shown, 1);
@@ -1985,7 +1993,10 @@ e_week_view_set_first_day_shown (EWeekView *week_view,
GDate *date)
{
GDate base_date;
- gint weekday, day_offset, num_days;
+ GDateWeekday weekday;
+ GDateWeekday display_start_day;
+ guint day_offset;
+ gint num_days;
gboolean update_adjustment_value = FALSE;
guint32 old_selection_start_julian = 0, old_selection_end_julian = 0;
struct icaltimetype start_tt = icaltime_null_time ();
@@ -2003,11 +2014,11 @@ e_week_view_set_first_day_shown (EWeekView *week_view,
+ week_view->selection_end_day;
}
- /* Calculate the weekday of the given date, 0 = Mon. */
- weekday = g_date_get_weekday (date) - 1;
+ weekday = g_date_get_weekday (date);
+ display_start_day = e_week_view_get_display_start_day (week_view);
/* Convert it to an offset from the start of the display. */
- day_offset = (weekday + 7 - week_view->display_start_day) % 7;
+ day_offset = e_weekday_get_days_between (display_start_day, weekday);
/* Calculate the base date, i.e. the first day shown when the
* scrollbar adjustment value is 0. */
@@ -2072,6 +2083,14 @@ e_week_view_set_first_day_shown (EWeekView *week_view,
gtk_widget_queue_draw (week_view->main_canvas);
}
+GDateWeekday
+e_week_view_get_display_start_day (EWeekView *week_view)
+{
+ g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), G_DATE_BAD_WEEKDAY);
+
+ return week_view->priv->display_start_day;
+}
+
/* Recalculates the time_t corresponding to the start of each day. */
static void
e_week_view_recalc_day_starts (EWeekView *week_view,
@@ -2307,8 +2326,9 @@ static gboolean
e_week_view_recalc_display_start_day (EWeekView *week_view)
{
ECalModel *model;
- gint week_start_day;
- gint display_start_day;
+ GDateWeekday week_start_day;
+ GDateWeekday display_start_day;
+ gboolean changed;
model = e_calendar_view_get_model (E_CALENDAR_VIEW (week_view));
week_start_day = e_cal_model_get_week_start_day (model);
@@ -2318,20 +2338,19 @@ e_week_view_recalc_display_start_day (EWeekView *week_view)
* is Sunday. */
display_start_day = week_start_day;
- if (display_start_day == 6) {
+ if (display_start_day == G_DATE_SUNDAY) {
if (!e_week_view_get_multi_week_view (week_view))
- display_start_day = 5;
+ display_start_day = G_DATE_SATURDAY;
if (e_week_view_get_compress_weekend (week_view))
- display_start_day = 5;
+ display_start_day = G_DATE_SATURDAY;
}
- if (week_view->display_start_day != display_start_day) {
- week_view->display_start_day = display_start_day;
- return TRUE;
- }
+ changed = (display_start_day != week_view->priv->display_start_day);
- return FALSE;
+ week_view->priv->display_start_day = display_start_day;
+
+ return changed;
}
/* Checks if the users participation status is NEEDS-ACTION and shows the summary as bold text */
@@ -2492,7 +2511,7 @@ e_week_view_get_day_position (EWeekView *week_view,
day,
e_week_view_get_multi_week_view (week_view),
e_week_view_get_weeks_shown (week_view),
- week_view->display_start_day,
+ e_week_view_get_display_start_day (week_view),
e_week_view_get_compress_weekend (week_view),
&cell_x, &cell_y, &cell_h);
@@ -2548,7 +2567,7 @@ e_week_view_get_span_position (EWeekView *week_view,
event, span,
week_view->rows_per_cell,
week_view->rows_per_compressed_cell,
- week_view->display_start_day,
+ e_week_view_get_display_start_day (week_view),
e_week_view_get_multi_week_view (week_view),
e_week_view_get_compress_weekend (week_view),
&num_days)) {
@@ -2817,9 +2836,12 @@ e_week_view_convert_position_to_day (EWeekView *week_view,
gint x,
gint y)
{
+ GDateWeekday display_start_day;
gint col, row, grid_x = -1, grid_y = -1, week, day;
gint weekend_col;
+ display_start_day = e_week_view_get_display_start_day (week_view);
+
/* First we convert it to a grid position. */
for (col = 0; col <= week_view->columns; col++) {
if (x < week_view->col_offsets[col]) {
@@ -2845,7 +2867,8 @@ e_week_view_convert_position_to_day (EWeekView *week_view,
day = grid_x;
if (e_week_view_get_compress_weekend (week_view)) {
- weekend_col = (5 + 7 - week_view->display_start_day) % 7;
+ weekend_col = e_weekday_get_days_between (
+ display_start_day, G_DATE_SATURDAY);
if (grid_x > weekend_col
|| (grid_x == weekend_col && grid_y % 2 == 1))
day++;
@@ -2857,7 +2880,7 @@ e_week_view_convert_position_to_day (EWeekView *week_view,
gint day_x = 0, day_y = 0, rows = 0;
e_week_view_layout_get_day_position (
day, FALSE, 1,
- week_view->display_start_day,
+ e_week_view_get_display_start_day (week_view),
e_week_view_get_compress_weekend (week_view),
&day_x, &day_y, &rows);
@@ -3051,7 +3074,7 @@ e_week_view_check_layout (EWeekView *week_view)
e_week_view_get_multi_week_view (week_view),
e_week_view_get_weeks_shown (week_view),
e_week_view_get_compress_weekend (week_view),
- week_view->display_start_day,
+ e_week_view_get_display_start_day (week_view),
week_view->day_starts,
week_view->rows_per_day);
@@ -3101,6 +3124,7 @@ static void
e_week_view_reshape_events (EWeekView *week_view)
{
EWeekViewEvent *event;
+ GDateWeekday display_start_day;
gint event_num, span_num;
gint num_days, day, day_x, day_y, day_w, day_h, max_rows;
gboolean is_weekend;
@@ -3138,9 +3162,18 @@ e_week_view_reshape_events (EWeekView *week_view)
/* Reshape the jump buttons and show/hide them as appropriate. */
num_days = e_week_view_get_weeks_shown (week_view) * 7;
+ display_start_day = e_week_view_get_display_start_day (week_view);
for (day = 0; day < num_days; day++) {
+ switch (e_weekday_add_days (display_start_day, day)) {
+ case G_DATE_SATURDAY:
+ case G_DATE_SUNDAY:
+ is_weekend = TRUE;
+ break;
+ default:
+ is_weekend = FALSE;
+ break;
+ }
- is_weekend = ((week_view->display_start_day + day) % 7 >= 5) ? TRUE : FALSE;
if (!is_weekend || (
e_week_view_get_multi_week_view (week_view)
&& !e_week_view_get_compress_weekend (week_view)))
diff --git a/calendar/gui/e-week-view.h b/calendar/gui/e-week-view.h
index ae528b3298..00181d1d89 100644
--- a/calendar/gui/e-week-view.h
+++ b/calendar/gui/e-week-view.h
@@ -208,11 +208,6 @@ struct _EWeekView {
gboolean month_scroll_by_week;
guint scroll_by_week_notif_id;
- /* The first day of the week we display, 0 (Monday) to 6 (Sunday).
- * This will usually be week_start_day, but if the weekend is
- * compressed, and week_start_day is Sunday we have to use Saturday. */
- gint display_start_day;
-
/* The vertical offset of the events from the top of the cells. */
gint events_y_offset;
@@ -348,6 +343,10 @@ void e_week_view_get_first_day_shown (EWeekView *week_view,
void e_week_view_set_first_day_shown (EWeekView *week_view,
GDate *date);
+/* The first day of the week we display. */
+GDateWeekday e_week_view_get_display_start_day
+ (EWeekView *week_view);
+
/* The selected time range. The EWeekView will show the corresponding
* month and the days between start_time and end_time will be selected.
* To select a single day, use the same value for start_time & end_time. */
diff --git a/calendar/gui/e-weekday-chooser.c b/calendar/gui/e-weekday-chooser.c
index 4585699f9c..ef459e574d 100644
--- a/calendar/gui/e-weekday-chooser.c
+++ b/calendar/gui/e-weekday-chooser.c
@@ -36,17 +36,14 @@
/* Private part of the EWeekdayChooser structure */
struct _EWeekdayChooserPrivate {
- /* Selected days; see weekday_chooser_set_days() */
- guint8 day_mask;
+ gboolean blocked_weekdays[8]; /* indexed by GDateWeekday */
+ gboolean selected_weekdays[8]; /* indexed by GDateWeekday */
- /* Blocked days; these cannot be modified */
- guint8 blocked_day_mask;
-
- /* Day that defines the start of the week; 0 = Sunday, ..., 6 = Saturday */
- gint week_start_day;
+ /* Day that defines the start of the week. */
+ GDateWeekday week_start_day;
/* Current keyboard focus day */
- gint focus_day;
+ GDateWeekday focus_day;
/* Metrics */
gint font_ascent, font_descent;
@@ -76,29 +73,16 @@ G_DEFINE_TYPE_WITH_CODE (
G_IMPLEMENT_INTERFACE (
E_TYPE_EXTENSIBLE, NULL))
-static gchar *
-get_day_text (gint day_index)
-{
- GDateWeekday weekday;
-
- /* Convert from tm_wday to GDateWeekday. */
- weekday = (day_index == 0) ? G_DATE_SUNDAY : day_index;
-
- return g_strdup (e_get_weekday_name (weekday, TRUE));
-}
-
static void
colorize_items (EWeekdayChooser *chooser)
{
- EWeekdayChooserPrivate *priv;
GdkColor *outline, *focus_outline;
GdkColor *fill, *sel_fill;
GdkColor *text_fill, *sel_text_fill;
GtkStateType state;
GtkStyle *style;
- gint i;
-
- priv = chooser->priv;
+ GDateWeekday weekday;
+ gint ii;
state = gtk_widget_get_state (GTK_WIDGET (chooser));
style = gtk_widget_get_style (GTK_WIDGET (chooser));
@@ -112,15 +96,12 @@ colorize_items (EWeekdayChooser *chooser)
sel_fill = &style->bg[GTK_STATE_SELECTED];
sel_text_fill = &style->fg[GTK_STATE_SELECTED];
- for (i = 0; i < 7; i++) {
- gint day;
- GdkColor *f, *t, *o;
+ weekday = e_weekday_chooser_get_week_start_day (chooser);
- day = i + priv->week_start_day;
- if (day >= 7)
- day -= 7;
+ for (ii = 0; ii < 7; ii++) {
+ GdkColor *f, *t, *o;
- if (priv->day_mask & (0x1 << day)) {
+ if (chooser->priv->selected_weekdays[weekday]) {
f = sel_fill;
t = sel_text_fill;
} else {
@@ -128,34 +109,34 @@ colorize_items (EWeekdayChooser *chooser)
t = text_fill;
}
- if (day == priv->focus_day)
+ if (weekday == chooser->priv->focus_day)
o = focus_outline;
else
o = outline;
gnome_canvas_item_set (
- priv->boxes[i],
+ chooser->priv->boxes[ii],
"fill_color_gdk", f,
"outline_color_gdk", o,
NULL);
gnome_canvas_item_set (
- priv->labels[i],
+ chooser->priv->labels[ii],
"fill_color_gdk", t,
NULL);
+
+ weekday = e_weekday_get_next (weekday);
}
}
static void
configure_items (EWeekdayChooser *chooser)
{
- EWeekdayChooserPrivate *priv;
GtkAllocation allocation;
gint width, height;
gint box_width;
- gint i;
-
- priv = chooser->priv;
+ GDateWeekday weekday;
+ gint ii;
gtk_widget_get_allocation (GTK_WIDGET (chooser), &allocation);
@@ -164,31 +145,26 @@ configure_items (EWeekdayChooser *chooser)
box_width = (width - 1) / 7;
- for (i = 0; i < 7; i++) {
- gchar *c;
- gint day;
-
- day = i + priv->week_start_day;
- if (day >= 7)
- day -= 7;
+ weekday = e_weekday_chooser_get_week_start_day (chooser);
+ for (ii = 0; ii < 7; ii++) {
gnome_canvas_item_set (
- priv->boxes[i],
- "x1", (gdouble) (i * box_width),
+ chooser->priv->boxes[ii],
+ "x1", (gdouble) (ii * box_width),
"y1", (gdouble) 0,
- "x2", (gdouble) ((i + 1) * box_width),
+ "x2", (gdouble) ((ii + 1) * box_width),
"y2", (gdouble) (height - 1),
"line_width", 0.0,
NULL);
- c = get_day_text (day);
gnome_canvas_item_set (
- priv->labels[i],
- "text", c,
- "x", (gdouble) (i * box_width) + PADDING,
+ chooser->priv->labels[ii],
+ "text", e_get_weekday_name (weekday, TRUE),
+ "x", (gdouble) (ii * box_width) + PADDING,
"y", (gdouble) (1 + PADDING),
NULL);
- g_free (c);
+
+ weekday = e_weekday_get_next (weekday);
}
colorize_items (chooser);
@@ -204,7 +180,7 @@ weekday_chooser_set_property (GObject *object,
case PROP_WEEK_START_DAY:
e_weekday_chooser_set_week_start_day (
E_WEEKDAY_CHOOSER (object),
- g_value_get_int (value));
+ g_value_get_enum (value));
return;
}
@@ -219,7 +195,7 @@ weekday_chooser_get_property (GObject *object,
{
switch (property_id) {
case PROP_WEEK_START_DAY:
- g_value_set_int (
+ g_value_set_enum (
value,
e_weekday_chooser_get_week_start_day (
E_WEEKDAY_CHOOSER (object)));
@@ -279,11 +255,11 @@ weekday_chooser_style_set (GtkWidget *widget,
EWeekdayChooser *chooser;
EWeekdayChooserPrivate *priv;
gint max_width;
- gint i;
PangoFontDescription *font_desc;
PangoContext *pango_context;
PangoFontMetrics *font_metrics;
PangoLayout *layout;
+ GDateWeekday weekday;
chooser = E_WEEKDAY_CHOOSER (widget);
priv = chooser->priv;
@@ -303,14 +279,13 @@ weekday_chooser_style_set (GtkWidget *widget,
max_width = 0;
- for (i = 0; i < 7; i++) {
- gchar *c;
+ for (weekday = G_DATE_MONDAY; weekday <= G_DATE_SUNDAY; weekday++) {
+ const gchar *name;
gint w;
- c = get_day_text (i);
- pango_layout_set_text (layout, c, strlen (c));
+ name = e_get_weekday_name (weekday, TRUE);
+ pango_layout_set_text (layout, name, strlen (name));
pango_layout_get_pixel_size (layout, &w, NULL);
- g_free (c);
if (w > max_width)
max_width = w;
@@ -362,23 +337,21 @@ weekday_chooser_focus (GtkWidget *widget,
GtkDirectionType direction)
{
EWeekdayChooser *chooser;
- EWeekdayChooserPrivate *priv;
- g_return_val_if_fail (E_IS_WEEKDAY_CHOOSER (widget), FALSE);
chooser = E_WEEKDAY_CHOOSER (widget);
- priv = chooser->priv;
if (!gtk_widget_get_can_focus (widget))
return FALSE;
if (gtk_widget_has_focus (widget)) {
- priv->focus_day = -1;
+ chooser->priv->focus_day = G_DATE_BAD_WEEKDAY;
colorize_items (chooser);
return FALSE;
}
- priv->focus_day = priv->week_start_day;
- gnome_canvas_item_grab_focus (priv->boxes[priv->focus_day]);
+ chooser->priv->focus_day = chooser->priv->week_start_day;
+ gnome_canvas_item_grab_focus (chooser->priv->boxes[0]);
+
colorize_items (chooser);
return TRUE;
@@ -408,13 +381,12 @@ e_weekday_chooser_class_init (EWeekdayChooserClass *class)
g_object_class_install_property (
object_class,
PROP_WEEK_START_DAY,
- g_param_spec_int (
+ g_param_spec_enum (
"week-start-day",
"Week Start Day",
NULL,
- 0, /* Monday */
- 6, /* Sunday */
- 0,
+ E_TYPE_DATE_WEEKDAY,
+ G_DATE_MONDAY,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
@@ -430,20 +402,15 @@ e_weekday_chooser_class_init (EWeekdayChooserClass *class)
static void
day_clicked (EWeekdayChooser *chooser,
- gint index)
+ GDateWeekday weekday)
{
- EWeekdayChooserPrivate *priv = chooser->priv;
- guint8 day_mask;
+ gboolean selected;
- if (priv->blocked_day_mask & (0x1 << index))
+ if (chooser->priv->blocked_weekdays[weekday])
return;
- if (priv->day_mask & (0x1 << index))
- day_mask = priv->day_mask & ~(0x1 << index);
- else
- day_mask = priv->day_mask | (0x1 << index);
-
- e_weekday_chooser_set_days (chooser, day_mask);
+ selected = e_weekday_chooser_get_selected (chooser, weekday);
+ e_weekday_chooser_set_selected (chooser, weekday, !selected);
}
static gint
@@ -452,18 +419,21 @@ handle_key_press_event (EWeekdayChooser *chooser,
{
EWeekdayChooserPrivate *priv = chooser->priv;
guint keyval = event->key.keyval;
+ guint index;
- if (priv->focus_day == -1)
- priv->focus_day = priv->week_start_day;
+ if (chooser->priv->focus_day == G_DATE_BAD_WEEKDAY)
+ chooser->priv->focus_day = chooser->priv->week_start_day;
switch (keyval) {
case GDK_KEY_Up:
case GDK_KEY_Right:
- priv->focus_day += 1;
+ chooser->priv->focus_day =
+ e_weekday_get_next (chooser->priv->focus_day);
break;
case GDK_KEY_Down:
case GDK_KEY_Left:
- priv->focus_day -= 1;
+ chooser->priv->focus_day =
+ e_weekday_get_prev (chooser->priv->focus_day);
break;
case GDK_KEY_space:
case GDK_KEY_Return:
@@ -473,28 +443,27 @@ handle_key_press_event (EWeekdayChooser *chooser,
return FALSE;
}
- if (priv->focus_day > 6)
- priv->focus_day = 0;
- if (priv->focus_day < 0)
- priv->focus_day = 6;
-
colorize_items (chooser);
- gnome_canvas_item_grab_focus (priv->boxes[priv->focus_day]);
+
+ index = e_weekday_get_days_between (
+ chooser->priv->week_start_day,
+ chooser->priv->focus_day);
+
+ gnome_canvas_item_grab_focus (chooser->priv->boxes[index]);
+
return TRUE;
}
/* Event handler for the day items */
-static gint
+static gboolean
day_event_cb (GnomeCanvasItem *item,
GdkEvent *event,
gpointer data)
{
EWeekdayChooser *chooser;
- EWeekdayChooserPrivate *priv;
- gint i;
+ gint ii;
chooser = E_WEEKDAY_CHOOSER (data);
- priv = chooser->priv;
if (event->type == GDK_KEY_PRESS)
return handle_key_press_event (chooser, event);
@@ -504,19 +473,22 @@ day_event_cb (GnomeCanvasItem *item,
/* Find which box was clicked */
- for (i = 0; i < 7; i++)
- if (priv->boxes[i] == item || priv->labels[i] == item)
+ for (ii = 0; ii < 7; ii++) {
+ if (chooser->priv->boxes[ii] == item)
+ break;
+ if (chooser->priv->labels[ii] == item)
break;
+ }
+
+ g_return_val_if_fail (ii < 7, FALSE);
- g_return_val_if_fail (i != 7, TRUE);
+ chooser->priv->focus_day = e_weekday_add_days (
+ chooser->priv->week_start_day, ii);
- i += priv->week_start_day;
- if (i >= 7)
- i -= 7;
+ gnome_canvas_item_grab_focus (chooser->priv->boxes[ii]);
+
+ day_clicked (chooser, chooser->priv->focus_day);
- priv->focus_day = i;
- gnome_canvas_item_grab_focus (priv->boxes[i]);
- day_clicked (chooser, i);
return TRUE;
}
@@ -525,29 +497,26 @@ day_event_cb (GnomeCanvasItem *item,
static void
create_items (EWeekdayChooser *chooser)
{
- EWeekdayChooserPrivate *priv;
GnomeCanvasGroup *parent;
- gint i;
-
- priv = chooser->priv;
+ gint ii;
parent = gnome_canvas_root (GNOME_CANVAS (chooser));
- for (i = 0; i < 7; i++) {
- priv->boxes[i] = gnome_canvas_item_new (
+ for (ii = 0; ii < 7; ii++) {
+ chooser->priv->boxes[ii] = gnome_canvas_item_new (
parent,
GNOME_TYPE_CANVAS_RECT,
NULL);
g_signal_connect (
- priv->boxes[i], "event",
+ chooser->priv->boxes[ii], "event",
G_CALLBACK (day_event_cb), chooser);
- priv->labels[i] = gnome_canvas_item_new (
+ chooser->priv->labels[ii] = gnome_canvas_item_new (
parent,
GNOME_TYPE_CANVAS_TEXT,
NULL);
g_signal_connect (
- priv->labels[i], "event",
+ chooser->priv->labels[ii], "event",
G_CALLBACK (day_event_cb), chooser);
}
}
@@ -577,74 +546,81 @@ e_weekday_chooser_new (void)
/**
* e_weekday_chooser_get_days:
* @chooser: an #EWeekdayChooser
+ * @weekday: a #GDateWeekday
*
- * Queries the days that are selected in @chooser.
+ * Returns whether @weekday is selected.
*
- * Return value: Bit mask of selected days. Sunday is bit 0, Monday is bit 1,
- * etc.
+ * Returns: whether @weekday is selected
**/
-guint8
-e_weekday_chooser_get_days (EWeekdayChooser *chooser)
+gboolean
+e_weekday_chooser_get_selected (EWeekdayChooser *chooser,
+ GDateWeekday weekday)
{
- g_return_val_if_fail (E_IS_WEEKDAY_CHOOSER (chooser), 0);
+ g_return_val_if_fail (E_IS_WEEKDAY_CHOOSER (chooser), FALSE);
+ g_return_val_if_fail (g_date_valid_weekday (weekday), FALSE);
- return chooser->priv->day_mask;
+ return chooser->priv->selected_weekdays[weekday];
}
/**
- * e_weekday_chooser_set_days:
+ * e_weekday_chooser_set_selected:
* @chooser: an #EWeekdayChooser
- * @day_mask: Bitmask with the days to be selected.
+ * @weekday: a #GDateWeekday
+ * @selected: selected flag
*
- * Sets the days that are selected in @chooser. In the @day_mask,
- * Sunday is bit 0, Monday is bit 1, etc.
+ * Selects or deselects @weekday.
**/
void
-e_weekday_chooser_set_days (EWeekdayChooser *chooser,
- guint8 day_mask)
+e_weekday_chooser_set_selected (EWeekdayChooser *chooser,
+ GDateWeekday weekday,
+ gboolean selected)
{
g_return_if_fail (E_IS_WEEKDAY_CHOOSER (chooser));
+ g_return_if_fail (g_date_valid_weekday (weekday));
+
+ chooser->priv->selected_weekdays[weekday] = selected;
- chooser->priv->day_mask = day_mask;
colorize_items (chooser);
g_signal_emit (chooser, chooser_signals[CHANGED], 0);
}
/**
- * e_weekday_chooser_get_blocked_days:
+ * e_weekday_chooser_get_blocked:
* @chooser: an #EWeekdayChooser
+ * @weekday: a #GDateWeekday
*
- * Queries the set of days that the @chooser prevents from being modified
- * by the user.
+ * Returns whether @weekday is blocked from being modified by the user.
*
- * Return value: Bit mask of blocked days, with the same format as that
- * returned by e_weekday_chooser_get_days().
+ * Returns: whether @weekday is blocked
**/
-guint
-e_weekday_chooser_get_blocked_days (EWeekdayChooser *chooser)
+gboolean
+e_weekday_chooser_get_blocked (EWeekdayChooser *chooser,
+ GDateWeekday weekday)
{
- g_return_val_if_fail (E_IS_WEEKDAY_CHOOSER (chooser), 0);
+ g_return_val_if_fail (E_IS_WEEKDAY_CHOOSER (chooser), FALSE);
+ g_return_val_if_fail (g_date_valid_weekday (weekday), FALSE);
- return chooser->priv->blocked_day_mask;
+ return chooser->priv->blocked_weekdays[weekday];
}
/**
- * e_weekday_chooser_set_blocked_days:
+ * e_weekday_chooser_set_blocked:
* @chooser: an #EWeekdayChooser
- * @blocked_day_mask: Bitmask with the days to be blocked.
+ * @weekday: a #GDateWeekday
+ * @blocked: blocked flag
*
- * Sets the days that the @chooser will prevent from being modified by
- * the user. The @blocked_day_mask is specified in the same way as in
- * e_weekday_chooser_set_days().
+ * Sets whether @weekday is blocked from being modified by the user.
**/
void
-e_weekday_chooser_set_blocked_days (EWeekdayChooser *chooser,
- guint8 blocked_day_mask)
+e_weekday_chooser_set_blocked (EWeekdayChooser *chooser,
+ GDateWeekday weekday,
+ gboolean blocked)
{
g_return_if_fail (E_IS_WEEKDAY_CHOOSER (chooser));
+ g_return_if_fail (g_date_valid_weekday (weekday));
- chooser->priv->blocked_day_mask = blocked_day_mask;
+ chooser->priv->blocked_weekdays[weekday] = blocked;
}
/**
@@ -653,10 +629,9 @@ e_weekday_chooser_set_blocked_days (EWeekdayChooser *chooser,
*
* Queries the day that defines the start of the week in @chooser.
*
- * Return value: Index of the day that defines the start of the week. See
- * weekday_chooser_set_week_start_day() to see how this is represented.
+ * Returns: a #GDateWeekday
**/
-gint
+GDateWeekday
e_weekday_chooser_get_week_start_day (EWeekdayChooser *chooser)
{
g_return_val_if_fail (E_IS_WEEKDAY_CHOOSER (chooser), -1);
@@ -667,17 +642,16 @@ e_weekday_chooser_get_week_start_day (EWeekdayChooser *chooser)
/**
* e_weekday_chooser_set_week_start_day:
* @chooser: an #EWeekdayChooser
- * @week_start_day: Index of the day that defines the start of the week; 0 is
- * Sunday, 1 is Monday, etc.
+ * @week_start_day: a #GDateWeekday
*
* Sets the day that defines the start of the week for @chooser.
**/
void
e_weekday_chooser_set_week_start_day (EWeekdayChooser *chooser,
- gint week_start_day)
+ GDateWeekday week_start_day)
{
g_return_if_fail (E_IS_WEEKDAY_CHOOSER (chooser));
- g_return_if_fail (week_start_day >= 0 && week_start_day < 7);
+ g_return_if_fail (g_date_valid_weekday (week_start_day));
if (week_start_day == chooser->priv->week_start_day)
return;
diff --git a/calendar/gui/e-weekday-chooser.h b/calendar/gui/e-weekday-chooser.h
index cde70e411e..1d28830d0c 100644
--- a/calendar/gui/e-weekday-chooser.h
+++ b/calendar/gui/e-weekday-chooser.h
@@ -59,19 +59,21 @@ struct _EWeekdayChooserClass {
GType e_weekday_chooser_get_type (void) G_GNUC_CONST;
GtkWidget * e_weekday_chooser_new (void);
-guint8 e_weekday_chooser_get_days (EWeekdayChooser *chooser);
-void e_weekday_chooser_set_days (EWeekdayChooser *chooser,
- guint8 day_mask);
-guint e_weekday_chooser_get_blocked_days
- (EWeekdayChooser *chooser);
-void e_weekday_chooser_set_blocked_days
- (EWeekdayChooser *chooser,
- guint8 blocked_day_mask);
-gint e_weekday_chooser_get_week_start_day
+gboolean e_weekday_chooser_get_selected (EWeekdayChooser *chooser,
+ GDateWeekday weekday);
+void e_weekday_chooser_set_selected (EWeekdayChooser *chooser,
+ GDateWeekday weekday,
+ gboolean selected);
+gboolean e_weekday_chooser_get_blocked (EWeekdayChooser *chooser,
+ GDateWeekday weekday);
+void e_weekday_chooser_set_blocked (EWeekdayChooser *chooser,
+ GDateWeekday weekday,
+ gboolean blocked);
+GDateWeekday e_weekday_chooser_get_week_start_day
(EWeekdayChooser *chooser);
void e_weekday_chooser_set_week_start_day
(EWeekdayChooser *chooser,
- gint week_start_day);
+ GDateWeekday week_start_day);
G_END_DECLS
diff --git a/calendar/gui/ea-week-view-cell.c b/calendar/gui/ea-week-view-cell.c
index 6ef8e15f14..ff83c00da6 100644
--- a/calendar/gui/ea-week-view-cell.c
+++ b/calendar/gui/ea-week-view-cell.c
@@ -221,7 +221,8 @@ ea_week_view_cell_get_name (AtkObject *accessible)
gchar *new_name;
const gchar *row_label, *column_label;
gint new_column, new_row;
- gint start_day;
+ GDateWeekday start_day;
+ gint offset;
atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible);
g_obj = atk_gobject_accessible_get_object (atk_gobj);
@@ -232,12 +233,14 @@ ea_week_view_cell_get_name (AtkObject *accessible)
main_item = cell->week_view->main_canvas_item;
ea_main_item = atk_gobject_accessible_for_object (G_OBJECT (main_item));
- start_day = cell->week_view->display_start_day;
- if (cell->column + start_day >= 7) {
- new_column = cell->column + start_day - 7;
+ start_day = e_week_view_get_display_start_day (cell->week_view);
+ offset = (start_day - G_DATE_MONDAY);
+
+ if (cell->column + offset >= 7) {
+ new_column = cell->column + offset - 7;
new_row = cell->row + 1;
} else {
- new_column = cell->column + start_day;
+ new_column = cell->column + offset;
new_row = cell->row;
}
@@ -359,7 +362,7 @@ component_interface_get_extents (AtkComponent *component,
gboolean compress_weekend;
gint week_view_width, week_view_height;
gint scroll_x, scroll_y;
- gint start_day;
+ GDateWeekday start_day;
*x = *y = *width = *height = 0;
@@ -385,19 +388,19 @@ component_interface_get_extents (AtkComponent *component,
gnome_canvas_get_scroll_offsets (
GNOME_CANVAS (week_view->main_canvas),
&scroll_x, &scroll_y);
- start_day = week_view->display_start_day;
+ start_day = e_week_view_get_display_start_day (week_view);
if (e_week_view_get_multi_week_view (week_view)) {
- if (compress_weekend && (cell->column == (5 - start_day))) {
+ if (compress_weekend && (cell->column == e_weekday_get_days_between (start_day, G_DATE_SATURDAY))) {
*height = week_view->row_heights[cell->row*2];
*width = week_view->col_widths[cell->column];
*x += week_view->col_offsets[cell->column] - scroll_x;
*y += week_view->row_offsets[cell->row*2]- scroll_y;
- } else if (compress_weekend && (cell->column == (6 - start_day))) {
+ } else if (compress_weekend && (cell->column == e_weekday_get_days_between (start_day, G_DATE_SUNDAY))) {
*height = week_view->row_heights[cell->row*2];
*width = week_view->col_widths[cell->column - 1];
*x += week_view->col_offsets[cell->column - 1]- scroll_x;
*y += week_view->row_offsets[cell->row*2 + 1]- scroll_y;
- } else if (compress_weekend && (cell->column > (6 - start_day))) {
+ } else if (compress_weekend && (cell->column > e_weekday_get_days_between (start_day, G_DATE_SUNDAY))) {
*height = week_view->row_heights[cell->row*2]*2;
*width = week_view->col_widths[cell->column - 1];
*x += week_view->col_offsets[cell->column - 1] - scroll_x;
@@ -409,24 +412,24 @@ component_interface_get_extents (AtkComponent *component,
*y += week_view->row_offsets[cell->row*2]- scroll_y;
}
} else {
- if (start_day < 3) {
+ if (start_day < G_DATE_THURSDAY) {
if (cell->column < 3) {
*height = week_view->row_heights[cell->column*2]*2;
*width = week_view->col_widths[0];
*x += week_view->col_offsets[0] - scroll_x;
*y += week_view->row_offsets[cell->column*2]- scroll_y;
} else {
- if (cell->column == 5 - start_day) {
+ if (cell->column == e_weekday_get_days_between (start_day, G_DATE_SATURDAY)) {
*height = week_view->row_heights[(cell->column - 3)*2];
*width = week_view->col_widths[1];
*x += week_view->col_offsets[1] - scroll_x;
*y += week_view->row_offsets[(cell->column - 3)*2]- scroll_y;
- } else if (cell->column == 6 - start_day) {
+ } else if (cell->column == e_weekday_get_days_between (start_day, G_DATE_SUNDAY)) {
*height = week_view->row_heights[(cell->column - 4)*2];
*width = week_view->col_widths[1];
*x += week_view->col_offsets[1] - scroll_x;
*y += week_view->row_offsets[(cell->column - 3)*2 - 1]- scroll_y;
- } else if (cell->column > 6 - start_day) {
+ } else if (cell->column > e_weekday_get_days_between (start_day, G_DATE_SUNDAY)) {
*height = week_view->row_heights[(cell->column - 4)*2]*2;
*width = week_view->col_widths[1];
*x += week_view->col_offsets[1] - scroll_x;
@@ -439,17 +442,17 @@ component_interface_get_extents (AtkComponent *component,
}
}
} else if (cell->column < 4) {
- if (cell->column == 5 - start_day) {
+ if (cell->column == e_weekday_get_days_between (start_day, G_DATE_SATURDAY)) {
*height = week_view->row_heights[cell->column*2];
*width = week_view->col_widths[0];
*x += week_view->col_offsets[0] - scroll_x;
*y += week_view->row_offsets[cell->column*2]- scroll_y;
- } else if (cell->column == 6 - start_day) {
+ } else if (cell->column == e_weekday_get_days_between (start_day, G_DATE_SUNDAY)) {
*height = week_view->row_heights[(cell->column - 1)*2];
*width = week_view->col_widths[0];
*x += week_view->col_offsets[0] - scroll_x;
*y += week_view->row_offsets[cell->column*2 - 1]- scroll_y;
- } else if (cell->column > 6 - start_day) {
+ } else if (cell->column > e_weekday_get_days_between (start_day, G_DATE_SUNDAY)) {
*height = week_view->row_heights[(cell->column - 1)*2]*2;
*width = week_view->col_widths[0];
*x += week_view->col_offsets[0] - scroll_x;
diff --git a/calendar/gui/gnome-cal.c b/calendar/gui/gnome-cal.c
index bcf0fb7ce7..c464eef119 100644
--- a/calendar/gui/gnome-cal.c
+++ b/calendar/gui/gnome-cal.c
@@ -927,12 +927,13 @@ get_times_for_views (GnomeCalendar *gcal,
ECalModel *model;
EDayView *day_view;
EWeekView *week_view;
- gint shown, display_start;
+ gint shown;
GDate date;
gint days_shown;
GDateWeekday week_start_day;
GDateWeekday first_work_day;
GDateWeekday last_work_day;
+ GDateWeekday start_day;
GDateWeekday weekday;
guint offset;
struct icaltimetype tt = icaltime_null_time ();
@@ -943,7 +944,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) + 1;
+ week_start_day = e_cal_model_get_week_start_day (model);
priv = gcal->priv;
@@ -1004,13 +1005,13 @@ get_times_for_views (GnomeCalendar *gcal,
time (select_time);
break;
case GNOME_CAL_WEEK_VIEW:
- /* FIXME We should be using the same day
- * of the week enum everywhere. */
week_view = E_WEEK_VIEW (priv->views[view_type]);
- display_start = (week_view->display_start_day + 1) % 7;
+ start_day = e_week_view_get_display_start_day (week_view);
*start_time = time_week_begin_with_zone (
- *start_time, display_start, timezone);
+ *start_time,
+ e_weekday_to_tm_wday (start_day),
+ timezone);
*end_time = time_add_week_with_zone (
*start_time, 1, timezone);
@@ -1018,19 +1019,20 @@ get_times_for_views (GnomeCalendar *gcal,
time (select_time);
break;
case GNOME_CAL_MONTH_VIEW:
- /* FIXME We should be using the same day
- * of the week enum everywhere. */
week_view = E_WEEK_VIEW (priv->views[view_type]);
shown = e_week_view_get_weeks_shown (week_view);
- display_start = (week_view->display_start_day + 1) % 7;
+ start_day = e_week_view_get_display_start_day (week_view);
if (!range_selected && (
!e_week_view_get_multi_week_view (week_view) ||
!week_view->month_scroll_by_week))
*start_time = time_month_begin_with_zone (
*start_time, timezone);
+
*start_time = time_week_begin_with_zone (
- *start_time, display_start, timezone);
+ *start_time,
+ e_weekday_to_tm_wday (start_day),
+ timezone);
*end_time = time_add_week_with_zone (
*start_time, shown, timezone);
@@ -1621,8 +1623,8 @@ gnome_calendar_goto_date (GnomeCalendar *gcal,
GnomeCalendarGotoDateType goto_date)
{
ECalModel *model;
- time_t new_time = 0;
- gint week_start_day;
+ time_t new_time = 0;
+ GDateWeekday week_start_day;
gboolean need_updating = FALSE;
icaltimezone *timezone;
@@ -1654,12 +1656,16 @@ 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, week_start_day, timezone);
+ gcal->priv->base_view_time,
+ e_weekday_to_tm_wday (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, week_start_day, timezone);
+ gcal->priv->base_view_time,
+ e_weekday_to_tm_wday (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 */
diff --git a/calendar/gui/print.c b/calendar/gui/print.c
index 0e60f84e29..7b9df1578d 100644
--- a/calendar/gui/print.c
+++ b/calendar/gui/print.c
@@ -211,8 +211,7 @@ struct pdinfo
icaltimezone *zone;
};
-struct psinfo
-{
+struct psinfo {
gint days_shown;
time_t day_starts[E_WEEK_VIEW_MAX_WEEKS * 7 + 1];
@@ -220,7 +219,7 @@ struct psinfo
gint rows_per_cell;
gint rows_per_compressed_cell;
- gint display_start_weekday;
+ GDateWeekday display_start_weekday;
gboolean multi_week_view;
gint weeks_shown;
gint month;
@@ -268,7 +267,10 @@ build_month (ECalModel *model,
gint *end)
{
gint i;
- gint d_month, d_week, week_start_day;
+ gint d_month;
+ gint d_week;
+ GDateWeekday weekday;
+ GDateWeekday week_start_day;
/* Note that months are zero-based, so September is month 8 */
@@ -292,17 +294,16 @@ build_month (ECalModel *model,
d_week = time_day_of_week (1, month, year);
/* Get the configuration setting specifying which weekday we put on
- * the left column, 0=Sun to 6=Sat. */
+ * the left column. */
week_start_day = e_cal_model_get_week_start_day (model);
- /* Figure out which square we want to put the 1 in. */
- d_week = (d_week + 7 - week_start_day) % 7;
+ weekday = e_weekday_from_tm_wday (d_week);
for (i = 0; i < d_month; i++)
days[d_week + i] = i + 1;
if (start)
- *start = d_week;
+ *start = e_weekday_get_days_between (week_start_day, weekday);
if (end)
*end = d_week + d_month - 1;
@@ -716,10 +717,18 @@ instance_cb (ECalComponent *comp,
return FALSE;
}
-const gchar *daynames[] =
-/* Translators: These are workday abbreviations, e.g. Su=Sunday and Th=thursday */
- { N_("Su"), N_("Mo"), N_("Tu"), N_("We"),
- N_("Th"), N_("Fr"), N_("Sa") };
+const gchar *daynames[] = {
+ /* Translators: These are workday abbreviations,
+ * e.g. Su=Sunday and Th=thursday */
+ /* G_DATE_BAD_WEEKDAY */ "",
+ /* G_DATE_MONDAY */ N_("Mo"),
+ /* G_DATE_TUESDAY */ N_("Tu"),
+ /* G_DATE_WEDNESDAY */ N_("We"),
+ /* G_DATE_THURSDAY */ N_("Th"),
+ /* G_DATE_FRIDAY */ N_("Fr"),
+ /* G_DATE_SATURDAY */ N_("Sa"),
+ /* G_DATE_SUNDAY */ N_("Su")
+};
static gdouble
calc_small_month_width (GtkPrintContext *context,
@@ -733,7 +742,7 @@ calc_small_month_width (GtkPrintContext *context,
font_bold = get_font_for_size (for_height / 7.4, PANGO_WEIGHT_BOLD);
res = MAX (evo_calendar_print_renderer_get_width (
context, font_bold, "23"), res);
- for (ii = 0; ii < 7; ii++) {
+ for (ii = G_DATE_MONDAY; ii < G_N_ELEMENTS (daynames); ii++) {
res = MAX (evo_calendar_print_renderer_get_width (
context, font_bold, _(daynames[ii])), res);
}
@@ -771,8 +780,10 @@ print_month_small (GtkPrintContext *context,
ECalModel *model;
time_t now, next;
gint x, y;
+ gint day;
gint days[42];
- gint day, weekday, week_start_day;
+ GDateWeekday weekday;
+ GDateWeekday week_start_day;
gchar buf[100];
struct tm tm;
gdouble font_size;
@@ -837,7 +848,7 @@ print_month_small (GtkPrintContext *context,
x1 + (x + (week_numbers ? 1 : 0)) * col_width,
x1 + (x + 1 + (week_numbers ? 1 : 0)) * col_width,
y1, y1 + row_height * 1.4);
- weekday = (weekday + 1) % 7;
+ weekday = e_weekday_get_next (weekday);
}
y1 += row_height * 1.4;
@@ -866,9 +877,11 @@ print_month_small (GtkPrintContext *context,
if (day != 0) {
time_t week_begin;
+ gint wday;
+ wday = e_weekday_to_tm_wday (week_start_day);
week_begin = time_week_begin_with_zone (
- now, week_start_day, zone);
+ now, wday, zone);
convert_timet_to_struct_tm (
week_begin, zone, &tm);
@@ -1895,8 +1908,8 @@ print_week_event (GtkPrintContext *context,
span = &g_array_index (spans, EWeekViewEventSpan,
event->spans_index + span_num);
- if (e_week_view_layout_get_span_position
- (event, span,
+ if (e_week_view_layout_get_span_position (
+ event, span,
psi->rows_per_cell,
psi->rows_per_compressed_cell,
psi->display_start_weekday,
@@ -1952,25 +1965,31 @@ print_week_event (GtkPrintContext *context,
} else {
cairo_t *cr = gtk_print_context_get_cairo_context (context);
- e_week_view_layout_get_day_position
- (span->start_day,
- psi->multi_week_view,
- psi->weeks_shown,
- psi->display_start_weekday,
- psi->compress_weekend,
- &start_x, &start_y, &start_h);
+ e_week_view_layout_get_day_position (
+ span->start_day,
+ psi->multi_week_view,
+ psi->weeks_shown,
+ psi->display_start_weekday,
+ psi->compress_weekend,
+ &start_x, &start_y, &start_h);
y1 = top + start_y * cell_height
+ psi->header_row_height
+ psi->rows_per_cell * (psi->row_height + 2);
if (span->row >= psi->rows_per_compressed_cell && psi->compress_weekend) {
- gint end_day_of_week =
- (psi->display_start_weekday +
- span->start_day) % 7;
+ GDateWeekday end_weekday;
+ gboolean end_on_weekend;
+
+ end_weekday = e_weekday_add_days (
+ psi->display_start_weekday,
+ span->start_day);
- if (end_day_of_week == 5 || end_day_of_week == 6) {
- /* Sat or Sun */
+ end_on_weekend =
+ (end_weekday == G_DATE_SATURDAY) ||
+ (end_weekday == G_DATE_SUNDAY);
+
+ if (end_on_weekend) {
y1 = top + start_y * cell_height
+ psi->header_row_height
+ psi->rows_per_compressed_cell * (psi->row_height + 2);
@@ -2167,13 +2186,11 @@ print_week_summary (GtkPrintContext *context,
psi.compress_weekend = TRUE;
psi.use_24_hour_format = e_cal_model_get_use_24_hour_format (model);
- /* We convert this from (0 = Sun, 6 = Sat) to (0 = Mon, 6 = Sun). */
psi.display_start_weekday = e_cal_model_get_week_start_day (model);
- psi.display_start_weekday = (psi.display_start_weekday + 6) % 7;
/* If weekends are compressed then we can't start on a Sunday. */
- if (psi.compress_weekend && psi.display_start_weekday == 6)
- psi.display_start_weekday = 5;
+ if (psi.compress_weekend && psi.display_start_weekday == G_DATE_SUNDAY)
+ psi.display_start_weekday = G_DATE_SATURDAY;
day_start = time_day_begin_with_zone (whence, zone);
for (day = 0; day <= psi.days_shown; day++) {
@@ -2184,8 +2201,8 @@ print_week_summary (GtkPrintContext *context,
/* Get the events from the server. */
e_cal_model_generate_instances_sync (
model,
- psi.day_starts[0], psi.day_starts[psi.days_shown],
- print_week_summary_cb, &psi);
+ psi.day_starts[0], psi.day_starts[psi.days_shown],
+ print_week_summary_cb, &psi);
qsort (
psi.events->data, psi.events->len,
sizeof (EWeekViewEvent), e_week_view_event_sort_func);
@@ -2263,7 +2280,9 @@ print_month_summary (GtkPrintContext *context,
ECalModel *model;
PangoFontDescription *font;
gboolean compress_weekend;
- gint columns, col, weekday, month, weeks;
+ gint columns, col, month, weeks;
+ GDateWeekday weekday;
+ gint wday;
gdouble font_size, cell_width, x1, x2, y1, y2;
model = gnome_calendar_get_model (gcal);
@@ -2303,10 +2322,12 @@ print_month_summary (GtkPrintContext *context,
* or before that day. */
if (!date)
date = time_month_begin_with_zone (whence, zone);
- date = time_week_begin_with_zone (date, weekday, zone);
+
+ wday = e_weekday_to_tm_wday (weekday);
+ date = time_week_begin_with_zone (date, wday, zone);
/* If weekends are compressed then we can't start on a Sunday. */
- if (compress_weekend && weekday == 0)
+ if (compress_weekend && weekday == G_DATE_SUNDAY)
date = time_add_day_with_zone (date, -1, zone);
/* do day names ... */
@@ -3027,7 +3048,8 @@ print_week_view (GtkPrintContext *context,
gdouble l, week_numbers_inc, small_month_width;
gchar buf[100];
time_t when;
- gint week_start_day;
+ GDateWeekday week_start_day;
+ gint wday;
struct tm tm;
gdouble width, height;
@@ -3043,11 +3065,13 @@ print_week_view (GtkPrintContext *context,
convert_timet_to_struct_tm (date, zone, &tm);
week_start_day = e_cal_model_get_week_start_day (model);
- when = time_week_begin_with_zone (date, week_start_day, zone);
+
+ wday = e_weekday_to_tm_wday (week_start_day);
+ when = time_week_begin_with_zone (date, wday, zone);
/* If the week starts on a Sunday, we have to show the Saturday first,
* since the weekend is compressed. */
- if (week_start_day == 0) {
+ if (week_start_day == G_DATE_SUNDAY) {
if (tm.tm_wday == 6)
when = time_add_day_with_zone (when, 6, zone);
else