evolution-3.6.4/e-util/e-selection.c

No issues found

  1 /*
  2  * e-selection.c
  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  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 19  *
 20  */
 21 
 22 /**
 23  * SECTION: e-selection
 24  * @short_description: selection and clipboard utilities
 25  * @include: e-util/e-selection.h
 26  **/
 27 
 28 #ifdef HAVE_CONFIG_H
 29 #include <config.h>
 30 #endif
 31 
 32 #include "e-selection.h"
 33 
 34 #include <string.h>
 35 
 36 typedef struct _RequestTextInfo RequestTextInfo;
 37 typedef struct _WaitForDataResults WaitForDataResults;
 38 
 39 struct _RequestTextInfo {
 40 	GtkClipboardTextReceivedFunc callback;
 41 	gpointer user_data;
 42 };
 43 
 44 struct _WaitForDataResults {
 45 	GMainLoop *loop;
 46 	gpointer data;
 47 };
 48 
 49 enum {
 50 	ATOM_CALENDAR,
 51 	ATOM_X_VCALENDAR,
 52 	NUM_CALENDAR_ATOMS
 53 };
 54 
 55 enum {
 56 	ATOM_DIRECTORY,
 57 	ATOM_X_VCARD,
 58 	NUM_DIRECTORY_ATOMS
 59 };
 60 
 61 enum {
 62 	ATOM_HTML,
 63 	NUM_HTML_ATOMS
 64 };
 65 
 66 static GdkAtom calendar_atoms[NUM_CALENDAR_ATOMS];
 67 static GdkAtom directory_atoms[NUM_DIRECTORY_ATOMS];
 68 static GdkAtom html_atoms[NUM_HTML_ATOMS];
 69 
 70 static void
 71 init_atoms (void)
 72 {
 73 	static gboolean initialized = FALSE;
 74 
 75 	if (initialized)
 76 		return;
 77 
 78 	/* Calendar Atoms */
 79 
 80 	calendar_atoms[ATOM_CALENDAR] =
 81 		gdk_atom_intern_static_string ("text/calendar");
 82 
 83 	calendar_atoms[ATOM_X_VCALENDAR] =
 84 		gdk_atom_intern_static_string ("text/x-vcalendar");
 85 
 86 	/* Directory Atoms */
 87 
 88 	directory_atoms[ATOM_DIRECTORY] =
 89 		gdk_atom_intern_static_string ("text/directory");
 90 
 91 	directory_atoms[ATOM_X_VCARD] =
 92 		gdk_atom_intern_static_string ("text/x-vcard");
 93 
 94 	/* HTML Atoms */
 95 
 96 	html_atoms[ATOM_HTML] =
 97 		gdk_atom_intern_static_string ("text/html");
 98 
 99 	initialized = TRUE;
100 }
101 
102 static void
103 clipboard_wait_for_text_cb (GtkClipboard *clipboard,
104                             const gchar *source,
105                             WaitForDataResults *results)
106 {
107 	results->data = g_strdup (source);
108 	g_main_loop_quit (results->loop);
109 }
110 
111 void
112 e_target_list_add_calendar_targets (GtkTargetList *list,
113                                     guint info)
114 {
115 	gint ii;
116 
117 	g_return_if_fail (list != NULL);
118 
119 	init_atoms ();
120 
121 	for (ii = 0; ii < NUM_CALENDAR_ATOMS; ii++)
122 		gtk_target_list_add (list, calendar_atoms[ii], 0, info);
123 }
124 
125 void
126 e_target_list_add_directory_targets (GtkTargetList *list,
127                                      guint info)
128 {
129 	gint ii;
130 
131 	g_return_if_fail (list != NULL);
132 
133 	init_atoms ();
134 
135 	for (ii = 0; ii < NUM_DIRECTORY_ATOMS; ii++)
136 		gtk_target_list_add (list, directory_atoms[ii], 0, info);
137 }
138 
139 void
140 e_target_list_add_html_targets (GtkTargetList *list,
141                                 guint info)
142 {
143 	gint ii;
144 
145 	g_return_if_fail (list != NULL);
146 
147 	init_atoms ();
148 
149 	for (ii = 0; ii < NUM_HTML_ATOMS; ii++)
150 		gtk_target_list_add (list, html_atoms[ii], 0, info);
151 }
152 
153 gboolean
154 e_selection_data_set_calendar (GtkSelectionData *selection_data,
155                                const gchar *source,
156                                gint length)
157 {
158 	GdkAtom atom;
159 	gint ii;
160 
161 	g_return_val_if_fail (selection_data != NULL, FALSE);
162 	g_return_val_if_fail (source != NULL, FALSE);
163 
164 	if (length < 0)
165 		length = strlen (source);
166 
167 	init_atoms ();
168 
169 	atom = gtk_selection_data_get_target (selection_data);
170 
171 	/* All calendar atoms are treated the same. */
172 	for (ii = 0; ii < NUM_CALENDAR_ATOMS; ii++) {
173 		if (atom == calendar_atoms[ii]) {
174 			gtk_selection_data_set (
175 				selection_data, atom, 8,
176 				(guchar *) source, length);
177 			return TRUE;
178 		}
179 	}
180 
181 	return FALSE;
182 }
183 
184 gboolean
185 e_selection_data_set_directory (GtkSelectionData *selection_data,
186                                 const gchar *source,
187                                 gint length)
188 {
189 	GdkAtom atom;
190 	gint ii;
191 
192 	g_return_val_if_fail (selection_data != NULL, FALSE);
193 	g_return_val_if_fail (source != NULL, FALSE);
194 
195 	if (length < 0)
196 		length = strlen (source);
197 
198 	init_atoms ();
199 
200 	atom = gtk_selection_data_get_target (selection_data);
201 
202 	/* All directory atoms are treated the same. */
203 	for (ii = 0; ii < NUM_DIRECTORY_ATOMS; ii++) {
204 		if (atom == directory_atoms[ii]) {
205 			gtk_selection_data_set (
206 				selection_data, atom, 8,
207 				(guchar *) source, length);
208 			return TRUE;
209 		}
210 	}
211 
212 	return FALSE;
213 }
214 
215 gboolean
216 e_selection_data_set_html (GtkSelectionData *selection_data,
217                            const gchar *source,
218                            gint length)
219 {
220 	GdkAtom atom;
221 	gint ii;
222 
223 	g_return_val_if_fail (selection_data != NULL, FALSE);
224 	g_return_val_if_fail (source != NULL, FALSE);
225 
226 	if (length < 0)
227 		length = strlen (source);
228 
229 	init_atoms ();
230 
231 	atom = gtk_selection_data_get_target (selection_data);
232 
233 	/* All HTML atoms are treated the same. */
234 	for (ii = 0; ii < NUM_HTML_ATOMS; ii++) {
235 		if (atom == html_atoms[ii]) {
236 			gtk_selection_data_set (
237 				selection_data, atom, 8,
238 				(guchar *) source, length);
239 			return TRUE;
240 		}
241 	}
242 
243 	return FALSE;
244 }
245 
246 gchar *
247 e_selection_data_get_calendar (GtkSelectionData *selection_data)
248 {
249 	GdkAtom data_type;
250 	const guchar *data = NULL;
251 	gint ii;
252 
253 	/* XXX May need to do encoding and line ending conversions
254 	 *     here.  Not worrying about it for now. */
255 
256 	g_return_val_if_fail (selection_data != NULL, NULL);
257 
258 	data = gtk_selection_data_get_data (selection_data);
259 	data_type = gtk_selection_data_get_data_type (selection_data);
260 
261 	/* All calendar atoms are treated the same. */
262 	for (ii = 0; ii < NUM_CALENDAR_ATOMS; ii++)
263 		if (data_type == calendar_atoms[ii])
264 			return g_strdup ((gchar *) data);
265 
266 	return NULL;
267 }
268 
269 gchar *
270 e_selection_data_get_directory (GtkSelectionData *selection_data)
271 {
272 	GdkAtom data_type;
273 	const guchar *data = NULL;
274 	gint ii;
275 
276 	/* XXX May need to do encoding and line ending conversions
277 	 *     here.  Not worrying about it for now. */
278 
279 	g_return_val_if_fail (selection_data != NULL, NULL);
280 
281 	data = gtk_selection_data_get_data (selection_data);
282 	data_type = gtk_selection_data_get_data_type (selection_data);
283 
284 	/* All directory atoms are treated the same. */
285 	for (ii = 0; ii < NUM_DIRECTORY_ATOMS; ii++)
286 		if (data_type == directory_atoms[ii])
287 			return g_strdup ((gchar *) data);
288 
289 	return NULL;
290 }
291 
292 gchar *
293 e_selection_data_get_html (GtkSelectionData *selection_data)
294 {
295 	GdkAtom data_type;
296 	const guchar *data = NULL;
297 	gchar *utf8_text;
298 	gint length;
299 	gint ii;
300 	GError *error = NULL;
301 
302 	/* XXX May need to do encoding conversions here.
303 	 *     Not worrying about it for now. */
304 
305 	g_return_val_if_fail (selection_data != NULL, NULL);
306 
307 	data = gtk_selection_data_get_data (selection_data);
308 	length = gtk_selection_data_get_length (selection_data);
309 	data_type = gtk_selection_data_get_data_type (selection_data);
310 
311 	g_return_val_if_fail (data != NULL, NULL);
312 
313 	/* First validate the data.  Assume it's UTF-8 or UTF-16. */
314 	if (g_utf8_validate ((const gchar *) data, length - 1, NULL))
315 		utf8_text = g_strdup ((const gchar *) data);
316 	else
317 		utf8_text = g_convert (
318 			(const gchar *) data, length,
319 			"UTF-8", "UTF-16", NULL, NULL, &error);
320 
321 	if (error != NULL) {
322 		g_warning ("%s", error->message);
323 		g_error_free (error);
324 	}
325 
326 	/* All HTML atoms are treated the same. */
327 	for (ii = 0; ii < NUM_HTML_ATOMS; ii++)
328 		if (data_type == html_atoms[ii])
329 			return utf8_text;
330 
331 	g_free (utf8_text);
332 
333 	return NULL;
334 }
335 
336 gboolean
337 e_selection_data_targets_include_calendar (GtkSelectionData *selection_data)
338 {
339 	GdkAtom *targets;
340 	gint n_targets;
341 	gboolean result = FALSE;
342 
343 	g_return_val_if_fail (selection_data != NULL, FALSE);
344 
345 	if (gtk_selection_data_get_targets (selection_data, &targets, &n_targets)) {
346 		result = e_targets_include_calendar (targets, n_targets);
347 		g_free (targets);
348 	}
349 
350 	return result;
351 }
352 
353 gboolean
354 e_selection_data_targets_include_directory (GtkSelectionData *selection_data)
355 {
356 	GdkAtom *targets;
357 	gint n_targets;
358 	gboolean result = FALSE;
359 
360 	g_return_val_if_fail (selection_data != NULL, FALSE);
361 
362 	if (gtk_selection_data_get_targets (selection_data, &targets, &n_targets)) {
363 		result = e_targets_include_directory (targets, n_targets);
364 		g_free (targets);
365 	}
366 
367 	return result;
368 }
369 
370 gboolean
371 e_selection_data_targets_include_html (GtkSelectionData *selection_data)
372 {
373 	GdkAtom *targets;
374 	gint n_targets;
375 	gboolean result = FALSE;
376 
377 	g_return_val_if_fail (selection_data != NULL, FALSE);
378 
379 	if (gtk_selection_data_get_targets (selection_data, &targets, &n_targets)) {
380 		result = e_targets_include_html (targets, n_targets);
381 		g_free (targets);
382 	}
383 
384 	return result;
385 }
386 
387 gboolean
388 e_targets_include_calendar (GdkAtom *targets,
389                             gint n_targets)
390 {
391 	gint ii, jj;
392 
393 	g_return_val_if_fail (targets != NULL || n_targets == 0, FALSE);
394 
395 	init_atoms ();
396 
397 	for (ii = 0; ii < n_targets; ii++)
398 		for (jj = 0; jj < NUM_CALENDAR_ATOMS; jj++)
399 			if (targets[ii] == calendar_atoms[jj])
400 				return TRUE;
401 
402 	return FALSE;
403 }
404 
405 gboolean
406 e_targets_include_directory (GdkAtom *targets,
407                              gint n_targets)
408 {
409 	gint ii, jj;
410 
411 	g_return_val_if_fail (targets != NULL || n_targets == 0, FALSE);
412 
413 	init_atoms ();
414 
415 	for (ii = 0; ii < n_targets; ii++)
416 		for (jj = 0; jj < NUM_DIRECTORY_ATOMS; jj++)
417 			if (targets[ii] == directory_atoms[jj])
418 				return TRUE;
419 
420 	return FALSE;
421 }
422 
423 gboolean
424 e_targets_include_html (GdkAtom *targets,
425                         gint n_targets)
426 {
427 	gint ii, jj;
428 
429 	g_return_val_if_fail (targets != NULL || n_targets == 0, FALSE);
430 
431 	init_atoms ();
432 
433 	for (ii = 0; ii < n_targets; ii++)
434 		for (jj = 0; jj < NUM_HTML_ATOMS; jj++)
435 			if (targets[ii] == html_atoms[jj])
436 				return TRUE;
437 
438 	return FALSE;
439 }
440 
441 static void
442 clipboard_get_calendar (GtkClipboard *clipboard,
443                         GtkSelectionData *selection_data,
444                         guint info,
445                         gchar *source)
446 {
447 	e_selection_data_set_calendar (selection_data, source, -1);
448 }
449 
450 static void
451 clipboard_clear_calendar (GtkClipboard *clipboard,
452                           gchar *source)
453 {
454 	g_free (source);
455 }
456 
457 void
458 e_clipboard_set_calendar (GtkClipboard *clipboard,
459                           const gchar *source,
460                           gint length)
461 {
462 	GtkTargetList *list;
463 	GtkTargetEntry *targets;
464 	gint n_targets;
465 
466 	g_return_if_fail (clipboard != NULL);
467 	g_return_if_fail (source != NULL);
468 
469 	list = gtk_target_list_new (NULL, 0);
470 	e_target_list_add_calendar_targets (list, 0);
471 
472 	targets = gtk_target_table_new_from_list (list, &n_targets);
473 
474 	if (length < 0)
475 		length = strlen (source);
476 
477 	gtk_clipboard_set_with_data (
478 		clipboard, targets, n_targets,
479 		(GtkClipboardGetFunc) clipboard_get_calendar,
480 		(GtkClipboardClearFunc) clipboard_clear_calendar,
481 		g_strndup (source, length));
482 
483 	gtk_clipboard_set_can_store (clipboard, NULL, 0);
484 
485 	gtk_target_table_free (targets, n_targets);
486 	gtk_target_list_unref (list);
487 }
488 
489 static void
490 clipboard_get_directory (GtkClipboard *clipboard,
491                          GtkSelectionData *selection_data,
492                          guint info,
493                          gchar *source)
494 {
495 	e_selection_data_set_directory (selection_data, source, -1);
496 }
497 
498 static void
499 clipboard_clear_directory (GtkClipboard *clipboard,
500                            gchar *source)
501 {
502 	g_free (source);
503 }
504 
505 void
506 e_clipboard_set_directory (GtkClipboard *clipboard,
507                            const gchar *source,
508                            gint length)
509 {
510 	GtkTargetList *list;
511 	GtkTargetEntry *targets;
512 	gint n_targets;
513 
514 	g_return_if_fail (clipboard != NULL);
515 	g_return_if_fail (source != NULL);
516 
517 	list = gtk_target_list_new (NULL, 0);
518 	e_target_list_add_directory_targets (list, 0);
519 
520 	targets = gtk_target_table_new_from_list (list, &n_targets);
521 
522 	if (length < 0)
523 		length = strlen (source);
524 
525 	gtk_clipboard_set_with_data (
526 		clipboard, targets, n_targets,
527 		(GtkClipboardGetFunc) clipboard_get_directory,
528 		(GtkClipboardClearFunc) clipboard_clear_directory,
529 		g_strndup (source, length));
530 
531 	gtk_clipboard_set_can_store (clipboard, NULL, 0);
532 
533 	gtk_target_table_free (targets, n_targets);
534 	gtk_target_list_unref (list);
535 }
536 
537 static void
538 clipboard_get_html (GtkClipboard *clipboard,
539                     GtkSelectionData *selection_data,
540                     guint info,
541                     gchar *source)
542 {
543 	e_selection_data_set_html (selection_data, source, -1);
544 }
545 
546 static void
547 clipboard_clear_html (GtkClipboard *clipboard,
548                       gchar *source)
549 {
550 	g_free (source);
551 }
552 
553 void
554 e_clipboard_set_html (GtkClipboard *clipboard,
555                       const gchar *source,
556                       gint length)
557 {
558 	GtkTargetList *list;
559 	GtkTargetEntry *targets;
560 	gint n_targets;
561 
562 	g_return_if_fail (clipboard != NULL);
563 	g_return_if_fail (source != NULL);
564 
565 	list = gtk_target_list_new (NULL, 0);
566 	e_target_list_add_html_targets (list, 0);
567 
568 	targets = gtk_target_table_new_from_list (list, &n_targets);
569 
570 	if (length < 0)
571 		length = strlen (source);
572 
573 	gtk_clipboard_set_with_data (
574 		clipboard, targets, n_targets,
575 		(GtkClipboardGetFunc) clipboard_get_html,
576 		(GtkClipboardClearFunc) clipboard_clear_html,
577 		g_strndup (source, length));
578 
579 	gtk_clipboard_set_can_store (clipboard, NULL, 0);
580 
581 	gtk_target_table_free (targets, n_targets);
582 	gtk_target_list_unref (list);
583 }
584 
585 static void
586 clipboard_request_calendar_cb (GtkClipboard *clipboard,
587                                GtkSelectionData *selection_data,
588                                RequestTextInfo *info)
589 {
590 	gchar *source;
591 
592 	source = e_selection_data_get_calendar (selection_data);
593 	info->callback (clipboard, source, info->user_data);
594 	g_free (source);
595 
596 	g_slice_free (RequestTextInfo, info);
597 }
598 
599 void
600 e_clipboard_request_calendar (GtkClipboard *clipboard,
601                               GtkClipboardTextReceivedFunc callback,
602                               gpointer user_data)
603 {
604 	RequestTextInfo *info;
605 
606 	g_return_if_fail (clipboard != NULL);
607 	g_return_if_fail (callback != NULL);
608 
609 	init_atoms ();
610 
611 	info = g_slice_new (RequestTextInfo);
612 	info->callback = callback;
613 	info->user_data = user_data;
614 
615 	gtk_clipboard_request_contents (
616 		clipboard, calendar_atoms[ATOM_CALENDAR],
617 		(GtkClipboardReceivedFunc)
618 		clipboard_request_calendar_cb, info);
619 }
620 
621 static void
622 clipboard_request_directory_cb (GtkClipboard *clipboard,
623                                 GtkSelectionData *selection_data,
624                                 RequestTextInfo *info)
625 {
626 	gchar *source;
627 
628 	source = e_selection_data_get_directory (selection_data);
629 	info->callback (clipboard, source, info->user_data);
630 	g_free (source);
631 
632 	g_slice_free (RequestTextInfo, info);
633 }
634 
635 void
636 e_clipboard_request_directory (GtkClipboard *clipboard,
637                                GtkClipboardTextReceivedFunc callback,
638                                gpointer user_data)
639 {
640 	RequestTextInfo *info;
641 
642 	g_return_if_fail (clipboard != NULL);
643 	g_return_if_fail (callback != NULL);
644 
645 	init_atoms ();
646 
647 	info = g_slice_new (RequestTextInfo);
648 	info->callback = callback;
649 	info->user_data = user_data;
650 
651 	gtk_clipboard_request_contents (
652 		clipboard, directory_atoms[ATOM_DIRECTORY],
653 		(GtkClipboardReceivedFunc)
654 		clipboard_request_directory_cb, info);
655 }
656 
657 static void
658 clipboard_request_html_cb (GtkClipboard *clipboard,
659                            GtkSelectionData *selection_data,
660                            RequestTextInfo *info)
661 {
662 	gchar *source;
663 
664 	source = e_selection_data_get_html (selection_data);
665 	info->callback (clipboard, source, info->user_data);
666 	g_free (source);
667 
668 	g_slice_free (RequestTextInfo, info);
669 }
670 
671 void
672 e_clipboard_request_html (GtkClipboard *clipboard,
673                           GtkClipboardTextReceivedFunc callback,
674                           gpointer user_data)
675 {
676 	RequestTextInfo *info;
677 
678 	g_return_if_fail (clipboard != NULL);
679 	g_return_if_fail (callback != NULL);
680 
681 	init_atoms ();
682 
683 	info = g_slice_new (RequestTextInfo);
684 	info->callback = callback;
685 	info->user_data = user_data;
686 
687 	gtk_clipboard_request_contents (
688 		clipboard, html_atoms[ATOM_HTML],
689 		(GtkClipboardReceivedFunc)
690 		clipboard_request_html_cb, info);
691 }
692 
693 gchar *
694 e_clipboard_wait_for_calendar (GtkClipboard *clipboard)
695 {
696 	WaitForDataResults results;
697 
698 	g_return_val_if_fail (clipboard != NULL, NULL);
699 
700 	results.data = NULL;
701 	results.loop = g_main_loop_new (NULL, TRUE);
702 
703 	e_clipboard_request_calendar (
704 		clipboard, (GtkClipboardTextReceivedFunc)
705 		clipboard_wait_for_text_cb, &results);
706 
707 	if (g_main_loop_is_running (results.loop))
708 		g_main_loop_run (results.loop);
709 
710 	g_main_loop_unref (results.loop);
711 
712 	return results.data;
713 }
714 
715 gchar *
716 e_clipboard_wait_for_directory (GtkClipboard *clipboard)
717 {
718 	WaitForDataResults results;
719 
720 	g_return_val_if_fail (clipboard != NULL, NULL);
721 
722 	results.data = NULL;
723 	results.loop = g_main_loop_new (NULL, TRUE);
724 
725 	e_clipboard_request_directory (
726 		clipboard, (GtkClipboardTextReceivedFunc)
727 		clipboard_wait_for_text_cb, &results);
728 
729 	if (g_main_loop_is_running (results.loop))
730 		g_main_loop_run (results.loop);
731 
732 	g_main_loop_unref (results.loop);
733 
734 	return results.data;
735 }
736 
737 gchar *
738 e_clipboard_wait_for_html (GtkClipboard *clipboard)
739 {
740 	WaitForDataResults results;
741 
742 	g_return_val_if_fail (clipboard != NULL, NULL);
743 
744 	results.data = NULL;
745 	results.loop = g_main_loop_new (NULL, TRUE);
746 
747 	e_clipboard_request_html (
748 		clipboard, (GtkClipboardTextReceivedFunc)
749 		clipboard_wait_for_text_cb, &results);
750 
751 	if (g_main_loop_is_running (results.loop))
752 		g_main_loop_run (results.loop);
753 
754 	g_main_loop_unref (results.loop);
755 
756 	return results.data;
757 }
758 
759 gboolean
760 e_clipboard_wait_is_calendar_available (GtkClipboard *clipboard)
761 {
762 	GdkAtom *targets;
763 	gint n_targets;
764 	gboolean result = FALSE;
765 
766 	if (gtk_clipboard_wait_for_targets (clipboard, &targets, &n_targets)) {
767 		result = e_targets_include_calendar (targets, n_targets);
768 		g_free (targets);
769 	}
770 
771 	return result;
772 }
773 
774 gboolean
775 e_clipboard_wait_is_directory_available (GtkClipboard *clipboard)
776 {
777 	GdkAtom *targets;
778 	gint n_targets;
779 	gboolean result = FALSE;
780 
781 	if (gtk_clipboard_wait_for_targets (clipboard, &targets, &n_targets)) {
782 		result = e_targets_include_directory (targets, n_targets);
783 		g_free (targets);
784 	}
785 
786 	return result;
787 }
788 
789 gboolean
790 e_clipboard_wait_is_html_available (GtkClipboard *clipboard)
791 {
792 	GdkAtom *targets;
793 	gint n_targets;
794 	gboolean result = FALSE;
795 
796 	if (gtk_clipboard_wait_for_targets (clipboard, &targets, &n_targets)) {
797 		result = e_targets_include_html (targets, n_targets);
798 		g_free (targets);
799 	}
800 
801 	return result;
802 }
803 
804 void
805 e_drag_dest_add_calendar_targets (GtkWidget *widget)
806 {
807 	GtkTargetList *target_list;
808 
809 	g_return_if_fail (GTK_IS_WIDGET (widget));
810 
811 	target_list = gtk_drag_source_get_target_list (widget);
812 	if (target_list != NULL)
813 		gtk_target_list_ref (target_list);
814 	else
815 		target_list = gtk_target_list_new (NULL, 0);
816 	e_target_list_add_calendar_targets (target_list, 0);
817 	gtk_drag_dest_set_target_list (widget, target_list);
818 	gtk_target_list_unref (target_list);
819 }
820 
821 void
822 e_drag_dest_add_directory_targets (GtkWidget *widget)
823 {
824 	GtkTargetList *target_list;
825 
826 	g_return_if_fail (GTK_IS_WIDGET (widget));
827 
828 	target_list = gtk_drag_source_get_target_list (widget);
829 	if (target_list != NULL)
830 		gtk_target_list_ref (target_list);
831 	else
832 		target_list = gtk_target_list_new (NULL, 0);
833 	e_target_list_add_directory_targets (target_list, 0);
834 	gtk_drag_dest_set_target_list (widget, target_list);
835 	gtk_target_list_unref (target_list);
836 }
837 
838 void
839 e_drag_dest_add_html_targets (GtkWidget *widget)
840 {
841 	GtkTargetList *target_list;
842 
843 	g_return_if_fail (GTK_IS_WIDGET (widget));
844 
845 	target_list = gtk_drag_source_get_target_list (widget);
846 	if (target_list != NULL)
847 		gtk_target_list_ref (target_list);
848 	else
849 		target_list = gtk_target_list_new (NULL, 0);
850 	e_target_list_add_html_targets (target_list, 0);
851 	gtk_drag_dest_set_target_list (widget, target_list);
852 	gtk_target_list_unref (target_list);
853 }
854 
855 void
856 e_drag_source_add_calendar_targets (GtkWidget *widget)
857 {
858 	GtkTargetList *target_list;
859 
860 	g_return_if_fail (GTK_IS_WIDGET (widget));
861 
862 	target_list = gtk_drag_source_get_target_list (widget);
863 	if (target_list != NULL)
864 		gtk_target_list_ref (target_list);
865 	else
866 		target_list = gtk_target_list_new (NULL, 0);
867 	e_target_list_add_calendar_targets (target_list, 0);
868 	gtk_drag_source_set_target_list (widget, target_list);
869 	gtk_target_list_unref (target_list);
870 }
871 
872 void
873 e_drag_source_add_directory_targets (GtkWidget *widget)
874 {
875 	GtkTargetList *target_list;
876 
877 	g_return_if_fail (GTK_IS_WIDGET (widget));
878 
879 	target_list = gtk_drag_source_get_target_list (widget);
880 	if (target_list != NULL)
881 		gtk_target_list_ref (target_list);
882 	else
883 		target_list = gtk_target_list_new (NULL, 0);
884 	e_target_list_add_directory_targets (target_list, 0);
885 	gtk_drag_source_set_target_list (widget, target_list);
886 	gtk_target_list_unref (target_list);
887 }
888 
889 void
890 e_drag_source_add_html_targets (GtkWidget *widget)
891 {
892 	GtkTargetList *target_list;
893 
894 	g_return_if_fail (GTK_IS_WIDGET (widget));
895 
896 	target_list = gtk_drag_source_get_target_list (widget);
897 	if (target_list != NULL)
898 		gtk_target_list_ref (target_list);
899 	else
900 		target_list = gtk_target_list_new (NULL, 0);
901 	e_target_list_add_html_targets (target_list, 0);
902 	gtk_drag_source_set_target_list (widget, target_list);
903 	gtk_target_list_unref (target_list);
904 }