Switch to unified view

a/src/desktop/unity-scope-recoll/unity_recoll_daemon.py b/src/desktop/unity-scope-recoll/unity_recoll_daemon.py
...
...
18
from gi.repository import Accounts, Signon
18
from gi.repository import Accounts, Signon
19
from gi.repository import GData
19
from gi.repository import GData
20
from gi.repository import Unity
20
from gi.repository import Unity
21
21
22
try:
22
try:
23
    from recoll import rclconfig
23
  from recoll import rclconfig
24
    hasrclconfig = True
24
  hasrclconfig = True
25
except:
25
except:
26
    hasrclconfig = False
26
  hasrclconfig = False
27
# As a temporary measure, we also look for rclconfig as a bare
27
# As a temporary measure, we also look for rclconfig as a bare
28
# module. This is so that the intermediate releases of the lens can
28
# module. This is so that the intermediate releases of the lens can
29
# ship and use rclconfig.py with the lens code
29
# ship and use rclconfig.py with the lens code
30
if not hasrclconfig:
30
if not hasrclconfig:
31
    try:
31
  try:
32
        import rclconfig
32
    import rclconfig
33
        hasrclconfig = True
33
    hasrclconfig = True
34
    except:
34
  except:
35
        pass
35
    pass
36
    
36
    
37
#try:
37
try:
38
#from recoll import recoll
38
  from recoll import recoll
39
from recoll import rclextract
39
  from recoll import rclextract
40
hasextract = True
40
  hasextract = True
41
#except:
41
except:
42
#    import recoll
42
  import recoll
43
#    hasextract = False
43
  hasextract = False
44
print("Recoll scope: hasrclconfig %d hasextract %d\n" % (hasrclconfig, hasextract))
45
44
46
APP_NAME = "unity-scope-recoll"
45
APP_NAME = "unity-scope-recoll"
47
LOCAL_PATH = "/usr/share/locale/"
46
LOCAL_PATH = "/usr/share/locale/"
48
47
49
locale.setlocale(locale.LC_ALL, '')
48
locale.setlocale(locale.LC_ALL, '')
...
...
75
    begins with file:// and is unencoded. We encode it properly
74
    begins with file:// and is unencoded. We encode it properly
76
    and compute the path inside the thumbnail storage
75
    and compute the path inside the thumbnail storage
77
    directory. We return the path only if the thumbnail does exist
76
    directory. We return the path only if the thumbnail does exist
78
    (no generation performed)"""
77
    (no generation performed)"""
79
    global THUMBDIRS
78
    global THUMBDIRS
79
    print("_get_thumbnail_path", file=sys.stderr)
80
80
81
    # Compute the thumbnail file name by encoding and hashing the url string
81
    # Compute the thumbnail file name by encoding and hashing the url string
82
    path = url.replace("file://", "", 1)
82
    path = url[7:]
83
    try:
83
    try:
84
        path = "file://" + urllib.quote(path)
84
        path = "file://" + urllib.quote(path)
85
    except:
85
    except:
86
        #print("_get_thumbnail_path: urllib.quote failed")
86
        #print("_get_thumbnail_path: urllib.quote failed")
87
        return None
87
        return None
88
    #print("_get_thumbnail: encoded path: [%s]" % (path,))
88
    print("_get_thumbnail: encoded path: [%s]" % (path,), file=sys.stderr)
89
    thumbname = hashlib.md5(path).hexdigest() + ".png"
89
    thumbname = hashlib.md5(path).hexdigest() + ".png"
90
90
91
    # If the "new style" directory exists, we should stop looking in
91
    # If the "new style" directory exists, we should stop looking in
92
    # the "old style" one (there might be interesting files in there,
92
    # the "old style" one (there might be interesting files in there,
93
    # but they may be stale, so it's best to not touch them). We do
93
    # but they may be stale, so it's best to not touch them). We do
...
...
225
      " ".join((search_string, catgf, datef))
225
      " ".join((search_string, catgf, datef))
226
    
226
    
