[evolution-patches] [calendar] fix for b#271842



Attached patch fixes bug #271842 (Clicking "Select today" selects
usually wrong day in "Work week", "Week" and "Month" view).

Please review.

Thanks,
Dinesh

Index: gui/gnome-cal.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/gnome-cal.c,v
retrieving revision 1.386
diff -u -p -r1.386 gnome-cal.c
--- gui/gnome-cal.c	24 Aug 2005 03:07:49 -0000	1.386
+++ gui/gnome-cal.c	3 Oct 2005 13:10:40 -0000
@@ -1750,20 +1750,13 @@ gnome_calendar_goto_date (GnomeCalendar 
 void
 gnome_calendar_goto (GnomeCalendar *gcal, time_t new_time)
 {
-	GnomeCalendarPrivate *priv;
-	
 	g_return_if_fail (gcal != NULL);
 	g_return_if_fail (GNOME_IS_CALENDAR (gcal));
 	g_return_if_fail (new_time != -1);
 
-	priv = gcal->priv;
-
-	update_view_times (gcal, new_time);
-	gnome_calendar_update_date_navigator (gcal);
-	gnome_calendar_notify_dates_shown_changed (gcal);
+	gnome_calendar_dayjump (gcal, new_time);
 }
 
-
 static void
 update_view_times (GnomeCalendar *gcal, time_t start_time)
 {
@@ -1786,6 +1779,23 @@ update_view_times (GnomeCalendar *gcal, 
 	}
 }
 
+
+static void
+update_view_time (GnomeCalendar *gcal, GnomeCalendarViewType view, time_t start_time)
+{
+	GnomeCalendarPrivate *priv;
+	ECalModel *model;
+	time_t real_start_time = start_time;
+	time_t end_time;
+
+	priv = gcal->priv;
+
+	model = e_calendar_view_get_model (priv->views[view]);
+	get_times_for_views (gcal, view, &real_start_time, &end_time);
+
+	e_cal_model_set_time_range (model, real_start_time, end_time);
+}
+
 static void
 gnome_calendar_direction (GnomeCalendar *gcal, int direction)
 {
@@ -1838,16 +1848,50 @@ void
 gnome_calendar_dayjump (GnomeCalendar *gcal, time_t time)
 {
 	GnomeCalendarPrivate *priv;
+	GDate date;
+	gint weekday = 0;
 
 	g_return_if_fail (gcal != NULL);
 	g_return_if_fail (GNOME_IS_CALENDAR (gcal));
 
 	priv = gcal->priv;
-
 	priv->base_view_time = time_day_begin_with_zone (time, priv->zone);
 
-	update_view_times (gcal, priv->base_view_time);
-	gnome_calendar_set_view (gcal, GNOME_CAL_DAY_VIEW);
+	time_to_gdate_with_zone (&date, time, e_calendar_view_get_timezone (E_CALENDAR_VIEW ((E_WEEK_VIEW (priv->views[GNOME_CAL_WEEK_VIEW])))));
+	weekday = g_date_weekday (&date) - 1;
+
+
+	if (priv->current_view_type == GNOME_CAL_DAY_VIEW) {
+	        (E_DAY_VIEW (priv->views[GNOME_CAL_DAY_VIEW]))->selection_start_day = weekday;
+	        (E_DAY_VIEW (priv->views[GNOME_CAL_DAY_VIEW]))->selection_end_day = weekday;
+	        gtk_widget_queue_draw ((E_DAY_VIEW (priv->views[GNOME_CAL_DAY_VIEW]))->main_canvas);
+
+	} else if (priv->current_view_type == GNOME_CAL_WEEK_VIEW) {
+	        (E_WEEK_VIEW (priv->views[GNOME_CAL_WEEK_VIEW]))->selection_start_day = weekday;
+        	(E_WEEK_VIEW (priv->views[GNOME_CAL_WEEK_VIEW]))->selection_end_day = weekday;
+	        gtk_widget_queue_draw ((E_WEEK_VIEW (priv->views[GNOME_CAL_WEEK_VIEW]))->main_canvas);
+
+	} else if (priv->current_view_type == GNOME_CAL_WORK_WEEK_VIEW) {
+	        (E_DAY_VIEW (priv->views[GNOME_CAL_WORK_WEEK_VIEW]))->selection_start_day = weekday;
+        	(E_DAY_VIEW (priv->views[GNOME_CAL_WORK_WEEK_VIEW]))->selection_end_day = weekday;
+	        gtk_widget_queue_draw ((E_DAY_VIEW (priv->views[GNOME_CAL_WORK_WEEK_VIEW]))->main_canvas);
+
+	} else if (priv->current_view_type == GNOME_CAL_MONTH_VIEW) {
+		gint monthday, offset = 0;
+
+        	monthday = g_date_day (&date) - 1;
+		if (monthday%7)
+			offset = 7 - (monthday % 7);
+		monthday += (offset + weekday)%7;
+
+	        (E_WEEK_VIEW (priv->views[GNOME_CAL_MONTH_VIEW]))->selection_start_day = monthday;
+        	(E_WEEK_VIEW (priv->views[GNOME_CAL_MONTH_VIEW]))->selection_end_day = monthday;
+	        gtk_widget_queue_draw ((E_WEEK_VIEW (priv->views[GNOME_CAL_MONTH_VIEW]))->main_canvas);
+	}
+
+	update_view_time (gcal, priv->current_view_type, priv->base_view_time);
+	gnome_calendar_update_date_navigator (gcal);
+	gnome_calendar_notify_dates_shown_changed (gcal);
 }
 
 static void
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/calendar/ChangeLog,v
retrieving revision 1.2825
diff -u -p -r1.2825 ChangeLog
--- ChangeLog	3 Oct 2005 11:20:50 -0000	1.2825
+++ ChangeLog	3 Oct 2005 13:10:43 -0000
@@ -1,3 +1,11 @@
+2006-10-03  Dinesh Layek <LDinesh novell com>
+	
+	Fixes #271842
+	* gui/gnome-cal.c (gnome_calendar_goto):
+	* gui/gnome-cal.c (gnome_calendar_dayjump):
+	* gui/gnome-cal.c (update_view_time):
+	selected time range is updated at gnome_calendar_goto only for the current view.
+
 2005-10-02  Srinivasa Ragavan <sragavan novell com>
 	
 	Provides across calendars keyboard accelerators for popup menus


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