[connections/decouple-display-name-and-address: 2/2] connection, properties: Untangle display_name and uri




commit 974b9a5527bb15ff74c7f9d32ec7ffe245c8908e
Author: Felipe Borges <felipeborges gnome org>
Date:   Tue May 18 16:08:15 2021 +0200

    connection, properties: Untangle display_name and uri
    
    The fallback value for display_name was the connection uri, which
    gives the impression that changing the display_name allows you to
    also change the connection address, which isn't true.
    
    Fixes #47

 src/collection-view-child.vala | 11 +++++++++--
 src/connection.vala            | 15 +--------------
 src/properties.vala            |  9 +++++----
 3 files changed, 15 insertions(+), 20 deletions(-)
---
diff --git a/src/collection-view-child.vala b/src/collection-view-child.vala
index e2a21ad..b176b41 100644
--- a/src/collection-view-child.vala
+++ b/src/collection-view-child.vala
@@ -33,8 +33,8 @@ namespace Connections {
         public CollectionViewChild (Connection connection) {
             this.connection = connection;
 
-            connection_name.set_text (connection.display_name);
-            connection.bind_property ("display_name", connection_name, "label", BindingFlags.SYNC_CREATE);
+            update_display_name ();
+            connection.notify["display-name"].connect (update_display_name);
 
             connection.thumbnailer.update.connect (() => {
                 thumbnail.set_from_pixbuf (connection.thumbnail.scale_simple (180, 134, 
Gdk.InterpType.BILINEAR));
@@ -43,6 +43,13 @@ namespace Connections {
             update_thumbnail.begin ();
         }
 
+        private void update_display_name () {
+            if (connection.display_name != null && connection.display_name != "")
+                connection_name.set_text (connection.display_name);
+            else
+                connection_name.set_text (connection.uri);
+        }
+
         private async void update_thumbnail () {
             var file = GLib.File.new_for_path (connection.thumbnailer.thumbnail_path);
             if (file.query_exists ()) {
diff --git a/src/connection.vala b/src/connection.vala
index 1d2c5e4..2609a04 100644
--- a/src/connection.vala
+++ b/src/connection.vala
@@ -47,20 +47,7 @@ namespace Connections {
         public string host { get; protected set; }
         public abstract int port { get; protected set; }
         public string protocol { get; protected set; }
-
-        private string _display_name;
-        public string display_name {
-            owned get {
-                if (_display_name != null)
-                    return _display_name;
-
-                return uri;
-            }
-
-            set {
-                _display_name = value;
-            }
-        }
+        public string display_name { get; set; }
 
         public abstract void send_keys (uint[] keys);
 
diff --git a/src/properties.vala b/src/properties.vala
index 1f9457e..c566a3c 100644
--- a/src/properties.vala
+++ b/src/properties.vala
@@ -48,8 +48,10 @@ namespace Connections {
             set_transient_for (Application.application.main_window);
 
             notify["connection"].connect (() => {
-                connection_name_label.set_text (connection.display_name);
-                connection_name_entry.set_text (connection.display_name);
+                if (connection.display_name != null && connection.display_name != "") {
+                    connection_name_label.set_text (connection.display_name);
+                    connection_name_entry.set_text (connection.display_name);
+                }
 
                 host_address_label.set_text (connection.uri);
             });
@@ -115,8 +117,7 @@ namespace Connections {
                 return;
 
             if (connection_name_entry.text == "") {
-                connection.display_name = null;
-                connection_name_label.set_text (connection.uri);
+                connection.display_name = connection_name_label.label = null;
             } else {
                 connection.display_name = connection_name_entry.text;
                 connection_name_label.set_text (connection_name_entry.text);


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