Minor formatting changes
[moonshot-ui.git] / src / moonshot-password-dialog.vala
1 /*
2  * Copyright (c) 2011-2014, 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 Entry password_entry;
37     private CheckButton remember_checkbutton;
38
39     public string password {
40         get { return password_entry.get_text(); }
41     }
42
43     public bool remember {
44         get { return remember_checkbutton.get_active(); }
45     }
46
47     public AddPasswordDialog(IdCard id_card, IdentityRequest? request)
48     {
49         this.set_title(_("Please enter password for ") + id_card.display_name);
50         this.set_modal(true);
51
52         if (request != null) {
53             this.add_buttons(_("Send"), ResponseType.OK,
54                              _("Return to application"), ResponseType.CANCEL);
55         } else {
56             this.add_buttons(_("Done"), ResponseType.OK,
57                              _("Cancel"), ResponseType.CANCEL);
58         }
59         this.set_default_response(ResponseType.OK);
60
61         var content_area = this.get_content_area();
62         ((Box) content_area).set_spacing(12);
63         Label service_label = null;
64         Label service_value = null;
65         if (request != null) {
66             service_label = new Label(_("for use with:"));
67             service_label.set_alignment(1, (float) 0.5);
68             service_value = new Label(request.service);
69             service_value.set_alignment(0, (float) 0.5);
70         }
71
72         var nai_label = new Label(_("Network Access Identifier:"));
73         nai_label.set_alignment(1, (float) 0.5);
74         var nai_value = new Label(id_card.nai);
75         nai_value.set_alignment(0, (float) 0.5);
76
77         var password_label = new Label(_("Password:"));
78         password_label.set_alignment(1, (float) 0.5);
79         this.password_entry = new Entry();
80         password_entry.set_invisible_char('*');
81         password_entry.set_visibility(false);
82         password_entry.activates_default = true;
83         remember_checkbutton = new CheckButton.with_label(_("Remember password"));
84
85         set_atk_relation(password_entry, password_entry, Atk.RelationType.LABEL_FOR);
86
87         var table = new Table(4, 2, false);
88         int row = 0;
89         table.set_col_spacings(10);
90         table.set_row_spacings(10);
91         if (request != null) {
92             table.attach_defaults(service_label, 0, 1, row, row + 1);
93             table.attach_defaults(service_value, 1, 2, row, row + 1);
94             row++;
95         }
96         table.attach_defaults(nai_label, 0, 1, row, row+1);
97         table.attach_defaults(nai_value, 1, 2, row, row+1);
98         row++;
99         table.attach_defaults(password_label, 0, 1, row, row+1);
100         table.attach_defaults(password_entry, 1, 2, row, row+1);
101         row++;
102         table.attach_defaults(remember_checkbutton,  1, 2, row, row+1);
103
104         var vbox = new VBox(false, 0);
105         vbox.set_border_width(6);
106         vbox.pack_start(table, false, false, 0);
107
108         ((Container) content_area).add(vbox);
109
110         this.set_border_width(6);
111         //this.set_resizable(false);
112         this.show_all();
113     }
114
115     private void set_atk_relation(Widget widget, Widget target_widget, Atk.RelationType relationship)
116     {
117         var atk_widget = widget.get_accessible();
118         var atk_target_widget = target_widget.get_accessible();
119
120         atk_widget.add_relationship(relationship, atk_target_widget);
121     }
122 }