[gnome-boxes/split-remote-outta-wizard: 6/7] assistant: Introduce the "Remote Connection" assistant



commit c96a2090bdaed42e099c1bd28646bf93b4295530
Author: Felipe Borges <felipeborges gnome org>
Date:   Tue Jul 16 14:16:52 2019 +0200

    assistant: Introduce the "Remote Connection" assistant
    
    Fixes #306

 data/gnome-boxes.gresource.xml         |  1 +
 data/ui/assistant/remote-connection.ui | 53 ++++++++++++++++++++++++
 data/ui/collection-toolbar.ui          |  7 ++++
 src/app-window.vala                    |  4 ++
 src/assistant/remote-connection.vala   | 73 ++++++++++++++++++++++++++++++++++
 src/collection-toolbar.vala            |  5 +++
 src/meson.build                        |  1 +
 7 files changed, 144 insertions(+)
---
diff --git a/data/gnome-boxes.gresource.xml b/data/gnome-boxes.gresource.xml
index 47c2a917..c7ba7de1 100644
--- a/data/gnome-boxes.gresource.xml
+++ b/data/gnome-boxes.gresource.xml
@@ -47,5 +47,6 @@
     <file preprocess="xml-stripblanks">ui/wizard-toolbar.ui</file>
     <file preprocess="xml-stripblanks">ui/wizard-web-view.ui</file>
     <file preprocess="xml-stripblanks">ui/wizard-window.ui</file>
+    <file preprocess="xml-stripblanks">ui/assistant/remote-connection.ui</file>
   </gresource>
 </gresources>
diff --git a/data/ui/assistant/remote-connection.ui b/data/ui/assistant/remote-connection.ui
new file mode 100644
index 00000000..c4d12759
--- /dev/null
+++ b/data/ui/assistant/remote-connection.ui
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="BoxesRemoteConnectionAssistant" parent="GtkDialog">
+    <property name="modal">True</property>
+    <property name="type-hint">dialog</property>
+    <property name="title" translatable="yes">Connect to a Box</property>
+    <property name="height-request">250</property>
+
+    <child internal-child="vbox">
+      <object class="GtkBox">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <property name="border-width">20</property>
+        <property name="spacing">20</property>
+        <property name="valign">center</property>
+        <child>
+          <object class="GtkLabel">
+            <property name="visible">True</property>
+            <property name="wrap">True</property>
+            <property name="halign">start</property>
+            <property name="max-width-chars">45</property>
+            <property name="label" translatable="yes">Enter an address to connect to. Addresses can begin 
with spice://, rdp:// or vnc://.</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkEntry" id="url_entry">
+            <property name="visible">True</property>
+            <signal name="activate" handler="on_url_entry_activated"/>
+          </object>
+        </child>
+      </object>
+    </child>
+
+    <child type="action">
+      <object class="GtkButton" id="cancel_button">
+        <property name="visible">True</property>
+        <property name="label" translatable="yes">Cancel</property>
+        <signal name="clicked" handler="gtk_widget_destroy" object="BoxesRemoteConnectionAssistant"/>
+      </object>
+    </child>
+    <child type="action">
+      <object class="GtkButton" id="connect_button">
+        <property name="visible">True</property>
+        <property name="sensitive">False</property>
+        <property name="label" translatable="yes">Connect</property>
+      </object>
+    </child>
+
+    <action-widgets>
+      <action-widget response="cancel">cancel_button</action-widget>
+    </action-widgets>
+  </template>
+</interface>
diff --git a/data/ui/collection-toolbar.ui b/data/ui/collection-toolbar.ui
index 6ce618a4..a9810b6e 100644
--- a/data/ui/collection-toolbar.ui
+++ b/data/ui/collection-toolbar.ui
@@ -213,6 +213,13 @@
             <signal name="clicked" handler="on_new_vm_btn_clicked"/>
           </object>
         </child>
+        <child>
+          <object class="GtkModelButton">
+            <property name="visible">True</property>
+            <property name="text" translatable="yes">Connect to a Remote Computer…</property>
+            <signal name="clicked" handler="on_connect_to_remote_btn_clicked"/>
+          </object>
+        </child>
       </object>
     </child>
   </object>
