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

Proposed by David Callé
Status: Merged
Approved by: Michal Hruby
Approved revision: 37
Merged at revision: 33
Proposed branch: lp:~davidc3/unity-scope-deviantart/previews
Merge into: lp:unity-scope-deviantart
Diff against target: 162 lines (+53/-27)
3 files modified
data/deviantart.scope.in (+1/-1)
src/unity_deviantart_daemon.py (+47/-22)
tests/test_deviantart.py (+5/-4)
To merge this branch: bzr merge lp:~davidc3/unity-scope-deviantart/previews
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Michal Hruby (community) Approve
Review via email: mp+159836@code.launchpad.net

Commit message

Add previews

Description of the change

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

Add tags support in previews

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
Michal Hruby (mhr3) wrote :

112 + preview.props.image_source_uri = self.result.metadata['resource'].get_string()

The "image_source_uri" property is for requesting Unity to generate a thumbnail for a *local* media file, please don't try to use with remote uris. The property you want is "image" (also the third parameter to GenericPreview.new).

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

117 + preview.props.subtitle = _("By ") + author

Please use format strings for these kind of translations. _("By %s") % author

35. By David Callé

Fix translation string for By

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
36. By David Callé

Use the image property of Unity Preview instead of image_source_uri

37. By David Callé

Do it everywhere

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

