25
25
from softwarecenter.ui.gtk3.em import StockEms
26
26
from softwarecenter.ui.gtk3.widgets.containers import (FramedHeaderBox,
28
from softwarecenter.ui.gtk3.utils import get_parent_xid
28
29
from softwarecenter.db.categories import (RecommendedForYouCategory,
29
30
AppRecommendationsCategory)
30
31
from softwarecenter.backend.recagent import RecommenderAgent
32
from softwarecenter.backend.login_sso import get_sso_backend
33
from softwarecenter.backend.ubuntusso import get_ubuntu_sso_backend
34
from softwarecenter.enums import SOFTWARE_CENTER_NAME_KEYRING
31
35
from softwarecenter.utils import utf8
36
from softwarecenter.netstatus import network_state_is_connected
33
38
LOG = logging.getLogger(__name__)
186
191
self.opt_in_to_recommendations_service()
188
193
def opt_in_to_recommendations_service(self):
194
# first we verify the ubuntu sso login/oath status, and if that is good
189
195
# we upload the user profile here, and only after this is finished
190
196
# do we fire the request for recommendations and finally display
191
197
# them here -- a spinner is shown for this process (the spec
192
198
# wants a progress bar, but we don't have access to real-time
194
self._upload_user_profile_and_get_recommendations()
200
self._try_sso_login()
196
202
def opt_out_of_recommendations_service(self):
197
203
# tell the backend that the user has opted out
205
211
self.emit("recommendations-opt-out")
206
212
self._disconnect_recommender_listeners()
214
def _try_sso_login(self):
215
# display the SSO login dialog if needed
216
# FIXME: consider improving the text in the SSO dialog, for now
217
# we simply reuse the opt-in text from the panel since we
218
# are well past string freeze
219
self.spinner_notebook.show_spinner()
220
self.sso = get_sso_backend(get_parent_xid(self),
221
SOFTWARE_CENTER_NAME_KEYRING,
222
self.RECOMMENDATIONS_OPT_IN_TEXT)
223
self.sso.connect("login-successful", self._maybe_login_successful)
224
self.sso.connect("login-failed", self._login_failed)
225
self.sso.connect("login-canceled", self._login_canceled)
226
self.sso.login_or_register()
228
def _maybe_login_successful(self, sso, oauth_result):
229
self.ssoapi = get_ubuntu_sso_backend()
230
self.ssoapi.connect("whoami", self._whoami_done)
231
self.ssoapi.connect("error", self._whoami_error)
232
# this will automatically verify the keyring token and retrigger
233
# login (once) if its expired
236
def _whoami_done(self, ssologin, result):
237
# we are all squared up with SSO login, now we can proceed with the
238
# recommendations display, or the profile upload if this is an
240
if self.recommender_agent.is_opted_in():
241
self._update_recommended_for_you_content()
243
self._upload_user_profile_and_get_recommendations()
245
def _whoami_error(self, ssologin, e):
246
self.spinner_notebook.hide_spinner()
247
# FIXME: there is a race condition here if the network state changed
248
# between the call and this check, to fix this properly the
249
# spawn_helper/piston-generic-helper will need to return
250
# better error information though
251
if not network_state_is_connected():
252
# if there is an error in the SSO whois, first just check if we
253
# have network access and if we do no, just hide the panel
254
self._hide_recommended_for_you_panel()
256
# an error that is not network related indicates that the user's
257
# token has likely been revoked or invalidated on the server, for
258
# this case we want to reset the user's opt-in status
259
self.opt_out_of_recommendations_service()
261
def _login_failed(self, sso):
262
# if the user cancels out of the SSO dialog, reset everything to the
264
self.spinner_notebook.hide_spinner()
265
self.opt_out_of_recommendations_service()
267
def _login_canceled(self, sso):
268
# if the user cancels out of the SSO dialog, reset everything to the
270
self.spinner_notebook.hide_spinner()
271
self.opt_out_of_recommendations_service()
208
273
def _upload_user_profile_and_get_recommendations(self):
209
274
# initiate upload of the user profile here
210
275
self._upload_user_profile()