No issues found
1 /*
2 * Evolution calendar - Send calendar component dialog
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with the program; if not, see <http://www.gnu.org/licenses/>
16 *
17 *
18 * Authors:
19 * JP Rosevear <jpr@ximian.com>
20 *
21 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
22 *
23 */
24
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
28
29 #include <gtk/gtk.h>
30 #include <glib/gi18n.h>
31 #include "libevolution-utils/e-alert-dialog.h"
32 #include "cancel-comp.h"
33
34 /* is_past_event:
35 *
36 * returns TRUE if @comp is in the past, FALSE otherwise.
37 * Comparision is based only on date part, time part is ignored.
38 */
39 static gboolean
40 is_past_event (ECalComponent *comp)
41 {
42 ECalComponentDateTime end_date;
43 gboolean res;
44
45 if (!comp) return TRUE;
46
47 e_cal_component_get_dtend (comp, &end_date);
48 res = icaltime_compare_date_only (
49 *end_date.value,
50 icaltime_current_time_with_zone (
51 icaltime_get_timezone (*end_date.value))) == -1;
52 e_cal_component_free_datetime (&end_date);
53
54 return res;
55 }
56
57 /**
58 * cancel_component_dialog:
59 *
60 * Pops up a dialog box asking the user whether he wants to send a
61 * cancel and delete an iTip/iMip message
62 *
63 * Return value: TRUE if the user clicked Yes, FALSE otherwise.
64 **/
65 gboolean
66 cancel_component_dialog (GtkWindow *parent,
67 ECalClient *cal_client,
68 ECalComponent *comp,
69 gboolean deleting)
70 {
71 ECalComponentVType vtype;
72 const gchar *id;
73
74 if (deleting && e_cal_client_check_save_schedules (cal_client))
75 return TRUE;
76
77 vtype = e_cal_component_get_vtype (comp);
78
79 switch (vtype) {
80 case E_CAL_COMPONENT_EVENT:
81 if (is_past_event (comp)) {
82 /* don't ask neither send notification to others on past events */
83 return FALSE;
84 }
85 if (deleting)
86 id = "calendar:prompt-cancel-meeting";
87 else
88 id = "calendar:prompt-delete-meeting";
89 break;
90
91 case E_CAL_COMPONENT_TODO:
92 if (deleting)
93 id = "calendar:prompt-cancel-task";
94 else
95 id = "calendar:prompt-delete-task";
96 break;
97
98 case E_CAL_COMPONENT_JOURNAL:
99 if (deleting)
100 id = "calendar:prompt-cancel-memo";
101 else
102 id = "calendar:prompt-delete-memo";
103 break;
104
105 default:
106 g_message (G_STRLOC ": Cannot handle object of type %d", vtype);
107 return FALSE;
108 }
109
110 if (e_alert_run_dialog_for_args (parent, id, NULL) == GTK_RESPONSE_YES)
111 return TRUE;
112 else
113 return FALSE;
114 }