From 6f8d7e3c1de05145935c266800c3dda825da908a Mon Sep 17 00:00:00 2001 From: Ferdinand Schober Date: Fri, 14 Mar 2025 18:27:09 +0100 Subject: [PATCH] fix hostname / port binding --- lan-mouse-gtk/src/client_object/imp.rs | 2 +- lan-mouse-gtk/src/client_row.rs | 10 ++-------- lan-mouse-gtk/src/client_row/imp.rs | 4 ++-- lan-mouse-gtk/src/window.rs | 2 +- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/lan-mouse-gtk/src/client_object/imp.rs b/lan-mouse-gtk/src/client_object/imp.rs index fbcd5db..016ae8c 100644 --- a/lan-mouse-gtk/src/client_object/imp.rs +++ b/lan-mouse-gtk/src/client_object/imp.rs @@ -13,7 +13,7 @@ use super::ClientData; #[properties(wrapper_type = super::ClientObject)] pub struct ClientObject { #[property(name = "handle", get, set, type = ClientHandle, member = handle)] - #[property(name = "hostname", get, set, type = String, member = hostname)] + #[property(name = "hostname", get, set, type = Option, member = hostname)] #[property(name = "port", get, set, type = u32, member = port, maximum = u16::MAX as u32)] #[property(name = "active", get, set, type = bool, member = active)] #[property(name = "position", get, set, type = String, member = position)] diff --git a/lan-mouse-gtk/src/client_row.rs b/lan-mouse-gtk/src/client_row.rs index 5b99130..4e5bfe7 100644 --- a/lan-mouse-gtk/src/client_row.rs +++ b/lan-mouse-gtk/src/client_row.rs @@ -56,13 +56,7 @@ impl ClientRow { // bind hostname to title let title_binding = client_object .bind_property("hostname", self, "title") - .transform_to(|_, v: Option| { - if let Some(hostname) = v { - Some(hostname) - } else { - Some("no hostname!".to_string()) - } - }) + .transform_to(|_, v: Option| v.or(Some("no hostname!".to_string()))) .sync_create() .build(); @@ -141,7 +135,7 @@ impl ClientRow { self.imp().set_active(active); } - pub fn set_hostname(&self, hostname: &str) { + pub fn set_hostname(&self, hostname: Option) { self.imp().set_hostname(hostname); } diff --git a/lan-mouse-gtk/src/client_row/imp.rs b/lan-mouse-gtk/src/client_row/imp.rs index fb44ed3..fac7a52 100644 --- a/lan-mouse-gtk/src/client_row/imp.rs +++ b/lan-mouse-gtk/src/client_row/imp.rs @@ -162,7 +162,7 @@ impl ClientRow { .emit_by_name("request-position-change", &[&position.selected()]) } - pub(super) fn set_hostname(&self, hostname: &str) { + pub(super) fn set_hostname(&self, hostname: Option) { let position = self.hostname.position(); let handler = self.hostname_change_handler.borrow(); let handler = handler.as_ref().expect("signal handler"); @@ -171,7 +171,7 @@ impl ClientRow { .borrow_mut() .as_mut() .expect("client object") - .set_hostname(hostname); + .set_property("hostname", hostname); self.hostname.unblock_signal(handler); self.hostname.set_position(position); } diff --git a/lan-mouse-gtk/src/window.rs b/lan-mouse-gtk/src/window.rs index 546ba14..c52a77d 100644 --- a/lan-mouse-gtk/src/window.rs +++ b/lan-mouse-gtk/src/window.rs @@ -298,7 +298,7 @@ impl Window { log::warn!("could not find row for handle {}", handle); return; }; - row.set_hostname(&client.hostname.unwrap_or("".into())); + row.set_hostname(client.hostname); row.set_port(client.port); row.set_position(client.pos); }