Merge lp:~gary-lasker/software-center/launcher-integration-lp761851 into lp:software-center

Proposed by Gary Lasker on 2012-01-27
Status: Merged
Merged at revision: 2710
Proposed branch: lp:~gary-lasker/software-center/launcher-integration-lp761851
Merge into: lp:software-center
Diff against target: 309 lines (+75/-95)
4 files modified
debian/changelog (+6/-1)
softwarecenter/backend/unitylauncher.py (+8/-27)
softwarecenter/ui/gtk3/panes/availablepane.py (+20/-36)
test/gtk3/test_unity_launcher_integration.py (+41/-31)
To merge this branch: bzr merge lp:~gary-lasker/software-center/launcher-integration-lp761851
Reviewer Review Type Date Requested Status
software-store-developers 2012-01-27 Pending
Review via email: mp+90354@code.launchpad.net

Description of the change

This branch completes the software-center side implementation of the new Unity launcher functionality as specified at https://wiki.ubuntu.com/SoftwareCenter#Learning_how_to_launch_an_application. Note that there remains some additional functionality to be completed on the Unity side (see details in the Unity MP https://code.launchpad.net/~bilalakhtar/unity/software-center-integration-for-o/+merge/89364), but as of this branch the software-center side of the feature should be complete.

I've updated the corresponding unit test for the changes.

NOTE: This branch should land and be released as soon as possible after the corresponding Unity release (scheduled for tonight? but no sign of it yet).

Many thanks!

To post a comment you must log in.
2601. By Gary Lasker on 2012-01-30

