~ubuntu-branches/ubuntu/quantal/ubuntuone-control-panel/quantal-proposed

« back to all changes in this revision

Viewing changes to ubuntuone/controlpanel/gui/qt/signin.py

Tags: upstream-2.0.0
ImportĀ upstreamĀ versionĀ 2.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
# Authors: Natalia B Bidart <natalia.bidart@canonical.com>
 
4
#
 
5
# Copyright 2011 Canonical Ltd.
 
6
#
 
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.
 
10
#
 
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.
 
15
#
 
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/>.
 
18
 
 
19
"""The signin page."""
 
20
 
 
21
from PyQt4 import QtCore
 
22
from twisted.internet import defer
 
23
 
 
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
 
29
 
 
30
 
 
31
logger = setup_logging('qt.signin')
 
32
 
 
33
 
 
34
class SignInPanel(UbuntuOneBin):
 
35
    """The widget for signing in."""
 
36
 
 
37
    ui_class = signin_ui
 
38
    logger = logger
 
39
 
 
40
    signinCanceled = QtCore.pyqtSignal()
 
41
    credentialsFound = QtCore.pyqtSignal(dict)
 
42
 
 
43
    def _setup(self):
 
44
        """Do some extra setupping for the UI."""
 
45
        super(SignInPanel, self)._setup()
 
46
 
 
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)
 
50
 
 
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)
 
55
 
 
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)
 
63
 
 
64
    # pylint: disable=E0202
 
65
    @defer.inlineCallbacks
 
66
    def load(self):
 
67
        """Load specific tab info."""
 
68
        yield self.backend.get_credentials()
 
69
 
 
70
    @QtCore.pyqtSlot()
 
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
 
79
        try:
 
80
            result = yield self.backend.login(email=email, password=password)
 
81
            logger.info('Emitting credentialsFound for email %r.', email)
 
82
            self.credentialsFound.emit(result)
 
83
        finally:
 
84
            self.is_processing = False
 
85
 
 
86
    @QtCore.pyqtSlot()
 
87
    def on_cancel_button_clicked(self):
 
88
        """The 'Cancel' button was clicked."""
 
89
        self.signinCanceled.emit()