From 9cbd7f2d09a096ad0d60757ed3873487f7c96d78 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Thu, 7 Nov 2013 12:32:24 +0100 Subject: [PATCH] unity smart scope begins to work standalone --- src/desktop/unity-scope-recoll/recoll.scope | 4 +- src/desktop/unity-scope-recoll/setup.py | 4 +- .../unity-scope-recoll/unity_recoll_daemon.py | 58 +++++++++++-------- 3 files changed, 38 insertions(+), 28 deletions(-) diff --git a/src/desktop/unity-scope-recoll/recoll.scope b/src/desktop/unity-scope-recoll/recoll.scope index 049ed97f..89f47ff7 100644 --- a/src/desktop/unity-scope-recoll/recoll.scope +++ b/src/desktop/unity-scope-recoll/recoll.scope @@ -1,11 +1,11 @@ [Scope] DBusName=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 Icon=/usr/share/icons/unity-icon-theme/places/svg/service-recoll.svg Keywords=recoll;doc;text; -Loader=/usr/share/unity-scopes/recoll/unity_recoll_daemon +Loader=/usr/share/unity-scopes/recollscope/unity_recoll_daemon RequiredMetadata= OptionalMetadata= RemoteContent=false diff --git a/src/desktop/unity-scope-recoll/setup.py b/src/desktop/unity-scope-recoll/setup.py index 8e9e9018..a68e78ef 100644 --- a/src/desktop/unity-scope-recoll/setup.py +++ b/src/desktop/unity-scope-recoll/setup.py @@ -11,8 +11,8 @@ setup(name="unity-scope-recoll", url="http://www.recoll.org", license="GNU General Public License v3 (GPLv3)", data_files=[ - ('share/unity-scopes/recoll', ['unity_recoll_daemon.py']), - ('share/unity-scopes/recoll', ['__init__.py']), + ('share/unity-scopes/recollscope', ['unity_recoll_daemon.py']), + ('share/unity-scopes/recollscope', ['__init__.py']), ('share/applications', ['unity-scope-recoll.desktop']), ('share/dbus-1/services', ['unity-scope-recoll.service']), ('share/icons/hicolor/48x48/apps', ['unity-scope-recoll.png']), diff --git a/src/desktop/unity-scope-recoll/unity_recoll_daemon.py b/src/desktop/unity-scope-recoll/unity_recoll_daemon.py index b5ee53b2..dc2a277c 100755 --- a/src/desktop/unity-scope-recoll/unity_recoll_daemon.py +++ b/src/desktop/unity-scope-recoll/unity_recoll_daemon.py @@ -20,28 +20,27 @@ from gi.repository import GData from gi.repository import Unity try: - from recoll import rclconfig - hasrclconfig = True + from recoll import rclconfig + hasrclconfig = True except: - hasrclconfig = False + hasrclconfig = False # As a temporary measure, we also look for rclconfig as a bare # module. This is so that the intermediate releases of the lens can # ship and use rclconfig.py with the lens code if not hasrclconfig: - try: - import rclconfig - hasrclconfig = True - except: - pass + try: + import rclconfig + hasrclconfig = True + except: + pass -#try: -#from recoll import recoll -from recoll import rclextract -hasextract = True -#except: -# import recoll -# hasextract = False -print("Recoll scope: hasrclconfig %d hasextract %d\n" % (hasrclconfig, hasextract)) +try: + from recoll import recoll + from recoll import rclextract + hasextract = True +except: + import recoll + hasextract = False APP_NAME = "unity-scope-recoll" 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 (no generation performed)""" global THUMBDIRS + print("_get_thumbnail_path", file=sys.stderr) # Compute the thumbnail file name by encoding and hashing the url string - path = url.replace("file://", "", 1) + path = url[7:] try: path = "file://" + urllib.quote(path) except: #print("_get_thumbnail_path: urllib.quote failed") 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" # If the "new style" directory exists, we should stop looking in @@ -227,7 +227,7 @@ class RecollScopeSearch(Unity.ScopeSearchBase): # Do the recoll thing try: query = self.db.query() - nres = query.execute(search_string.decode(self.localecharset)) + nres = query.execute(search_string) except Exception as msg: print("recoll query execute error: %s" % msg) return @@ -238,16 +238,17 @@ class RecollScopeSearch(Unity.ScopeSearchBase): doc = query.fetchone() except: break + titleorfilename = doc.title if titleorfilename == "": titleorfilename = doc.filename # Results with an ipath get a special mime type so that they # get opened by starting a recoll instance. - mimetype, iconname = self.icon_for_type (doc) + url, mimetype, iconname = self.icon_for_type (doc) try: - abstract = self.db.makeDocAbstract(doc, query).encode('utf-8') + abstract = self.db.makeDocAbstract(doc, query) except: break @@ -261,8 +262,17 @@ class RecollScopeSearch(Unity.ScopeSearchBase): else: 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( - url, + uri=url, icon=iconname, category=category, result_type=Unity.ResultType.PERSONAL, @@ -323,7 +333,7 @@ class RecollScopeSearch(Unity.ScopeSearchBase): if thumbnail: iconname = thumbnail else: - if SPEC_MIME_ICONS.has_key(doc.mimetype): + if doc.mimetype in SPEC_MIME_ICONS: iconname = SPEC_MIME_ICONS[doc.mimetype] else: icon = Gio.content_type_get_icon(doc.mimetype) @@ -335,7 +345,7 @@ class RecollScopeSearch(Unity.ScopeSearchBase): iconname = iname break - return (mimetype, iconname); + return (url, mimetype, iconname); def load_scope():