Merge lp:~mvo/software-center/auto-fill-email-5.2 into lp:software-center/5.2

Proposed by Michael Vogt
Status: Merged
Merged at revision: 3076
Proposed branch: lp:~mvo/software-center/auto-fill-email-5.2
Merge into: lp:software-center/5.2
Diff against target: 146 lines (+59/-3)
5 files modified
softwarecenter/backend/ubuntusso.py (+5/-0)
softwarecenter/config.py (+0/-1)
softwarecenter/ui/gtk3/views/purchaseview.py (+5/-0)
softwarecenter/ui/gtk3/views/webkit.py (+28/-0)
test/gtk3/test_webkit.py (+21/-2)
To merge this branch: bzr merge lp:~mvo/software-center/auto-fill-email-5.2
Reviewer Review Type Date Requested Status
Gary Lasker (community) Approve
Review via email: mp+122856@code.launchpad.net

Description of the change

Backport of the auto-fill-email branch from quantal for 5.2

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

Michael, awesome that you backported this. I think it's a really nice usability improvement and folks will appreciate it!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'softwarecenter/backend/ubuntusso.py'
2--- softwarecenter/backend/ubuntusso.py 2012-04-24 14:16:06 +0000
3+++ softwarecenter/backend/ubuntusso.py 2012-09-05 12:15:24 +0000
4@@ -30,6 +30,7 @@
5 # mostly for testing
6 from fake_review_settings import FakeReviewSettings, network_delay
7 from spawn_helper import SpawnHelper
8+from softwarecenter.config import get_config
9
10 LOG = logging.getLogger(__name__)
11
12@@ -52,6 +53,10 @@
13 GObject.GObject.__init__(self)
14
15 def _on_whoami_data(self, spawner, piston_whoami):
16+ # once we have data, make sure to save it
17+ config = get_config()
18+ config.set("general", "email", piston_whoami["preferred_email"])
19+ # emit
20 self.emit("whoami", piston_whoami)
21
22 def whoami(self):
23
24=== modified file 'softwarecenter/config.py'
25--- softwarecenter/config.py 2012-05-15 07:51:29 +0000
26+++ softwarecenter/config.py 2012-09-05 12:15:24 +0000
27@@ -67,7 +67,6 @@
28 self.configfile, e)
29 pass
30
31-
32 _software_center_config = None
33
34
35
36=== modified file 'softwarecenter/ui/gtk3/views/purchaseview.py'
37--- softwarecenter/ui/gtk3/views/purchaseview.py 2012-04-02 18:23:20 +0000
38+++ softwarecenter/ui/gtk3/views/purchaseview.py 2012-09-05 12:15:24 +0000
39@@ -112,6 +112,11 @@
40 def init_view(self):
41 if self.wk is None:
42 self.wk = ScrolledWebkitWindow()
43+ # automatically fill in the email in the login page
44+ email = ""
45+ if self.config.has_option("general", "email"):
46+ email = self.config.get("general", "email")
47+ self.wk.webkit.set_auto_insert_email(email)
48 #self.wk.webkit.connect("new-window-policy-decision-requested",
49 # self._on_new_window)
50 self.wk.webkit.connect("create-web-view", self._on_create_web_view)
51
52=== modified file 'softwarecenter/ui/gtk3/views/webkit.py'
53--- softwarecenter/ui/gtk3/views/webkit.py 2012-08-28 14:26:41 +0000
54+++ softwarecenter/ui/gtk3/views/webkit.py 2012-09-05 12:15:24 +0000
55@@ -54,16 +54,30 @@
56 - send Accept-Language headers from the users language
57 - disable plugings
58 - send a custom user-agent string
59+ - auto-fill in id_email in login.ubuntu.com
60 """
61
62+ # javascript to auto fill email login on login.ubuntu.com
63+ AUTO_FILL_SERVER = "https://login.ubuntu.com"
64+ AUTO_FILL_EMAIL_JS = """
65+document.getElementById("id_email").value="%s";
66+document.getElementById("id_password").focus();
67+"""
68+
69 def __init__(self):
70 # actual webkit init
71 webkit.WebView.__init__(self)
72 self.connect("resource-request-starting",
73 self._on_resource_request_starting)
74+ self.connect("notify::load-status",
75+ self._on_load_status_changed)
76 settings = self.get_settings()
77 settings.set_property("enable-plugins", False)
78 settings.set_property("user-agent", self._get_user_agent_string())
79+ self._auto_fill_email = ""
80+
81+ def set_auto_insert_email(self, email):
82+ self._auto_fill_email = email
83
84 def _get_user_agent_string(self):
85 settings = self.get_settings()
86@@ -83,6 +97,20 @@
87 # print name, value
88 #headers.foreach(_show_header, None)
89
90+ def _maybe_auto_fill_in_username(self):
91+ uri = self.get_uri()
92+ if self._auto_fill_email and uri.startswith(self.AUTO_FILL_SERVER):
93+ self.execute_script(
94+ self.AUTO_FILL_EMAIL_JS % self._auto_fill_email)
95+ # ensure that we have the keyboard focus
96+ self.grab_focus()
97+
98+ def _on_load_status_changed(self, view, pspec):
99+ prop = pspec.name
100+ status = view.get_property(prop)
101+ if status == webkit.LoadStatus.FINISHED:
102+ self._maybe_auto_fill_in_username()
103+
104
105 class ScrolledWebkitWindow(Gtk.VBox):
106
107
108=== modified file 'test/gtk3/test_webkit.py'
109--- test/gtk3/test_webkit.py 2012-08-28 14:26:41 +0000
110+++ test/gtk3/test_webkit.py 2012-09-05 12:15:24 +0000
111@@ -1,6 +1,10 @@
112 import unittest
113
114-from gi.repository import Soup, WebKit
115+from gi.repository import (
116+ GObject,
117+ Soup,
118+ WebKit,
119+ )
120
121 from mock import patch
122
123@@ -36,7 +40,22 @@
124 self.assertTrue(
125 canary in settings.get_property("user-agent"))
126
127-
128+ def test_auto_fill_in_email(self):
129+ def _load_status_changed(view, status):
130+ if view.get_property("load-status") == WebKit.LoadStatus.FINISHED:
131+ loop.quit()
132+ loop = GObject.MainLoop(GObject.main_context_default())
133+ webview = SoftwareCenterWebView()
134+ email = "foo@bar"
135+ webview.set_auto_insert_email(email)
136+ with patch.object(webview, "execute_script") as mock_execute_js:
137+ webview.connect("notify::load-status", _load_status_changed)
138+ webview.load_uri("https://login.ubuntu.com")
139+ loop.run()
140+ mock_execute_js.assert_called()
141+ mock_execute_js.assert_called_with(
142+ SoftwareCenterWebView.AUTO_FILL_EMAIL_JS % email)
143+
144
145 if __name__ == "__main__":
146 unittest.main()

Subscribers

People subscribed via source and target branches