LGTM

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
=== modified file 'data/deviantart.scope.in'
--- data/deviantart.scope.in 2013-03-15 17:28:32 +0000
+++ data/deviantart.scope.in 2013-04-23 10:30:34 +0000
@@ -4,7 +4,7 @@
4Icon=4Icon=
5_Keywords=art;deviantart;image;da;deviant;5_Keywords=art;deviantart;image;da;deviant;
6RequiredMetadata=6RequiredMetadata=
7OptionalMetadata=published[s];author[s]7OptionalMetadata=published[s];author[s];tags[s];
8Loader=/usr/share/unity-scopes/deviantart/unity_deviantart_daemon.py8Loader=/usr/share/unity-scopes/deviantart/unity_deviantart_daemon.py
9RemoteContent=true9RemoteContent=true
10Type=graphics10Type=graphics
1111
=== modified file 'src/unity_deviantart_daemon.py'
--- src/unity_deviantart_daemon.py 2013-03-19 22:20:35 +0000
+++ src/unity_deviantart_daemon.py 2013-04-23 10:30:34 +0000
@@ -14,12 +14,13 @@
14# You should have received a copy of the GNU General Public License along 14# You should have received a copy of the GNU General Public License along
15# with this program. If not, see <http://www.gnu.org/licenses/>.15# with this program. If not, see <http://www.gnu.org/licenses/>.
1616
17from gi.repository import Unity, UnityExtras17from gi.repository import Unity
18from gi.repository import Gio, GLib18from gi.repository import Gio
19import feedparser19import feedparser
20import urllib.parse20import urllib.parse
21import urllib.request21import urllib.request
22import gettext22import gettext
23import re
2324
24APP_NAME = 'unity-scope-deviantart'25APP_NAME = 'unity-scope-deviantart'
25LOCAL_PATH = '/usr/share/locale/'26LOCAL_PATH = '/usr/share/locale/'
@@ -48,13 +49,16 @@
4849
49FILTERS = []50FILTERS = []
5051
51m1 = {'id' :'published',52m1 = {'id' :'tags',
52 'type' :'s',53 'type' :'s',
53 'field':Unity.SchemaFieldType.OPTIONAL}54 'field':Unity.SchemaFieldType.OPTIONAL}
54m2 = {'id' :'author',55m2 = {'id' :'author',
55 'type' :'s',56 'type' :'s',
56 'field':Unity.SchemaFieldType.OPTIONAL}57 'field':Unity.SchemaFieldType.OPTIONAL}
57EXTRA_METADATA = [m1, m2]58m3 = {'id' :'resource',
59 'type' :'s',
60 'field':Unity.SchemaFieldType.OPTIONAL}
61EXTRA_METADATA = [m1, m2, m3]
5862
59def search(search, filters):63def search(search, filters):
60 '''64 '''
@@ -74,7 +78,7 @@
74 if not search:78 if not search:
75 return results79 return results
76 search = urllib.parse.quote(search)80 search = urllib.parse.quote(search)
77 uri = "%srss.xml?type=deviation&q=boost:popular+%s" % (SEARCH_URI, search)81 uri = "%srss.xml?type=deviation&limit=25&q=boost:popular+%s" % (SEARCH_URI, search)
78 print(uri)82 print(uri)
79 try:83 try:
80 feed = feedparser.parse(uri)84 feed = feedparser.parse(uri)
@@ -92,10 +96,10 @@
92 results.append({'uri':entry['link'].replace('http://', 'https://'),96 results.append({'uri':entry['link'].replace('http://', 'https://'),
93 'icon':entry['media_thumbnail'][0]['url'].replace('http://', 'https://'),97 'icon':entry['media_thumbnail'][0]['url'].replace('http://', 'https://'),
94 'title':entry['title'],98 'title':entry['title'],
95 'comment':entry['tags'][0]['label'],99 'comment':entry['summary'],
96 'date':entry['published'],100 'author':entry['media_copyright']['url'],
97 'author':GLib.Variant('s', entry['media_copyright']['url']),101 'tags':entry['tags'][0]['term'],
98 'published':GLib.Variant('s', entry['published'])})102 'resource':entry['media_content'][0]['url'].replace('http://', 'https://')})
99 except Exception as error:103 except Exception as error:
100 print("Skipping an invalid result", error)104 print("Skipping an invalid result", error)
101 return results105 return results
@@ -134,22 +138,37 @@
134 i['comment'] = ''138 i['comment'] = ''
135 if not 'dnd_uri' in i or not i['dnd_uri'] or i['dnd_uri'] == '':139 if not 'dnd_uri' in i or not i['dnd_uri'] or i['dnd_uri'] == '':
136 i['dnd_uri'] = i['uri']140 i['dnd_uri'] = i['uri']
137 i['metadata'] = {}141 result_set.add_result(**i)
138 if EXTRA_METADATA:
139 for e in i:
140 for m in EXTRA_METADATA:
141 if m['id'] == e:
142 i['metadata'][e] = i[e]
143 i['metadata']['provider_credits'] = GLib.Variant('s', PROVIDER_CREDITS)
144 result = Unity.ScopeResult.create(str(i['uri']), str(i['icon']),
145 i['category'], i['result_type'],
146 str(i['mimetype']), str(i['title']),
147 str(i['comment']), str(i['dnd_uri']),
148 i['metadata'])
149 result_set.add_result(result)
150 except Exception as error:142 except Exception as error:
151 print (error)143 print (error)
152144
145class Preview (Unity.ResultPreviewer):
146
147 def strip_html_tags(self, data):
148 data = data.replace('<br />', '\n')
149 p = re.compile(r'<.*?>')
150 return p.sub('', data)
151
152 def do_run(self):
153 comment = self.strip_html_tags(self.result.comment.strip())
154 preview = Unity.GenericPreview.new(self.result.title, comment, None)
155 if self.result.metadata and 'tags' in self.result.metadata and self.result.metadata['tags'].get_string() != '':
156 tags = self.result.metadata['tags'].get_string().split('/')
157 if len(tags) > 0:
158 preview.add_info(Unity.InfoHint.new("tags", _("Tags"), None, ', '.join(tags)))
159 if self.result.metadata and 'resource' in self.result.metadata and self.result.metadata['resource'].get_string() != '':
160 thumbnail = Gio.FileIcon.new(Gio.file_new_for_uri(self.result.metadata['resource'].get_string()))
161 else:
162 thumbnail = Gio.FileIcon.new(Gio.file_new_for_uri(self.result.icon_hint))
163 preview.props.image = thumbnail
164 if self.result.metadata and 'author' in self.result.metadata and self.result.metadata['author'].get_string() != '':
165 author = self.result.metadata['author'].get_string().split('://')[1].split('.deviantart')[0]
166 preview.props.subtitle = _("By %s") % author
167 icon = Gio.FileIcon.new (Gio.file_new_for_path(PROVIDER_ICON))
168 view_action = Unity.PreviewAction.new("view", _("View"), icon)
169 preview.add_action(view_action)
170 return preview
171
153class Scope (Unity.AbstractScope):172class Scope (Unity.AbstractScope):
154 def __init__(self):173 def __init__(self):
155 Unity.AbstractScope.__init__(self)174 Unity.AbstractScope.__init__(self)
@@ -201,5 +220,11 @@
201 se = MySearch (search_context)220 se = MySearch (search_context)
202 return se221 return se
203222
223 def do_create_previewer(self, result, metadata):
224 rp = Preview()
225 rp.set_scope_result(result)
226 rp.set_search_metadata(metadata)
227 return rp
228
204def load_scope():229def load_scope():
205 return Scope()230 return Scope()
206231
=== modified file 'tests/test_deviantart.py'
--- tests/test_deviantart.py 2013-02-14 14:59:25 +0000
+++ tests/test_deviantart.py 2013-04-23 10:30:34 +0000
@@ -40,14 +40,15 @@
4040
41 def test_valid_searches(self):41 def test_valid_searches(self):
42 self.scope_module.SEARCH_URI = 'file:tests/data/mock_deviantart_pass#'42 self.scope_module.SEARCH_URI = 'file:tests/data/mock_deviantart_pass#'
43 expected_results = ['Noise Context Pane',43 expected_results = ['Asus eeeBox Heaven And Earth',
44 'Application Interfaces']44 'https://th07.deviantart.net/fs70/150/f/2013/016/2/d/asus_eeebox_heaven_and_earth_by_mmesantos1-d5roikz.png']
45 results = []45 results = []
46 for s in ['danrabbit']:46 for s in ['danrabbit']:
47 result_set = self.perform_query(s)47 result_set = self.perform_query(s)
48 results.append(result_set.results[1]['title'])48 results.append(result_set.results[0]['title'])
49 results.append(result_set.results[1]['comment'])49 results.append(result_set.results[0]['icon'])
50 self.assertEqual(results, expected_results)50 self.assertEqual(results, expected_results)
51 self.assertEqual(result_set.results[0]['comment'].startswith('OS: Linux Mint XFCE 14 x86'), True)
5152
52 def test_failing_search(self):53 def test_failing_search(self):
53 self.scope_module.SEARCH_URI = 'file:tests/data/mock_deviantart_fail#'54 self.scope_module.SEARCH_URI = 'file:tests/data/mock_deviantart_fail#'

Subscribers

People subscribed via source and target branches

to all changes: