diff options
author | Milan Crha <mcrha@redhat.com> | 2010-05-27 23:27:47 +0800 |
---|---|---|
committer | Milan Crha <mcrha@redhat.com> | 2010-05-27 23:27:47 +0800 |
commit | c98ff48755c6a0bdd1005e9427d184385a4999b8 (patch) | |
tree | 012149825495a1d43f48aed21fb22668cbeb03a2 /calendar | |
parent | 7f51095908ab0332ca2722beceffbcb123eefc1c (diff) | |
download | gsoc2013-evolution-c98ff48755c6a0bdd1005e9427d184385a4999b8.tar gsoc2013-evolution-c98ff48755c6a0bdd1005e9427d184385a4999b8.tar.gz gsoc2013-evolution-c98ff48755c6a0bdd1005e9427d184385a4999b8.tar.bz2 gsoc2013-evolution-c98ff48755c6a0bdd1005e9427d184385a4999b8.tar.lz gsoc2013-evolution-c98ff48755c6a0bdd1005e9427d184385a4999b8.tar.xz gsoc2013-evolution-c98ff48755c6a0bdd1005e9427d184385a4999b8.tar.zst gsoc2013-evolution-c98ff48755c6a0bdd1005e9427d184385a4999b8.zip |
Bug #248105 - No warning if you create an appointment in the past
Diffstat (limited to 'calendar')
-rw-r--r-- | calendar/gui/dialogs/comp-editor-util.c | 31 | ||||
-rw-r--r-- | calendar/gui/dialogs/comp-editor-util.h | 2 | ||||
-rw-r--r-- | calendar/gui/dialogs/event-page.c | 46 | ||||
-rw-r--r-- | calendar/gui/dialogs/memo-page.c | 43 | ||||
-rw-r--r-- | calendar/gui/dialogs/task-page.c | 54 |
5 files changed, 161 insertions, 15 deletions
diff --git a/calendar/gui/dialogs/comp-editor-util.c b/calendar/gui/dialogs/comp-editor-util.c index 9856bd7c96..6d3adfe733 100644 --- a/calendar/gui/dialogs/comp-editor-util.c +++ b/calendar/gui/dialogs/comp-editor-util.c @@ -381,3 +381,34 @@ comp_editor_have_in_new_attendees_lst (const GSList *new_attendees, return FALSE; } + +/** + * comp_editor_test_time_in_the_past: + * @time_tt: Time to check. + * @parent: Parent window for a question dialog. + * @tag: Question message tag to use. + * Returns whether given time is in the past. + * + * Tests the given @time_tt whether occurs in the past, + * and if so, returns TRUE. + **/ +gboolean +comp_editor_test_time_in_the_past (const struct icaltimetype time_tt) +{ + struct icaltimetype now_tt; + gboolean is_past; + + if (icaltime_is_null_time (time_tt)) + return FALSE; + + if (time_tt.is_date) { + now_tt = icaltime_today (); + is_past = icaltime_compare_date_only (time_tt, now_tt) < 0; + } else { + now_tt = icaltime_current_time_with_zone (time_tt.zone); + now_tt.zone = time_tt.zone; + is_past = icaltime_compare (time_tt, now_tt) < 0; + } + + return is_past; +} diff --git a/calendar/gui/dialogs/comp-editor-util.h b/calendar/gui/dialogs/comp-editor-util.h index 6eeb8c5410..6ebe4735d1 100644 --- a/calendar/gui/dialogs/comp-editor-util.h +++ b/calendar/gui/dialogs/comp-editor-util.h @@ -47,4 +47,6 @@ void comp_editor_copy_new_attendees (ECalComponent *des, ECalComponent *src); gboolean comp_editor_have_in_new_attendees (ECalComponent *comp, EMeetingAttendee *ma); gboolean comp_editor_have_in_new_attendees_lst (const GSList *new_attendees, const gchar *eml); +gboolean comp_editor_test_time_in_the_past (const struct icaltimetype time_tt); + #endif diff --git a/calendar/gui/dialogs/event-page.c b/calendar/gui/dialogs/event-page.c index 361451efb8..5ceeb9e90b 100644 --- a/calendar/gui/dialogs/event-page.c +++ b/calendar/gui/dialogs/event-page.c @@ -720,6 +720,41 @@ create_image_event_box (const gchar *image_text, const gchar *tip_text) return box; } +/* returns whether changed info text */ +static gboolean +check_starts_in_the_past (EventPage *epage) +{ + EventPagePrivate *priv; + struct icaltimetype start_tt = icaltime_null_time (); + gboolean date_set; + + if ((comp_editor_get_flags (comp_editor_page_get_editor (COMP_EDITOR_PAGE (epage))) & COMP_EDITOR_NEW_ITEM) == 0) + return FALSE; + + priv = epage->priv; + date_set = e_date_edit_get_date (E_DATE_EDIT (priv->start_time), &start_tt.year, &start_tt.month, &start_tt.day); + + g_return_val_if_fail (date_set, FALSE); + + if (priv->all_day_event) { + start_tt.is_date = TRUE; + } else { + e_date_edit_get_time_of_day (E_DATE_EDIT (priv->start_time), &start_tt.hour, &start_tt.minute); + start_tt.zone = e_timezone_entry_get_timezone (E_TIMEZONE_ENTRY (priv->start_timezone)); + } + + if (comp_editor_test_time_in_the_past (start_tt)) { + gchar *tmp = g_strconcat ("<b>", _("Event's start time is in the past"), "</b>", + priv->subscriber_info_text ? "\n" : "", priv->subscriber_info_text, NULL); + event_page_set_info_string (epage, GTK_STOCK_DIALOG_WARNING, tmp); + g_free (tmp); + } else { + event_page_set_info_string (epage, priv->subscriber_info_text ? GTK_STOCK_DIALOG_INFO : NULL, priv->subscriber_info_text); + } + + return TRUE; +} + static void sensitize_widgets (EventPage *epage) { @@ -757,7 +792,7 @@ sensitize_widgets (EventPage *epage) gchar *tmp = g_strconcat ("<b>", _("Event cannot be fully edited, because you are not the organizer"), "</b>", NULL); event_page_set_info_string (epage, GTK_STOCK_DIALOG_INFO, tmp); g_free (tmp); - } else { + } else if (!check_starts_in_the_past (epage)) { event_page_set_info_string (epage, priv->subscriber_info_text ? GTK_STOCK_DIALOG_INFO : NULL, priv->subscriber_info_text); } @@ -2311,6 +2346,8 @@ notify_dates_changed (EventPage *epage, struct icaltimetype *start_tt, comp_editor_page_notify_dates_changed (COMP_EDITOR_PAGE (epage), &dates); + + check_starts_in_the_past (epage); } static gboolean @@ -2639,14 +2676,13 @@ set_subscriber_info_string (EventPage *epage, const gchar *backend_address) /* Translators: This string is used when we are creating an Event (meeting or appointment) on behalf of some other user */ epage->priv->subscriber_info_text = g_markup_printf_escaped (_("You are acting on behalf of %s"), backend_address); - - event_page_set_info_string (epage, GTK_STOCK_DIALOG_INFO, epage->priv->subscriber_info_text); } else { g_free (epage->priv->subscriber_info_text); epage->priv->subscriber_info_text = NULL; - - event_page_set_info_string (epage, NULL, NULL); } + + if (!check_starts_in_the_past (epage)) + event_page_set_info_string (epage, epage->priv->subscriber_info_text ? GTK_STOCK_DIALOG_INFO : NULL, epage->priv->subscriber_info_text); } static void diff --git a/calendar/gui/dialogs/memo-page.c b/calendar/gui/dialogs/memo-page.c index 8ffe45d2c5..27270fd592 100644 --- a/calendar/gui/dialogs/memo-page.c +++ b/calendar/gui/dialogs/memo-page.c @@ -320,6 +320,32 @@ memo_page_init (MemoPage *mpage) mpage->priv = MEMO_PAGE_GET_PRIVATE (mpage); } +/* returns whether changed info text */ +static gboolean +check_starts_in_the_past (MemoPage *mpage) +{ + MemoPagePrivate *priv; + struct icaltimetype start_tt = icaltime_null_time (); + + if ((comp_editor_get_flags (comp_editor_page_get_editor (COMP_EDITOR_PAGE (mpage))) & COMP_EDITOR_NEW_ITEM) == 0) + return FALSE; + + priv = mpage->priv; + + start_tt.is_date = TRUE; + if (e_date_edit_get_date (E_DATE_EDIT (priv->start_date), &start_tt.year, &start_tt.month, &start_tt.day) && + comp_editor_test_time_in_the_past (start_tt)) { + gchar *tmp = g_strconcat ("<b>", _("Memo's start date is in the past"), "</b>", + priv->subscriber_info_text ? "\n" : "", priv->subscriber_info_text, NULL); + memo_page_set_info_string (mpage, GTK_STOCK_DIALOG_WARNING, tmp); + g_free (tmp); + } else { + memo_page_set_info_string (mpage, priv->subscriber_info_text ? GTK_STOCK_DIALOG_INFO : NULL, priv->subscriber_info_text); + } + + return TRUE; +} + static void sensitize_widgets (MemoPage *mpage) { @@ -354,7 +380,7 @@ sensitize_widgets (MemoPage *mpage) gchar *tmp = g_strconcat ("<b>", _("Memo cannot be fully edited, because you are not the organizer"), "</b>", NULL); memo_page_set_info_string (mpage, GTK_STOCK_DIALOG_INFO, tmp); g_free (tmp); - } else { + } else if (!check_starts_in_the_past (mpage)) { memo_page_set_info_string (mpage, priv->subscriber_info_text ? GTK_STOCK_DIALOG_INFO : NULL, priv->subscriber_info_text); } @@ -918,13 +944,13 @@ set_subscriber_info_string (MemoPage *mpage, /* Translators: This string is used when we are creating a Memo on behalf of some other user */ mpage->priv->subscriber_info_text = g_markup_printf_escaped (_("You are acting on behalf of %s"), backend_address); - memo_page_set_info_string (mpage, GTK_STOCK_DIALOG_INFO, mpage->priv->subscriber_info_text); } else { g_free (mpage->priv->subscriber_info_text); mpage->priv->subscriber_info_text = NULL; - - memo_page_set_info_string (mpage, NULL, NULL); } + + if (!check_starts_in_the_past (mpage)) + memo_page_set_info_string (mpage, mpage->priv->subscriber_info_text ? GTK_STOCK_DIALOG_INFO : NULL, mpage->priv->subscriber_info_text); } static void @@ -954,6 +980,13 @@ to_button_clicked_cb (GtkButton *button, gtk_widget_show (GTK_WIDGET (name_selector_dialog)); } +static void +memo_page_start_date_changed_cb (MemoPage *mpage) +{ + check_starts_in_the_past (mpage); + comp_editor_page_changed (COMP_EDITOR_PAGE (mpage)); +} + /* Hooks the widget signals */ static gboolean init_widgets (MemoPage *mpage) @@ -1013,7 +1046,7 @@ init_widgets (MemoPage *mpage) g_signal_connect_swapped ( priv->start_date, "changed", - G_CALLBACK (comp_editor_page_changed), mpage); + G_CALLBACK (memo_page_start_date_changed_cb), mpage); if (priv->name_selector) { ENameSelectorDialog *name_selector_dialog; diff --git a/calendar/gui/dialogs/task-page.c b/calendar/gui/dialogs/task-page.c index 9747501eea..718d45497b 100644 --- a/calendar/gui/dialogs/task-page.c +++ b/calendar/gui/dialogs/task-page.c @@ -309,6 +309,49 @@ task_page_set_view_rsvp (TaskPage *page, gboolean state) e_meeting_list_view_column_set_visible (priv->list_view, E_MEETING_STORE_RSVP_COL, state); } +static gboolean +date_in_past (TaskPage *tpage, EDateEdit *date) +{ + struct icaltimetype tt = icaltime_null_time (); + + if (!e_date_edit_get_date (date, &tt.year, &tt.month, &tt.day)) + return FALSE; + + if (e_date_edit_get_time_of_day (date, &tt.hour, &tt.minute)) + tt.zone = e_timezone_entry_get_timezone (E_TIMEZONE_ENTRY (tpage->priv->timezone)); + else + tt.is_date = TRUE; + + return comp_editor_test_time_in_the_past (tt); +} + +/* returns whether changed info text */ +static gboolean +check_starts_in_the_past (TaskPage *tpage) +{ + TaskPagePrivate *priv; + gboolean start_in_past, due_in_past; + + if ((comp_editor_get_flags (comp_editor_page_get_editor (COMP_EDITOR_PAGE (tpage))) & COMP_EDITOR_NEW_ITEM) == 0) + return FALSE; + + priv = tpage->priv; + start_in_past = date_in_past (tpage, E_DATE_EDIT (priv->start_date)); + due_in_past = date_in_past (tpage, E_DATE_EDIT (priv->due_date)); + + if (start_in_past || due_in_past) { + gchar *tmp = g_strconcat ("<b>", start_in_past ? _("Task's start date is in the past") : "", + start_in_past && due_in_past ? "\n" : "", due_in_past ? _("Task's due date is in the past") : "", "</b>", + priv->subscriber_info_text ? "\n" : "", priv->subscriber_info_text, NULL); + task_page_set_info_string (tpage, GTK_STOCK_DIALOG_WARNING, tmp); + g_free (tmp); + } else { + task_page_set_info_string (tpage, priv->subscriber_info_text ? GTK_STOCK_DIALOG_INFO : NULL, priv->subscriber_info_text); + } + + return TRUE; +} + static void sensitize_widgets (TaskPage *tpage) { @@ -340,7 +383,7 @@ sensitize_widgets (TaskPage *tpage) gchar *tmp = g_strconcat ("<b>", _("Task cannot be fully edited, because you are not the organizer"), "</b>", NULL); task_page_set_info_string (tpage, GTK_STOCK_DIALOG_INFO, tmp); g_free (tmp); - } else { + } else if (!check_starts_in_the_past (tpage)) { task_page_set_info_string (tpage, priv->subscriber_info_text ? GTK_STOCK_DIALOG_INFO : NULL, priv->subscriber_info_text); } @@ -1506,6 +1549,8 @@ date_changed_cb (EDateEdit *dedit, /* Notify upstream */ comp_editor_page_notify_dates_changed (COMP_EDITOR_PAGE (tpage), &dates); + + check_starts_in_the_past (tpage); } static void @@ -1744,14 +1789,13 @@ set_subscriber_info_string (TaskPage *tpage, const gchar *backend_address) /* Translators: This string is used when we are creating a Task on behalf of some other user */ tpage->priv->subscriber_info_text = g_markup_printf_escaped (_("You are acting on behalf of %s"), backend_address); - - task_page_set_info_string (tpage, GTK_STOCK_DIALOG_INFO, tpage->priv->subscriber_info_text); } else { g_free (tpage->priv->subscriber_info_text); tpage->priv->subscriber_info_text = NULL; - - task_page_set_info_string (tpage, NULL, NULL); } + + if (!check_starts_in_the_past (tpage)) + task_page_set_info_string (tpage, tpage->priv->subscriber_info_text ? GTK_STOCK_DIALOG_INFO : NULL, tpage->priv->subscriber_info_text); } void |