227
    # Do the recoll thing
227
    # Do the recoll thing
228
    try:
228
    try:
229
      query = self.db.query()
229
      query = self.db.query()
230
      nres = query.execute(search_string.decode(self.localecharset))
230
      nres = query.execute(search_string)
231
    except Exception as msg:
231
    except Exception as msg:
232
      print("recoll query execute error: %s" % msg)
232
      print("recoll query execute error: %s" % msg)
233
      return
233
      return
234
234
235
    actual_results = 0
235
    actual_results = 0
236
    for i in range(nres):
236
    for i in range(nres):
237
      try:
237
      try:
238
        doc = query.fetchone()
238
        doc = query.fetchone()
239
      except:
239
      except:
240
        break
240
        break
241
241
      titleorfilename = doc.title
242
      titleorfilename = doc.title
242
      if titleorfilename == "":
243
      if titleorfilename == "":
243
        titleorfilename = doc.filename
244
        titleorfilename = doc.filename
244
245
245
      # Results with an ipath get a special mime type so that they
246
      # Results with an ipath get a special mime type so that they
246
      # get opened by starting a recoll instance.
247
      # get opened by starting a recoll instance.
247
      mimetype, iconname = self.icon_for_type (doc)
248
      url, mimetype, iconname = self.icon_for_type (doc)
248
249
249
      try:
250
      try:
250
        abstract = self.db.makeDocAbstract(doc, query).encode('utf-8')
251
        abstract = self.db.makeDocAbstract(doc, query)
251
      except:
252
      except:
252
        break
253
        break
253
254
254
      # Ok, I don't understand this category thing for now...
255
      # Ok, I don't understand this category thing for now...
255
      if is_global:
256
      if is_global:
...
...
259
                "application/x-fsdirectory":
260
                "application/x-fsdirectory":
260
          category = 3
261
          category = 3
261
        else:
262
        else:
262
          category = 1
263
          category = 1
263
264
265
#      result_set.add_result(
266
#        uri=url,
267
#        icon=iconname,
268
#        category=category,
269
#        result_type=Unity.ResultType.PERSONAL,
270
#        mimetype=mimetype,
271
#        title=titleorfilename,
272
#        comment=abstract,
273
#        dnd_uri=doc.url)
264
      result_set.add_result(
274
      result_set.add_result(
265
        url,
275
        uri=url,
266
        icon=iconname,
276
        icon=iconname,
267
        category=category,
277
        category=category,
268
        result_type=Unity.ResultType.PERSONAL,
278
        result_type=Unity.ResultType.PERSONAL,
269
        mimetype=mimetype,
279
        mimetype=mimetype,
270
        title=titleorfilename,
280
        title=titleorfilename,
...
...
321
331
322
    iconname = None
332
    iconname = None
323
    if thumbnail:
333
    if thumbnail:
324
      iconname = thumbnail
334
      iconname = thumbnail
325
    else:
335
    else:
326
      if SPEC_MIME_ICONS.has_key(doc.mimetype):
336
      if doc.mimetype in SPEC_MIME_ICONS:
327
        iconname = SPEC_MIME_ICONS[doc.mimetype]
337
        iconname = SPEC_MIME_ICONS[doc.mimetype]
328
      else:
338
      else:
329
        icon = Gio.content_type_get_icon(doc.mimetype)
339
        icon = Gio.content_type_get_icon(doc.mimetype)
330
        if icon:
340
        if icon:
331
          # At least on Quantal, get_names() sometimes returns
341
          # At least on Quantal, get_names() sometimes returns
...
...
333
          for iname in icon.get_names():
343
          for iname in icon.get_names():
334
            if iname != '(null)':
344
            if iname != '(null)':
335
              iconname = iname
345
              iconname = iname
336
              break
346
              break
337
347
338
    return (mimetype, iconname);
348
    return (url, mimetype, iconname);
339
349
340
350
341
def load_scope():
351
def load_scope():
342
  return RecollScope()
352
  return RecollScope()
343
353