summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiep Ha <thiepha@gmail.com>2015-03-26 22:49:27 +0000
committerThiep Ha <thiepha@gmail.com>2015-06-02 21:50:24 +0900
commit676f2dca4220caa3da472756c215f02968e3ce71 (patch)
treed64cc752db58af7fc007a89d7883ae1a9f2c53d8
parente06316882c8dd9f0987a386d41bba6d300324d7d (diff)
DnD/Wl: Add types' notify handlers
This patch adds notify handlers for types. It provides different ways to handle different data types.
-rw-r--r--src/lib/elm_cnp.c506
1 files changed, 444 insertions, 62 deletions
diff --git a/src/lib/elm_cnp.c b/src/lib/elm_cnp.c
index 6d4418902..af2703f6b 100644
--- a/src/lib/elm_cnp.c
+++ b/src/lib/elm_cnp.c
@@ -258,9 +258,14 @@ typedef struct _Wl_Cnp_Selection Wl_Cnp_Selection;
258typedef Eina_Bool (*Wl_Converter_Fn_Cb) (char *target, Wl_Cnp_Selection *sel, void *data, int size, void **data_ret, int *size_ret); 258typedef Eina_Bool (*Wl_Converter_Fn_Cb) (char *target, Wl_Cnp_Selection *sel, void *data, int size, void **data_ret, int *size_ret);
259static Eina_Bool _wl_targets_converter(char *target, Wl_Cnp_Selection *sel, void *data, int size, void **data_ret, int *size_ret); 259static Eina_Bool _wl_targets_converter(char *target, Wl_Cnp_Selection *sel, void *data, int size, void **data_ret, int *size_ret);
260static Eina_Bool _wl_general_converter(char *target, Wl_Cnp_Selection *sel, void *data, int size, void **data_ret, int *size_ret); 260static Eina_Bool _wl_general_converter(char *target, Wl_Cnp_Selection *sel, void *data, int size, void **data_ret, int *size_ret);
261static Eina_Bool _wl_image_converter(char *target, Wl_Cnp_Selection *sel, void *data, int size, void **data_ret, int *size_ret);
262static Eina_Bool _wl_text_converter(char *target, Wl_Cnp_Selection *sel, void *data, int size, void **data_ret, int *size_ret); 261static Eina_Bool _wl_text_converter(char *target, Wl_Cnp_Selection *sel, void *data, int size, void **data_ret, int *size_ret);
263static Eina_Bool _wl_vcard_converter(char *target, Wl_Cnp_Selection *sel, void *data, int size, void **data_ret, int *size_ret); 262
263typedef Eina_Bool (*Wl_Notify_Handler_Cb) (Wl_Cnp_Selection *sel, Ecore_Wl_Event_Selection_Data_Ready *ev);
264static Eina_Bool _wl_notify_handler_targets(Wl_Cnp_Selection *sel, Ecore_Wl_Event_Selection_Data_Ready *ev);
265static Eina_Bool _wl_notify_handler_uri(Wl_Cnp_Selection *sel, Ecore_Wl_Event_Selection_Data_Ready *ev);
266static Eina_Bool _wl_vcard_receive(Wl_Cnp_Selection *sel, Ecore_Wl_Event_Selection_Data_Ready *ev);
267static Eina_Bool _wl_notify_handler_image(Wl_Cnp_Selection *sel, Ecore_Wl_Event_Selection_Data_Ready *ev);
268static Eina_Bool _wl_notify_handler_text(Wl_Cnp_Selection *sel, Ecore_Wl_Event_Selection_Data_Ready *ev);
264#endif 269#endif
265 270
266struct _Cnp_Atom 271struct _Cnp_Atom
@@ -277,6 +282,7 @@ struct _Cnp_Atom
277#endif 282#endif
278#ifdef HAVE_ELEMENTARY_WAYLAND 283#ifdef HAVE_ELEMENTARY_WAYLAND
279 Wl_Converter_Fn_Cb wl_converter; 284 Wl_Converter_Fn_Cb wl_converter;
285 Wl_Notify_Handler_Cb wl_notify;
280#endif 286#endif
281 287
282 void *_term; 288 void *_term;
@@ -461,6 +467,7 @@ static Cnp_Atom _atoms[CNP_N_ATOMS] = {
461#endif 467#endif
462#ifdef HAVE_ELEMENTARY_WAYLAND 468#ifdef HAVE_ELEMENTARY_WAYLAND
463 .wl_converter = _wl_targets_converter, 469 .wl_converter = _wl_targets_converter,
470 .wl_notify = _wl_notify_handler_targets,
464#endif 471#endif
465 }, 472 },
466 ARRAYINIT(CNP_ATOM_ATOM) { 473 ARRAYINIT(CNP_ATOM_ATOM) {
@@ -473,6 +480,7 @@ static Cnp_Atom _atoms[CNP_N_ATOMS] = {
473#endif 480#endif
474#ifdef HAVE_ELEMENTARY_WAYLAND 481#ifdef HAVE_ELEMENTARY_WAYLAND
475 .wl_converter = _wl_targets_converter, 482 .wl_converter = _wl_targets_converter,
483 .wl_notify = _wl_notify_handler_targets,
476#endif 484#endif
477 }, 485 },
478 ARRAYINIT(CNP_ATOM_XELM) { 486 ARRAYINIT(CNP_ATOM_XELM) {
@@ -494,6 +502,7 @@ static Cnp_Atom _atoms[CNP_N_ATOMS] = {
494#endif 502#endif
495#ifdef HAVE_ELEMENTARY_WAYLAND 503#ifdef HAVE_ELEMENTARY_WAYLAND
496 .wl_converter = _wl_general_converter, 504 .wl_converter = _wl_general_converter,
505 .wl_notify = _wl_notify_handler_uri,
497#endif 506#endif
498 }, 507 },
499 ARRAYINIT(CNP_ATOM_text_urilist) { 508 ARRAYINIT(CNP_ATOM_text_urilist) {
@@ -505,6 +514,7 @@ static Cnp_Atom _atoms[CNP_N_ATOMS] = {
505#endif 514#endif
506#ifdef HAVE_ELEMENTARY_WAYLAND 515#ifdef HAVE_ELEMENTARY_WAYLAND
507 .wl_converter = _wl_general_converter, 516 .wl_converter = _wl_general_converter,
517 .wl_notify = _wl_notify_handler_uri,
508#endif 518#endif
509 }, 519 },
510 ARRAYINIT(CNP_ATOM_text_x_vcard) { 520 ARRAYINIT(CNP_ATOM_text_x_vcard) {
@@ -515,7 +525,7 @@ static Cnp_Atom _atoms[CNP_N_ATOMS] = {
515 .x_notify = _x11_vcard_receive, 525 .x_notify = _x11_vcard_receive,
516#endif 526#endif
517#ifdef HAVE_ELEMENTARY_WAYLAND 527#ifdef HAVE_ELEMENTARY_WAYLAND
518 .wl_converter = _wl_vcard_converter, 528 .wl_notify = _wl_vcard_receive,
519#endif 529#endif
520 }, 530 },
521 ARRAYINIT(CNP_ATOM_image_png) { 531 ARRAYINIT(CNP_ATOM_image_png) {
@@ -526,7 +536,7 @@ static Cnp_Atom _atoms[CNP_N_ATOMS] = {
526 .x_notify = _x11_notify_handler_image, 536 .x_notify = _x11_notify_handler_image,
527#endif 537#endif
528#ifdef HAVE_ELEMENTARY_WAYLAND 538#ifdef HAVE_ELEMENTARY_WAYLAND
529 .wl_converter = _wl_image_converter, 539 .wl_notify = _wl_notify_handler_image,
530#endif 540#endif
531 }, 541 },
532 ARRAYINIT(CNP_ATOM_image_jpeg) { 542 ARRAYINIT(CNP_ATOM_image_jpeg) {
@@ -537,7 +547,7 @@ static Cnp_Atom _atoms[CNP_N_ATOMS] = {
537 .x_notify = _x11_notify_handler_image, 547 .x_notify = _x11_notify_handler_image,
538#endif 548#endif
539#ifdef HAVE_ELEMENTARY_WAYLAND 549#ifdef HAVE_ELEMENTARY_WAYLAND
540 .wl_converter = _wl_image_converter, 550 .wl_notify = _wl_notify_handler_image,
541#endif 551#endif
542 }, 552 },
543 ARRAYINIT(CNP_ATOM_image_bmp) { 553 ARRAYINIT(CNP_ATOM_image_bmp) {
@@ -548,7 +558,7 @@ static Cnp_Atom _atoms[CNP_N_ATOMS] = {
548 .x_notify = _x11_notify_handler_image, 558 .x_notify = _x11_notify_handler_image,
549#endif 559#endif
550#ifdef HAVE_ELEMENTARY_WAYLAND 560#ifdef HAVE_ELEMENTARY_WAYLAND
551 .wl_converter = _wl_image_converter, 561 .wl_notify = _wl_notify_handler_image,
552#endif 562#endif
553 }, 563 },
554 ARRAYINIT(CNP_ATOM_image_gif) { 564 ARRAYINIT(CNP_ATOM_image_gif) {
@@ -559,7 +569,7 @@ static Cnp_Atom _atoms[CNP_N_ATOMS] = {
559 .x_notify = _x11_notify_handler_image, 569 .x_notify = _x11_notify_handler_image,
560#endif 570#endif
561#ifdef HAVE_ELEMENTARY_WAYLAND 571#ifdef HAVE_ELEMENTARY_WAYLAND
562 .wl_converter = _wl_image_converter, 572 .wl_notify = _wl_notify_handler_image,
563#endif 573#endif
564 }, 574 },
565 ARRAYINIT(CNP_ATOM_image_tiff) { 575 ARRAYINIT(CNP_ATOM_image_tiff) {
@@ -570,7 +580,7 @@ static Cnp_Atom _atoms[CNP_N_ATOMS] = {
570 .x_notify = _x11_notify_handler_image, 580 .x_notify = _x11_notify_handler_image,
571#endif 581#endif
572#ifdef HAVE_ELEMENTARY_WAYLAND 582#ifdef HAVE_ELEMENTARY_WAYLAND
573 .wl_converter = _wl_image_converter, 583 .wl_notify = _wl_notify_handler_image,
574#endif 584#endif
575 }, 585 },
576 ARRAYINIT(CNP_ATOM_image_svg) { 586 ARRAYINIT(CNP_ATOM_image_svg) {
@@ -581,7 +591,7 @@ static Cnp_Atom _atoms[CNP_N_ATOMS] = {
581 .x_notify = _x11_notify_handler_image, 591 .x_notify = _x11_notify_handler_image,
582#endif 592#endif
583#ifdef HAVE_ELEMENTARY_WAYLAND 593#ifdef HAVE_ELEMENTARY_WAYLAND
584 .wl_converter = _wl_image_converter, 594 .wl_notify = _wl_notify_handler_image,
585#endif 595#endif
586 }, 596 },
587 ARRAYINIT(CNP_ATOM_image_xpm) { 597 ARRAYINIT(CNP_ATOM_image_xpm) {
@@ -592,7 +602,7 @@ static Cnp_Atom _atoms[CNP_N_ATOMS] = {
592 .x_notify = _x11_notify_handler_image, 602 .x_notify = _x11_notify_handler_image,
593#endif 603#endif
594#ifdef HAVE_ELEMENTARY_WAYLAND 604#ifdef HAVE_ELEMENTARY_WAYLAND
595 .wl_converter = _wl_image_converter, 605 .wl_notify = _wl_notify_handler_image,
596#endif 606#endif
597 }, 607 },
598 ARRAYINIT(CNP_ATOM_image_tga) { 608 ARRAYINIT(CNP_ATOM_image_tga) {
@@ -603,7 +613,7 @@ static Cnp_Atom _atoms[CNP_N_ATOMS] = {
603 .x_notify = _x11_notify_handler_image, 613 .x_notify = _x11_notify_handler_image,
604#endif 614#endif
605#ifdef HAVE_ELEMENTARY_WAYLAND 615#ifdef HAVE_ELEMENTARY_WAYLAND
606 .wl_converter = _wl_image_converter, 616 .wl_notify = _wl_notify_handler_image,
607#endif 617#endif
608 }, 618 },
609 ARRAYINIT(CNP_ATOM_image_ppm) { 619 ARRAYINIT(CNP_ATOM_image_ppm) {
@@ -614,7 +624,7 @@ static Cnp_Atom _atoms[CNP_N_ATOMS] = {
614 .x_notify = _x11_notify_handler_image, 624 .x_notify = _x11_notify_handler_image,
615#endif 625#endif
616#ifdef HAVE_ELEMENTARY_WAYLAND 626#ifdef HAVE_ELEMENTARY_WAYLAND
617 .wl_converter = _wl_image_converter, 627 .wl_notify = _wl_notify_handler_image,
618#endif 628#endif
619 }, 629 },
620/* 630/*
@@ -627,6 +637,7 @@ static Cnp_Atom _atoms[CNP_N_ATOMS] = {
627#endif 637#endif
628#ifdef HAVE_ELEMENTARY_WAYLAND 638#ifdef HAVE_ELEMENTARY_WAYLAND
629 .wl_converter = _wl_general_converter, 639 .wl_converter = _wl_general_converter,
640 .wl_notify = _wl_notify_handler_html,
630#endif 641#endif
631 }, 642 },
632 ARRAYINIT(CNP_ATOM_text_html) { 643 ARRAYINIT(CNP_ATOM_text_html) {
@@ -638,6 +649,7 @@ static Cnp_Atom _atoms[CNP_N_ATOMS] = {
638#endif 649#endif
639#ifdef HAVE_ELEMENTARY_WAYLAND 650#ifdef HAVE_ELEMENTARY_WAYLAND
640 .wl_converter = _wl_general_converter, 651 .wl_converter = _wl_general_converter,
652 .wl_notify = _wl_notify_handler_html,
641#endif 653#endif
642 }, 654 },
643 */ 655 */
@@ -650,6 +662,7 @@ static Cnp_Atom _atoms[CNP_N_ATOMS] = {
650#endif 662#endif
651#ifdef HAVE_ELEMENTARY_WAYLAND 663#ifdef HAVE_ELEMENTARY_WAYLAND
652 .wl_converter = _wl_text_converter, 664 .wl_converter = _wl_text_converter,
665 .wl_notify = _wl_notify_handler_text,
653#endif 666#endif
654 }, 667 },
655 ARRAYINIT(CNP_ATOM_STRING) { 668 ARRAYINIT(CNP_ATOM_STRING) {
@@ -661,6 +674,7 @@ static Cnp_Atom _atoms[CNP_N_ATOMS] = {
661#endif 674#endif
662#ifdef HAVE_ELEMENTARY_WAYLAND 675#ifdef HAVE_ELEMENTARY_WAYLAND
663 .wl_converter = _wl_text_converter, 676 .wl_converter = _wl_text_converter,
677 .wl_notify = _wl_notify_handler_text,
664#endif 678#endif
665 }, 679 },
666 ARRAYINIT(CNP_ATOM_COMPOUND_TEXT) { 680 ARRAYINIT(CNP_ATOM_COMPOUND_TEXT) {
@@ -672,6 +686,7 @@ static Cnp_Atom _atoms[CNP_N_ATOMS] = {
672#endif 686#endif
673#ifdef HAVE_ELEMENTARY_WAYLAND 687#ifdef HAVE_ELEMENTARY_WAYLAND
674 .wl_converter = _wl_text_converter, 688 .wl_converter = _wl_text_converter,
689 .wl_notify = _wl_notify_handler_text,
675#endif 690#endif
676 }, 691 },
677 ARRAYINIT(CNP_ATOM_TEXT) { 692 ARRAYINIT(CNP_ATOM_TEXT) {
@@ -683,6 +698,7 @@ static Cnp_Atom _atoms[CNP_N_ATOMS] = {
683#endif 698#endif
684#ifdef HAVE_ELEMENTARY_WAYLAND 699#ifdef HAVE_ELEMENTARY_WAYLAND
685 .wl_converter = _wl_text_converter, 700 .wl_converter = _wl_text_converter,
701 .wl_notify = _wl_notify_handler_text,
686#endif 702#endif
687 }, 703 },
688 ARRAYINIT(CNP_ATOM_text_plain_utf8) { 704 ARRAYINIT(CNP_ATOM_text_plain_utf8) {
@@ -694,6 +710,7 @@ static Cnp_Atom _atoms[CNP_N_ATOMS] = {
694#endif 710#endif
695#ifdef HAVE_ELEMENTARY_WAYLAND 711#ifdef HAVE_ELEMENTARY_WAYLAND
696 .wl_converter = _wl_text_converter, 712 .wl_converter = _wl_text_converter,
713 .wl_notify = _wl_notify_handler_text,
697#endif 714#endif
698 }, 715 },
699 ARRAYINIT(CNP_ATOM_text_plain) { 716 ARRAYINIT(CNP_ATOM_text_plain) {
@@ -705,6 +722,7 @@ static Cnp_Atom _atoms[CNP_N_ATOMS] = {
705#endif 722#endif
706#ifdef HAVE_ELEMENTARY_WAYLAND 723#ifdef HAVE_ELEMENTARY_WAYLAND
707 .wl_converter = _wl_text_converter, 724 .wl_converter = _wl_text_converter,
725 .wl_notify = _wl_notify_handler_text,
708#endif 726#endif
709 }, 727 },
710}; 728};
@@ -2509,6 +2527,7 @@ struct _Wl_Cnp_Selection
2509 Elm_Xdnd_Action action; 2527 Elm_Xdnd_Action action;
2510 2528
2511 Eina_Bool active : 1; 2529 Eina_Bool active : 1;
2530 Eina_Bool requestfinished : 1;
2512}; 2531};
2513 2532
2514static Eina_Bool 2533static Eina_Bool
@@ -2596,13 +2615,6 @@ _wl_general_converter(char *target, Wl_Cnp_Selection *sel EINA_UNUSED, void *dat
2596} 2615}
2597 2616
2598static Eina_Bool 2617static Eina_Bool
2599_wl_image_converter(char *target EINA_UNUSED, Wl_Cnp_Selection *sel EINA_UNUSED, void *data EINA_UNUSED, int size EINA_UNUSED, void **data_ret EINA_UNUSED, int *size_ret EINA_UNUSED)
2600{
2601 cnp_debug("in\n");
2602 return EINA_TRUE;
2603}
2604
2605static Eina_Bool
2606_wl_text_converter(char *target, Wl_Cnp_Selection *sel, void *data, int size, void **data_ret, int *size_ret) 2618_wl_text_converter(char *target, Wl_Cnp_Selection *sel, void *data, int size, void **data_ret, int *size_ret)
2607{ 2619{
2608 cnp_debug("in\n"); 2620 cnp_debug("in\n");
@@ -2652,13 +2664,392 @@ _wl_text_converter(char *target, Wl_Cnp_Selection *sel, void *data, int size, vo
2652 return EINA_TRUE; 2664 return EINA_TRUE;
2653} 2665}
2654 2666
2667static void
2668_wl_selection_parser(void *_data,
2669 int size,
2670 char ***ret_data,
2671 int *ret_count)
2672{
2673 char **files = NULL;
2674 int num_files = 0;
2675 char *data = _data;
2676
2677 if (data && (size > 0))
2678 {
2679 int i, is;
2680 char *tmp;
2681 char **t2;
2682
2683 if (data[size - 1])
2684 {
2685 char *t;
2686
2687 /* Isn't nul terminated */
2688 size++;
2689 t = realloc(data, size);
2690 if (!t) goto done;
2691 data = t;
2692 data[size - 1] = 0;
2693 }
2694
2695 tmp = malloc(size);
2696 if (!tmp) goto done;
2697 i = 0;
2698 is = 0;
2699 while ((is < size) && (data[is]))
2700 {
2701 if ((i == 0) && (data[is] == '#'))
2702 for (; ((data[is]) && (data[is] != '\n')); is++) ;
2703 else
2704 {
2705 if ((data[is] != '\r') &&
2706 (data[is] != '\n'))
2707 tmp[i++] = data[is++];
2708 else
2709 {
2710 while ((data[is] == '\r') || (data[is] == '\n'))
2711 is++;
2712 tmp[i] = 0;
2713 num_files++;
2714 t2 = realloc(files, num_files * sizeof(char *));
2715 if (t2)
2716 {
2717 files = t2;
2718 files[num_files - 1] = strdup(tmp);
2719 }
2720 tmp[0] = 0;
2721 i = 0;
2722 }
2723 }
2724 }
2725 if (i > 0)
2726 {
2727 tmp[i] = 0;
2728 num_files++;
2729 t2 = realloc(files, num_files * sizeof(char *));
2730 if (t2)
2731 {
2732 files = t2;
2733 files[num_files - 1] = strdup(tmp);
2734 }
2735 }
2736
2737 free(tmp);
2738 }
2739done:
2740 if (ret_data) *ret_data = files;
2741 if (ret_count) *ret_count = num_files;
2742}
2743
2744static Eina_Bool
2745_wl_dnd_drag_get_timer_cb(void *data)
2746{
2747 char *type = data;
2748
2749 ecore_wl_dnd_drag_get(ecore_wl_input_get(), type);
2750 return ECORE_CALLBACK_CANCEL;
2751}
2752
2753static Eina_Bool
2754_wl_notify_handler_targets(Wl_Cnp_Selection *sel, Ecore_Wl_Event_Selection_Data_Ready *ev)
2755{
2756 cnp_debug("In\n");
2757 if (!ev) return EINA_FALSE;
2758 char *data = ev->data;
2759 int len = ev->len;
2760 int count = 0;
2761 int i = 0, j = 0;
2762 char **data_arr = NULL;
2763
2764 _wl_selection_parser(data, len, &data_arr, &count);
2765 for (i = 0; i < CNP_N_ATOMS; i++)
2766 {
2767 Eina_Bool found = EINA_FALSE;
2768 for (j = 2; j < count; j++)
2769 {
2770 if (!strcmp(_atoms[i].name, data_arr[j]))
2771 {
2772 printf("\n%d: Match found: %s\n", __LINE__, _atoms[i].name);
2773 sel->requestfinished = EINA_FALSE;
2774 /* Since we cannot call ecore_wl_dnd_drag_get in here (it causes
2775 ecore callbacks circular dependency and makes drag_send cannot
2776 be called), we use ecore_timer to call it */
2777 ecore_timer_add(0.001, _wl_dnd_drag_get_timer_cb, _atoms[i].name);
2778 found = EINA_TRUE;
2779 break;
2780 }
2781 }
2782 if (found) break;
2783 }
2784 free(data_arr);
2785 return EINA_TRUE;
2786}
2787
2655static Eina_Bool 2788static Eina_Bool
2656_wl_vcard_converter(char *target EINA_UNUSED, Wl_Cnp_Selection *sel EINA_UNUSED, void *data, int size EINA_UNUSED, void **data_ret, int *size_ret) 2789_wl_notify_handler_uri(Wl_Cnp_Selection *sel, Ecore_Wl_Event_Selection_Data_Ready *ev)
2657{ 2790{
2658 cnp_debug("in\n"); 2791 cnp_debug("In\n");
2659 if (data_ret) *data_ret = strdup(data); 2792
2660 if (size_ret) *size_ret = strlen(data); 2793 char *p, *s, *stripstr = NULL;
2794 char *data = ev->data;
2795 Dropable *drop;
2796 const char *type = NULL;
2797 Dropable *dropable;
2798 Eina_List *l;
2799 Dropable_Cbs *cbs;
2800 Eina_Inlist *itr;
2801 Elm_Selection_Data ddata;
2802
2803 eo_do(sel->requestwidget, drop = eo_key_data_get("__elm_dropable"));
2804 if (drop)
2805 type = drop->last.type;
2806 if (!strcmp(type, "text/uri-list"))
2807 {
2808 int num_files = 0;
2809 char **files = NULL;
2810 int i, len = 0;
2811 Efreet_Uri **uri;
2812
2813 _wl_selection_parser(ev->data, ev->len, &files, &num_files);
2814 cnp_debug("got a files list\n");
2815 //files = ev->data;
2816 /*
2817 if (files->num_files > 1)
2818 {
2819 // Don't handle many items <- this makes mr bigglesworth sad :(
2820 cnp_debug("more then one file: Bailing\n");
2821 return 0;
2822 }
2823 stripstr = p = strdup(files->files[0]);
2824 */
2825
2826 uri = calloc(1, sizeof(*uri) * num_files);
2827 if (!uri) return 0;
2828
2829 for (i = 0; i < num_files ; i++)
2830 {
2831 uri[i] = efreet_uri_decode(files[i]);
2832 if (!uri[i])
2833 {
2834 /* Is there any reason why we care of URI without scheme? */
2835 if (files[i][0] != '/') continue;
2836 len += strlen(files[i]) + 1;
2837 }
2838 else
2839 {
2840 if (strcmp(uri[i]->protocol, "file"))
2841 {
2842 efreet_uri_free(uri[i]);
2843 uri[i] = NULL;
2844 continue;
2845 }
2846 len += strlen(uri[i]->path) + 1;
2847 }
2848 }
2849 p = NULL;
2850 if (len > 0)
2851 {
2852 s = stripstr = malloc(len + 1);
2853 for (i = 0; i < num_files ; i++)
2854 {
2855 if (uri[i])
2856 p = (char *)uri[i]->path;
2857 else
2858 p = files[i];
2859
2860 len = strlen(p);
2861 strcpy(s, p);
2862 if (i < (num_files - 1))
2863 {
2864 s[len] = '\n';
2865 s[len + 1] = 0;
2866 s += len + 1;
2867 }
2868 else
2869 {
2870 s[len] = 0;
2871 s += len;
2872 }
2873
2874 if (uri[i])
2875 efreet_uri_free(uri[i]);
2876 }
2877 }
2878 free(uri);
2879 }
2880 else
2881 {
2882 Efreet_Uri *uri;
2883 int len = 0;
2884
2885 p = (char *)data;
2886 uri = efreet_uri_decode(p);
2887 if (!uri)
2888 {
2889 /* Is there any reason why we care of URI without scheme? */
2890 if (p[0] == '/')
2891 len = ev->len;
2892 }
2893 else
2894 {
2895 p = (char *)uri->path;
2896 len = strlen(p);
2897 }
2898 if (len > 0)
2899 {
2900 stripstr = malloc(len + 1);
2901 if (!stripstr) return 0;
2902 memcpy(stripstr, p, len);
2903 stripstr[len] = 0;
2904 }
2905 }
2906
2907 if (!stripstr)
2908 {
2909 cnp_debug("Couldn't find a file\n");
2910 return 0;
2911 }
2912 free(savedtypes.imgfile);
2913
2914 /* FIXME: this needs to be generic: Used for all receives */
2915 EINA_LIST_FOREACH(drops, l, dropable)
2916 {
2917 if (dropable->obj == sel->requestwidget) break;
2918 }
2919 if (!dropable)
2920 {
2921 cnp_debug("Unable to find drop object");
2922 ecore_wl_dnd_drag_end(ecore_wl_input_get());
2923 return 0;
2924 }
2925 dropable = eina_list_data_get(l);
2926 ddata.x = savedtypes.x;
2927 ddata.y = savedtypes.y;
2928 ddata.data = stripstr;
2929 ddata.len = strlen(stripstr);
2930 ddata.action = sel->action;
2931 ddata.format = sel->requestformat;
2932 EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
2933 if ((cbs->types & dropable->last.format) && cbs->dropcb)
2934 cbs->dropcb(cbs->dropdata, dropable->obj, &ddata);
2935 ecore_wl_dnd_drag_end(ecore_wl_input_get());
2936 return 0;
2937}
2938
2939static Eina_Bool
2940_wl_vcard_receive(Wl_Cnp_Selection *sel, Ecore_Wl_Event_Selection_Data_Ready *ev)
2941{
2942 cnp_debug("In\n");
2661 return EINA_TRUE; 2943 return EINA_TRUE;
2944
2945 Dropable *dropable;
2946 Eina_List *l;
2947
2948 cnp_debug("vcard receive\n");
2949 Dropable_Cbs *cbs;
2950 Eina_Inlist *itr;
2951 Elm_Selection_Data ddata;
2952
2953 /* FIXME: this needs to be generic: Used for all receives */
2954 EINA_LIST_FOREACH(drops, l, dropable)
2955 {
2956 if (dropable->obj == sel->requestwidget) break;
2957 }
2958 if (!dropable)
2959 {
2960 cnp_debug("Unable to find drop object");
2961 ecore_wl_dnd_drag_end(ecore_wl_input_get());
2962 return 0;
2963 }
2964 dropable = eina_list_data_get(l);
2965 ddata.x = savedtypes.x;
2966 ddata.y = savedtypes.y;
2967 ddata.format = ELM_SEL_FORMAT_VCARD;
2968 ddata.data = ev->data;
2969 ddata.len = ev->len;
2970 ddata.action = sel->action;
2971 EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
2972 if ((cbs->types & dropable->last.format) && cbs->dropcb)
2973 cbs->dropcb(cbs->dropdata, dropable->obj, &ddata);
2974 ecore_wl_dnd_drag_end(ecore_wl_input_get());
2975 return 0;
2976}
2977
2978static Eina_Bool
2979_wl_notify_handler_image(Wl_Cnp_Selection *sel, Ecore_Wl_Event_Selection_Data_Ready *ev)
2980{
2981 cnp_debug("In\n");
2982 Tmp_Info *tmp;
2983 Eina_List *l;
2984 Dropable *dropable;
2985
2986 Elm_Selection_Data ddata;
2987
2988 tmp = _tempfile_new(ev->len);
2989 if (!tmp) goto end;
2990 memcpy(tmp->map, ev->data, ev->len);
2991 munmap(tmp->map, ev->len);
2992
2993 /* FIXME: this needs to be generic: Used for all receives */
2994 EINA_LIST_FOREACH(drops, l, dropable)
2995 {
2996 if (dropable->obj == sel->requestwidget) break;
2997 dropable = NULL;
2998 }
2999 if (dropable)
3000 {
3001 Dropable_Cbs *cbs;
3002 Eina_Inlist *itr;
3003 ddata.x = savedtypes.x;
3004 ddata.y = savedtypes.y;
3005 ddata.format = ELM_SEL_FORMAT_IMAGE;
3006 ddata.data = tmp->filename;
3007 ddata.len = strlen(tmp->filename);
3008 ddata.action = sel->action;
3009 EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
3010 if ((cbs->types & dropable->last.format) && cbs->dropcb)
3011 cbs->dropcb(cbs->dropdata, dropable->obj, &ddata);
3012 }
3013 _tmpinfo_free(tmp);
3014
3015end:
3016 ecore_wl_dnd_drag_end(ecore_wl_input_get());
3017 return 0;
3018}
3019
3020static Eina_Bool
3021_wl_notify_handler_text(Wl_Cnp_Selection *sel, Ecore_Wl_Event_Selection_Data_Ready *ev)
3022{
3023 cnp_debug("In\n");
3024
3025 Eina_List *l;
3026 Dropable *dropable;
3027
3028 Elm_Selection_Data ddata;
3029
3030 cnp_debug("drag & drop\n");
3031 /* FIXME: this needs to be generic: Used for all receives */
3032 EINA_LIST_FOREACH(drops, l, dropable)
3033 {
3034 if (dropable->obj == sel->requestwidget) break;
3035 dropable = NULL;
3036 }
3037 if (dropable)
3038 {
3039 Dropable_Cbs *cbs;
3040 Eina_Inlist *itr;
3041 ddata.x = savedtypes.x;
3042 ddata.y = savedtypes.y;
3043 ddata.format = ELM_SEL_FORMAT_TEXT;
3044 ddata.data = ev->data;
3045 ddata.len = ev->len;
3046 ddata.action = sel->action;
3047 EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
3048 if ((cbs->types & dropable->last.format) && cbs->dropcb)
3049 cbs->dropcb(cbs->dropdata, dropable->obj, &ddata);
3050 }
3051 ecore_wl_dnd_drag_end(ecore_wl_input_get());
3052 return 0;
2662} 3053}
2663 3054
2664static Eina_Bool _wl_elm_cnp_init(void); 3055static Eina_Bool _wl_elm_cnp_init(void);
@@ -2696,7 +3087,7 @@ static Eina_Bool _wl_dnd_drop(void *data EINA_UNUSED, int type EINA_UNUSED, void
2696static Eina_Bool _wl_dnd_send(void *data, int type EINA_UNUSED, void *event); 3087static Eina_Bool _wl_dnd_send(void *data, int type EINA_UNUSED, void *event);
2697static Eina_Bool _wl_dnd_receive(void *data, int type EINA_UNUSED, void *event); 3088static Eina_Bool _wl_dnd_receive(void *data, int type EINA_UNUSED, void *event);
2698static Eina_Bool _wl_dnd_end(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED); 3089static Eina_Bool _wl_dnd_end(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED);
2699static void _wl_dropable_data_handle(Wl_Cnp_Selection *sel, char *data); 3090static void _wl_dropable_data_handle(Wl_Cnp_Selection *sel, Ecore_Wl_Event_Selection_Data_Ready *data);
2700 3091
2701static Dropable *_wl_dropable_find(unsigned int win); 3092static Dropable *_wl_dropable_find(unsigned int win);
2702static void _wl_dropable_handle(Dropable *drop, Evas_Coord x, Evas_Coord y); 3093static void _wl_dropable_handle(Dropable *drop, Evas_Coord x, Evas_Coord y);
@@ -3499,8 +3890,20 @@ _wl_dnd_send(void *data, int type EINA_UNUSED, void *event)
3499 if (!strcmp(_atoms[i].name, ev->type)) 3890 if (!strcmp(_atoms[i].name, ev->type))
3500 { 3891 {
3501 cnp_debug("Found a type: %s\n", _atoms[i].name); 3892 cnp_debug("Found a type: %s\n", _atoms[i].name);
3502 _atoms[i].wl_converter(ev->type, sel, sel->selbuf, 3893 Dropable *drop;
3503 sel->buflen, &data_ret, &len_ret); 3894 eo_do(sel->requestwidget, drop = eo_key_data_get("__elm_dropable"));
3895 if (drop)
3896 drop->last.type = _atoms[i].name;
3897 if (_atoms[i].wl_converter)
3898 {
3899 _atoms[i].wl_converter(ev->type, sel, sel->selbuf,
3900 sel->buflen, &data_ret, &len_ret);
3901 }
3902 else
3903 {
3904 data_ret = strdup(sel->selbuf);
3905 len_ret = sel->buflen;
3906 }
3504 break; 3907 break;
3505 } 3908 }
3506 } 3909 }
@@ -3535,8 +3938,10 @@ _wl_dnd_receive(void *data, int type EINA_UNUSED, void *event)
3535 if (sel->requestwidget) 3938 if (sel->requestwidget)
3536 { 3939 {
3537 if (!ev->done) 3940 if (!ev->done)
3538 _wl_dropable_data_handle(sel, ev->data); 3941 {
3539 else 3942 _wl_dropable_data_handle(sel, ev);
3943 }
3944 else if (sel->requestfinished)
3540 { 3945 {
3541 evas_object_event_callback_del_full(sel->requestwidget, 3946 evas_object_event_callback_del_full(sel->requestwidget,
3542 EVAS_CALLBACK_DEL, 3947 EVAS_CALLBACK_DEL,
@@ -3587,29 +3992,12 @@ _wl_dnd_end(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSE
3587} 3992}
3588 3993
3589static void 3994static void
3590_wl_dropable_data_handle(Wl_Cnp_Selection *sel, char *data) 3995_wl_dropable_data_handle(Wl_Cnp_Selection *sel, Ecore_Wl_Event_Selection_Data_Ready *ev)
3591{ 3996{
3592 cnp_debug("In\n"); 3997 cnp_debug("In\n");
3593 Dropable *drop; 3998 Dropable *drop;
3594 Elm_Selection_Data sdata;
3595 int len = 0;
3596 char *s = NULL;
3597
3598 len = strlen(data);
3599 if (!(s = malloc(len + 1))) return;
3600 memcpy(s, data, len);
3601 s[len] = 0;
3602
3603 if (savedtypes.textreq)
3604 {
3605 savedtypes.textreq = 0;
3606 savedtypes.imgfile = s;
3607 }
3608
3609 sdata.len = len;
3610 sdata.x = savedtypes.x;
3611 sdata.y = savedtypes.y;
3612 3999
4000 sel->requestfinished = EINA_TRUE;
3613 eo_do(sel->requestwidget, drop = eo_key_data_get("__elm_dropable")); 4001 eo_do(sel->requestwidget, drop = eo_key_data_get("__elm_dropable"));
3614 if (drop) 4002 if (drop)
3615 { 4003 {
@@ -3619,23 +4007,17 @@ _wl_dropable_data_handle(Wl_Cnp_Selection *sel, char *data)
3619 { 4007 {
3620 if (cbs->types && drop->last.format) 4008 if (cbs->types && drop->last.format)
3621 { 4009 {
3622 /* If it's markup that also supports images */ 4010 int i = 0;
3623 if (cbs->types & (ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE)) 4011 for (i = 0; i < CNP_N_ATOMS; i++)
3624 { 4012 {
3625 sdata.format = ELM_SEL_FORMAT_MARKUP; 4013 if ((!strcmp(_atoms[i].name, drop->last.type))
3626 sdata.data = (char *)savedtypes.imgfile; 4014 && _atoms[i].wl_notify)
3627 } 4015 {
3628 else if (cbs->types & ELM_SEL_FORMAT_IMAGE) 4016 cnp_debug("call notify: %s\n", drop->last.type);
3629 { 4017 _atoms[i].wl_notify(sel, ev);
3630 sdata.format = ELM_SEL_FORMAT_IMAGE; 4018 return;
3631 sdata.data = (char *)savedtypes.imgfile; 4019 }
3632 }
3633 else
3634 {
3635 sdata.format = drop->last.format;
3636 sdata.data = s;
3637 } 4020 }
3638 if (cbs->dropcb) cbs->dropcb(cbs->dropdata, drop->obj, &sdata);
3639 } 4021 }
3640 } 4022 }
3641 } 4023 }