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
=== modified file 'data/googlebooks.scope.in'
--- data/googlebooks.scope.in 2013-04-15 13:56:26 +0000
+++ data/googlebooks.scope.in 2013-10-24 11:06:27 +0000
@@ -1,16 +1,17 @@
1[Scope]1[Scope]
2DBusName=com.canonical.Unity.Scope.Books.Googlebooks2DBusName=com.canonical.Unity.Scope.Books.Googlebooks
3DBusPath=/com/canonical/unity/scope/books/googlebooks3DBusPath=/com/canonical/unity/scope/books/googlebooks
4Icon=4Icon=/usr/share/icons/unity-icon-theme/places/svg/group-books.svg
5QueryBinary=5QueryBinary=
6_Keywords=googlebooks;books;6_Keywords=googlebooks;books;book;read;
7RequiredMetadata=7RequiredMetadata=
8OptionalMetadata=author[s];publisher[s];published_date[s];selfLink[s];8OptionalMetadata=author[s];publisher[s];published_date[s];selfLink[s];
9Loader=/usr/share/unity-scopes/googlebooks/unity_googlebooks_daemon.py9Loader=/usr/share/unity-scopes/googlebooks/unity_googlebooks_daemon.py
10RemoteContent=true10RemoteContent=true
11Type=books11Type=books
12Master=books.scope
12_Name=Google Books13_Name=Google Books
13_Description=Find Google Books books14_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.
14_SearchHint=Search Google Books15_SearchHint=Search Google Books
1516
16[Desktop Entry]17[Desktop Entry]
1718
=== modified file 'src/unity_googlebooks_daemon.py'
--- src/unity_googlebooks_daemon.py 2013-04-15 14:03:15 +0000
+++ src/unity_googlebooks_daemon.py 2013-10-24 11:06:27 +0000
@@ -20,6 +20,7 @@
20import urllib.parse20import urllib.parse
21import urllib.request21import urllib.request
22import json22import json
23import logging
2324
24APP_NAME = 'unity-scope-googlebooks'25APP_NAME = 'unity-scope-googlebooks'
25LOCAL_PATH = '/usr/share/locale/'26LOCAL_PATH = '/usr/share/locale/'
@@ -27,6 +28,8 @@
27gettext.textdomain(APP_NAME)28gettext.textdomain(APP_NAME)
28_ = gettext.gettext29_ = gettext.gettext
2930
31logger = logging.getLogger("unity.scope.googlebooks")
32
30GROUP_NAME = 'com.canonical.Unity.Scope.Books.Googlebooks'33GROUP_NAME = 'com.canonical.Unity.Scope.Books.Googlebooks'
31UNIQUE_PATH = '/com/canonical/unity/scope/books/googlebooks'34UNIQUE_PATH = '/com/canonical/unity/scope/books/googlebooks'
32SEARCH_URI = 'https://www.googleapis.com/books/v1/volumes'35SEARCH_URI = 'https://www.googleapis.com/books/v1/volumes'
@@ -35,20 +38,17 @@
35NO_RESULTS_HINT = _('Sorry, there are no Googlebooks results that match your search.')38NO_RESULTS_HINT = _('Sorry, there are no Googlebooks results that match your search.')
36PROVIDER_CREDITS = _('Powered by Google Books')39PROVIDER_CREDITS = _('Powered by Google Books')
37SVG_DIR = '/usr/share/icons/unity-icon-theme/places/svg/'40SVG_DIR = '/usr/share/icons/unity-icon-theme/places/svg/'
38PROVIDER_ICON = SVG_DIR+'service-googlebooks.svg'41#FIXME use the stadard Google icon until we have a Google Books one
39DEFAULT_RESULT_ICON = SVG_DIR+'result-books.svg'42PROVIDER_ICON = SVG_DIR+'service-googlenews.svg'
43DEFAULT_RESULT_ICON = SVG_DIR+'group-books.svg'
40DEFAULT_RESULT_MIMETYPE = 'text/html'44DEFAULT_RESULT_MIMETYPE = 'text/html'
41DEFAULT_RESULT_TYPE = Unity.ResultType.DEFAULT45DEFAULT_RESULT_TYPE = Unity.ResultType.DEFAULT
4246
43c1 = {'id' :'recent',47c1 = {'id' :'top',
44 'name' :_('Recent'),
45 'icon' :SVG_DIR+'group-installed.svg',
46 'renderer':Unity.CategoryRenderer.VERTICAL_TILE}
47c2 = {'id' :'top',
48 'name' :_('Top'),48 'name' :_('Top'),
49 'icon' :SVG_DIR+'group-installed.svg',49 'icon' :SVG_DIR+'group-installed.svg',
50 'renderer':Unity.CategoryRenderer.VERTICAL_TILE}50 'renderer':Unity.CategoryRenderer.VERTICAL_TILE}
51CATEGORIES = [c1, c2]51CATEGORIES = [c1]
5252
53FILTERS = []53FILTERS = []
5454
@@ -81,21 +81,21 @@
81 if not search:81 if not search:
82 return results82 return results
83 search = urllib.parse.quote(search)83 search = urllib.parse.quote(search)
84 orders = ['newest', 'relevance']84 orders = ['relevance']
85 for order in orders:85 for order in orders:
86 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)86 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)
87 print (uri)87 logger.debug("Request: %s", uri)
88 try:88 try:
89 r = urllib.request.urlopen(uri).read()89 r = urllib.request.urlopen(uri).read()
90 data = json.loads(r.decode('utf-8'))90 data = json.loads(r.decode('utf-8'))
91 except Exception as error:91 except Exception:
92 data = None92 data = None
93 print (error)93 logger.exception("Error while fetching data")
94 if not data:94 if not data:
95 return results95 return results
96 for e in data['items']:96 for e in data['items']:
97 authors, description, icon, publishedDate = '', '', '', ''97 authors, description, icon, publishedDate = '', '', '', ''
98 selfLink, uri = '', ''98 selfLink, uri, categories, rating = '', '', '', ''
99 title = e['volumeInfo']['title']99 title = e['volumeInfo']['title']
100 if 'authors' in e['volumeInfo']:100 if 'authors' in e['volumeInfo']:
101 authors = ', '.join(e['volumeInfo']['authors'])101 authors = ', '.join(e['volumeInfo']['authors'])
@@ -109,16 +109,44 @@
109 selfLink = e['volumeInfo']['selfLink']109 selfLink = e['volumeInfo']['selfLink']
110 if 'canonicalVolumeLink' in e['volumeInfo']:110 if 'canonicalVolumeLink' in e['volumeInfo']:
111 uri = e['volumeInfo']['canonicalVolumeLink']111 uri = e['volumeInfo']['canonicalVolumeLink']
112 if 'averageRating' in e['volumeInfo']:
113 rating = e['volumeInfo']['averageRating']
114 rating = '\u2605' * round(rating) + '\u2606' * (5-round(rating))
115 if 'categories' in e['volumeInfo']:
116 categories = ', '.join(e['volumeInfo']['categories'])
112 results.append({'uri':uri,117 results.append({'uri':uri,
113 'title':title,118 'title':title,
114 'icon':icon,119 'icon':icon,
115 'comment':description,120 'comment':description,
116 'selfLink':GLib.Variant('s', selfLink),121 'selfLink':selfLink,
117 'author':GLib.Variant('s', authors),122 'author':authors,
118 'published_date':GLib.Variant('s', publishedDate),123 'published_date':publishedDate,
119 'category':orders.index(order)})124 'categories':categories,
125 'rating':rating})
120 return results126 return results
121127
128class Preview (Unity.ResultPreviewer):
129
130 def do_run(self):
131 zoom_cover = self.result.icon_hint.replace("&zoom=1", "&zoom=2")
132 image = Gio.FileIcon.new(Gio.file_new_for_uri(zoom_cover))
133 clean_comment = self.result.comment.replace("&", "&")
134 preview = Unity.GenericPreview.new(self.result.title, clean_comment, image)
135 preview.props.subtitle = self.result.metadata['author'].get_string()
136 if self.result.metadata['rating'].get_string() != '':
137 preview.add_info(Unity.InfoHint.new("rating", _("Reader ratings"), None, self.result.metadata['rating'].get_string()))
138 if self.result.metadata['categories'].get_string() != '':
139 if ',' in self.result.metadata['categories'].get_string():
140 cat_string = _("Categories")
141 else:
142 cat_string = _("Category")
143 preview.add_info(Unity.InfoHint.new("category", cat_string, None, self.result.metadata['categories'].get_string()))
144 if self.result.metadata['published_date'].get_string() != '':
145 preview.add_info(Unity.InfoHint.new("Published", _("Published"), None, self.result.metadata['published_date'].get_string()))
146 icon = Gio.FileIcon.new (Gio.file_new_for_path(PROVIDER_ICON))
147 view_action = Unity.PreviewAction.new('view', _('Google Books'), icon)
148 preview.add_action(view_action)
149 return preview
122150
123# Classes below this point establish communication151# Classes below this point establish communication
124# with Unity, you probably shouldn't modify them.152# with Unity, you probably shouldn't modify them.
@@ -154,21 +182,8 @@
154 if not 'dnd_uri' in i or not i['dnd_uri'] or i['dnd_uri'] == '':182 if not 'dnd_uri' in i or not i['dnd_uri'] or i['dnd_uri'] == '':
155 i['dnd_uri'] = i['uri']183 i['dnd_uri'] = i['uri']
156 result_set.add_result(**i)184 result_set.add_result(**i)
157 except Exception as error:185 except Exception:
158 print (error)186 logger.exception("Error while creating results set")
159
160class Preview (Unity.ResultPreviewer):
161
162 def do_run(self):
163 preview = Unity.GenericPreview.new(self.result.title, self.result.comment, None)
164 preview.props.subtitle = self.result.metadata['author'].get_string()
165 if self.result.metadata['published_date'].get_string() != '':
166 preview.add_info(Unity.InfoHint.new("Published", _("Published"), None, self.result.metadata['published_date'].get_string()))
167 preview.props.image_source_uri = self.result.icon_hint
168 icon = Gio.FileIcon.new (Gio.file_new_for_path(PROVIDER_ICON))
169 view_action = Unity.PreviewAction.new('view', _('View'), icon)
170 preview.add_action(view_action)
171 return preview
172187
173class Scope (Unity.AbstractScope):188class Scope (Unity.AbstractScope):
174 def __init__(self):189 def __init__(self):

Subscribers

People subscribed via source and target branches

to all changes: