2 * Copyright (c) 2011-2014, JANET(UK)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of JANET(UK) nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 class IdCardWidget : Box
36 public IdCard id_card { get; set; default = null; }
38 private VBox main_vbox;
40 public Button delete_button { get; private set; default = null; }
41 public Button details_button { get; private set; default = null; }
42 public Button send_button { get; private set; default = null; }
43 private HButtonBox hbutton_box;
44 private EventBox event_box;
48 public signal void expanded();
49 public signal void remove_id();
50 public signal void details_id();
51 public signal void send_id();
53 public void collapse()
55 this.hbutton_box.set_visible(false);
62 this.hbutton_box.set_visible(true);
68 private bool button_press_cb()
70 if (hbutton_box.get_visible())
78 private void delete_button_cb()
83 private void details_button_cb()
88 private void send_button_cb()
93 private void set_idcard_color()
95 var color = Gdk.Color();
97 if (hbutton_box.get_visible() == false)
109 var state = this.get_state();
110 this.event_box.modify_bg(state, color);
114 update_id_card_label()
116 string services_text = "";
118 var display_name = Markup.printf_escaped("<big>%s</big>", this.id_card.display_name);
119 for (int i = 0; i < id_card.services.length; i++)
121 var service = id_card.services[i];
123 if (i == (id_card.services.length - 1))
124 services_text = services_text + Markup.printf_escaped("<i>%s</i>", service);
126 services_text = services_text + Markup.printf_escaped("<i>%s, </i>", service);
128 label.set_markup(display_name + "\n" + services_text);
131 public IdCardWidget(IdCard id_card)
133 this.id_card = id_card;
135 var image = new Image.from_pixbuf(get_pixbuf(id_card));
137 label = new Label(null);
138 label.set_alignment((float) 0, (float) 0.5);
139 label.set_ellipsize(Pango.EllipsizeMode.END);
140 update_id_card_label();
142 table = new Gtk.HBox(false, 6);
143 table.pack_start(image, false, false, 0);
144 table.pack_start(label, true, true, 0);
146 this.delete_button = new Button.with_label(_("Delete"));
147 this.details_button = new Button.with_label(_("View details"));
148 this.send_button = new Button.with_label(_("Send"));
149 set_atk_name_description(delete_button, _("Delete"), _("Delete this ID Card"));
150 set_atk_name_description(details_button, _("Details"), _("View the details of this ID Card"));
151 set_atk_name_description(send_button, _("Send"), _("Send this ID Card"));
152 this.hbutton_box = new HButtonBox();
153 hbutton_box.pack_end(delete_button);
154 hbutton_box.pack_end(details_button);
155 hbutton_box.pack_end(send_button);
156 send_button.set_sensitive(false);
158 delete_button.clicked.connect(delete_button_cb);
159 details_button.clicked.connect(details_button_cb);
160 send_button.clicked.connect(send_button_cb);
162 this.main_vbox = new VBox(false, 12);
163 main_vbox.pack_start(table, true, true, 0);
164 main_vbox.pack_start(hbutton_box, false, false, 0);
165 main_vbox.set_border_width(12);
167 event_box = new EventBox();
168 event_box.add(main_vbox);
169 event_box.button_press_event.connect(button_press_cb);
170 this.pack_start(event_box, true, true);
173 this.hbutton_box.hide();
178 private void set_atk_name_description(Widget widget, string name, string description)
180 var atk_widget = widget.get_accessible();
182 atk_widget.set_name(name);
183 atk_widget.set_description(description);