Use a different color when the IdCard is selected
[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     private bool button_press_cb ()
16     {
17         this.hbutton_box.set_visible (!hbutton_box.get_visible ());
18
19         set_idcard_color ();
20
21         return false;
22     }
23
24     private void set_idcard_color ()
25     {
26         var color = Gdk.Color ();
27
28         if (hbutton_box.get_visible () == false)
29         {
30             color.red = 65535;
31             color.green = 65535;
32             color.blue = 65535;
33         }
34         else
35         {
36             color.red = 33333;
37             color.green = 33333;
38             color.blue = 60000;
39         }
40         var state = this.get_state ();
41         this.event_box.modify_bg (state, color);
42     }
43
44     public IdCardWidget ()
45     {
46         Gdk.Pixbuf pixbuf;
47
48         var icon_theme = IconTheme.get_default ();
49         try
50         {
51             pixbuf = icon_theme.load_icon ("avatar-default",
52                                            48,
53                                            IconLookupFlags.FORCE_SIZE);
54         }
55         catch (Error e)
56         {
57             pixbuf = null;
58             stdout.printf("Error: %s\n", e.message);
59         }
60         var image = new Image.from_pixbuf (pixbuf);
61
62         var issuer = Markup.printf_escaped ("<b>%s</b>", "University");
63         var services = Markup.printf_escaped ("<i>%s</i>", "Send Email, Connect to jabber");
64         var text = issuer + "\n" + services;
65
66         var id_data_label = new Label (null);
67         id_data_label.set_markup (text);
68
69         this.table = new Table (1, 2, false);
70         table.attach_defaults (image, 0, 1, 0, 1);
71         table.attach_defaults (id_data_label, 1, 2, 0, 1);
72
73         this.delete_button = new Button.with_label ("Delete");
74         this.details_button = new Button.with_label ("View details");
75         this.send_button = new Button.with_label ("Send");
76         this.hbutton_box = new HButtonBox ();
77         hbutton_box.pack_end (delete_button);
78         hbutton_box.pack_end (details_button);
79         hbutton_box.pack_end (send_button);
80
81         this.main_vbox = new VBox (false, 12);
82         main_vbox.pack_start (table, true, true, 0);
83         main_vbox.pack_start (hbutton_box, false, false, 0);
84         main_vbox.set_border_width (12);
85
86         event_box = new EventBox ();
87         event_box.add (main_vbox);
88         event_box.button_press_event.connect (button_press_cb);
89         this.pack_start (event_box, true, true);
90
91         this.show_all ();
92         this.hbutton_box.hide ();
93
94         set_idcard_color ();
95     }
96 }