|
a/src/desktop/unity-scope-recoll/unity_recoll_daemon.py |
|
b/src/desktop/unity-scope-recoll/unity_recoll_daemon.py |
|
... |
|
... |
108 |
# Where the thumbnails live:
|
108 |
# Where the thumbnails live:
|
109 |
XDGCACHE = os.getenv('XDG_CACHE_DIR', os.path.expanduser("~/.cache"))
|
109 |
XDGCACHE = os.getenv('XDG_CACHE_DIR', os.path.expanduser("~/.cache"))
|
110 |
THUMBDIRS = [os.path.join(XDGCACHE, "thumbnails"),
|
110 |
THUMBDIRS = [os.path.join(XDGCACHE, "thumbnails"),
|
111 |
os.path.expanduser("~/.thumbnails")]
|
111 |
os.path.expanduser("~/.thumbnails")]
|
112 |
|
112 |
|
|
|
113 |
def url_encode_for_thumb(in_s, offs):
|
|
|
114 |
h = b"0123456789ABCDEF"
|
|
|
115 |
out = in_s[:offs]
|
|
|
116 |
for i in range(offs, len(in_s)):
|
|
|
117 |
c = in_s[i]
|
|
|
118 |
if c <= 0x20 or c >= 0x7f or in_s[i] in b'"#%;<>?[\\]^`{|}':
|
|
|
119 |
out += bytes('%', 'ascii');
|
|
|
120 |
out += bytes(chr(h[(c >> 4) & 0xf]), 'ascii')
|
|
|
121 |
out += bytes(chr(h[c & 0xf]), 'ascii')
|
|
|
122 |
else:
|
|
|
123 |
out += bytes(chr(c), 'ascii')
|
|
|
124 |
pass
|
|
|
125 |
return out
|
|
|
126 |
|
113 |
def _get_thumbnail_path(url):
|
127 |
def _get_thumbnail_path(url):
|
114 |
"""Look for a thumbnail for the input url, according to the
|
128 |
"""Look for a thumbnail for the input url, according to the
|
115 |
freedesktop thumbnail storage standard. The input 'url' always
|
129 |
freedesktop thumbnail storage standard. The input 'url' always
|
116 |
begins with file:// and is unencoded. We encode it properly
|
130 |
begins with file:// and is binary. We encode it properly
|
117 |
and compute the path inside the thumbnail storage
|
131 |
and compute the path inside the thumbnail storage
|
118 |
directory. We return the path only if the thumbnail does exist
|
132 |
directory. We return the path only if the thumbnail does exist
|
119 |
(no generation performed)"""
|
133 |
(no generation performed)"""
|
120 |
global THUMBDIRS
|
134 |
global THUMBDIRS
|
121 |
|
135 |
|
122 |
# Compute the thumbnail file name by encoding and hashing the url string
|
136 |
# Compute the thumbnail file name by encoding and hashing the url string
|
123 |
path = url[7:]
|
|
|
124 |
try:
|
137 |
try:
|
125 |
path = "file://" + urllib.parse.quote_from_bytes(path)
|
138 |
url = url_encode_for_thumb(url, 7)
|
126 |
except Exception as msg:
|
139 |
except Exception as msg:
|
127 |
print("_get_thumbnail_path: urllib.parse.quote failed: %s" % msg,
|
140 |
print("_get_thumbnail_path: url encode failed: %s" % msg,
|
128 |
file=sys.stderr)
|
141 |
file=sys.stderr)
|
129 |
return ""
|
142 |
return ""
|
130 |
#print("_get_thumbnail: encoded path: [%s]" % path, file=sys.stderr)
|
143 |
#print("_get_thumbnail: encoded path: [%s]" % url, file=sys.stderr)
|
131 |
thumbname = hashlib.md5(path.encode('utf-8')).hexdigest() + ".png"
|
144 |
thumbname = hashlib.md5(url).hexdigest() + ".png"
|
132 |
|
145 |
|
133 |
# If the "new style" directory exists, we should stop looking in
|
146 |
# If the "new style" directory exists, we should stop looking in
|
134 |
# the "old style" one (there might be interesting files in there,
|
147 |
# the "old style" one (there might be interesting files in there,
|
135 |
# but they may be stale, so it's best to not touch them). We do
|
148 |
# but they may be stale, so it's best to not touch them). We do
|
136 |
# this semi-dynamically so that we catch things up if the
|
149 |
# this semi-dynamically so that we catch things up if the
|