elm cnp/Wl: Remove duplicated data send callback 74/84774/2 accepted/tizen/common/20160826.142851 submit/tizen/20160826.104819
authorThiep Ha <thiepha@gmail.com>
Tue, 3 May 2016 09:44:16 +0000 (09:44 +0000)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Fri, 26 Aug 2016 02:23:03 +0000 (19:23 -0700)
If we do drag & drop and then do copy & paste, both _wl_selection_send
and _wl_dnd_send are called for one action (dnd or cnp). It is reduntdant.
We only need one callback to handle two cases dnd and cnp.

Change-Id: I991f778c3748e03cc4590d49a7b99b43a9ffc891

src/lib/elm_cnp.c

index 784bd45..a5f1fc6 100644 (file)
@@ -2451,7 +2451,6 @@ static Eina_Bool _wl_dnd_position(void *data EINA_UNUSED, int type EINA_UNUSED,
 static Eina_Bool _wl_dnd_drop(void *data EINA_UNUSED, int type EINA_UNUSED, void *event);
 /* static Eina_Bool _wl_dnd_offer(void *data EINA_UNUSED, int type EINA_UNUSED, void *event); */
 
-static Eina_Bool _wl_dnd_send(void *data, int type EINA_UNUSED, void *event);
 static Eina_Bool _wl_dnd_receive(void *data, int type EINA_UNUSED, void *event);
 static Eina_Bool _wl_dnd_end(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED);
 static void _wl_dropable_data_handle(Wl_Cnp_Selection *sel, Ecore_Wl_Event_Selection_Data_Ready *ev);
@@ -3149,18 +3148,27 @@ _wl_elm_cnp_selection_clear(Evas_Object *obj, Elm_Sel_Type selection EINA_UNUSED
 }
 
 static Eina_Bool
-_wl_selection_send(void *udata, int type EINA_UNUSED, void *event)
+_wl_selection_send(void *data, int type EINA_UNUSED, void *event)
 {
    cnp_debug("In\n");
    char *buf;
    int ret, len_remained;
    int len_written = 0;
-   Wl_Cnp_Selection *sel = udata;
-   Ecore_Wl_Event_Data_Source_Send *ev = event;
+   Wl_Cnp_Selection *sel;
+   Ecore_Wl_Event_Data_Source_Send *ev;
+   void *data_ret = NULL;
+   int len_ret = 0;
+   int i = 0;
+
+   _wl_elm_cnp_init();
+   cnp_debug("In\n");
+   ev = event;
+   sel = data;
+
    // TIZEN ONLY(20160627): support multiple selection types' buffer
    // use priority: dnd->clipboard->primary->secondary
    sel = NULL;
-   Wl_Cnp_Selection *sels = udata;
+   Wl_Cnp_Selection *sels = data;
    if (sels[ELM_SEL_TYPE_XDND].active)
      {
         sel = sels + ELM_SEL_TYPE_XDND;
@@ -3184,12 +3192,34 @@ _wl_selection_send(void *udata, int type EINA_UNUSED, void *event)
    if (!sel) return EINA_FALSE;
    //
 
-   _wl_elm_cnp_init();
+   for (i = 0; i < CNP_N_ATOMS; i++)
+     {
+        if (!strcmp(_atoms[i].name, ev->type))
+          {
+             cnp_debug("Found a type: %s\n", _atoms[i].name);
+             Dropable *drop;
+             eo_do(sel->requestwidget, drop = eo_key_data_get("__elm_dropable"));
+             if (drop)
+               drop->last.type = _atoms[i].name;
+             if (_atoms[i].wl_converter)
+               {
+                  _atoms[i].wl_converter(ev->type, sel, sel->selbuf,
+                                         sel->buflen, &data_ret, &len_ret);
+               }
+             else
+               {
+                  data_ret = strdup(sel->selbuf);
+                  len_ret = sel->buflen;
+               }
+             break;
+          }
+     }
 
-   len_remained = sel->buflen;
-   buf = sel->selbuf;
+   len_remained = len_ret;
+   buf = data_ret;
+   cnp_debug("write: %s", buf);
 
-   while (len_written < sel->buflen)
+   while (len_written < len_ret)
      {
         ret = write(ev->fd, buf, len_remained);
         if (ret == -1) break;
@@ -3197,6 +3227,7 @@ _wl_selection_send(void *udata, int type EINA_UNUSED, void *event)
         len_written += ret;
         len_remained -= ret;
      }
+   free(data_ret);
 
    close(ev->fd);
    return ECORE_CALLBACK_PASS_ON;
@@ -3481,9 +3512,7 @@ _wl_elm_dnd_init(void)
 
    text_uri = eina_stringshare_add("text/uri-list");
 
-   ecore_event_handler_add(ECORE_WL_EVENT_DATA_SOURCE_SEND,
-                           //_wl_dnd_send, &wl_cnp_selection);// TIZEN ONLY(20160627)
-                           _wl_dnd_send, &wl_cnp_selections);// TIZEN ONLY(20160627)
+   _wl_elm_cnp_init();
    ecore_event_handler_add(ECORE_WL_EVENT_SELECTION_DATA_READY,
                            //_wl_dnd_receive, &wl_cnp_selection);// TIZEN ONLY(20160627)
                            _wl_dnd_receive, &wl_cnp_selections);// TIZEN ONLY(20160627)
@@ -3978,89 +4007,6 @@ _wl_dnd_drop(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
 }
 
 static Eina_Bool
-_wl_dnd_send(void *data, int type EINA_UNUSED, void *event)
-{
-   char *buf;
-   int ret, len_remained;
-   int len_written = 0;
-   Wl_Cnp_Selection *sel;
-   Ecore_Wl_Event_Data_Source_Send *ev;
-   void *data_ret = NULL;
-   int len_ret = 0;
-   int i = 0;
-
-   cnp_debug("In\n");
-   ev = event;
-   // TIZEN ONLY(20160627): support multiple selection types' buffer
-   Wl_Cnp_Selection *sels = data;
-   sel = NULL;
-   //use priority: dnd->clipboard->primary->secondary
-   if (sels[ELM_SEL_TYPE_XDND].active)
-     {
-        sel = sels + ELM_SEL_TYPE_XDND;
-        cnp_debug("dnd type\n");
-     }
-   else if (sels[ELM_SEL_TYPE_CLIPBOARD].active)
-     {
-        sel = sels + ELM_SEL_TYPE_CLIPBOARD;
-        cnp_debug("Clipboard type\n");
-     }
-   else if (sels[ELM_SEL_TYPE_SECONDARY].active)
-     {
-        sel = sels + ELM_SEL_TYPE_SECONDARY;
-        cnp_debug("Secondary type\n");
-     }
-   else
-     {
-        sel = sels + ELM_SEL_TYPE_PRIMARY;
-        cnp_debug("Primary type\n");
-     }
-   if (!sel) return EINA_FALSE;
-   //sel = data;
-   //
-
-   for (i = 0; i < CNP_N_ATOMS; i++)
-     {
-        if (!strcmp(_atoms[i].name, ev->type))
-          {
-             cnp_debug("Found a type: %s\n", _atoms[i].name);
-             Dropable *drop;
-             eo_do(sel->requestwidget, drop = eo_key_data_get("__elm_dropable"));
-             if (drop)
-               drop->last.type = _atoms[i].name;
-             if (_atoms[i].wl_converter)
-               {
-                  _atoms[i].wl_converter(ev->type, sel, sel->selbuf,
-                                         sel->buflen, &data_ret, &len_ret);
-               }
-             else
-               {
-                  data_ret = strdup(sel->selbuf);
-                  len_ret = sel->buflen;
-               }
-             break;
-          }
-     }
-
-   len_remained = len_ret;
-   buf = data_ret;
-   cnp_debug("write: %s\n", buf);
-
-   while (len_written < len_ret)
-     {
-        ret = write(ev->fd, buf, len_remained);
-        if (ret == -1) break;
-        buf += ret;
-        len_written += ret;
-        len_remained -= ret;
-     }
-   free(data_ret);
-
-   close(ev->fd);
-   return ECORE_CALLBACK_PASS_ON;
-}
-
-static Eina_Bool
 _wl_dnd_receive(void *data, int type EINA_UNUSED, void *event)
 {
    Wl_Cnp_Selection *sel;