From d6e71d2ad96d9929f9b5053f1f730ca3628c20a2 Mon Sep 17 00:00:00 2001 From: JP Rosevear Date: Mon, 22 Oct 2001 03:51:41 +0000 Subject: listen for changes in the date editors (schedule_page_set_dates): update 2001-10-21 JP Rosevear * gui/dialogs/schedule-page.c (init_widgets): listen for changes in the date editors (schedule_page_set_dates): update the times when they change elsewhere (update_time): set the time in the dialog (time_changed_cb): notify of changed times * gui/dialogs/comp-editor.c (page_dates_changed_cb): don't call the set dates function on the page that noted the change (page_summary_changed_cb): same for set summary function * gui/dialogs/event-page.c (update_time): move time setting stuff to util function (event_page_set_dates): use it (event_page_fill_component): ditto * gui/e-meeting-time-sel.h: fix comment svn path=/trunk/; revision=13863 --- calendar/gui/dialogs/comp-editor.c | 22 ++--- calendar/gui/dialogs/event-page.c | 152 +++++++++++++++++++---------------- calendar/gui/dialogs/schedule-page.c | 149 +++++++++++++++++++++++++++++++++- 3 files changed, 240 insertions(+), 83 deletions(-) (limited to 'calendar/gui/dialogs') diff --git a/calendar/gui/dialogs/comp-editor.c b/calendar/gui/dialogs/comp-editor.c index 46b60e56e9..372614b9f2 100644 --- a/calendar/gui/dialogs/comp-editor.c +++ b/calendar/gui/dialogs/comp-editor.c @@ -83,10 +83,10 @@ static void real_send_comp (CompEditor *editor, CalComponentItipMethod method); static void delete_comp (CompEditor *editor); static void close_dialog (CompEditor *editor); -static void page_changed_cb (GtkWidget *widget, gpointer data); -static void page_needs_send_cb (GtkWidget *widget, gpointer data); -static void page_summary_changed_cb (GtkWidget *widget, const char *summary, gpointer data); -static void page_dates_changed_cb (GtkWidget *widget, CompEditorPageDates *dates, gpointer data); +static void page_changed_cb (GtkObject *obj, gpointer data); +static void page_needs_send_cb (GtkObject *obj, gpointer data); +static void page_summary_changed_cb (GtkObject *obj, const char *summary, gpointer data); +static void page_dates_changed_cb (GtkObject *obj, CompEditorPageDates *dates, gpointer data); static void obj_updated_cb (CalClient *client, const char *uid, gpointer data); static void obj_removed_cb (CalClient *client, const char *uid, gpointer data); @@ -1147,7 +1147,7 @@ close_cmd (GtkWidget *widget, gpointer data) } static void -page_changed_cb (GtkWidget *widget, gpointer data) +page_changed_cb (GtkObject *obj, gpointer data) { CompEditor *editor = COMP_EDITOR (data); CompEditorPrivate *priv; @@ -1158,7 +1158,7 @@ page_changed_cb (GtkWidget *widget, gpointer data) } static void -page_needs_send_cb (GtkWidget *widget, gpointer data) +page_needs_send_cb (GtkObject *obj, gpointer data) { CompEditor *editor = COMP_EDITOR (data); CompEditorPrivate *priv; @@ -1170,7 +1170,7 @@ page_needs_send_cb (GtkWidget *widget, gpointer data) /* Page signal callbacks */ static void -page_summary_changed_cb (GtkWidget *widget, const char *summary, gpointer data) +page_summary_changed_cb (GtkObject *obj, const char *summary, gpointer data) { CompEditor *editor = COMP_EDITOR (data); CompEditorPrivate *priv; @@ -1179,13 +1179,14 @@ page_summary_changed_cb (GtkWidget *widget, const char *summary, gpointer data) priv = editor->priv; for (l = priv->pages; l != NULL; l = l->next) - comp_editor_page_set_summary (l->data, summary); + if (obj != l->data) + comp_editor_page_set_summary (l->data, summary); priv->changed = TRUE; } static void -page_dates_changed_cb (GtkWidget *widget, +page_dates_changed_cb (GtkObject *obj, CompEditorPageDates *dates, gpointer data) { @@ -1196,7 +1197,8 @@ page_dates_changed_cb (GtkWidget *widget, priv = editor->priv; for (l = priv->pages; l != NULL; l = l->next) - comp_editor_page_set_dates (l->data, dates); + if (obj != l->data) + comp_editor_page_set_dates (l->data, dates); priv->changed = TRUE; } diff --git a/calendar/gui/dialogs/event-page.c b/calendar/gui/dialogs/event-page.c index c57a849a24..a3c8041933 100644 --- a/calendar/gui/dialogs/event-page.c +++ b/calendar/gui/dialogs/event-page.c @@ -311,6 +311,81 @@ check_all_day (EventPage *epage) } } +static void +update_time (EventPage *epage, CalComponentDateTime *start_date, CalComponentDateTime *end_date) +{ + EventPagePrivate *priv; + struct icaltimetype *start_tt, *end_tt; + icaltimezone *start_zone = NULL, *end_zone = NULL; + CalClientGetStatus status; + + priv = epage->priv; + + /* Note that if we are creating a new event, the timezones may not be + on the server, so we try to get the builtin timezone with the TZID + first. */ + start_zone = icaltimezone_get_builtin_timezone_from_tzid (start_date->tzid); + if (!start_zone) { + status = cal_client_get_timezone (COMP_EDITOR_PAGE (epage)->client, + start_date->tzid, + &start_zone); + /* FIXME: Handle error better. */ + if (status != CAL_CLIENT_GET_SUCCESS) + g_warning ("Couldn't get timezone from server: %s", + start_date->tzid ? start_date->tzid : ""); + } + + end_zone = icaltimezone_get_builtin_timezone_from_tzid (end_date->tzid); + if (!end_zone) { + status = cal_client_get_timezone (COMP_EDITOR_PAGE (epage)->client, + end_date->tzid, + &end_zone); + /* FIXME: Handle error better. */ + if (status != CAL_CLIENT_GET_SUCCESS) + g_warning ("Couldn't get timezone from server: %s", + end_date->tzid ? end_date->tzid : ""); + } + + /* All-day events are inclusive, i.e. if the end date shown is 2nd Feb + then the event includes all of the 2nd Feb. We would normally show + 3rd Feb as the end date, since it really ends at midnight on 3rd, + so we have to subtract a day so we only show the 2nd. */ + start_tt = start_date->value; + end_tt = end_date->value; + if (start_tt->hour == 0 && start_tt->minute == 0 && start_tt->second == 0 + && end_tt->hour == 0 && end_tt->minute == 0 && end_tt->second == 0) + icaltime_adjust (end_tt, -1, 0, 0, 0); + + gtk_signal_handler_block_by_data (GTK_OBJECT (priv->start_time), + epage); + gtk_signal_handler_block_by_data (GTK_OBJECT (priv->end_time), epage); + + e_date_edit_set_date (E_DATE_EDIT (priv->start_time), start_tt->year, + start_tt->month, start_tt->day); + e_date_edit_set_time_of_day (E_DATE_EDIT (priv->start_time), + start_tt->hour, start_tt->minute); + + e_date_edit_set_date (E_DATE_EDIT (priv->end_time), end_tt->year, + end_tt->month, end_tt->day); + e_date_edit_set_time_of_day (E_DATE_EDIT (priv->end_time), + end_tt->hour, end_tt->minute); + + gtk_signal_handler_unblock_by_data (GTK_OBJECT (priv->start_time), + epage); + gtk_signal_handler_unblock_by_data (GTK_OBJECT (priv->end_time), + epage); + + /* Set the timezones, and set sync_timezones to TRUE if both timezones + are the same. */ + if (start_zone && end_zone) { + e_timezone_entry_set_timezone (E_TIMEZONE_ENTRY (priv->start_timezone), + start_zone); + e_timezone_entry_set_timezone (E_TIMEZONE_ENTRY (priv->end_timezone), + end_zone); + priv->sync_timezones = (start_zone == end_zone) ? TRUE : FALSE; + } +} + /* Fills the widgets with default values */ static void clear_widgets (EventPage *epage) @@ -381,11 +456,8 @@ event_page_fill_widgets (CompEditorPage *page, CalComponent *comp) CalComponentClassification cl; CalComponentTransparency transparency; CalComponentDateTime start_date, end_date; - GSList *l; const char *categories; - CalClientGetStatus status; - struct icaltimetype *start_tt, *end_tt; - icaltimezone *start_zone = NULL, *end_zone = NULL; + GSList *l; g_return_if_fail (page->client != NULL); @@ -413,76 +485,14 @@ event_page_fill_widgets (CompEditorPage *page, CalComponent *comp) /* Start and end times */ cal_component_get_dtstart (comp, &start_date); - - /* Note that if we are creating a new event, the timezones may not be - on the server, so we try to get the builtin timezone with the TZID - first. */ - start_zone = icaltimezone_get_builtin_timezone_from_tzid (start_date.tzid); - if (!start_zone) { - status = cal_client_get_timezone (page->client, - start_date.tzid, - &start_zone); - /* FIXME: Handle error better. */ - if (status != CAL_CLIENT_GET_SUCCESS) - g_warning ("Couldn't get timezone from server: %s", - start_date.tzid ? start_date.tzid : ""); - } - cal_component_get_dtend (comp, &end_date); - end_zone = icaltimezone_get_builtin_timezone_from_tzid (end_date.tzid); - if (!end_zone) { - status = cal_client_get_timezone (page->client, - end_date.tzid, - &end_zone); - /* FIXME: Handle error better. */ - if (status != CAL_CLIENT_GET_SUCCESS) - g_warning ("Couldn't get timezone from server: %s", - end_date.tzid ? end_date.tzid : ""); - } - - /* All-day events are inclusive, i.e. if the end date shown is 2nd Feb - then the event includes all of the 2nd Feb. We would normally show - 3rd Feb as the end date, since it really ends at midnight on 3rd, - so we have to subtract a day so we only show the 2nd. */ - start_tt = start_date.value; - end_tt = end_date.value; - if (start_tt->hour == 0 && start_tt->minute == 0 && start_tt->second == 0 - && end_tt->hour == 0 && end_tt->minute == 0 && end_tt->second == 0) - icaltime_adjust (end_tt, -1, 0, 0, 0); - - gtk_signal_handler_block_by_data (GTK_OBJECT (priv->start_time), - epage); - gtk_signal_handler_block_by_data (GTK_OBJECT (priv->end_time), epage); - - e_date_edit_set_date (E_DATE_EDIT (priv->start_time), start_tt->year, - start_tt->month, start_tt->day); - e_date_edit_set_time_of_day (E_DATE_EDIT (priv->start_time), - start_tt->hour, start_tt->minute); - - e_date_edit_set_date (E_DATE_EDIT (priv->end_time), end_tt->year, - end_tt->month, end_tt->day); - e_date_edit_set_time_of_day (E_DATE_EDIT (priv->end_time), - end_tt->hour, end_tt->minute); - - gtk_signal_handler_unblock_by_data (GTK_OBJECT (priv->start_time), - epage); - gtk_signal_handler_unblock_by_data (GTK_OBJECT (priv->end_time), - epage); - + update_time (epage, &start_date, &end_date); + cal_component_free_datetime (&start_date); cal_component_free_datetime (&end_date); check_all_day (epage); - /* Set the timezones, and set sync_timezones to TRUE if both timezones - are the same. */ - e_timezone_entry_set_timezone (E_TIMEZONE_ENTRY (priv->start_timezone), - start_zone); - e_timezone_entry_set_timezone (E_TIMEZONE_ENTRY (priv->end_timezone), - end_zone); - priv->sync_timezones = (start_zone == end_zone) ? TRUE : FALSE; - - /* Classification */ cal_component_get_classification (comp, &cl); @@ -697,8 +707,8 @@ event_page_set_summary (CompEditorPage *page, const char *summary) static void event_page_set_dates (CompEditorPage *page, CompEditorPageDates *dates) -{ - /* nothing */ +{ + update_time (EVENT_PAGE (page), dates->start, dates->end); } @@ -795,7 +805,7 @@ notify_dates_changed (EventPage *epage, struct icaltimetype *start_tt, icaltimezone *start_zone, *end_zone; priv = epage->priv; - + all_day_event = e_dialog_toggle_get (priv->all_day_event); start_dt.value = start_tt; diff --git a/calendar/gui/dialogs/schedule-page.c b/calendar/gui/dialogs/schedule-page.c index 25e20a1e4a..3da74ad6a1 100644 --- a/calendar/gui/dialogs/schedule-page.c +++ b/calendar/gui/dialogs/schedule-page.c @@ -80,6 +80,9 @@ static GtkWidget *schedule_page_get_widget (CompEditorPage *page); static void schedule_page_focus_main_widget (CompEditorPage *page); static void schedule_page_fill_widgets (CompEditorPage *page, CalComponent *comp); static gboolean schedule_page_fill_component (CompEditorPage *page, CalComponent *comp); +static void schedule_page_set_dates (CompEditorPage *page, CompEditorPageDates *dates); + +static void time_changed_cb (GtkWidget *widget, gpointer data); static CompEditorPageClass *parent_class = NULL; @@ -135,7 +138,7 @@ schedule_page_class_init (SchedulePageClass *class) editor_page_class->fill_widgets = schedule_page_fill_widgets; editor_page_class->fill_component = schedule_page_fill_component; editor_page_class->set_summary = NULL; - editor_page_class->set_dates = NULL; + editor_page_class->set_dates = schedule_page_set_dates; object_class->destroy = schedule_page_destroy; } @@ -211,6 +214,57 @@ schedule_page_focus_main_widget (CompEditorPage *page) gtk_widget_grab_focus (GTK_WIDGET (priv->sel)); } +/* Set date/time */ +static void +update_time (SchedulePage *spage, CalComponentDateTime *start_date, CalComponentDateTime *end_date) +{ + SchedulePagePrivate *priv; + struct icaltimetype *start_tt, *end_tt; + icaltimezone *start_zone = NULL, *end_zone = NULL; + CalClientGetStatus status; + + priv = spage->priv; + + /* Note that if we are creating a new event, the timezones may not be + on the server, so we try to get the builtin timezone with the TZID + first. */ + start_zone = icaltimezone_get_builtin_timezone_from_tzid (start_date->tzid); + if (!start_zone) { + status = cal_client_get_timezone (COMP_EDITOR_PAGE (spage)->client, + start_date->tzid, + &start_zone); + /* FIXME: Handle error better. */ + if (status != CAL_CLIENT_GET_SUCCESS) + g_warning ("Couldn't get timezone from server: %s", + start_date->tzid ? start_date->tzid : ""); + } + + end_zone = icaltimezone_get_builtin_timezone_from_tzid (end_date->tzid); + if (!end_zone) { + status = cal_client_get_timezone (COMP_EDITOR_PAGE (spage)->client, + end_date->tzid, + &end_zone); + /* FIXME: Handle error better. */ + if (status != CAL_CLIENT_GET_SUCCESS) + g_warning ("Couldn't get timezone from server: %s", + end_date->tzid ? end_date->tzid : ""); + } + + start_tt = start_date->value; + end_tt = end_date->value; + + e_date_edit_set_date (E_DATE_EDIT (priv->sel->start_date_edit), start_tt->year, + start_tt->month, start_tt->day); + e_date_edit_set_time_of_day (E_DATE_EDIT (priv->sel->start_date_edit), + start_tt->hour, start_tt->minute); + + e_date_edit_set_date (E_DATE_EDIT (priv->sel->end_date_edit), end_tt->year, + end_tt->month, end_tt->day); + e_date_edit_set_time_of_day (E_DATE_EDIT (priv->sel->end_date_edit), + end_tt->hour, end_tt->minute); +} + + /* Fills the widgets with default values */ static void clear_widgets (SchedulePage *spage) @@ -226,7 +280,8 @@ schedule_page_fill_widgets (CompEditorPage *page, CalComponent *comp) { SchedulePage *spage; SchedulePagePrivate *priv; - + CalComponentDateTime start_date, end_date; + spage = SCHEDULE_PAGE (page); priv = spage->priv; @@ -235,6 +290,14 @@ schedule_page_fill_widgets (CompEditorPage *page, CalComponent *comp) /* Clean the screen */ clear_widgets (spage); + /* Start and end times */ + cal_component_get_dtstart (comp, &start_date); + cal_component_get_dtend (comp, &end_date); + update_time (spage, &start_date, &end_date); + + cal_component_free_datetime (&start_date); + cal_component_free_datetime (&end_date); + priv->updating = FALSE; } @@ -251,6 +314,22 @@ schedule_page_fill_component (CompEditorPage *page, CalComponent *comp) return TRUE; } +static void +schedule_page_set_dates (CompEditorPage *page, CompEditorPageDates *dates) +{ + SchedulePage *spage; + SchedulePagePrivate *priv; + + spage = SCHEDULE_PAGE (page); + priv = spage->priv; + + priv->updating = TRUE; + + update_time (spage, dates->start, dates->end); + + priv->updating = FALSE; +} + /* Gets the widgets from the XML file and returns if they are all available. */ @@ -275,6 +354,22 @@ get_widgets (SchedulePage *spage) return TRUE; } +static gboolean +init_widgets (SchedulePage *spage) +{ + SchedulePagePrivate *priv; + + priv = spage->priv; + + gtk_signal_connect (GTK_OBJECT (priv->sel->start_date_edit), + "changed", time_changed_cb, spage); + gtk_signal_connect (GTK_OBJECT (priv->sel->end_date_edit), + "changed", time_changed_cb, spage); + + return TRUE; + +} + /** @@ -316,6 +411,12 @@ schedule_page_construct (SchedulePage *spage, EMeetingModel *emm) gtk_widget_show (GTK_WIDGET (priv->sel)); gtk_box_pack_start (GTK_BOX (priv->main), GTK_WIDGET (priv->sel), TRUE, TRUE, 2); + if (!init_widgets (spage)) { + g_message ("schedule_page_construct(): " + "Could not initialize the widgets!"); + return NULL; + } + return spage; } @@ -340,3 +441,47 @@ schedule_page_new (EMeetingModel *emm) return spage; } + +static void +time_changed_cb (GtkWidget *widget, gpointer data) +{ + SchedulePage *spage = data; + SchedulePagePrivate *priv; + CompEditorPageDates dates; + CalComponentDateTime start_dt, end_dt; + struct icaltimetype start_tt, end_tt; + + priv = spage->priv; + + if (priv->updating) + return; + + e_date_edit_get_date (E_DATE_EDIT (priv->sel->start_date_edit), + &start_tt.year, + &start_tt.month, + &start_tt.day); + e_date_edit_get_time_of_day (E_DATE_EDIT (priv->sel->start_date_edit), + &start_tt.hour, + &start_tt.minute); + e_date_edit_get_date (E_DATE_EDIT (priv->sel->end_date_edit), + &end_tt.year, + &end_tt.month, + &end_tt.day); + e_date_edit_get_time_of_day (E_DATE_EDIT (priv->sel->end_date_edit), + &end_tt.hour, + &end_tt.minute); + + start_dt.value = &start_tt; + end_dt.value = &end_tt; + + start_dt.tzid = NULL; + end_dt.tzid = NULL; + + dates.start = &start_dt; + dates.end = &end_dt; + dates.due = NULL; + dates.complete = NULL; + + comp_editor_page_notify_dates_changed (COMP_EDITOR_PAGE (spage), + &dates); +} -- cgit v1.2.3