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

Proposed by David Callé
Status: Merged
Approved by: Michal Hruby
Approved revision: 21
Merged at revision: 21
Proposed branch: lp:~davidc3/unity-scope-launchpad/previews
Merge into: lp:unity-scope-launchpad
Diff against target: 136 lines (+64/-23)
1 file modified
src/unity_launchpad_daemon.py (+64/-23)
To merge this branch: bzr merge lp:~davidc3/unity-scope-launchpad/previews
Reviewer Review Type Date Requested Status
Michal Hruby (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+160940@code.launchpad.net

Commit message

Add previews

Description of the change

To post a comment you must log in.
Revision history for this message
Michal Hruby (mhr3) wrote :

48 + if len(results) > 25:
49 + break

Doesn't the API have a "limit" parameter?

review: Needs Information
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
David Callé (davidc3) wrote :

No

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

> No

:(

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/unity_launchpad_daemon.py'
2--- src/unity_launchpad_daemon.py 2013-03-19 22:25:43 +0000
3+++ src/unity_launchpad_daemon.py 2013-04-25 15:58:28 +0000
4@@ -18,6 +18,7 @@
5 from gi.repository import Gio, GLib
6 from launchpadlib.launchpad import Launchpad
7 import gettext
8+import datetime
9
10 APP_NAME = 'unity-scope-launchpad'
11 LOCAL_PATH = '/usr/share/locale/'
12@@ -33,7 +34,7 @@
13 PROVIDER_CREDITS = _('Powered by Launchpad')
14 SVG_DIR = '/usr/share/icons/unity-icon-theme/places/svg/'
15 PROVIDER_ICON = SVG_DIR+'service-launchpad.svg'
16-DEFAULT_RESULT_ICON = SVG_DIR+'result-developer.svg'
17+DEFAULT_RESULT_ICON = SVG_DIR+'group-developer.svg'
18 DEFAULT_RESULT_MIMETYPE = 'text/html'
19 DEFAULT_RESULT_TYPE = Unity.ResultType.DEFAULT
20
21@@ -66,7 +67,8 @@
22 extras metadata fields (variant)
23 '''
24 results = []
25-
26+ if len(search) < 2:
27+ return results
28 if search[0] == '#':
29 search = search[1:]
30 if search.isdigit():
31@@ -81,16 +83,13 @@
32 print (error)
33 if not len(search) >= 3 and search.isdigit():
34 return results
35- i = 0
36 for project in lp.projects.search(text=search):
37- if not i < 200:
38- return results
39- if not project.title:
40- return results
41 results.append({'uri':str(project.web_link),
42- 'icon':str(project.logo_link),
43- 'title':project.title})
44- i += 1
45+ 'icon':str(project.brand_link),
46+ 'title':str(project.title.encode('utf-8')),
47+ 'comment':str(project.name.encode('utf-8'))})
48+ if len(results) > 25:
49+ break
50 return results
51
52
53@@ -127,22 +126,58 @@
54 i['comment'] = ''
55 if not 'dnd_uri' in i or not i['dnd_uri'] or i['dnd_uri'] == '':
56 i['dnd_uri'] = i['uri']
57- i['metadata'] = {}
58- if EXTRA_METADATA:
59- for e in i:
60- for m in EXTRA_METADATA:
61- if m['id'] == e:
62- i['metadata'][e] = i[e]
63- i['metadata']['provider_credits'] = GLib.Variant('s', PROVIDER_CREDITS)
64- result = Unity.ScopeResult.create(str(i['uri']), str(i['icon']),
65- i['category'], i['result_type'],
66- str(i['mimetype']), str(i['title']),
67- str(i['comment']), str(i['dnd_uri']),
68- i['metadata'])
69- result_set.add_result(result)
70+ result_set.add_result(**i)
71 except Exception as error:
72 print (error)
73
74+class Preview (Unity.ResultPreviewer):
75+
76+ def do_run(self):
77+ project = lp.projects(self.result.comment)
78+ image = Gio.FileIcon.new(Gio.file_new_for_uri(self.result.icon_hint))
79+ screenshot = project.screenshots_url
80+ if screenshot and screenshot != '':
81+ if screenshot.endswith('.jpg') or screenshot.endswith('.png'):
82+ image = Gio.FileIcon.new(Gio.file_new_for_uri(screenshot))
83+ description = project.description
84+ if description:
85+ description = description.encode('utf-8')
86+ else:
87+ description = ''
88+ preview = Unity.GenericPreview.new(self.result.title, description, image)
89+ summary = project.summary
90+ if summary:
91+ summary = summary.encode('utf-8')
92+ preview.props.subtitle = summary
93+ created = project.date_created
94+ if created:
95+ created = created.strftime('%x')
96+ preview.add_info(Unity.InfoHint.new("created", _("Created"), None, str(created)))
97+
98+ licenses = project.licenses
99+ if licenses:
100+ licenses = ','.join(licenses)
101+ if ',' in licenses:
102+ license_display = _("Licenses")
103+ else:
104+ license_display = _("License")
105+ preview.add_info(Unity.InfoHint.new("licenses", license_display, None, licenses))
106+
107+ programming_language = project.programming_language
108+ if programming_language:
109+ programming_language = programming_language.encode('utf-8')
110+ if ',' in programming_language:
111+ language_display = _("Languages")
112+ else:
113+ language_display = _("Language")
114+ preview.add_info(Unity.InfoHint.new("languages", language_display, None, programming_language))
115+ icon = Gio.FileIcon.new (Gio.file_new_for_path(PROVIDER_ICON))
116+ view_action = Unity.PreviewAction.new("view", _("View"), icon)
117+ preview.add_action(view_action)
118+ return preview
119+
120+
121+
122 class Scope (Unity.AbstractScope):
123 def __init__(self):
124 Unity.AbstractScope.__init__(self)
125@@ -194,5 +229,11 @@
126 se = MySearch (search_context)
127 return se
128
129+ def do_create_previewer(self, result, metadata):
130+ rp = Preview()
131+ rp.set_scope_result(result)
132+ rp.set_search_metadata(metadata)
133+ return rp
134+
135 def load_scope():
136 return Scope()

Subscribers

People subscribed via source and target branches

to all changes: