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 private static const ShadowType ARROW_SHADOW = ShadowType.NONE;
40 private IdentityManagerView manager_view;
42 public IdCard id_card { get; set; default = null; }
43 private VBox main_vbox;
45 private EventBox event_box;
46 private bool is_selected = false;
51 internal int _position = 0;
52 internal int position {
53 get {return _position;}
54 set {_position = value; set_idcard_color();}
57 public signal void expanded();
58 public signal void collapsed();
60 internal void select()
66 internal void unselect()
78 arrow.set(ArrowType.DOWN, ARROW_SHADOW);
81 public void collapse()
87 arrow.set(ArrowType.RIGHT, ARROW_SHADOW);
90 private bool button_press_cb()
100 private void set_idcard_color()
102 var color = Gdk.Color();
106 color.red = 0xd9 << 8;
107 color.green = 0xf7 << 8;
111 if (position % 2 == 0)
113 color.red = color.green = color.blue = 0xf2 << 8;
123 this.event_box.modify_bg(StateType.NORMAL, color);
124 this.arrow.modify_bg(StateType.NORMAL, color);
128 make_id_card_label(Label label)
130 var display_name = (manager_view.selection_in_progress() && this.id_card.is_no_identity()
131 ? _("Do not use a Moonshot identity for this service") : this.id_card.display_name);
132 var label_text = Markup.printf_escaped("<span rise='8000'><big>%s</big></span>", display_name);
134 label.set_markup(label_text);
137 public IdCardWidget(IdCard id_card, IdentityManagerView manager_view)
139 this.id_card = id_card;
140 this.manager_view = manager_view;
142 var display_name_label = new Label(null);
143 display_name_label.set_alignment((float) 0, (float) 0.5);
144 display_name_label.set_ellipsize(Pango.EllipsizeMode.END);
145 make_id_card_label(display_name_label);
147 var details_wrapper = new VBox(false, 0);
148 details_wrapper.pack_start(display_name_label, false, false, 0);
149 this.details = new VBox(false, 0);
150 details_wrapper.pack_start(details, false, false, 0);
152 if (!this.id_card.is_no_identity()) {
153 var upper_details_text = _("Username") + ": " + id_card.username;
154 upper_details_text += "\n" + _("Realm:") + " " + id_card.issuer;
155 if (!id_card.trust_anchor.is_empty()) {
156 upper_details_text += "\n" + _("Trust anchor: Enterprise provisioned");
158 Label upper_details = new Label(upper_details_text);
159 upper_details.set_alignment(0, 0);
160 details.pack_start(upper_details);
162 var services_hbox = new HBox(false, 6);
163 Label services_label = new Label(_("Services: "));
164 services_label.set_alignment(0, 0);
166 string services_text = this.id_card.get_services_string("\n");
167 Label service_list = new Label(services_text);
168 service_list.set_alignment(0, 0);
169 service_list.set_ellipsize(Pango.EllipsizeMode.END);
170 service_list.set_max_width_chars(50);
171 services_hbox.pack_start(services_label, false, false, 0);
172 services_hbox.pack_start(service_list, false, false, 0);
173 details.pack_start(services_hbox);
175 hbox = new Gtk.HBox(false, 6);
176 var image = new Image.from_pixbuf(get_pixbuf(id_card));
177 if (this.id_card.is_no_identity()) {
179 // Use padding to make the image size = 48x48 (size = 2x padding)
180 image.set_padding(24, 24);
182 hbox.pack_start(image, false, false, 0);
183 hbox.pack_start(details_wrapper, true, true, 0);
184 this.arrow = new Arrow(ArrowType.RIGHT, ARROW_SHADOW);
185 this.arrow.set_alignment((float) 0.5, (float) 0);
186 hbox.pack_start(arrow, false, false);
188 this.main_vbox = new VBox(false, 12);
189 main_vbox.pack_start(hbox, true, true, 0);
190 main_vbox.set_border_width(12);
192 event_box = new EventBox();
193 event_box.add(main_vbox);
194 event_box.button_press_event.connect(button_press_cb);
195 event_box.set_visible(false);
196 this.pack_start(event_box, true, true);