Merge lp:~davidc3/unity-scope-songkick/fix-previews into lp:unity-scope-songkick

Proposed by David Callé
Status: Merged
Approved by: Guillermo Gonzalez
Approved revision: 18
Merged at revision: 16
Proposed branch: lp:~davidc3/unity-scope-songkick/fix-previews
Merge into: lp:unity-scope-songkick
Diff against target: 253 lines (+79/-93)
3 files modified
data/songkick.scope.in (+6/-5)
src/unity_songkick_daemon.py (+72/-87)
tests/test_songkick.py (+1/-1)
To merge this branch: bzr merge lp:~davidc3/unity-scope-songkick/fix-previews
Reviewer Review Type Date Requested Status
Guillermo Gonzalez Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+189698@code.launchpad.net

Commit message

Fix previews and move to Info master scope

Description of the change

Fix previews and move to info master scope

http://ubuntuone.com/10Bup3EFcIZtWkr79Xrdpg

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

Fix wrong paste

18. By David Callé

Fix location failure case

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/songkick.scope.in'
2--- data/songkick.scope.in 2013-03-15 17:29:46 +0000
3+++ data/songkick.scope.in 2013-10-07 20:41:53 +0000
4@@ -1,16 +1,17 @@
5 [Scope]
6 DBusName=com.canonical.Unity.Scope.Music.Songkick
7 DBusPath=/com/canonical/unity/scope/music/songkick
8-Icon=
9-_Keywords=songkick;
10+Icon=/usr/share/icons/unity-icon-theme/places/svg/service-songkick.svg
11+_Keywords=songkick;concert;band;artist;
12 RequiredMetadata=
13 OptionalMetadata=
14 Loader=/usr/share/unity-scopes/songkick/unity_songkick_daemon.py
15 RemoteContent=true
16-Type=music
17+Master=info.scope
18+Type=info
19 _Name=Songkick
20-_Description=Find Songkick items
21-_SearchHint=Search Songkick
22+_Description=This is an Ubuntu search plugin that enables information from Songkick to be searched and displayed in the Dash underneath the Info header. If you do not wish to search this content source, you can disable this search plugin.
23+_SearchHint=Search concerts near you
24
25 [Desktop Entry]
26 X-Ubuntu-Gettext-Domain=unity-scope-songkick
27
28=== modified file 'src/unity_songkick_daemon.py'
29--- src/unity_songkick_daemon.py 2013-10-03 19:07:24 +0000
30+++ src/unity_songkick_daemon.py 2013-10-07 20:41:53 +0000
31@@ -18,6 +18,7 @@
32 from gi.repository import Unity
33 import gettext
34 import urllib.request
35+import urllib.parse
36 import json
37 import datetime
38 import logging
39@@ -58,17 +59,24 @@
40
41 logger = logging.getLogger("unity.scope.songkick")
42
43-def search(search, filters):
44+def search(search, filters, metadata):
45 '''
46 Search the server for questions and use stackexchange's api for tags
47 '''
48 results = []
49- search = search.replace(" ", "%20")
50- if search == "":
51- uri = '%s?location=clientip&apikey=%s' % (SEARCH_URI, API_KEY)
52+ try:
53+ location = metadata.get_property('location')
54+ latitude = location.latitude
55+ longitude = location.longitude
56+ except Exception:
57+ logger.exception("Error while fetching location.")
58+ location = None
59+
60+ if len(search) < 1 and location:
61+ uri = '%s?location=geo:%s,%s&apikey=%s' % (SEARCH_URI,latitude,longitude,API_KEY)
62 else:
63+ search = urllib.parse.quote(search)
64 uri = '%s?artist_name=%s&apikey=%s' % (SEARCH_URI, search, API_KEY)
65-
66 try:
67 logger.debug("Request: %s", uri)
68 response = urllib.request.urlopen(uri).read()
69@@ -78,83 +86,61 @@
70 except Exception:
71 logger.exception("Error while fetching: %r", uri)
72 result = []
73- if result:
74- for item in result:
75- icon_hint = ""
76- for artist in item['performance']:
77- #if artist['artist']['displayName'].lower() == search.replace("%20", " "):
78- icon_hint = 'http://www2.sk-static.com/images/media/profile_images/artists/%s/col2' % artist['artist']['id']
79- continue
80-
81- comment = item['venue']['displayName']
82- comment += "\n" + item['venue']['metroArea']['displayName']
83- comment += "\n" + item['venue']['metroArea']['country']['displayName']
84- try:
85- starttime = item['start']['datetime']
86- now = datetime.datetime.now()
87- starttime = now.strptime(starttime[:19], "%Y-%m-%dT%H:%M:%S")
88- comment += "\n\n<b>Doors open:</b> %s" % starttime.strftime("%A %x %H:%M")
89- except:
90- starttime = item['start']['date']
91- now = datetime.datetime.now()
92- starttime = now.strptime(starttime, "%Y-%m-%d")
93- comment += "\n\n<b>Doors open:</b> %s" % starttime.strftime("%A %x")
94- comment += "\n\n<b>Lineup:</b>\n\n"
95-
96- headliners = ""
97- support = ""
98- for performer in item['performance']:
99- if performer['billing'] == 'headline':
100- headliners += ", %s" % performer['displayName']
101- else:
102- support += ", %s" % performer['displayName']
103- comment += "<big>%s</big>\n" % headliners[2:]
104- if not support == "":
105- comment += "with\n%s" % support[2:]
106-
107- for artist in item['performance']:
108- icon_hint = 'http://www2.sk-static.com/images/media/profile_images/artists/%s/col2' % artist['artist']['id']
109- continue
110- results.append({'uri': item['uri'],
111- 'icon': icon_hint,
112- 'category': 0,
113- 'title': item['displayName'],
114- 'comment': comment})
115-
116+ for item in result:
117+ icon_hint = None
118+ comment = item['venue']['displayName']
119+ venue = item['venue']['displayName']
120+ city = "%s, %s" % (item['venue']['metroArea']['displayName'],
121+ item['venue']['metroArea']['country']['displayName'])
122+ try:
123+ starttime = item['start']['datetime']
124+ now = datetime.datetime.now()
125+ starttime = now.strptime(starttime[:19], "%Y-%m-%dT%H:%M:%S")
126+ date = starttime.strftime("%A %x %H:%M")
127+ except:
128+ starttime = item['start']['date']
129+ now = datetime.datetime.now()
130+ starttime = now.strptime(starttime, "%Y-%m-%d")
131+ date = starttime.strftime("%A %x")
132+ performers = []
133+ for performer in item['performance']:
134+ if performer['billing'] == 'headline':
135+ performers.append(performer['displayName'])
136+ for performer in item['performance']:
137+ if performer['billing'] != 'headline':
138+ performers.append(performer['displayName'])
139+ description = " / ".join(performers)
140+ for artist in item['performance']:
141+ icon_hint = 'http://www2.sk-static.com/images/media/profile_images/artists/%s/col2' % artist['artist']['id']
142+ continue
143+ results.append({'uri': item['uri'],
144+ 'icon': icon_hint,
145+ 'title': item['displayName'],
146+ 'comment': venue,
147+ 'city': city,
148+ 'description': description,
149+ 'date': date})
150 return results
151
152
153-def preview(scope, uri):
154- '''
155- Preview request handler
156- '''
157- # FIXME: Previews not yet implemented
158- model = self.model
159- iteration = model.get_first_iter()
160- end_iter = model.get_last_iter()
161- preview = None
162- while iteration != end_iter:
163- if model.get_value(iteration, 0) == uri:
164- title = ""
165- description = model.get_value(iteration, 6)
166- icon_hint = model.get_value(iteration, 1)[:-1] + "6"
167-
168- # Assemble the preview
169- preview = Unity.GenericPreview.new(title, description, None)
170- preview.props.image_source_uri = icon_hint
171- preview.props.subtitle = model.get_value(iteration, 5).title()
172-
173- # Add the "View" action
174- button_icon = Gio.ThemedIcon.new(SVG_DIR + "songkick.png")
175- view_action = Unity.PreviewAction.new("activate_uri", "View on Songkick", button_icon)
176- view_action.connect("activated", self.activate_uri)
177- preview.add_action(view_action)
178- break
179-
180- iteration = model.next(iteration)
181- if preview is None:
182- print ("Couldn't find model row for requested preview uri: '%s'", uri)
183- return preview
184+class Preview (Unity.ResultPreviewer):
185+
186+ def do_run(self):
187+ thumb = self.result.icon_hint.replace("/col2", "/col4")
188+ image = Gio.FileIcon.new (Gio.file_new_for_uri(thumb))
189+ description = self.result.metadata['description'].unpack()
190+ description = description.replace('&', '&amp;')
191+ preview = Unity.GenericPreview.new(self.result.title, description, image)
192+ preview.add_info(Unity.InfoHint.new("venue", _("Venue"), None,
193+ self.result.comment))
194+ preview.add_info(Unity.InfoHint.new("city", _("Location"), None,
195+ self.result.metadata['city'].unpack()))
196+ preview.props.subtitle = "%s at %s" % (self.result.metadata['date'].unpack(),
197+ self.result.comment)
198+ icon = Gio.FileIcon.new (Gio.file_new_for_path(PROVIDER_ICON))
199+ view_action = Unity.PreviewAction.new("activate_uri", "View on Songkick", icon)
200+ preview.add_action(view_action)
201+ return preview
202
203 # Classes below this point establish communication
204 # with Unity, you probably shouldn't modify them.
205@@ -172,7 +158,8 @@
206 try:
207 result_set = self.search_context.result_set
208 for i in search(self.search_context.search_query,
209- self.search_context.filter_state):
210+ self.search_context.filter_state,
211+ self.search_context.search_metadata):
212 if not 'uri' in i or not i['uri'] or i['uri'] == '':
213 continue
214 if not 'icon' in i or not i['icon'] or i['icon'] == '':
215@@ -189,13 +176,6 @@
216 i['comment'] = ''
217 if not 'dnd_uri' in i or not i['dnd_uri'] or i['dnd_uri'] == '':
218 i['dnd_uri'] = i['uri']
219- i['metadata'] = {}
220- if EXTRA_METADATA:
221- for e in i:
222- for m in EXTRA_METADATA:
223- if m['id'] == e:
224- i['metadata'][e] = i[e]
225- i['metadata']['provider_credits'] = GLib.Variant('s', PROVIDER_CREDITS)
226 result_set.add_result(**i)
227 except Exception:
228 logger.exception("Error while building result set.")
229@@ -252,6 +232,11 @@
230 se = MySearch(search_context)
231 return se
232
233+ def do_create_previewer(self, result, metadata):
234+ rp = Preview()
235+ rp.set_scope_result(result)
236+ rp.set_search_metadata(metadata)
237+ return rp
238
239 def load_scope():
240 return Scope()
241
242=== modified file 'tests/test_songkick.py'
243--- tests/test_songkick.py 2013-10-03 19:07:24 +0000
244+++ tests/test_songkick.py 2013-10-07 20:41:53 +0000
245@@ -62,7 +62,7 @@
246 self.scope_module.logger.addHandler(handler)
247 result_set = self.perform_query("foo")
248 self.assertEqual(len(result_set.results), 0)
249- self.assertEqual(len(handler.records), 0)
250+ self.assertEqual(len(handler.records), 1)
251
252
253 class Handler(logging.Handler):

Subscribers

People subscribed via source and target branches

to all changes: