|
a |
|
b/src/desktop/unity-lens-recoll/bin/unity-recoll-daemon.in |
|
|
1 |
#! /usr/bin/python
|
|
|
2 |
|
|
|
3 |
# Set Python path up to load from the source code dir if we're running out
|
|
|
4 |
# of the source tree, otherwise point at the installed code
|
|
|
5 |
import sys, os
|
|
|
6 |
execpath = os.path.dirname(__file__)
|
|
|
7 |
if os.path.isfile(os.path.join(execpath, "..", "configure.ac")):
|
|
|
8 |
print "Running from source tree"
|
|
|
9 |
sys.path.insert (0, os.path.join(execpath, ".."))
|
|
|
10 |
else:
|
|
|
11 |
sys.path.insert (0, os.path.join("@DATADIR@", "unity-lens-recoll"))
|
|
|
12 |
del execpath
|
|
|
13 |
|
|
|
14 |
import recollscope.rclsearch
|
|
|
15 |
from gi.repository import GLib, GObject, Gio
|
|
|
16 |
|
|
|
17 |
# NOTE: If we used the normal 'dbus' module for Python we'll get
|
|
|
18 |
# slightly odd results because it uses a default connection
|
|
|
19 |
# to the session bus that is different from the default connection
|
|
|
20 |
# GDBus (hence libunity) will use. Meaning that the daemon name
|
|
|
21 |
# will be owned by a connection different from the one all our
|
|
|
22 |
# Dee + Unity magic is working on...
|
|
|
23 |
# Still waiting for nice GDBus bindings to land:
|
|
|
24 |
# http://www.piware.de/2011/01/na-zdravi-pygi/
|
|
|
25 |
|
|
|
26 |
#
|
|
|
27 |
# The primary bus name we grab *must* match what we specify in our .lens file
|
|
|
28 |
#
|
|
|
29 |
BUS_NAME = "org.recoll.UnityLensRecoll.Lens"
|
|
|
30 |
|
|
|
31 |
session_bus_connection = Gio.bus_get_sync (Gio.BusType.SESSION, None)
|
|
|
32 |
session_bus = Gio.DBusProxy.new_sync (session_bus_connection, 0, None,
|
|
|
33 |
'org.freedesktop.DBus',
|
|
|
34 |
'/org/freedesktop/DBus',
|
|
|
35 |
'org.freedesktop.DBus', None)
|
|
|
36 |
result = session_bus.call_sync('RequestName',
|
|
|
37 |
GLib.Variant ("(su)", (BUS_NAME, 0x4)),
|
|
|
38 |
0, -1, None)
|
|
|
39 |
|
|
|
40 |
# Unpack variant response with signature "(u)". 1 means we got it.
|
|
|
41 |
result = result.unpack()[0]
|
|
|
42 |
|
|
|
43 |
if result != 1 :
|
|
|
44 |
print >> sys.stderr, "Failed to own name %s. Bailing out." % BUS_NAME
|
|
|
45 |
raise SystemExit (1)
|
|
|
46 |
|
|
|
47 |
def create_lens ():
|
|
|
48 |
# The path for the Lens *must* also match the one in our .lens file
|
|
|
49 |
from gi.repository import Unity
|
|
|
50 |
lens = Unity.Lens.new ("/org/recoll/unitylensrecoll/lens", "recoll")
|
|
|
51 |
|
|
|
52 |
lens.props.search_hint = "Recoll search string"
|
|
|
53 |
lens.props.visible = True;
|
|
|
54 |
lens.props.search_in_global = False;
|
|
|
55 |
|
|
|
56 |
# Populate categories
|
|
|
57 |
cats = []
|
|
|
58 |
cats.append (Unity.Category.new ("Documents",
|
|
|
59 |
Gio.ThemedIcon.new("document"),
|
|
|
60 |
Unity.CategoryRenderer.HORIZONTAL_TILE))
|
|
|
61 |
lens.props.categories = cats
|
|
|
62 |
|
|
|
63 |
|
|
|
64 |
# Populate filters
|
|
|
65 |
lens.props.filters = []
|
|
|
66 |
|
|
|
67 |
# We should get the categories from the config but the python
|
|
|
68 |
# module currently has no code for this.
|
|
|
69 |
filter = Unity.RadioOptionFilter.new("rclcat", "Category",
|
|
|
70 |
Gio.ThemedIcon.new(""), False)
|
|
|
71 |
|
|
|
72 |
filter.add_option("text", "Text", None);
|
|
|
73 |
filter.add_option("spreadsheet", "Spreadsheet", None);
|
|
|
74 |
filter.add_option("presentation", "Presentation", None);
|
|
|
75 |
filter.add_option("media", "Media", None);
|
|
|
76 |
filter.add_option("message", "Message", None);
|
|
|
77 |
filter.add_option("other", "Other", None);
|
|
|
78 |
|
|
|
79 |
lens.props.filters.append(filter)
|
|
|
80 |
return lens
|
|
|
81 |
|
|
|
82 |
lens = create_lens ()
|
|
|
83 |
lens.add_local_scope (recollscope.rclsearch.Scope())
|
|
|
84 |
# add more local scopes here (remote dbus scopes added automagically)
|
|
|
85 |
lens.export ()
|
|
|
86 |
|
|
|
87 |
GObject.MainLoop().run()
|