From db7a74c0b7276ea71c45d029210112a92ce33d7a Mon Sep 17 00:00:00 2001 From: Rodrigo Moya Date: Tue, 16 Dec 2003 23:29:07 +0000 Subject: Fixes part of #41237 2003-12-16 Rodrigo Moya Fixes part of #41237 * gui/e-calendar-table.c: use GtkClipboard instead of GtkInvisible for cut/copy/paste. (selection_clear_event, selection_received, selection_get): removed unneeded functions. (e_calendar_table_init): don't create the invisible widget. (e_calendar_table_copy_clipboard): use gtk_clipboard_set_text(). (e_calendar_table_paste_clipboard): use gtk_clipboard_request_text(). (clipboard_get_text_cb): callback for gtk_clipboard_request_text(). * gui/e-cal-view.c (e_calendar_view_init, e_calendar_view_destroy, e_calendar_view_copy_clipboard): no need anymore to keep the last clipboard selection, GtkClipboard does it for us. svn path=/trunk/; revision=23952 --- calendar/ChangeLog | 17 +++ calendar/gui/e-cal-view.c | 13 --- calendar/gui/e-calendar-table.c | 245 ++++++++++++++-------------------------- calendar/gui/e-calendar-table.h | 4 +- calendar/gui/e-calendar-view.c | 13 --- 5 files changed, 101 insertions(+), 191 deletions(-) (limited to 'calendar') diff --git a/calendar/ChangeLog b/calendar/ChangeLog index e5c330a325..6c6a63d9bc 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,20 @@ +2003-12-16 Rodrigo Moya + + Fixes part of #41237 + + * gui/e-calendar-table.c: use GtkClipboard instead of GtkInvisible + for cut/copy/paste. + (selection_clear_event, selection_received, selection_get): removed + unneeded functions. + (e_calendar_table_init): don't create the invisible widget. + (e_calendar_table_copy_clipboard): use gtk_clipboard_set_text(). + (e_calendar_table_paste_clipboard): use gtk_clipboard_request_text(). + (clipboard_get_text_cb): callback for gtk_clipboard_request_text(). + + * gui/e-cal-view.c (e_calendar_view_init, e_calendar_view_destroy, + e_calendar_view_copy_clipboard): no need anymore to keep the last + clipboard selection, GtkClipboard does it for us. + 2003-12-16 Rodrigo Moya * gui/alarm-notify/notify-main.c (alarm_notify_factory_fn): return diff --git a/calendar/gui/e-cal-view.c b/calendar/gui/e-cal-view.c index f93cee6c10..ffaca9bedb 100644 --- a/calendar/gui/e-cal-view.c +++ b/calendar/gui/e-cal-view.c @@ -63,9 +63,6 @@ struct _ECalendarViewPrivate { /* Current activity (for the EActivityHandler, i.e. the status bar). */ guint activity_id; - /* clipboard selections */ - gchar *clipboard_selection; - /* The popup menu */ EPopupMenu *view_menu; @@ -341,8 +338,6 @@ e_calendar_view_init (ECalendarView *cal_view, ECalendarViewClass *klass) G_CALLBACK (model_rows_changed_cb), cal_view); g_signal_connect (G_OBJECT (cal_view->priv->model), "model_rows_deleted", G_CALLBACK (model_rows_changed_cb), cal_view); - - cal_view->priv->clipboard_selection = NULL; } static void @@ -361,11 +356,6 @@ e_calendar_view_destroy (GtkObject *object) cal_view->priv->model = NULL; } - if (cal_view->priv->clipboard_selection) { - g_free (cal_view->priv->clipboard_selection); - cal_view->priv->clipboard_selection = NULL; - } - if (cal_view->priv->default_category) { g_free (cal_view->priv->default_category); cal_view->priv->default_category = NULL; @@ -674,9 +664,6 @@ e_calendar_view_copy_clipboard (ECalendarView *cal_view) /* copy the VCALENDAR to the clipboard */ comp_str = icalcomponent_as_ical_string (vcal_comp); - if (cal_view->priv->clipboard_selection != NULL) - g_free (cal_view->priv->clipboard_selection); - cal_view->priv->clipboard_selection = g_strdup (comp_str); gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (cal_view), clipboard_atom), (const gchar *) comp_str, g_utf8_strlen (comp_str, -1)); diff --git a/calendar/gui/e-calendar-table.c b/calendar/gui/e-calendar-table.c index d9ea59905b..d04315799d 100644 --- a/calendar/gui/e-calendar-table.c +++ b/calendar/gui/e-calendar-table.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -106,18 +105,6 @@ static gint e_calendar_table_on_key_press (ETable *table, GdkEventKey *event, ECalendarTable *cal_table); -static void selection_clear_event (GtkWidget *invisible, - GdkEventSelection *event, - ECalendarTable *cal_table); -static void selection_received (GtkWidget *invisible, - GtkSelectionData *selection_data, - guint time, - ECalendarTable *cal_table); -static void selection_get (GtkWidget *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - ECalendarTable *cal_table); static struct tm e_calendar_table_get_current_time (ECellDateEdit *ecde, gpointer data); static void mark_row_complete_cb (int model_row, gpointer data); @@ -531,21 +518,6 @@ e_calendar_table_init (ECalendarTable *cal_table) g_signal_connect (e_table, "right_click", G_CALLBACK (e_calendar_table_on_right_click), cal_table); g_signal_connect (e_table, "key_press", G_CALLBACK (e_calendar_table_on_key_press), cal_table); g_signal_connect (e_table, "popup_menu", G_CALLBACK (e_calendar_table_on_popup_menu), cal_table); - - /* Set up the invisible widget for the clipboard selections */ - cal_table->invisible = gtk_invisible_new (); - gtk_selection_add_target (cal_table->invisible, - clipboard_atom, - GDK_SELECTION_TYPE_STRING, - 0); - g_signal_connect (cal_table->invisible, "selection_get", - G_CALLBACK (selection_get), cal_table); - g_signal_connect (cal_table->invisible, "selection_clear_event", - G_CALLBACK (selection_clear_event), cal_table); - g_signal_connect (cal_table->invisible, "selection_received", - G_CALLBACK (selection_received), cal_table); - - cal_table->clipboard_selection = NULL; } @@ -595,15 +567,6 @@ e_calendar_table_destroy (GtkObject *object) g_object_unref (cal_table->model); cal_table->model = NULL; } - - if (cal_table->invisible) { - gtk_widget_destroy (cal_table->invisible); - cal_table->invisible = NULL; - } - if (cal_table->clipboard_selection) { - g_free (cal_table->clipboard_selection); - cal_table->clipboard_selection = NULL; - } GTK_OBJECT_CLASS (parent_class)->destroy (object); } @@ -838,23 +801,96 @@ e_calendar_table_copy_clipboard (ECalendarTable *cal_table) g_return_if_fail (E_IS_CALENDAR_TABLE (cal_table)); - if (cal_table->clipboard_selection) { - g_free (cal_table->clipboard_selection); - cal_table->clipboard_selection = NULL; - } - /* create temporary VCALENDAR object */ cal_table->tmp_vcal = e_cal_util_new_top_level (); etable = e_table_scrolled_get_table (E_TABLE_SCROLLED (cal_table->etable)); e_table_selected_row_foreach (etable, copy_row_cb, cal_table); - comp_str = icalcomponent_as_ical_string (cal_table->tmp_vcal); - cal_table->clipboard_selection = g_strdup (comp_str); + gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (cal_table), clipboard_atom), + (const char *) comp_str, + g_utf8_strlen (comp_str, -1)); + + /* free memory */ icalcomponent_free (cal_table->tmp_vcal); cal_table->tmp_vcal = NULL; +} + +static void +clipboard_get_text_cb (GtkClipboard *clipboard, const gchar *text, ECalendarTable *cal_table) +{ + char *comp_str; + icalcomponent *icalcomp; + char *uid; + ECalComponent *comp; + ECal *client; + icalcomponent_kind kind; + + g_return_if_fail (E_IS_CALENDAR_TABLE (cal_table)); + + comp_str = (char *) text; + icalcomp = icalparser_parse_string ((const char *) comp_str); + if (!icalcomp) + return; + + /* check the type of the component */ + kind = icalcomponent_isa (icalcomp); + if (kind != ICAL_VCALENDAR_COMPONENT && + kind != ICAL_VEVENT_COMPONENT && + kind != ICAL_VTODO_COMPONENT && + kind != ICAL_VJOURNAL_COMPONENT) { + return; + } + + client = e_cal_model_get_default_client (cal_table->model); + + e_calendar_table_set_status_message (cal_table, _("Updating objects")); + + if (kind == ICAL_VCALENDAR_COMPONENT) { + icalcomponent_kind child_kind; + icalcomponent *subcomp; + icalcomponent *vcal_comp; + + vcal_comp = icalcomp; + subcomp = icalcomponent_get_first_component ( + vcal_comp, ICAL_ANY_COMPONENT); + while (subcomp) { + child_kind = icalcomponent_isa (subcomp); + if (child_kind == ICAL_VEVENT_COMPONENT || + child_kind == ICAL_VTODO_COMPONENT || + child_kind == ICAL_VJOURNAL_COMPONENT) { + ECalComponent *tmp_comp; + + uid = e_cal_component_gen_uid (); + tmp_comp = e_cal_component_new (); + e_cal_component_set_icalcomponent ( + tmp_comp, icalcomponent_new_clone (subcomp)); + e_cal_component_set_uid (tmp_comp, uid); + free (uid); + + /* FIXME should we convert start/due/complete times? */ + /* FIXME Error handling */ + e_cal_create_object (client, e_cal_component_get_icalcomponent (tmp_comp), NULL, NULL); + + g_object_unref (tmp_comp); + } + subcomp = icalcomponent_get_next_component ( + vcal_comp, ICAL_ANY_COMPONENT); + } + } + else { + comp = e_cal_component_new (); + e_cal_component_set_icalcomponent (comp, icalcomp); + uid = e_cal_component_gen_uid (); + e_cal_component_set_uid (comp, (const char *) uid); + free (uid); - gtk_selection_owner_set (cal_table->invisible, clipboard_atom, GDK_CURRENT_TIME); + e_cal_create_object (client, e_cal_component_get_icalcomponent (comp), NULL, NULL); + + g_object_unref (comp); + } + + e_calendar_table_set_status_message (cal_table, NULL); } /** @@ -868,10 +904,8 @@ e_calendar_table_paste_clipboard (ECalendarTable *cal_table) { g_return_if_fail (E_IS_CALENDAR_TABLE (cal_table)); - gtk_selection_convert (cal_table->invisible, - clipboard_atom, - GDK_SELECTION_TYPE_STRING, - GDK_CURRENT_TIME); + gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (cal_table), clipboard_atom), + (GtkClipboardTextReceivedFunc) clipboard_get_text_cb, cal_table); } /* Opens a task in the task editor */ @@ -1281,119 +1315,6 @@ e_calendar_table_save_state (ECalendarTable *cal_table, filename); } -static void -selection_get (GtkWidget *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - ECalendarTable *cal_table) -{ - if (cal_table->clipboard_selection != NULL) { - gtk_selection_data_set (selection_data, - GDK_SELECTION_TYPE_STRING, - 8, - cal_table->clipboard_selection, - strlen (cal_table->clipboard_selection)); - } -} - -static void -selection_clear_event (GtkWidget *invisible, - GdkEventSelection *event, - ECalendarTable *cal_table) -{ - if (cal_table->clipboard_selection != NULL) { - g_free (cal_table->clipboard_selection); - cal_table->clipboard_selection = NULL; - } -} - -static void -selection_received (GtkWidget *invisible, - GtkSelectionData *selection_data, - guint time, - ECalendarTable *cal_table) -{ - char *comp_str; - icalcomponent *icalcomp; - char *uid; - ECalComponent *comp; - ECal *client; - icalcomponent_kind kind; - - g_return_if_fail (E_IS_CALENDAR_TABLE (cal_table)); - - if (selection_data->length < 0 || - selection_data->type != GDK_SELECTION_TYPE_STRING) { - return; - } - - comp_str = (char *) selection_data->data; - icalcomp = icalparser_parse_string ((const char *) comp_str); - if (!icalcomp) - return; - - /* check the type of the component */ - kind = icalcomponent_isa (icalcomp); - if (kind != ICAL_VCALENDAR_COMPONENT && - kind != ICAL_VEVENT_COMPONENT && - kind != ICAL_VTODO_COMPONENT && - kind != ICAL_VJOURNAL_COMPONENT) { - return; - } - - client = e_cal_model_get_default_client (cal_table->model); - - e_calendar_table_set_status_message (cal_table, _("Updating objects")); - - if (kind == ICAL_VCALENDAR_COMPONENT) { - icalcomponent_kind child_kind; - icalcomponent *subcomp; - icalcomponent *vcal_comp; - - vcal_comp = icalcomp; - subcomp = icalcomponent_get_first_component ( - vcal_comp, ICAL_ANY_COMPONENT); - while (subcomp) { - child_kind = icalcomponent_isa (subcomp); - if (child_kind == ICAL_VEVENT_COMPONENT || - child_kind == ICAL_VTODO_COMPONENT || - child_kind == ICAL_VJOURNAL_COMPONENT) { - ECalComponent *tmp_comp; - - uid = e_cal_component_gen_uid (); - tmp_comp = e_cal_component_new (); - e_cal_component_set_icalcomponent ( - tmp_comp, icalcomponent_new_clone (subcomp)); - e_cal_component_set_uid (tmp_comp, uid); - free (uid); - - /* FIXME should we convert start/due/complete times? */ - /* FIXME Error handling */ - e_cal_create_object (client, e_cal_component_get_icalcomponent (tmp_comp), NULL, NULL); - - g_object_unref (tmp_comp); - } - subcomp = icalcomponent_get_next_component ( - vcal_comp, ICAL_ANY_COMPONENT); - } - } - else { - comp = e_cal_component_new (); - e_cal_component_set_icalcomponent (comp, icalcomp); - uid = e_cal_component_gen_uid (); - e_cal_component_set_uid (comp, (const char *) uid); - free (uid); - - e_cal_create_object (client, e_cal_component_get_icalcomponent (comp), NULL, NULL); - - g_object_unref (comp); - } - - e_calendar_table_set_status_message (cal_table, NULL); -} - - /* Returns the current time, for the ECellDateEdit items. FIXME: Should probably use the timezone of the item rather than the current timezone, though that may be difficult to get from here. */ diff --git a/calendar/gui/e-calendar-table.h b/calendar/gui/e-calendar-table.h index 810c78254b..2cff1bead3 100644 --- a/calendar/gui/e-calendar-table.h +++ b/calendar/gui/e-calendar-table.h @@ -57,9 +57,7 @@ struct _ECalendarTable { /* The ECell used to view & edit dates. */ ECellDateEdit *dates_cell; - /* The invisible widget used for cut/copy/paste */ - GtkWidget *invisible; - gchar *clipboard_selection; + /* Fields used for cut/copy/paste */ icalcomponent *tmp_vcal; /* Activity ID for the EActivityHandler (i.e. the status bar). */ diff --git a/calendar/gui/e-calendar-view.c b/calendar/gui/e-calendar-view.c index f93cee6c10..ffaca9bedb 100644 --- a/calendar/gui/e-calendar-view.c +++ b/calendar/gui/e-calendar-view.c @@ -63,9 +63,6 @@ struct _ECalendarViewPrivate { /* Current activity (for the EActivityHandler, i.e. the status bar). */ guint activity_id; - /* clipboard selections */ - gchar *clipboard_selection; - /* The popup menu */ EPopupMenu *view_menu; @@ -341,8 +338,6 @@ e_calendar_view_init (ECalendarView *cal_view, ECalendarViewClass *klass) G_CALLBACK (model_rows_changed_cb), cal_view); g_signal_connect (G_OBJECT (cal_view->priv->model), "model_rows_deleted", G_CALLBACK (model_rows_changed_cb), cal_view); - - cal_view->priv->clipboard_selection = NULL; } static void @@ -361,11 +356,6 @@ e_calendar_view_destroy (GtkObject *object) cal_view->priv->model = NULL; } - if (cal_view->priv->clipboard_selection) { - g_free (cal_view->priv->clipboard_selection); - cal_view->priv->clipboard_selection = NULL; - } - if (cal_view->priv->default_category) { g_free (cal_view->priv->default_category); cal_view->priv->default_category = NULL; @@ -674,9 +664,6 @@ e_calendar_view_copy_clipboard (ECalendarView *cal_view) /* copy the VCALENDAR to the clipboard */ comp_str = icalcomponent_as_ical_string (vcal_comp); - if (cal_view->priv->clipboard_selection != NULL) - g_free (cal_view->priv->clipboard_selection); - cal_view->priv->clipboard_selection = g_strdup (comp_str); gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (cal_view), clipboard_atom), (const gchar *) comp_str, g_utf8_strlen (comp_str, -1)); -- cgit v1.2.3