a4f3073e8415dac5f50af22025bd56a73838d56d
[moonshot-ui.git] / src / moonshot-idcard-widget.vala
1 using Gtk;
2
3 class IdCardWidget : Box
4 {
5     private VBox main_vbox;
6     private Table table;
7     public Button delete_button { get; private set; default = null; }
8     public Button details_button { get; private set; default = null; }
9     public Button send_button { get; private set; default = null; }
10     private HButtonBox hbutton_box;
11
12     private bool button_press_cb ()
13     {
14         this.hbutton_box.set_visible (!hbutton_box.get_visible ());
15
16         return false;
17     }
18
19     public IdCardWidget ()
20     {
21         Gdk.Pixbuf pixbuf;
22
23         var icon_theme = IconTheme.get_default ();
24         try
25         {
26             pixbuf = icon_theme.load_icon ("avatar-default",
27                                            48,
28                                            IconLookupFlags.FORCE_SIZE);
29         }
30         catch (Error e)
31         {
32             pixbuf = null;
33             stdout.printf("Error: %s\n", e.message);
34         }
35         var image = new Image.from_pixbuf (pixbuf);
36
37         var issuer = Markup.printf_escaped ("<b>%s</b>", "University");
38         var services = Markup.printf_escaped ("<i>%s</i>", "Send Email, Connect to jabber");
39         var text = issuer + "\n" + services;
40
41         var id_data_label = new Label (null);
42         id_data_label.set_markup (text);
43
44         this.table = new Table (1, 2, false);
45         table.attach_defaults (image, 0, 1, 0, 1);
46         table.attach_defaults (id_data_label, 1, 2, 0, 1);
47
48         this.delete_button = new Button.with_label ("Delete");
49         this.details_button = new Button.with_label ("View details");
50         this.send_button = new Button.with_label ("Send");
51         this.hbutton_box = new HButtonBox ();
52         hbutton_box.pack_end (delete_button);
53         hbutton_box.pack_end (details_button);
54         hbutton_box.pack_end (send_button);
55
56         this.main_vbox = new VBox (false, 12);
57         main_vbox.pack_start (table, true, true, 0);
58         main_vbox.pack_start (hbutton_box, false, false, 0);
59         main_vbox.set_border_width (12);
60
61         var event_box = new EventBox ();
62         event_box.add (main_vbox);
63         event_box.button_press_event.connect (button_press_cb);
64         add (event_box);
65
66         this.show_all ();
67         this.hbutton_box.hide ();
68     }
69 }