unity smart scope begins to work standalone

This commit is contained in:
Jean-Francois Dockes 2013-11-07 12:32:24 +01:00
parent 0509a79df5
commit 90723d03e4
3 changed files with 38 additions and 28 deletions

View file

@ -1,11 +1,11 @@
[Scope] [Scope]
DBusName=org.recoll.Unity.Scope.File.Recoll DBusName=org.recoll.Unity.Scope.File.Recoll
DBusPath=/org/recoll/unity/scope/file/recoll DBusPath=/org/recoll/unity/scope/file/recoll
Module=recoll.unity_recoll_daemon Module=recollscope.unity_recoll_daemon
ModuleType=python3 ModuleType=python3
Icon=/usr/share/icons/unity-icon-theme/places/svg/service-recoll.svg Icon=/usr/share/icons/unity-icon-theme/places/svg/service-recoll.svg
Keywords=recoll;doc;text; Keywords=recoll;doc;text;
Loader=/usr/share/unity-scopes/recoll/unity_recoll_daemon Loader=/usr/share/unity-scopes/recollscope/unity_recoll_daemon
RequiredMetadata= RequiredMetadata=
OptionalMetadata= OptionalMetadata=
RemoteContent=false RemoteContent=false

View file

@ -11,8 +11,8 @@ setup(name="unity-scope-recoll",
url="http://www.recoll.org", url="http://www.recoll.org",
license="GNU General Public License v3 (GPLv3)", license="GNU General Public License v3 (GPLv3)",
data_files=[ data_files=[
('share/unity-scopes/recoll', ['unity_recoll_daemon.py']), ('share/unity-scopes/recollscope', ['unity_recoll_daemon.py']),
('share/unity-scopes/recoll', ['__init__.py']), ('share/unity-scopes/recollscope', ['__init__.py']),
('share/applications', ['unity-scope-recoll.desktop']), ('share/applications', ['unity-scope-recoll.desktop']),
('share/dbus-1/services', ['unity-scope-recoll.service']), ('share/dbus-1/services', ['unity-scope-recoll.service']),
('share/icons/hicolor/48x48/apps', ['unity-scope-recoll.png']), ('share/icons/hicolor/48x48/apps', ['unity-scope-recoll.png']),

View file

@ -20,28 +20,27 @@ from gi.repository import GData
from gi.repository import Unity from gi.repository import Unity
try: try:
from recoll import rclconfig from recoll import rclconfig
hasrclconfig = True hasrclconfig = True
except: except:
hasrclconfig = False hasrclconfig = False
# As a temporary measure, we also look for rclconfig as a bare # As a temporary measure, we also look for rclconfig as a bare
# module. This is so that the intermediate releases of the lens can # module. This is so that the intermediate releases of the lens can
# ship and use rclconfig.py with the lens code # ship and use rclconfig.py with the lens code
if not hasrclconfig: if not hasrclconfig:
try: try:
import rclconfig import rclconfig
hasrclconfig = True hasrclconfig = True
except: except:
pass pass
#try: try:
#from recoll import recoll from recoll import recoll
from recoll import rclextract from recoll import rclextract
hasextract = True hasextract = True
#except: except:
# import recoll import recoll
# hasextract = False hasextract = False
print("Recoll scope: hasrclconfig %d hasextract %d\n" % (hasrclconfig, hasextract))
APP_NAME = "unity-scope-recoll" APP_NAME = "unity-scope-recoll"
LOCAL_PATH = "/usr/share/locale/" LOCAL_PATH = "/usr/share/locale/"
@ -77,15 +76,16 @@ def _get_thumbnail_path(url):
directory. We return the path only if the thumbnail does exist directory. We return the path only if the thumbnail does exist
(no generation performed)""" (no generation performed)"""
global THUMBDIRS global THUMBDIRS
print("_get_thumbnail_path", file=sys.stderr)
# Compute the thumbnail file name by encoding and hashing the url string # Compute the thumbnail file name by encoding and hashing the url string
path = url.replace("file://", "", 1) path = url[7:]
try: try:
path = "file://" + urllib.quote(path) path = "file://" + urllib.quote(path)
except: except:
#print("_get_thumbnail_path: urllib.quote failed") #print("_get_thumbnail_path: urllib.quote failed")
return None return None
#print("_get_thumbnail: encoded path: [%s]" % (path,)) print("_get_thumbnail: encoded path: [%s]" % (path,), file=sys.stderr)
thumbname = hashlib.md5(path).hexdigest() + ".png" thumbname = hashlib.md5(path).hexdigest() + ".png"
# If the "new style" directory exists, we should stop looking in # If the "new style" directory exists, we should stop looking in
@ -227,7 +227,7 @@ class RecollScopeSearch(Unity.ScopeSearchBase):
# Do the recoll thing # Do the recoll thing
try: try:
query = self.db.query() query = self.db.query()
nres = query.execute(search_string.decode(self.localecharset)) nres = query.execute(search_string)
except Exception as msg: except Exception as msg:
print("recoll query execute error: %s" % msg) print("recoll query execute error: %s" % msg)
return return
@ -238,16 +238,17 @@ class RecollScopeSearch(Unity.ScopeSearchBase):
doc = query.fetchone() doc = query.fetchone()
except: except:
break break
titleorfilename = doc.title titleorfilename = doc.title
if titleorfilename == "": if titleorfilename == "":
titleorfilename = doc.filename titleorfilename = doc.filename
# Results with an ipath get a special mime type so that they # Results with an ipath get a special mime type so that they
# get opened by starting a recoll instance. # get opened by starting a recoll instance.
mimetype, iconname = self.icon_for_type (doc) url, mimetype, iconname = self.icon_for_type (doc)
try: try:
abstract = self.db.makeDocAbstract(doc, query).encode('utf-8') abstract = self.db.makeDocAbstract(doc, query)
except: except:
break break
@ -261,8 +262,17 @@ class RecollScopeSearch(Unity.ScopeSearchBase):
else: else:
category = 1 category = 1
# result_set.add_result(
# uri=url,
# icon=iconname,
# category=category,
# result_type=Unity.ResultType.PERSONAL,
# mimetype=mimetype,
# title=titleorfilename,
# comment=abstract,
# dnd_uri=doc.url)
result_set.add_result( result_set.add_result(
url, uri=url,
icon=iconname, icon=iconname,
category=category, category=category,
result_type=Unity.ResultType.PERSONAL, result_type=Unity.ResultType.PERSONAL,
@ -323,7 +333,7 @@ class RecollScopeSearch(Unity.ScopeSearchBase):
if thumbnail: if thumbnail:
iconname = thumbnail iconname = thumbnail
else: else:
if SPEC_MIME_ICONS.has_key(doc.mimetype): if doc.mimetype in SPEC_MIME_ICONS:
iconname = SPEC_MIME_ICONS[doc.mimetype] iconname = SPEC_MIME_ICONS[doc.mimetype]
else: else:
icon = Gio.content_type_get_icon(doc.mimetype) icon = Gio.content_type_get_icon(doc.mimetype)
@ -335,7 +345,7 @@ class RecollScopeSearch(Unity.ScopeSearchBase):
iconname = iname iconname = iname
break break
return (mimetype, iconname); return (url, mimetype, iconname);
def load_scope(): def load_scope():