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
1=== modified file 'data/deviantart.scope.in'
2--- data/deviantart.scope.in 2013-03-15 17:28:32 +0000
3+++ data/deviantart.scope.in 2013-04-23 10:30:34 +0000
4@@ -4,7 +4,7 @@
5 Icon=
6 _Keywords=art;deviantart;image;da;deviant;
7 RequiredMetadata=
8-OptionalMetadata=published[s];author[s]
9+OptionalMetadata=published[s];author[s];tags[s];
10 Loader=/usr/share/unity-scopes/deviantart/unity_deviantart_daemon.py
11 RemoteContent=true
12 Type=graphics
13
14=== modified file 'src/unity_deviantart_daemon.py'
15--- src/unity_deviantart_daemon.py 2013-03-19 22:20:35 +0000
16+++ src/unity_deviantart_daemon.py 2013-04-23 10:30:34 +0000
17@@ -14,12 +14,13 @@
18 # You should have received a copy of the GNU General Public License along
19 # with this program. If not, see <http://www.gnu.org/licenses/>.
20
21-from gi.repository import Unity, UnityExtras
22-from gi.repository import Gio, GLib
23+from gi.repository import Unity
24+from gi.repository import Gio
25 import feedparser
26 import urllib.parse
27 import urllib.request
28 import gettext
29+import re
30
31 APP_NAME = 'unity-scope-deviantart'
32 LOCAL_PATH = '/usr/share/locale/'
33@@ -48,13 +49,16 @@
34
35 FILTERS = []
36
37-m1 = {'id' :'published',
38+m1 = {'id' :'tags',
39 'type' :'s',
40 'field':Unity.SchemaFieldType.OPTIONAL}
41 m2 = {'id' :'author',
42 'type' :'s',
43 'field':Unity.SchemaFieldType.OPTIONAL}
44-EXTRA_METADATA = [m1, m2]
45+m3 = {'id' :'resource',
46+ 'type' :'s',
47+ 'field':Unity.SchemaFieldType.OPTIONAL}
48+EXTRA_METADATA = [m1, m2, m3]
49
50 def search(search, filters):
51 '''
52@@ -74,7 +78,7 @@
53 if not search:
54 return results
55 search = urllib.parse.quote(search)
56- uri = "%srss.xml?type=deviation&q=boost:popular+%s" % (SEARCH_URI, search)
57+ uri = "%srss.xml?type=deviation&limit=25&q=boost:popular+%s" % (SEARCH_URI, search)
58 print(uri)
59 try:
60 feed = feedparser.parse(uri)
61@@ -92,10 +96,10 @@
62 results.append({'uri':entry['link'].replace('http://', 'https://'),
63 'icon':entry['media_thumbnail'][0]['url'].replace('http://', 'https://'),
64 'title':entry['title'],
65- 'comment':entry['tags'][0]['label'],
66- 'date':entry['published'],
67- 'author':GLib.Variant('s', entry['media_copyright']['url']),
68- 'published':GLib.Variant('s', entry['published'])})
69+ 'comment':entry['summary'],
70+ 'author':entry['media_copyright']['url'],
71+ 'tags':entry['tags'][0]['term'],
72+ 'resource':entry['media_content'][0]['url'].replace('http://', 'https://')})
73 except Exception as error:
74 print("Skipping an invalid result", error)
75 return results
76@@ -134,22 +138,37 @@
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 strip_html_tags(self, data):
100+ data = data.replace('<br />', '\n')
101+ p = re.compile(r'<.*?>')
102+ return p.sub('', data)
103+
104+ def do_run(self):
105+ comment = self.strip_html_tags(self.result.comment.strip())
106+ preview = Unity.GenericPreview.new(self.result.title, comment, None)
107+ if self.result.metadata and 'tags' in self.result.metadata and self.result.metadata['tags'].get_string() != '':
108+ tags = self.result.metadata['tags'].get_string().split('/')
109+ if len(tags) > 0:
110+ preview.add_info(Unity.InfoHint.new("tags", _("Tags"), None, ', '.join(tags)))
111+ if self.result.metadata and 'resource' in self.result.metadata and self.result.metadata['resource'].get_string() != '':
112+ thumbnail = Gio.FileIcon.new(Gio.file_new_for_uri(self.result.metadata['resource'].get_string()))
113+ else:
114+ thumbnail = Gio.FileIcon.new(Gio.file_new_for_uri(self.result.icon_hint))
115+ preview.props.image = thumbnail
116+ if self.result.metadata and 'author' in self.result.metadata and self.result.metadata['author'].get_string() != '':
117+ author = self.result.metadata['author'].get_string().split('://')[1].split('.deviantart')[0]
118+ preview.props.subtitle = _("By %s") % author
119+ icon = Gio.FileIcon.new (Gio.file_new_for_path(PROVIDER_ICON))
120+ view_action = Unity.PreviewAction.new("view", _("View"), icon)
121+ preview.add_action(view_action)
122+ return preview
123+
124 class Scope (Unity.AbstractScope):
125 def __init__(self):
126 Unity.AbstractScope.__init__(self)
127@@ -201,5 +220,11 @@
128 se = MySearch (search_context)
129 return se
130
131+ def do_create_previewer(self, result, metadata):
132+ rp = Preview()
133+ rp.set_scope_result(result)
134+ rp.set_search_metadata(metadata)
135+ return rp
136+
137 def load_scope():
138 return Scope()
139
140=== modified file 'tests/test_deviantart.py'
141--- tests/test_deviantart.py 2013-02-14 14:59:25 +0000
142+++ tests/test_deviantart.py 2013-04-23 10:30:34 +0000
143@@ -40,14 +40,15 @@
144
145 def test_valid_searches(self):
146 self.scope_module.SEARCH_URI = 'file:tests/data/mock_deviantart_pass#'
147- expected_results = ['Noise Context Pane',
148- 'Application Interfaces']
149+ expected_results = ['Asus eeeBox Heaven And Earth',
150+ 'https://th07.deviantart.net/fs70/150/f/2013/016/2/d/asus_eeebox_heaven_and_earth_by_mmesantos1-d5roikz.png']
151 results = []
152 for s in ['danrabbit']:
153 result_set = self.perform_query(s)
154- results.append(result_set.results[1]['title'])
155- results.append(result_set.results[1]['comment'])
156+ results.append(result_set.results[0]['title'])
157+ results.append(result_set.results[0]['icon'])
158 self.assertEqual(results, expected_results)
159+ self.assertEqual(result_set.results[0]['comment'].startswith('OS: Linux Mint XFCE 14 x86'), True)
160
161 def test_failing_search(self):
162 self.scope_module.SEARCH_URI = 'file:tests/data/mock_deviantart_fail#'

Subscribers

People subscribed via source and target branches

to all changes: