Merge lp:~mvo/software-center/click_url into lp:software-center/5.2

Proposed by Michael Vogt
Status: Merged
Merged at revision: 3059
Proposed branch: lp:~mvo/software-center/click_url
Merge into: lp:software-center/5.2
Diff against target: 110 lines (+44/-7)
4 files modified
softwarecenter/backend/scagent.py (+3/-0)
softwarecenter/ui/gtk3/views/catview_gtk.py (+11/-4)
softwarecenter/ui/gtk3/widgets/exhibits.py (+1/-2)
test/gtk3/test_catview.py (+29/-1)
To merge this branch: bzr merge lp:~mvo/software-center/click_url
Reviewer Review Type Date Requested Status
Gary Lasker (community) Approve
Review via email: mp+113079@code.launchpad.net

Description of the change

This small branch adds support for a "click_url" from the exhibits banner to support banners for things like the humble-bundle where we don't have packages but URLs.

To post a comment you must log in.
Revision history for this message
Gary Lasker (gary-lasker) wrote :

Hi Michael, this code looks good and the test case seems good. Were you by chance able to test this in the "real world" using a banner with a click_url value from the agent? In any case, this is straightforward and seems fine and so I will set this to approved and merge it.

Many thanks!

review: Approve
Revision history for this message
Michael Vogt (mvo) wrote :

On Mon, Jul 09, 2012 at 10:39:20PM -0000, Gary Lasker wrote:
> Review: Approve
>
> Hi Michael, this code looks good and the test case seems good. Were you by chance able to test this in the "real world" using a banner with a click_url value from the agent? In any case, this is straightforward and seems fine and so I will set this to approved and merge it.

Thanks for the review. I don't know of a easy way. One is to see if
the staging server for software-center-agent supports it and add one
there, the other one would be to make the default exhibit have a
click_url just for testing.

Cheers,
 Michael

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'softwarecenter/backend/scagent.py'
2--- softwarecenter/backend/scagent.py 2012-05-30 14:16:11 +0000
3+++ softwarecenter/backend/scagent.py 2012-07-02 17:09:21 +0000
4@@ -129,6 +129,9 @@
5 exhibit.html)
6 else:
7 exhibit.title_translated = ""
8+ # allow having urls to click on in a banner
9+ if not hasattr(exhibit, "click_url"):
10+ exhibit.click_url = ""
11 # ensure to fix #1004417
12 if exhibit.package_names:
13 exhibit.package_names = exhibit.package_names.strip()
14
15=== modified file 'softwarecenter/ui/gtk3/views/catview_gtk.py'
16--- softwarecenter/ui/gtk3/views/catview_gtk.py 2012-05-22 15:40:01 +0000
17+++ softwarecenter/ui/gtk3/views/catview_gtk.py 2012-07-02 17:09:21 +0000
18@@ -22,6 +22,7 @@
19 from gi.repository import Gtk, GObject
20 import logging
21 import os
22+import webbrowser
23 import xapian
24
25 from gettext import gettext as _
26@@ -328,7 +329,10 @@
27
28 def _on_show_exhibits(self, exhibit_banner, exhibit):
29 pkgs = exhibit.package_names.split(",")
30- if len(pkgs) == 1:
31+ url = exhibit.click_url
32+ if url:
33+ webbrowser.open_new_tab(url)
34+ elif len(pkgs) == 1:
35 app = Application("", pkgs[0])
36 self.emit("application-activated", app)
37 else:
38@@ -344,10 +348,13 @@
39 result = []
40 # filter out those exhibits that are not available in this run
41 for exhibit in exhibit_list:
42- available = all(self.db.is_pkgname_known(p) for p in
43- exhibit.package_names.split(','))
44- if available:
45+ if not exhibit.package_names:
46 result.append(exhibit)
47+ else:
48+ available = all(self.db.is_pkgname_known(p) for p in
49+ exhibit.package_names.split(','))
50+ if available:
51+ result.append(exhibit)
52
53 # its ok if result is empty, since set_exhibits() will ignore
54 # empty lists
55
56=== modified file 'softwarecenter/ui/gtk3/widgets/exhibits.py'
57--- softwarecenter/ui/gtk3/widgets/exhibits.py 2012-03-19 22:05:35 +0000
58+++ softwarecenter/ui/gtk3/widgets/exhibits.py 2012-07-02 17:09:21 +0000
59@@ -338,9 +338,8 @@
60 int(event.x), int(event.y)):
61 self.pressed = False
62 return
63-
64 exhibit = self.exhibits[self.cursor]
65- if exhibit.package_names and self.pressed:
66+ if (exhibit.package_names or exhibit.click_url) and self.pressed:
67 self.emit("show-exhibits-clicked", exhibit)
68 self.pressed = False
69
70
71=== modified file 'test/gtk3/test_catview.py'
72--- test/gtk3/test_catview.py 2012-06-04 16:47:05 +0000
73+++ test/gtk3/test_catview.py 2012-07-02 17:09:21 +0000
74@@ -326,7 +326,35 @@
75 self.assertEqual(1, len(banner.exhibits))
76 self.assertIs(banner.exhibits[0], exhibit)
77
78-
79+ def test_exhibit_with_url(self):
80+ # available exhibit
81+ exhibit = Mock()
82+ exhibit.package_names = ''
83+ exhibit.click_url = 'http://example.com'
84+ exhibit.banner_url = 'banner'
85+ exhibit.title_translated = ''
86+
87+ sca = ObjectWithSignals()
88+ sca.query_exhibits = lambda: sca.emit('exhibits', sca,
89+ [exhibit])
90+
91+ with patch.object(catview_gtk, 'SoftwareCenterAgent', lambda: sca):
92+ # add the banners
93+ self.lobby._append_banner_ads()
94+ # fake click
95+ alloc = self.lobby.exhibit_banner.get_allocation()
96+ mock_event = Mock()
97+ mock_event.x = alloc.x
98+ mock_event.y = alloc.y
99+ with patch.object(self.lobby.exhibit_banner, 'emit') as mock_emit:
100+ self.lobby.exhibit_banner.on_button_press(None, mock_event)
101+ self.lobby.exhibit_banner.on_button_release(None, mock_event)
102+ mock_emit.assert_called()
103+ signal_name = mock_emit.call_args[0][0]
104+ call_exhibit = mock_emit.call_args[0][1]
105+ self.assertEqual(signal_name, "show-exhibits-clicked")
106+ self.assertEqual(call_exhibit.click_url, "http://example.com")
107+
108 if __name__ == "__main__":
109 #import logging
110 #logging.basicConfig(level=logging.DEBUG)

Subscribers

People subscribed via source and target branches