[connections/gnome-41-improve-scheme-port-parsing] assistant: Improve the parsing of incomplete addresses




commit 402b0c6cf4ca239c11e2256d1cf8b80f848855a6
Author: Felipe Borges <felipeborges gnome org>
Date:   Tue Oct 5 10:56:31 2021 +0200

    assistant: Improve the parsing of incomplete addresses
    
    We do an effort to accept "incomplete" addresses by pre-setting
    the protocol (scheme). Our existing logic was failing to parse
    some valid addresses, such as an IP address with an specified port
    without a protocol prefix.
    
    Fixes #76

 src/assistant.vala  | 19 +++++++++++++------
 src/ui/assistant.ui |  2 ++
 2 files changed, 15 insertions(+), 6 deletions(-)
---
diff --git a/src/assistant.vala b/src/assistant.vala
index d8b8cf7..b4e5e71 100644
--- a/src/assistant.vala
+++ b/src/assistant.vala
@@ -32,7 +32,7 @@ namespace Connections {
         private unowned Gtk.RadioButton vnc_radio_button;
 
         private bool uri_has_supported_scheme (string uri) {
-            return uri.has_prefix ("rdp") || uri.has_prefix ("vnc");
+            return uri.has_prefix ("rdp://") || uri.has_prefix ("vnc://");
         }
 
         [GtkCallback]
@@ -43,20 +43,27 @@ namespace Connections {
                 return;
             }
 
-            var uri = Xml.URI.parse (url_entry.text);
+            var address = url_entry.text;
+            if (!uri_has_supported_scheme (address)) {
+                if (rdp_radio_button.get_active ())
+                    address = "rdp://" + address;
+                else
+                    address = "vnc://" + address;
+            }
+
+            debug ("Attempting to add \"%s\"", address);
+            var uri = Xml.URI.parse (address);
             if (uri == null) {
                 create_button.sensitive = false;
 
+                debug ("Address \"%s\" is invalid", address);
+
                 return;
             }
 
             rdp_radio_button.set_active (uri.scheme == "rdp");
             vnc_radio_button.set_active (uri.scheme == "vnc");
 
-            if (!uri_has_supported_scheme (url_entry.text)) {
-                uri.server = url_entry.text;
-            }
-
             create_button.sensitive = uri.server != null;
         }
 
diff --git a/src/ui/assistant.ui b/src/ui/assistant.ui
index 19d0a5d..a6a25eb 100644
--- a/src/ui/assistant.ui
+++ b/src/ui/assistant.ui
@@ -61,6 +61,7 @@
                 <object class="GtkRadioButton" id="rdp_radio_button">
                   <property name="visible">True</property>
                   <property name="label" translatable="yes">RDP (standard for connecting to 
Windows)</property>
+                  <signal name="toggled" handler="on_url_entry_changed"/>
                 </object>
               </child>
 
@@ -69,6 +70,7 @@
                   <property name="visible">True</property>
                   <property name="group">rdp_radio_button</property>
                   <property name="label" translatable="yes">VNC (standard for connecting to Linux)</property>
+                  <signal name="toggled" handler="on_url_entry_changed"/>
                 </object>
               </child>
             </object>


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