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
=== modified file 'data/gallica.scope.in'
--- data/gallica.scope.in 2013-04-24 22:16:25 +0000
+++ data/gallica.scope.in 2013-04-25 14:46:27 +0000
@@ -4,7 +4,7 @@
4Icon=4Icon=
5_Keywords=gallica;book;library;books;art;history;bnf;5_Keywords=gallica;book;library;books;art;history;bnf;
6RequiredMetadata=6RequiredMetadata=
7OptionalMetadata=7OptionalMetadata=author[s];publisher[s];published_date[s];
8Loader=/usr/share/unity-scopes/gallica/unity_gallica_daemon.py8Loader=/usr/share/unity-scopes/gallica/unity_gallica_daemon.py
9RemoteContent=true9RemoteContent=true
10Type=books10Type=books
1111
=== modified file 'src/unity_gallica_daemon.py'
--- src/unity_gallica_daemon.py 2013-04-24 22:16:25 +0000
+++ src/unity_gallica_daemon.py 2013-04-25 14:46:27 +0000
@@ -45,7 +45,16 @@
45 'renderer':Unity.CategoryRenderer.VERTICAL_TILE}45 'renderer':Unity.CategoryRenderer.VERTICAL_TILE}
46CATEGORIES = [c1]46CATEGORIES = [c1]
47FILTERS = []47FILTERS = []
48EXTRA_METADATA = []48m1 = {'id' :'author',
49 'type' :'s',
50 'field':Unity.SchemaFieldType.OPTIONAL}
51m2 = {'id' :'publisher',
52 'type' :'s',
53 'field':Unity.SchemaFieldType.OPTIONAL}
54m3 = {'id' :'published_date',
55 'type' :'s',
56 'field':Unity.SchemaFieldType.OPTIONAL}
57EXTRA_METADATA = [m1, m2, m3]
4958
50def search(search, filters):59def search(search, filters):
51 '''60 '''
@@ -80,9 +89,10 @@
80 for record in data.iter():89 for record in data.iter():
81 try:90 try:
82 if record.tag == "{http://www.loc.gov/zing/srw/}record":91 if record.tag == "{http://www.loc.gov/zing/srw/}record":
83 thumb, title, uri = None, None, None92 thumb, title, uri, comment = None, None, None, None
93 publisher, published_date = '', ''
94 author = []
84 for r in record:95 for r in record:
85
86 if r.tag == "{http://www.loc.gov/zing/srw/}extraRecordData":96 if r.tag == "{http://www.loc.gov/zing/srw/}extraRecordData":
87 for element in r:97 for element in r:
88 if element.tag == "{http://gallica.bnf.fr/namespaces/gallica}thumbnail":98 if element.tag == "{http://gallica.bnf.fr/namespaces/gallica}thumbnail":
@@ -98,9 +108,26 @@
98 if e.tag == "{http://purl.org/dc/elements/1.1/}title":108 if e.tag == "{http://purl.org/dc/elements/1.1/}title":
99 if e.text != "":109 if e.text != "":
100 title = e.text110 title = e.text
111 elif e.tag == "{http://purl.org/dc/elements/1.1/}description":
112 if e.text != "":
113 comment = e.text
114 elif e.tag == "{http://purl.org/dc/elements/1.1/}creator":
115 if e.text != "":
116 author.append(e.text)
117 elif e.tag == "{http://purl.org/dc/elements/1.1/}publisher":
118 if e.text != "":
119 publisher = e.text
120 elif e.tag == "{http://purl.org/dc/elements/1.1/}date":
121 if e.text != "":
122 date = e.text
123 author = ", ".join(author)
101 results.append({'uri':uri,124 results.append({'uri':uri,
102 'icon':thumb,125 'icon':thumb,
103 'title':title})126 'title':title,
127 'comment':comment,
128 'author':author,
129 'publisher':publisher,
130 'published_date':date})
104 except Exception as error: 131 except Exception as error:
105 print (error)132 print (error)
106 continue133 continue
@@ -141,22 +168,27 @@
141 i['comment'] = ''168 i['comment'] = ''
142 if not 'dnd_uri' in i or not i['dnd_uri'] or i['dnd_uri'] == '':169 if not 'dnd_uri' in i or not i['dnd_uri'] or i['dnd_uri'] == '':
143 i['dnd_uri'] = i['uri']170 i['dnd_uri'] = i['uri']
144 i['metadata'] = {}171 result_set.add_result(**i)
145 if EXTRA_METADATA:
146 for e in i:
147 for m in EXTRA_METADATA:
148 if m['id'] == e:
149 i['metadata'][e] = i[e]
150 i['metadata']['provider_credits'] = GLib.Variant('s', PROVIDER_CREDITS)
151 result = Unity.ScopeResult.create(str(i['uri']), str(i['icon']),
152 i['category'], i['result_type'],
153 str(i['mimetype']), str(i['title']),
154 str(i['comment']), str(i['dnd_uri']),
155 i['metadata'])
156 result_set.add_result(result)
157 except Exception as error:172 except Exception as error:
158 print (error)173 print (error)
159174
175class Preview (Unity.ResultPreviewer):
176
177 def do_run(self):
178 icon = Gio.FileIcon.new(Gio.file_new_for_uri(self.result.icon_hint))
179 preview = Unity.GenericPreview.new(self.result.title, self.result.comment.strip(), icon)
180 preview.props.subtitle = self.result.metadata['author'].get_string()
181 if self.result.metadata['publisher'].get_string():
182 preview.add_info(Unity.InfoHint.new("publisher", _("Publisher"), None, self.result.metadata['publisher'].get_string()))
183 if self.result.metadata['published_date'].get_string():
184 preview.add_info(Unity.InfoHint.new("published", _("Published"), None, self.result.metadata['published_date'].get_string()))
185# if self.result.metadata['followers'].get_int32():
186# preview.add_info(Unity.InfoHint.new("followers", _("Followers"), None, str(self.result.metadata['followers'].get_int32())))
187 icon = Gio.FileIcon.new (Gio.file_new_for_path(PROVIDER_ICON))
188 view_action = Unity.PreviewAction.new("open", _("View"), icon)
189 preview.add_action(view_action)
190 return preview
191
160class Scope (Unity.AbstractScope):192class Scope (Unity.AbstractScope):
161 def __init__(self):193 def __init__(self):
162 Unity.AbstractScope.__init__(self)194 Unity.AbstractScope.__init__(self)
@@ -208,5 +240,11 @@
208 se = MySearch (search_context)240 se = MySearch (search_context)
209 return se241 return se
210242
243 def do_create_previewer(self, result, metadata):
244 rp = Preview()
245 rp.set_scope_result(result)
246 rp.set_search_metadata(metadata)
247 return rp
248
211def load_scope():249def load_scope():
212 return Scope()250 return Scope()

Subscribers

People subscribed via source and target branches

to all changes: