[evolution-patches] 60904 Not displaying all appointments in work week



We were cutting off the query after 5 days instead of calculating the
work week like the day view did.  Most obvious if you made all 7 days
your "work week".

-JP
-- 
JP Rosevear <jpr novell com>
Novell, Inc.
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/calendar/ChangeLog,v
retrieving revision 1.2500.2.3
diff -u -p -r1.2500.2.3 ChangeLog
--- ChangeLog	10 Sep 2004 15:58:42 -0000	1.2500.2.3
+++ ChangeLog	15 Sep 2004 19:05:03 -0000
@@ -1,3 +1,15 @@
+2004-09-15  JP Rosevear  <jpr novell com>
+
+	Fixes #60904
+	
+	* gui/gnome-cal.c (set_week_start): update the view
+	(get_times_for_views): mimic the work week guessing code exactly
+	for calculating the time range needed instead of hardcoding 5 days
+	(set_working_days): new routine to update the view
+	(working_days_changed_cb): use above when getting config change
+	notification
+	(setup_config): set working days and add notification
+
 2004-09-09  JP Rosevear  <jpr novell com>
 
 	Fixes #65454
Index: gui/gnome-cal.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/gnome-cal.c,v
retrieving revision 1.350
diff -u -p -r1.350 gnome-cal.c
--- gui/gnome-cal.c	24 Aug 2004 16:08:14 -0000	1.350
+++ gui/gnome-cal.c	15 Sep 2004 19:05:03 -0000
@@ -489,7 +489,8 @@ get_times_for_views (GnomeCalendar *gcal
 	GnomeCalendarPrivate *priv;
 	int shown, display_start;
 	GDate date;
-	gint weekday, day, i;
+	gint weekday, first_day, last_day, days_shown, i;
+	gboolean has_working_days = FALSE;
 	guint offset;
 	struct icaltimetype tt = icaltime_null_time ();
 	
@@ -511,22 +512,38 @@ get_times_for_views (GnomeCalendar *gcal
 		/* Get the weekday corresponding to start_time, 0 (Sun) to 6 (Sat). */
 		weekday = g_date_weekday (&date) % 7;
 
-		/* 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 = (E_DAY_VIEW (priv->day_view)->week_start_day + 1) % 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;
 		for (i = 0; i < 7; i++) {
-			if (E_DAY_VIEW (priv->day_view)->working_days & (1 << day))
+			if (E_DAY_VIEW (priv->views[view_type])->working_days & (1 << first_day)) {
+				has_working_days = TRUE;
 				break;
-			day = (day + 1) % 7;
+			}
+			first_day = (first_day + 1) % 7;
+		}
+
+		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;
+			for (i = 0; i < 7; i++) {
+				if (E_DAY_VIEW (priv->views[view_type])->working_days & (1 << last_day))
+					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;
+		} else {
+			/* If no working days are set, just use 7. */
+			days_shown = 7;
 		}
 
 		/* Calculate how many days we need to go back to the first workday. */
-		if (weekday < day) {
-			offset = (day - weekday) % 7;
+		if (weekday < first_day) {
+			offset = (first_day - weekday) % 7;
 			g_date_add_days (&date, offset);
 		} else {
-			offset = (weekday - day) % 7;
+			offset = (weekday - first_day) % 7;
 			g_date_subtract_days (&date, offset);
 		}
 
@@ -535,7 +552,7 @@ get_times_for_views (GnomeCalendar *gcal
 		tt.day = g_date_day (&date);
 
 		*start_time = icaltime_as_timet_with_zone (tt, priv->zone);
-		*end_time = time_add_day_with_zone (*start_time, 5, priv->zone);
+		*end_time = time_add_day_with_zone (*start_time, days_shown, priv->zone);
 		break;
 	case GNOME_CAL_WEEK_VIEW:
 		/* FIXME We should be using the same day of the week enum every where */
@@ -950,8 +967,14 @@ set_week_start (GnomeCalendar *calendar)
 
 	priv = calendar->priv;
 	
-	/* FIXME we should adjust the week and work week views */
 	priv->week_start = calendar_config_get_week_start_day ();
+
+	/* Only do this if views exist */
+	if (priv->day_view && priv->work_week_view && priv->week_view && priv->month_view && priv->list_view) {
+		update_view_times (calendar, priv->base_view_time);
+		gnome_calendar_update_date_navigator (calendar);
+		gnome_calendar_notify_dates_shown_changed (calendar);
+	}
 }
 
 static void
@@ -963,6 +986,29 @@ week_start_changed_cb (GConfClient *clie
 }
 
 static void
+set_working_days (GnomeCalendar *calendar)
+{
+	GnomeCalendarPrivate *priv;
+
+	priv = calendar->priv;
+	
+	/* Only do this if views exist */
+	if (priv->day_view && priv->work_week_view && priv->week_view && priv->month_view && priv->list_view) {
+		update_view_times (calendar, priv->base_view_time);
+		gnome_calendar_update_date_navigator (calendar);
+		gnome_calendar_notify_dates_shown_changed (calendar);
+	}
+}
+
+static void
+working_days_changed_cb (GConfClient *client, guint id, GConfEntry *entry, gpointer data)
+{
+	GnomeCalendar *calendar = data;
+	
+	set_working_days (calendar);
+}
+
+static void
 set_timezone (GnomeCalendar *calendar) 
 {
 	GnomeCalendarPrivate *priv;
@@ -1050,6 +1096,11 @@ setup_config (GnomeCalendar *calendar)
 	/* Week Start */
 	set_week_start (calendar);
 	not = calendar_config_add_notification_week_start_day (week_start_changed_cb, calendar);
+	priv->notifications = g_list_prepend (priv->notifications, GUINT_TO_POINTER (not));
+
+	/* Working Days */
+	set_working_days (calendar);
+	not = calendar_config_add_notification_working_days (working_days_changed_cb, calendar);
 	priv->notifications = g_list_prepend (priv->notifications, GUINT_TO_POINTER (not));
 
 	/* Timezone */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]