diff --git a/src/app-window.vala b/src/app-window.vala
index 0f5ebc75..8a1ebb6a 100644
--- a/src/app-window.vala
+++ b/src/app-window.vala
@@ -299,6 +299,10 @@ public void foreach_view (Func<ICollectionView> func) {
             func (view);
     }
 
+    public void show_remote_connection_assistant () {
+        new Boxes.RemoteConnectionAssistant (this).run ();
+    }
+
     public void show_properties () {
         if (current_item != null) {
             if (ui_state == UIState.COLLECTION && selection_mode)
diff --git a/src/assistant/remote-connection.vala b/src/assistant/remote-connection.vala
new file mode 100644
index 00000000..d2342815
--- /dev/null
+++ b/src/assistant/remote-connection.vala
@@ -0,0 +1,73 @@
+// This file is part of GNOME Boxes. License: LGPLv2+
+using Gtk;
+
+[GtkTemplate (ui = "/org/gnome/Boxes/ui/assistant/remote-connection.ui")]
+private class Boxes.RemoteConnectionAssistant : Gtk.Dialog {
+    [GtkChild]
+    private Gtk.Entry url_entry;
+
+    [GtkChild]
+    private Gtk.Button connect_button;
+
+    private AppWindow app_window;
+
+    construct {
+        use_header_bar = 1;
+    }
+
+    public RemoteConnectionAssistant (AppWindow app_window) {
+        this.app_window = app_window;
+
+        set_transient_for (app_window);
+
+        url_entry.changed.connect (on_url_entry_changed);
+        connect_button.clicked.connect (on_connect_button_clicked);
+        connect_button.get_style_context ().add_class ("suggested-action");
+    }
+
+    private void on_url_entry_changed () {
+        if (url_entry.text == "") {
+            connect_button.sensitive = false;
+
+            return;
+        }
+
+        var uri = Xml.URI.parse (url_entry.text);
+        if (uri == null || uri.scheme == null) {
+            connect_button.sensitive = false;
+
+            return;
+        }
+
+        if (uri.scheme == "vnc" ||
+            uri.scheme == "ssh" ||
+            uri.scheme == "rdp") {
+            connect_button.sensitive = true;
+        }
+    }
+
+    [GtkCallback]
+    private void on_url_entry_activated () {
+        if (connect_button.sensitive)
+            on_connect_button_clicked ();
+    }
+
+    private void on_connect_button_clicked () {
+        var uri = Xml.URI.parse (url_entry.text);
+        var source = new CollectionSource (uri.server ?? url_entry.text, uri.scheme, url_entry.text);
+
+        try {
+            if (source != null) {
+                var machine = new RemoteMachine (source);
+                if (machine is RemoteMachine)
+                    App.app.add_collection_source.begin (source);
+
+                app_window.connect_to (machine);
+            }
+
+            destroy ();
+        } catch (GLib.Error error) {
+            warning (error.message);
+        }
+    }
+}
diff --git a/src/collection-toolbar.vala b/src/collection-toolbar.vala
index 4db11a5f..10fd5b94 100644
--- a/src/collection-toolbar.vala
+++ b/src/collection-toolbar.vala
@@ -65,6 +65,11 @@ private void on_new_vm_btn_clicked () {
         window.set_state (UIState.WIZARD);
     }
 
+    [GtkCallback]
+    private void on_connect_to_remote_btn_clicked () {
+        window.show_remote_connection_assistant ();
+    }
+
     [GtkCallback]
     private void on_back_btn_clicked () {
         window.set_state (UIState.COLLECTION);
diff --git a/src/meson.build b/src/meson.build
index b485c812..5b59c3b8 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -117,6 +117,7 @@ vala_sources = [
   'troubleshoot-log.vala',
   'snapshot-list-row.vala',
   'snapshots-property.vala',
+  'assistant/remote-connection.vala',
 ]
 
 dependencies = [


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