[evolution-patches] A patch for calendar based on trunk



Hi,

This patch is aimed for trunk. We have found the behaviour of copy & paste is different from that of drag and drop. Suppose we have a 8:30am-9:00am appointment, for example, we get an all-day event if we drag it from main canvas to top canvas. On the other hand, the result will be a 12:00am-12:30am appointment if we perform a copy & paste on
the same original appointment.
Enclosed is a patch to make the two actions behave the same way described as follows:
In day view and work week view
       from main canvas to top canvas
before copy or drag: short event, after paste or drop: all-day event
       from main canvas to main canvas
before copy or drag: short event, after paste or drop: short event
       from top canvas to top canvas
before copy or drag: all-day event, after paste or drop: all-day event before copy or drag: long event, after paste or drop: long event
       from top canvas to main canvas
before copy or drag: all-day event, after paste or drop: short event before copy or drag: long event, after paste or drop: short event
I hope the above pseudo code is clear enough:-)
In week view, month view and list view life is pretty simple since there's no top canvas in these three views. We just get what
we copy or drag after we perform paste or drop.

Best regards
Index: calendar/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/calendar/ChangeLog,v
retrieving revision 1.2157
diff -u -r1.2157 ChangeLog
--- calendar/ChangeLog	16 Feb 2004 17:57:11 -0000	1.2157
+++ calendar/ChangeLog	17 Feb 2004 09:07:46 -0000
@@ -1,3 +1,9 @@
+2004-02-17  Kidd Wang  <kidd wang sun com>
+
+	* gui/e-cal-view.c: (e_calendar_view_add_event),
+	(clipboard_get_text_cb): revise the copy & paste action to the same
+	as drag & drop.
+
 2004-02-16  Rodrigo Moya <rodrigo ximian com>
 
 	* gui/alarm-notify/alarm-queue.c (tray_icon_clicked_cb): removed buggy
Index: calendar/gui/e-cal-view.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/e-cal-view.c,v
retrieving revision 1.34
diff -u -r1.34 e-cal-view.c
--- calendar/gui/e-cal-view.c	6 Feb 2004 03:03:41 -0000	1.34
+++ calendar/gui/e-cal-view.c	17 Feb 2004 09:07:47 -0000
@@ -341,10 +341,12 @@
 	ECalComponent *comp;
 	struct icaltimetype itime, old_dtstart, old_dtend;
 	time_t tt_start, tt_end, new_dtstart;
-	struct icaldurationtype ic_dur;
+	struct icaldurationtype ic_dur, ic_oneday;
 	char *uid;
 	gint start_offset, end_offset;
-	gboolean all_day_event;
+	gboolean all_day_event = FALSE;
+	GnomeCalendarViewType view_type;
+	ECalComponentDateTime dt;
 
 	start_offset = 0;
 	end_offset = 0;
@@ -361,11 +363,37 @@
 		end_offset = old_dtstart.hour * 60 + old_dtend.minute;
 	}
 
-	if (start_offset == 0 && end_offset == 0 && in_top_canvas)
-		all_day_event = TRUE;
-	else
-		all_day_event = FALSE;
+	ic_oneday = icaldurationtype_null_duration ();
+	ic_oneday.days = 1;
 
+	view_type = gnome_calendar_get_view (cal_view->priv->calendar);
+
+	switch (view_type) {
+	case GNOME_CAL_DAY_VIEW:
+	case GNOME_CAL_WORK_WEEK_VIEW:
+		if (start_offset == 0 && end_offset == 0 && in_top_canvas)
+			all_day_event = TRUE;
+		
+		if (all_day_event) {
+			ic_dur = ic_oneday;
+		} else if (icaldurationtype_as_int (ic_dur) >= 60*60*24
+				&& !in_top_canvas) {
+			/* copy & paste from top canvas to main canvas */
+			int time_divisions;
+
+			time_divisions = calendar_config_get_time_divisions ();
+			ic_dur = icaldurationtype_from_int (time_divisions * 60);
+		}
+		break;
+	case GNOME_CAL_WEEK_VIEW:
+	case GNOME_CAL_MONTH_VIEW:
+	case GNOME_CAL_LIST_VIEW:
+		if (old_dtstart.is_date && old_dtend.is_date
+			&& memcmp (&ic_dur, &ic_oneday, sizeof(ic_dur)) == 0)
+			all_day_event = TRUE;
+		break;
+	}
+	
 	if (in_top_canvas)
 		new_dtstart = dtstart + start_offset * 60;
 	else
@@ -376,6 +404,7 @@
 		itime.is_date = TRUE;
 	icalcomponent_set_dtstart (icalcomp, itime);
 
+	itime.is_date = FALSE;
 	itime = icaltime_add (itime, ic_dur);
 	if (all_day_event)
 		itime.is_date = TRUE;
@@ -388,6 +417,16 @@
 		comp, icalcomponent_new_clone (icalcomp));
 	e_cal_component_set_uid (comp, uid);
 
+	/* set the timezone properly */
+	dt.value = &itime;
+	e_cal_component_get_dtstart (comp, &dt);
+	dt.tzid = icaltimezone_get_tzid (default_zone);
+	e_cal_component_set_dtstart (comp, &dt);
+	e_cal_component_get_dtend (comp, &dt);
+	dt.tzid = icaltimezone_get_tzid (default_zone);
+	e_cal_component_set_dtend (comp, &dt);
+	e_cal_component_commit_sequence (comp);
+
 	/* FIXME Error handling */
 	if (e_cal_create_object (client, e_cal_component_get_icalcomponent (comp), NULL, NULL)) {
 		if (itip_organizer_is_user (comp, client) &&
@@ -761,6 +800,7 @@
 	time_t selected_time_start, selected_time_end;
 	icaltimezone *default_zone;
 	ECal *client;
+	gboolean in_top_canvas;
 
 	g_return_if_fail (E_IS_CALENDAR_VIEW (cal_view));
 
@@ -780,6 +820,11 @@
 	e_calendar_view_set_status_message (cal_view, _("Updating objects"));
 	e_calendar_view_get_selected_time_range (cal_view, &selected_time_start, &selected_time_end);
 
+	if ((selected_time_end - selected_time_start) == 60 * 60 * 24)
+		in_top_canvas = TRUE;
+	else
+		in_top_canvas = FALSE;
+
 	/* FIXME Timezone handling */
 	if (kind == ICAL_VCALENDAR_COMPONENT) {
 		icalcomponent_kind child_kind;
@@ -790,7 +835,7 @@
 			child_kind = icalcomponent_isa (subcomp);
 			if (child_kind == ICAL_VEVENT_COMPONENT)
 				e_calendar_view_add_event (cal_view, client, selected_time_start, 
-						      default_zone, subcomp, FALSE);
+						      default_zone, subcomp, in_top_canvas);
 			else if (child_kind == ICAL_VTIMEZONE_COMPONENT) {
 				icaltimezone *zone;
 
@@ -808,7 +853,7 @@
 		icalcomponent_free (icalcomp);
 
 	} else {
-		e_calendar_view_add_event (cal_view, client, selected_time_start, default_zone, icalcomp, FALSE);
+		e_calendar_view_add_event (cal_view, client, selected_time_start, default_zone, icalcomp, in_top_canvas);
 	}
 
 	e_calendar_view_set_status_message (cal_view, NULL);


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