Use the label text 'Do not use a Moonshot identity for this service' if displaying...
[moonshot-ui.git] / src / moonshot-identity-management-view.vala
index cea963b..aebaec9 100644 (file)
@@ -35,6 +35,11 @@ using Gtk;
 public class IdentityManagerView : Window {
     static MoonshotLogger logger = get_logger("IdentityManagerView");
 
+    // The latest year in which Moonshot sources were modified.
+    private static int LATEST_EDIT_YEAR = 2016;
+
+    public static Gdk.Color white = make_color(65535, 65535, 65535);
+
     private const int WINDOW_WIDTH = 700;
     private const int WINDOW_HEIGHT = 500;
     protected IdentityManagerApp parent_app;
@@ -58,7 +63,7 @@ public class IdentityManagerView : Window {
     internal IdentityManagerModel identities_manager;
     private unowned SList<IdCard>    candidates;
 
-    public GLib.Queue<IdentityRequest> request_queue;
+    private GLib.Queue<IdentityRequest> request_queue;
 
     internal CheckButton remember_identity_binding = null;
 
@@ -246,6 +251,10 @@ public class IdentityManagerView : Window {
 
         id_card.update_services_from_list(dialog.get_services());
 
+        if (dialog.clear_trust_anchor) {
+            id_card.clear_trust_anchor();
+        }
+
         return id_card;
     }
 
@@ -287,7 +296,7 @@ public class IdentityManagerView : Window {
 
     private IdCardWidget add_id_card_widget(IdCard id_card)
     {
-        var id_card_widget = new IdCardWidget(id_card);
+        var id_card_widget = new IdCardWidget(id_card, this);
         this.custom_vbox.add_id_card_widget(id_card_widget);
         id_card_widget.expanded.connect(this.widget_selected_cb);
         id_card_widget.collapsed.connect(this.widget_unselected_cb);
@@ -300,7 +309,7 @@ public class IdentityManagerView : Window {
         this.edit_button.set_sensitive(true);
         this.custom_vbox.receive_expanded_event(id_card_widget);
 
-        if (this.request_queue.length > 0)
+        if (this.selection_in_progress())
              this.send_button.set_sensitive(true);
     }
 
@@ -481,7 +490,7 @@ public class IdentityManagerView : Window {
 
     public void queue_identity_request(IdentityRequest request)
     {
-        if (this.request_queue.is_empty())
+        if (!this.selection_in_progress())
         { /* setup widgets */
             candidates = request.candidates;
             filter.refilter();
@@ -542,15 +551,20 @@ public class IdentityManagerView : Window {
 
     private void send_identity_cb(IdCard id)
     {
-        send_button.set_sensitive(false);
+        return_if_fail(this.selection_in_progress());
 
-        IdCard identity = id;
-        return_if_fail(request_queue.length > 0);
+        if (!check_and_confirm_trust_anchor(id)) {
+            // Allow user to pick again
+            return;
+        }
 
-        candidates = null;
         var request = this.request_queue.pop_head();
-        identity = check_add_password(identity, request, identities_manager);
-        if (this.request_queue.is_empty())
+        var identity = check_add_password(id, request, identities_manager);
+        send_button.set_sensitive(false);
+
+        candidates = null;
+      
+        if (!this.selection_in_progress())
         {
             candidates = null;
             clear_selection_prompts();
@@ -578,6 +592,34 @@ public class IdentityManagerView : Window {
         remember_identity_binding.hide();
     }
 
+    private bool check_and_confirm_trust_anchor(IdCard id)
+    {
+        if (!id.trust_anchor.is_empty() && id.trust_anchor.get_anchor_type() == TrustAnchor.TrustAnchorType.SERVER_CERT) {
+            if (!id.trust_anchor.user_verified) {
+
+                bool ret = false;
+                int result = ResponseType.CANCEL;
+                var dialog = new TrustAnchorDialog(id, this);
+                while (!dialog.complete)
+                    result = dialog.run();
+
+                switch (result) {
+                case ResponseType.OK:
+                    id.trust_anchor.user_verified = true;
+                    ret = true;
+                    break;
+                default:
+                    break;
+                }
+
+                dialog.destroy();
+                return ret;
+            }
+        }
+        return true;
+    }
+
+
     // private void label_make_bold(Label label)
     // {
     //     var font_desc = new Pango.FontDescription();
@@ -594,11 +636,11 @@ public class IdentityManagerView : Window {
 
     private void on_about_action()
     {
-        string copyright = "Copyright 2011, 2016 JANET";
+        string copyright = "Copyright (c) 2011, %d JANET".printf(LATEST_EDIT_YEAR);
 
         string license =
         """
-Copyright (c) 2011, 2016 JANET(UK)
+Copyright (c) 2011, %d JANET(UK)
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
@@ -627,18 +669,24 @@ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 SUCH DAMAGE.
-""";
-
-        Gtk.show_about_dialog(this,
-                              "comments", _("Moonshot project UI"),
-                              "copyright", copyright,
-                              "website", Config.PACKAGE_URL,
-                              "version", Config.PACKAGE_VERSION,
-                              "license", license,
-                              "website-label", _("Visit the Moonshot project web site"),
-                              "translator-credits", _("translator-credits"),
-                              null
-            );
+""".printf(LATEST_EDIT_YEAR);
+
+        AboutDialog about = new AboutDialog();
+
+        about.set_comments(_("Moonshot project UI"));
+        about.set_copyright(copyright);
+        about.set_website(Config.PACKAGE_URL);
+        about.set_website_label(_("Visit the Moonshot project web site"));
+
+        // Note: The package version is configured at the top of moonshot/ui/configure.ac
+        about.set_version(Config.PACKAGE_VERSION);
+        about.set_license(license);
+        about.set_modal(true);
+        about.set_transient_for(this);
+        about.response.connect((a, b) => {about.destroy();});
+        about.modify_bg(StateType.NORMAL, white);
+        
+        about.run();
     }
 
     private Gtk.ActionEntry[] create_actions() {
@@ -685,8 +733,6 @@ SUCH DAMAGE.
     private void build_ui()
     {
         // Note: On Debian7/Gtk+2, the menu bar remains gray. This doesn't happen on Debian8/Gtk+3.
-        Gdk.Color white = Gdk.Color();
-        white.red = white.green = white.blue = 65535;
         this.modify_bg(StateType.NORMAL, white);
 
         create_ui_manager();
@@ -817,10 +863,14 @@ SUCH DAMAGE.
         add(main_vbox);
         main_vbox.show_all();
 
-        if (this.request_queue.length == 0)
+        if (!this.selection_in_progress())
             remember_identity_binding.hide();
     } 
 
+    internal bool selection_in_progress() {
+        return !this.request_queue.is_empty();
+    }
+
     private void set_atk_name_description(Widget widget, string name, string description)
     {
         var atk_widget = widget.get_accessible();