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

Proposed by David Callé
Status: Merged
Approved by: Michal Hruby
Approved revision: 26
Merged at revision: 26
Proposed branch: lp:~davidc3/unity-scope-gallica/previews
Merge into: lp:unity-scope-gallica
Diff against target: 128 lines (+56/-18)
2 files modified
data/gallica.scope.in (+1/-1)
src/unity_gallica_daemon.py (+55/-17)
To merge this branch: bzr merge lp:~davidc3/unity-scope-gallica/previews
Reviewer Review Type Date Requested Status
Michal Hruby (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+160914@code.launchpad.net

Commit message

Add previews

Description of the change

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 :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/gallica.scope.in'
2--- data/gallica.scope.in 2013-04-24 22:16:25 +0000
3+++ data/gallica.scope.in 2013-04-25 14:46:27 +0000
4@@ -4,7 +4,7 @@
5 Icon=
6 _Keywords=gallica;book;library;books;art;history;bnf;
7 RequiredMetadata=
8-OptionalMetadata=
9+OptionalMetadata=author[s];publisher[s];published_date[s];
10 Loader=/usr/share/unity-scopes/gallica/unity_gallica_daemon.py
11 RemoteContent=true
12 Type=books
13
14=== modified file 'src/unity_gallica_daemon.py'
15--- src/unity_gallica_daemon.py 2013-04-24 22:16:25 +0000
16+++ src/unity_gallica_daemon.py 2013-04-25 14:46:27 +0000
17@@ -45,7 +45,16 @@
18 'renderer':Unity.CategoryRenderer.VERTICAL_TILE}
19 CATEGORIES = [c1]
20 FILTERS = []
21-EXTRA_METADATA = []
22+m1 = {'id' :'author',
23+ 'type' :'s',
24+ 'field':Unity.SchemaFieldType.OPTIONAL}
25+m2 = {'id' :'publisher',
26+ 'type' :'s',
27+ 'field':Unity.SchemaFieldType.OPTIONAL}
28+m3 = {'id' :'published_date',
29+ 'type' :'s',
30+ 'field':Unity.SchemaFieldType.OPTIONAL}
31+EXTRA_METADATA = [m1, m2, m3]
32
33 def search(search, filters):
34 '''
35@@ -80,9 +89,10 @@
36 for record in data.iter():
37 try:
38 if record.tag == "{http://www.loc.gov/zing/srw/}record":
39- thumb, title, uri = None, None, None
40+ thumb, title, uri, comment = None, None, None, None
41+ publisher, published_date = '', ''
42+ author = []
43 for r in record:
44-
45 if r.tag == "{http://www.loc.gov/zing/srw/}extraRecordData":
46 for element in r:
47 if element.tag == "{http://gallica.bnf.fr/namespaces/gallica}thumbnail":
48@@ -98,9 +108,26 @@
49 if e.tag == "{http://purl.org/dc/elements/1.1/}title":
50 if e.text != "":
51 title = e.text
52+ elif e.tag == "{http://purl.org/dc/elements/1.1/}description":
53+ if e.text != "":
54+ comment = e.text
55+ elif e.tag == "{http://purl.org/dc/elements/1.1/}creator":
56+ if e.text != "":
57+ author.append(e.text)
58+ elif e.tag == "{http://purl.org/dc/elements/1.1/}publisher":
59+ if e.text != "":
60+ publisher = e.text
61+ elif e.tag == "{http://purl.org/dc/elements/1.1/}date":
62+ if e.text != "":
63+ date = e.text
64+ author = ", ".join(author)
65 results.append({'uri':uri,
66 'icon':thumb,
67- 'title':title})
68+ 'title':title,
69+ 'comment':comment,
70+ 'author':author,
71+ 'publisher':publisher,
72+ 'published_date':date})
73 except Exception as error:
74 print (error)
75 continue
76@@ -141,22 +168,27 @@
77 i['comment'] = ''
78 if not 'dnd_uri' in i or not i['dnd_uri'] or i['dnd_uri'] == '':
79 i['dnd_uri'] = i['uri']
80- i['metadata'] = {}
81- if EXTRA_METADATA:
82- for e in i:
83- for m in EXTRA_METADATA:
84- if m['id'] == e:
85- i['metadata'][e] = i[e]
86- i['metadata']['provider_credits'] = GLib.Variant('s', PROVIDER_CREDITS)
87- result = Unity.ScopeResult.create(str(i['uri']), str(i['icon']),
88- i['category'], i['result_type'],
89- str(i['mimetype']), str(i['title']),
90- str(i['comment']), str(i['dnd_uri']),
91- i['metadata'])
92- result_set.add_result(result)
93+ result_set.add_result(**i)
94 except Exception as error:
95 print (error)
96
97+class Preview (Unity.ResultPreviewer):
98+
99+ def do_run(self):
100+ icon = Gio.FileIcon.new(Gio.file_new_for_uri(self.result.icon_hint))
101+ preview = Unity.GenericPreview.new(self.result.title, self.result.comment.strip(), icon)
102+ preview.props.subtitle = self.result.metadata['author'].get_string()
103+ if self.result.metadata['publisher'].get_string():
104+ preview.add_info(Unity.InfoHint.new("publisher", _("Publisher"), None, self.result.metadata['publisher'].get_string()))
105+ if self.result.metadata['published_date'].get_string():
106+ preview.add_info(Unity.InfoHint.new("published", _("Published"), None, self.result.metadata['published_date'].get_string()))
107+# if self.result.metadata['followers'].get_int32():
108+# preview.add_info(Unity.InfoHint.new("followers", _("Followers"), None, str(self.result.metadata['followers'].get_int32())))
109+ icon = Gio.FileIcon.new (Gio.file_new_for_path(PROVIDER_ICON))
110+ view_action = Unity.PreviewAction.new("open", _("View"), icon)
111+ preview.add_action(view_action)
112+ return preview
113+
114 class Scope (Unity.AbstractScope):
115 def __init__(self):
116 Unity.AbstractScope.__init__(self)
117@@ -208,5 +240,11 @@
118 se = MySearch (search_context)
119 return se
120
121+ def do_create_previewer(self, result, metadata):
122+ rp = Preview()
123+ rp.set_scope_result(result)
124+ rp.set_search_metadata(metadata)
125+ return rp
126+
127 def load_scope():
128 return Scope()

Subscribers

People subscribed via source and target branches

to all changes: