~saurabhanandiit/gtg/exportFixed

« back to all changes in this revision

Viewing changes to GTG/gtk/backends_dialog/parameters_ui/passwordui.py

Merge of my work on liblarch newbase and all the backends ported to liblarch
(which mainly means porting the datastore).
One failing test, will check it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
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, either version 3 of the License, or (at your option) any later
 
9
# version.
 
10
#
 
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
 
14
# details.
 
15
#
 
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
# -----------------------------------------------------------------------------
 
19
 
 
20
import gtk
 
21
 
 
22
from GTG import _
 
23
 
 
24
 
 
25
 
 
26
class PasswordUI(gtk.HBox):
 
27
    '''Widget displaying a gtk.Label and a textbox to input a password'''
 
28
    
 
29
 
 
30
    def __init__(self, req, backend, width):
 
31
        '''Creates the gtk widgets and loads the current password in the text
 
32
        field
 
33
 
 
34
        @param req: a Requester
 
35
        @param backend: a backend object
 
36
        @param width: the width of the gtk.Label object
 
37
        '''
 
38
        super(PasswordUI, self).__init__()
 
39
        self.backend = backend
 
40
        self.req = req
 
41
        self._populate_gtk(width)
 
42
        self._load_password()
 
43
        self._connect_signals()
 
44
 
 
45
    def _populate_gtk(self, width):
 
46
        '''Creates the text box and the related label
 
47
        
 
48
        @param width: the width of the gtk.Label object
 
49
        '''
 
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)
 
59
 
 
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)
 
66
 
 
67
    def _connect_signals(self):
 
68
        '''Connects the gtk signals'''
 
69
        self.password_textbox.connect('changed', self.on_password_modified)
 
70
 
 
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())
 
74
 
 
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
 
78
        (s)he made.
 
79
 
 
80
        @param sender: not used, only here for signal compatibility
 
81
        '''
 
82
        if self.backend.is_enabled() and not self.backend.is_default():
 
83
            self.req.set_backend_enabled(self.backend.get_id(), False)
 
84