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; }
39 private VBox main_vbox;
41 // public Button delete_button { get; private set; default = null; }
42 // public Button details_button { get; private set; default = null; }
43 // public Button send_button { get; private set; default = null; }
44 // private HButtonBox hbutton_box;
45 private EventBox event_box;
46 private bool is_selected = false;
50 internal int _position;
51 internal int position {
52 get {return _position;}
53 set {_position = value; set_idcard_color();}
57 public signal void expanded();
58 public signal void remove_id();
59 public signal void details_id();
60 public signal void send_id();
62 public void collapse()
64 // this.hbutton_box.set_visible(false);
66 update_id_card_label();
73 // this.hbutton_box.set_visible(true);
75 update_id_card_label();
81 private bool button_press_cb()
91 private void delete_button_cb()
96 private void details_button_cb()
101 private void send_button_cb()
106 private void set_idcard_color()
108 var color = Gdk.Color();
112 color.red = 0xd9 << 8;
113 color.green = 0xf7 << 8;
117 if (position % 2 == 0)
119 color.red = color.green = color.blue = 0xf2 << 8;
129 var state = this.get_state();
130 this.event_box.modify_bg(state, color);
134 update_id_card_label()
136 // !!TODO: Use a table to format the labels and values
137 string services_text = "Services: ";
138 string service_spacer = " ";
140 var label_text = Markup.printf_escaped("<big>%s</big>", this.id_card.display_name);
144 label_text += "\nUsername: " + id_card.username;
145 label_text += "\nRealm: " + id_card.issuer;
148 for (int i = 0; i < id_card.services.length; i++)
150 services_text += sep;
151 services_text += id_card.services[i];
153 sep = "\n" + service_spacer;
155 label_text += "\n" + services_text;
158 label.set_markup(label_text);
161 public IdCardWidget(IdCard id_card)
163 this.id_card = id_card;
165 var image = new Image.from_pixbuf(get_pixbuf(id_card));
167 label = new Label(null);
168 label.set_alignment((float) 0, (float) 0.5);
169 label.set_ellipsize(Pango.EllipsizeMode.END);
170 update_id_card_label();
172 table = new Gtk.HBox(false, 6);
173 table.pack_start(image, false, false, 0);
174 table.pack_start(label, true, true, 0);
176 // this.delete_button = new Button.with_label(_("Delete"));
177 // this.details_button = new Button.with_label(_("View details"));
178 // this.send_button = new Button.with_label(_("Send"));
179 // set_atk_name_description(delete_button, _("Delete"), _("Delete this ID Card"));
180 // set_atk_name_description(details_button, _("Details"), _("View the details of this ID Card"));
181 // set_atk_name_description(send_button, _("Send"), _("Send this ID Card"));
182 // this.hbutton_box = new HButtonBox();
183 // hbutton_box.pack_end(delete_button);
184 // hbutton_box.pack_end(details_button);
185 // hbutton_box.pack_end(send_button);
186 // send_button.set_sensitive(false);
188 // delete_button.clicked.connect(delete_button_cb);
189 // details_button.clicked.connect(details_button_cb);
190 // send_button.clicked.connect(send_button_cb);
192 this.main_vbox = new VBox(false, 12);
193 main_vbox.pack_start(table, true, true, 0);
194 // main_vbox.pack_start(hbutton_box, false, false, 0);
195 main_vbox.set_border_width(12);
197 event_box = new EventBox();
198 event_box.add(main_vbox);
199 event_box.button_press_event.connect(button_press_cb);
200 event_box.set_visible(false);
201 this.pack_start(event_box, true, true);
204 // this.hbutton_box.hide();
209 // private void set_atk_name_description(Widget widget, string name, string description)
211 // if (widget == null)
213 // logger.error("set_atk_name_description: widget is null for name=" + name + "; description=" + description);
217 // var atk_widget = widget.get_accessible();
219 // if (atk_widget == null)
221 // logger.error("set_atk_name_description: atk_widget is null for name=" + name + "; description=" + description);
224 // atk_widget.set_name(name);
225 // atk_widget.set_description(description);