From 806e63b32a7fdca4899d89ba236a0eb64726707c Mon Sep 17 00:00:00 2001 From: Rodrigo Moya Date: Tue, 22 Jul 2003 21:13:38 +0000 Subject: added "get_selected_events", and "update_query" virtual methods. 2003-07-22 Rodrigo Moya * gui/e-cal-view.[ch]: added "get_selected_events", and "update_query" virtual methods. (e_cal_view_class_init): initialize new virtual methods. (e_cal_view_destroy): destroy new private members. (e_cal_view_get_selected_events, e_cal_view_set_cal_client, e_cal_view_get_cal_client): new functions. (e_cal_view_cut_clipboard, e_cal_view_copy_clipboard, e_cal_view_paste_clipboard): merged clipboard stuff. * gui/e-day-view.c (e_day_view_cut_clipboard, e_day_view_copy_clipboard, e_day_view_paste_clipboard): removed. (e_day_view_get_selected_events): made these private as the implementation of the 'get_selected_events' base class virtual method. * gui/e-week-view.c (e_week_view_get_selected_events): ditto. (e_week_view_cut_clipboard, e_week_view_copy_clipboard, e_week_view_paste_clipboard): removed. * gui/calendar-commands.c (sensitize_calendar_commands): call e_cal_view_get_selected_events. * gui/gnome-cal.c: removed a lot of redundant code thanks to the above changes. svn path=/trunk/; revision=21893 --- calendar/ChangeLog | 26 ++ calendar/gui/calendar-commands.c | 12 +- calendar/gui/e-cal-view.c | 421 +++++++++++++++++++++++ calendar/gui/e-cal-view.h | 19 + calendar/gui/e-calendar-view.c | 421 +++++++++++++++++++++++ calendar/gui/e-calendar-view.h | 19 + calendar/gui/e-day-view.c | 726 ++++++++++----------------------------- calendar/gui/e-day-view.h | 24 -- calendar/gui/e-week-view.c | 647 ++++++++-------------------------- calendar/gui/e-week-view.h | 26 +- calendar/gui/gnome-cal.c | 94 +---- 11 files changed, 1249 insertions(+), 1186 deletions(-) diff --git a/calendar/ChangeLog b/calendar/ChangeLog index b84625c773..3f3b46b0a5 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,29 @@ +2003-07-22 Rodrigo Moya + + * gui/e-cal-view.[ch]: added "get_selected_events", + and "update_query" virtual methods. + (e_cal_view_class_init): initialize new virtual methods. + (e_cal_view_destroy): destroy new private members. + (e_cal_view_get_selected_events, e_cal_view_set_cal_client, + e_cal_view_get_cal_client): new functions. + (e_cal_view_cut_clipboard, e_cal_view_copy_clipboard, + e_cal_view_paste_clipboard): merged clipboard stuff. + + * gui/e-day-view.c (e_day_view_cut_clipboard, + e_day_view_copy_clipboard, e_day_view_paste_clipboard): removed. + (e_day_view_get_selected_events): made these private as the + implementation of the 'get_selected_events' base class virtual method. + + * gui/e-week-view.c (e_week_view_get_selected_events): ditto. + (e_week_view_cut_clipboard, e_week_view_copy_clipboard, + e_week_view_paste_clipboard): removed. + + * gui/calendar-commands.c (sensitize_calendar_commands): call + e_cal_view_get_selected_events. + + * gui/gnome-cal.c: removed a lot of redundant code thanks to the + above changes. + 2003-07-21 Rodrigo Moya * gui/e-day-view.[ch]: removed e_day_view_set_calendar prototype. diff --git a/calendar/gui/calendar-commands.c b/calendar/gui/calendar-commands.c index 82cf5e1976..8f2aba9988 100644 --- a/calendar/gui/calendar-commands.c +++ b/calendar/gui/calendar-commands.c @@ -8,6 +8,7 @@ * Authors: Miguel de Icaza * Federico Mena-Quintero * Seth Alves + * Rodrigo Moya * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public @@ -598,14 +599,15 @@ sensitize_calendar_commands (GnomeCalendar *gcal, BonoboControl *control, gboole has_recurrences = FALSE; if (n_selected > 0 && !read_only) { CalComponent *comp; + GList *list; GtkWidget *view; view = gnome_calendar_get_current_view_widget (gcal); - if (E_IS_DAY_VIEW (view)) - comp = e_day_view_get_selected_event (E_DAY_VIEW (view)); - else if (E_IS_WEEK_VIEW (view)) - comp = e_week_view_get_selected_event (E_WEEK_VIEW (view)); - else + list = e_cal_view_get_selected_events (E_CAL_VIEW (view)); + if (list) { + comp = (CalComponent *) list->data; + g_list_free (list); + } else comp = NULL; if (comp) { diff --git a/calendar/gui/e-cal-view.c b/calendar/gui/e-cal-view.c index 6272f0eab9..1b4676beb8 100644 --- a/calendar/gui/e-cal-view.c +++ b/calendar/gui/e-cal-view.c @@ -22,9 +22,17 @@ */ #include +#include +#include +#include #include #include "evolution-activity-client.h" +#include "calendar-config.h" #include "e-cal-view.h" +#include "itip-utils.h" +#include "dialogs/cancel-comp.h" +#include "dialogs/delete-error.h" +#include "dialogs/send-comp.h" /* Used for the status bar messages */ #define EVOLUTION_CALENDAR_PROGRESS_IMAGE "evolution-calendar-mini.png" @@ -34,8 +42,18 @@ struct _ECalViewPrivate { /* The GnomeCalendar we are associated to */ GnomeCalendar *calendar; + /* Calendar client we are monitoring */ + CalClient *client; + + /* Search expression */ + gchar *sexp; + /* The activity client used to show messages on the status bar. */ EvolutionActivityClient *activity; + + /* the invisible widget to manage the clipboard selections */ + GtkWidget *invisible; + gchar *clipboard_selection; }; static void e_cal_view_class_init (ECalViewClass *klass); @@ -43,6 +61,7 @@ static void e_cal_view_init (ECalView *cal_view, ECalViewClass *klass); static void e_cal_view_destroy (GtkObject *object); static GObjectClass *parent_class = NULL; +static GdkAtom clipboard_atom = GDK_NONE; /* Signal IDs */ enum { @@ -73,12 +92,203 @@ e_cal_view_class_init (ECalViewClass *klass) object_class->destroy = e_cal_view_destroy; klass->selection_changed = NULL; + klass->get_selected_events = NULL; + klass->get_selected_time_range = NULL; + klass->set_selected_time_range = NULL; + klass->update_query = NULL; + + /* clipboard atom */ + if (!clipboard_atom) + clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE); +} + +static void +selection_get (GtkWidget *invisible, + GtkSelectionData *selection_data, + guint info, + guint time_stamp, + ECalView *cal_view) +{ + if (cal_view->priv->clipboard_selection != NULL) { + gtk_selection_data_set (selection_data, + GDK_SELECTION_TYPE_STRING, + 8, + cal_view->priv->clipboard_selection, + strlen (cal_view->priv->clipboard_selection)); + } +} + +static void +selection_clear_event (GtkWidget *invisible, + GdkEventSelection *event, + ECalView *cal_view) +{ + if (cal_view->priv->clipboard_selection != NULL) { + g_free (cal_view->priv->clipboard_selection); + cal_view->priv->clipboard_selection = NULL; + } +} + +static void +selection_received (GtkWidget *invisible, + GtkSelectionData *selection_data, + guint time, + ECalView *cal_view) +{ + char *comp_str, *default_tzid; + icalcomponent *icalcomp; + icalcomponent_kind kind; + CalComponent *comp; + time_t selected_time_start, selected_time_end; + struct icaltimetype itime; + struct icaltimetype tmp_itime; + time_t tt_start, tt_end; + struct icaldurationtype ic_dur; + char *uid; + CalComponentDateTime ccdt; + icaltimezone *default_zone; + + g_return_if_fail (E_IS_CAL_VIEW (cal_view)); + + 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; + + default_tzid = calendar_config_get_timezone (); + cal_client_get_timezone (cal_view->priv->client, default_tzid, &default_zone); + + /* 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; + } + + e_cal_view_set_status_message (cal_view, _("Updating objects")); + e_cal_view_get_selected_time_range (cal_view, &selected_time_start, &selected_time_end); + + 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 || + child_kind == ICAL_VTODO_COMPONENT || + child_kind == ICAL_VJOURNAL_COMPONENT) { + icalcomponent *new_icalcomp; + + new_icalcomp = icalcomponent_new_clone (subcomp); + comp = cal_component_new (); + + /* change the day for the event */ + tt_start = icaltime_as_timet ( + icalcomponent_get_dtstart (new_icalcomp)); + tt_end = icaltime_as_timet ( + icalcomponent_get_dtend (new_icalcomp)); + ic_dur = icaldurationtype_from_int (tt_end - tt_start); + + tmp_itime = icaltime_from_timet_with_zone ( + selected_time_start, FALSE, default_zone); + itime = icalcomponent_get_dtstart (new_icalcomp); + itime.year = tmp_itime.year; + itime.month = tmp_itime.month; + itime.day = tmp_itime.day; + + cal_component_set_icalcomponent (comp, new_icalcomp); + ccdt.value = &itime; + ccdt.tzid = icaltimezone_get_tzid (default_zone); + cal_component_set_dtstart (comp, &ccdt); + + itime = icaltime_add (itime, ic_dur); + ccdt.value = &itime; + cal_component_set_dtend (comp, &ccdt); + + uid = cal_component_gen_uid (); + cal_component_set_uid (comp, uid); + + cal_client_update_object (cal_view->priv->client, comp); + + g_free (uid); + g_object_unref (comp); + } + subcomp = icalcomponent_get_next_component ( + icalcomp, ICAL_ANY_COMPONENT); + } + + icalcomponent_free (icalcomp); + + } + else { + comp = cal_component_new (); + + /* change the day for the event */ + tt_start = icaltime_as_timet (icalcomponent_get_dtstart (icalcomp)); + tt_end = icaltime_as_timet (icalcomponent_get_dtend (icalcomp)); + ic_dur = icaldurationtype_from_int (tt_end - tt_start); + + tmp_itime = icaltime_from_timet_with_zone ( + selected_time_start, FALSE, default_zone); + itime = icalcomponent_get_dtstart (icalcomp); + itime.year = tmp_itime.year; + itime.month = tmp_itime.month; + itime.day = tmp_itime.day; + + cal_component_set_icalcomponent (comp, icalcomp); + ccdt.value = &itime; + ccdt.tzid = icaltimezone_get_tzid (default_zone); + cal_component_set_dtstart (comp, &ccdt); + + itime = icaltime_add (itime, ic_dur); + ccdt.value = &itime; + cal_component_set_dtend (comp, &ccdt); + + uid = cal_component_gen_uid (); + cal_component_set_uid (comp, (const char *) uid); + + cal_client_update_object (cal_view->priv->client, comp); + + if (itip_organizer_is_user (comp, cal_view->priv->client) && + send_component_dialog (gtk_widget_get_toplevel (cal_view), cal_view->priv->client, comp, TRUE)) + itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, cal_view->priv->client, NULL); + + g_free (uid); + g_object_unref (comp); + } + + e_cal_view_set_status_message (cal_view, NULL); } static void e_cal_view_init (ECalView *cal_view, ECalViewClass *klass) { cal_view->priv = g_new0 (ECalViewPrivate, 1); + + cal_view->priv->sexp = g_strdup ("#t"); /* match all by default */ + + /* Set up the invisible widget for the clipboard selections */ + cal_view->priv->invisible = gtk_invisible_new (); + gtk_selection_add_target (cal_view->priv->invisible, + clipboard_atom, + GDK_SELECTION_TYPE_STRING, + 0); + g_signal_connect (cal_view->priv->invisible, "selection_get", + G_CALLBACK (selection_get), (gpointer) cal_view); + g_signal_connect (cal_view->priv->invisible, "selection_clear_event", + G_CALLBACK (selection_clear_event), (gpointer) cal_view); + g_signal_connect (cal_view->priv->invisible, "selection_received", + G_CALLBACK (selection_received), (gpointer) cal_view); + + cal_view->priv->clipboard_selection = NULL; } static void @@ -89,11 +299,31 @@ e_cal_view_destroy (GtkObject *object) g_return_if_fail (E_IS_CAL_VIEW (cal_view)); if (cal_view->priv) { + if (cal_view->priv->client) { + g_object_unref (cal_view->priv->client); + cal_view->priv->client = NULL; + } + + if (cal_view->priv->sexp) { + g_free (cal_view->priv->sexp); + cal_view->priv->sexp = NULL; + } + if (cal_view->priv->activity) { g_object_unref (cal_view->priv->activity); cal_view->priv->activity = NULL; } + if (cal_view->priv->invisible) { + gtk_widget_destroy (cal_view->priv->invisible); + cal_view->priv->invisible = NULL; + } + + if (cal_view->priv->clipboard_selection) { + g_free (cal_view->priv->clipboard_selection); + cal_view->priv->clipboard_selection = NULL; + } + g_free (cal_view->priv); cal_view->priv = NULL; } @@ -121,6 +351,72 @@ e_cal_view_set_calendar (ECalView *cal_view, GnomeCalendar *calendar) cal_view->priv->calendar = calendar; } +CalClient * +e_cal_view_get_cal_client (ECalView *cal_view) +{ + g_return_val_if_fail (E_IS_CAL_VIEW (cal_view), NULL); + + return cal_view->priv->client; +} + +static void +cal_opened_cb (CalClient *client, CalClientOpenStatus status, gpointer user_data) +{ + ECalView *cal_view = (ECalView *) user_data; + + if (status != CAL_CLIENT_OPEN_SUCCESS) + return; + + e_cal_view_update_query (cal_view); +} + +void +e_cal_view_set_cal_client (ECalView *cal_view, CalClient *client) +{ + g_return_if_fail (E_IS_CAL_VIEW (cal_view)); + + if (client == cal_view->priv->client) + return; + + if (IS_CAL_CLIENT (client)) + g_object_ref (client); + + if (cal_view->priv->client) { + g_signal_handlers_disconnect_matched (cal_view->priv->client, G_SIGNAL_MATCH_DATA, 0, 0, + NULL, NULL, cal_view); + g_object_unref (cal_view->priv->client); + } + + cal_view->priv->client = client; + if (cal_view->priv->client) { + if (cal_client_get_load_state (cal_view->priv->client) == CAL_CLIENT_LOAD_LOADED) + e_cal_view_update_query (cal_view); + else + g_signal_connect (cal_view->priv->client, "cal_opened", + G_CALLBACK (cal_opened_cb), cal_view); + } +} + +const gchar * +e_cal_view_get_query (ECalView *cal_view) +{ + g_return_val_if_fail (E_IS_CAL_VIEW (cal_view), NULL); + + return (const gchar *) cal_view->priv->sexp; +} + +void +e_cal_view_set_query (ECalView *cal_view, const gchar *sexp) +{ + g_return_if_fail (E_IS_CAL_VIEW (cal_view)); + + if (cal_view->priv->sexp) + g_free (cal_view->priv->sexp); + + cal_view->priv->sexp = g_strdup (sexp); + e_cal_view_update_query (cal_view); +} + void e_cal_view_set_status_message (ECalView *cal_view, const gchar *message) { @@ -147,3 +443,128 @@ e_cal_view_set_status_message (ECalView *cal_view, const gchar *message) } else evolution_activity_client_update (cal_view->priv->activity, message, -1.0); } + +GList * +e_cal_view_get_selected_events (ECalView *cal_view) +{ + g_return_val_if_fail (E_IS_CAL_VIEW (cal_view), NULL); + + if (E_CAL_VIEW_CLASS (G_OBJECT_GET_CLASS (cal_view))->get_selected_events) + return E_CAL_VIEW_CLASS (G_OBJECT_GET_CLASS (cal_view))->get_selected_events (cal_view); + + return NULL; +} + +void +e_cal_view_get_selected_time_range (ECalView *cal_view, time_t *start_time, time_t *end_time) +{ + g_return_if_fail (E_IS_CAL_VIEW (cal_view)); + + if (E_CAL_VIEW_CLASS (G_OBJECT_GET_CLASS (cal_view))->get_selected_time_range) { + E_CAL_VIEW_CLASS (G_OBJECT_GET_CLASS (cal_view))->get_selected_time_range ( + cal_view, start_time, end_time); + } +} + +void +e_cal_view_set_selected_time_range (ECalView *cal_view, time_t start_time, time_t end_time) +{ + g_return_if_fail (E_IS_CAL_VIEW (cal_view)); + + if (E_CAL_VIEW_CLASS (G_OBJECT_GET_CLASS (cal_view))->set_selected_time_range) { + E_CAL_VIEW_CLASS (G_OBJECT_GET_CLASS (cal_view))->set_selected_time_range ( + cal_view, start_time, end_time); + } +} + +void +e_cal_view_update_query (ECalView *cal_view) +{ + g_return_if_fail (E_IS_CAL_VIEW (cal_view)); + + if (E_CAL_VIEW_CLASS (G_OBJECT_GET_CLASS (cal_view))->update_query) { + E_CAL_VIEW_CLASS (G_OBJECT_GET_CLASS (cal_view))->update_query (cal_view); + } +} + +void +e_cal_view_cut_clipboard (ECalView *cal_view) +{ + GList *selected, *l; + const char *uid; + + g_return_if_fail (E_IS_CAL_VIEW (cal_view)); + + selected = e_cal_view_get_selected_events (cal_view); + if (!selected) + return; + + e_cal_view_set_status_message (cal_view, _("Deleting selected objects")); + + e_cal_view_copy_clipboard (cal_view); + for (l = selected; l != NULL; l = l->next) { + CalComponent *comp = l->data; + + if (itip_organizer_is_user (comp, cal_view->priv->client) + && cancel_component_dialog ((GtkWindow *) gtk_widget_get_toplevel (cal_view), + cal_view->priv->client, comp, TRUE)) + itip_send_comp (CAL_COMPONENT_METHOD_CANCEL, comp, cal_view->priv->client, NULL); + + cal_component_get_uid (comp, &uid); + delete_error_dialog (cal_client_remove_object (cal_view->priv->client, uid), + CAL_COMPONENT_EVENT); + } + + e_cal_view_set_status_message (cal_view, NULL); + + g_list_free (selected); +} + +void +e_cal_view_copy_clipboard (ECalView *cal_view) +{ + GList *selected, *l; + gchar *comp_str; + icalcomponent *vcal_comp; + icalcomponent *new_icalcomp; + + g_return_if_fail (E_IS_CAL_VIEW (cal_view)); + + selected = e_cal_view_get_selected_events (cal_view); + if (!selected) + return; + + /* create top-level VCALENDAR component and add VTIMEZONE's */ + vcal_comp = cal_util_new_top_level (); + for (l = selected; l != NULL; l = l->next) + cal_util_add_timezones_from_component (vcal_comp, (CalComponent *) l->data); + + for (l = selected; l != NULL; l = l->next) { + CalComponent *comp = (CalComponent *) l->data; + + new_icalcomp = icalcomponent_new_clone (cal_component_get_icalcomponent (comp)); + icalcomponent_add_component (vcal_comp, new_icalcomp); + } + + /* 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_selection_owner_set (cal_view->priv->invisible, clipboard_atom, GDK_CURRENT_TIME); + + /* free memory */ + icalcomponent_free (vcal_comp); + g_list_free (selected); +} + +void +e_cal_view_paste_clipboard (ECalView *cal_view) +{ + g_return_if_fail (E_IS_CAL_VIEW (cal_view)); + + gtk_selection_convert (cal_view->priv->invisible, + clipboard_atom, + GDK_SELECTION_TYPE_STRING, + GDK_CURRENT_TIME); +} diff --git a/calendar/gui/e-cal-view.h b/calendar/gui/e-cal-view.h index b43fa0301d..d188ee6659 100644 --- a/calendar/gui/e-cal-view.h +++ b/calendar/gui/e-cal-view.h @@ -51,15 +51,34 @@ struct _ECalViewClass { /* Notification signals */ void (* selection_changed) (ECalView *cal_view); + + /* Virtual methods */ + GList * (* get_selected_events) (ECalView *cal_view); + void (* get_selected_time_range) (ECalView *cal_view, time_t *start_time, time_t *end_time); + void (* set_selected_time_range) (ECalView *cal_view, time_t start_time, time_t end_time); + void (* update_query) (ECalView *cal_view); }; GType e_cal_view_get_type (void); GnomeCalendar *e_cal_view_get_calendar (ECalView *cal_view); void e_cal_view_set_calendar (ECalView *cal_view, GnomeCalendar *calendar); +CalClient *e_cal_view_get_cal_client (ECalView *cal_view); +void e_cal_view_set_cal_client (ECalView *cal_view, CalClient *client); +const gchar *e_cal_view_get_query (ECalView *cal_view); +void e_cal_view_set_query (ECalView *cal_view, const gchar *sexp); void e_cal_view_set_status_message (ECalView *cal_view, const gchar *message); +GList *e_cal_view_get_selected_events (ECalView *cal_view); +void e_cal_view_get_selected_time_range (ECalView *cal_view, time_t *start_time, time_t *end_time); +void e_cal_view_set_selected_time_range (ECalView *cal_view, time_t start_time, time_t end_time); +void e_cal_view_update_query (ECalView *cal_view); + +void e_cal_view_cut_clipboard (ECalView *cal_view); +void e_cal_view_copy_clipboard (ECalView *cal_view); +void e_cal_view_paste_clipboard (ECalView *cal_view); + G_END_DECLS #endif diff --git a/calendar/gui/e-calendar-view.c b/calendar/gui/e-calendar-view.c index 6272f0eab9..1b4676beb8 100644 --- a/calendar/gui/e-calendar-view.c +++ b/calendar/gui/e-calendar-view.c @@ -22,9 +22,17 @@ */ #include +#include +#include +#include #include #include "evolution-activity-client.h" +#include "calendar-config.h" #include "e-cal-view.h" +#include "itip-utils.h" +#include "dialogs/cancel-comp.h" +#include "dialogs/delete-error.h" +#include "dialogs/send-comp.h" /* Used for the status bar messages */ #define EVOLUTION_CALENDAR_PROGRESS_IMAGE "evolution-calendar-mini.png" @@ -34,8 +42,18 @@ struct _ECalViewPrivate { /* The GnomeCalendar we are associated to */ GnomeCalendar *calendar; + /* Calendar client we are monitoring */ + CalClient *client; + + /* Search expression */ + gchar *sexp; + /* The activity client used to show messages on the status bar. */ EvolutionActivityClient *activity; + + /* the invisible widget to manage the clipboard selections */ + GtkWidget *invisible; + gchar *clipboard_selection; }; static void e_cal_view_class_init (ECalViewClass *klass); @@ -43,6 +61,7 @@ static void e_cal_view_init (ECalView *cal_view, ECalViewClass *klass); static void e_cal_view_destroy (GtkObject *object); static GObjectClass *parent_class = NULL; +static GdkAtom clipboard_atom = GDK_NONE; /* Signal IDs */ enum { @@ -73,12 +92,203 @@ e_cal_view_class_init (ECalViewClass *klass) object_class->destroy = e_cal_view_destroy; klass->selection_changed = NULL; + klass->get_selected_events = NULL; + klass->get_selected_time_range = NULL; + klass->set_selected_time_range = NULL; + klass->update_query = NULL; + + /* clipboard atom */ + if (!clipboard_atom) + clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE); +} + +static void +selection_get (GtkWidget *invisible, + GtkSelectionData *selection_data, + guint info, + guint time_stamp, + ECalView *cal_view) +{ + if (cal_view->priv->clipboard_selection != NULL) { + gtk_selection_data_set (selection_data, + GDK_SELECTION_TYPE_STRING, + 8, + cal_view->priv->clipboard_selection, + strlen (cal_view->priv->clipboard_selection)); + } +} + +static void +selection_clear_event (GtkWidget *invisible, + GdkEventSelection *event, + ECalView *cal_view) +{ + if (cal_view->priv->clipboard_selection != NULL) { + g_free (cal_view->priv->clipboard_selection); + cal_view->priv->clipboard_selection = NULL; + } +} + +static void +selection_received (GtkWidget *invisible, + GtkSelectionData *selection_data, + guint time, + ECalView *cal_view) +{ + char *comp_str, *default_tzid; + icalcomponent *icalcomp; + icalcomponent_kind kind; + CalComponent *comp; + time_t selected_time_start, selected_time_end; + struct icaltimetype itime; + struct icaltimetype tmp_itime; + time_t tt_start, tt_end; + struct icaldurationtype ic_dur; + char *uid; + CalComponentDateTime ccdt; + icaltimezone *default_zone; + + g_return_if_fail (E_IS_CAL_VIEW (cal_view)); + + 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; + + default_tzid = calendar_config_get_timezone (); + cal_client_get_timezone (cal_view->priv->client, default_tzid, &default_zone); + + /* 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; + } + + e_cal_view_set_status_message (cal_view, _("Updating objects")); + e_cal_view_get_selected_time_range (cal_view, &selected_time_start, &selected_time_end); + + 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 || + child_kind == ICAL_VTODO_COMPONENT || + child_kind == ICAL_VJOURNAL_COMPONENT) { + icalcomponent *new_icalcomp; + + new_icalcomp = icalcomponent_new_clone (subcomp); + comp = cal_component_new (); + + /* change the day for the event */ + tt_start = icaltime_as_timet ( + icalcomponent_get_dtstart (new_icalcomp)); + tt_end = icaltime_as_timet ( + icalcomponent_get_dtend (new_icalcomp)); + ic_dur = icaldurationtype_from_int (tt_end - tt_start); + + tmp_itime = icaltime_from_timet_with_zone ( + selected_time_start, FALSE, default_zone); + itime = icalcomponent_get_dtstart (new_icalcomp); + itime.year = tmp_itime.year; + itime.month = tmp_itime.month; + itime.day = tmp_itime.day; + + cal_component_set_icalcomponent (comp, new_icalcomp); + ccdt.value = &itime; + ccdt.tzid = icaltimezone_get_tzid (default_zone); + cal_component_set_dtstart (comp, &ccdt); + + itime = icaltime_add (itime, ic_dur); + ccdt.value = &itime; + cal_component_set_dtend (comp, &ccdt); + + uid = cal_component_gen_uid (); + cal_component_set_uid (comp, uid); + + cal_client_update_object (cal_view->priv->client, comp); + + g_free (uid); + g_object_unref (comp); + } + subcomp = icalcomponent_get_next_component ( + icalcomp, ICAL_ANY_COMPONENT); + } + + icalcomponent_free (icalcomp); + + } + else { + comp = cal_component_new (); + + /* change the day for the event */ + tt_start = icaltime_as_timet (icalcomponent_get_dtstart (icalcomp)); + tt_end = icaltime_as_timet (icalcomponent_get_dtend (icalcomp)); + ic_dur = icaldurationtype_from_int (tt_end - tt_start); + + tmp_itime = icaltime_from_timet_with_zone ( + selected_time_start, FALSE, default_zone); + itime = icalcomponent_get_dtstart (icalcomp); + itime.year = tmp_itime.year; + itime.month = tmp_itime.month; + itime.day = tmp_itime.day; + + cal_component_set_icalcomponent (comp, icalcomp); + ccdt.value = &itime; + ccdt.tzid = icaltimezone_get_tzid (default_zone); + cal_component_set_dtstart (comp, &ccdt); + + itime = icaltime_add (itime, ic_dur); + ccdt.value = &itime; + cal_component_set_dtend (comp, &ccdt); + + uid = cal_component_gen_uid (); + cal_component_set_uid (comp, (const char *) uid); + + cal_client_update_object (cal_view->priv->client, comp); + + if (itip_organizer_is_user (comp, cal_view->priv->client) && + send_component_dialog (gtk_widget_get_toplevel (cal_view), cal_view->priv->client, comp, TRUE)) + itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, cal_view->priv->client, NULL); + + g_free (uid); + g_object_unref (comp); + } + + e_cal_view_set_status_message (cal_view, NULL); } static void e_cal_view_init (ECalView *cal_view, ECalViewClass *klass) { cal_view->priv = g_new0 (ECalViewPrivate, 1); + + cal_view->priv->sexp = g_strdup ("#t"); /* match all by default */ + + /* Set up the invisible widget for the clipboard selections */ + cal_view->priv->invisible = gtk_invisible_new (); + gtk_selection_add_target (cal_view->priv->invisible, + clipboard_atom, + GDK_SELECTION_TYPE_STRING, + 0); + g_signal_connect (cal_view->priv->invisible, "selection_get", + G_CALLBACK (selection_get), (gpointer) cal_view); + g_signal_connect (cal_view->priv->invisible, "selection_clear_event", + G_CALLBACK (selection_clear_event), (gpointer) cal_view); + g_signal_connect (cal_view->priv->invisible, "selection_received", + G_CALLBACK (selection_received), (gpointer) cal_view); + + cal_view->priv->clipboard_selection = NULL; } static void @@ -89,11 +299,31 @@ e_cal_view_destroy (GtkObject *object) g_return_if_fail (E_IS_CAL_VIEW (cal_view)); if (cal_view->priv) { + if (cal_view->priv->client) { + g_object_unref (cal_view->priv->client); + cal_view->priv->client = NULL; + } + + if (cal_view->priv->sexp) { + g_free (cal_view->priv->sexp); + cal_view->priv->sexp = NULL; + } + if (cal_view->priv->activity) { g_object_unref (cal_view->priv->activity); cal_view->priv->activity = NULL; } + if (cal_view->priv->invisible) { + gtk_widget_destroy (cal_view->priv->invisible); + cal_view->priv->invisible = NULL; + } + + if (cal_view->priv->clipboard_selection) { + g_free (cal_view->priv->clipboard_selection); + cal_view->priv->clipboard_selection = NULL; + } + g_free (cal_view->priv); cal_view->priv = NULL; } @@ -121,6 +351,72 @@ e_cal_view_set_calendar (ECalView *cal_view, GnomeCalendar *calendar) cal_view->priv->calendar = calendar; } +CalClient * +e_cal_view_get_cal_client (ECalView *cal_view) +{ + g_return_val_if_fail (E_IS_CAL_VIEW (cal_view), NULL); + + return cal_view->priv->client; +} + +static void +cal_opened_cb (CalClient *client, CalClientOpenStatus status, gpointer user_data) +{ + ECalView *cal_view = (ECalView *) user_data; + + if (status != CAL_CLIENT_OPEN_SUCCESS) + return; + + e_cal_view_update_query (cal_view); +} + +void +e_cal_view_set_cal_client (ECalView *cal_view, CalClient *client) +{ + g_return_if_fail (E_IS_CAL_VIEW (cal_view)); + + if (client == cal_view->priv->client) + return; + + if (IS_CAL_CLIENT (client)) + g_object_ref (client); + + if (cal_view->priv->client) { + g_signal_handlers_disconnect_matched (cal_view->priv->client, G_SIGNAL_MATCH_DATA, 0, 0, + NULL, NULL, cal_view); + g_object_unref (cal_view->priv->client); + } + + cal_view->priv->client = client; + if (cal_view->priv->client) { + if (cal_client_get_load_state (cal_view->priv->client) == CAL_CLIENT_LOAD_LOADED) + e_cal_view_update_query (cal_view); + else + g_signal_connect (cal_view->priv->client, "cal_opened", + G_CALLBACK (cal_opened_cb), cal_view); + } +} + +const gchar * +e_cal_view_get_query (ECalView *cal_view) +{ + g_return_val_if_fail (E_IS_CAL_VIEW (cal_view), NULL); + + return (const gchar *) cal_view->priv->sexp; +} + +void +e_cal_view_set_query (ECalView *cal_view, const gchar *sexp) +{ + g_return_if_fail (E_IS_CAL_VIEW (cal_view)); + + if (cal_view->priv->sexp) + g_free (cal_view->priv->sexp); + + cal_view->priv->sexp = g_strdup (sexp); + e_cal_view_update_query (cal_view); +} + void e_cal_view_set_status_message (ECalView *cal_view, const gchar *message) { @@ -147,3 +443,128 @@ e_cal_view_set_status_message (ECalView *cal_view, const gchar *message) } else evolution_activity_client_update (cal_view->priv->activity, message, -1.0); } + +GList * +e_cal_view_get_selected_events (ECalView *cal_view) +{ + g_return_val_if_fail (E_IS_CAL_VIEW (cal_view), NULL); + + if (E_CAL_VIEW_CLASS (G_OBJECT_GET_CLASS (cal_view))->get_selected_events) + return E_CAL_VIEW_CLASS (G_OBJECT_GET_CLASS (cal_view))->get_selected_events (cal_view); + + return NULL; +} + +void +e_cal_view_get_selected_time_range (ECalView *cal_view, time_t *start_time, time_t *end_time) +{ + g_return_if_fail (E_IS_CAL_VIEW (cal_view)); + + if (E_CAL_VIEW_CLASS (G_OBJECT_GET_CLASS (cal_view))->get_selected_time_range) { + E_CAL_VIEW_CLASS (G_OBJECT_GET_CLASS (cal_view))->get_selected_time_range ( + cal_view, start_time, end_time); + } +} + +void +e_cal_view_set_selected_time_range (ECalView *cal_view, time_t start_time, time_t end_time) +{ + g_return_if_fail (E_IS_CAL_VIEW (cal_view)); + + if (E_CAL_VIEW_CLASS (G_OBJECT_GET_CLASS (cal_view))->set_selected_time_range) { + E_CAL_VIEW_CLASS (G_OBJECT_GET_CLASS (cal_view))->set_selected_time_range ( + cal_view, start_time, end_time); + } +} + +void +e_cal_view_update_query (ECalView *cal_view) +{ + g_return_if_fail (E_IS_CAL_VIEW (cal_view)); + + if (E_CAL_VIEW_CLASS (G_OBJECT_GET_CLASS (cal_view))->update_query) { + E_CAL_VIEW_CLASS (G_OBJECT_GET_CLASS (cal_view))->update_query (cal_view); + } +} + +void +e_cal_view_cut_clipboard (ECalView *cal_view) +{ + GList *selected, *l; + const char *uid; + + g_return_if_fail (E_IS_CAL_VIEW (cal_view)); + + selected = e_cal_view_get_selected_events (cal_view); + if (!selected) + return; + + e_cal_view_set_status_message (cal_view, _("Deleting selected objects")); + + e_cal_view_copy_clipboard (cal_view); + for (l = selected; l != NULL; l = l->next) { + CalComponent *comp = l->data; + + if (itip_organizer_is_user (comp, cal_view->priv->client) + && cancel_component_dialog ((GtkWindow *) gtk_widget_get_toplevel (cal_view), + cal_view->priv->client, comp, TRUE)) + itip_send_comp (CAL_COMPONENT_METHOD_CANCEL, comp, cal_view->priv->client, NULL); + + cal_component_get_uid (comp, &uid); + delete_error_dialog (cal_client_remove_object (cal_view->priv->client, uid), + CAL_COMPONENT_EVENT); + } + + e_cal_view_set_status_message (cal_view, NULL); + + g_list_free (selected); +} + +void +e_cal_view_copy_clipboard (ECalView *cal_view) +{ + GList *selected, *l; + gchar *comp_str; + icalcomponent *vcal_comp; + icalcomponent *new_icalcomp; + + g_return_if_fail (E_IS_CAL_VIEW (cal_view)); + + selected = e_cal_view_get_selected_events (cal_view); + if (!selected) + return; + + /* create top-level VCALENDAR component and add VTIMEZONE's */ + vcal_comp = cal_util_new_top_level (); + for (l = selected; l != NULL; l = l->next) + cal_util_add_timezones_from_component (vcal_comp, (CalComponent *) l->data); + + for (l = selected; l != NULL; l = l->next) { + CalComponent *comp = (CalComponent *) l->data; + + new_icalcomp = icalcomponent_new_clone (cal_component_get_icalcomponent (comp)); + icalcomponent_add_component (vcal_comp, new_icalcomp); + } + + /* 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_selection_owner_set (cal_view->priv->invisible, clipboard_atom, GDK_CURRENT_TIME); + + /* free memory */ + icalcomponent_free (vcal_comp); + g_list_free (selected); +} + +void +e_cal_view_paste_clipboard (ECalView *cal_view) +{ + g_return_if_fail (E_IS_CAL_VIEW (cal_view)); + + gtk_selection_convert (cal_view->priv->invisible, + clipboard_atom, + GDK_SELECTION_TYPE_STRING, + GDK_CURRENT_TIME); +} diff --git a/calendar/gui/e-calendar-view.h b/calendar/gui/e-calendar-view.h index b43fa0301d..d188ee6659 100644 --- a/calendar/gui/e-calendar-view.h +++ b/calendar/gui/e-calendar-view.h @@ -51,15 +51,34 @@ struct _ECalViewClass { /* Notification signals */ void (* selection_changed) (ECalView *cal_view); + + /* Virtual methods */ + GList * (* get_selected_events) (ECalView *cal_view); + void (* get_selected_time_range) (ECalView *cal_view, time_t *start_time, time_t *end_time); + void (* set_selected_time_range) (ECalView *cal_view, time_t start_time, time_t end_time); + void (* update_query) (ECalView *cal_view); }; GType e_cal_view_get_type (void); GnomeCalendar *e_cal_view_get_calendar (ECalView *cal_view); void e_cal_view_set_calendar (ECalView *cal_view, GnomeCalendar *calendar); +CalClient *e_cal_view_get_cal_client (ECalView *cal_view); +void e_cal_view_set_cal_client (ECalView *cal_view, CalClient *client); +const gchar *e_cal_view_get_query (ECalView *cal_view); +void e_cal_view_set_query (ECalView *cal_view, const gchar *sexp); void e_cal_view_set_status_message (ECalView *cal_view, const gchar *message); +GList *e_cal_view_get_selected_events (ECalView *cal_view); +void e_cal_view_get_selected_time_range (ECalView *cal_view, time_t *start_time, time_t *end_time); +void e_cal_view_set_selected_time_range (ECalView *cal_view, time_t start_time, time_t end_time); +void e_cal_view_update_query (ECalView *cal_view); + +void e_cal_view_cut_clipboard (ECalView *cal_view); +void e_cal_view_copy_clipboard (ECalView *cal_view); +void e_cal_view_paste_clipboard (ECalView *cal_view); + G_END_DECLS #endif diff --git a/calendar/gui/e-day-view.c b/calendar/gui/e-day-view.c index 55343080ba..53123917e2 100644 --- a/calendar/gui/e-day-view.c +++ b/calendar/gui/e-day-view.c @@ -35,7 +35,6 @@ #include #include #include -#include #include #include #include @@ -152,6 +151,10 @@ static gboolean e_day_view_get_extreme_event (EDayView *day_view, static gboolean e_day_view_do_key_press (GtkWidget *widget, GdkEventKey *event); static gboolean e_day_view_popup_menu (GtkWidget *widget); +static GList *e_day_view_get_selected_events (ECalView *cal_view); +static void e_day_view_get_selected_time_range (EDayView *day_view, time_t *start_time, time_t *end_time); +static void e_day_view_set_selected_time_range (EDayView *day_view, time_t start_time, time_t end_time); +static void e_day_view_update_query (EDayView *day_view); static void e_day_view_goto_start_of_work_day (EDayView *day_view); static void e_day_view_goto_end_of_work_day (EDayView *day_view); static void e_day_view_cursor_key_up_shifted (EDayView *day_view, @@ -466,26 +469,12 @@ static time_t e_day_view_find_work_week_start (EDayView *day_view, static void e_day_view_recalc_work_week (EDayView *day_view); static void e_day_view_recalc_work_week_days_shown (EDayView *day_view); -static void selection_clear_event (GtkWidget *invisible, - GdkEventSelection *event, - EDayView *day_view); -static void selection_received (GtkWidget *invisible, - GtkSelectionData *selection_data, - guint time, - EDayView *day_view); -static void selection_get (GtkWidget *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - EDayView *day_view); - static void e_day_view_queue_layout (EDayView *day_view); static void e_day_view_cancel_layout (EDayView *day_view); static gboolean e_day_view_layout_timeout_cb (gpointer data); static GtkTableClass *parent_class; -static GdkAtom clipboard_atom = GDK_NONE; E_MAKE_TYPE (e_day_view, "EDayView", EDayView, e_day_view_class_init, e_day_view_init, e_cal_view_get_type ()); @@ -495,10 +484,12 @@ e_day_view_class_init (EDayViewClass *class) { GtkObjectClass *object_class; GtkWidgetClass *widget_class; + ECalViewClass *view_class; parent_class = g_type_class_peek_parent (class); object_class = (GtkObjectClass *) class; widget_class = (GtkWidgetClass *) class; + view_class = (ECalViewClass *) class; /* Method override */ object_class->destroy = e_day_view_destroy; @@ -513,10 +504,10 @@ e_day_view_class_init (EDayViewClass *class) widget_class->focus = e_day_view_focus; widget_class->popup_menu = e_day_view_popup_menu; - /* clipboard atom */ - if (!clipboard_atom) - clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE); - + view_class->get_selected_events = e_day_view_get_selected_events; + view_class->get_selected_time_range = e_day_view_get_selected_time_range; + view_class->set_selected_time_range = e_day_view_set_selected_time_range; + view_class->update_query = e_day_view_update_query; } static void @@ -527,8 +518,6 @@ e_day_view_init (EDayView *day_view) GTK_WIDGET_SET_FLAGS (day_view, GTK_CAN_FOCUS); - day_view->client = NULL; - day_view->sexp = g_strdup ("#t"); /* match all by default */ day_view->query = NULL; day_view->long_events = g_array_new (FALSE, FALSE, @@ -836,21 +825,6 @@ e_day_view_init (EDayView *day_view) GTK_DEST_DEFAULT_ALL, target_table, n_targets, GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK); - - /* Set up the invisible widget for the clipboard selections */ - day_view->invisible = gtk_invisible_new (); - gtk_selection_add_target (day_view->invisible, - clipboard_atom, - GDK_SELECTION_TYPE_STRING, - 0); - g_signal_connect (day_view->invisible, "selection_get", - G_CALLBACK (selection_get), (gpointer) day_view); - g_signal_connect (day_view->invisible, "selection_clear_event", - G_CALLBACK (selection_clear_event), (gpointer) day_view); - g_signal_connect (day_view->invisible, "selection_received", - G_CALLBACK (selection_received), (gpointer) day_view); - - day_view->clipboard_selection = NULL; } @@ -894,15 +868,9 @@ e_day_view_destroy (GtkObject *object) e_day_view_stop_auto_scroll (day_view); - if (day_view->client) { - g_signal_handlers_disconnect_matched (day_view->client, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, day_view); - g_object_unref (day_view->client); - day_view->client = NULL; - } - - if (day_view->sexp) { - g_free (day_view->sexp); - day_view->sexp = NULL; + if (e_cal_view_get_cal_client (E_CAL_VIEW (day_view))) { + g_signal_handlers_disconnect_matched (e_cal_view_get_cal_client (E_CAL_VIEW (day_view)), + G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, day_view); } if (day_view->query) { @@ -953,15 +921,6 @@ e_day_view_destroy (GtkObject *object) } } - if (day_view->invisible) { - gtk_widget_destroy (day_view->invisible); - day_view->invisible = NULL; - } - if (day_view->clipboard_selection) { - g_free (day_view->clipboard_selection); - day_view->clipboard_selection = NULL; - } - GTK_OBJECT_CLASS (parent_class)->destroy (object); } @@ -1493,7 +1452,7 @@ query_obj_updated_cb (CalQuery *query, const char *uid, return; /* Get the event from the server. */ - status = cal_client_get_object (day_view->client, uid, &comp); + status = cal_client_get_object (e_cal_view_get_cal_client (E_CAL_VIEW (day_view)), uid, &comp); switch (status) { case CAL_CLIENT_GET_SUCCESS: @@ -1551,7 +1510,8 @@ query_obj_updated_cb (CalQuery *query, const char *uid, cal_recur_generate_instances (comp, day_view->lower, day_view->upper, e_day_view_add_event, day_view, - cal_client_resolve_tzid_cb, day_view->client, + cal_client_resolve_tzid_cb, + e_cal_view_get_cal_client (E_CAL_VIEW (day_view)), day_view->zone); g_object_unref (comp); @@ -1635,136 +1595,6 @@ adjust_query_sexp (EDayView *day_view, const char *sexp) return new_sexp; } - -/* Restarts a query for the day view */ -static void -update_query (EDayView *day_view) -{ - CalQuery *old_query; - char *real_sexp; - - e_day_view_stop_editing_event (day_view); - - gtk_widget_queue_draw (day_view->top_canvas); - gtk_widget_queue_draw (day_view->main_canvas); - e_day_view_free_events (day_view); - e_day_view_queue_layout (day_view); - - if (!(day_view->client - && cal_client_get_load_state (day_view->client) == CAL_CLIENT_LOAD_LOADED)) - return; - - old_query = day_view->query; - day_view->query = NULL; - - if (old_query) { - g_signal_handlers_disconnect_matched (old_query, G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, day_view); - g_object_unref (old_query); - } - - g_assert (day_view->sexp != NULL); - - real_sexp = adjust_query_sexp (day_view, day_view->sexp); - if (!real_sexp) - return; /* No time range is set, so don't start a query */ - - e_cal_view_set_status_message (E_CAL_VIEW (day_view), _("Searching")); - day_view->query = cal_client_get_query (day_view->client, real_sexp); - g_free (real_sexp); - - if (!day_view->query) { - g_message ("update_query(): Could not create the query"); - return; - } - - g_signal_connect (day_view->query, "obj_updated", - G_CALLBACK (query_obj_updated_cb), day_view); - g_signal_connect (day_view->query, "obj_removed", - G_CALLBACK (query_obj_removed_cb), day_view); - g_signal_connect (day_view->query, "query_done", - G_CALLBACK (query_query_done_cb), day_view); - g_signal_connect (day_view->query, "eval_error", - G_CALLBACK (query_eval_error_cb), day_view); -} - -/* Callback used when the calendar client finishes opening */ -static void -cal_opened_cb (CalClient *client, CalClientOpenStatus status, gpointer data) -{ - EDayView *day_view; - - day_view = E_DAY_VIEW (data); - - if (status != CAL_CLIENT_OPEN_SUCCESS) - return; - - update_query (day_view); -} - -/** - * e_day_view_set_cal_client: - * @day_view: A day view. - * @client: A calendar client interface object. - * - * Sets the calendar client interface object that a day view will monitor. - **/ -void -e_day_view_set_cal_client (EDayView *day_view, - CalClient *client) -{ - g_return_if_fail (day_view != NULL); - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - - if (client == day_view->client) - return; - - if (client) - g_return_if_fail (IS_CAL_CLIENT (client)); - - if (client) - g_object_ref (client); - - if (day_view->client) { - g_signal_handlers_disconnect_matched (day_view->client, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, day_view); - g_object_unref (day_view->client); - } - - day_view->client = client; - - if (day_view->client) { - if (cal_client_get_load_state (day_view->client) == CAL_CLIENT_LOAD_LOADED) - update_query (day_view); - else - g_signal_connect (day_view->client, "cal_opened", - G_CALLBACK (cal_opened_cb), day_view); - } -} - -/** - * e_day_view_set_query: - * @day_view: A day view. - * @sexp: S-expression that defines the query. - * - * Sets the query sexp that the day view will use for filtering the displayed - * events. - **/ -void -e_day_view_set_query (EDayView *day_view, const char *sexp) -{ - g_return_if_fail (day_view != NULL); - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - g_return_if_fail (sexp != NULL); - - if (day_view->sexp) - g_free (day_view->sexp); - - day_view->sexp = g_strdup (sexp); - - update_query (day_view); -} - - /** * e_day_view_set_default_category: * @day_view: A day view. @@ -2160,7 +1990,7 @@ e_day_view_find_event_from_uid (EDayView *day_view, corresponding to the start time. If the start_time & end_time are not equal and are both visible in the view, then the selection is set to those times, otherwise it is set to 1 hour from the start of the working day. */ -void +static void e_day_view_set_selected_time_range (EDayView *day_view, time_t start_time, time_t end_time) @@ -2184,7 +2014,7 @@ e_day_view_set_selected_time_range (EDayView *day_view, /* See if we need to change the days shown. */ if (lower != day_view->lower) { e_day_view_recalc_day_starts (day_view, lower); - update_query (day_view); + e_day_view_update_query (day_view); } /* Set the selection. */ @@ -2379,7 +2209,7 @@ e_day_view_find_work_week_start (EDayView *day_view, /* Returns the selected time range. */ -void +static void e_day_view_get_selected_time_range (EDayView *day_view, time_t *start_time, time_t *end_time) @@ -2495,7 +2325,7 @@ e_day_view_set_days_shown (EDayView *day_view, e_day_view_recalc_day_starts (day_view, day_view->lower); e_day_view_recalc_cell_sizes (day_view); - update_query (day_view); + e_day_view_update_query (day_view); } @@ -2748,7 +2578,7 @@ e_day_view_set_timezone (EDayView *day_view, lower = icaltime_as_timet_with_zone (tt, zone); e_day_view_recalc_day_starts (day_view, lower); - update_query (day_view); + e_day_view_update_query (day_view); } @@ -2794,87 +2624,6 @@ e_day_view_set_week_start_day (EDayView *day_view, e_day_view_recalc_work_week (day_view); } -static EDayViewEvent * -get_current_event (EDayView *day_view) -{ - g_return_val_if_fail (E_IS_DAY_VIEW (day_view), NULL); - - if (day_view->editing_event_day == -1) - return NULL; - - if (day_view->editing_event_day == E_DAY_VIEW_LONG_EVENT) - return &g_array_index (day_view->long_events, - EDayViewEvent, - day_view->editing_event_num); - else - return &g_array_index (day_view->events[day_view->editing_event_day], - EDayViewEvent, - day_view->editing_event_num); -} - -void -e_day_view_cut_clipboard (EDayView *day_view) -{ - EDayViewEvent *event; - const char *uid; - - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - - event = get_current_event (day_view); - if (event == NULL) - return; - - e_cal_view_set_status_message (E_CAL_VIEW (day_view), _("Deleting selected objects")); - - e_day_view_copy_clipboard (day_view); - cal_component_get_uid (event->comp, &uid); - delete_error_dialog (cal_client_remove_object (day_view->client, uid), CAL_COMPONENT_EVENT); - - e_cal_view_set_status_message (E_CAL_VIEW (day_view), NULL); -} - -void -e_day_view_copy_clipboard (EDayView *day_view) -{ - EDayViewEvent *event; - char *comp_str; - icalcomponent *vcal_comp; - icalcomponent *new_icalcomp; - - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - - event = get_current_event (day_view); - if (event == NULL) - return; - - /* create top-level VCALENDAR component and add VTIMEZONE's */ - vcal_comp = cal_util_new_top_level (); - cal_util_add_timezones_from_component (vcal_comp, event->comp); - - new_icalcomp = icalcomponent_new_clone (cal_component_get_icalcomponent (event->comp)); - icalcomponent_add_component (vcal_comp, new_icalcomp); - - comp_str = icalcomponent_as_ical_string (vcal_comp); - if (day_view->clipboard_selection != NULL) - g_free (day_view->clipboard_selection); - day_view->clipboard_selection = g_strdup (comp_str); - gtk_selection_owner_set (day_view->invisible, clipboard_atom, GDK_CURRENT_TIME); - - /* free memory */ - icalcomponent_free (vcal_comp); -} - -void -e_day_view_paste_clipboard (EDayView *day_view) -{ - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - - gtk_selection_convert (day_view->invisible, - clipboard_atom, - GDK_SELECTION_TYPE_STRING, - GDK_CURRENT_TIME); -} - static void e_day_view_recalc_work_week (EDayView *day_view) { @@ -2896,7 +2645,7 @@ e_day_view_recalc_work_week (EDayView *day_view) day_view->selection_start_day = -1; e_day_view_recalc_day_starts (day_view, lower); - update_query (day_view); + e_day_view_update_query (day_view); /* This updates the date navigator. */ e_day_view_update_calendar_selection_time (day_view); @@ -3788,12 +3537,13 @@ e_day_view_show_popup_menu (EDayView *day_view, if (cal_component_has_organizer (event->comp)) { disable_mask |= MASK_MEETING; - if (!itip_organizer_is_user (event->comp, day_view->client)) + if (!itip_organizer_is_user (event->comp, + e_cal_view_get_cal_client (E_CAL_VIEW (day_view)))) disable_mask |= MASK_MEETING_ORGANIZER; } } - if (cal_client_is_read_only (day_view->client)) + if (cal_client_is_read_only (e_cal_view_get_cal_client (E_CAL_VIEW (day_view)))) disable_mask |= MASK_EDITABLE; if (being_edited) @@ -3817,6 +3567,78 @@ e_day_view_popup_menu (GtkWidget *widget) return TRUE; } +/* Returns the currently-selected event, or NULL if none */ +static GList * +e_day_view_get_selected_events (ECalView *cal_view) +{ + EDayViewEvent *event; + GList *list = NULL; + EDayView *day_view = (EDayView *) cal_view; + + g_return_val_if_fail (E_IS_DAY_VIEW (day_view), NULL); + g_return_val_if_fail (day_view->editing_event_day != -1, NULL); + + if (day_view->editing_event_day == E_DAY_VIEW_LONG_EVENT) + event = &g_array_index (day_view->long_events, + EDayViewEvent, + day_view->editing_event_num); + else + event = &g_array_index (day_view->events[day_view->editing_event_day], + EDayViewEvent, + day_view->editing_event_num); + + if (event) + list = g_list_append (list, event->comp); + + return list; +} + +/* Restarts a query for the day view */ +static void +e_day_view_update_query (EDayView *day_view) +{ + CalQuery *old_query; + char *real_sexp; + + e_day_view_stop_editing_event (day_view); + + gtk_widget_queue_draw (day_view->top_canvas); + gtk_widget_queue_draw (day_view->main_canvas); + e_day_view_free_events (day_view); + e_day_view_queue_layout (day_view); + + old_query = day_view->query; + day_view->query = NULL; + + if (old_query) { + g_signal_handlers_disconnect_matched (old_query, G_SIGNAL_MATCH_DATA, + 0, 0, NULL, NULL, day_view); + g_object_unref (old_query); + } + + real_sexp = adjust_query_sexp (day_view, e_cal_view_get_query (E_CAL_VIEW (day_view))); + if (!real_sexp) + return; /* No time range is set, so don't start a query */ + + e_cal_view_set_status_message (E_CAL_VIEW (day_view), _("Searching")); + day_view->query = cal_client_get_query (e_cal_view_get_cal_client (E_CAL_VIEW (day_view)), real_sexp); + g_free (real_sexp); + + if (!day_view->query) { + g_message ("e_day_view_update_query(): Could not create the query"); + return; + } + + g_signal_connect (day_view->query, "obj_updated", + G_CALLBACK (query_obj_updated_cb), day_view); + g_signal_connect (day_view->query, "obj_removed", + G_CALLBACK (query_obj_removed_cb), day_view); + g_signal_connect (day_view->query, "query_done", + G_CALLBACK (query_query_done_cb), day_view); + g_signal_connect (day_view->query, "eval_error", + G_CALLBACK (query_eval_error_cb), day_view); +} + static void e_day_view_on_event_right_click (EDayView *day_view, GdkEventButton *bevent, @@ -3961,7 +3783,8 @@ e_day_view_on_save_as (GtkWidget *widget, gpointer data) if (filename == NULL) return; - ical_string = cal_client_get_component_as_string (day_view->client, event->comp); + ical_string = cal_client_get_component_as_string (e_cal_view_get_cal_client (E_CAL_VIEW (day_view)), + event->comp); if (ical_string == NULL) { g_warning ("Couldn't convert item to a string"); return; @@ -4020,7 +3843,7 @@ e_day_view_on_print_event (GtkWidget *widget, gpointer data) if (event == NULL) return; - print_comp (event->comp, day_view->client, FALSE); + print_comp (event->comp, e_cal_view_get_cal_client (E_CAL_VIEW (day_view)), FALSE); } static void @@ -4036,7 +3859,7 @@ e_day_view_on_meeting (GtkWidget *widget, gpointer data) if (event == NULL) return; - e_cal_view_get_calendar (E_CAL_VIEW (day_view)); + calendar = e_cal_view_get_calendar (E_CAL_VIEW (day_view)); if (calendar) gnome_calendar_edit_object (calendar, event->comp, TRUE); else @@ -4056,7 +3879,7 @@ e_day_view_on_forward (GtkWidget *widget, gpointer data) return; itip_send_comp (CAL_COMPONENT_METHOD_PUBLISH, event->comp, - day_view->client, NULL); + e_cal_view_get_cal_client (E_CAL_VIEW (day_view)), NULL); } static void @@ -4073,14 +3896,15 @@ e_day_view_on_publish (GtkWidget *widget, gpointer data) start = time_day_begin_with_zone (start, utc); end = time_add_week_with_zone (start, 6, utc); - comp_list = cal_client_get_free_busy (day_view->client, NULL, start, end); + comp_list = cal_client_get_free_busy (e_cal_view_get_cal_client (E_CAL_VIEW (day_view)), NULL, + start, end); if (comp_list) { GList *l; for (l = comp_list; l; l = l->next) { CalComponent *comp = CAL_COMPONENT (l->data); itip_send_comp (CAL_COMPONENT_METHOD_PUBLISH, comp, - day_view->client, NULL); + e_cal_view_get_cal_client (E_CAL_VIEW (day_view)), NULL); g_object_unref (comp); } @@ -4110,14 +3934,17 @@ e_day_view_delete_event_internal (EDayView *day_view, EDayViewEvent *event) GTK_WIDGET (day_view))) { const char *uid; - if (itip_organizer_is_user (event->comp, day_view->client) + if (itip_organizer_is_user (event->comp, e_cal_view_get_cal_client (E_CAL_VIEW (day_view))) && cancel_component_dialog ((GtkWindow *) gtk_widget_get_toplevel (day_view), - day_view->client, event->comp, TRUE)) - itip_send_comp (CAL_COMPONENT_METHOD_CANCEL, event->comp, day_view->client, NULL); + e_cal_view_get_cal_client (E_CAL_VIEW (day_view)), + event->comp, TRUE)) + itip_send_comp (CAL_COMPONENT_METHOD_CANCEL, event->comp, + e_cal_view_get_cal_client (E_CAL_VIEW (day_view)), NULL); cal_component_get_uid (event->comp, &uid); - delete_error_dialog (cal_client_remove_object (day_view->client, uid), CAL_COMPONENT_EVENT); + delete_error_dialog (cal_client_remove_object (e_cal_view_get_cal_client (E_CAL_VIEW (day_view)), + uid), CAL_COMPONENT_EVENT); } } @@ -4179,8 +4006,10 @@ e_day_view_delete_occurrence_internal (EDayView *day_view, EDayViewEvent *event) cal_component_get_uid (event->comp, &uid); - delete_error_dialog (cal_client_remove_object_with_mod (day_view->client, uid, CALOBJ_MOD_THIS), - CAL_COMPONENT_EVENT); + delete_error_dialog ( + cal_client_remove_object_with_mod (e_cal_view_get_cal_client (E_CAL_VIEW (day_view)), + uid, CALOBJ_MOD_THIS), + CAL_COMPONENT_EVENT); return; } @@ -4189,7 +4018,8 @@ e_day_view_delete_occurrence_internal (EDayView *day_view, EDayViewEvent *event) comp = cal_component_clone (event->comp); cal_comp_util_add_exdate (comp, event->start, day_view->zone); - if (cal_client_update_object (day_view->client, comp) != CAL_CLIENT_RESULT_SUCCESS) + if (cal_client_update_object (e_cal_view_get_cal_client (E_CAL_VIEW (day_view)), comp) + != CAL_CLIENT_RESULT_SUCCESS) g_message ("e_day_view_on_delete_occurrence(): Could not update the object!"); g_object_unref (comp); @@ -4235,58 +4065,17 @@ e_day_view_delete_occurrence (EDayView *day_view) static void e_day_view_on_cut (GtkWidget *widget, gpointer data) { - EDayView *day_view; - EDayViewEvent *event; - const char *uid; - - day_view = E_DAY_VIEW (data); - - event = e_day_view_get_popup_menu_event (day_view); - if (event == NULL) - return; - - e_day_view_on_copy (widget, data); - - if (itip_organizer_is_user (event->comp, day_view->client) - && cancel_component_dialog ((GtkWindow *) gtk_widget_get_toplevel (day_view), - day_view->client, event->comp, TRUE)) - itip_send_comp (CAL_COMPONENT_METHOD_CANCEL, event->comp, day_view->client, NULL); + EDayView *day_view = E_DAY_VIEW (data); - cal_component_get_uid (event->comp, &uid); - delete_error_dialog (cal_client_remove_object (day_view->client, uid), CAL_COMPONENT_EVENT); + e_cal_view_cut_clipboard (E_CAL_VIEW (day_view)); } static void e_day_view_on_copy (GtkWidget *widget, gpointer data) { - EDayView *day_view; - EDayViewEvent *event; - char *comp_str; - icalcomponent *vcal_comp; - icalcomponent *new_icalcomp; - - day_view = E_DAY_VIEW (data); - - event = e_day_view_get_popup_menu_event (day_view); - if (event == NULL) - return; - - /* create top-level VCALENDAR component and add VTIMEZONE's */ - vcal_comp = cal_util_new_top_level (); - cal_util_add_timezones_from_component (vcal_comp, event->comp); - - new_icalcomp = icalcomponent_new_clone (cal_component_get_icalcomponent (event->comp)); - icalcomponent_add_component (vcal_comp, new_icalcomp); - - comp_str = icalcomponent_as_ical_string (vcal_comp); - if (day_view->clipboard_selection) - g_free (day_view->clipboard_selection); - day_view->clipboard_selection = g_strdup (comp_str); - - gtk_selection_owner_set (day_view->invisible, clipboard_atom, GDK_CURRENT_TIME); + EDayView *day_view = E_DAY_VIEW (data); - /* free memory */ - icalcomponent_free (vcal_comp); + e_cal_view_copy_clipboard (E_CAL_VIEW (day_view)); } static void @@ -4294,10 +4083,7 @@ e_day_view_on_paste (GtkWidget *widget, gpointer data) { EDayView *day_view = E_DAY_VIEW (data); - gtk_selection_convert (day_view->invisible, - clipboard_atom, - GDK_SELECTION_TYPE_STRING, - GDK_CURRENT_TIME); + e_cal_view_paste_clipboard (E_CAL_VIEW (day_view)); } static void @@ -4348,12 +4134,14 @@ e_day_view_on_unrecur_appointment (GtkWidget *widget, gpointer data) /* Now update both CalComponents. Note that we do this last since at * present the updates happen synchronously so our event may disappear. */ - if (cal_client_update_object (day_view->client, comp) != CAL_CLIENT_RESULT_SUCCESS) + if (cal_client_update_object (e_cal_view_get_cal_client (E_CAL_VIEW (day_view)), comp) + != CAL_CLIENT_RESULT_SUCCESS) g_message ("e_day_view_on_unrecur_appointment(): Could not update the object!"); g_object_unref (comp); - if (cal_client_update_object (day_view->client, new_comp) != CAL_CLIENT_RESULT_SUCCESS) + if (cal_client_update_object (e_cal_view_get_cal_client (E_CAL_VIEW (day_view)), new_comp) + != CAL_CLIENT_RESULT_SUCCESS) g_message ("e_day_view_on_unrecur_appointment(): Could not update the object!"); g_object_unref (new_comp); @@ -4853,6 +4641,9 @@ e_day_view_finish_long_event_resize (EDayView *day_view) CalComponentDateTime date; struct icaltimetype itt; time_t dt; + CalClient *client; + + client = e_cal_view_get_cal_client (E_CAL_VIEW (day_view)); event_num = day_view->resize_event_num; event = &g_array_index (day_view->long_events, EDayViewEvent, @@ -4884,22 +4675,22 @@ e_day_view_finish_long_event_resize (EDayView *day_view) CalObjModType mod; if (recur_component_dialog (comp, &mod, NULL)) { - if (cal_client_update_object_with_mod (day_view->client, comp, mod) == CAL_CLIENT_RESULT_SUCCESS) { - if (itip_organizer_is_user (comp, day_view->client) && + if (cal_client_update_object_with_mod (client, comp, mod) == CAL_CLIENT_RESULT_SUCCESS) { + if (itip_organizer_is_user (comp, client) && send_component_dialog (gtk_widget_get_toplevel (day_view), - day_view->client, comp, FALSE)) - itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, day_view->client, NULL); + client, comp, FALSE)) + itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, client, NULL); } else { g_message ("e_day_view_finish_resize(): Could not update the object!"); } } else { gtk_widget_queue_draw (day_view->top_canvas); } - } else if (cal_client_update_object (day_view->client, comp) == CAL_CLIENT_RESULT_SUCCESS) { - if (itip_organizer_is_user (comp, day_view->client) && + } else if (cal_client_update_object (client, comp) == CAL_CLIENT_RESULT_SUCCESS) { + if (itip_organizer_is_user (comp, client) && send_component_dialog (gtk_widget_get_toplevel (day_view), - day_view->client, comp, TRUE)) - itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, day_view->client, NULL); + client, comp, TRUE)) + itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, client, NULL); } else { g_message ("e_day_view_finish_long_event_resize(): Could not update the object!"); } @@ -4923,6 +4714,9 @@ e_day_view_finish_resize (EDayView *day_view) CalComponentDateTime date; struct icaltimetype itt; time_t dt; + CalClient *client; + + client = e_cal_view_get_cal_client (E_CAL_VIEW (day_view)); day = day_view->resize_event_day; event_num = day_view->resize_event_num; @@ -4966,21 +4760,21 @@ e_day_view_finish_resize (EDayView *day_view) CalObjModType mod; if (recur_component_dialog (comp, &mod, NULL)) { - if (cal_client_update_object_with_mod (day_view->client, comp, mod) == CAL_CLIENT_RESULT_SUCCESS) { - if (itip_organizer_is_user (comp, day_view->client) && + if (cal_client_update_object_with_mod (client, comp, mod) == CAL_CLIENT_RESULT_SUCCESS) { + if (itip_organizer_is_user (comp, client) && send_component_dialog (gtk_widget_get_toplevel (day_view), - day_view->client, comp, FALSE)) - itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, day_view->client, NULL); + client, comp, FALSE)) + itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, client, NULL); } else { g_message ("e_day_view_finish_resize(): Could not update the object!"); } } else { gtk_widget_queue_draw (day_view->main_canvas); } - } else if (cal_client_update_object (day_view->client, comp) == CAL_CLIENT_RESULT_SUCCESS) { - if (itip_organizer_is_user (comp, day_view->client) && - send_component_dialog (gtk_widget_get_toplevel (day_view), day_view->client, comp, FALSE)) - itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, day_view->client, NULL); + } else if (cal_client_update_object (client, comp) == CAL_CLIENT_RESULT_SUCCESS) { + if (itip_organizer_is_user (comp, client) && + send_component_dialog (gtk_widget_get_toplevel (day_view), client, comp, FALSE)) + itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, client, NULL); } else { g_message ("e_day_view_finish_resize(): Could not update the object!"); } @@ -5113,7 +4907,7 @@ e_day_view_add_event (CalComponent *comp, event.num_columns = 0; event.different_timezone = FALSE; - if (!cal_comp_util_compare_event_timezones (comp, day_view->client, + if (!cal_comp_util_compare_event_timezones (comp, e_cal_view_get_cal_client (E_CAL_VIEW (day_view)), day_view->zone)) event.different_timezone = TRUE; @@ -5631,7 +5425,9 @@ e_day_view_do_key_press (GtkWidget *widget, GdkEventKey *event) day_view = E_DAY_VIEW (widget); keyval = event->keyval; - if (!(day_view->client && cal_client_get_load_state (day_view->client) == CAL_CLIENT_LOAD_LOADED)) + if (!(e_cal_view_get_cal_client (E_CAL_VIEW (day_view)) + && cal_client_get_load_state (e_cal_view_get_cal_client (E_CAL_VIEW (day_view))) + == CAL_CLIENT_LOAD_LOADED)) return TRUE; /* The Escape key aborts a resize operation. */ @@ -5732,7 +5528,7 @@ e_day_view_do_key_press (GtkWidget *widget, GdkEventKey *event) /* Add a new event covering the selected range */ - comp = cal_comp_event_new_with_defaults (day_view->client); + comp = cal_comp_event_new_with_defaults (e_cal_view_get_cal_client (E_CAL_VIEW (day_view))); e_day_view_get_selected_time_range (day_view, &dtstart, &dtend); @@ -6561,7 +6357,8 @@ e_day_view_on_editing_stopped (EDayView *day_view, NULL); g_assert (text != NULL); - if (string_is_empty (text) && !cal_comp_is_on_server (event->comp, day_view->client)) { + if (string_is_empty (text) && + !cal_comp_is_on_server (event->comp, e_cal_view_get_cal_client (E_CAL_VIEW (day_view)))) { const char *uid; cal_component_get_uid (event->comp, &uid); @@ -6583,6 +6380,10 @@ e_day_view_on_editing_stopped (EDayView *day_view, e_day_view_update_event_label (day_view, day, event_num); } else if (summary.value || !string_is_empty (text)) { + CalClient *client; + + client = e_cal_view_get_cal_client (E_CAL_VIEW (day_view)); + summary.value = text; summary.altrep = NULL; cal_component_set_summary (event->comp, &summary); @@ -6591,22 +6392,22 @@ e_day_view_on_editing_stopped (EDayView *day_view, CalObjModType mod; if (recur_component_dialog (event->comp, &mod, NULL)) { - if (cal_client_update_object_with_mod (day_view->client, event->comp, mod) == CAL_CLIENT_RESULT_SUCCESS) { - if (itip_organizer_is_user (event->comp, day_view->client) + if (cal_client_update_object_with_mod (client, event->comp, mod) == CAL_CLIENT_RESULT_SUCCESS) { + if (itip_organizer_is_user (event->comp, client) && send_component_dialog (gtk_widget_get_toplevel (day_view), - day_view->client, event->comp, FALSE)) + client, event->comp, FALSE)) itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, event->comp, - day_view->client, NULL); + client, NULL); } else { g_message ("e_day_view_on_editing_stopped(): Could not update the object!"); } } - } else if (cal_client_update_object (day_view->client, event->comp) == CAL_CLIENT_RESULT_SUCCESS) { - if (itip_organizer_is_user (event->comp, day_view->client) && + } else if (cal_client_update_object (client, event->comp) == CAL_CLIENT_RESULT_SUCCESS) { + if (itip_organizer_is_user (event->comp, client) && send_component_dialog (gtk_widget_get_toplevel (day_view), - day_view->client, event->comp, FALSE)) + client, event->comp, FALSE)) itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, event->comp, - day_view->client, NULL); + client, NULL); } else { g_message ("e_day_view_on_editing_stopped(): Could not update the object!"); } @@ -7606,6 +7407,9 @@ e_day_view_on_top_canvas_drag_data_received (GtkWidget *widget, struct icaltimetype itt; time_t dt; gboolean all_day_event; + CalClient *client; + + client = e_cal_view_get_cal_client (E_CAL_VIEW (day_view)); /* Note that we only support DnD within the EDayView at present. */ if ((data->length >= 0) && (data->format == 8) @@ -7706,24 +7510,24 @@ e_day_view_on_top_canvas_drag_data_received (GtkWidget *widget, CalObjModType mod; if (recur_component_dialog (comp, &mod, NULL)) { - if (cal_client_update_object_with_mod (day_view->client, comp, mod) == CAL_CLIENT_RESULT_SUCCESS) { - if (itip_organizer_is_user (comp, day_view->client) + if (cal_client_update_object_with_mod (client, comp, mod) == CAL_CLIENT_RESULT_SUCCESS) { + if (itip_organizer_is_user (comp, client) && send_component_dialog (gtk_widget_get_toplevel (day_view), - day_view->client, comp, FALSE)) + client, comp, FALSE)) itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, - day_view->client, NULL); + client, NULL); } else { g_message ("e_day_view_on_top_canvas_drag_data_received(): Could " "not update the object!"); } } - } else if (cal_client_update_object (day_view->client, comp) + } else if (cal_client_update_object (client, comp) == CAL_CLIENT_RESULT_SUCCESS) { - if (itip_organizer_is_user (comp, day_view->client) && + if (itip_organizer_is_user (comp, client) && send_component_dialog (gtk_widget_get_toplevel (day_view), - day_view->client, comp, FALSE)) + client, comp, FALSE)) itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, - day_view->client, NULL); + client, NULL); } else { g_message ("e_day_view_on_top_canvas_drag_data_received(): Could " "not update the object!"); @@ -7758,6 +7562,9 @@ e_day_view_on_main_canvas_drag_data_received (GtkWidget *widget, CalComponentDateTime date; struct icaltimetype itt; time_t dt; + CalClient *client; + + client = e_cal_view_get_cal_client (E_CAL_VIEW (day_view)); gnome_canvas_get_scroll_offsets (GNOME_CANVAS (widget), &scroll_x, &scroll_y); @@ -7837,24 +7644,23 @@ e_day_view_on_main_canvas_drag_data_received (GtkWidget *widget, CalObjModType mod; if (recur_component_dialog (comp, &mod, NULL)) { - if (cal_client_update_object_with_mod (day_view->client, comp, mod) == CAL_CLIENT_RESULT_SUCCESS) { - if (itip_organizer_is_user (comp, day_view->client) + if (cal_client_update_object_with_mod (client, comp, mod) == CAL_CLIENT_RESULT_SUCCESS) { + if (itip_organizer_is_user (comp, client) && send_component_dialog (gtk_widget_get_toplevel (day_view), - day_view->client, comp, FALSE)) + client, comp, FALSE)) itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, - day_view->client, NULL); + client, NULL); } else { g_message ("e_day_view_on_top_canvas_drag_data_received(): Could " "not update the object!"); } } - } else if (cal_client_update_object (day_view->client, comp) - == CAL_CLIENT_RESULT_SUCCESS) { - if (itip_organizer_is_user (comp, day_view->client) && + } else if (cal_client_update_object (client, comp) == CAL_CLIENT_RESULT_SUCCESS) { + if (itip_organizer_is_user (comp, client) && send_component_dialog (gtk_widget_get_toplevel (day_view), - day_view->client, comp, FALSE)) + client, comp, FALSE)) itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, - day_view->client, NULL); + client, NULL); } else { g_message ("e_day_view_on_main_canvas_drag_data_received(): " "Could not update the object!"); @@ -7916,139 +7722,6 @@ e_day_view_get_time_string_width (EDayView *day_view) return time_width; } -static void -selection_get (GtkWidget *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - EDayView *day_view) -{ - if (day_view->clipboard_selection != NULL) { - gtk_selection_data_set (selection_data, - GDK_SELECTION_TYPE_STRING, - 8, - day_view->clipboard_selection, - strlen (day_view->clipboard_selection)); - } -} - -static void -selection_clear_event (GtkWidget *invisible, - GdkEventSelection *event, - EDayView *day_view) -{ - if (day_view->clipboard_selection != NULL) { - g_free (day_view->clipboard_selection); - day_view->clipboard_selection = NULL; - } -} - -static void -selection_received (GtkWidget *invisible, - GtkSelectionData *selection_data, - guint time, - EDayView *day_view) -{ - char *comp_str; - icalcomponent *icalcomp; - time_t dtstart, dtend; - struct icaltimetype itime; - icalcomponent_kind kind; - CalComponent *comp; - char *uid; - time_t tt_start, tt_end; - struct icaldurationtype ic_dur; - - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - - 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; - } - - e_cal_view_set_status_message (E_CAL_VIEW (day_view), _("Updating objects")); - e_day_view_get_selected_time_range (day_view, &dtstart, &dtend); - - 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 || - child_kind == ICAL_VTODO_COMPONENT || - child_kind == ICAL_VJOURNAL_COMPONENT) { - tt_start = icaltime_as_timet (icalcomponent_get_dtstart (subcomp)); - tt_end = icaltime_as_timet (icalcomponent_get_dtend (subcomp)); - ic_dur = icaldurationtype_from_int (tt_end - tt_start); - itime = icaltime_from_timet_with_zone (dtstart, FALSE, day_view->zone); - - icalcomponent_set_dtstart (subcomp, itime); - itime = icaltime_add (itime, ic_dur); - icalcomponent_set_dtend (subcomp, itime); - - uid = cal_component_gen_uid (); - comp = cal_component_new (); - cal_component_set_icalcomponent ( - comp, icalcomponent_new_clone (subcomp)); - cal_component_set_uid (comp, uid); - - cal_client_update_object (day_view->client, comp); - - free (uid); - g_object_unref (comp); - - } - subcomp = icalcomponent_get_next_component ( - icalcomp, ICAL_ANY_COMPONENT); - } - } - else { - tt_start = icaltime_as_timet (icalcomponent_get_dtstart (icalcomp)); - tt_end = icaltime_as_timet (icalcomponent_get_dtend (icalcomp)); - ic_dur = icaldurationtype_from_int (tt_end - tt_start); - itime = icaltime_from_timet_with_zone (dtstart, FALSE, day_view->zone); - - icalcomponent_set_dtstart (icalcomp, itime); - itime = icaltime_add (itime, ic_dur); - icalcomponent_set_dtend (icalcomp, itime); - - comp = cal_component_new (); - cal_component_set_icalcomponent (comp, icalcomp); - - uid = cal_component_gen_uid (); - cal_component_set_uid (comp, (const char *) uid); - free (uid); - - cal_client_update_object (day_view->client, comp); - - if (itip_organizer_is_user (comp, day_view->client) && - send_component_dialog (gtk_widget_get_toplevel (day_view), day_view->client, comp, TRUE)) - itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, day_view->client, NULL); - - g_object_unref (comp); - } - - e_cal_view_set_status_message (E_CAL_VIEW (day_view), NULL); -} - - /* Gets the visible time range. Returns FALSE if no time range has been set. */ gboolean e_day_view_get_visible_time_range (EDayView *day_view, @@ -8110,23 +7783,4 @@ e_day_view_get_num_events_selected (EDayView *day_view) return (day_view->editing_event_day != -1) ? 1 : 0; } -/* Returns the currently-selected event, or NULL if none */ -CalComponent * -e_day_view_get_selected_event (EDayView *day_view) -{ - EDayViewEvent *event; - - g_return_val_if_fail (E_IS_DAY_VIEW (day_view), NULL); - g_return_val_if_fail (day_view->editing_event_day != -1, NULL); - if (day_view->editing_event_day == E_DAY_VIEW_LONG_EVENT) - event = &g_array_index (day_view->long_events, - EDayViewEvent, - day_view->editing_event_num); - else - event = &g_array_index (day_view->events[day_view->editing_event_day], - EDayViewEvent, - day_view->editing_event_num); - - return event ? event->comp : NULL; -} diff --git a/calendar/gui/e-day-view.h b/calendar/gui/e-day-view.h index 3bbf793ffb..dd95eba078 100644 --- a/calendar/gui/e-day-view.h +++ b/calendar/gui/e-day-view.h @@ -240,11 +240,7 @@ struct _EDayView GtkWidget *vscrollbar; - /* Calendar client object we are monitoring */ - CalClient *client; - /* S-expression for query and the query object */ - char *sexp; CalQuery *query; /* The start and end of the days shown. */ @@ -491,10 +487,6 @@ struct _EDayView gint am_string_width; gint pm_string_width; - /* the invisible widget to manage the clipboard selections */ - GtkWidget *invisible; - gchar *clipboard_selection; - /* The default category for new events */ char *default_category; @@ -511,28 +503,12 @@ struct _EDayViewClass GtkType e_day_view_get_type (void); GtkWidget* e_day_view_new (void); -void e_day_view_set_cal_client (EDayView *day_view, - CalClient *client); - void e_day_view_set_query (EDayView *day_view, const char *sexp); void e_day_view_set_default_category (EDayView *day_view, const char *category); -/* This sets the selected time range. The EDayView will show the day or week - corresponding to the start time. If the start_time & end_time are not equal - and are both visible in the view, then the selection is set to those times, - otherwise it is set to 1 hour from the start of the working day. */ -void e_day_view_set_selected_time_range (EDayView *day_view, - time_t start_time, - time_t end_time); - -/* Returns the selected time range. */ -void e_day_view_get_selected_time_range (EDayView *day_view, - time_t *start_time, - time_t *end_time); - /* Gets the visible time range. Returns FALSE if no time range has been set. */ gboolean e_day_view_get_visible_time_range (EDayView *day_view, time_t *start_time, diff --git a/calendar/gui/e-week-view.c b/calendar/gui/e-week-view.c index 8d3ef6a26f..d3573db107 100644 --- a/calendar/gui/e-week-view.c +++ b/calendar/gui/e-week-view.c @@ -33,7 +33,6 @@ #include #include -#include #include #include #include @@ -111,6 +110,10 @@ static gboolean e_week_view_get_next_tab_event (EWeekView *week_view, gint *next_span_num); static gboolean e_week_view_focus (GtkWidget *widget, GtkDirectionType direction); +static GList *e_week_view_get_selected_events (ECalView *cal_view); +static void e_week_view_get_selected_time_range (EWeekView *cal_view, time_t *start_time, time_t *end_time); +static void e_week_view_set_selected_time_range (EWeekView *cal_view, time_t start_time, time_t end_time); +static void e_week_view_update_query (EWeekView *week_view); static void e_week_view_draw_shadow (EWeekView *week_view); static gboolean e_week_view_on_button_press (GtkWidget *widget, @@ -222,25 +225,11 @@ static gboolean e_week_view_remove_event_cb (EWeekView *week_view, gpointer data); static gboolean e_week_view_recalc_display_start_day (EWeekView *week_view); -static void selection_get (GtkWidget *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - EWeekView *week_view); -static void selection_clear_event (GtkWidget *invisible, - GdkEventSelection *event, - EWeekView *week_view); -static void selection_received (GtkWidget *invisible, - GtkSelectionData *selection_data, - guint time, - EWeekView *week_view); - static void e_week_view_queue_layout (EWeekView *week_view); static void e_week_view_cancel_layout (EWeekView *week_view); static gboolean e_week_view_layout_timeout_cb (gpointer data); static ECalViewClass *parent_class; -static GdkAtom clipboard_atom = GDK_NONE; E_MAKE_TYPE (e_week_view, "EWeekView", EWeekView, e_week_view_class_init, e_week_view_init, e_cal_view_get_type ()); @@ -250,10 +239,12 @@ e_week_view_class_init (EWeekViewClass *class) { GtkObjectClass *object_class; GtkWidgetClass *widget_class; + ECalViewClass *view_class; parent_class = g_type_class_peek_parent (class); object_class = (GtkObjectClass *) class; widget_class = (GtkWidgetClass *) class; + view_class = (ECalViewClass *) class; /* Method override */ object_class->destroy = e_week_view_destroy; @@ -269,9 +260,10 @@ e_week_view_class_init (EWeekViewClass *class) widget_class->expose_event = e_week_view_expose_event; widget_class->focus = e_week_view_focus; - /* clipboard atom */ - if (!clipboard_atom) - clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE); + view_class->get_selected_events = e_week_view_get_selected_events; + view_class->get_selected_time_range = e_week_view_get_selected_time_range; + view_class->set_selected_time_range = e_week_view_set_selected_time_range; + view_class->update_query = e_week_view_update_query; } @@ -285,8 +277,6 @@ e_week_view_init (EWeekView *week_view) GTK_WIDGET_SET_FLAGS (week_view, GTK_CAN_FOCUS); - week_view->client = NULL; - week_view->sexp = g_strdup ("#t"); /* match all by default */ week_view->query = NULL; week_view->events = g_array_new (FALSE, FALSE, @@ -415,22 +405,6 @@ e_week_view_init (EWeekView *week_view) week_view->move_cursor = gdk_cursor_new (GDK_FLEUR); week_view->resize_width_cursor = gdk_cursor_new (GDK_SB_H_DOUBLE_ARROW); week_view->last_cursor_set = NULL; - - /* Set up the inivisible widget for the clipboard selections */ - week_view->invisible = gtk_invisible_new (); - gtk_selection_add_target (week_view->invisible, - clipboard_atom, - GDK_SELECTION_TYPE_STRING, - 0); - - g_signal_connect (week_view->invisible, "selection_get", - G_CALLBACK (selection_get), (gpointer) week_view); - g_signal_connect (week_view->invisible, "selection_clear_event", - G_CALLBACK (selection_clear_event), (gpointer) week_view); - g_signal_connect (week_view->invisible, "selection_received", - G_CALLBACK (selection_received), (gpointer) week_view); - - week_view->clipboard_selection = NULL; } @@ -466,15 +440,10 @@ e_week_view_destroy (GtkObject *object) week_view->events = NULL; } - if (week_view->client) { - g_signal_handlers_disconnect_matched (week_view->client, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, week_view); - g_object_unref (week_view->client); - week_view->client = NULL; - } - - if (week_view->sexp) { - g_free (week_view->sexp); - week_view->sexp = NULL; + if (e_cal_view_get_cal_client (E_CAL_VIEW (week_view))) { + g_signal_handlers_disconnect_matched ( + e_cal_view_get_cal_client (E_CAL_VIEW (week_view)), G_SIGNAL_MATCH_DATA, + 0, 0, NULL, NULL, week_view); } if (week_view->query) { @@ -506,15 +475,6 @@ e_week_view_destroy (GtkObject *object) gdk_cursor_unref (week_view->resize_width_cursor); week_view->resize_width_cursor = NULL; } - - if (week_view->invisible) { - gtk_widget_destroy (week_view->invisible); - week_view->invisible = NULL; - } - if (week_view->clipboard_selection) { - g_free (week_view->clipboard_selection); - week_view->clipboard_selection = NULL; - } GTK_OBJECT_CLASS (parent_class)->destroy (object); } @@ -1057,58 +1017,24 @@ e_week_view_focus (GtkWidget *widget, GtkDirectionType direction) return editable; } -static void -e_week_view_draw_shadow (EWeekView *week_view) +/* Returns the currently-selected event, or NULL if none */ +static GList * +e_week_view_get_selected_events (ECalView *cal_view) { - gint x1, y1, x2, y2; - GtkStyle *style; - GdkGC *light_gc, *dark_gc; - GdkWindow *window; - - /* Draw the shadow around the graphical displays. */ - x1 = week_view->main_canvas->allocation.x - 1; - y1 = week_view->main_canvas->allocation.y - 1; - x2 = x1 + week_view->main_canvas->allocation.width + 2; - y2 = y1 + week_view->main_canvas->allocation.height + 2; - - style = GTK_WIDGET (week_view)->style; - dark_gc = style->dark_gc[GTK_STATE_NORMAL]; - light_gc = style->light_gc[GTK_STATE_NORMAL]; + EWeekViewEvent *event; + GList *list = NULL; + EWeekView *week_view = (EWeekView *) cal_view; - window = GTK_WIDGET (week_view)->window; - gdk_draw_line (window, dark_gc, x1, y1, x1, y2); - gdk_draw_line (window, dark_gc, x1, y1, x2, y1); - gdk_draw_line (window, light_gc, x2, y1, x2, y2); - gdk_draw_line (window, light_gc, x1, y2, x2, y2); -} + g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), NULL); + g_return_val_if_fail (week_view->editing_event_num != -1, NULL); -static void -e_week_view_new_appointment (EWeekView *week_view, gboolean meeting) -{ - time_t dtstart, dtend; - struct icaltimetype itt; - gboolean all_day = FALSE; - - /* Edit a new event. If only one day is selected we set the time to - the first 1/2-hour of the working day. */ - if (week_view->selection_start_day == week_view->selection_end_day) { - dtstart = week_view->day_starts[week_view->selection_start_day]; - itt = icaltime_from_timet_with_zone (dtstart, FALSE, - week_view->zone); - itt.hour = calendar_config_get_day_start_hour (); - itt.minute = calendar_config_get_day_start_minute (); - dtstart = icaltime_as_timet_with_zone (itt, week_view->zone); + event = &g_array_index (week_view->events, EWeekViewEvent, + week_view->editing_event_num); - icaltime_adjust (&itt, 0, 0, 30, 0); - dtend = icaltime_as_timet_with_zone (itt, week_view->zone); - } else { - dtstart = week_view->day_starts[week_view->selection_start_day]; - dtend = week_view->day_starts[week_view->selection_end_day + 1]; - all_day = TRUE; - } + if (event) + list = g_list_prepend (list, event->comp); - gnome_calendar_new_appointment_for (e_cal_view_get_calendar (E_CAL_VIEW (week_view)), - dtstart, dtend, all_day, meeting); + return list; } /* Callback used when a component is updated in the live query */ @@ -1130,7 +1056,7 @@ query_obj_updated_cb (CalQuery *query, const char *uid, return; /* Get the event from the server. */ - status = cal_client_get_object (week_view->client, uid, &comp); + status = cal_client_get_object (e_cal_view_get_cal_client (E_CAL_VIEW (week_view)), uid, &comp); switch (status) { case CAL_CLIENT_GET_SUCCESS: @@ -1182,7 +1108,8 @@ query_obj_updated_cb (CalQuery *query, const char *uid, week_view->day_starts[0], week_view->day_starts[num_days], e_week_view_add_event, week_view, - cal_client_resolve_tzid_cb, week_view->client, + cal_client_resolve_tzid_cb, + e_cal_view_get_cal_client (E_CAL_VIEW (week_view)), week_view->zone); g_object_unref (comp); @@ -1274,7 +1201,7 @@ adjust_query_sexp (EWeekView *week_view, const char *sexp) /* Restarts a query for the week view */ static void -update_query (EWeekView *week_view) +e_week_view_update_query (EWeekView *week_view) { CalQuery *old_query; char *real_sexp; @@ -1283,10 +1210,6 @@ update_query (EWeekView *week_view) e_week_view_free_events (week_view); e_week_view_queue_layout (week_view); - if (!(week_view->client - && cal_client_get_load_state (week_view->client) == CAL_CLIENT_LOAD_LOADED)) - return; - old_query = week_view->query; week_view->query = NULL; @@ -1296,19 +1219,19 @@ update_query (EWeekView *week_view) g_object_unref (old_query); } - g_assert (week_view->sexp != NULL); + g_assert (e_cal_view_get_query (E_CAL_VIEW (week_view)) != NULL); - real_sexp = adjust_query_sexp (week_view, week_view->sexp); + real_sexp = adjust_query_sexp (week_view, e_cal_view_get_query (E_CAL_VIEW (week_view))); if (!real_sexp) { return; /* No time range is set, so don't start a query */ } e_cal_view_set_status_message (E_CAL_VIEW (week_view), _("Searching")); - week_view->query = cal_client_get_query (week_view->client, real_sexp); + week_view->query = cal_client_get_query (e_cal_view_get_cal_client (E_CAL_VIEW (week_view)), real_sexp); g_free (real_sexp); if (!week_view->query) { - g_message ("update_query(): Could not create the query"); + g_message ("e_week_view_update_query(): Could not create the query"); return; } @@ -1322,83 +1245,60 @@ update_query (EWeekView *week_view) G_CALLBACK (query_eval_error_cb), week_view); } -/* Callback used when the calendar client finishes opening */ static void -cal_opened_cb (CalClient *client, CalClientOpenStatus status, gpointer data) +e_week_view_draw_shadow (EWeekView *week_view) { - EWeekView *week_view; + gint x1, y1, x2, y2; + GtkStyle *style; + GdkGC *light_gc, *dark_gc; + GdkWindow *window; - week_view = E_WEEK_VIEW (data); + /* Draw the shadow around the graphical displays. */ + x1 = week_view->main_canvas->allocation.x - 1; + y1 = week_view->main_canvas->allocation.y - 1; + x2 = x1 + week_view->main_canvas->allocation.width + 2; + y2 = y1 + week_view->main_canvas->allocation.height + 2; - if (status != CAL_CLIENT_OPEN_SUCCESS) - return; + style = GTK_WIDGET (week_view)->style; + dark_gc = style->dark_gc[GTK_STATE_NORMAL]; + light_gc = style->light_gc[GTK_STATE_NORMAL]; - update_query (week_view); + window = GTK_WIDGET (week_view)->window; + gdk_draw_line (window, dark_gc, x1, y1, x1, y2); + gdk_draw_line (window, dark_gc, x1, y1, x2, y1); + gdk_draw_line (window, light_gc, x2, y1, x2, y2); + gdk_draw_line (window, light_gc, x1, y2, x2, y2); } -/** - * e_week_view_set_cal_client: - * @week_view: A week view. - * @client: A calendar client interface object. - * - * Sets the calendar client interface object that a week view will monitor. - **/ -void -e_week_view_set_cal_client (EWeekView *week_view, - CalClient *client) +static void +e_week_view_new_appointment (EWeekView *week_view, gboolean meeting) { - g_return_if_fail (week_view != NULL); - g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - - if (client == week_view->client) - return; - - if (client) - g_return_if_fail (IS_CAL_CLIENT (client)); - - if (client) - g_object_ref (client); - - if (week_view->client) { - g_signal_handlers_disconnect_matched (week_view->client, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, week_view); - g_object_unref (week_view->client); - } - - week_view->client = client; + time_t dtstart, dtend; + struct icaltimetype itt; + gboolean all_day = FALSE; + + /* Edit a new event. If only one day is selected we set the time to + the first 1/2-hour of the working day. */ + if (week_view->selection_start_day == week_view->selection_end_day) { + dtstart = week_view->day_starts[week_view->selection_start_day]; + itt = icaltime_from_timet_with_zone (dtstart, FALSE, + week_view->zone); + itt.hour = calendar_config_get_day_start_hour (); + itt.minute = calendar_config_get_day_start_minute (); + dtstart = icaltime_as_timet_with_zone (itt, week_view->zone); - if (week_view->client) { - if (cal_client_get_load_state (week_view->client) == CAL_CLIENT_LOAD_LOADED) - update_query (week_view); - else - g_signal_connect (week_view->client, "cal_opened", - G_CALLBACK (cal_opened_cb), week_view); + icaltime_adjust (&itt, 0, 0, 30, 0); + dtend = icaltime_as_timet_with_zone (itt, week_view->zone); + } else { + dtstart = week_view->day_starts[week_view->selection_start_day]; + dtend = week_view->day_starts[week_view->selection_end_day + 1]; + all_day = TRUE; } -} - -/** - * e_week_view_set_query: - * @week_view: A week view. - * @sexp: S-expression that defines the query. - * - * Sets the query sexp that the week view will use for filtering the displayed - * events. - **/ -void -e_week_view_set_query (EWeekView *week_view, const char *sexp) -{ - g_return_if_fail (week_view != NULL); - g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - g_return_if_fail (sexp != NULL); - - if (week_view->sexp) - g_free (week_view->sexp); - week_view->sexp = g_strdup (sexp); - - update_query (week_view); + gnome_calendar_new_appointment_for (e_cal_view_get_calendar (E_CAL_VIEW (week_view)), + dtstart, dtend, all_day, meeting); } - /** * e_week_view_set_default_category: * @week_view: A week view. @@ -1423,7 +1323,7 @@ e_week_view_set_default_category (EWeekView *week_view, const char *category) /* This sets the selected time range. The EWeekView will show the corresponding month and the days between start_time and end_time will be selected. To select a single day, use the same value for start_time & end_time. */ -void +static void e_week_view_set_selected_time_range (EWeekView *week_view, time_t start_time, time_t end_time) @@ -1487,7 +1387,7 @@ e_week_view_set_selected_time_range (EWeekView *week_view, start_time = time_day_begin_with_zone (start_time, week_view->zone); e_week_view_recalc_day_starts (week_view, start_time); - update_query (week_view); + e_week_view_update_query (week_view); } /* Set the selection to the given days. */ @@ -1560,7 +1460,7 @@ e_week_view_set_selected_time_range_visible (EWeekView *week_view, /* Returns the selected time range. */ -void +static void e_week_view_get_selected_time_range (EWeekView *week_view, time_t *start_time, time_t *end_time) @@ -1648,7 +1548,7 @@ e_week_view_set_first_day_shown (EWeekView *week_view, week_view->zone); e_week_view_recalc_day_starts (week_view, start_time); - update_query (week_view); + e_week_view_update_query (week_view); } /* Try to keep the previous selection, but if it is no longer shown @@ -1785,7 +1685,7 @@ e_week_view_set_weeks_shown (EWeekView *week_view, if (g_date_valid (&week_view->first_day_shown)) e_week_view_set_first_day_shown (week_view, &week_view->first_day_shown); - update_query (week_view); + e_week_view_update_query (week_view); } } @@ -1960,79 +1860,9 @@ e_week_view_set_timezone (EWeekView *week_view, lower = icaltime_as_timet_with_zone (tt, zone); e_week_view_recalc_day_starts (week_view, lower); - update_query (week_view); + e_week_view_update_query (week_view); } - -void -e_week_view_cut_clipboard (EWeekView *week_view) -{ - EWeekViewEvent *event; - const char *uid; - - g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - - if (week_view->editing_event_num == -1) - return; - - event = &g_array_index (week_view->events, EWeekViewEvent, - week_view->editing_event_num); - if (event == NULL) - return; - - e_cal_view_set_status_message (E_CAL_VIEW (week_view), _("Deleting selected objects")); - - e_week_view_copy_clipboard (week_view); - cal_component_get_uid (event->comp, &uid); - delete_error_dialog (cal_client_remove_object (week_view->client, uid), CAL_COMPONENT_EVENT); - - e_cal_view_set_status_message (E_CAL_VIEW (week_view), NULL); -} - -void -e_week_view_copy_clipboard (EWeekView *week_view) -{ - EWeekViewEvent *event; - char *comp_str; - icalcomponent *vcal_comp; - icalcomponent *new_icalcomp; - - g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - - event = &g_array_index (week_view->events, EWeekViewEvent, - week_view->editing_event_num); - if (event == NULL) - return; - - /* create top-level VCALENDAR component and add VTIMEZONE's */ - vcal_comp = cal_util_new_top_level (); - cal_util_add_timezones_from_component (vcal_comp, event->comp); - - new_icalcomp = icalcomponent_new_clone (cal_component_get_icalcomponent (event->comp)); - icalcomponent_add_component (vcal_comp, new_icalcomp); - - comp_str = icalcomponent_as_ical_string (vcal_comp); - if (week_view->clipboard_selection != NULL) - g_free (week_view->clipboard_selection); - week_view->clipboard_selection = g_strdup (comp_str); - gtk_selection_owner_set (week_view->invisible, clipboard_atom, GDK_CURRENT_TIME); - - /* free memory */ - icalcomponent_free (vcal_comp); -} - -void -e_week_view_paste_clipboard (EWeekView *week_view) -{ - g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - - gtk_selection_convert (week_view->invisible, - clipboard_atom, - GDK_SELECTION_TYPE_STRING, - GDK_CURRENT_TIME); -} - - static gboolean e_week_view_recalc_display_start_day (EWeekView *week_view) { @@ -2593,7 +2423,7 @@ e_week_view_add_event (CalComponent *comp, event.end_minute = 24 * 60; event.different_timezone = FALSE; - if (!cal_comp_util_compare_event_timezones (comp, week_view->client, + if (!cal_comp_util_compare_event_timezones (comp, e_cal_view_get_cal_client (E_CAL_VIEW (week_view)), week_view->zone)) event.different_timezone = TRUE; @@ -3016,7 +2846,7 @@ e_week_view_on_adjustment_changed (GtkAdjustment *adjustment, lower = icaltime_as_timet_with_zone (start_tt, week_view->zone); e_week_view_recalc_day_starts (week_view, lower); - update_query (week_view); + e_week_view_update_query (week_view); /* Update the selection, if needed. */ if (week_view->selection_start_day != -1) { @@ -3346,7 +3176,9 @@ e_week_view_on_editing_stopped (EWeekView *week_view, g_object_get (G_OBJECT (span->text_item), "text", &text, NULL); g_assert (text != NULL); - if (string_is_empty (text) && !cal_comp_is_on_server (event->comp, week_view->client)) { + if (string_is_empty (text) && + !cal_comp_is_on_server (event->comp, + e_cal_view_get_cal_client (E_CAL_VIEW (week_view)))) { const char *uid; cal_component_get_uid (event->comp, &uid); @@ -3365,30 +3197,33 @@ e_week_view_on_editing_stopped (EWeekView *week_view, e_week_view_reshape_event_span (week_view, event_num, span_num); } else if (summary.value || !string_is_empty (text)) { + CalClient *client; summary.value = text; summary.altrep = NULL; cal_component_set_summary (event->comp, &summary); + client = e_cal_view_get_cal_client (E_CAL_VIEW (week_view)); if (cal_component_is_instance (event->comp)) { CalObjModType mod; - + if (recur_component_dialog (event->comp, &mod, NULL)) { - if (cal_client_update_object_with_mod (week_view->client, event->comp, mod) == CAL_CLIENT_RESULT_SUCCESS) { - if (itip_organizer_is_user (event->comp, week_view->client) + if (cal_client_update_object_with_mod (client, event->comp, mod) + == CAL_CLIENT_RESULT_SUCCESS) { + if (itip_organizer_is_user (event->comp, client) && send_component_dialog (gtk_widget_get_toplevel (week_view), - week_view->client, event->comp, FALSE)) + client, event->comp, FALSE)) itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, event->comp, - week_view->client, NULL); + client, NULL); } else { g_message ("e_week_view_on_editing_stopped(): Could not update the object!"); } } - } else if (cal_client_update_object (week_view->client, event->comp) == CAL_CLIENT_RESULT_SUCCESS) { - if (itip_organizer_is_user (event->comp, week_view->client) && + } else if (cal_client_update_object (client, event->comp) == CAL_CLIENT_RESULT_SUCCESS) { + if (itip_organizer_is_user (event->comp, client) && send_component_dialog (gtk_widget_get_toplevel (week_view), - week_view->client, event->comp, FALSE)) + client, event->comp, FALSE)) itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, event->comp, - week_view->client, NULL); + client, NULL); } else { g_message ("e_week_view_on_editing_stopped(): Could not update the object!"); } @@ -3508,7 +3343,8 @@ e_week_view_do_key_press (GtkWidget *widget, GdkEventKey *event) week_view = E_WEEK_VIEW (widget); - if (cal_client_get_load_state (week_view->client) != CAL_CLIENT_LOAD_LOADED) + if (cal_client_get_load_state (e_cal_view_get_cal_client (E_CAL_VIEW (week_view))) + != CAL_CLIENT_LOAD_LOADED) return TRUE; /* The Escape key aborts a resize operation. */ @@ -3537,7 +3373,7 @@ e_week_view_do_key_press (GtkWidget *widget, GdkEventKey *event) initial_text = e_utf8_from_gtk_event_key (widget, event->keyval, event->string); /* Add a new event covering the selected range. */ - comp = cal_comp_event_new_with_defaults (week_view->client); + comp = cal_comp_event_new_with_defaults (e_cal_view_get_cal_client (E_CAL_VIEW (week_view))); dtstart = week_view->day_starts[week_view->selection_start_day]; dtend = week_view->day_starts[week_view->selection_end_day + 1]; @@ -3747,12 +3583,13 @@ e_week_view_show_popup_menu (EWeekView *week_view, if (cal_component_has_organizer (event->comp)) { disable_mask |= MASK_MEETING; - if (!itip_organizer_is_user (event->comp, week_view->client)) + if (!itip_organizer_is_user (event->comp, + e_cal_view_get_cal_client (E_CAL_VIEW (week_view)))) disable_mask |= MASK_MEETING_ORGANIZER; } } - if (cal_client_is_read_only (week_view->client)) + if (cal_client_is_read_only (e_cal_view_get_cal_client (E_CAL_VIEW (week_view)))) disable_mask |= MASK_EDITABLE; if (being_edited) @@ -3899,7 +3736,8 @@ e_week_view_on_save_as (GtkWidget *widget, gpointer data) if (filename == NULL) return; - ical_string = cal_client_get_component_as_string (week_view->client, event->comp); + ical_string = cal_client_get_component_as_string (e_cal_view_get_cal_client (E_CAL_VIEW (week_view)), + event->comp); if (ical_string == NULL) { g_warning ("Couldn't convert item to a string"); return; @@ -3930,7 +3768,7 @@ e_week_view_on_print_event (GtkWidget *widget, gpointer data) event = &g_array_index (week_view->events, EWeekViewEvent, week_view->popup_event_num); - print_comp (event->comp, week_view->client, FALSE); + print_comp (event->comp, e_cal_view_get_cal_client (E_CAL_VIEW (week_view)), FALSE); } static void @@ -3970,7 +3808,7 @@ e_week_view_on_forward (GtkWidget *widget, gpointer data) week_view->popup_event_num); itip_send_comp (CAL_COMPONENT_METHOD_PUBLISH, event->comp, - week_view->client, NULL); + e_cal_view_get_cal_client (E_CAL_VIEW (week_view)), NULL); } static void @@ -3987,14 +3825,15 @@ e_week_view_on_publish (GtkWidget *widget, gpointer data) start = time_day_begin_with_zone (start, utc); end = time_add_week_with_zone (start, 6, utc); - comp_list = cal_client_get_free_busy (week_view->client, NULL, start, end); + comp_list = cal_client_get_free_busy (e_cal_view_get_cal_client (E_CAL_VIEW (week_view)), NULL, + start, end); if (comp_list) { GList *l; for (l = comp_list; l; l = l->next) { CalComponent *comp = CAL_COMPONENT (l->data); itip_send_comp (CAL_COMPONENT_METHOD_PUBLISH, comp, - week_view->client, NULL); + e_cal_view_get_cal_client (E_CAL_VIEW (week_view)), NULL); g_object_unref (comp); } @@ -4028,14 +3867,19 @@ e_week_view_delete_event_internal (EWeekView *week_view, gint event_num) GTK_WIDGET (week_view))) { const char *uid; - if (itip_organizer_is_user (event->comp, week_view->client) + if (itip_organizer_is_user (event->comp, + e_cal_view_get_cal_client (E_CAL_VIEW (week_view))) && cancel_component_dialog ((GtkWindow *) gtk_widget_get_toplevel (week_view), - week_view->client, event->comp, TRUE)) - itip_send_comp (CAL_COMPONENT_METHOD_CANCEL, event->comp, week_view->client, NULL); + e_cal_view_get_cal_client (E_CAL_VIEW (week_view)), + event->comp, TRUE)) + itip_send_comp (CAL_COMPONENT_METHOD_CANCEL, event->comp, + e_cal_view_get_cal_client (E_CAL_VIEW (week_view)), NULL); cal_component_get_uid (event->comp, &uid); - delete_error_dialog (cal_client_remove_object (week_view->client, uid), CAL_COMPONENT_EVENT); + delete_error_dialog ( + cal_client_remove_object (e_cal_view_get_cal_client (E_CAL_VIEW (week_view)), + uid), CAL_COMPONENT_EVENT); } } @@ -4081,7 +3925,9 @@ e_week_view_delete_occurrence_internal (EWeekView *week_view, gint event_num) const char *uid; cal_component_get_uid (event->comp, &uid); - delete_error_dialog (cal_client_remove_object_with_mod (week_view->client, uid, CALOBJ_MOD_THIS), + delete_error_dialog (cal_client_remove_object_with_mod ( + e_cal_view_get_cal_client (E_CAL_VIEW (week_view)), + uid, CALOBJ_MOD_THIS), CAL_COMPONENT_EVENT); return; } @@ -4092,7 +3938,8 @@ e_week_view_delete_occurrence_internal (EWeekView *week_view, gint event_num) comp = cal_component_clone (event->comp); cal_comp_util_add_exdate (comp, event->start, week_view->zone); - if (cal_client_update_object (week_view->client, comp) != CAL_CLIENT_RESULT_SUCCESS) + if (cal_client_update_object (e_cal_view_get_cal_client (E_CAL_VIEW (week_view)), comp) + != CAL_CLIENT_RESULT_SUCCESS) g_message ("e_week_view_on_delete_occurrence(): Could not update the object!"); g_object_unref (comp); @@ -4125,62 +3972,17 @@ e_week_view_delete_occurrence (EWeekView *week_view) static void e_week_view_on_cut (GtkWidget *widget, gpointer data) { - EWeekView *week_view; - EWeekViewEvent *event; - const char *uid; - - week_view = E_WEEK_VIEW (data); + EWeekView *week_view = E_WEEK_VIEW (data); - e_week_view_on_copy (widget, data); - - if (week_view->popup_event_num == -1) - return; - - event = &g_array_index (week_view->events, EWeekViewEvent, - week_view->popup_event_num); - - if (itip_organizer_is_user (event->comp, week_view->client) - && cancel_component_dialog ((GtkWindow *) gtk_widget_get_toplevel (week_view), - week_view->client, event->comp, TRUE)) - itip_send_comp (CAL_COMPONENT_METHOD_CANCEL, event->comp, week_view->client, NULL); - - cal_component_get_uid (event->comp, &uid); - delete_error_dialog (cal_client_remove_object (week_view->client, uid), CAL_COMPONENT_EVENT); + e_cal_view_cut_clipboard (E_CAL_VIEW (week_view)); } static void e_week_view_on_copy (GtkWidget *widget, gpointer data) { - EWeekView *week_view; - EWeekViewEvent *event; - char *comp_str; - icalcomponent *vcal_comp; - icalcomponent *new_icalcomp; - - week_view = E_WEEK_VIEW (data); - - if (week_view->popup_event_num == -1) - return; - - event = &g_array_index (week_view->events, EWeekViewEvent, - week_view->popup_event_num); - - /* create top-level VCALENDAR component and add VTIMEZONE's */ - vcal_comp = cal_util_new_top_level (); - cal_util_add_timezones_from_component (vcal_comp, event->comp); - - new_icalcomp = icalcomponent_new_clone (cal_component_get_icalcomponent (event->comp)); - icalcomponent_add_component (vcal_comp, new_icalcomp); - - comp_str = icalcomponent_as_ical_string (vcal_comp); - if (week_view->clipboard_selection) - g_free (week_view->clipboard_selection); - week_view->clipboard_selection = g_strdup (comp_str); - - gtk_selection_owner_set (week_view->invisible, clipboard_atom, GDK_CURRENT_TIME); + EWeekView *week_view = E_WEEK_VIEW (data); - /* free memory */ - icalcomponent_free (vcal_comp); + e_cal_view_copy_clipboard (E_CAL_VIEW (week_view)); } static void @@ -4188,10 +3990,7 @@ e_week_view_on_paste (GtkWidget *widget, gpointer data) { EWeekView *week_view = E_WEEK_VIEW (data); - gtk_selection_convert (week_view->invisible, - clipboard_atom, - GDK_SELECTION_TYPE_STRING, - GDK_CURRENT_TIME); + e_cal_view_paste_clipboard (E_CAL_VIEW (week_view)); } static void @@ -4239,12 +4038,14 @@ e_week_view_on_unrecur_appointment (GtkWidget *widget, gpointer data) /* Now update both CalComponents. Note that we do this last since at present the updates happen synchronously so our event may disappear. */ - if (cal_client_update_object (week_view->client, comp) != CAL_CLIENT_RESULT_SUCCESS) + if (cal_client_update_object (e_cal_view_get_cal_client (E_CAL_VIEW (week_view)), comp) + != CAL_CLIENT_RESULT_SUCCESS) g_message ("e_week_view_on_unrecur_appointment(): Could not update the object!"); g_object_unref (comp); - if (cal_client_update_object (week_view->client, new_comp) != CAL_CLIENT_RESULT_SUCCESS) + if (cal_client_update_object (e_cal_view_get_cal_client (E_CAL_VIEW (week_view)), new_comp) + != CAL_CLIENT_RESULT_SUCCESS) g_message ("e_week_view_on_unrecur_appointment(): Could not update the object!"); g_object_unref (new_comp); @@ -4331,170 +4132,6 @@ e_week_view_get_time_string_width (EWeekView *week_view) return time_width; } -static void -selection_get (GtkWidget *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - EWeekView *week_view) -{ - if (week_view->clipboard_selection != NULL) { - gtk_selection_data_set (selection_data, - GDK_SELECTION_TYPE_STRING, - 8, - week_view->clipboard_selection, - strlen (week_view->clipboard_selection)); - } -} - -static void -selection_clear_event (GtkWidget *invisible, - GdkEventSelection *event, - EWeekView *week_view) -{ - if (week_view->clipboard_selection != NULL) { - g_free (week_view->clipboard_selection); - week_view->clipboard_selection = NULL; - } -} - -static void -selection_received (GtkWidget *invisible, - GtkSelectionData *selection_data, - guint time, - EWeekView *week_view) -{ - char *comp_str; - icalcomponent *icalcomp; - icalcomponent_kind kind; - CalComponent *comp; - time_t selected_time; - struct icaltimetype itime; - struct icaltimetype tmp_itime; - time_t tt_start, tt_end; - struct icaldurationtype ic_dur; - char *uid; - CalComponentDateTime ccdt; - - g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - - 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; - } - - e_cal_view_set_status_message (E_CAL_VIEW (week_view), _("Updating objects")); - selected_time = week_view->day_starts[week_view->selection_start_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 || - child_kind == ICAL_VTODO_COMPONENT || - child_kind == ICAL_VJOURNAL_COMPONENT) { - icalcomponent *new_icalcomp; - - new_icalcomp = icalcomponent_new_clone (subcomp); - comp = cal_component_new (); - - /* change the day for the event */ - tt_start = icaltime_as_timet ( - icalcomponent_get_dtstart (new_icalcomp)); - tt_end = icaltime_as_timet ( - icalcomponent_get_dtend (new_icalcomp)); - ic_dur = icaldurationtype_from_int (tt_end - tt_start); - - tmp_itime = icaltime_from_timet_with_zone ( - selected_time, FALSE, week_view->zone); - itime = icalcomponent_get_dtstart (new_icalcomp); - itime.year = tmp_itime.year; - itime.month = tmp_itime.month; - itime.day = tmp_itime.day; - - cal_component_set_icalcomponent (comp, new_icalcomp); - ccdt.value = &itime; - ccdt.tzid = icaltimezone_get_tzid (week_view->zone); - cal_component_set_dtstart (comp, &ccdt); - - itime = icaltime_add (itime, ic_dur); - ccdt.value = &itime; - cal_component_set_dtend (comp, &ccdt); - - uid = cal_component_gen_uid (); - cal_component_set_uid (comp, uid); - - cal_client_update_object (week_view->client, comp); - - g_free (uid); - g_object_unref (comp); - } - subcomp = icalcomponent_get_next_component ( - icalcomp, ICAL_ANY_COMPONENT); - } - - icalcomponent_free (icalcomp); - - } - else { - comp = cal_component_new (); - - /* change the day for the event */ - tt_start = icaltime_as_timet (icalcomponent_get_dtstart (icalcomp)); - tt_end = icaltime_as_timet (icalcomponent_get_dtend (icalcomp)); - ic_dur = icaldurationtype_from_int (tt_end - tt_start); - - tmp_itime = icaltime_from_timet_with_zone ( - selected_time, FALSE, week_view->zone); - itime = icalcomponent_get_dtstart (icalcomp); - itime.year = tmp_itime.year; - itime.month = tmp_itime.month; - itime.day = tmp_itime.day; - - cal_component_set_icalcomponent (comp, icalcomp); - ccdt.value = &itime; - ccdt.tzid = icaltimezone_get_tzid (week_view->zone); - cal_component_set_dtstart (comp, &ccdt); - - itime = icaltime_add (itime, ic_dur); - ccdt.value = &itime; - cal_component_set_dtend (comp, &ccdt); - - uid = cal_component_gen_uid (); - cal_component_set_uid (comp, (const char *) uid); - - cal_client_update_object (week_view->client, comp); - - if (itip_organizer_is_user (comp, week_view->client) && - send_component_dialog (gtk_widget_get_toplevel (week_view), week_view->client, comp, TRUE)) - itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, week_view->client, NULL); - - g_free (uid); - g_object_unref (comp); - } - - e_cal_view_set_status_message (E_CAL_VIEW (week_view), NULL); -} - - /* Gets the visible time range. Returns FALSE if no time range has been set. */ gboolean e_week_view_get_visible_time_range (EWeekView *week_view, @@ -4558,18 +4195,4 @@ e_week_view_get_num_events_selected (EWeekView *week_view) return (week_view->editing_event_num != -1) ? 1 : 0; } -/* Returns the currently-selected event, or NULL if none */ -CalComponent * -e_week_view_get_selected_event (EWeekView *week_view) -{ - EWeekViewEvent *event; - - g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), NULL); - g_return_val_if_fail (week_view->editing_event_num != -1, NULL); - - event = &g_array_index (week_view->events, EWeekViewEvent, - week_view->editing_event_num); - - return event ? event->comp : NULL; -} diff --git a/calendar/gui/e-week-view.h b/calendar/gui/e-week-view.h index 0fdbbf6cdd..7b3d85711b 100644 --- a/calendar/gui/e-week-view.h +++ b/calendar/gui/e-week-view.h @@ -192,11 +192,7 @@ struct _EWeekView GtkWidget *vscrollbar; - /* Calendar client object we are monitoring */ - CalClient *client; - - /* S-expression for query and the query object */ - char *sexp; + /* The query object */ CalQuery *query; /* The array of EWeekViewEvent elements. */ @@ -358,10 +354,6 @@ struct _EWeekView gint am_string_width; gint pm_string_width; - /* the invisible widget to manage the clipboard selections */ - GtkWidget *invisible; - gchar *clipboard_selection; - /* The default category for new events */ char *default_category; }; @@ -375,9 +367,6 @@ struct _EWeekViewClass GtkType e_week_view_get_type (void); GtkWidget* e_week_view_new (void); -void e_week_view_set_calendar (EWeekView *week_view, - GnomeCalendar *calendar); - /* The first day shown. Note that it will be rounded down to the start of a week when set. The returned value will be invalid if no date has been set yet. */ @@ -386,25 +375,12 @@ void e_week_view_get_first_day_shown (EWeekView *week_view, void e_week_view_set_first_day_shown (EWeekView *week_view, GDate *date); -void e_week_view_set_cal_client (EWeekView *week_view, - CalClient *client); - -void e_week_view_set_query (EWeekView *week_view, - const char *sexp); - void e_week_view_set_default_category (EWeekView *week_view, const char *category); /* The selected time range. The EWeekView will show the corresponding month and the days between start_time and end_time will be selected. To select a single day, use the same value for start_time & end_time. */ -void e_week_view_get_selected_time_range (EWeekView *week_view, - time_t *start_time, - time_t *end_time); -void e_week_view_set_selected_time_range (EWeekView *week_view, - time_t start_time, - time_t end_time); - void e_week_view_set_selected_time_range_visible (EWeekView *week_view, time_t start_time, time_t end_time); diff --git a/calendar/gui/gnome-cal.c b/calendar/gui/gnome-cal.c index d8bcff310c..a144b77ef5 100644 --- a/calendar/gui/gnome-cal.c +++ b/calendar/gui/gnome-cal.c @@ -665,28 +665,7 @@ gnome_calendar_set_query (GnomeCalendar *gcal, const char *sexp) update_query (gcal); /* Set the query on the main view */ - - switch (priv->current_view_type) { - case GNOME_CAL_DAY_VIEW: - e_day_view_set_query (E_DAY_VIEW (priv->day_view), sexp); - break; - - case GNOME_CAL_WORK_WEEK_VIEW: - e_day_view_set_query (E_DAY_VIEW (priv->work_week_view), sexp); - break; - - case GNOME_CAL_WEEK_VIEW: - e_week_view_set_query (E_WEEK_VIEW (priv->week_view), sexp); - break; - - case GNOME_CAL_MONTH_VIEW: - e_week_view_set_query (E_WEEK_VIEW (priv->month_view), sexp); - break; - - default: - g_warning ("A penguin bit my hand!"); - g_assert_not_reached (); - } + e_cal_view_set_query (E_CAL_VIEW (gnome_calendar_get_current_view_widget (gcal)), sexp); /* Set the query on the task pad */ @@ -1211,35 +1190,9 @@ gnome_calendar_update_view_times (GnomeCalendar *gcal) priv = gcal->priv; - switch (priv->current_view_type) { - case GNOME_CAL_DAY_VIEW: - e_day_view_set_selected_time_range (E_DAY_VIEW (priv->day_view), - priv->selection_start_time, - priv->selection_end_time); - break; - - case GNOME_CAL_WORK_WEEK_VIEW: - e_day_view_set_selected_time_range (E_DAY_VIEW (priv->work_week_view), - priv->selection_start_time, - priv->selection_end_time); - break; - - case GNOME_CAL_WEEK_VIEW: - e_week_view_set_selected_time_range (E_WEEK_VIEW (priv->week_view), - priv->selection_start_time, - priv->selection_end_time); - break; - - case GNOME_CAL_MONTH_VIEW: - e_week_view_set_selected_time_range (E_WEEK_VIEW (priv->month_view), - priv->selection_start_time, - priv->selection_end_time); - break; - - default: - g_warning ("My penguin is gone!"); - g_assert_not_reached (); - } + e_cal_view_set_selected_time_range (E_CAL_VIEW (gnome_calendar_get_current_view_widget (gcal)), + priv->selection_start_time, + priv->selection_end_time); } static void @@ -2002,14 +1955,10 @@ gnome_calendar_construct (GnomeCalendar *gcal) g_signal_connect (priv->client, "backend_died", G_CALLBACK (backend_died_cb), gcal); - e_day_view_set_cal_client (E_DAY_VIEW (priv->day_view), - priv->client); - e_day_view_set_cal_client (E_DAY_VIEW (priv->work_week_view), - priv->client); - e_week_view_set_cal_client (E_WEEK_VIEW (priv->week_view), - priv->client); - e_week_view_set_cal_client (E_WEEK_VIEW (priv->month_view), - priv->client); + e_cal_view_set_cal_client (E_CAL_VIEW (priv->day_view), priv->client); + e_cal_view_set_cal_client (E_CAL_VIEW (priv->work_week_view), priv->client); + e_cal_view_set_cal_client (E_CAL_VIEW (priv->week_view), priv->client); + e_cal_view_set_cal_client (E_CAL_VIEW (priv->month_view), priv->client); /* * TaskPad Folder Client. @@ -2587,31 +2536,8 @@ gnome_calendar_get_current_time_range (GnomeCalendar *gcal, priv = gcal->priv; - switch (priv->current_view_type) { - case GNOME_CAL_DAY_VIEW: - e_day_view_get_selected_time_range (E_DAY_VIEW (priv->day_view), - start_time, end_time); - break; - - case GNOME_CAL_WORK_WEEK_VIEW: - e_day_view_get_selected_time_range (E_DAY_VIEW (priv->work_week_view), - start_time, end_time); - break; - - case GNOME_CAL_WEEK_VIEW: - e_week_view_get_selected_time_range (E_WEEK_VIEW (priv->week_view), - start_time, end_time); - break; - - case GNOME_CAL_MONTH_VIEW: - e_week_view_get_selected_time_range (E_WEEK_VIEW (priv->month_view), - start_time, end_time); - break; - - default: - g_message ("My penguin is gone!"); - g_assert_not_reached (); - } + e_cal_view_get_selected_time_range (E_CAL_VIEW (gnome_calendar_get_current_view_widget (gcal)), + start_time, end_time); } -- cgit