35
36
PROVIDER_CREDITS = _('')
36
37
SVG_DIR = '/usr/share/icons/unity-icon-theme/places/svg/'
37
38
PROVIDER_ICON = SVG_DIR + 'service-firefoxbookmarks.svg'
38
DEFAULT_RESULT_ICON = SVG_DIR + 'result-help.svg'
39
DEFAULT_RESULT_ICON = 'gtk-about'
39
40
DEFAULT_RESULT_MIMETYPE = 'text/html'
40
41
DEFAULT_RESULT_TYPE = Unity.ResultType.DEFAULT
42
FIREFOX_EXECUTABLE = '/usr/bin/firefox'
41
43
BOOKMARKS_PATH = os.getenv("HOME") + "/.mozilla/firefox/"
44
BOOKMARKS_QUERY = '''SELECT moz_bookmarks.title, moz_places.url, moz_favicons.url, '%s', '%s'
45
FROM moz_bookmarks, moz_places, moz_favicons
46
WHERE moz_places.id = moz_bookmarks.fk
47
AND moz_places.favicon_id = moz_favicons.id
48
AND moz_bookmarks.title is not null
49
AND moz_places.favicon_id is not null
50
AND moz_bookmarks.type = 1
51
AND (moz_bookmarks.title LIKE '%%%s%%' OR moz_places.url LIKE '%%%s%%')
52
ORDER BY moz_bookmarks.lastModified;'''
43
54
c1 = {'id': 'bookmarks',
44
55
'name': _('Bookmarks'),
68
79
filename = dbfile.replace('/places.sqlite', '')
69
80
file_name, profile_name = os.path.splitext(filename)
70
81
profile_name = profile_name[1:]
71
sqlite_query = '''SELECT moz_bookmarks.title, moz_places.url, moz_favicons.url, '%s'
72
FROM moz_bookmarks, moz_places, moz_favicons
73
WHERE moz_places.id = moz_bookmarks.fk
74
AND moz_places.favicon_id = moz_favicons.id
75
AND moz_bookmarks.title is not null
76
AND moz_places.favicon_id is not null
77
AND moz_bookmarks.type = 1
78
ORDER BY moz_bookmarks.lastModified;''' % profile_name
82
sqlite_query = BOOKMARKS_QUERY % (profile_name, dbfile, search, search)
80
84
conn = sqlite3.connect(dbfile)
81
85
connection = conn.cursor()
82
86
connection.execute(sqlite_query)
94
98
Search for help documents matching the search string
97
bookmarks = get_bookmarks_from_firefox(BOOKMARKS_PATH)
101
bookmarks = get_bookmarks_from_firefox(BOOKMARKS_PATH, search)
99
103
for bookmark in bookmarks:
100
104
# Stop Firefox's smart bookmark folders from showing up
101
105
if not bookmark[1].find("place:") == -1:
104
if bookmark[2].startswith("chrome:"):
105
icon = Gio.ThemedIcon.new("firefox").to_string()
109
# Search bookmark names for matches
110
if not bookmark[0].lower().find(search.lower()) == -1:
111
results.append({'uri': bookmark[1],
114
'title': bookmark[0],
115
'comment': bookmark[1],
116
'user':GLib.Variant('s', bookmark[3])})
119
# Search bookmark urls for matches
120
if not bookmark[1].lower().find(search.lower()) == -1:
121
results.append({'uri': bookmark[1],
124
'title': bookmark[0],
125
'comment': bookmark[1],
126
'user':GLib.Variant('s', bookmark[3])})
107
path = bookmark[4].replace('places.sqlite', 'thumbnails/')
108
icon = '%s%s.png' % (path, hashlib.md5(bookmark[1].encode()).hexdigest())
109
if not os.path.exists(icon):
111
results.append({'uri': bookmark[1],
114
'title': bookmark[0],
115
'user': GLib.Variant('s', bookmark[3])})
130
def activate(scope, uri):
119
def activate(result, metadata, id):
132
121
Open the url in the default webbrowser
134
123
uri: The url to be opened
137
return Unity.ActivationResponse(handled=Unity.HandledType.HIDE_DASH, goto_uri='')
125
parameters = [FIREFOX_EXECUTABLE, result.uri]
126
GLib.spawn_async(parameters)
127
return Unity.ActivationResponse(handled=Unity.HandledType.HIDE_DASH, goto_uri=None)
130
class Preview(Unity.ResultPreviewer):
132
Creates the preview for the result
136
Create a preview and return it
138
preview = Unity.GenericPreview.new(self.result.title, '', None)
139
preview.props.subtitle = self.result.uri
141
if os.path.exists(self.result.icon_hint):
142
preview.props.image_source_uri = 'file://' + self.result.icon_hint
144
preview.props.image = Gio.ThemedIcon.new('gtk-about')
145
show_action = Unity.PreviewAction.new("show", _("Show"), None)
146
preview.add_action(show_action)
140
149
# Classes below this point establish communication
141
150
# with Unity, you probably shouldn't modify them.
170
179
i['comment'] = ''
171
180
if not 'dnd_uri' in i or not i['dnd_uri'] or i['dnd_uri'] == '':
172
181
i['dnd_uri'] = i['uri']
176
for m in EXTRA_METADATA:
178
i['metadata'][e] = i[e]
179
i['metadata']['provider_credits'] = GLib.Variant('s', PROVIDER_CREDITS)
180
result = Unity.ScopeResult.create(str(i['uri']), str(i['icon']),
181
i['category'], i['result_type'],
182
str(i['mimetype']), str(i['title']),
183
str(i['comment']), str(i['dnd_uri']),
185
result_set.add_result(result)
182
i['provider_credits'] = GLib.Variant('s', PROVIDER_CREDITS)
183
result_set.add_result(**i)
186
184
except Exception as error:
238
236
se = MySearch(search_context)
239
def do_activate(self, result, metadata, id):
240
return activate(result, metadata, id)
242
def do_create_previewer(self, result, metadata):
244
Creates a preview when a resut is right-clicked
246
result_preview = Preview()
247
result_preview.set_scope_result(result)
248
result_preview.set_search_metadata(metadata)
249
return result_preview
242
252
def load_scope():