Use GKeyFile backend
[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 display_name = Markup.printf_escaped ("<b>%s</b>", this.id_card.display_name);
82         
83         for (int i=0; i<id_card.services.length; i++)
84         {
85             var service = id_card.services[i];
86             
87             if (i == (id_card.services.length - 1))
88               services_text = services_text + Markup.printf_escaped ("<i>%s</i>", service);
89             else
90               services_text = services_text + Markup.printf_escaped ("<i>%s, </i>", service);
91         }
92         var text = display_name + "\n" + services_text;
93
94         var id_data_label = new Label (null);
95         id_data_label.set_markup (text);
96         id_data_label.set_alignment ((float) 0, (float) 0.5);
97
98         this.table = new Table (1, 2, false);
99         table.attach_defaults (image, 0, 1, 0, 1);
100         table.attach_defaults (id_data_label, 1, 2, 0, 1);
101
102         this.delete_button = new Button.with_label (_("Delete"));
103         this.details_button = new Button.with_label (_("View details"));
104         this.send_button = new Button.with_label (_("Send"));
105         set_atk_name_description (delete_button, _("Delete"), _("Delete this ID Card"));
106         set_atk_name_description (details_button, _("Details"), _("View the details of this ID Card"));
107         set_atk_name_description (send_button, _("Send"), _("Send this ID Card"));
108         this.hbutton_box = new HButtonBox ();
109         hbutton_box.pack_end (delete_button);
110         hbutton_box.pack_end (details_button);
111         hbutton_box.pack_end (send_button);
112
113         delete_button.clicked.connect (delete_button_cb);
114         details_button.clicked.connect (details_button_cb);
115         send_button.clicked.connect (send_button_cb);
116
117         this.main_vbox = new VBox (false, 12);
118         main_vbox.pack_start (table, true, true, 0);
119         main_vbox.pack_start (hbutton_box, false, false, 0);
120         main_vbox.set_border_width (12);
121
122         event_box = new EventBox ();
123         event_box.add (main_vbox);
124         event_box.button_press_event.connect (button_press_cb);
125         this.pack_start (event_box, true, true);
126
127         this.show_all ();
128         this.hbutton_box.hide ();
129
130         set_idcard_color ();
131     }
132
133     private void set_atk_name_description (Widget widget, string name, string description)
134     {
135        var atk_widget = widget.get_accessible ();
136
137        atk_widget.set_name (name);
138        atk_widget.set_description (description);
139     }
140 }