[gnome-boxes] Prep vnc-display for authentication



commit ceb88a3a8ff461b2f5841449dd19182a1b01be8d
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date:   Wed Oct 26 16:26:24 2011 +0200

    Prep vnc-display for authentication

 src/display.vala     |    2 ++
 src/machine.vala     |   11 +++++++++++
 src/vnc-display.vala |   38 +++++++++++++++++++++++++++++++++-----
 3 files changed, 46 insertions(+), 5 deletions(-)
---
diff --git a/src/display.vala b/src/display.vala
index d2d8993..afc85ee 100644
--- a/src/display.vala
+++ b/src/display.vala
@@ -2,7 +2,9 @@
 
 private abstract class Boxes.Display: GLib.Object {
     public bool need_password { get; set; }
+    public bool need_username { get; set; }
     public string? password { get; set; }
+    public string? username { get; set; }
 
     public signal void show (int display_id);
     public signal void hide (int display_id);
diff --git a/src/machine.vala b/src/machine.vala
index df36982..188c37a 100644
--- a/src/machine.vala
+++ b/src/machine.vala
@@ -14,6 +14,7 @@ private abstract class Boxes.Machine: Boxes.CollectionItem {
     private ulong hide_id;
     private ulong disconnected_id;
     private ulong need_password_id;
+    private ulong need_username_id;
     private uint screenshot_id;
 
     private Display? _display;
@@ -29,6 +30,8 @@ private abstract class Boxes.Machine: Boxes.CollectionItem {
                 disconnected_id = 0;
                 _display.disconnect (need_password_id);
                 need_password_id = 0;
+                _display.disconnect (need_username_id);
+                need_username_id = 0;
             }
 
             _display = value;
@@ -62,6 +65,10 @@ private abstract class Boxes.Machine: Boxes.CollectionItem {
                 machine_actor.set_password_needed (display.need_password);
             });
 
+            need_username_id = _display.notify["need-username"].connect (() => {
+                machine_actor.set_username_needed (display.need_username);
+            });
+
             _display.password = machine_actor.get_password ();
 
             if (_connect_display)
@@ -450,6 +457,10 @@ private class Boxes.MachineActor: Boxes.UI {
             password_entry.grab_focus ();
     }
 
+    public void set_username_needed (bool needed) {
+        debug ("fixme");
+    }
+
     public string get_password () {
         return password_entry.text;
     }
diff --git a/src/vnc-display.vala b/src/vnc-display.vala
index 179c709..efcec9c 100644
--- a/src/vnc-display.vala
+++ b/src/vnc-display.vala
@@ -29,17 +29,37 @@ private class Boxes.VncDisplay: Boxes.Display {
         display.vnc_disconnected.connect (() => {
             hide (0);
         });
-        display.vnc_initialized.connect (() => {
-            debug ("initialized");
-        });
+
         display.vnc_auth_failure.connect (() => {
             debug ("auth failure");
         });
         display.vnc_auth_unsupported.connect (() => {
             debug ("auth unsupported");
         });
-        display.vnc_auth_credential.connect (() => {
-            debug ("auth credentials");
+
+        display.vnc_auth_credential.connect ((vnc, creds) => {
+            foreach (var cred in creds) {
+                var credential = cred as DisplayCredential;
+
+                switch (credential) {
+                case DisplayCredential.USERNAME:
+                    need_username = true;
+                    break;
+
+                case DisplayCredential.PASSWORD:
+                    need_password = true;
+                    break;
+
+                case DisplayCredential.CLIENTNAME:
+                    break;
+
+                default:
+                    debug ("Unsupported credential: %s".printf (credential.to_string ()));
+                    break;
+                }
+            }
+
+            display.close ();
         });
     }
 
@@ -63,13 +83,21 @@ private class Boxes.VncDisplay: Boxes.Display {
 
     public override Gtk.Widget? get_display (int n) throws Boxes.Error {
         window.remove (display);
+
         return display;
     }
 
     public override void connect_it () {
+        // FIXME: we ignore return value which seems to be inconsistent
+        display.set_credential (DisplayCredential.USERNAME, username);
+        display.set_credential (DisplayCredential.PASSWORD, password);
+        display.set_credential (DisplayCredential.CLIENTNAME, "boxes");
+
         display.open_host (host, port.to_string ());
     }
 
     public override void disconnect_it () {
+        if (display.is_open ())
+            display.close ();
     }
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]