Merge lp:~submarine/unity-scope-isgd/isgd-previews into lp:unity-scope-isgd

Proposed by Mark Tully
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
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

To post a comment you must log in.
Revision history for this message
David Callé (davidc3) wrote :

+1

review: Approve
Revision history for this message
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.uri.replace('&', '&amp;'))
+ 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><b>%(title)s</b></big>\n\n'
    '...'
    'Click the <i>Shorten url</i> button below to shorten <b>%(uri)s</b>'
    '...') % dict(title=escape(self.result.title), uri=escape(self.result.uri))

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

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file '.bzrignore'
--- .bzrignore 1970-01-01 00:00:00 +0000
+++ .bzrignore 2013-04-20 13:47:26 +0000
@@ -0,0 +1,5 @@
1*.log
2*.substvars
3./build
4./debian/files
5./debian/unity-scope-isgd
06
=== modified file 'data/isgd.scope.in'
--- data/isgd.scope.in 2013-03-15 17:29:22 +0000
+++ data/isgd.scope.in 2013-04-20 13:47:26 +0000
@@ -1,13 +1,13 @@
1[Scope]1[Scope]
2DBusName=com.canonical.Unity.Scope.Utilities.Isgd2DBusName=com.canonical.Unity.Scope.Info.Isgd
3DBusPath=/com/canonical/unity/scope/utilities/isgd3DBusPath=/com/canonical/unity/scope/info/isgd
4Icon=4Icon=
5_Keywords=isgd;5_Keywords=isgd;
6RequiredMetadata=6RequiredMetadata=
7OptionalMetadata=7OptionalMetadata=
8Loader=/usr/share/unity-scopes/isgd/unity_isgd_daemon.py8Loader=/usr/share/unity-scopes/isgd/unity_isgd_daemon.py
9RemoteContent=true9RemoteContent=true
10Type=utilities10Type=info
11_Name=Isgd11_Name=Isgd
12_Description=Find Isgd items12_Description=Find Isgd items
13_SearchHint=Search Isgd13_SearchHint=Search Isgd
1414
=== modified file 'data/unity-scope-isgd.service'
--- data/unity-scope-isgd.service 2013-03-14 12:28:39 +0000
+++ data/unity-scope-isgd.service 2013-04-20 13:47:26 +0000
@@ -1,3 +1,3 @@
1[D-BUS Service]1[D-BUS Service]
2Name=com.canonical.Unity.Scope.Utilities.Isgd2Name=com.canonical.Unity.Scope.Info.Isgd
3Exec=/usr/bin/python3 /usr/share/unity-scopes/scope-runner-dbus.py /usr/share/unity-scopes/isgd/unity_isgd_daemon.py3Exec=/usr/bin/python3 /usr/share/unity-scopes/scope-runner-dbus.py /usr/share/unity-scopes/isgd/unity_isgd_daemon.py
44
=== modified file 'debian/control'
--- debian/control 2013-03-14 15:15:18 +0000
+++ debian/control 2013-04-20 13:47:26 +0000
@@ -19,7 +19,7 @@
19 ${python3:Depends},19 ${python3:Depends},
20 python3,20 python3,
21 gir1.2-unity-5.0 (>= 6.8),21 gir1.2-unity-5.0 (>= 6.8),
22   gir1.2-dee-1.0,22 gir1.2-dee-1.0,
23 unity-scopes-runner,23 unity-scopes-runner,
24 gir1.2-glib-2.024 gir1.2-glib-2.0
25Description: isgd scope for Unity25Description: isgd scope for Unity
2626
=== modified file 'debian/rules' (properties changed: -x to +x)
=== modified file 'po/unity-scope-isgd.pot'
--- po/unity-scope-isgd.pot 2013-02-21 00:56:47 +0000
+++ po/unity-scope-isgd.pot 2013-04-20 13:47:26 +0000
@@ -9,7 +9,7 @@
9msgstr ""9msgstr ""
10"Project-Id-Version: PACKAGE VERSION\n"10"Project-Id-Version: PACKAGE VERSION\n"
11"Report-Msgid-Bugs-To: \n"11"Report-Msgid-Bugs-To: \n"
12"POT-Creation-Date: 2013-02-21 01:56+0100\n"12"POT-Creation-Date: 2013-04-18 01:13+0100\n"
13"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"13"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
14"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"14"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
15"Language-Team: LANGUAGE <LL@li.org>\n"15"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -30,55 +30,63 @@
30msgid "Shorten URL"30msgid "Shorten URL"
31msgstr ""31msgstr ""
3232
33#: ../src/unity_isgd_daemon.py:7933#: ../src/unity_isgd_daemon.py:80
34#, python-format34#, python-format
35msgid "Shorten %s with is.gd"35msgid "Shorten %s with is.gd"
36msgstr ""36msgstr ""
3737
38#: ../src/unity_isgd_daemon.py:10138#: ../src/unity_isgd_daemon.py:105
39msgid "Copied shortened url to clipboard"39msgid "Copied shortened url to clipboard"
40msgstr ""40msgstr ""
4141
42#: ../src/unity_isgd_daemon.py:10142#: ../src/unity_isgd_daemon.py:105
43#, python-format43#, python-format
44msgid "%s → %s"44msgid "%s → %s"
45msgstr ""45msgstr ""
4646
47#: ../src/unity_isgd_daemon.py:12547#: ../src/unity_isgd_daemon.py:117
48msgid "is.gd url shortener"48msgid "is.gd url shortener"
49msgstr ""49msgstr ""
5050
51#: ../src/unity_isgd_daemon.py:12751#: ../src/unity_isgd_daemon.py:120
52msgid "is.gd is a free service for shortening web addresses and "52msgid "is.gd is a free service for shortening web addresses and "
53msgstr ""53msgstr ""
5454
55#: ../src/unity_isgd_daemon.py:12855#: ../src/unity_isgd_daemon.py:121
56msgid "other URLs. This is useful in many circumstances e.g. when "56msgid "other URLs. This is useful in many circumstances e.g. when "
57msgstr ""57msgstr ""
5858
59#: ../src/unity_isgd_daemon.py:12959#: ../src/unity_isgd_daemon.py:122
60msgid ""60msgid ""
61"sending an address to a phone via SMS and character count is limited.\n"61"sending an address to a phone via SMS and character count is limited.\n"
62"\n"62"\n"
63msgstr ""63msgstr ""
6464
65#: ../src/unity_isgd_daemon.py:13065#: ../src/unity_isgd_daemon.py:123
66#, python-format66#, python-format
67msgid "Click the <i>Shorten url</i> button below to shorten <b>%s</b> "67msgid "Click the <i>Shorten url</i> button below to shorten <b>%s</b> "
68msgstr ""68msgstr ""
6969
70#: ../src/unity_isgd_daemon.py:13170#: ../src/unity_isgd_daemon.py:124
71msgid "and copy the shortened link to the clipboard, ready for pasting or the "71msgid "and copy the shortened link to the clipboard, ready for pasting or the "
72msgstr ""72msgstr ""
7373
74#: ../src/unity_isgd_daemon.py:13274#: ../src/unity_isgd_daemon.py:125
75msgid "<i>is.gd Preferences</i> button to visit is.gd's preferences "75msgid "<i>is.gd Preferences</i> button to visit is.gd's preferences "
76msgstr ""76msgstr ""
7777
78#: ../src/unity_isgd_daemon.py:13378#: ../src/unity_isgd_daemon.py:126
79msgid "page."79msgid "page."
80msgstr ""80msgstr ""
8181
82#: ../src/unity_isgd_daemon.py:128
83msgid "Shorten"
84msgstr ""
85
86#: ../src/unity_isgd_daemon.py:130
87msgid "Preferences"
88msgstr ""
89
82#: ../data/isgd.scope.in.h:190#: ../data/isgd.scope.in.h:1
83msgid "isgd;"91msgid "isgd;"
84msgstr ""92msgstr ""
8593
=== modified file 'setup.py'
--- setup.py 2013-03-14 12:28:39 +0000
+++ setup.py 2013-04-20 13:47:26 +0000
@@ -16,7 +16,7 @@
16 url='http://launchpad.net/ubuntu-scopes',16 url='http://launchpad.net/ubuntu-scopes',
17 license='GNU General Public License (GPL)',17 license='GNU General Public License (GPL)',
18 data_files=[('share/dbus-1/services', ['data/unity-scope-isgd.service']),18 data_files=[('share/dbus-1/services', ['data/unity-scope-isgd.service']),
19 ('share/icons/unity-icon-theme/places/svg', ['data/icons/service-isgd.svg']),19 #('share/icons/unity-icon-theme/places/svg', ['data/icons/service-isgd.svg']),
20 ('share/unity-scopes/isgd', ['src/unity_isgd_daemon.py']),20 ('share/unity-scopes/isgd', ['src/unity_isgd_daemon.py']),
21 ('share/unity-scopes/isgd', ['src/__init__.py']), ],21 ('share/unity-scopes/isgd', ['src/__init__.py']), ],
22 cmdclass={'build': build_extra.build_extra,22 cmdclass={'build': build_extra.build_extra,
2323
=== modified file 'src/unity_isgd_daemon.py'
--- src/unity_isgd_daemon.py 2013-03-14 12:28:39 +0000
+++ src/unity_isgd_daemon.py 2013-04-20 13:47:26 +0000
@@ -18,6 +18,7 @@
18from gi.repository import Unity18from gi.repository import Unity
19import gettext19import gettext
20import urllib.request20import urllib.request
21import urllib.parse
21import json22import json
22import subprocess23import subprocess
23import webbrowser24import webbrowser
@@ -28,20 +29,20 @@
28gettext.textdomain(APP_NAME)29gettext.textdomain(APP_NAME)
29_ = gettext.gettext30_ = gettext.gettext
3031
31GROUP_NAME = 'com.canonical.Unity.Scope.Utilities.Isgd'32GROUP_NAME = 'com.canonical.Unity.Scope.Info.Isgd'
32UNIQUE_PATH = '/com/canonical/unity/scope/utilities/isgd'33UNIQUE_PATH = '/com/canonical/unity/scope/info/isgd'
3334
34SEARCH_HINT = _('Shorten URL with is.gd')35SEARCH_HINT = _('Shorten URL with is.gd')
35NO_RESULTS_HINT = _('Sorry, there is no url to shorten')36NO_RESULTS_HINT = _('Sorry, there is no url to shorten')
36PROVIDER_CREDITS = _('')37PROVIDER_CREDITS = _('')
37SVG_DIR = '/usr/share/icons/unity-icon-theme/places/svg/'38SVG_DIR = '/usr/share/icons/unity-icon-theme/places/svg/'
38PROVIDER_ICON = SVG_DIR + 'service-isgd.svg'39PROVIDER_ICON = SVG_DIR + 'service-isgd.svg'
39DEFAULT_RESULT_ICON = SVG_DIR + 'result-help.svg'40DEFAULT_RESULT_ICON = SVG_DIR + 'result-isgd.svg'
40DEFAULT_RESULT_MIMETYPE = 'x-scheme-handler/man'41DEFAULT_RESULT_MIMETYPE = 'text/html'
41DEFAULT_RESULT_TYPE = Unity.ResultType.DEFAULT42DEFAULT_RESULT_TYPE = Unity.ResultType.DEFAULT
42SEARCH_URI = 'http://is.gd/create.php?format=json&url=%s'43SEARCH_URI = 'http://is.gd/create.php?format=json&url=%s'
4344
44c1 = {'id': 'shorten',45c1 = {'id': 'results',
45 'name': _('Shorten URL'),46 'name': _('Shorten URL'),
46 'icon': SVG_DIR + 'group-installed.svg',47 'icon': SVG_DIR + 'group-installed.svg',
47 'renderer': Unity.CategoryRenderer.VERTICAL_TILE}48 'renderer': Unity.CategoryRenderer.VERTICAL_TILE}
@@ -69,90 +70,63 @@
69 try:70 try:
70 urllib.request.urlopen(search)71 urllib.request.urlopen(search)
71 real = True72 real = True
72 except:73 except IOError:
73 real = False74 real = False
74 if real:75 if real:
75 if not search.startswith("http://is.gd"):76 if not search.startswith("http://is.gd"):
76 results.append({'uri': search,77 results.append({'uri': search,
77 'icon': '',78 'title': _("Shorten %s with is.gd" % search)})
78 'category': 0,
79 'title': _("Shorten %s with is.gd" % search),
80 'comment': ''})
81 return results79 return results
8280
8381
84def activate(scope, uri):82def activate(result, metadata, action):
85 '''83 '''
86 On activation, the url is shortened and the shortened version is84 On activation, the url is shortened and the shortened version is
87 copied to the system clipboard. A notificatin is also displayed85 copied to the system clipboard. A notificatin is also displayed
88 letting the user know what has happened.86 letting the user know what has happened.
89 '''87 '''
90 # FIXME: Activate is not yet implemented88 if action == 'preferences':
91 search_url = SEARCH_URI % urllib.quote(uri)89 webbrowser.open('http://is.gd/previews.php')
92 response = urllib.request.urlopen(search_url).read()90 else:
93 try:91 search_url = SEARCH_URI % urllib.parse.quote(result.uri)
94 json_response = json.loads(response)92 response = urllib.request.urlopen(search_url).read()
95 except:93 json_response = json.loads(response.decode('utf8'))
96 result = None94 clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
97 clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)95 clipboard.set_text(json_response['shorturl'], -1)
98 clipboard.set_text(json_response['shorturl'], -1)96 clipboard.store()
99 clipboard.store()97 subprocess.Popen(["notify-send",
10098 _("Copied shortened url to clipboard"),
101 subprocess.Popen(["notify-send", _("Copied shortened url to clipboard"), _("%s → %s" % (uri, json_response['shorturl'])), "-i", SERVICE_ICON_LOCATION])99 _("%s → %s" % (result.uri, json_response['shorturl'])),
102 return Unity.ActivationResponse(handled=Unity.HandledType.HIDE_DASH, goto_uri='')100 "-i",
103101 DEFAULT_RESULT_ICON])
104102 return Unity.ActivationResponse(handled=Unity.HandledType.HIDE_DASH, goto_uri='')
105def visit_prefs(scope, uri):103
106 '''104
107 Open the webbrowser to is.gd's preferences page105class Preview(Unity.ResultPreviewer):
108 '''106 '''
109 webbrowser.open('http://is.gd/previews.php')107 Creates the preview for the result
110 return Unity.ActivationResponse(handled=Unity.HandledType.HIDE_DASH, goto_uri='')108 '''
111109 def do_run(self):
112110 '''
113def preview(scope, uri):111 Create a preview and return it
114 '''112 '''
115 Preview request handler113 preview = Unity.GenericPreview.new(_("is.gd url shortener"), '', None)
116 '''114 preview.props.image_source_uri = 'file://%s' % self.result.icon_hint
117 # FIXME: Preview is not yet implemented115 description = '<big><b>' + self.result.title + "</b></big>\n\n"
118 model = self.model116 description += _('is.gd is a free service for shortening web addresses and ')
119 iteration = model.get_first_iter()117 description += _('other URLs. This is useful in many circumstances e.g. when ')
120 end_iter = model.get_last_iter()118 description += _('sending an address to a phone via SMS and character count is limited.\n\n')
121 preview = None119 description += _('Click the <i>Shorten url</i> button below to shorten <b>%s</b> ' % self.result.uri.replace('&', '&amp;'))
122 while iteration != end_iter:120 description += _('and copy the shortened link to the clipboard, ready for pasting or the ')
123 if model.get_value(iteration, 0) == uri:121 description += _('<i>is.gd Preferences</i> button to visit is.gd\'s preferences ')
124 display_uri = uri.replace('&', '&amp;')122 description += _('page.')
125 title = _("is.gd url shortener")123 preview.props.description_markup = description
126 description = '<big><b>' + model.get_value(iteration, 5) + "</b></big>\n\n"124 shorten_action = Unity.PreviewAction.new("shorten", _("Shorten url"), None)
127 description += _('is.gd is a free service for shortening web addresses and ')125 preview.add_action(shorten_action)
128 description += _('other URLs. This is useful in many circumstances e.g. when ')126 preferences_action = Unity.PreviewAction.new("preferences", _("isgd Preferences"), None)
129 description += _('sending an address to a phone via SMS and character count is limited.\n\n')127 preview.add_action(preferences_action)
130 description += _('Click the <i>Shorten url</i> button below to shorten <b>%s</b> ' % display_uri)128 return preview
131 description += _('and copy the shortened link to the clipboard, ready for pasting or the ')129
132 description += _('<i>is.gd Preferences</i> button to visit is.gd\'s preferences ')
133 description += _('page.')
134
135 icon_hint = SVG_DIR + 'isgd.png'
136 # Assemble the preview
137 preview = Unity.GenericPreview.new(title, description, None)
138 preview.props.image_source_uri = icon_hint
139 preview.props.subtitle = model.get_value(iteration, 5)
140
141 # Add the "View" action
142 view_action = Unity.PreviewAction.new("activate_uri", "Shorten url", None)
143 view_action.connect("activated", activate)
144 preview.add_action(view_action)
145
146 # Add the "View" action
147 view_action = Unity.PreviewAction.new("visit_prefs", "is.gd Preferences", None)
148 view_action.connect("activated", visit_prefs)
149 preview.add_action(view_action)
150 break
151
152 iteration = model.next(iteration)
153 if preview is None:
154 print ("Couldn't find model row for requested preview uri: '%s'", uri)
155 return preview
156130
157# Classes below this point establish communication131# Classes below this point establish communication
158# with Unity, you probably shouldn't modify them.132# with Unity, you probably shouldn't modify them.
@@ -187,19 +161,8 @@
187 i['comment'] = ''161 i['comment'] = ''
188 if not 'dnd_uri' in i or not i['dnd_uri'] or i['dnd_uri'] == '':162 if not 'dnd_uri' in i or not i['dnd_uri'] or i['dnd_uri'] == '':
189 i['dnd_uri'] = i['uri']163 i['dnd_uri'] = i['uri']
190 i['metadata'] = {}164 i['provider_credits'] = GLib.Variant('s', PROVIDER_CREDITS)
191 if EXTRA_METADATA:165 result_set.add_result(**i)
192 for e in i:
193 for m in EXTRA_METADATA:
194 if m['id'] == e:
195 i['metadata'][e] = i[e]
196 i['metadata']['provider_credits'] = GLib.Variant('s', PROVIDER_CREDITS)
197 result = Unity.ScopeResult.create(str(i['uri']), str(i['icon']),
198 i['category'], i['result_type'],
199 str(i['mimetype']), str(i['title']),
200 str(i['comment']), str(i['dnd_uri']),
201 i['metadata'])
202 result_set.add_result(result)
203 except Exception as error:166 except Exception as error:
204 print(error)167 print(error)
205168
@@ -255,6 +218,21 @@
255 se = MySearch(search_context)218 se = MySearch(search_context)
256 return se219 return se
257220
221 def do_activate(self, result, metadata, action):
222 '''
223 What to do when a resut is clicked
224 '''
225 return activate(result, metadata, action)
226
227 def do_create_previewer(self, result, metadata):
228 '''
229 Creates a preview when a resut is right-clicked
230 '''
231 result_preview = Preview()
232 result_preview.set_scope_result(result)
233 result_preview.set_search_metadata(metadata)
234 return result_preview
235
258236
259def load_scope():237def load_scope():
260 return Scope()238 return Scope()

Subscribers

People subscribed via source and target branches

to all changes: