evolution-3.6.4/calendar/gui/dialogs/delete-comp.c

No issues found

  1 /*
  2  * Evolution calendar - Delete 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  *		Federico Mena-Quintero <federico@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 <glib/gi18n.h>
 30 #include "libevolution-utils/e-alert-dialog.h"
 31 #include "delete-comp.h"
 32 
 33 /**
 34  * delete_component_dialog:
 35  * @comp: A calendar component if a single component is to be deleted, or NULL
 36  * if more that one component is to be deleted.
 37  * @consider_as_untitled: If deleting more than one component, this is ignored.
 38  * Otherwise, whether to consider the component as not having a summary; if
 39  * FALSE then the component's summary string will be used.
 40  * @n_comps: Number of components that are to be deleted.
 41  * @vtype: Type of the components that are to be deleted.  This is ignored
 42  * if only one component is to be deleted, and the vtype is extracted from
 43  * the component instead.
 44  * @widget: A widget to use as a basis for conversion from UTF8 into font
 45  * encoding.
 46  *
 47  * Pops up a dialog box asking the user whether he wants to delete a number of
 48  * calendar components.  The dialog will not appear, however, if the
 49  * configuration option for confirmation is turned off.
 50  *
 51  * Return value: TRUE if the user clicked Yes, FALSE otherwise.  If the
 52  * configuration option for confirmation is turned off, this function will
 53  * unconditionally return TRUE.
 54  **/
 55 gboolean
 56 delete_component_dialog (ECalComponent *comp,
 57                          gboolean consider_as_untitled,
 58                          gint n_comps,
 59                          ECalComponentVType vtype,
 60                          GtkWidget *widget)
 61 {
 62 	const gchar *id;
 63 	gchar *arg0 = NULL;
 64 	gint response;
 65 	gboolean attendees;
 66 
 67 	if (comp) {
 68 		g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), FALSE);
 69 		g_return_val_if_fail (n_comps == 1, FALSE);
 70 	} else {
 71 		g_return_val_if_fail (n_comps > 1, FALSE);
 72 		g_return_val_if_fail (vtype != E_CAL_COMPONENT_NO_TYPE, FALSE);
 73 	}
 74 
 75 	g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
 76 
 77 	if (comp) {
 78 		ECalComponentText summary;
 79 
 80 		vtype = e_cal_component_get_vtype (comp);
 81 
 82 		if (!consider_as_untitled) {
 83 			e_cal_component_get_summary (comp, &summary);
 84 			arg0 = g_strdup (summary.value);
 85 		}
 86 
 87 		switch (vtype) {
 88 		case E_CAL_COMPONENT_EVENT:
 89 			attendees = e_cal_component_has_attendees (comp);
 90 			if (arg0) {
 91 				if (attendees)
 92 					id = "calendar:prompt-delete-titled-meeting";
 93 				else
 94 					id = "calendar:prompt-delete-titled-appointment";
 95 			} else {
 96 				if (attendees)
 97 					id = "calendar:prompt-delete-meeting";
 98 				else
 99 					id = "calendar:prompt-delete-appointment";
100 			}
101 			break;
102 
103 		case E_CAL_COMPONENT_TODO:
104 			if (arg0)
105 				id = "calendar:prompt-delete-named-task";
106 			else
107 				id = "calendar:prompt-delete-task";
108 			break;
109 
110 		case E_CAL_COMPONENT_JOURNAL:
111 			if (arg0)
112 				id = "calendar:prompt-delete-named-memo";
113 			else
114 				id = "calendar:prompt-delete-memo";
115 			break;
116 
117 		default:
118 			g_message (
119 				"delete_component_dialog(): Cannot handle object of type %d",
120 				vtype);
121 			g_free (arg0);
122 			return FALSE;
123 		}
124 	} else {
125 		switch (vtype) {
126 		case E_CAL_COMPONENT_EVENT:
127 			if (n_comps == 1)
128 				id = "calendar:prompt-delete-appointment";
129 			else
130 				id = "calendar:prompt-delete-appointments";
131 			break;
132 
133 		case E_CAL_COMPONENT_TODO:
134 			if (n_comps == 1)
135 				id = "calendar:prompt-delete-task";
136 			else
137 				id = "calendar:prompt-delete-tasks";
138 			break;
139 
140 		case E_CAL_COMPONENT_JOURNAL:
141 			if (n_comps == 1)
142 				id = "calendar:prompt-delete-memo";
143 			else
144 				id = "calendar:prompt-delete-memos";
145 			break;
146 
147 		default:
148 			g_message (
149 				"delete_component_dialog(): Cannot handle objects of type %d",
150 				vtype);
151 			return FALSE;
152 		}
153 
154 		if (n_comps > 1)
155 			arg0 = g_strdup_printf ("%d", n_comps);
156 	}
157 
158 	response = e_alert_run_dialog_for_args ((GtkWindow *) gtk_widget_get_toplevel (widget), id, arg0, NULL);
159 	g_free (arg0);
160 
161 	return response == GTK_RESPONSE_YES;
162 }
163 
164 static void
165 cb_toggled_cb (GtkToggleButton *toggle,
166                gpointer data)
167 {
168 	gboolean active = FALSE;
169 	GtkWidget *entry = (GtkWidget *) data;
170 
171 	active = gtk_toggle_button_get_active (toggle);
172 	gtk_widget_set_sensitive (entry, active);
173 }
174 
175 gboolean
176 prompt_retract_dialog (ECalComponent *comp,
177                        gchar **retract_text,
178                        GtkWidget *parent,
179                        gboolean *retract)
180 {
181 	gchar *message = NULL;
182 	ECalComponentVType type = E_CAL_COMPONENT_NO_TYPE;
183 	GtkMessageDialog *dialog = NULL;
184 	GtkWidget *cb, *label, *entry, *vbox, *sw, *frame;
185 	gboolean ret_val = FALSE;
186 
187 	type = e_cal_component_get_vtype (comp);
188 
189 	switch (type) {
190 		case E_CAL_COMPONENT_EVENT:
191 			message = g_strdup_printf (_("Are you sure you want to delete this meeting?"));
192 			break;
193 		case E_CAL_COMPONENT_TODO:
194 			message = g_strdup_printf (_("Are you sure you want to delete this task?"));
195 			break;
196 		case E_CAL_COMPONENT_JOURNAL:
197 			message = g_strdup_printf (_("Are you sure you want to delete this memo?"));
198 			break;
199 		default:
200 			g_message ("Retract: Unsupported object type \n");
201 			return FALSE;
202 	}
203 
204 	dialog = (GtkMessageDialog *) gtk_message_dialog_new_with_markup
205 		((GtkWindow *) gtk_widget_get_toplevel (parent), GTK_DIALOG_MODAL,
206 		 GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, "<b>%s</b>", message);
207 	g_free (message);
208 
209 	gtk_window_set_resizable (GTK_WINDOW (dialog), TRUE);
210 
211 	vbox = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
212 	gtk_box_set_spacing (GTK_BOX (vbox), 12);
213 
214 	cb = gtk_check_button_new_with_mnemonic (_("_Delete this item from all other recipient's mailboxes?"));
215 	gtk_container_add (GTK_CONTAINER (vbox), cb);
216 
217 	label = gtk_label_new_with_mnemonic (_("_Retract comment"));
218 
219 	frame = gtk_frame_new (NULL);
220 	gtk_frame_set_label_widget ((GtkFrame *) frame, label);
221 	gtk_frame_set_label_align ((GtkFrame *) frame, 0, 0);
222 	gtk_container_add (GTK_CONTAINER (vbox), frame);
223 	gtk_frame_set_shadow_type ((GtkFrame *) frame, GTK_SHADOW_NONE);
224 
225 	sw = gtk_scrolled_window_new (NULL, NULL);
226 	gtk_scrolled_window_set_policy ((GtkScrolledWindow *) sw, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
227 
228 	entry = gtk_text_view_new ();
229 	gtk_scrolled_window_add_with_viewport ((GtkScrolledWindow *) sw, entry);
230 	gtk_label_set_mnemonic_widget ((GtkLabel *) label, entry);
231 	gtk_container_add (GTK_CONTAINER (frame), sw);
232 
233 	g_signal_connect (
234 		cb, "toggled",
235 		G_CALLBACK (cb_toggled_cb), entry);
236 
237 	gtk_widget_show_all ((GtkWidget *) dialog);
238 
239 	ret_val = (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK);
240 
241 	if (ret_val) {
242 		if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (cb))) {
243 			GtkTextIter text_iter_start, text_iter_end;
244 			GtkTextBuffer *text_buffer;
245 
246 			*retract = TRUE;
247 			text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (entry));
248 			gtk_text_buffer_get_start_iter (text_buffer, &text_iter_start);
249 			gtk_text_buffer_get_end_iter   (text_buffer, &text_iter_end);
250 
251 			*retract_text = gtk_text_buffer_get_text (text_buffer, &text_iter_start,
252 					&text_iter_end, FALSE);
253 		} else
254 			*retract = FALSE;
255 	}
256 
257 	gtk_widget_destroy ((GtkWidget *) dialog);
258 
259 	return ret_val;
260 }