~juliank/software-center/debian-next

« back to all changes in this revision

Viewing changes to softwarecenter/view/logindialog.py

  • Committer: Julian Andres Klode
  • Date: 2010-08-02 15:20:09 UTC
  • mfrom: (429.62.230 trunk)
  • Revision ID: jak@debian.org-20100802152009-r5s64zd6rb43g7pa
* Merge with Ubuntu's 2.1 series (2.1.7 + bzr), remaining differences:
  - po/cs.po: Updated.
  - softwarecenter/app.py: Remove views menu when not on Ubuntu.
  - setup.py: Support + and - in version numbers.
  - setup.py, setup.cfg: Use unbranded stuff.
  - debian/control:
    - Update Standards-Version
    - Change Vcs-Bzr, Maintainer to Debian.
    - Do not depend on humanity-icon-theme, but gnome-icon-theme.
    - Remove Ubuntu from package description-
  - debian/rules:
    - Drop the old hack for handling non-Ubuntu systems.
    - Run build_i18n in clean.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2010 Canonical
 
2
#
 
3
# Authors:
 
4
#  Michael Vogt
 
5
#
 
6
# This program is free software; you can redistribute it and/or modify it under
 
7
# the terms of the GNU General Public License as published by the Free Software
 
8
# Foundation; version 3.
 
9
#
 
10
# This program is distributed in the hope that it will be useful, but WITHOUT
 
11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
12
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 
13
# details.
 
14
#
 
15
# You should have received a copy of the GNU General Public License along with
 
16
# this program; if not, write to the Free Software Foundation, Inc.,
 
17
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
18
 
 
19
import glib
 
20
import gobject
 
21
gobject.threads_init()
 
22
import gtk
 
23
import logging
 
24
import sys
 
25
 
 
26
 
 
27
from gettext import gettext as _
 
28
import subprocess
 
29
 
 
30
from softwarecenter.backend.launchpad import GLaunchpad
 
31
from softwarecenter.backend.restfulclient import UbuntuSSOlogin
 
32
import softwarecenter
 
33
 
 
34
class LoginDialog(object):
 
35
 
 
36
    def __init__(self, loginbackend, datadir, parent=None):
 
37
        # launchpad
 
38
        self.loginbackend = loginbackend
 
39
        self.loginbackend.connect("need-username-password", 
 
40
                                self.cb_need_username_password)
 
41
        self.loginbackend.connect("login-successful", self.cb_login_successful)
 
42
        self.loginbackend.connect("login-failed", self.cb_login_failure)
 
43
 
 
44
        # setup ui
 
45
        self.builder = gtk.Builder()
 
46
        self.builder.add_from_file(datadir+"/ui/login.ui")
 
47
        self.builder.connect_signals(self)
 
48
        for o in self.builder.get_objects():
 
49
            if issubclass(type(o), gtk.Buildable):
 
50
                name = gtk.Buildable.get_name(o)
 
51
                setattr(self, name, o)
 
52
            else:
 
53
                print >> sys.stderr, "WARNING: can not get name for '%s'" % o
 
54
        # parent
 
55
        if parent:
 
56
            self.dialog_login.set_transient_for(parent)
 
57
        self.parent = parent
 
58
 
 
59
        # create spinner
 
60
        #self.login_spinner = gtk.Spinner()
 
61
        #self.dialog_action_area_login.pack_start(self.login_spinner)
 
62
        #self.dialog_action_area_login.reorder_child(self.login_spinner, 0)
 
63
        #self.login_spinner.start()
 
64
        #self.login_spinner.show()
 
65
 
 
66
    def login(self):
 
67
        self.loginbackend.login()
 
68
 
 
69
    def cb_need_username_password(self, lp):
 
70
        res = self.dialog_login.run()
 
71
        self.dialog_login.hide()
 
72
        if res != gtk.RESPONSE_OK:
 
73
            self.on_button_cancel_clicked()
 
74
            return 
 
75
        self._enter_user_name_password_finished()
 
76
 
 
77
    def cb_login_successful(self, lp, token):
 
78
        """ callback when the login was successful """
 
79
        print "login_successful", token
 
80
 
 
81
    def cb_login_failure(self, lp):
 
82
        """ callback when the login failed """
 
83
        softwarecenter.view.dialogs.error(self.parent,
 
84
                                          _("Authentication failure"),
 
85
                                          _("Sorry, please try again"))
 
86
        self.cb_need_username_password(None)
 
87
 
 
88
    def on_button_cancel_clicked(self, button=None):
 
89
        self.loginbackend.cancel_login()
 
90
        self.dialog_login.hide()
 
91
        while gtk.events_pending():
 
92
            gtk.main_iteration()
 
93
 
 
94
    def _enter_user_name_password_finished(self):
 
95
        """ run when the user finished with the login dialog box
 
96
            this checks the users choices and sets the appropriate state
 
97
        """
 
98
        has_account = self.radiobutton_review_login_have_account.get_active()
 
99
        new_account = self.radiobutton_review_login_register_new_account.get_active()
 
100
        forgotten_pw = self.radiobutton_review_login_forgot_password.get_active()
 
101
        if has_account:
 
102
            username = self.entry_review_login_email.get_text()
 
103
            password = self.entry_review_login_password.get_text()
 
104
            self.loginbackend.login(username, password)
 
105
        elif new_account:
 
106
            #print "new_account"
 
107
            subprocess.call(["xdg-open", self.loginbackend.new_account_url])
 
108
        elif forgotten_pw:
 
109
            #print "forgotten passowrd"
 
110
            subprocess.call(["xdg-open", self.loginbackend.forgot_password_url])
 
111
 
 
112
 
 
113
 
 
114
if __name__ == "__main__":
 
115
 
 
116
    logging.basicConfig(level=logging.DEBUG)
 
117
    # glaunchpad
 
118
    if sys.argv[1] == "launchpad":
 
119
        loginbackend = GLaunchpad()
 
120
    elif sys.argv[1] == "sso":
 
121
        loginbackend = UbuntuSSOlogin()
 
122
    else:
 
123
        print "need either 'sso' or 'launchpad' as arguments"
 
124
    d = LoginDialog(loginbackend, datadir="./data")
 
125
    res = d.login()
 
126
 
 
127
    try:
 
128
        gtk.main()
 
129
    except KeyboardInterrupt:
 
130
        # FIXME: port shutdown?!?
 
131
        #glaunchpad.shutdown() 
 
132
        pass
 
133
 
 
134
 
 
135
 
 
136