[webp] Trust anchor information in.
[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     public signal void send_id ();
19
20     public void collapse ()
21     {
22         this.hbutton_box.set_visible (false);
23
24         set_idcard_color ();
25     }
26
27     private bool button_press_cb ()
28     {
29         this.hbutton_box.set_visible (!hbutton_box.get_visible ());
30
31         set_idcard_color ();
32
33         if (hbutton_box.get_visible () == true)
34           this.expanded ();
35
36         return false;
37     }
38
39     private void delete_button_cb ()
40     {
41        this.remove_id ();
42     }
43
44     private void details_button_cb ()
45     {
46        this.details_id ();
47     }
48
49     private void send_button_cb ()
50     {
51        this.send_id ();
52     }
53
54     private void set_idcard_color ()
55     {
56         var color = Gdk.Color ();
57
58         if (hbutton_box.get_visible () == false)
59         {
60             color.red = 65535;
61             color.green = 65535;
62             color.blue = 65535;
63         }
64         else
65         {
66             color.red = 33333;
67             color.green = 33333;
68             color.blue = 60000;
69         }
70         var state = this.get_state ();
71         this.event_box.modify_bg (state, color);
72     }
73
74     public IdCardWidget (IdCard id_card)
75     {
76         string services_text = "";
77         this.id_card = id_card;
78
79         var image = new Image.from_pixbuf (id_card.pixbuf);
80
81         var issuer = Markup.printf_escaped ("<b>%s</b>", this.id_card.issuer);
82         foreach (string service in id_card.services)
83         {
84             services_text = services_text + Markup.printf_escaped ("<i>%s, </i>", service);
85         }
86         var text = issuer + "\n" + services_text;
87
88         var id_data_label = new Label (null);
89         id_data_label.set_markup (text);
90         id_data_label.set_alignment ((float) 0, (float) 0.5);
91
92         this.table = new Table (1, 2, false);
93         table.attach_defaults (image, 0, 1, 0, 1);
94         table.attach_defaults (id_data_label, 1, 2, 0, 1);
95
96         this.delete_button = new Button.with_label (_("Delete"));
97         this.details_button = new Button.with_label (_("View details"));
98         this.send_button = new Button.with_label (_("Send"));
99         set_atk_name_description (delete_button, _("Delete"), _("Delete this ID Card"));
100         set_atk_name_description (details_button, _("Details"), _("View the details of this ID Card"));
101         set_atk_name_description (send_button, _("Send"), _("Send this ID Card"));
102         this.hbutton_box = new HButtonBox ();
103         hbutton_box.pack_end (delete_button);
104         hbutton_box.pack_end (details_button);
105         hbutton_box.pack_end (send_button);
106
107         delete_button.clicked.connect (delete_button_cb);
108         details_button.clicked.connect (details_button_cb);
109         send_button.clicked.connect (send_button_cb);
110
111         this.main_vbox = new VBox (false, 12);
112         main_vbox.pack_start (table, true, true, 0);
113         main_vbox.pack_start (hbutton_box, false, false, 0);
114         main_vbox.set_border_width (12);
115
116         event_box = new EventBox ();
117         event_box.add (main_vbox);
118         event_box.button_press_event.connect (button_press_cb);
119         this.pack_start (event_box, true, true);
120
121         this.show_all ();
122         this.hbutton_box.hide ();
123
124         set_idcard_color ();
125     }
126
127     private void set_atk_name_description (Widget widget, string name, string description)
128     {
129        var atk_widget = widget.get_accessible ();
130
131        atk_widget.set_name (name);
132        atk_widget.set_description (description);
133     }
134 }