X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=src%2Fmoonshot-identity-dialog.vala;h=dc9142b01e4d68c35a19739350eb0ee44d24b700;hb=537f157a7a5fb7ea9e44a403a65621b81556b78a;hp=ce3899f166db1f8332f6f93ad3ffa76eeaf56f5f;hpb=23366f80079adcd7b170e672de9957ccbf49f5a2;p=moonshot-ui.git diff --git a/src/moonshot-identity-dialog.vala b/src/moonshot-identity-dialog.vala index ce3899f..dc9142b 100644 --- a/src/moonshot-identity-dialog.vala +++ b/src/moonshot-identity-dialog.vala @@ -29,6 +29,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ + +using Gee; using Gtk; @@ -44,7 +46,6 @@ class IdentityDialog : Dialog { private static Gdk.Color white = make_color(65535, 65535, 65535); private static Gdk.Color selected_color = make_color(0xd9 << 8, 0xf7 << 8, 65535); - private static Gdk.Color alt_color = make_color(0xf2 << 8, 0xf2 << 8, 0xf2 << 8); private static MoonshotLogger logger = get_logger("IdentityDialog"); @@ -53,7 +54,6 @@ class IdentityDialog : Dialog static const string username_labeltext = _("Username"); static const string password_labeltext = _("Password"); - private IdentityManagerView parent; private Entry displayname_entry; private Label displayname_label; private Entry realm_entry; @@ -89,7 +89,7 @@ class IdentityDialog : Dialog get { return remember_checkbutton.active; } } - internal string[] get_services() + internal ArrayList get_services() { return card.services; } @@ -111,7 +111,6 @@ class IdentityDialog : Dialog this.set_title(title); this.set_modal(true); this.set_transient_for(parent); - this.parent = parent; this.add_buttons(_("OK"), ResponseType.OK, CANCEL, ResponseType.CANCEL); Box content_area = (Box) this.get_content_area(); @@ -176,18 +175,98 @@ class IdentityDialog : Dialog this.response.connect(on_response); content_area.set_border_width(6); + Widget trust_anchor_box = make_trust_anchor_box(card); + content_area.pack_start(trust_anchor_box, false, false, 15); + if (!is_new_card) { var services_vbox = make_services_vbox(); content_area.pack_start(services_vbox); } + if (card.is_no_identity()) + { + displayname_entry.set_sensitive(false); + realm_entry.set_sensitive(false); + username_entry.set_sensitive(false); + password_entry.set_sensitive(false); + remember_checkbutton.set_sensitive(false); + } + this.set_border_width(6); this.set_resizable(false); this.modify_bg(StateType.NORMAL, white); this.show_all(); } + private static Widget make_trust_anchor_box(IdCard id) + { + + Label ta_label = new Label(_("Trust anchor: ") + + (id.trust_anchor.is_empty() ? _("None") : _("Enterprise provisioned"))); + ta_label.set_alignment(0, 0.5f); + + if (id.trust_anchor.is_empty()) { + return ta_label; + } + + + AttachOptions opts = AttachOptions.EXPAND | AttachOptions.FILL; + AttachOptions fill = AttachOptions.FILL; + + Table ta_table = new Table(6, 2, false); + int row = 0; + + var ta_clear_button = new Button.with_label(_("Clear Trust Anchor")); + ta_clear_button.clicked.connect((w) => {id.trust_anchor = new TrustAnchor();}); + + ta_table.attach(ta_label, 0, 1, row, row + 1, opts, opts, 0, 0); + ta_table.attach(ta_clear_button, 1, 2, row, row + 1, fill, fill, 0, 0); + row++; + + //!!TODO + Label added_label = new Label(_("Added on: N/A")); + added_label.set_alignment(0, 0.5f); + ta_table.attach(added_label, 0, 1, row, row + 1, opts, opts, 20, 5); + row++; + + if (id.trust_anchor.get_anchor_type() == TrustAnchor.TrustAnchorType.SERVER_CERT) { + Widget fingerprint = make_ta_fingerprint_widget(id.trust_anchor); + ta_table.attach(fingerprint, 0, 2, row, row + 2, opts, opts, 20, 5); + } + else { + Label ca_cert_label = new Label(_("CA Certificate:")); + ca_cert_label.set_alignment(0, 0.5f); + var export_button = new Button.with_label(_("Export Certificate")); + //!!TODO! + export_button.clicked.connect((w) => {/* !!TODO! */}); + + ta_table.attach(ca_cert_label, 0, 1, row, row + 1, opts, opts, 20, 0); + ta_table.attach(export_button, 1, 2, row, row + 1, fill, fill, 0, 0); + row++; + + //!!TODO: When to show Subject, and when (if ever) show Subject-Altname here? + Label subject_label = new Label(_("Subject: ") + id.trust_anchor.subject); + subject_label.set_alignment(0, 0.5f); + ta_table.attach(subject_label, 0, 1, row, row + 1, opts, opts, 40, 5); + row++; + + Label expiration_label = new Label(_("Expiration date: ") + id.trust_anchor.get_expiration_date()); + expiration_label.set_alignment(0, 0.5f); + ta_table.attach(expiration_label, 0, 1, row, row + 1, opts, opts, 40, 5); + row++; + + //!!TODO: What *is* this? + Label constraint_label = new Label(_("Constraint: ")); + constraint_label.set_alignment(0, 0.5f); + ta_table.attach(constraint_label, 0, 1, row, row + 1, opts, opts, 20, 0); + row++; + } + + return ta_table; + + } + private static void add_as_vbox(Box content_area, Label label, Entry entry) { VBox vbox = new VBox(false, 2); @@ -234,10 +313,13 @@ class IdentityDialog : Dialog string preamble = ""; string message = ""; string password_test = store_password ? password : "not required"; - check_field(display_name, displayname_label, displayname_labeltext, ref preamble, ref message); - check_field(username, username_label, username_labeltext, ref preamble, ref message); - check_field(issuer, realm_label, realm_labeltext, ref preamble, ref message); - check_field(password_test, password_label, password_labeltext, ref preamble, ref message); + if (!card.is_no_identity()) + { + check_field(display_name, displayname_label, displayname_labeltext, ref preamble, ref message); + check_field(username, username_label, username_labeltext, ref preamble, ref message); + check_field(issuer, realm_label, realm_labeltext, ref preamble, ref message); + check_field(password_test, password_label, password_labeltext, ref preamble, ref message); + } if (message != "") { message_label.set_visible(true); message_label.set_markup(@"$preamble$message"); @@ -276,7 +358,7 @@ class IdentityDialog : Dialog { logger.trace("make_services_vbox"); - var services_vbox_alignment = new Alignment(0, 0, 0, 1); + var services_vbox_alignment = new Alignment(0, 0, 1, 0); var services_vscroll = new ScrolledWindow(null, null); services_vscroll.set_policy(PolicyType.NEVER, PolicyType.AUTOMATIC); services_vscroll.set_shadow_type(ShadowType.IN); @@ -291,7 +373,7 @@ class IdentityDialog : Dialog remove_button.set_sensitive(false); - var services_table = new Table(card.services.length, 1, false); + var services_table = new Table(card.services.size, 1, false); services_table.set_row_spacings(1); services_table.set_col_spacings(0); services_table.modify_bg(StateType.NORMAL, white); @@ -302,7 +384,7 @@ class IdentityDialog : Dialog // Hack to prevent the button from growing vertically VBox fixed_height = new VBox(false, 0); fixed_height.pack_start(remove_button, false, false, 0); - table_button_hbox.pack_start(fixed_height, false, false, 6); + table_button_hbox.pack_start(fixed_height, false, false, 0); // A table doesn't have a background color, so put it in an EventBox, and // set the EventBox's background color instead. @@ -313,17 +395,18 @@ class IdentityDialog : Dialog var services_vbox_title = new Label(_("Services:")); label_make_bold(services_vbox_title); - services_vbox_title.set_alignment(0, (float) 0.5); + services_vbox_title.set_alignment(0, 0.5f); var services_vbox = new VBox(false, 6); - services_vbox.pack_start(services_vbox_title, false, false, 6); - services_vbox.pack_start(table_button_hbox, true, true, 6); + services_vbox.pack_start(services_vbox_title, false, false, 0); + services_vbox.pack_start(table_button_hbox, true, true, 0); int i = 0; foreach (string service in card.services) { var label = new Label(service); label.set_alignment((float) 0, (float) 0); + label.xpad = 3; EventBox event_box = new EventBox(); event_box.modify_bg(StateType.NORMAL, white); @@ -357,39 +440,23 @@ class IdentityDialog : Dialog return false; }); - AttachOptions opts = AttachOptions.EXPAND | AttachOptions.FILL; - services_table.attach(event_box, 0, 1, i, i+1, opts, opts, 3, 0); + services_table.attach_defaults(event_box, 0, 1, i, i+1); i++; } remove_button.clicked.connect((remove_button) => { - var dialog = new Gtk.MessageDialog(this, - Gtk.DialogFlags.DESTROY_WITH_PARENT, - Gtk.MessageType.QUESTION, - Gtk.ButtonsType.YES_NO, - _("You are about to remove the service '%s'. Are you sure you want to do this?"), - selected_item.label); - var ret = dialog.run(); - dialog.destroy(); - - if (ret == Gtk.ResponseType.YES) + var result = WarningDialog.confirm(this, + Markup.printf_escaped( + "You are about to remove the service '%s'.", + selected_item.label) + + "\n\nAre you sure you want to do this?", + "delete_service"); + + if (result) { if (card != null) { - SList services = new SList(); - - foreach (string srv in card.services) - { - if (srv != selected_item.label) - services.append(srv); - } - - card.services = new string[services.length()]; - for (int j = 0; j < card.services.length; j++) - { - card.services[j] = services.nth_data(j); - } - + card.services.remove(selected_item.label); services_table.remove(selected_item.parent); selected_item = null; remove_button.set_sensitive(false);