1
# -*- coding: utf-8 -*-
2
# -----------------------------------------------------------------------------
3
# Getting Things Gnome! - a personal organizer for the GNOME desktop
4
# Copyright (c) 2008-2009 - Lionel Dricot & Bertrand Rousseau
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, either version 3 of the License, or (at your option) any later
11
# This program is distributed in the hope that it will be useful, but WITHOUT
12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16
# You should have received a copy of the GNU General Public License along with
17
# this program. If not, see <http://www.gnu.org/licenses/>.
18
# -----------------------------------------------------------------------------
26
class PasswordUI(gtk.HBox):
27
'''Widget displaying a gtk.Label and a textbox to input a password'''
30
def __init__(self, req, backend, width):
31
'''Creates the gtk widgets and loads the current password in the text
34
@param req: a Requester
35
@param backend: a backend object
36
@param width: the width of the gtk.Label object
38
super(PasswordUI, self).__init__()
39
self.backend = backend
41
self._populate_gtk(width)
43
self._connect_signals()
45
def _populate_gtk(self, width):
46
'''Creates the text box and the related label
48
@param width: the width of the gtk.Label object
50
password_label = gtk.Label(_("Password:"))
51
password_label.set_alignment(xalign = 0, yalign = 0.5)
52
password_label.set_size_request(width = width, height = -1)
53
self.pack_start(password_label, False)
54
align = gtk.Alignment(xalign = 0, yalign = 0.5, xscale = 1)
55
align.set_padding(0, 0, 10, 0)
56
self.pack_start(align, True)
57
self.password_textbox = gtk.Entry()
58
align.add(self.password_textbox)
60
def _load_password(self):
61
'''Loads the password from the backend'''
62
password = self.backend.get_parameters()['password']
63
self.password_textbox.set_invisible_char('*')
64
self.password_textbox.set_visibility(False)
65
self.password_textbox.set_text(password)
67
def _connect_signals(self):
68
'''Connects the gtk signals'''
69
self.password_textbox.connect('changed', self.on_password_modified)
71
def commit_changes(self):
72
'''Saves the changes to the backend parameter ('password')'''
73
self.backend.set_parameter('password', self.password_textbox.get_text())
75
def on_password_modified(self, sender):
76
''' Signal callback, executed when the user edits the password.
77
Disables the backend. The user will re-enable it to confirm the changes
80
@param sender: not used, only here for signal compatibility
82
if self.backend.is_enabled() and not self.backend.is_default():
83
self.req.set_backend_enabled(self.backend.get_id(), False)