1
# -*- coding: utf-8 -*-
3
# Authors: Natalia B Bidart <natalia.bidart@canonical.com>
5
# Copyright 2011 Canonical Ltd.
7
# This program is free software: you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License version 3, as published
9
# by the Free Software Foundation.
11
# This program is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranties of
13
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14
# PURPOSE. See the GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License along
17
# with this program. If not, see <http://www.gnu.org/licenses/>.
19
"""The signin page."""
21
from PyQt4 import QtCore
22
from twisted.internet import defer
24
from ubuntuone.controlpanel.gui import RESET_PASSWORD_LINK
25
from ubuntuone.controlpanel.gui.qt import icon_from_name, handle_errors
26
from ubuntuone.controlpanel.gui.qt.ubuntuonebin import UbuntuOneBin
27
from ubuntuone.controlpanel.gui.qt.ui import signin_ui
28
from ubuntuone.controlpanel.logger import setup_logging, log_call
31
logger = setup_logging('qt.signin')
34
class SignInPanel(UbuntuOneBin):
35
"""The widget for signing in."""
40
signinCanceled = QtCore.pyqtSignal()
41
credentialsFound = QtCore.pyqtSignal(dict)
44
"""Do some extra setupping for the UI."""
45
super(SignInPanel, self)._setup()
47
self.ui.forgot_password_button.uri = RESET_PASSWORD_LINK
48
icon = icon_from_name('external_icon_orange')
49
self.ui.forgot_password_button.setIcon(icon)
51
self.ui.signin_button.setEnabled(False)
52
for entry in (self.ui.email_entry, self.ui.password_entry):
53
entry.textChanged.connect(self.validate)
54
entry.returnPressed.connect(self.ui.signin_button.click)
56
def validate(self, *a, **kw):
57
"""Enable sign in button only if email and password are non empty."""
58
email = unicode(self.ui.email_entry.text())
59
password = unicode(self.ui.password_entry.text())
60
self.ui.signin_button.setEnabled(bool(email and password))
61
self.ui.signin_button.style().unpolish(self.ui.signin_button)
62
self.ui.signin_button.style().polish(self.ui.signin_button)
64
# pylint: disable=E0202
65
@defer.inlineCallbacks
67
"""Load specific tab info."""
68
yield self.backend.get_credentials()
71
@handle_errors(logger=logger)
72
@log_call(logger.debug)
73
@defer.inlineCallbacks
74
def on_signin_button_clicked(self):
75
"""The 'Sign in' button was clicked."""
76
email = unicode(self.ui.email_entry.text())
77
password = unicode(self.ui.password_entry.text())
78
self.is_processing = True
80
result = yield self.backend.login(email=email, password=password)
81
logger.info('Emitting credentialsFound for email %r.', email)
82
self.credentialsFound.emit(result)
84
self.is_processing = False
87
def on_cancel_button_clicked(self):
88
"""The 'Cancel' button was clicked."""
89
self.signinCanceled.emit()