sync up with latest trunk

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2012-01-30 03:59:38 +0000
3+++ debian/changelog 2012-01-30 04:08:26 +0000
4@@ -15,7 +15,12 @@
5 - add a test function in test_utils.py which covers all of
6 get_nice_date_string
7
8- -- Gary Lasker <gary.lasker@canonical.com> Sun, 29 Jan 2012 22:57:47 -0500
9+ [ Gary Lasker ]
10+ * lp:~gary-lasker/software-center/launcher-integration-lp761851:
11+ - update to the Unity launcher integration implementation to
12+ support the revamped functionality on the Unity side (LP: #761851)
13+
14+ -- Gary Lasker <gary.lasker@canonical.com> Sun, 29 Jan 2012 23:04:52 -0500
15
16 software-center (5.1.7) precise; urgency=low
17
18
19=== modified file 'softwarecenter/backend/unitylauncher.py'
20--- softwarecenter/backend/unitylauncher.py 2011-11-29 21:50:55 +0000
21+++ softwarecenter/backend/unitylauncher.py 2012-01-30 04:08:26 +0000
22@@ -33,7 +33,6 @@
23 icon_y,
24 icon_size,
25 app_install_desktop_file_path,
26- installed_desktop_file_path,
27 trans_id):
28 self.name = name
29 self.icon_name = icon_name
30@@ -42,43 +41,25 @@
31 self.icon_y = icon_y
32 self.icon_size = icon_size
33 self.app_install_desktop_file_path = app_install_desktop_file_path
34- self.installed_desktop_file_path = installed_desktop_file_path
35 self.trans_id = trans_id
36
37 class UnityLauncher(object):
38 """ Implements the integration between Software Center and the Unity
39 launcher
40 """
41- def __init__(self):
42- # keep track of applications that are candidates for adding
43- # to the Unity launcher
44- self.launcher_queue = {}
45-
46- def add_to_launcher_queue(self, pkgname, launcher_info):
47- """ add an application and its associated info to the set of candidates
48- for adding to the Unity launcher
49- """
50- self.launcher_queue[pkgname] = launcher_info
51-
52- def remove_from_launcher_queue(self, pkgname):
53- """ remove an application and its associated info from the set of
54- candidates for adding to the Unity launcher
55- """
56- if pkgname in self.launcher_queue:
57- return self.launcher_queue.pop(pkgname)
58-
59+
60 def send_application_to_launcher(self, pkgname, launcher_info):
61+ """ send a dbus message to the Unity launcher service to initiate
62+ the add to launcher functionality for the specified application
63+ """
64 LOG.debug("sending dbus signal to Unity launcher for application: ",
65 launcher_info.name)
66 LOG.debug(" launcher_info.icon_file_path: ",
67 launcher_info.icon_file_path)
68- LOG.debug(" launcher_info.installed_desktop_file_path: ",
69- launcher_info.installed_desktop_file_path)
70+ LOG.debug(" launcher_info.app_install_desktop_file_path: ",
71+ launcher_info.app_install_desktop_file_path)
72 LOG.debug(" launcher_info.trans_id: ", launcher_info.trans_id)
73- # the application is being added to the launcher, so clear it from the
74- # list of candidates in the launcher queue
75- self.remove_from_launcher_queue(pkgname)
76- # add the application by sending a dbus signal to the Unity launcher
77+
78 try:
79 bus = dbus.SessionBus()
80 launcher_obj = bus.get_object('com.canonical.Unity.Launcher',
81@@ -91,7 +72,7 @@
82 launcher_info.icon_x,
83 launcher_info.icon_y,
84 launcher_info.icon_size,
85- launcher_info.installed_desktop_file_path,
86+ launcher_info.app_install_desktop_file_path,
87 launcher_info.trans_id)
88 except Exception as e:
89 LOG.warn("could not send dbus signal to the Unity launcher: (%s)",
90
91=== modified file 'softwarecenter/ui/gtk3/panes/availablepane.py'
92--- softwarecenter/ui/gtk3/panes/availablepane.py 2012-01-12 20:18:16 +0000
93+++ softwarecenter/ui/gtk3/panes/availablepane.py 2012-01-30 04:08:26 +0000
94@@ -37,7 +37,6 @@
95 from softwarecenter.paths import APP_INSTALL_PATH
96 from softwarecenter.utils import (wait_for_apt_cache_ready,
97 get_exec_line_from_desktop,
98- convert_desktop_file_to_installed_location,
99 get_file_path_from_iconname)
100 from softwarecenter.db.appfilter import AppFilter
101 from softwarecenter.db.database import Application
102@@ -199,8 +198,6 @@
103 # install backend
104 self.backend.connect("transactions-changed", self._on_transactions_changed)
105 self.backend.connect("transaction-started", self.on_transaction_started)
106- self.backend.connect("transaction-finished", self.on_transaction_finished)
107- self.backend.connect("transaction-stopped", self.on_transaction_stopped)
108
109 # now we are initialized
110 self.searchentry.set_sensitive(True)
111@@ -352,22 +349,22 @@
112
113 def on_transaction_started(self, backend, pkgname, appname, trans_id,
114 trans_type):
115- self._register_unity_launcher_transaction_started(
116- backend, pkgname, appname, trans_id, trans_type)
117+ self._add_application_to_unity_launcher(
118+ backend, pkgname, appname, trans_id, trans_type)
119
120- def _register_unity_launcher_transaction_started(self, backend, pkgname,
121- appname, trans_id,
122- trans_type):
123+ def _add_application_to_unity_launcher(self, backend, pkgname,
124+ appname, trans_id,
125+ trans_type):
126 if not self.add_to_launcher_enabled:
127 return
128 # mvo: use use softwarecenter.utils explictly so that we can monkey
129 # patch it in the test
130 if not softwarecenter.utils.is_unity_running():
131 return
132- # we only care about getting the launcher information on an install
133+ # we only care about installs
134 if not trans_type == TransactionTypes.INSTALL:
135 return
136- # gather details for this transaction and create the launcher_info object
137+
138 app = Application(pkgname=pkgname, appname=appname)
139 appdetails = app.get_details(self.db)
140 # we only add items to the launcher that have a desktop file
141@@ -380,17 +377,26 @@
142 not get_exec_line_from_desktop(appdetails.desktop_file)):
143 return
144
145- (icon_size, icon_x, icon_y) = self._get_onscreen_icon_details_for_launcher_service(app)
146+ # now gather up the unity launcher info items and send the app to the
147+ # launcher service
148+ launcher_info = self._get_unity_launcher_info(app, appdetails, trans_id)
149+ self.unity_launcher.send_application_to_launcher(pkgname, launcher_info)
150+
151+ def _get_unity_launcher_info(self, app, appdetails, trans_id):
152+ (icon_size, icon_x, icon_y) = (
153+ self._get_onscreen_icon_details_for_launcher_service(app))
154+ icon_path = get_file_path_from_iconname(
155+ self.icons,
156+ iconname=appdetails.icon_file_name)
157 launcher_info = UnityLauncherInfo(app.name,
158 appdetails.icon,
159- "", # we set the icon_file_path value *after* install
160+ icon_path,
161 icon_x,
162 icon_y,
163 icon_size,
164 appdetails.desktop_file,
165- "", # we set the installed_desktop_file_path *after* install
166 trans_id)
167- self.unity_launcher.add_to_launcher_queue(app.pkgname, launcher_info)
168+ return launcher_info
169
170 def _get_onscreen_icon_details_for_launcher_service(self, app):
171 if self.is_app_details_view_showing():
172@@ -399,28 +405,6 @@
173 # TODO: implement the app list view case once it has been specified
174 return (0, 0, 0)
175
176- def on_transaction_finished(self, backend, result):
177- self._check_unity_launcher_transaction_finished(result)
178-
179- def _check_unity_launcher_transaction_finished(self, result):
180- # add the completed transaction details to the corresponding
181- # launcher_item
182- if result.pkgname in self.unity_launcher.launcher_queue:
183- launcher_info = self.unity_launcher.launcher_queue[result.pkgname]
184- launcher_info.icon_file_path = get_file_path_from_iconname(
185- self.icons, launcher_info.icon_name)
186- installed_path = convert_desktop_file_to_installed_location(
187- launcher_info.app_install_desktop_file_path, result.pkgname)
188- launcher_info.installed_desktop_file_path = installed_path
189- if result.success:
190- self.unity_launcher.send_application_to_launcher(
191- result.pkgname, launcher_info)
192- else:
193- self.unity_launcher.remove_from_launcher_queue(result.pkgname)
194-
195- def on_transaction_stopped(self, backend, result):
196- self.unity_launcher.remove_from_launcher_queue(result.pkgname)
197-
198 def on_app_list_changed(self, pane, length):
199 """internal helper that keeps the status text and the action
200 bar up-to-date by keeping track of the app-list-changed
201
202=== modified file 'test/gtk3/test_unity_launcher_integration.py'
203--- test/gtk3/test_unity_launcher_integration.py 2012-01-16 14:42:49 +0000
204+++ test/gtk3/test_unity_launcher_integration.py 2012-01-30 04:08:26 +0000
205@@ -4,8 +4,6 @@
206 import time
207 import unittest
208
209-from mock import Mock
210-
211 from testutils import setup_test_env
212 setup_test_env()
213
214@@ -16,6 +14,7 @@
215 from softwarecenter.utils import convert_desktop_file_to_installed_location
216 from softwarecenter.db.application import Application
217 from softwarecenter.ui.gtk3.panes.availablepane import get_test_window
218+from softwarecenter.backend.unitylauncher import UnityLauncherInfo
219
220 # we can only have one instance of availablepane, so create it here
221 win = get_test_window()
222@@ -51,47 +50,58 @@
223 TransactionTypes.INSTALL)
224 # wait a wee bit
225 self._zzz()
226-
227- def test_unity_launcher_integration(self):
228- # test the automatic add to launcher enabled functionality
229- available_pane.add_to_launcher_enabled = True
230- test_pkgname = "lincity-ng"
231- mock_result = Mock()
232- mock_result.pkgname = test_pkgname
233- mock_result.success = True
234- # now pretend
235- self._navigate_to_appdetails_and_install(test_pkgname)
236
237- # check that a correct UnityLauncherInfo object has been created and
238- # added to the queue
239- self.assertTrue(test_pkgname in available_pane.unity_launcher.launcher_queue)
240- launcher_info = available_pane.unity_launcher.remove_from_launcher_queue(test_pkgname)
241- # check the UnityLauncherInfo values themselves
242- self.assertEqual(launcher_info.name, "lincity-ng")
243- self.assertEqual(launcher_info.icon_name, "lincity-ng")
244+ def _fake_send_application_to_launcher_and_check(self,
245+ pkgname, launcher_info):
246+ self.assertEqual(pkgname, self.expected_pkgname)
247+ self.assertEqual(launcher_info.name, self.expected_launcher_info.name)
248+ self.assertEqual(launcher_info.icon_name,
249+ self.expected_launcher_info.icon_name)
250 self.assertTrue(launcher_info.icon_x > 5)
251 self.assertTrue(launcher_info.icon_y > 5)
252 self.assertEqual(launcher_info.icon_size, 96)
253 self.assertEqual(launcher_info.app_install_desktop_file_path,
254- "/usr/share/app-install/desktop/lincity-ng:lincity-ng.desktop")
255- self.assertEqual(launcher_info.trans_id, "testid101")
256- # finally, make sure the the app has been removed from the launcher
257- # queue
258- self.assertFalse(test_pkgname in available_pane.unity_launcher.launcher_queue)
259+ self.expected_launcher_info.app_install_desktop_file_path)
260+ self.assertEqual(launcher_info.trans_id,
261+ self.expected_launcher_info.trans_id)
262+
263+ def test_unity_launcher_integration(self):
264+ # test the automatic add to launcher enabled functionality
265+ available_pane.add_to_launcher_enabled = True
266+ test_pkgname = "lincity-ng"
267+ # now pretend
268+ # for testing, we substitute a fake version of UnityLauncher's
269+ # send_application_to_launcher method that lets us check for the
270+ # correct values and also avoids firing the actual dbus signal
271+ # to the unity launcher service
272+ self.expected_pkgname = test_pkgname
273+ self.expected_launcher_info = UnityLauncherInfo("lincity-ng",
274+ "lincity-ng",
275+ 0, 0, 0, 0, # these values are set in availablepane
276+ "/usr/share/app-install/desktop/lincity-ng:lincity-ng.desktop",
277+ "testid101")
278+ available_pane.unity_launcher.send_application_to_launcher = (
279+ self._fake_send_application_to_launcher_and_check)
280+ self._navigate_to_appdetails_and_install(test_pkgname)
281
282 def test_unity_launcher_integration_disabled(self):
283 # test the case where automatic add to launcher is disabled
284 available_pane.add_to_launcher_enabled = False
285 test_pkgname = "lincity-ng"
286- mock_result = Mock()
287- mock_result.pkgname = test_pkgname
288- mock_result.success = True
289 # now pretend
290+ # for testing, we substitute a fake version of UnityLauncher's
291+ # send_application_to_launcher method that lets us check for the
292+ # correct values and also avoids firing the actual dbus signal
293+ # to the unity launcher service
294+ # in the disabled add to launcher case, we just want to insure
295+ # that we never call send_application_to_launcher, so we can just
296+ # plug in bogus values and we will catch a call if it occurs
297+ self.expected_pkgname = ""
298+ self.expected_launcher_info = UnityLauncherInfo("", "",
299+ 0, 0, 0, 0, "", "")
300+ available_pane.unity_launcher.send_application_to_launcher = (
301+ self._fake_send_application_to_launcher_and_check)
302 self._navigate_to_appdetails_and_install(test_pkgname)
303-
304- # check that no corresponding unity_launcher info object has been added
305- # to the queue
306- self.assertFalse(test_pkgname in available_pane.unity_launcher.launcher_queue)
307
308 def test_desktop_file_path_conversion(self):
309 # test 'normal' case

Subscribers

People subscribed via source and target branches