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 static MoonshotLogger logger = get_logger("IdCardWidget");
38 public IdCard id_card { get; set; default = null; }
40 private VBox main_vbox;
42 public Button delete_button { get; private set; default = null; }
43 public Button details_button { get; private set; default = null; }
44 public Button send_button { get; private set; default = null; }
45 // private HButtonBox hbutton_box;
46 private EventBox event_box;
47 private bool is_selected = false;
51 public signal void expanded();
52 public signal void remove_id();
53 public signal void details_id();
54 public signal void send_id();
56 public void collapse()
58 // this.hbutton_box.set_visible(false);
60 update_id_card_label();
67 // this.hbutton_box.set_visible(true);
69 update_id_card_label();
75 private bool button_press_cb()
85 private void delete_button_cb()
90 private void details_button_cb()
95 private void send_button_cb()
100 private void set_idcard_color()
102 var color = Gdk.Color();
113 color.red = 0xd9 << 8;
114 color.green = 0xf7 << 8;
117 var state = this.get_state();
118 this.event_box.modify_bg(state, color);
122 update_id_card_label()
124 // !!TODO: Use a table to format the labels and values
125 string services_text = "Services: ";
126 string service_spacer = " ";
128 var label_text = Markup.printf_escaped("<big>%s</big>", this.id_card.display_name);
132 label_text += "\nUsername: " + id_card.username;
133 label_text += "\nRealm: " + id_card.issuer;
136 for (int i = 0; i < id_card.services.length; i++)
138 services_text += sep;
139 services_text += id_card.services[i];
141 sep = "\n" + service_spacer;
143 label_text += "\n" + services_text;
146 label.set_markup(label_text);
149 public IdCardWidget(IdCard id_card)
151 this.id_card = id_card;
153 var image = new Image.from_pixbuf(get_pixbuf(id_card));
155 label = new Label(null);
156 label.set_alignment((float) 0, (float) 0.5);
157 label.set_ellipsize(Pango.EllipsizeMode.END);
158 update_id_card_label();
160 table = new Gtk.HBox(false, 6);
161 table.pack_start(image, false, false, 0);
162 table.pack_start(label, true, true, 0);
164 this.delete_button = new Button.with_label(_("Delete"));
165 this.details_button = new Button.with_label(_("View details"));
166 this.send_button = new Button.with_label(_("Send"));
167 set_atk_name_description(delete_button, _("Delete"), _("Delete this ID Card"));
168 set_atk_name_description(details_button, _("Details"), _("View the details of this ID Card"));
169 set_atk_name_description(send_button, _("Send"), _("Send this ID Card"));
170 // this.hbutton_box = new HButtonBox();
171 // hbutton_box.pack_end(delete_button);
172 // hbutton_box.pack_end(details_button);
173 // hbutton_box.pack_end(send_button);
174 send_button.set_sensitive(false);
176 delete_button.clicked.connect(delete_button_cb);
177 details_button.clicked.connect(details_button_cb);
178 send_button.clicked.connect(send_button_cb);
180 this.main_vbox = new VBox(false, 12);
181 main_vbox.pack_start(table, true, true, 0);
182 // main_vbox.pack_start(hbutton_box, false, false, 0);
183 main_vbox.set_border_width(12);
185 event_box = new EventBox();
186 event_box.add(main_vbox);
187 event_box.button_press_event.connect(button_press_cb);
188 this.pack_start(event_box, true, true);
191 // this.hbutton_box.hide();
196 private void set_atk_name_description(Widget widget, string name, string description)
198 var atk_widget = widget.get_accessible();
200 atk_widget.set_name(name);
201 atk_widget.set_description(description);