Bump the version number in configure.ac to 1.0.5
[moonshot-ui.git] / src / moonshot-password-dialog.vala
1 /*
2  * Copyright (c) 2011-2016, JANET(UK)
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * 3. Neither the name of JANET(UK) nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31 */
32 using Gtk;
33
34 class AddPasswordDialog : Dialog
35 {
36     private static Gdk.Color white = make_color(65535, 65535, 65535);
37
38     private Entry password_entry;
39     private CheckButton remember_checkbutton;
40
41     public string password {
42         get { return password_entry.get_text(); }
43     }
44
45     /**
46      * Don't leave passwords in memory longer than necessary.
47      * This may not actually erase the password data bytes, but it seems to be the best we can do.
48      */
49     public void clear_password() {
50         clear_password_entry(password_entry);
51     }
52
53     public bool remember {
54         get { return remember_checkbutton.get_active(); }
55     }
56
57     public AddPasswordDialog(IdCard id_card, IdentityRequest? request)
58     {
59         this.set_title(_("Moonshot - Password"));
60         this.set_modal(true);
61         set_bg_color(this);
62
63         this.add_buttons(_("Cancel"), ResponseType.CANCEL,
64                          _("Connect"), ResponseType.OK);
65
66         this.set_default_response(ResponseType.OK);
67
68         var content_area = this.get_content_area();
69         ((Box) content_area).set_spacing(12);
70         set_bg_color(content_area);
71
72         Label dialog_label = new Label(_("Enter the password for ") + id_card.display_name);
73         dialog_label.set_alignment(0, 0);
74
75         var nai_label = new Label(_("User (NAI):"));
76         nai_label.set_alignment(0, 1);
77         var nai_value = new Label(id_card.nai);
78         nai_value.set_alignment(0, 0);
79
80         var password_label = new Label(_("Password:"));
81         password_label.set_alignment(0, (float) 1);
82         this.password_entry = new Entry();
83         password_entry.set_invisible_char('*');
84         password_entry.set_visibility(false);
85         password_entry.activates_default = true;
86         remember_checkbutton = new CheckButton.with_label(_("Remember password"));
87
88         set_atk_relation(password_label, password_entry, Atk.RelationType.LABEL_FOR);
89
90         var table = new Table(6, 1, false);
91         AttachOptions opts = AttachOptions.EXPAND | AttachOptions.FILL;
92         int row = 0;
93         table.set_col_spacings(6);
94         table.set_row_spacings(0);
95         table.attach(dialog_label, 0, 1, row, row + 1, opts, opts, 0, 2);
96 //            table.attach_defaults(service_value, 1, 2, row, row + 1);
97         row++;
98
99         VBox nai_vbox = new VBox(false, 0);
100         nai_vbox.pack_start(nai_label, false, false, 0);
101         nai_vbox.pack_start(nai_value, false, false, 0);
102         table.attach(nai_vbox, 0, 1, row, row + 1, opts, opts, 0, 12);
103         row++;
104
105         VBox password_vbox = new VBox(false, 1);
106         var empty_box2 = new VBox(false, 0);
107         empty_box2.set_size_request(0, 0);
108         password_vbox.pack_start(empty_box2, false, false, 3);
109         password_vbox.pack_start(password_label, false, false, 0);
110         password_vbox.pack_start(password_entry, false, false, 0);
111         table.attach(password_vbox, 0, 1, row, row + 1, opts, opts, 0, 0);
112         row++;
113
114         table.attach(remember_checkbutton,  0, 1, row, row + 1, opts, opts, 20, 2);
115         row++;
116
117         var empty_box3 = new VBox(false, 0);
118         empty_box3.set_size_request(0, 0);
119         table.attach(empty_box3,  0, 1, row, row + 1, opts, opts, 0, 10);
120         row++;
121
122         var vbox = new VBox(false, 0);
123         vbox.set_border_width(6);
124         vbox.pack_start(table, false, false, 0);
125
126         ((Container) content_area).add(vbox);
127
128         this.set_border_width(6);
129         //this.set_resizable(false);
130         this.show_all();
131     }
132 }