Only use the new Stock syntax if we have vala >= 0.12
[moonshot-ui.git] / src / moonshot-add-dialog.vala
1 using Gtk;
2
3 class AddIdentityDialog : Dialog
4 {
5     private Entry issuer_entry;
6     private Entry username_entry;
7     private Entry password_entry;
8
9     public string issuer {
10         get { return issuer_entry.get_text (); }
11     }
12
13      public string username {
14         get { return username_entry.get_text (); }
15     }
16
17     public string password {
18         get { return password_entry.get_text (); }
19     }
20
21     public AddIdentityDialog ()
22     {
23         this.set_title (_("Add ID Card"));
24         this.set_modal (true);
25
26         this.add_buttons (_("Add ID Card"), ResponseType.OK,
27 #if VALA_0_12
28                           Stock.CANCEL, ResponseType.CANCEL);
29 #else
30                           STOCK_CANCEL, ResponseType.CANCEL);
31 #endif
32
33         var content_area = this.get_content_area ();
34         ((Box) content_area).set_spacing (12);
35
36         var issuer_label = new Label (_("Issuer:"));
37         issuer_label.set_alignment (1, (float) 0.5);
38         this.issuer_entry = new Entry ();
39         var username_label = new Label (_("Username:"));
40         username_label.set_alignment (1, (float) 0.5);
41         this.username_entry = new Entry ();
42         var password_label = new Label (_("Password:"));
43         password_label.set_alignment (1, (float) 0.5);
44         this.password_entry = new Entry ();
45         password_entry.set_invisible_char ('*');
46         password_entry.set_visibility (false);
47         var remember_checkbutton = new CheckButton.with_label (_("Remember password"));
48
49         set_atk_relation (issuer_label, issuer_entry, Atk.RelationType.LABEL_FOR);
50         set_atk_relation (username_label, username_entry, Atk.RelationType.LABEL_FOR);
51         set_atk_relation (password_entry, password_entry, Atk.RelationType.LABEL_FOR);
52
53         var table = new Table (4, 4, false);
54         table.set_col_spacings (10);
55         table.set_row_spacings (10);
56         table.attach_defaults (issuer_label, 0, 1, 0, 1);
57         table.attach_defaults (issuer_entry, 1, 2, 0, 1);
58         table.attach_defaults (username_label, 0, 1, 1, 2);
59         table.attach_defaults (username_entry, 1, 2, 1, 2);
60         table.attach_defaults (password_label, 0, 1, 2, 3);
61         table.attach_defaults (password_entry, 1, 2, 2, 3);
62         table.attach_defaults (remember_checkbutton,  1, 2, 3, 4);
63
64         var vbox = new VBox (false, 0);
65         vbox.set_border_width (6);
66         vbox.pack_start (table, false, false, 0);
67
68         ((Container) content_area).add (vbox);
69
70         this.set_border_width (6);
71         this.set_resizable (false);
72         this.show_all ();
73     }
74
75     private void set_atk_relation (Widget widget, Widget target_widget, Atk.RelationType relationship)
76     {
77         var atk_widget = widget.get_accessible ();
78         var atk_target_widget = target_widget.get_accessible ();
79
80         atk_widget.add_relationship (relationship, atk_target_widget);
81     }
82 }