From 204f09a2d27e1be00c45c1e927df3b333e8495e0 Mon Sep 17 00:00:00 2001 From: Brett Nash Date: Sat, 8 Jan 2011 04:55:31 +0000 Subject: [PATCH] Add support for file:/// URIs in cut and paste and persistent URIs/ Patch original from Hyoyoung Chang. Modified by me a lot, with some extra debug. Also I removed the sizeof(char). That was defined to be one before most of us where born. SVN revision: 55986 --- src/lib/elm_cnp_helper.c | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/src/lib/elm_cnp_helper.c b/src/lib/elm_cnp_helper.c index 99d4b75..22a8939 100644 --- a/src/lib/elm_cnp_helper.c +++ b/src/lib/elm_cnp_helper.c @@ -12,6 +12,7 @@ //#define DEBUGON 1 + #ifdef DEBUGON # define cnp_debug(x...) fprintf(stderr, __FILE__": " x) #else @@ -1073,9 +1074,9 @@ pasteimage_alloc(const char *file, int pathlen) if (file) { if (strstr(file,"file://")) file += prefixlen; - filebuf = alloca(sizeof(char) * (pathlen - prefixlen + 1)); - strncpy(filebuf, file, pathlen - prefixlen); - filebuf[pathlen-prefixlen] = '\0'; + filebuf = alloca(pathlen + 1); + strncpy(filebuf, file, pathlen); + filebuf[pathlen] = 0; pi->file = strdup(filebuf); } @@ -1117,16 +1118,20 @@ pasteimage_provider_set(Evas_Object *entry) static Eina_Bool pasteimage_append(Paste_Image *pi, Evas_Object *entry) { - char entrytag[256]; - + char *entrytag; + int len; + static const char *tagstring = ""; + if (!pi) return EINA_FALSE; if (!entry) return EINA_FALSE; pasteimage_provider_set(entry); + len = strlen(tagstring)+strlen(pi->file); + pastedimages = eina_list_append(pastedimages, pi); - snprintf(entrytag, sizeof(entrytag), - "", pi->tag); + entrytag = alloca(len + 1); + snprintf(entrytag, len + 1, tagstring, pi->file); elm_entry_entry_insert(entry, entrytag); return EINA_TRUE; @@ -1344,11 +1349,14 @@ found: if (i == CNP_ATOM_text_urilist) { - cnp_debug("We found a URI... (%scached)\n", savedtypes.pi ? "" : "not "); + cnp_debug("We found a URI... (%scached) %s\n", + savedtypes.pi ? "" : "not ", + savedtypes.pi->file); if (savedtypes.pi) { - char entrytag[100]; - + char *entrytag; + static const char *tagstring = ""; ddata.x = savedtypes.x; ddata.y = savedtypes.y; @@ -1359,27 +1367,32 @@ found: ddata.data = (char *)savedtypes.pi->file; dropable->dropcb(dropable->cbdata, dropable->obj, &ddata); ecore_x_dnd_send_finished(); - + pasteimage_free(savedtypes.pi); savedtypes.pi = NULL; - + return EINA_TRUE; } else if (dropable->types & ELM_SEL_FORMAT_MARKUP) { + int len; ddata.format = ELM_SEL_FORMAT_MARKUP; pasteimage_provider_set(dropable->obj); - + pastedimages = eina_list_append(pastedimages, savedtypes.pi); - snprintf(entrytag, sizeof(entrytag), - "", - savedtypes.pi->tag); + len = strlen(tagstring) + strlen(savedtypes.pi->file); + entrytag = alloca(len + 1); + snprintf(entrytag, len + 1, tagstring, savedtypes.pi->file); ddata.data = entrytag; cnp_debug("Insert %s\n", (char *)ddata.data); dropable->dropcb(dropable->cbdata, dropable->obj, &ddata); ecore_x_dnd_send_finished(); return EINA_TRUE; } + else + { + cnp_debug("Umm,, dropped that\n"); + } } else if (savedtypes.textreq) { -- 2.7.4