Merge lp:~davidc3/unity-scope-googlebooks/enhance-previews into lp:unity-scope-googlebooks

Proposed by David Callé
Status: Merged
Approved by: David Callé
Approved revision: 9
Merged at revision: 8
Proposed branch: lp:~davidc3/unity-scope-googlebooks/enhance-previews
Merge into: lp:unity-scope-googlebooks
Diff against target: 172 lines (+52/-36)
2 files modified
data/googlebooks.scope.in (+4/-3)
src/unity_googlebooks_daemon.py (+48/-33)
To merge this branch: bzr merge lp:~davidc3/unity-scope-googlebooks/enhance-previews
Reviewer Review Type Date Requested Status
Guillermo Gonzalez Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+192482@code.launchpad.net

Commit message

* Add categories and ratings in previews
* Preview description ampersand fix
* Only sort results by relevancy (faster search)
* Bigger cover in previews
* Change "View" to "Google Books"
* Misc .scope file fixes

Description of the change

* Add categories and ratings in previews
* Preview description ampersand fix
* Only sort results by relevancy (faster search)
* Bigger cover in previews
* Change "View" to "Google Books"
* Misc .scope file fixes

To post a comment you must log in.
9. By David Callé

Actually use the new logger

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

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/googlebooks.scope.in'
2--- data/googlebooks.scope.in 2013-04-15 13:56:26 +0000
3+++ data/googlebooks.scope.in 2013-10-24 11:06:27 +0000
4@@ -1,16 +1,17 @@
5 [Scope]
6 DBusName=com.canonical.Unity.Scope.Books.Googlebooks
7 DBusPath=/com/canonical/unity/scope/books/googlebooks
8-Icon=
9+Icon=/usr/share/icons/unity-icon-theme/places/svg/group-books.svg
10 QueryBinary=
11-_Keywords=googlebooks;books;
12+_Keywords=googlebooks;books;book;read;
13 RequiredMetadata=
14 OptionalMetadata=author[s];publisher[s];published_date[s];selfLink[s];
15 Loader=/usr/share/unity-scopes/googlebooks/unity_googlebooks_daemon.py
16 RemoteContent=true
17 Type=books
18+Master=books.scope
19 _Name=Google Books
20-_Description=Find Google Books books
21+_Description=This is an Ubuntu search plugin that enables books and magazines from Google Books to be searched and displayed in the Dash underneath the Books header. If you do not wish to search this content source, you can disable this search plugin.
22 _SearchHint=Search Google Books
23
24 [Desktop Entry]
25
26=== modified file 'src/unity_googlebooks_daemon.py'
27--- src/unity_googlebooks_daemon.py 2013-04-15 14:03:15 +0000
28+++ src/unity_googlebooks_daemon.py 2013-10-24 11:06:27 +0000
29@@ -20,6 +20,7 @@
30 import urllib.parse
31 import urllib.request
32 import json
33+import logging
34
35 APP_NAME = 'unity-scope-googlebooks'
36 LOCAL_PATH = '/usr/share/locale/'
37@@ -27,6 +28,8 @@
38 gettext.textdomain(APP_NAME)
39 _ = gettext.gettext
40
41+logger = logging.getLogger("unity.scope.googlebooks")
42+
43 GROUP_NAME = 'com.canonical.Unity.Scope.Books.Googlebooks'
44 UNIQUE_PATH = '/com/canonical/unity/scope/books/googlebooks'
45 SEARCH_URI = 'https://www.googleapis.com/books/v1/volumes'
46@@ -35,20 +38,17 @@
47 NO_RESULTS_HINT = _('Sorry, there are no Googlebooks results that match your search.')
48 PROVIDER_CREDITS = _('Powered by Google Books')
49 SVG_DIR = '/usr/share/icons/unity-icon-theme/places/svg/'
50-PROVIDER_ICON = SVG_DIR+'service-googlebooks.svg'
51-DEFAULT_RESULT_ICON = SVG_DIR+'result-books.svg'
52+#FIXME use the stadard Google icon until we have a Google Books one
53+PROVIDER_ICON = SVG_DIR+'service-googlenews.svg'
54+DEFAULT_RESULT_ICON = SVG_DIR+'group-books.svg'
55 DEFAULT_RESULT_MIMETYPE = 'text/html'
56 DEFAULT_RESULT_TYPE = Unity.ResultType.DEFAULT
57
58-c1 = {'id' :'recent',
59- 'name' :_('Recent'),
60- 'icon' :SVG_DIR+'group-installed.svg',
61- 'renderer':Unity.CategoryRenderer.VERTICAL_TILE}
62-c2 = {'id' :'top',
63+c1 = {'id' :'top',
64 'name' :_('Top'),
65 'icon' :SVG_DIR+'group-installed.svg',
66 'renderer':Unity.CategoryRenderer.VERTICAL_TILE}
67-CATEGORIES = [c1, c2]
68+CATEGORIES = [c1]
69
70 FILTERS = []
71
72@@ -81,21 +81,21 @@
73 if not search:
74 return results
75 search = urllib.parse.quote(search)
76- orders = ['newest', 'relevance']
77+ orders = ['relevance']
78 for order in orders:
79- uri = "%s?alt=json&key=%s&printType=books&q=%s&maxResults=20&orderBy=%s&&fields=items(selfLink,volumeInfo(title,publishedDate,authors,imageLinks/thumbnail,canonicalVolumeLink,description))" % (SEARCH_URI, API_KEY, search, order)
80- print (uri)
81+ uri = "%s?alt=json&key=%s&printType=books&q=%s&maxResults=20&orderBy=%s&&fields=items(selfLink,volumeInfo(title,publishedDate,authors,imageLinks/thumbnail,canonicalVolumeLink,description,categories,averageRating))" % (SEARCH_URI, API_KEY, search, order)
82+ logger.debug("Request: %s", uri)
83 try:
84 r = urllib.request.urlopen(uri).read()
85 data = json.loads(r.decode('utf-8'))
86- except Exception as error:
87+ except Exception:
88 data = None
89- print (error)
90+ logger.exception("Error while fetching data")
91 if not data:
92 return results
93 for e in data['items']:
94 authors, description, icon, publishedDate = '', '', '', ''
95- selfLink, uri = '', ''
96+ selfLink, uri, categories, rating = '', '', '', ''
97 title = e['volumeInfo']['title']
98 if 'authors' in e['volumeInfo']:
99 authors = ', '.join(e['volumeInfo']['authors'])
100@@ -109,16 +109,44 @@
101 selfLink = e['volumeInfo']['selfLink']
102 if 'canonicalVolumeLink' in e['volumeInfo']:
103 uri = e['volumeInfo']['canonicalVolumeLink']
104+ if 'averageRating' in e['volumeInfo']:
105+ rating = e['volumeInfo']['averageRating']
106+ rating = '\u2605' * round(rating) + '\u2606' * (5-round(rating))
107+ if 'categories' in e['volumeInfo']:
108+ categories = ', '.join(e['volumeInfo']['categories'])
109 results.append({'uri':uri,
110 'title':title,
111 'icon':icon,
112 'comment':description,
113- 'selfLink':GLib.Variant('s', selfLink),
114- 'author':GLib.Variant('s', authors),
115- 'published_date':GLib.Variant('s', publishedDate),
116- 'category':orders.index(order)})
117+ 'selfLink':selfLink,
118+ 'author':authors,
119+ 'published_date':publishedDate,
120+ 'categories':categories,
121+ 'rating':rating})
122 return results
123
124+class Preview (Unity.ResultPreviewer):
125+
126+ def do_run(self):
127+ zoom_cover = self.result.icon_hint.replace("&zoom=1", "&zoom=2")
128+ image = Gio.FileIcon.new(Gio.file_new_for_uri(zoom_cover))
129+ clean_comment = self.result.comment.replace("&", "&")
130+ preview = Unity.GenericPreview.new(self.result.title, clean_comment, image)
131+ preview.props.subtitle = self.result.metadata['author'].get_string()
132+ if self.result.metadata['rating'].get_string() != '':
133+ preview.add_info(Unity.InfoHint.new("rating", _("Reader ratings"), None, self.result.metadata['rating'].get_string()))
134+ if self.result.metadata['categories'].get_string() != '':
135+ if ',' in self.result.metadata['categories'].get_string():
136+ cat_string = _("Categories")
137+ else:
138+ cat_string = _("Category")
139+ preview.add_info(Unity.InfoHint.new("category", cat_string, None, self.result.metadata['categories'].get_string()))
140+ if self.result.metadata['published_date'].get_string() != '':
141+ preview.add_info(Unity.InfoHint.new("Published", _("Published"), None, self.result.metadata['published_date'].get_string()))
142+ icon = Gio.FileIcon.new (Gio.file_new_for_path(PROVIDER_ICON))
143+ view_action = Unity.PreviewAction.new('view', _('Google Books'), icon)
144+ preview.add_action(view_action)
145+ return preview
146
147 # Classes below this point establish communication
148 # with Unity, you probably shouldn't modify them.
149@@ -154,21 +182,8 @@
150 if not 'dnd_uri' in i or not i['dnd_uri'] or i['dnd_uri'] == '':
151 i['dnd_uri'] = i['uri']
152 result_set.add_result(**i)
153- except Exception as error:
154- print (error)
155-
156-class Preview (Unity.ResultPreviewer):
157-
158- def do_run(self):
159- preview = Unity.GenericPreview.new(self.result.title, self.result.comment, None)
160- preview.props.subtitle = self.result.metadata['author'].get_string()
161- if self.result.metadata['published_date'].get_string() != '':
162- preview.add_info(Unity.InfoHint.new("Published", _("Published"), None, self.result.metadata['published_date'].get_string()))
163- preview.props.image_source_uri = self.result.icon_hint
164- icon = Gio.FileIcon.new (Gio.file_new_for_path(PROVIDER_ICON))
165- view_action = Unity.PreviewAction.new('view', _('View'), icon)
166- preview.add_action(view_action)
167- return preview
168+ except Exception:
169+ logger.exception("Error while creating results set")
170
171 class Scope (Unity.AbstractScope):
172 def __init__(self):

Subscribers

People subscribed via source and target branches

to all changes: