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