[gnome-boxes/wip/feborges/rdp: 8/14] remote-machine: Introduce RDP support



commit e6088aea433d6950a6a949b2831c3b5034910246
Author: Felipe Borges <felipeborges gnome org>
Date:   Mon Apr 23 15:18:30 2018 +0200

    remote-machine: Introduce RDP support

 src/app.vala            |  1 +
 src/meson.build         |  1 +
 src/rdp-display.vala    | 90 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/remote-machine.vala |  6 +++-
 src/wizard.vala         |  3 ++
 5 files changed, 100 insertions(+), 1 deletion(-)
---
diff --git a/src/app.vala b/src/app.vala
index 77d7d7c6..0fa9abe6 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -378,6 +378,7 @@ public async void add_collection_source (CollectionSource source) throws GLib.Er
         switch (source.source_type) {
         case "vnc":
         case "spice":
+        case "rdp":
             try {
                 var machine = new RemoteMachine (source);
                 collection.add_item (machine);
diff --git a/src/meson.build b/src/meson.build
index b361a302..2f30704b 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -103,6 +103,7 @@ vala_sources = [
   'libvirt-vm-cloner.vala',
   'libvirt-vm-importer.vala',
   'vnc-display.vala',
+  'rdp-display.vala',
   'wizard-downloads-page.vala',
   'wizard-window.vala',
   'wizard-source.vala',
diff --git a/src/rdp-display.vala b/src/rdp-display.vala
new file mode 100644
index 00000000..973b9617
--- /dev/null
+++ b/src/rdp-display.vala
@@ -0,0 +1,90 @@
+// This file is part of GNOME Boxes. License: LGPLv2+
+using Gtk;
+using Frdp;
+
+private class Boxes.RdpDisplay: Boxes.Display {
+    public override string protocol { get { return "RDP"; } }
+    public override string? uri { owned get { return @"rdp://$host:$port"; } }
+    private Frdp.Display display;
+    private string host;
+    private int port;
+    private BoxConfig.SavedProperty[] saved_properties;
+
+    construct {
+        saved_properties = {
+            BoxConfig.SavedProperty () { name = "read-only", default_value = false }
+        };
+        need_password = false;
+
+        display = new Frdp.Display ();
+
+        display.rdp_connected.connect (() => {
+            show (0);
+            access_start ();
+        });
+        display.rdp_disconnected.connect (() => {
+            hide (0);
+            access_finish ();
+        });
+    }
+
+    public RdpDisplay (BoxConfig config, string host, int port) {
+        this.config = config;
+
+        this.host = host;
+        this.port = port;
+
+        config.save_properties (display, saved_properties);
+    }
+
+    public RdpDisplay.with_uri (BoxConfig config, string _uri) throws Boxes.Error {
+        this.config = config;
+
+        var uri = Xml.URI.parse (_uri);
+
+        if (uri.scheme != "rdp")
+            throw new Boxes.Error.INVALID ("the URL is not rdp://");
+
+        if (uri.server == null)
+            throw new Boxes.Error.INVALID ("the URL is missing a server");
+
+        this.host = uri.server;
+        this.port = uri.port <= 0 ? 3389 : uri.port;
+
+        config.save_properties (display, saved_properties);
+    }
+
+    public override Gtk.Widget get_display (int n) {
+        return display;
+    }
+
+    public override void set_enable_audio (bool enable) {
+    }
+
+    public override Gdk.Pixbuf? get_pixbuf (int n) throws Boxes.Error {
+        return null;
+    }
+
+    public override void connect_it (owned Display.OpenFDFunc? open_fd = null) throws GLib.Error {
+        // We only initiate connection once
+        if (connected)
+            return;
+        connected = true;
+
+        display.open_host (host, port);
+    }
+
+    public override void disconnect_it () {
+        if (display.is_open ())
+            display.close ();
+    }
+
+    public override List<Boxes.Property> get_properties (Boxes.PropertiesPage page) {
+        var list = new List<Boxes.Property> ();
+
+        return list;
+    }
+
+    public override void send_keys (uint[] keyvals) {
+    }
+}
diff --git a/src/remote-machine.vala b/src/remote-machine.vala
index 0c07e9da..ebe145d9 100644
--- a/src/remote-machine.vala
+++ b/src/remote-machine.vala
@@ -7,7 +7,8 @@
 
     public RemoteMachine (CollectionSource source) throws Boxes.Error {
         if (source.source_type != "spice" &&
-            source.source_type != "vnc")
+            source.source_type != "vnc" &&
+            source.source_type != "rdp")
             throw new Boxes.Error.INVALID ("source is not remote machine: %s", source.uri);
 
         base (source, source.name);
@@ -34,6 +35,9 @@ public RemoteMachine (CollectionSource source) throws Boxes.Error {
         case "vnc":
             return new VncDisplay.with_uri (config, source.uri);
 
+        case "rdp":
+            return new RdpDisplay.with_uri (config, source.uri);
+
         default:
             throw new Boxes.Error.INVALID ("unsupported display of type " + type);
         }
diff --git a/src/wizard.vala b/src/wizard.vala
index 223a1476..c9be7dbe 100644
--- a/src/wizard.vala
+++ b/src/wizard.vala
@@ -363,6 +363,8 @@ private void prepare_for_uri (string uri_as_text, string? filename = null) throw
             source.source_type = "spice";
         } else if (uri.scheme == "vnc") {
             // accept any vnc:// uri
+        } else if (uri.scheme == "rdp") {
+            // accept any rdp:// uri
         } else if (uri.scheme.has_prefix ("qemu")) {
             // accept any qemu..:// uri
             source.source_type = "libvirt";
@@ -546,6 +548,7 @@ private async bool do_review_cancellable () {
                 break;
 
             case "vnc":
+            case "rdp":
                 if (uri.port > 0)
                     summary.add_property (_("Port"), uri.port.to_string ());
                 break;


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