Squashed merge of many commits, including (but not limited to) :
[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     public bool remember {
46         get { return remember_checkbutton.get_active(); }
47     }
48
49     public AddPasswordDialog(IdCard id_card, IdentityRequest? request)
50     {
51         this.set_title(_("Moonshot - Password"));
52         this.set_modal(true);
53         set_bg_color(this);
54
55         this.add_buttons(_("Cancel"), ResponseType.CANCEL,
56                          _("Connect"), ResponseType.OK);
57
58         this.set_default_response(ResponseType.OK);
59
60         var content_area = this.get_content_area();
61         ((Box) content_area).set_spacing(12);
62         set_bg_color(content_area);
63
64         Label dialog_label = new Label(_("Enter the password for ") + id_card.display_name);
65         dialog_label.set_alignment(0, 0);
66
67         var nai_label = new Label(_("User (NAI):"));
68         nai_label.set_alignment(0, 1);
69         var nai_value = new Label(id_card.nai);
70         nai_value.set_alignment(0, 0);
71
72         var password_label = new Label(_("Password:"));
73         password_label.set_alignment(0, (float) 1);
74         this.password_entry = new Entry();
75         password_entry.set_invisible_char('*');
76         password_entry.set_visibility(false);
77         password_entry.activates_default = true;
78         remember_checkbutton = new CheckButton.with_label(_("Remember password"));
79
80         set_atk_relation(password_label, password_entry, Atk.RelationType.LABEL_FOR);
81
82         var table = new Table(6, 1, false);
83         AttachOptions opts = AttachOptions.EXPAND | AttachOptions.FILL;
84         int row = 0;
85         table.set_col_spacings(6);
86         table.set_row_spacings(0);
87         table.attach(dialog_label, 0, 1, row, row + 1, opts, opts, 0, 2);
88 //            table.attach_defaults(service_value, 1, 2, row, row + 1);
89         row++;
90
91         VBox nai_vbox = new VBox(false, 0);
92         nai_vbox.pack_start(nai_label, false, false, 0);
93         nai_vbox.pack_start(nai_value, false, false, 0);
94         table.attach(nai_vbox, 0, 1, row, row + 1, opts, opts, 0, 12);
95         row++;
96
97         VBox password_vbox = new VBox(false, 1);
98         var empty_box2 = new VBox(false, 0);
99         empty_box2.set_size_request(0, 0);
100         password_vbox.pack_start(empty_box2, false, false, 3);
101         password_vbox.pack_start(password_label, false, false, 0);
102         password_vbox.pack_start(password_entry, false, false, 0);
103         table.attach(password_vbox, 0, 1, row, row + 1, opts, opts, 0, 0);
104         row++;
105
106         table.attach(remember_checkbutton,  0, 1, row, row + 1, opts, opts, 20, 2);
107         row++;
108
109         var empty_box3 = new VBox(false, 0);
110         empty_box3.set_size_request(0, 0);
111         table.attach(empty_box3,  0, 1, row, row + 1, opts, opts, 0, 10);
112         row++;
113
114         var vbox = new VBox(false, 0);
115         vbox.set_border_width(6);
116         vbox.pack_start(table, false, false, 0);
117
118         ((Container) content_area).add(vbox);
119
120         this.set_border_width(6);
121         //this.set_resizable(false);
122         this.show_all();
123     }
124 }