Merge lp:~davidc3/unity-scope-openclipart/previews into lp:unity-scope-openclipart

Proposed by David Callé
Status: Merged
Approved by: Michal Hruby
Approved revision: 23
Merged at revision: 22
Proposed branch: lp:~davidc3/unity-scope-openclipart/previews
Merge into: lp:unity-scope-openclipart
Diff against target: 121 lines (+49/-17)
2 files modified
data/openclipart.scope.in (+1/-1)
src/unity_openclipart_daemon.py (+48/-16)
To merge this branch: bzr merge lp:~davidc3/unity-scope-openclipart/previews
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Michal Hruby (community) Approve
Review via email: mp+160393@code.launchpad.net

Commit message

Add previews

Description of the change

Implement previews:
- License info
- Open in Inkscape action if installed

http://ubuntuone.com/7mJr5n5sKEf3qmZllPvulB

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michal Hruby (mhr3) wrote :

113 + GLib.spawn_async([shutil.which("inkscape"), result.metadata['resource'].get_string().replace(' ', '%20')])

Please use a safer method to convert the string into a valid uri. (Gio.file_new_for_uri(..).get_uri())

93 + if shutil.which("inkscape"):

Perhaps check if the resource if not empty string first?

82 + if self.result.metadata and 'resource' in self.result.metadata and self.result.metadata['resource'].get_string() != '':
83 + thumb = Gio.FileIcon.new(Gio.file_new_for_uri(self.result.metadata['resource'].get_string()))
84 + else:
85 + thumb = Gio.FileIcon.new(Gio.file_new_for_uri(self.result.icon_hint))
86 + preview.props.image = thumb

Why don't you do this first and pass thumb to GenericPreview constructor?

review: Needs Fixing
23. By David Callé

Fix review issues

Revision history for this message
Michal Hruby (mhr3) wrote :

+1

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/openclipart.scope.in'
2--- data/openclipart.scope.in 2013-03-15 17:29:38 +0000
3+++ data/openclipart.scope.in 2013-04-23 15:45:03 +0000
4@@ -4,7 +4,7 @@
5 Icon=
6 _Keywords=openclipart;clipart;svg;vector;
7 RequiredMetadata=
8-OptionalMetadata=published[s];author[s];
9+OptionalMetadata=published[s];author[s];resource[s];
10 Loader=/usr/share/unity-scopes/openclipart/unity_openclipart_daemon.py
11 RemoteContent=true
12 Type=graphics
13
14=== modified file 'src/unity_openclipart_daemon.py'
15--- src/unity_openclipart_daemon.py 2013-03-19 22:40:52 +0000
16+++ src/unity_openclipart_daemon.py 2013-04-23 15:45:03 +0000
17@@ -19,6 +19,7 @@
18 import urllib
19 import feedparser
20 import gettext
21+import shutil
22
23 APP_NAME = 'unity-scope-openclipart'
24 LOCAL_PATH = '/usr/share/locale/'
25@@ -52,7 +53,10 @@
26 m2 = {'id' :'author',
27 'type' :'s',
28 'field':Unity.SchemaFieldType.OPTIONAL}
29-EXTRA_METADATA = [m1, m2]
30+m3 = {'id' :'resource',
31+ 'type' :'s',
32+ 'field':Unity.SchemaFieldType.OPTIONAL}
33+EXTRA_METADATA = [m1, m2, m3]
34
35 def search(search, filters):
36 '''
37@@ -85,12 +89,17 @@
38 try:
39 if f is None:
40 continue
41+ resource = ''
42+ for link in f['links']:
43+ if link['rel'] == 'enclosure':
44+ resource = link['href']
45 results.append({'uri':f['link'],
46 'icon':f['media_thumbnail'][0]['url'],
47 'title':f['title'],
48 'comment':f['summary'],
49- 'published':GLib.Variant('s', f['published']),
50- 'author':GLib.Variant('s', f['author'])})
51+ 'published':f['published'],
52+ 'author':f['author'],
53+ 'resource':resource})
54 except Exception as error:
55 print(error)
56 return results
57@@ -130,22 +139,32 @@
58 i['comment'] = ''
59 if not 'dnd_uri' in i or not i['dnd_uri'] or i['dnd_uri'] == '':
60 i['dnd_uri'] = i['uri']
61- i['metadata'] = {}
62- if EXTRA_METADATA:
63- for e in i:
64- for m in EXTRA_METADATA:
65- if m['id'] == e:
66- i['metadata'][e] = i[e]
67- i['metadata']['provider_credits'] = GLib.Variant('s', PROVIDER_CREDITS)
68- result = Unity.ScopeResult.create(str(i['uri']), str(i['icon']),
69- i['category'], i['result_type'],
70- str(i['mimetype']), str(i['title']),
71- str(i['comment']), str(i['dnd_uri']),
72- i['metadata'])
73- result_set.add_result(result)
74+ result_set.add_result(**i)
75 except Exception as error:
76 print (error)
77
78+class Preview (Unity.ResultPreviewer):
79+
80+ def do_run(self):
81+ resource = False
82+ if self.result.metadata and 'resource' in self.result.metadata and self.result.metadata['resource'].get_string() != '':
83+ resource = True
84+ thumb = Gio.FileIcon.new(Gio.file_new_for_uri(self.result.metadata['resource'].get_string()))
85+ else:
86+ thumb = Gio.FileIcon.new(Gio.file_new_for_uri(self.result.icon_hint))
87+ preview = Unity.GenericPreview.new(self.result.title, self.result.comment.strip(), thumb)
88+ preview.add_info(Unity.InfoHint.new("license", _("License"), None, _("Public Domain")))
89+ if self.result.metadata and 'author' in self.result.metadata and self.result.metadata['author'].get_string() != '':
90+ preview.props.subtitle = _("By ") + self.result.metadata['author'].get_string()
91+ icon = Gio.FileIcon.new (Gio.file_new_for_path(PROVIDER_ICON))
92+ view_action = Unity.PreviewAction.new("view", _("View"), icon)
93+ preview.add_action(view_action)
94+
95+ if resource and shutil.which("inkscape"):
96+ inkscape_action = Unity.PreviewAction.new("inkscape", _("Open in Inkscape"), None)
97+ preview.add_action(inkscape_action)
98+ return preview
99+
100 class Scope (Unity.AbstractScope):
101 def __init__(self):
102 Unity.AbstractScope.__init__(self)
103@@ -197,5 +216,18 @@
104 se = MySearch (search_context)
105 return se
106
107+ def do_create_previewer(self, result, metadata):
108+ rp = Preview()
109+ rp.set_scope_result(result)
110+ rp.set_search_metadata(metadata)
111+ return rp
112+
113+ def do_activate(self, result, metadata, id):
114+ if id == 'inkscape':
115+ uri = Gio.file_new_for_uri(result.metadata['resource'].get_string()).get_uri()
116+ GLib.spawn_async([shutil.which("inkscape"), uri.replace(' ', '%20')])
117+ return Unity.ActivationResponse(handled=Unity.HandledType.HIDE_DASH, goto_uri=None)
118+ return Unity.ActivationResponse()
119+
120 def load_scope():
121 return Scope()

Subscribers

People subscribed via source and target branches

to all changes: