2 * Copyright (c) 2011-2016, 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 private EventBox event_box;
42 private bool is_selected = false;
46 internal int _position = 0;
47 internal int position {
48 get {return _position;}
49 set {_position = value; set_idcard_color();}
52 public signal void expanded();
53 public signal void collapsed();
61 private void unselect()
70 update_id_card_label();
76 public void collapse()
79 update_id_card_label();
84 private bool button_press_cb()
94 private void set_idcard_color()
96 var color = Gdk.Color();
100 color.red = 0xd9 << 8;
101 color.green = 0xf7 << 8;
105 if (position % 2 == 0)
107 color.red = color.green = color.blue = 0xf2 << 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 = "\n ";
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;
134 if (!id_card.trust_anchor.is_empty()) {
135 label_text += "\nTrust anchor: " + id_card.trust_anchor.get_anchor_type();
137 services_text += this.id_card.get_services_string(service_spacer);
138 label_text += "\n" + services_text;
141 label.set_markup(label_text);
144 public IdCardWidget(IdCard id_card)
146 this.id_card = id_card;
148 var image = new Image.from_pixbuf(get_pixbuf(id_card));
150 label = new Label(null);
151 label.set_alignment((float) 0, (float) 0.5);
152 label.set_ellipsize(Pango.EllipsizeMode.END);
153 update_id_card_label();
155 table = new Gtk.HBox(false, 6);
156 table.pack_start(image, false, false, 0);
157 table.pack_start(label, true, true, 0);
159 this.main_vbox = new VBox(false, 12);
160 main_vbox.pack_start(table, true, true, 0);
161 main_vbox.set_border_width(12);
163 event_box = new EventBox();
164 event_box.add(main_vbox);
165 event_box.button_press_event.connect(button_press_cb);
166 event_box.set_visible(false);
167 this.pack_start(event_box, true, true);