Cleaning up compilation warnings
[moonshot-ui.git] / src / moonshot-trust-anchor-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 TrustAnchorDialog : Dialog
35 {
36     private static Gdk.Color white = make_color(65535, 65535, 65535);
37
38     public bool complete = false;
39
40     public TrustAnchorDialog(IdCard idcard, Window parent)
41     {
42         this.set_title(_("Trust Anchor"));
43         this.set_modal(true);
44         this.set_transient_for(parent);
45         this.modify_bg(StateType.NORMAL, white);
46
47         this.add_buttons(_("Confirm"), ResponseType.OK,
48                          _("Cancel"), ResponseType.CANCEL);
49
50         this.set_default_response(ResponseType.OK);
51
52         var content_area = this.get_content_area();
53         ((Box) content_area).set_spacing(12);
54         content_area.modify_bg(StateType.NORMAL, white);
55
56         Label dialog_label = new Label("");
57         dialog_label.set_alignment(0, 0);
58
59         string label_markup = _("<span font-weight='heavy'>You are using this identity for the first time with the following trust anchor:</span>");
60
61         dialog_label.set_markup(label_markup);
62         dialog_label.set_line_wrap(true);
63         dialog_label.set_width_chars(60);
64                                                    
65         var user_label = new Label(_("Username: ") + idcard.username);
66         user_label.set_alignment(0, 0.5f);
67
68         var realm_label = new Label(_("Realm: ") + idcard.issuer);
69         realm_label.set_alignment(0, 0.5f);
70
71         Label confirm_label = new Label(_("Please confirm that this is the correct trust anchor."));
72         confirm_label.set_alignment(0, 0.5f);
73
74         var trust_anchor_display = make_ta_fingerprint_widget(idcard.trust_anchor);
75
76         var vbox = new VBox(false, 0);
77         vbox.set_border_width(6);
78         vbox.pack_start(dialog_label, true, true, 12);
79         vbox.pack_start(user_label, true, true, 2);
80         vbox.pack_start(realm_label, true, true, 2);
81         vbox.pack_start(trust_anchor_display, true, true, 0);
82         vbox.pack_start(confirm_label, true, true, 12);
83
84         ((Container) content_area).add(vbox);
85
86         this.set_border_width(6);
87         this.set_resizable(false);
88
89         this.response.connect(on_response);
90
91         this.show_all();
92     }
93
94     private void on_response(Dialog source, int response_id)
95     {
96         switch (response_id) {
97         case ResponseType.OK:
98             complete = true;
99             break;
100         case ResponseType.CANCEL:
101             complete = true;
102             break;
103         }
104     }
105 }