diff options
author | Harry Lu <harry.lu@sun.com> | 2003-10-24 00:10:09 +0800 |
---|---|---|
committer | Rodrigo Moya <rodrigo@src.gnome.org> | 2003-10-24 00:10:09 +0800 |
commit | eca844b013c8de01e2b6dcdecffdf50e1ecab7b6 (patch) | |
tree | 631264e05bdd79eb9e43507eadfac45cd5f95620 | |
parent | 39e56385b1abe6e053dd04004cc4fecbc0cf2d86 (diff) | |
download | gsoc2013-evolution-eca844b013c8de01e2b6dcdecffdf50e1ecab7b6.tar.gz gsoc2013-evolution-eca844b013c8de01e2b6dcdecffdf50e1ecab7b6.tar.zst gsoc2013-evolution-eca844b013c8de01e2b6dcdecffdf50e1ecab7b6.zip |
remove and free op before return.
2003-10-23 Harry Lu <harry.lu@sun.com>
* cal-client/cal-client.c: (cal_client_get_timezone): remove and free
op before return.
* gui/e-cal-view.c (e_cal_view_add_event): modified from
selection_received_add_event() so that it call be called out of
e-cal-view.c.
(selection_received): modified to call e_cal_view_add_event().
* gui/e-cal-view.h: add declaration for e_cal_view_add_event().
* gui/e-day-view.c (e_day_view_on_drag_data_get): Provide a
icalcomponent for both TARGET_CALENDAR_EVENT and TARGET_VCALENDAR.
(e_day_view_on_top_canvas_drag_data_received): If dragging between
different windows, make it works like a copy and paste.
(e_day_view_on_main_canvas_drag_data_received): ditto.
svn path=/trunk/; revision=23041
-rw-r--r-- | calendar/ChangeLog | 18 | ||||
-rw-r--r-- | calendar/cal-client/cal-client.c | 11 | ||||
-rw-r--r-- | calendar/gui/e-cal-view.c | 61 | ||||
-rw-r--r-- | calendar/gui/e-cal-view.h | 2 | ||||
-rw-r--r-- | calendar/gui/e-calendar-view.c | 61 | ||||
-rw-r--r-- | calendar/gui/e-calendar-view.h | 2 | ||||
-rw-r--r-- | calendar/gui/e-day-view.c | 178 |
7 files changed, 276 insertions, 57 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog index 732a9196c5..3f825ddeff 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,21 @@ +2003-10-23 Harry Lu <harry.lu@sun.com> + + * cal-client/cal-client.c: (cal_client_get_timezone): remove and free + op before return. + + * gui/e-cal-view.c (e_cal_view_add_event): modified from + selection_received_add_event() so that it call be called out of + e-cal-view.c. + (selection_received): modified to call e_cal_view_add_event(). + + * gui/e-cal-view.h: add declaration for e_cal_view_add_event(). + + * gui/e-day-view.c (e_day_view_on_drag_data_get): Provide a + icalcomponent for both TARGET_CALENDAR_EVENT and TARGET_VCALENDAR. + (e_day_view_on_top_canvas_drag_data_received): If dragging between + different windows, make it works like a copy and paste. + (e_day_view_on_main_canvas_drag_data_received): ditto. + 2003-10-23 JP Rosevear <jpr@ximian.com> * cal-util/cal-recur.c: update g_date calls to non-deprecated diff --git a/calendar/cal-client/cal-client.c b/calendar/cal-client/cal-client.c index 8aea224485..91242a20c5 100644 --- a/calendar/cal-client/cal-client.c +++ b/calendar/cal-client/cal-client.c @@ -3482,13 +3482,22 @@ cal_client_get_timezone (CalClient *client, const char *tzid, icaltimezone **zon g_free (our_op->string); /* FIXME Invalid object status? */ - if (!icalcomp) + if (!icalcomp) { + e_calendar_remove_op (client, our_op); + e_mutex_unlock (our_op->mutex); + e_calendar_free_op (our_op); + E_CALENDAR_CHECK_STATUS (E_CALENDAR_STATUS_OBJECT_NOT_FOUND, error); + } *zone = icaltimezone_new (); if (!icaltimezone_set_component (*zone, icalcomp)) { icaltimezone_free (*zone, 1); + e_calendar_remove_op (client, our_op); + e_mutex_unlock (our_op->mutex); + e_calendar_free_op (our_op); + E_CALENDAR_CHECK_STATUS (E_CALENDAR_STATUS_OBJECT_NOT_FOUND, error); } diff --git a/calendar/gui/e-cal-view.c b/calendar/gui/e-cal-view.c index a95f976d21..184e5d6689 100644 --- a/calendar/gui/e-cal-view.c +++ b/calendar/gui/e-cal-view.c @@ -276,23 +276,51 @@ selection_clear_event (GtkWidget *invisible, } } -static void -selection_received_add_event (ECalView *cal_view, CalClient *client, time_t selected_time_start, - icaltimezone *default_zone, icalcomponent *icalcomp) +void +e_cal_view_add_event (ECalView *cal_view, CalClient *client, time_t dtstart, + icaltimezone *default_zone, icalcomponent *icalcomp, gboolean in_top_canvas) { CalComponent *comp; - struct icaltimetype itime; - time_t tt_start, tt_end; + struct icaltimetype itime, old_dtstart, old_dtend; + time_t tt_start, tt_end, new_dtstart; struct icaldurationtype ic_dur; char *uid; + gint start_offset, end_offset; + gboolean all_day_event; + + start_offset = 0; + end_offset = 0; - tt_start = icaltime_as_timet (icalcomponent_get_dtstart (icalcomp)); - tt_end = icaltime_as_timet (icalcomponent_get_dtend (icalcomp)); + old_dtstart = icalcomponent_get_dtstart (icalcomp); + tt_start = icaltime_as_timet (old_dtstart); + old_dtend = icalcomponent_get_dtend (icalcomp); + tt_end = icaltime_as_timet (old_dtend); ic_dur = icaldurationtype_from_int (tt_end - tt_start); - itime = icaltime_from_timet_with_zone (selected_time_start, FALSE, default_zone); + if (icaldurationtype_as_int (ic_dur) > 60*60*24) { + /* This is a long event */ + start_offset = old_dtstart.hour * 60 + old_dtstart.minute; + 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; + + if (in_top_canvas) + new_dtstart = dtstart + start_offset * 60; + else + new_dtstart = dtstart; + + itime = icaltime_from_timet_with_zone (new_dtstart, FALSE, default_zone); + if (all_day_event) + itime.is_date = TRUE; icalcomponent_set_dtstart (icalcomp, itime); + itime = icaltime_add (itime, ic_dur); + if (all_day_event) + itime.is_date = TRUE; icalcomponent_set_dtend (icalcomp, itime); /* FIXME The new uid stuff can go away once we actually set it in the backend */ @@ -303,12 +331,15 @@ selection_received_add_event (ECalView *cal_view, CalClient *client, time_t sele cal_component_set_uid (comp, uid); /* FIXME Error handling */ - cal_client_create_object (client, cal_component_get_icalcomponent (comp), NULL, NULL); - if (itip_organizer_is_user (comp, client) && - send_component_dialog ((GtkWindow *) gtk_widget_get_toplevel (GTK_WIDGET (cal_view)), + if (cal_client_create_object (client, cal_component_get_icalcomponent (comp), NULL, NULL)) { + if (itip_organizer_is_user (comp, client) && + send_component_dialog ((GtkWindow *) gtk_widget_get_toplevel (GTK_WIDGET (cal_view)), client, comp, TRUE)) { - itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, + itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, client, NULL); + } + } else { + g_message (G_STRLOC ": Could not create the object!"); } free (uid); @@ -364,8 +395,8 @@ selection_received (GtkWidget *invisible, while (subcomp) { child_kind = icalcomponent_isa (subcomp); if (child_kind == ICAL_VEVENT_COMPONENT) - selection_received_add_event (cal_view, client, selected_time_start, - default_zone, subcomp); + e_cal_view_add_event (cal_view, client, selected_time_start, + default_zone, subcomp, FALSE); else if (child_kind == ICAL_VTIMEZONE_COMPONENT) { icaltimezone *zone; @@ -383,7 +414,7 @@ selection_received (GtkWidget *invisible, icalcomponent_free (icalcomp); } else { - selection_received_add_event (cal_view, client, selected_time_start, default_zone, icalcomp); + e_cal_view_add_event (cal_view, client, selected_time_start, default_zone, icalcomp, FALSE); } e_cal_view_set_status_message (cal_view, NULL); diff --git a/calendar/gui/e-cal-view.h b/calendar/gui/e-cal-view.h index 9a09a5236a..04d6d079bb 100644 --- a/calendar/gui/e-cal-view.h +++ b/calendar/gui/e-cal-view.h @@ -116,6 +116,8 @@ void e_cal_view_delete_selected_occurrence (ECalView *cal_view); GtkMenu *e_cal_view_create_popup_menu (ECalView *cal_view); +void e_cal_view_add_event (ECalView *cal_view, CalClient *client, time_t dtstart, + icaltimezone *default_zone, icalcomponent *icalcomp, gboolean in_top_canvas); void e_cal_view_new_appointment_for (ECalView *cal_view, time_t dtstart, time_t dtend, diff --git a/calendar/gui/e-calendar-view.c b/calendar/gui/e-calendar-view.c index a95f976d21..184e5d6689 100644 --- a/calendar/gui/e-calendar-view.c +++ b/calendar/gui/e-calendar-view.c @@ -276,23 +276,51 @@ selection_clear_event (GtkWidget *invisible, } } -static void -selection_received_add_event (ECalView *cal_view, CalClient *client, time_t selected_time_start, - icaltimezone *default_zone, icalcomponent *icalcomp) +void +e_cal_view_add_event (ECalView *cal_view, CalClient *client, time_t dtstart, + icaltimezone *default_zone, icalcomponent *icalcomp, gboolean in_top_canvas) { CalComponent *comp; - struct icaltimetype itime; - time_t tt_start, tt_end; + struct icaltimetype itime, old_dtstart, old_dtend; + time_t tt_start, tt_end, new_dtstart; struct icaldurationtype ic_dur; char *uid; + gint start_offset, end_offset; + gboolean all_day_event; + + start_offset = 0; + end_offset = 0; - tt_start = icaltime_as_timet (icalcomponent_get_dtstart (icalcomp)); - tt_end = icaltime_as_timet (icalcomponent_get_dtend (icalcomp)); + old_dtstart = icalcomponent_get_dtstart (icalcomp); + tt_start = icaltime_as_timet (old_dtstart); + old_dtend = icalcomponent_get_dtend (icalcomp); + tt_end = icaltime_as_timet (old_dtend); ic_dur = icaldurationtype_from_int (tt_end - tt_start); - itime = icaltime_from_timet_with_zone (selected_time_start, FALSE, default_zone); + if (icaldurationtype_as_int (ic_dur) > 60*60*24) { + /* This is a long event */ + start_offset = old_dtstart.hour * 60 + old_dtstart.minute; + 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; + + if (in_top_canvas) + new_dtstart = dtstart + start_offset * 60; + else + new_dtstart = dtstart; + + itime = icaltime_from_timet_with_zone (new_dtstart, FALSE, default_zone); + if (all_day_event) + itime.is_date = TRUE; icalcomponent_set_dtstart (icalcomp, itime); + itime = icaltime_add (itime, ic_dur); + if (all_day_event) + itime.is_date = TRUE; icalcomponent_set_dtend (icalcomp, itime); /* FIXME The new uid stuff can go away once we actually set it in the backend */ @@ -303,12 +331,15 @@ selection_received_add_event (ECalView *cal_view, CalClient *client, time_t sele cal_component_set_uid (comp, uid); /* FIXME Error handling */ - cal_client_create_object (client, cal_component_get_icalcomponent (comp), NULL, NULL); - if (itip_organizer_is_user (comp, client) && - send_component_dialog ((GtkWindow *) gtk_widget_get_toplevel (GTK_WIDGET (cal_view)), + if (cal_client_create_object (client, cal_component_get_icalcomponent (comp), NULL, NULL)) { + if (itip_organizer_is_user (comp, client) && + send_component_dialog ((GtkWindow *) gtk_widget_get_toplevel (GTK_WIDGET (cal_view)), client, comp, TRUE)) { - itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, + itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, client, NULL); + } + } else { + g_message (G_STRLOC ": Could not create the object!"); } free (uid); @@ -364,8 +395,8 @@ selection_received (GtkWidget *invisible, while (subcomp) { child_kind = icalcomponent_isa (subcomp); if (child_kind == ICAL_VEVENT_COMPONENT) - selection_received_add_event (cal_view, client, selected_time_start, - default_zone, subcomp); + e_cal_view_add_event (cal_view, client, selected_time_start, + default_zone, subcomp, FALSE); else if (child_kind == ICAL_VTIMEZONE_COMPONENT) { icaltimezone *zone; @@ -383,7 +414,7 @@ selection_received (GtkWidget *invisible, icalcomponent_free (icalcomp); } else { - selection_received_add_event (cal_view, client, selected_time_start, default_zone, icalcomp); + e_cal_view_add_event (cal_view, client, selected_time_start, default_zone, icalcomp, FALSE); } e_cal_view_set_status_message (cal_view, NULL); diff --git a/calendar/gui/e-calendar-view.h b/calendar/gui/e-calendar-view.h index 9a09a5236a..04d6d079bb 100644 --- a/calendar/gui/e-calendar-view.h +++ b/calendar/gui/e-calendar-view.h @@ -116,6 +116,8 @@ void e_cal_view_delete_selected_occurrence (ECalView *cal_view); GtkMenu *e_cal_view_create_popup_menu (ECalView *cal_view); +void e_cal_view_add_event (ECalView *cal_view, CalClient *client, time_t dtstart, + icaltimezone *default_zone, icalcomponent *icalcomp, gboolean in_top_canvas); void e_cal_view_new_appointment_for (ECalView *cal_view, time_t dtstart, time_t dtend, diff --git a/calendar/gui/e-day-view.c b/calendar/gui/e-day-view.c index 08c7ef2fa3..92e356af99 100644 --- a/calendar/gui/e-day-view.c +++ b/calendar/gui/e-day-view.c @@ -6736,15 +6736,8 @@ e_day_view_on_drag_data_get (GtkWidget *widget, event = &g_array_index (day_view->events[day], EDayViewEvent, event_num); - if (info == TARGET_CALENDAR_EVENT) { - const char *event_uid; - - event_uid = icalcomponent_get_uid (event->comp_data->icalcomp); - g_return_if_fail (event_uid != NULL); - - gtk_selection_data_set (selection_data, selection_data->target, - 8, event_uid, strlen (event_uid)); - } else if (info == TARGET_VCALENDAR) { + if (info == TARGET_CALENDAR_EVENT || info == TARGET_VCALENDAR) { + /* we will pass an icalcalendar component for both types */ char *comp_str; icalcomponent *vcal; @@ -6779,26 +6772,32 @@ e_day_view_on_top_canvas_drag_data_received (GtkWidget *widget, ECalViewPosition pos; gint day, start_day, end_day, num_days; gint start_offset, end_offset; - gchar *event_uid; CalComponent *comp; CalComponentDateTime date; struct icaltimetype itt; time_t dt; gboolean all_day_event; CalClient *client; + gboolean drag_from_same_window; + + if (day_view->drag_event_day != -1) + drag_from_same_window = TRUE; + else + drag_from_same_window = FALSE; client = e_cal_model_get_default_client (e_cal_view_get_model (E_CAL_VIEW (day_view))); /* Note that we only support DnD within the EDayView at present. */ if ((data->length >= 0) && (data->format == 8) && (day_view->drag_event_day != -1)) { + /* We are dragging in the same window */ + pos = e_day_view_convert_position_in_top_canvas (day_view, x, y, &day, NULL); if (pos != E_CAL_VIEW_POS_OUTSIDE) { CalObjModType mod = CALOBJ_MOD_ALL; GtkWindow *toplevel; - const char *uid; num_days = 1; start_offset = 0; @@ -6829,13 +6828,6 @@ e_day_view_on_top_canvas_drag_data_received (GtkWidget *widget, client = event->comp_data->client; - event_uid = data->data; - - uid = icalcomponent_get_uid (event->comp_data->icalcomp); - - if (!event_uid || !uid || strcmp (event_uid, uid)) - g_warning ("Unexpected event UID"); - /* We clone the event since we don't want to change the original comp here. Otherwise we would not detect that the event's time @@ -6896,6 +6888,7 @@ e_day_view_on_top_canvas_drag_data_received (GtkWidget *widget, } toplevel = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (day_view))); + cal_component_commit_sequence (comp); if (cal_client_modify_object (client, cal_component_get_icalcomponent (comp), mod, NULL)) { if (itip_organizer_is_user (comp, client) @@ -6910,6 +6903,72 @@ e_day_view_on_top_canvas_drag_data_received (GtkWidget *widget, } } + if ((data->length >= 0) && (data->format == 8) + && !drag_from_same_window) { + /* We are dragging between different window */ + + char *comp_str, *default_tzid; + icalcomponent *icalcomp; + icalcomponent_kind kind; + time_t dtstart; + icaltimezone *default_zone; + + pos = e_day_view_convert_position_in_top_canvas (day_view, + x, y, &day, + NULL); + if (pos == E_CAL_VIEW_POS_OUTSIDE) + goto error; + + comp_str = (char *) data->data; + icalcomp = icalparser_parse_string ((const char *) comp_str); + if (!icalcomp) + goto error; + + default_tzid = calendar_config_get_timezone (); + cal_client_get_timezone (client, default_tzid, &default_zone, NULL); + + /* check the type of the component */ + kind = icalcomponent_isa (icalcomp); + if (kind != ICAL_VCALENDAR_COMPONENT && kind != ICAL_VEVENT_COMPONENT) + goto error; + + dtstart = day_view->day_starts[day]; + + if (kind == ICAL_VCALENDAR_COMPONENT) { + icalcomponent_kind child_kind; + icalcomponent *subcomp; + + subcomp = icalcomponent_get_first_component (icalcomp, ICAL_ANY_COMPONENT); + while (subcomp) { + child_kind = icalcomponent_isa (subcomp); + if (child_kind == ICAL_VEVENT_COMPONENT) + e_cal_view_add_event (E_CAL_VIEW (day_view), client, dtstart, + default_zone, subcomp, TRUE); + else if (child_kind == ICAL_VTIMEZONE_COMPONENT) { + icaltimezone *zone; + + zone = icaltimezone_new (); + icaltimezone_set_component (zone, subcomp); + cal_client_add_timezone (client, zone, NULL); + + icaltimezone_free (zone, 1); + } + + subcomp = icalcomponent_get_next_component ( + icalcomp, ICAL_ANY_COMPONENT); + } + + icalcomponent_free (icalcomp); + + } else { + e_cal_add_event (E_CAL_VIEW (day_view), client, dtstart, default_zone, icalcomp, TRUE); + } + + gtk_drag_finish (context, TRUE, TRUE, time); + return; + } + +error: gtk_drag_finish (context, FALSE, FALSE, time); } @@ -6928,12 +6987,17 @@ e_day_view_on_main_canvas_drag_data_received (GtkWidget *widget, ECalViewPosition pos; gint day, row, start_row, end_row, num_rows, scroll_x, scroll_y; gint start_offset, end_offset; - gchar *event_uid; CalComponent *comp; CalComponentDateTime date; struct icaltimetype itt; time_t dt; CalClient *client; + gboolean drag_from_same_window; + + if (day_view->drag_event_day != -1) + drag_from_same_window = TRUE; + else + drag_from_same_window = FALSE; client = e_cal_model_get_default_client (e_cal_view_get_model (E_CAL_VIEW (day_view))); @@ -6945,13 +7009,14 @@ e_day_view_on_main_canvas_drag_data_received (GtkWidget *widget, /* Note that we only support DnD within the EDayView at present. */ if ((data->length >= 0) && (data->format == 8) && (day_view->drag_event_day != -1)) { + /* We are dragging in the same window */ + pos = e_day_view_convert_position_in_main_canvas (day_view, x, y, &day, &row, NULL); if (pos != E_CAL_VIEW_POS_OUTSIDE) { CalObjModType mod = CALOBJ_MOD_ALL; GtkWindow *toplevel; - const char *uid; num_rows = 1; start_offset = 0; @@ -6982,12 +7047,6 @@ e_day_view_on_main_canvas_drag_data_received (GtkWidget *widget, client = event->comp_data->client; - event_uid = data->data; - - uid = icalcomponent_get_uid (event->comp_data->icalcomp); - if (!event_uid || !uid || strcmp (event_uid, uid)) - g_warning ("Unexpected event UID"); - /* We use a temporary shallow copy of comp since we don't want to change the original comp here. Otherwise we would not detect that the event's time @@ -7025,6 +7084,7 @@ e_day_view_on_main_canvas_drag_data_received (GtkWidget *widget, } toplevel = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (day_view))); + cal_component_commit_sequence (comp); if (cal_client_modify_object (client, cal_component_get_icalcomponent (comp), mod, NULL)) { if (itip_organizer_is_user (comp, client) @@ -7039,6 +7099,72 @@ e_day_view_on_main_canvas_drag_data_received (GtkWidget *widget, } } + if ((data->length >= 0) && (data->format == 8) + && !drag_from_same_window) { + /* We are dragging between different window */ + + char *comp_str, *default_tzid;; + icalcomponent *icalcomp; + icalcomponent_kind kind; + time_t dtstart; + icaltimezone *default_zone; + + pos = e_day_view_convert_position_in_main_canvas (day_view, + x, y, &day, + &row, NULL); + if (pos == E_CAL_VIEW_POS_OUTSIDE) + goto error; + + comp_str = (char *) data->data; + icalcomp = icalparser_parse_string ((const char *) comp_str); + if (!icalcomp) + goto error; + + default_tzid = calendar_config_get_timezone (); + cal_client_get_timezone (client, default_tzid, &default_zone, NULL); + + /* check the type of the component */ + kind = icalcomponent_isa (icalcomp); + if (kind != ICAL_VCALENDAR_COMPONENT && kind != ICAL_VEVENT_COMPONENT) + goto error; + + dtstart = e_day_view_convert_grid_position_to_time (day_view, day, row); + + if (kind == ICAL_VCALENDAR_COMPONENT) { + icalcomponent_kind child_kind; + icalcomponent *subcomp; + + subcomp = icalcomponent_get_first_component (icalcomp, ICAL_ANY_COMPONENT); + while (subcomp) { + child_kind = icalcomponent_isa (subcomp); + if (child_kind == ICAL_VEVENT_COMPONENT) + e_cal_view_add_event (E_CAL_VIEW (day_view), client, dtstart, + default_zone, subcomp, FALSE); + else if (child_kind == ICAL_VTIMEZONE_COMPONENT) { + icaltimezone *zone; + + zone = icaltimezone_new (); + icaltimezone_set_component (zone, subcomp); + cal_client_add_timezone (client, zone, NULL); + + icaltimezone_free (zone, 1); + } + + subcomp = icalcomponent_get_next_component ( + icalcomp, ICAL_ANY_COMPONENT); + } + + icalcomponent_free (icalcomp); + + } else { + e_cal_add_event (E_CAL_VIEW (day_view), client, dtstart, default_zone, icalcomp, FALSE); + } + + gtk_drag_finish (context, TRUE, TRUE, time); + return; + } + +error: gtk_drag_finish (context, FALSE, FALSE, time); } |