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 = 0;
51 internal int position {
52 get {return _position;}
53 set {_position = value; set_idcard_color();}
56 public signal void expanded();
57 public signal void remove_id();
58 public signal void details_id();
59 public signal void send_id();
61 public void collapse()
63 // this.hbutton_box.set_visible(false);
65 update_id_card_label();
72 // this.hbutton_box.set_visible(true);
74 update_id_card_label();
80 private bool button_press_cb()
90 private void delete_button_cb()
95 private void details_button_cb()
100 private void send_button_cb()
105 private void set_idcard_color()
107 var color = Gdk.Color();
111 color.red = 0xd9 << 8;
112 color.green = 0xf7 << 8;
116 if (position % 2 == 0)
118 color.red = color.green = color.blue = 0xf2 << 8;
128 var state = this.get_state();
129 this.event_box.modify_bg(state, color);
133 update_id_card_label()
135 // !!TODO: Use a table to format the labels and values
136 string services_text = "Services: ";
137 string service_spacer = " ";
139 var label_text = Markup.printf_escaped("<big>%s</big>", this.id_card.display_name);
143 label_text += "\nUsername: " + id_card.username;
144 label_text += "\nRealm: " + id_card.issuer;
147 for (int i = 0; i < id_card.services.length; i++)
149 services_text += sep;
150 services_text += id_card.services[i];
152 sep = "\n" + service_spacer;
154 label_text += "\n" + services_text;
157 label.set_markup(label_text);
160 public IdCardWidget(IdCard id_card)
162 this.id_card = id_card;
164 var image = new Image.from_pixbuf(get_pixbuf(id_card));
166 label = new Label(null);
167 label.set_alignment((float) 0, (float) 0.5);
168 label.set_ellipsize(Pango.EllipsizeMode.END);
169 update_id_card_label();
171 table = new Gtk.HBox(false, 6);
172 table.pack_start(image, false, false, 0);
173 table.pack_start(label, true, true, 0);
175 // this.delete_button = new Button.with_label(_("Delete"));
176 // this.details_button = new Button.with_label(_("View details"));
177 // this.send_button = new Button.with_label(_("Send"));
178 // set_atk_name_description(delete_button, _("Delete"), _("Delete this ID Card"));
179 // set_atk_name_description(details_button, _("Details"), _("View the details of this ID Card"));
180 // set_atk_name_description(send_button, _("Send"), _("Send this ID Card"));
181 // this.hbutton_box = new HButtonBox();
182 // hbutton_box.pack_end(delete_button);
183 // hbutton_box.pack_end(details_button);
184 // hbutton_box.pack_end(send_button);
185 // send_button.set_sensitive(false);
187 // delete_button.clicked.connect(delete_button_cb);
188 // details_button.clicked.connect(details_button_cb);
189 // send_button.clicked.connect(send_button_cb);
191 this.main_vbox = new VBox(false, 12);
192 main_vbox.pack_start(table, true, true, 0);
193 // main_vbox.pack_start(hbutton_box, false, false, 0);
194 main_vbox.set_border_width(12);
196 event_box = new EventBox();
197 event_box.add(main_vbox);
198 event_box.button_press_event.connect(button_press_cb);
199 event_box.set_visible(false);
200 this.pack_start(event_box, true, true);
203 // this.hbutton_box.hide();
208 // private void set_atk_name_description(Widget widget, string name, string description)
210 // if (widget == null)
212 // logger.error("set_atk_name_description: widget is null for name=" + name + "; description=" + description);
216 // var atk_widget = widget.get_accessible();
218 // if (atk_widget == null)
220 // logger.error("set_atk_name_description: atk_widget is null for name=" + name + "; description=" + description);
223 // atk_widget.set_name(name);
224 // atk_widget.set_description(description);