diff options
Diffstat (limited to 'calendar')
-rw-r--r-- | calendar/gui/e-calendar-view.c | 339 | ||||
-rw-r--r-- | calendar/gui/e-calendar-view.h | 4 | ||||
-rw-r--r-- | calendar/gui/e-memo-table.c | 155 | ||||
-rw-r--r-- | calendar/gui/e-memo-table.h | 1 | ||||
-rw-r--r-- | calendar/gui/e-task-table.c | 312 | ||||
-rw-r--r-- | calendar/gui/e-task-table.h | 1 |
6 files changed, 411 insertions, 401 deletions
diff --git a/calendar/gui/e-calendar-view.c b/calendar/gui/e-calendar-view.c index 2bfa0918c3..57973828a3 100644 --- a/calendar/gui/e-calendar-view.c +++ b/calendar/gui/e-calendar-view.c @@ -103,6 +103,138 @@ G_DEFINE_ABSTRACT_TYPE_WITH_CODE (ECalendarView, e_calendar_view, GTK_TYPE_TABLE G_IMPLEMENT_INTERFACE (E_TYPE_SELECTABLE, calendar_view_selectable_init)); static void +calendar_view_add_retract_data (ECalComponent *comp, + const gchar *retract_comment, + CalObjModType mod) +{ + icalcomponent *icalcomp = NULL; + icalproperty *icalprop = NULL; + + icalcomp = e_cal_component_get_icalcomponent (comp); + if (retract_comment && *retract_comment) + icalprop = icalproperty_new_x (retract_comment); + else + icalprop = icalproperty_new_x ("0"); + icalproperty_set_x_name (icalprop, "X-EVOLUTION-RETRACT-COMMENT"); + icalcomponent_add_property (icalcomp, icalprop); + + if (mod == CALOBJ_MOD_ALL) + icalprop = icalproperty_new_x ("All"); + else + icalprop = icalproperty_new_x ("This"); + icalproperty_set_x_name (icalprop, "X-EVOLUTION-RECUR-MOD"); + icalcomponent_add_property (icalcomp, icalprop); +} + +static gboolean +calendar_view_check_for_retract (ECalComponent *comp, + ECal *client) +{ + ECalComponentOrganizer organizer; + const gchar *strip; + gchar *email = NULL; + gboolean ret_val; + + if (!e_cal_component_has_attendees (comp)) + return FALSE; + + if (!e_cal_get_save_schedules (client)) + return FALSE; + + e_cal_component_get_organizer (comp, &organizer); + strip = itip_strip_mailto (organizer.value); + + ret_val = + e_cal_get_cal_address (client, &email, NULL) && + (g_ascii_strcasecmp (email, strip) == 0); + + g_free (email); + + return ret_val; +} + +static void +calendar_view_delete_event (ECalendarView *cal_view, + ECalendarViewEvent *event) +{ + ECalComponent *comp; + ECalComponentVType vtype; + gboolean delete = FALSE; + GError *error = NULL; + + comp = e_cal_component_new (); + e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp)); + vtype = e_cal_component_get_vtype (comp); + + /*FIXME remove it once the we dont set the recurrence id for all the generated instances */ + if (!e_cal_get_static_capability (event->comp_data->client, CAL_STATIC_CAPABILITY_RECURRENCES_NO_MASTER)) + e_cal_component_set_recurid (comp, NULL); + + /*FIXME Retract should be moved to Groupwise features plugin */ + if (calendar_view_check_for_retract (comp, event->comp_data->client)) { + gchar *retract_comment = NULL; + gboolean retract = FALSE; + + delete = prompt_retract_dialog (comp, &retract_comment, GTK_WIDGET (cal_view), &retract); + if (retract) { + GList *users = NULL; + icalcomponent *icalcomp = NULL, *mod_comp = NULL; + + calendar_view_add_retract_data ( + comp, retract_comment, CALOBJ_MOD_ALL); + icalcomp = e_cal_component_get_icalcomponent (comp); + icalcomponent_set_method (icalcomp, ICAL_METHOD_CANCEL); + if (!e_cal_send_objects (event->comp_data->client, icalcomp, &users, + &mod_comp, &error)) { + delete_error_dialog (error, E_CAL_COMPONENT_EVENT); + g_clear_error (&error); + error = NULL; + } else { + + if (mod_comp) + icalcomponent_free (mod_comp); + + if (users) { + g_list_foreach (users, (GFunc) g_free, NULL); + g_list_free (users); + } + } + } + } else + delete = delete_component_dialog (comp, FALSE, 1, vtype, GTK_WIDGET (cal_view)); + + if (delete) { + const gchar *uid; + gchar *rid = NULL; + + if ((itip_organizer_is_user (comp, event->comp_data->client) || itip_sentby_is_user (comp, event->comp_data->client)) + && cancel_component_dialog ((GtkWindow *) gtk_widget_get_toplevel (GTK_WIDGET (cal_view)), + event->comp_data->client, + comp, TRUE)) + itip_send_comp (E_CAL_COMPONENT_METHOD_CANCEL, comp, + event->comp_data->client, NULL, NULL, NULL, TRUE, FALSE); + + e_cal_component_get_uid (comp, &uid); + if (!uid || !*uid) { + g_object_unref (comp); + return; + } + rid = e_cal_component_get_recurid_as_string (comp); + if (e_cal_util_component_is_instance (event->comp_data->icalcomp) || e_cal_util_component_has_recurrences (event->comp_data->icalcomp)) + e_cal_remove_object_with_mod (event->comp_data->client, uid, + rid, CALOBJ_MOD_ALL, &error); + else + e_cal_remove_object (event->comp_data->client, uid, &error); + + delete_error_dialog (error, E_CAL_COMPONENT_EVENT); + g_clear_error (&error); + g_free (rid); + } + + g_object_unref (comp); +} + +static void calendar_view_set_model (ECalendarView *calendar_view, ECalModel *model) { @@ -189,6 +321,7 @@ calendar_view_update_actions (ESelectable *selectable, GList *list, *iter; gboolean sources_are_editable = TRUE; gboolean clipboard_has_calendar; + gboolean recurring = FALSE; gboolean sensitive; const gchar *tooltip; gint n_selected; @@ -200,13 +333,22 @@ calendar_view_update_actions (ESelectable *selectable, for (iter = list; iter != NULL; iter = iter->next) { ECalendarViewEvent *event = iter->data; + ECal *client; + icalcomponent *icalcomp; gboolean read_only; if (event == NULL || event->comp_data == NULL) continue; - e_cal_is_read_only (event->comp_data->client, &read_only, NULL); + client = event->comp_data->client; + icalcomp = event->comp_data->icalcomp; + + e_cal_is_read_only (client, &read_only, NULL); sources_are_editable &= !read_only; + + recurring |= + e_cal_util_component_is_instance (icalcomp) || + e_cal_util_component_has_recurrences (icalcomp); } g_list_free (list); @@ -232,6 +374,12 @@ calendar_view_update_actions (ESelectable *selectable, tooltip = _("Paste events from the clipboard"); gtk_action_set_sensitive (action, sensitive); gtk_action_set_tooltip (action, tooltip); + + action = e_focus_tracker_get_delete_selection_action (focus_tracker); + sensitive = (n_selected > 0) && sources_are_editable && !recurring; + tooltip = _("Delete selected events"); + gtk_action_set_sensitive (action, sensitive); + gtk_action_set_tooltip (action, tooltip); } static void @@ -520,6 +668,29 @@ calendar_view_paste_clipboard (ESelectable *selectable) } static void +calendar_view_delete_selection (ESelectable *selectable) +{ + ECalendarView *cal_view; + GList *selected, *iter; + + cal_view = E_CALENDAR_VIEW (selectable); + + selected = e_calendar_view_get_selected_events (cal_view); + + for (iter = selected; iter != NULL; iter = iter->next) { + ECalendarViewEvent *event = iter->data; + + /* XXX Why would this ever be NULL? */ + if (event == NULL) + continue; + + calendar_view_delete_event (cal_view, event); + } + + g_list_free (selected); +} + +static void e_calendar_view_class_init (ECalendarViewClass *class) { GObjectClass *object_class; @@ -659,6 +830,7 @@ calendar_view_selectable_init (ESelectableInterface *interface) interface->cut_clipboard = calendar_view_cut_clipboard; interface->copy_clipboard = calendar_view_copy_clipboard; interface->paste_clipboard = calendar_view_paste_clipboard; + interface->delete_selection = calendar_view_delete_selection; } void @@ -938,166 +1110,6 @@ e_calendar_view_update_query (ECalendarView *cal_view) class->update_query (cal_view); } -static void -add_retract_data (ECalComponent *comp, const gchar *retract_comment, CalObjModType mod) -{ - icalcomponent *icalcomp = NULL; - icalproperty *icalprop = NULL; - - icalcomp = e_cal_component_get_icalcomponent (comp); - if (retract_comment && *retract_comment) - icalprop = icalproperty_new_x (retract_comment); - else - icalprop = icalproperty_new_x ("0"); - icalproperty_set_x_name (icalprop, "X-EVOLUTION-RETRACT-COMMENT"); - icalcomponent_add_property (icalcomp, icalprop); - - if (mod == CALOBJ_MOD_ALL) - icalprop = icalproperty_new_x ("All"); - else - icalprop = icalproperty_new_x ("This"); - icalproperty_set_x_name (icalprop, "X-EVOLUTION-RECUR-MOD"); - icalcomponent_add_property (icalcomp, icalprop); -} - -static gboolean -check_for_retract (ECalComponent *comp, ECal *client) -{ - ECalComponentOrganizer org; - gchar *email = NULL; - const gchar *strip = NULL; - gboolean ret_val = FALSE; - - if (!(e_cal_component_has_attendees (comp) && - e_cal_get_save_schedules (client))) - return ret_val; - - e_cal_component_get_organizer (comp, &org); - strip = itip_strip_mailto (org.value); - - if (e_cal_get_cal_address (client, &email, NULL) && !g_ascii_strcasecmp (email, strip)) { - ret_val = TRUE; - } - - g_free (email); - return ret_val; -} - -static void -delete_event (ECalendarView *cal_view, ECalendarViewEvent *event) -{ - ECalComponent *comp; - ECalComponentVType vtype; - gboolean delete = FALSE; - GError *error = NULL; - - comp = e_cal_component_new (); - e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp)); - vtype = e_cal_component_get_vtype (comp); - - /*FIXME remove it once the we dont set the recurrence id for all the generated instances */ - if (!e_cal_get_static_capability (event->comp_data->client, CAL_STATIC_CAPABILITY_RECURRENCES_NO_MASTER)) - e_cal_component_set_recurid (comp, NULL); - - /*FIXME Retract should be moved to Groupwise features plugin */ - if (check_for_retract (comp, event->comp_data->client)) { - gchar *retract_comment = NULL; - gboolean retract = FALSE; - - delete = prompt_retract_dialog (comp, &retract_comment, GTK_WIDGET (cal_view), &retract); - if (retract) { - GList *users = NULL; - icalcomponent *icalcomp = NULL, *mod_comp = NULL; - - add_retract_data (comp, retract_comment, CALOBJ_MOD_ALL); - icalcomp = e_cal_component_get_icalcomponent (comp); - icalcomponent_set_method (icalcomp, ICAL_METHOD_CANCEL); - if (!e_cal_send_objects (event->comp_data->client, icalcomp, &users, - &mod_comp, &error)) { - delete_error_dialog (error, E_CAL_COMPONENT_EVENT); - g_clear_error (&error); - error = NULL; - } else { - - if (mod_comp) - icalcomponent_free (mod_comp); - - if (users) { - g_list_foreach (users, (GFunc) g_free, NULL); - g_list_free (users); - } - } - } - } else - delete = delete_component_dialog (comp, FALSE, 1, vtype, GTK_WIDGET (cal_view)); - - if (delete) { - const gchar *uid; - gchar *rid = NULL; - - if ((itip_organizer_is_user (comp, event->comp_data->client) || itip_sentby_is_user (comp, event->comp_data->client)) - && cancel_component_dialog ((GtkWindow *) gtk_widget_get_toplevel (GTK_WIDGET (cal_view)), - event->comp_data->client, - comp, TRUE)) - itip_send_comp (E_CAL_COMPONENT_METHOD_CANCEL, comp, - event->comp_data->client, NULL, NULL, NULL, TRUE, FALSE); - - e_cal_component_get_uid (comp, &uid); - if (!uid || !*uid) { - g_object_unref (comp); - return; - } - rid = e_cal_component_get_recurid_as_string (comp); - if (e_cal_util_component_is_instance (event->comp_data->icalcomp) || e_cal_util_component_has_recurrences (event->comp_data->icalcomp)) - e_cal_remove_object_with_mod (event->comp_data->client, uid, - rid, CALOBJ_MOD_ALL, &error); - else - e_cal_remove_object (event->comp_data->client, uid, &error); - - delete_error_dialog (error, E_CAL_COMPONENT_EVENT); - g_clear_error (&error); - g_free (rid); - } - - g_object_unref (comp); -} - -void -e_calendar_view_delete_selected_event (ECalendarView *cal_view) -{ - GList *selected; - ECalendarViewEvent *event; - - selected = e_calendar_view_get_selected_events (cal_view); - if (!selected) - return; - - event = (ECalendarViewEvent *) selected->data; - if (event) - delete_event (cal_view, event); - - g_list_free (selected); -} - -void -e_calendar_view_delete_selected_events (ECalendarView *cal_view) -{ - GList *selected, *l; - ECalendarViewEvent *event; - - selected = e_calendar_view_get_selected_events (cal_view); - if (!selected) - return; - - for (l = selected; l != NULL; l = l->next) { - event = (ECalendarViewEvent *) l->data; - if (event) - delete_event (cal_view, event); - } - - g_list_free (selected); -} - void e_calendar_view_delete_selected_occurrence (ECalendarView *cal_view) { @@ -1117,7 +1129,7 @@ e_calendar_view_delete_selected_occurrence (ECalendarView *cal_view) vtype = e_cal_component_get_vtype (comp); /*FIXME Retract should be moved to Groupwise features plugin */ - if (check_for_retract (comp, event->comp_data->client)) { + if (calendar_view_check_for_retract (comp, event->comp_data->client)) { gchar *retract_comment = NULL; gboolean retract = FALSE; @@ -1126,7 +1138,8 @@ e_calendar_view_delete_selected_occurrence (ECalendarView *cal_view) GList *users = NULL; icalcomponent *icalcomp = NULL, *mod_comp = NULL; - add_retract_data (comp, retract_comment, CALOBJ_MOD_THIS); + calendar_view_add_retract_data ( + comp, retract_comment, CALOBJ_MOD_THIS); icalcomp = e_cal_component_get_icalcomponent (comp); icalcomponent_set_method (icalcomp, ICAL_METHOD_CANCEL); if (!e_cal_send_objects (event->comp_data->client, icalcomp, &users, diff --git a/calendar/gui/e-calendar-view.h b/calendar/gui/e-calendar-view.h index 3ad9565de3..d79a6fdc9d 100644 --- a/calendar/gui/e-calendar-view.h +++ b/calendar/gui/e-calendar-view.h @@ -176,10 +176,6 @@ gboolean e_calendar_view_get_visible_time_range time_t *end_time); void e_calendar_view_update_query (ECalendarView *cal_view); -void e_calendar_view_delete_selected_event - (ECalendarView *cal_view); -void e_calendar_view_delete_selected_events - (ECalendarView *cal_view); void e_calendar_view_delete_selected_occurrence (ECalendarView *cal_view); CompEditor * e_calendar_view_open_event_with_flags diff --git a/calendar/gui/e-memo-table.c b/calendar/gui/e-memo-table.c index 62c0b99e6e..5f2cd26baf 100644 --- a/calendar/gui/e-memo-table.c +++ b/calendar/gui/e-memo-table.c @@ -731,6 +731,12 @@ memo_table_update_actions (ESelectable *selectable, gtk_action_set_sensitive (action, sensitive); gtk_action_set_tooltip (action, tooltip); + action = e_focus_tracker_get_delete_selection_action (focus_tracker); + sensitive = (n_selected > 0) && sources_are_editable; + tooltip = _("Delete selected memos"); + gtk_action_set_sensitive (action, sensitive); + gtk_action_set_tooltip (action, tooltip); + action = e_focus_tracker_get_select_all_action (focus_tracker); sensitive = TRUE; tooltip = _("Select all visible memos"); @@ -939,6 +945,77 @@ memo_table_paste_clipboard (ESelectable *selectable) } } +/* Used from e_table_selected_row_foreach(); puts the selected row number in an + * gint pointed to by the closure data. + */ +static void +get_selected_row_cb (gint model_row, gpointer data) +{ + gint *row; + + row = data; + *row = model_row; +} + +/* + * Returns the component that is selected in the table; only works if there is + * one and only one selected row. + */ +static ECalModelComponent * +get_selected_comp (EMemoTable *memo_table) +{ + ECalModel *model; + gint row; + + model = e_memo_table_get_model (memo_table); + if (e_table_selected_count (E_TABLE (memo_table)) != 1) + return NULL; + + row = -1; + e_table_selected_row_foreach ( + E_TABLE (memo_table), get_selected_row_cb, &row); + g_return_val_if_fail (row != -1, NULL); + + return e_cal_model_get_component_at (model, row); +} + +static void +memo_table_delete_selection (ESelectable *selectable) +{ + EMemoTable *memo_table; + ECalComponent *comp = NULL; + ECalModelComponent *comp_data; + gint n_selected; + + memo_table = E_MEMO_TABLE (selectable); + + n_selected = e_table_selected_count (E_TABLE (memo_table)); + if (n_selected <= 0) + return; + + if (n_selected == 1) + comp_data = get_selected_comp (memo_table); + else + comp_data = NULL; + + /* FIXME: this may be something other than a TODO component */ + + if (comp_data) { + comp = e_cal_component_new (); + e_cal_component_set_icalcomponent ( + comp, icalcomponent_new_clone (comp_data->icalcomp)); + } + + if (delete_component_dialog ( + comp, FALSE, n_selected, E_CAL_COMPONENT_JOURNAL, + GTK_WIDGET (memo_table))) + delete_selected_components (memo_table); + + /* free memory */ + if (comp) + g_object_unref (comp); +} + static void memo_table_select_all (ESelectable *selectable) { @@ -1044,6 +1121,7 @@ memo_table_selectable_init (ESelectableInterface *interface) interface->cut_clipboard = memo_table_cut_clipboard; interface->copy_clipboard = memo_table_copy_clipboard; interface->paste_clipboard = memo_table_paste_clipboard; + interface->delete_selection = memo_table_delete_selection; interface->select_all = memo_table_select_all; } @@ -1128,40 +1206,6 @@ e_memo_table_get_shell_view (EMemoTable *memo_table) return memo_table->priv->shell_view; } -/* Used from e_table_selected_row_foreach(); puts the selected row number in an - * gint pointed to by the closure data. - */ -static void -get_selected_row_cb (gint model_row, gpointer data) -{ - gint *row; - - row = data; - *row = model_row; -} - -/* - * Returns the component that is selected in the table; only works if there is - * one and only one selected row. - */ -static ECalModelComponent * -get_selected_comp (EMemoTable *memo_table) -{ - ECalModel *model; - gint row; - - model = e_memo_table_get_model (memo_table); - if (e_table_selected_count (E_TABLE (memo_table)) != 1) - return NULL; - - row = -1; - e_table_selected_row_foreach ( - E_TABLE (memo_table), get_selected_row_cb, &row); - g_return_val_if_fail (row != -1, NULL); - - return e_cal_model_get_component_at (model, row); -} - struct get_selected_uids_closure { EMemoTable *memo_table; GSList *objects; @@ -1184,49 +1228,6 @@ add_uid_cb (gint model_row, gpointer data) } /** - * e_memo_table_delete_selected: - * @memo_table: A memo table. - * - * Deletes the selected components in the table; asks the user first. - **/ -void -e_memo_table_delete_selected (EMemoTable *memo_table) -{ - gint n_selected; - ECalModelComponent *comp_data; - ECalComponent *comp = NULL; - - g_return_if_fail (memo_table != NULL); - g_return_if_fail (E_IS_MEMO_TABLE (memo_table)); - - n_selected = e_table_selected_count (E_TABLE (memo_table)); - if (n_selected <= 0) - return; - - if (n_selected == 1) - comp_data = get_selected_comp (memo_table); - else - comp_data = NULL; - - /* FIXME: this may be something other than a TODO component */ - - if (comp_data) { - comp = e_cal_component_new (); - e_cal_component_set_icalcomponent ( - comp, icalcomponent_new_clone (comp_data->icalcomp)); - } - - if (delete_component_dialog ( - comp, FALSE, n_selected, E_CAL_COMPONENT_JOURNAL, - GTK_WIDGET (memo_table))) - delete_selected_components (memo_table); - - /* free memory */ - if (comp) - g_object_unref (comp); -} - -/** * e_memo_table_get_selected: * @memo_table: * diff --git a/calendar/gui/e-memo-table.h b/calendar/gui/e-memo-table.h index a5707ec22f..c891117203 100644 --- a/calendar/gui/e-memo-table.h +++ b/calendar/gui/e-memo-table.h @@ -102,7 +102,6 @@ gboolean e_memo_table_get_use_24_hour_format void e_memo_table_set_use_24_hour_format (EMemoTable *memo_table, gboolean use_24_hour_format); -void e_memo_table_delete_selected (EMemoTable *memo_table); GSList * e_memo_table_get_selected (EMemoTable *memo_table); G_END_DECLS diff --git a/calendar/gui/e-task-table.c b/calendar/gui/e-task-table.c index 5136a56b2d..9f0962dcb8 100644 --- a/calendar/gui/e-task-table.c +++ b/calendar/gui/e-task-table.c @@ -271,6 +271,7 @@ delete_selected_components (ETaskTable *task_table) g_slist_free (objs); } + static void task_table_set_model (ETaskTable *task_table, ECalModel *model) @@ -911,6 +912,12 @@ task_table_update_actions (ESelectable *selectable, gtk_action_set_sensitive (action, sensitive); gtk_action_set_tooltip (action, tooltip); + action = e_focus_tracker_get_delete_selection_action (focus_tracker); + sensitive = (n_selected > 0) && sources_are_editable; + tooltip = _("Delete selected tasks"); + gtk_action_set_sensitive (action, sensitive); + gtk_action_set_tooltip (action, tooltip); + action = e_focus_tracker_get_select_all_action (focus_tracker); sensitive = TRUE; tooltip = _("Select all visible tasks"); @@ -1119,6 +1126,155 @@ task_table_paste_clipboard (ESelectable *selectable) } } +/* Used from e_table_selected_row_foreach(); puts the selected row number in an + * gint pointed to by the closure data. + */ +static void +get_selected_row_cb (gint model_row, gpointer data) +{ + gint *row; + + row = data; + *row = model_row; +} + +/* + * Returns the component that is selected in the table; only works if there is + * one and only one selected row. + */ +static ECalModelComponent * +get_selected_comp (ETaskTable *task_table) +{ + ECalModel *model; + gint row; + + model = e_task_table_get_model (task_table); + if (e_table_selected_count (E_TABLE (task_table)) != 1) + return NULL; + + row = -1; + e_table_selected_row_foreach ( + E_TABLE (task_table), get_selected_row_cb, &row); + g_return_val_if_fail (row != -1, NULL); + + return e_cal_model_get_component_at (model, row); +} + +static void +add_retract_data (ECalComponent *comp, const gchar *retract_comment) +{ + icalcomponent *icalcomp = NULL; + icalproperty *icalprop = NULL; + + icalcomp = e_cal_component_get_icalcomponent (comp); + if (retract_comment && *retract_comment) + icalprop = icalproperty_new_x (retract_comment); + else + icalprop = icalproperty_new_x ("0"); + icalproperty_set_x_name (icalprop, "X-EVOLUTION-RETRACT-COMMENT"); + icalcomponent_add_property (icalcomp, icalprop); +} + +static gboolean +check_for_retract (ECalComponent *comp, ECal *client) +{ + ECalComponentOrganizer org; + gchar *email = NULL; + const gchar *strip = NULL; + gboolean ret_val; + + if (!e_cal_component_has_attendees (comp)) + return FALSE; + + if (!e_cal_get_save_schedules (client)) + return FALSE; + + e_cal_component_get_organizer (comp, &org); + strip = itip_strip_mailto (org.value); + + ret_val = + e_cal_get_cal_address (client, &email, NULL) && + g_ascii_strcasecmp (email, strip) == 0; + + g_free (email); + + return ret_val; +} + +static void +task_table_delete_selection (ESelectable *selectable) +{ + ETaskTable *task_table; + ECalModelComponent *comp_data; + ECalComponent *comp = NULL; + gboolean delete = FALSE; + gint n_selected; + GError *error = NULL; + + task_table = E_TASK_TABLE (selectable); + + n_selected = e_table_selected_count (E_TABLE (task_table)); + if (n_selected <= 0) + return; + + if (n_selected == 1) + comp_data = get_selected_comp (task_table); + else + comp_data = NULL; + + /* FIXME: this may be something other than a TODO component */ + + if (comp_data) { + comp = e_cal_component_new (); + e_cal_component_set_icalcomponent ( + comp, icalcomponent_new_clone (comp_data->icalcomp)); + } + + if ((n_selected == 1) && comp && check_for_retract (comp, comp_data->client)) { + gchar *retract_comment = NULL; + gboolean retract = FALSE; + + delete = prompt_retract_dialog ( + comp, &retract_comment, + GTK_WIDGET (task_table), &retract); + if (retract) { + GList *users = NULL; + icalcomponent *icalcomp = NULL, *mod_comp = NULL; + + add_retract_data (comp, retract_comment); + icalcomp = e_cal_component_get_icalcomponent (comp); + icalcomponent_set_method (icalcomp, ICAL_METHOD_CANCEL); + if (!e_cal_send_objects (comp_data->client, icalcomp, &users, + &mod_comp, &error)) { + delete_error_dialog (error, E_CAL_COMPONENT_TODO); + g_clear_error (&error); + error = NULL; + } else { + + if (mod_comp) + icalcomponent_free (mod_comp); + + if (users) { + g_list_foreach (users, (GFunc) g_free, NULL); + g_list_free (users); + } + } + + } + } else { + delete = delete_component_dialog ( + comp, FALSE, n_selected, + E_CAL_COMPONENT_TODO, GTK_WIDGET (task_table)); + } + + if (delete) + delete_selected_components (task_table); + + /* free memory */ + if (comp) + g_object_unref (comp); +} + static void task_table_select_all (ESelectable *selectable) { @@ -1224,6 +1380,7 @@ task_table_selectable_init (ESelectableInterface *interface) interface->cut_clipboard = task_table_cut_clipboard; interface->copy_clipboard = task_table_copy_clipboard; interface->paste_clipboard = task_table_paste_clipboard; + interface->delete_selection = task_table_delete_selection; interface->select_all = task_table_select_all; } @@ -1307,40 +1464,6 @@ e_task_table_get_shell_view (ETaskTable *task_table) return task_table->priv->shell_view; } -/* Used from e_table_selected_row_foreach(); puts the selected row number in an - * gint pointed to by the closure data. - */ -static void -get_selected_row_cb (gint model_row, gpointer data) -{ - gint *row; - - row = data; - *row = model_row; -} - -/* - * Returns the component that is selected in the table; only works if there is - * one and only one selected row. - */ -static ECalModelComponent * -get_selected_comp (ETaskTable *task_table) -{ - ECalModel *model; - gint row; - - model = e_task_table_get_model (task_table); - if (e_table_selected_count (E_TABLE (task_table)) != 1) - return NULL; - - row = -1; - e_table_selected_row_foreach ( - E_TABLE (task_table), get_selected_row_cb, &row); - g_return_val_if_fail (row != -1, NULL); - - return e_cal_model_get_component_at (model, row); -} - struct get_selected_uids_closure { ETaskTable *task_table; GSList *objects; @@ -1360,127 +1483,6 @@ add_uid_cb (gint model_row, gpointer data) closure->objects = g_slist_prepend (closure->objects, comp_data); } -static void -add_retract_data (ECalComponent *comp, const gchar *retract_comment) -{ - icalcomponent *icalcomp = NULL; - icalproperty *icalprop = NULL; - - icalcomp = e_cal_component_get_icalcomponent (comp); - if (retract_comment && *retract_comment) - icalprop = icalproperty_new_x (retract_comment); - else - icalprop = icalproperty_new_x ("0"); - icalproperty_set_x_name (icalprop, "X-EVOLUTION-RETRACT-COMMENT"); - icalcomponent_add_property (icalcomp, icalprop); -} - -static gboolean -check_for_retract (ECalComponent *comp, ECal *client) -{ - ECalComponentOrganizer org; - gchar *email = NULL; - const gchar *strip = NULL; - gboolean ret_val; - - if (!e_cal_component_has_attendees (comp)) - return FALSE; - - if (!e_cal_get_save_schedules (client)) - return FALSE; - - e_cal_component_get_organizer (comp, &org); - strip = itip_strip_mailto (org.value); - - ret_val = - e_cal_get_cal_address (client, &email, NULL) && - g_ascii_strcasecmp (email, strip) == 0; - - g_free (email); - - return ret_val; -} - -/** - * e_task_table_delete_selected: - * @task_table: A calendar table. - * - * Deletes the selected components in the table; asks the user first. - **/ -void -e_task_table_delete_selected (ETaskTable *task_table) -{ - gint n_selected; - ECalModelComponent *comp_data; - ECalComponent *comp = NULL; - gboolean delete = FALSE; - GError *error = NULL; - - g_return_if_fail (task_table != NULL); - g_return_if_fail (E_IS_CALENDAR_TABLE (task_table)); - - n_selected = e_table_selected_count (E_TABLE (task_table)); - if (n_selected <= 0) - return; - - if (n_selected == 1) - comp_data = get_selected_comp (task_table); - else - comp_data = NULL; - - /* FIXME: this may be something other than a TODO component */ - - if (comp_data) { - comp = e_cal_component_new (); - e_cal_component_set_icalcomponent ( - comp, icalcomponent_new_clone (comp_data->icalcomp)); - } - - if ((n_selected == 1) && comp && check_for_retract (comp, comp_data->client)) { - gchar *retract_comment = NULL; - gboolean retract = FALSE; - - delete = prompt_retract_dialog ( - comp, &retract_comment, - GTK_WIDGET (task_table), &retract); - if (retract) { - GList *users = NULL; - icalcomponent *icalcomp = NULL, *mod_comp = NULL; - - add_retract_data (comp, retract_comment); - icalcomp = e_cal_component_get_icalcomponent (comp); - icalcomponent_set_method (icalcomp, ICAL_METHOD_CANCEL); - if (!e_cal_send_objects (comp_data->client, icalcomp, &users, - &mod_comp, &error)) { - delete_error_dialog (error, E_CAL_COMPONENT_TODO); - g_clear_error (&error); - error = NULL; - } else { - - if (mod_comp) - icalcomponent_free (mod_comp); - - if (users) { - g_list_foreach (users, (GFunc) g_free, NULL); - g_list_free (users); - } - } - - } - } else { - delete = delete_component_dialog ( - comp, FALSE, n_selected, - E_CAL_COMPONENT_TODO, GTK_WIDGET (task_table)); - } - - if (delete) - delete_selected_components (task_table); - - /* free memory */ - if (comp) - g_object_unref (comp); -} - /** * e_task_table_get_selected: * @task_table: diff --git a/calendar/gui/e-task-table.h b/calendar/gui/e-task-table.h index 8564d9901b..b23f128b87 100644 --- a/calendar/gui/e-task-table.h +++ b/calendar/gui/e-task-table.h @@ -92,7 +92,6 @@ GtkWidget * e_task_table_new (EShellView *shell_view, ECalModel *model); ECalModel * e_task_table_get_model (ETaskTable *task_table); EShellView * e_task_table_get_shell_view (ETaskTable *task_table); -void e_task_table_delete_selected (ETaskTable *task_table); GSList * e_task_table_get_selected (ETaskTable *task_table); ECalModelComponent * e_task_table_get_selected_comp |