Merge lp:~submarine/unity-scope-isgd/isgd-previews into lp:unity-scope-isgd
- isgd-previews
- Merge into trunk
Status: | Approved |
---|---|
Approved by: | David Callé |
Approved revision: | 12 |
Proposed branch: | lp:~submarine/unity-scope-isgd/isgd-previews |
Merge into: | lp:unity-scope-isgd |
Diff against target: |
372 lines (+99/-108) 7 files modified
.bzrignore (+5/-0) data/isgd.scope.in (+3/-3) data/unity-scope-isgd.service (+1/-1) debian/control (+1/-1) po/unity-scope-isgd.pot (+20/-12) setup.py (+1/-1) src/unity_isgd_daemon.py (+68/-90) |
To merge this branch: | bzr merge lp:~submarine/unity-scope-isgd/isgd-previews |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
David Callé | Approve | ||
Review via email: mp+159938@code.launchpad.net |
Commit message
Add Previews and Activation
Change from Utilities master scope to Info master scope
Description of the change
Add Previews and Activation
Change from Utilities master scope to Info master scope
James Henstridge (jamesh) wrote : | # |
+ description = '<big><b>' + self.result.title + "</b></big>\n\n"
+ description += _('is.gd is a free service for shortening web addresses and ')
+ description += _('other URLs. This is useful in many circumstances e.g. when ')
+ description += _('sending an address to a phone via SMS and character count is limited.\n\n')
+ description += _('Click the <i>Shorten url</i> button below to shorten <b>%s</b> ' % self.result.
+ description += _('and copy the shortened link to the clipboard, ready for pasting or the ')
+ description += _('<i>is.gd Preferences</i> button to visit is.gd\'s preferences ')
+ description += _('page.')
This is going to be a pain to translate, since the translator has 7 separate strings to translate. Can you do something like:
description = _(
'<big>
'...'
'Click the <i>Shorten url</i> button below to shorten <b>%(uri)s</b>'
'...') % dict(title=
It would be necessary to check that the string gets extracted correctly in the .pot file.
Unmerged revisions
- 12. By Mark Tully
-
Fix Previews and Activation
Change from Utilities master scope to Info master scope
Preview Diff
1 | === added file '.bzrignore' |
2 | --- .bzrignore 1970-01-01 00:00:00 +0000 |
3 | +++ .bzrignore 2013-04-20 13:47:26 +0000 |
4 | @@ -0,0 +1,5 @@ |
5 | +*.log |
6 | +*.substvars |
7 | +./build |
8 | +./debian/files |
9 | +./debian/unity-scope-isgd |
10 | |
11 | === modified file 'data/isgd.scope.in' |
12 | --- data/isgd.scope.in 2013-03-15 17:29:22 +0000 |
13 | +++ data/isgd.scope.in 2013-04-20 13:47:26 +0000 |
14 | @@ -1,13 +1,13 @@ |
15 | [Scope] |
16 | -DBusName=com.canonical.Unity.Scope.Utilities.Isgd |
17 | -DBusPath=/com/canonical/unity/scope/utilities/isgd |
18 | +DBusName=com.canonical.Unity.Scope.Info.Isgd |
19 | +DBusPath=/com/canonical/unity/scope/info/isgd |
20 | Icon= |
21 | _Keywords=isgd; |
22 | RequiredMetadata= |
23 | OptionalMetadata= |
24 | Loader=/usr/share/unity-scopes/isgd/unity_isgd_daemon.py |
25 | RemoteContent=true |
26 | -Type=utilities |
27 | +Type=info |
28 | _Name=Isgd |
29 | _Description=Find Isgd items |
30 | _SearchHint=Search Isgd |
31 | |
32 | === modified file 'data/unity-scope-isgd.service' |
33 | --- data/unity-scope-isgd.service 2013-03-14 12:28:39 +0000 |
34 | +++ data/unity-scope-isgd.service 2013-04-20 13:47:26 +0000 |
35 | @@ -1,3 +1,3 @@ |
36 | [D-BUS Service] |
37 | -Name=com.canonical.Unity.Scope.Utilities.Isgd |
38 | +Name=com.canonical.Unity.Scope.Info.Isgd |
39 | Exec=/usr/bin/python3 /usr/share/unity-scopes/scope-runner-dbus.py /usr/share/unity-scopes/isgd/unity_isgd_daemon.py |
40 | |
41 | === modified file 'debian/control' |
42 | --- debian/control 2013-03-14 15:15:18 +0000 |
43 | +++ debian/control 2013-04-20 13:47:26 +0000 |
44 | @@ -19,7 +19,7 @@ |
45 | ${python3:Depends}, |
46 | python3, |
47 | gir1.2-unity-5.0 (>= 6.8), |
48 | - gir1.2-dee-1.0, |
49 | + gir1.2-dee-1.0, |
50 | unity-scopes-runner, |
51 | gir1.2-glib-2.0 |
52 | Description: isgd scope for Unity |
53 | |
54 | === modified file 'debian/rules' (properties changed: -x to +x) |
55 | === modified file 'po/unity-scope-isgd.pot' |
56 | --- po/unity-scope-isgd.pot 2013-02-21 00:56:47 +0000 |
57 | +++ po/unity-scope-isgd.pot 2013-04-20 13:47:26 +0000 |
58 | @@ -9,7 +9,7 @@ |
59 | msgstr "" |
60 | "Project-Id-Version: PACKAGE VERSION\n" |
61 | "Report-Msgid-Bugs-To: \n" |
62 | -"POT-Creation-Date: 2013-02-21 01:56+0100\n" |
63 | +"POT-Creation-Date: 2013-04-18 01:13+0100\n" |
64 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
65 | "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
66 | "Language-Team: LANGUAGE <LL@li.org>\n" |
67 | @@ -30,55 +30,63 @@ |
68 | msgid "Shorten URL" |
69 | msgstr "" |
70 | |
71 | -#: ../src/unity_isgd_daemon.py:79 |
72 | +#: ../src/unity_isgd_daemon.py:80 |
73 | #, python-format |
74 | msgid "Shorten %s with is.gd" |
75 | msgstr "" |
76 | |
77 | -#: ../src/unity_isgd_daemon.py:101 |
78 | +#: ../src/unity_isgd_daemon.py:105 |
79 | msgid "Copied shortened url to clipboard" |
80 | msgstr "" |
81 | |
82 | -#: ../src/unity_isgd_daemon.py:101 |
83 | +#: ../src/unity_isgd_daemon.py:105 |
84 | #, python-format |
85 | msgid "%s → %s" |
86 | msgstr "" |
87 | |
88 | -#: ../src/unity_isgd_daemon.py:125 |
89 | +#: ../src/unity_isgd_daemon.py:117 |
90 | msgid "is.gd url shortener" |
91 | msgstr "" |
92 | |
93 | -#: ../src/unity_isgd_daemon.py:127 |
94 | +#: ../src/unity_isgd_daemon.py:120 |
95 | msgid "is.gd is a free service for shortening web addresses and " |
96 | msgstr "" |
97 | |
98 | -#: ../src/unity_isgd_daemon.py:128 |
99 | +#: ../src/unity_isgd_daemon.py:121 |
100 | msgid "other URLs. This is useful in many circumstances e.g. when " |
101 | msgstr "" |
102 | |
103 | -#: ../src/unity_isgd_daemon.py:129 |
104 | +#: ../src/unity_isgd_daemon.py:122 |
105 | msgid "" |
106 | "sending an address to a phone via SMS and character count is limited.\n" |
107 | "\n" |
108 | msgstr "" |
109 | |
110 | -#: ../src/unity_isgd_daemon.py:130 |
111 | +#: ../src/unity_isgd_daemon.py:123 |
112 | #, python-format |
113 | msgid "Click the <i>Shorten url</i> button below to shorten <b>%s</b> " |
114 | msgstr "" |
115 | |
116 | -#: ../src/unity_isgd_daemon.py:131 |
117 | +#: ../src/unity_isgd_daemon.py:124 |
118 | msgid "and copy the shortened link to the clipboard, ready for pasting or the " |
119 | msgstr "" |
120 | |
121 | -#: ../src/unity_isgd_daemon.py:132 |
122 | +#: ../src/unity_isgd_daemon.py:125 |
123 | msgid "<i>is.gd Preferences</i> button to visit is.gd's preferences " |
124 | msgstr "" |
125 | |
126 | -#: ../src/unity_isgd_daemon.py:133 |
127 | +#: ../src/unity_isgd_daemon.py:126 |
128 | msgid "page." |
129 | msgstr "" |
130 | |
131 | +#: ../src/unity_isgd_daemon.py:128 |
132 | +msgid "Shorten" |
133 | +msgstr "" |
134 | + |
135 | +#: ../src/unity_isgd_daemon.py:130 |
136 | +msgid "Preferences" |
137 | +msgstr "" |
138 | + |
139 | #: ../data/isgd.scope.in.h:1 |
140 | msgid "isgd;" |
141 | msgstr "" |
142 | |
143 | === modified file 'setup.py' |
144 | --- setup.py 2013-03-14 12:28:39 +0000 |
145 | +++ setup.py 2013-04-20 13:47:26 +0000 |
146 | @@ -16,7 +16,7 @@ |
147 | url='http://launchpad.net/ubuntu-scopes', |
148 | license='GNU General Public License (GPL)', |
149 | data_files=[('share/dbus-1/services', ['data/unity-scope-isgd.service']), |
150 | - ('share/icons/unity-icon-theme/places/svg', ['data/icons/service-isgd.svg']), |
151 | + #('share/icons/unity-icon-theme/places/svg', ['data/icons/service-isgd.svg']), |
152 | ('share/unity-scopes/isgd', ['src/unity_isgd_daemon.py']), |
153 | ('share/unity-scopes/isgd', ['src/__init__.py']), ], |
154 | cmdclass={'build': build_extra.build_extra, |
155 | |
156 | === modified file 'src/unity_isgd_daemon.py' |
157 | --- src/unity_isgd_daemon.py 2013-03-14 12:28:39 +0000 |
158 | +++ src/unity_isgd_daemon.py 2013-04-20 13:47:26 +0000 |
159 | @@ -18,6 +18,7 @@ |
160 | from gi.repository import Unity |
161 | import gettext |
162 | import urllib.request |
163 | +import urllib.parse |
164 | import json |
165 | import subprocess |
166 | import webbrowser |
167 | @@ -28,20 +29,20 @@ |
168 | gettext.textdomain(APP_NAME) |
169 | _ = gettext.gettext |
170 | |
171 | -GROUP_NAME = 'com.canonical.Unity.Scope.Utilities.Isgd' |
172 | -UNIQUE_PATH = '/com/canonical/unity/scope/utilities/isgd' |
173 | +GROUP_NAME = 'com.canonical.Unity.Scope.Info.Isgd' |
174 | +UNIQUE_PATH = '/com/canonical/unity/scope/info/isgd' |
175 | |
176 | SEARCH_HINT = _('Shorten URL with is.gd') |
177 | NO_RESULTS_HINT = _('Sorry, there is no url to shorten') |
178 | PROVIDER_CREDITS = _('') |
179 | SVG_DIR = '/usr/share/icons/unity-icon-theme/places/svg/' |
180 | PROVIDER_ICON = SVG_DIR + 'service-isgd.svg' |
181 | -DEFAULT_RESULT_ICON = SVG_DIR + 'result-help.svg' |
182 | -DEFAULT_RESULT_MIMETYPE = 'x-scheme-handler/man' |
183 | +DEFAULT_RESULT_ICON = SVG_DIR + 'result-isgd.svg' |
184 | +DEFAULT_RESULT_MIMETYPE = 'text/html' |
185 | DEFAULT_RESULT_TYPE = Unity.ResultType.DEFAULT |
186 | SEARCH_URI = 'http://is.gd/create.php?format=json&url=%s' |
187 | |
188 | -c1 = {'id': 'shorten', |
189 | +c1 = {'id': 'results', |
190 | 'name': _('Shorten URL'), |
191 | 'icon': SVG_DIR + 'group-installed.svg', |
192 | 'renderer': Unity.CategoryRenderer.VERTICAL_TILE} |
193 | @@ -69,90 +70,63 @@ |
194 | try: |
195 | urllib.request.urlopen(search) |
196 | real = True |
197 | - except: |
198 | + except IOError: |
199 | real = False |
200 | if real: |
201 | if not search.startswith("http://is.gd"): |
202 | results.append({'uri': search, |
203 | - 'icon': '', |
204 | - 'category': 0, |
205 | - 'title': _("Shorten %s with is.gd" % search), |
206 | - 'comment': ''}) |
207 | + 'title': _("Shorten %s with is.gd" % search)}) |
208 | return results |
209 | |
210 | |
211 | -def activate(scope, uri): |
212 | +def activate(result, metadata, action): |
213 | ''' |
214 | On activation, the url is shortened and the shortened version is |
215 | copied to the system clipboard. A notificatin is also displayed |
216 | letting the user know what has happened. |
217 | ''' |
218 | - # FIXME: Activate is not yet implemented |
219 | - search_url = SEARCH_URI % urllib.quote(uri) |
220 | - response = urllib.request.urlopen(search_url).read() |
221 | - try: |
222 | - json_response = json.loads(response) |
223 | - except: |
224 | - result = None |
225 | - clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) |
226 | - clipboard.set_text(json_response['shorturl'], -1) |
227 | - clipboard.store() |
228 | - |
229 | - subprocess.Popen(["notify-send", _("Copied shortened url to clipboard"), _("%s → %s" % (uri, json_response['shorturl'])), "-i", SERVICE_ICON_LOCATION]) |
230 | - return Unity.ActivationResponse(handled=Unity.HandledType.HIDE_DASH, goto_uri='') |
231 | - |
232 | - |
233 | -def visit_prefs(scope, uri): |
234 | - ''' |
235 | - Open the webbrowser to is.gd's preferences page |
236 | - ''' |
237 | - webbrowser.open('http://is.gd/previews.php') |
238 | - return Unity.ActivationResponse(handled=Unity.HandledType.HIDE_DASH, goto_uri='') |
239 | - |
240 | - |
241 | -def preview(scope, uri): |
242 | - ''' |
243 | - Preview request handler |
244 | - ''' |
245 | - # FIXME: Preview is not yet implemented |
246 | - model = self.model |
247 | - iteration = model.get_first_iter() |
248 | - end_iter = model.get_last_iter() |
249 | - preview = None |
250 | - while iteration != end_iter: |
251 | - if model.get_value(iteration, 0) == uri: |
252 | - display_uri = uri.replace('&', '&') |
253 | - title = _("is.gd url shortener") |
254 | - description = '<big><b>' + model.get_value(iteration, 5) + "</b></big>\n\n" |
255 | - description += _('is.gd is a free service for shortening web addresses and ') |
256 | - description += _('other URLs. This is useful in many circumstances e.g. when ') |
257 | - description += _('sending an address to a phone via SMS and character count is limited.\n\n') |
258 | - description += _('Click the <i>Shorten url</i> button below to shorten <b>%s</b> ' % display_uri) |
259 | - description += _('and copy the shortened link to the clipboard, ready for pasting or the ') |
260 | - description += _('<i>is.gd Preferences</i> button to visit is.gd\'s preferences ') |
261 | - description += _('page.') |
262 | - |
263 | - icon_hint = SVG_DIR + 'isgd.png' |
264 | - # Assemble the preview |
265 | - preview = Unity.GenericPreview.new(title, description, None) |
266 | - preview.props.image_source_uri = icon_hint |
267 | - preview.props.subtitle = model.get_value(iteration, 5) |
268 | - |
269 | - # Add the "View" action |
270 | - view_action = Unity.PreviewAction.new("activate_uri", "Shorten url", None) |
271 | - view_action.connect("activated", activate) |
272 | - preview.add_action(view_action) |
273 | - |
274 | - # Add the "View" action |
275 | - view_action = Unity.PreviewAction.new("visit_prefs", "is.gd Preferences", None) |
276 | - view_action.connect("activated", visit_prefs) |
277 | - preview.add_action(view_action) |
278 | - break |
279 | - |
280 | - iteration = model.next(iteration) |
281 | - if preview is None: |
282 | - print ("Couldn't find model row for requested preview uri: '%s'", uri) |
283 | - return preview |
284 | + if action == 'preferences': |
285 | + webbrowser.open('http://is.gd/previews.php') |
286 | + else: |
287 | + search_url = SEARCH_URI % urllib.parse.quote(result.uri) |
288 | + response = urllib.request.urlopen(search_url).read() |
289 | + json_response = json.loads(response.decode('utf8')) |
290 | + clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) |
291 | + clipboard.set_text(json_response['shorturl'], -1) |
292 | + clipboard.store() |
293 | + subprocess.Popen(["notify-send", |
294 | + _("Copied shortened url to clipboard"), |
295 | + _("%s → %s" % (result.uri, json_response['shorturl'])), |
296 | + "-i", |
297 | + DEFAULT_RESULT_ICON]) |
298 | + return Unity.ActivationResponse(handled=Unity.HandledType.HIDE_DASH, goto_uri='') |
299 | + |
300 | + |
301 | +class Preview(Unity.ResultPreviewer): |
302 | + ''' |
303 | + Creates the preview for the result |
304 | + ''' |
305 | + def do_run(self): |
306 | + ''' |
307 | + Create a preview and return it |
308 | + ''' |
309 | + preview = Unity.GenericPreview.new(_("is.gd url shortener"), '', None) |
310 | + preview.props.image_source_uri = 'file://%s' % self.result.icon_hint |
311 | + description = '<big><b>' + self.result.title + "</b></big>\n\n" |
312 | + description += _('is.gd is a free service for shortening web addresses and ') |
313 | + description += _('other URLs. This is useful in many circumstances e.g. when ') |
314 | + description += _('sending an address to a phone via SMS and character count is limited.\n\n') |
315 | + description += _('Click the <i>Shorten url</i> button below to shorten <b>%s</b> ' % self.result.uri.replace('&', '&')) |
316 | + description += _('and copy the shortened link to the clipboard, ready for pasting or the ') |
317 | + description += _('<i>is.gd Preferences</i> button to visit is.gd\'s preferences ') |
318 | + description += _('page.') |
319 | + preview.props.description_markup = description |
320 | + shorten_action = Unity.PreviewAction.new("shorten", _("Shorten url"), None) |
321 | + preview.add_action(shorten_action) |
322 | + preferences_action = Unity.PreviewAction.new("preferences", _("isgd Preferences"), None) |
323 | + preview.add_action(preferences_action) |
324 | + return preview |
325 | + |
326 | |
327 | # Classes below this point establish communication |
328 | # with Unity, you probably shouldn't modify them. |
329 | @@ -187,19 +161,8 @@ |
330 | i['comment'] = '' |
331 | if not 'dnd_uri' in i or not i['dnd_uri'] or i['dnd_uri'] == '': |
332 | i['dnd_uri'] = i['uri'] |
333 | - i['metadata'] = {} |
334 | - if EXTRA_METADATA: |
335 | - for e in i: |
336 | - for m in EXTRA_METADATA: |
337 | - if m['id'] == e: |
338 | - i['metadata'][e] = i[e] |
339 | - i['metadata']['provider_credits'] = GLib.Variant('s', PROVIDER_CREDITS) |
340 | - result = Unity.ScopeResult.create(str(i['uri']), str(i['icon']), |
341 | - i['category'], i['result_type'], |
342 | - str(i['mimetype']), str(i['title']), |
343 | - str(i['comment']), str(i['dnd_uri']), |
344 | - i['metadata']) |
345 | - result_set.add_result(result) |
346 | + i['provider_credits'] = GLib.Variant('s', PROVIDER_CREDITS) |
347 | + result_set.add_result(**i) |
348 | except Exception as error: |
349 | print(error) |
350 | |
351 | @@ -255,6 +218,21 @@ |
352 | se = MySearch(search_context) |
353 | return se |
354 | |
355 | + def do_activate(self, result, metadata, action): |
356 | + ''' |
357 | + What to do when a resut is clicked |
358 | + ''' |
359 | + return activate(result, metadata, action) |
360 | + |
361 | + def do_create_previewer(self, result, metadata): |
362 | + ''' |
363 | + Creates a preview when a resut is right-clicked |
364 | + ''' |
365 | + result_preview = Preview() |
366 | + result_preview.set_scope_result(result) |
367 | + result_preview.set_search_metadata(metadata) |
368 | + return result_preview |
369 | + |
370 | |
371 | def load_scope(): |
372 | return Scope() |
+1