Change the format of the .gss_eap_id
[moonshot-ui.git] / src / moonshot-idcard-widget.vala
1 using Gtk;
2
3 class IdCardWidget : Box
4 {
5     public IdCard id_card { get; set; default = null; }
6
7     private VBox main_vbox;
8     private Table table;
9     public Button delete_button { get; private set; default = null; }
10     public Button details_button { get; private set; default = null; }
11     public Button send_button { get; private set; default = null; }
12     private HButtonBox hbutton_box;
13     private EventBox event_box;
14
15     public signal void expanded ();
16     public signal void remove_id ();
17     public signal void details_id ();
18
19     public void collapse ()
20     {
21         this.hbutton_box.set_visible (false);
22
23         set_idcard_color ();
24     }
25
26     private bool button_press_cb ()
27     {
28         this.hbutton_box.set_visible (!hbutton_box.get_visible ());
29
30         set_idcard_color ();
31
32         if (hbutton_box.get_visible () == true)
33           this.expanded ();
34
35         return false;
36     }
37
38     private void delete_button_cb ()
39     {
40        this.remove_id ();
41     }
42
43     private void details_button_cb ()
44     {
45        this.details_id ();
46     }
47
48     private void set_idcard_color ()
49     {
50         var color = Gdk.Color ();
51
52         if (hbutton_box.get_visible () == false)
53         {
54             color.red = 65535;
55             color.green = 65535;
56             color.blue = 65535;
57         }
58         else
59         {
60             color.red = 33333;
61             color.green = 33333;
62             color.blue = 60000;
63         }
64         var state = this.get_state ();
65         this.event_box.modify_bg (state, color);
66     }
67
68     public IdCardWidget (IdCard id_card)
69     {
70         string services_text = "";
71         this.id_card = id_card;
72
73         var image = new Image.from_pixbuf (id_card.pixbuf);
74
75         var issuer = Markup.printf_escaped ("<b>%s</b>", this.id_card.issuer);
76         foreach (string service in id_card.services)
77         {
78             services_text = services_text + Markup.printf_escaped ("<i>%s, </i>", service);
79         }
80         var text = issuer + "\n" + services_text;
81
82         var id_data_label = new Label (null);
83         id_data_label.set_markup (text);
84         id_data_label.set_alignment ((float) 0, (float) 0.5);
85
86         this.table = new Table (1, 2, false);
87         table.attach_defaults (image, 0, 1, 0, 1);
88         table.attach_defaults (id_data_label, 1, 2, 0, 1);
89
90         this.delete_button = new Button.with_label ("Delete");
91         this.details_button = new Button.with_label ("View details");
92         this.send_button = new Button.with_label ("Send");
93         this.hbutton_box = new HButtonBox ();
94         hbutton_box.pack_end (delete_button);
95         hbutton_box.pack_end (details_button);
96         hbutton_box.pack_end (send_button);
97
98         delete_button.clicked.connect (delete_button_cb);
99         details_button.clicked.connect (details_button_cb);
100
101         this.main_vbox = new VBox (false, 12);
102         main_vbox.pack_start (table, true, true, 0);
103         main_vbox.pack_start (hbutton_box, false, false, 0);
104         main_vbox.set_border_width (12);
105
106         event_box = new EventBox ();
107         event_box.add (main_vbox);
108         event_box.button_press_event.connect (button_press_cb);
109         this.pack_start (event_box, true, true);
110
111         this.show_all ();
112         this.hbutton_box.hide ();
113
114         set_idcard_color ();
115     }
116 }