On 12.02.2010 23:23, dmg wrote:

> For evince, I think I have found a problem in the parsing of the link.
> Evince already encodes
> the URL, but it does not encode the '/', hence you will get a link like this:
> 
> emacsclient 
> 'org-protocol://remember://docview/tmp/00%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA.pdf::1'
> 
> the filename is  /tmp/00áéíóú.pdf
> 
> But emacs incorrectly stops parsing the link after tmp/

I think I have found the proper way to handle this in evince.
Check out the attached patch or pull from:

git://github.com/jboecker/evince.git

This code first retrieves the non-URI-encoded UTF-8 filename and passes
that to uri_encode. Should g_file_get_path return NULL, we abort,
because the URI specifies something in gnomes VFS layer that has no
local path, so the link would not work, anyway.

> By the way, xournal now supports store-link

Works as advertised, thanks!

The only problem I have left now is a cosmetic one: when I store a link
to, say, /tmp/test.xoj, in Org it becomes file://tmp/test.xoj instead of
file:/tmp/test.xoj. (I have patched xournal and evince to generate file:
instead of docview: links.)

This is because org-protocol-sanitize-uri is called after decoding the
string, allegedly because emacsclient compresses multiple slashes in a
row to one. However, it seems that this function should be applied
/before/ the string is URL-decoded. Is this a bug?

>From f777bca64fd23066f626bc55cee6a81d6e03dac5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20B=C3=B6cker?= <jan.boec...@jboecker.de>
Date: Sat, 13 Feb 2010 12:38:39 +0100
Subject: [PATCH 1/2] bugfix in encode_uri: cast to unsigned char to get the 
correct byte value

---
 libview/ev-view.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libview/ev-view.c b/libview/ev-view.c
index c334fdc..1130d39 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -5775,8 +5775,8 @@ static void encode_uri(gchar *encoded_uri, gint bufsize, 
const gchar *uri)
       if (k + 4 >= bufsize)
         break;
       encoded_uri[k++] = '%';
-      encoded_uri[k++] = hexa[uri[i] / 16];
-      encoded_uri[k++] = hexa[uri[i] % 16];
+      encoded_uri[k++] = hexa[(unsigned char)uri[i] / 16];
+      encoded_uri[k++] = hexa[(unsigned char)uri[i] % 16];
     }
   }
   encoded_uri[k] = 0;
-- 
1.6.6.1

>From 1003e7809fbf2823e23b8dc8c7e3b46dfad0bcd5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20B=C3=B6cker?= <jan.boec...@jboecker.de>
Date: Sat, 13 Feb 2010 12:37:31 +0100
Subject: [PATCH 2/2] URI-encode the utf-8 filename instead of a partially 
URI-encoded gnome vfs uri

---
 libview/ev-view.c |   28 ++++++++++++++++------------
 1 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/libview/ev-view.c b/libview/ev-view.c
index 1130d39..4fda860 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -5800,9 +5800,18 @@ ev_view_annotate (EvView *ev_view, gchar *uri, int page)
 
        EvDocumentInfo  *p = ev_document_get_info(ev_view->document);
 
+       // get the real file path from evince
+       GFile *gfile = g_file_new_for_uri(uri);
+       char *filePath = g_file_get_path(gfile);
+       g_object_unref (gfile);
+       if (!filePath) {
+               printf("invalid file path");
+               return;
+       }
+       
        tempSel = g_malloc(ANN_MAX_BUFFER_LEN);
        tempFileName = g_malloc(strlen(uri) * 4);
-
+       
        if (!EV_IS_SELECTION (ev_view->document))  {
                strcmp(tempSel,  ""); 
                text = "";
@@ -5811,20 +5820,13 @@ ev_view_annotate (EvView *ev_view, gchar *uri, int page)
                text = get_selected_text (ev_view);
                encode_uri(tempSel, ANN_MAX_BUFFER_LEN, text);
        }
-       /// encode filename
-#define ANN_FILE_PREFIX "file://"
-       if (strncmp(uri,ANN_FILE_PREFIX, strlen(ANN_FILE_PREFIX) ) == 0) {
-               // skip the prefix
-               encode_uri(tempFileName, 
-                          ANN_MAX_BUFFER_LEN, uri+strlen(ANN_FILE_PREFIX));
-       } else {
-               encode_uri(tempFileName, ANN_MAX_BUFFER_LEN, uri);
-       }
-
+               
+       encode_uri(tempFileName, ANN_MAX_BUFFER_LEN, filePath);
+       
        tempCommandLine = g_malloc(strlen(tempSel) + strlen(tempFileName) + 
200);
 
-       printf("remember::::%s::::%s::::%s::::%d\n", p->title, uri, text, page);
        sprintf(tempCommandLine, "emacsclient 
'org-protocol://remember://docview:%s::%d'", tempFileName, page+1);
+       printf("remember::::%s::::%s::::%s::::%d\n", p->title, filePath, text, 
page);
        printf("temp: [%s]\n", tempCommandLine);
 
        if (!g_spawn_command_line_async (tempCommandLine, &error)) {
@@ -5836,6 +5838,8 @@ ev_view_annotate (EvView *ev_view, gchar *uri, int page)
        g_free (tempSel);
        g_free (tempCommandLine);
        g_free (tempFileName);
+       g_free (filePath);
+       
 
 
 #ifdef fork
-- 
1.6.6.1

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

Reply via email to