Add password dialog
authorJavier Jardón <javier.jardon@codethink.co.uk>
Wed, 8 Jun 2011 13:25:06 +0000 (14:25 +0100)
committerJavier Jardón <javier.jardon@codethink.co.uk>
Wed, 8 Jun 2011 13:25:06 +0000 (14:25 +0100)
This dialog appears when the password is not already saved in the
identity card

Makefile.am
src/moonshot-identities-manager.vala
src/moonshot-password-dialog.vala [new file with mode: 0644]
src/moonshot-window.vala

index 726c7fe..402113c 100644 (file)
@@ -22,6 +22,7 @@ src_moonshot_SOURCES = \
         src/moonshot-custom-vbox.vala \
         src/moonshot-identities-manager.vala \
         src/moonshot-window.vala \
+        src/moonshot-password-dialog.vala \
         src/moonshot-utils.vala
 
 src_moonshot_LDADD = \
index 8d5d0c5..8d80e9e 100644 (file)
@@ -102,7 +102,8 @@ class IdentitiesManager : Object {
             return null;
 
         id_card_data = text.split ("\n", 2);
-        id_card.password = id_card_data[1];
+        if (id_card_data[1] != "")
+            id_card.password = id_card_data[1];
         id_card_data = id_card_data[0].split ("@", 2);
         id_card.username = id_card_data[0];
         id_card.issuer = id_card_data[1];
diff --git a/src/moonshot-password-dialog.vala b/src/moonshot-password-dialog.vala
new file mode 100644 (file)
index 0000000..c5de2b7
--- /dev/null
@@ -0,0 +1,56 @@
+using Gtk;
+
+class AddPasswordDialog : Dialog
+{
+    private Entry password_entry;
+
+    public string password {
+        get { return password_entry.get_text (); }
+    }
+
+    public AddPasswordDialog ()
+    {
+        this.set_title (_("Please enter your password"));
+        this.set_modal (true);
+
+        this.add_buttons (_("Send"), ResponseType.OK,
+                          _("Return to application"), ResponseType.CANCEL);
+
+        var content_area = this.get_content_area ();
+        ((Box) content_area).set_spacing (12);
+
+        var password_label = new Label (_("Password:"));
+        password_label.set_alignment (1, (float) 0.5);
+        this.password_entry = new Entry ();
+        password_entry.set_invisible_char ('*');
+        password_entry.set_visibility (false);
+        var remember_checkbutton = new CheckButton.with_label (_("Remember password"));
+
+        set_atk_relation (password_entry, password_entry, Atk.RelationType.LABEL_FOR);
+
+        var table = new Table (2, 2, false);
+        table.set_col_spacings (10);
+        table.set_row_spacings (10);
+        table.attach_defaults (password_label, 0, 1, 2, 3);
+        table.attach_defaults (password_entry, 1, 2, 2, 3);
+        table.attach_defaults (remember_checkbutton,  1, 2, 3, 4);
+
+        var vbox = new VBox (false, 0);
+        vbox.set_border_width (6);
+        vbox.pack_start (table, false, false, 0);
+
+        ((Container) content_area).add (vbox);
+
+        this.set_border_width (6);
+        this.set_resizable (false);
+        this.show_all ();
+    }
+
+    private void set_atk_relation (Widget widget, Widget target_widget, Atk.RelationType relationship)
+    {
+        var atk_widget = widget.get_accessible ();
+        var atk_target_widget = target_widget.get_accessible ();
+
+        atk_widget.add_relationship (relationship, atk_target_widget);
+    }
+}
index 5fb5d83..9d774d4 100644 (file)
@@ -345,9 +345,29 @@ class MainWindow : Window
 
     public void send_identity_cb (IdCardWidget id_card_widget)
     {
-        this.hide ();
         this.selected_id_card_widget = id_card_widget;
-        this.callback ();
+
+        if (id_card_widget.id_card.password == null)
+        {
+            var dialog = new AddPasswordDialog ();
+            var result = dialog.run ();
+
+            switch (result) {
+            case ResponseType.OK:
+                this.hide ();
+                this.callback ();
+                break;
+            default:
+                this.hide ();
+                break;
+            }
+            dialog.destroy ();
+        }
+        else
+        {
+          this.hide ();
+          this.callback ();
+        }
     }
 
     private void label_make_bold (Label label)