mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-04-20 16:43:20 +03:00
improve
This commit is contained in:
@@ -4,7 +4,7 @@ use adw::prelude::*;
|
|||||||
use adw::subclass::prelude::*;
|
use adw::subclass::prelude::*;
|
||||||
use gtk::glib::{self, Object};
|
use gtk::glib::{self, Object};
|
||||||
|
|
||||||
use lan_mouse_ipc::DEFAULT_PORT;
|
use lan_mouse_ipc::{Position, DEFAULT_PORT};
|
||||||
|
|
||||||
use super::ClientObject;
|
use super::ClientObject;
|
||||||
|
|
||||||
@@ -15,8 +15,14 @@ glib::wrapper! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ClientRow {
|
impl ClientRow {
|
||||||
pub fn new(_client_object: &ClientObject) -> Self {
|
pub fn new(client_object: &ClientObject) -> Self {
|
||||||
Object::builder().build()
|
let client_row: Self = Object::builder().build();
|
||||||
|
client_row
|
||||||
|
.imp()
|
||||||
|
.client_object
|
||||||
|
.borrow_mut()
|
||||||
|
.replace(client_object.clone());
|
||||||
|
client_row
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bind(&self, client_object: &ClientObject) {
|
pub fn bind(&self, client_object: &ClientObject) {
|
||||||
@@ -130,4 +136,20 @@ impl ClientRow {
|
|||||||
binding.unbind();
|
binding.unbind();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_active(&self, active: bool) {
|
||||||
|
self.imp().set_active(active);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_hostname(&self, hostname: &str) {
|
||||||
|
self.imp().set_hostname(hostname);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_port(&self, port: u16) {
|
||||||
|
self.imp().set_port(port);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_position(&self, pos: Position) {
|
||||||
|
self.imp().set_pos(pos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,11 @@ use glib::{subclass::InitializingObject, Binding};
|
|||||||
use gtk::glib::subclass::Signal;
|
use gtk::glib::subclass::Signal;
|
||||||
use gtk::glib::{clone, SignalHandlerId};
|
use gtk::glib::{clone, SignalHandlerId};
|
||||||
use gtk::{glib, Button, CompositeTemplate, Entry, Switch};
|
use gtk::{glib, Button, CompositeTemplate, Entry, Switch};
|
||||||
|
use lan_mouse_ipc::Position;
|
||||||
use std::sync::OnceLock;
|
use std::sync::OnceLock;
|
||||||
|
|
||||||
|
use crate::client_object::ClientObject;
|
||||||
|
|
||||||
#[derive(CompositeTemplate, Default)]
|
#[derive(CompositeTemplate, Default)]
|
||||||
#[template(resource = "/de/feschber/LanMouse/client_row.ui")]
|
#[template(resource = "/de/feschber/LanMouse/client_row.ui")]
|
||||||
pub struct ClientRow {
|
pub struct ClientRow {
|
||||||
@@ -28,10 +31,11 @@ pub struct ClientRow {
|
|||||||
#[template_child]
|
#[template_child]
|
||||||
pub dns_loading_indicator: TemplateChild<gtk::Spinner>,
|
pub dns_loading_indicator: TemplateChild<gtk::Spinner>,
|
||||||
pub bindings: RefCell<Vec<Binding>>,
|
pub bindings: RefCell<Vec<Binding>>,
|
||||||
pub hostname_change_handler: RefCell<Option<SignalHandlerId>>,
|
hostname_change_handler: RefCell<Option<SignalHandlerId>>,
|
||||||
pub port_change_handler: RefCell<Option<SignalHandlerId>>,
|
port_change_handler: RefCell<Option<SignalHandlerId>>,
|
||||||
pub position_change_handler: RefCell<Option<SignalHandlerId>>,
|
position_change_handler: RefCell<Option<SignalHandlerId>>,
|
||||||
pub set_state_handler: RefCell<Option<SignalHandlerId>>,
|
set_state_handler: RefCell<Option<SignalHandlerId>>,
|
||||||
|
pub client_object: RefCell<Option<ClientObject>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[glib::object_subclass]
|
#[glib::object_subclass]
|
||||||
@@ -87,7 +91,6 @@ impl ObjectImpl for ClientRow {
|
|||||||
}
|
}
|
||||||
));
|
));
|
||||||
self.position_change_handler.replace(Some(handler));
|
self.position_change_handler.replace(Some(handler));
|
||||||
// <signal name="state_set" handler="handle_activate_switch" swapped="true"/>
|
|
||||||
let handler = self.enable_switch.connect_state_set(clone!(
|
let handler = self.enable_switch.connect_state_set(clone!(
|
||||||
#[weak(rename_to = row)]
|
#[weak(rename_to = row)]
|
||||||
self,
|
self,
|
||||||
@@ -150,7 +153,6 @@ impl ClientRow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn handle_hostname_changed(&self, hostname_entry: &Entry) {
|
fn handle_hostname_changed(&self, hostname_entry: &Entry) {
|
||||||
log::error!("hostname changed: {}", hostname_entry.text());
|
|
||||||
self.obj()
|
self.obj()
|
||||||
.emit_by_name::<()>("request-hostname-change", &[&hostname_entry.text()]);
|
.emit_by_name::<()>("request-hostname-change", &[&hostname_entry.text()]);
|
||||||
}
|
}
|
||||||
@@ -160,51 +162,55 @@ impl ClientRow {
|
|||||||
.emit_by_name("request-position-change", &[&position.selected()])
|
.emit_by_name("request-position-change", &[&position.selected()])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn block_hostname_change(&self) {
|
pub(super) fn set_hostname(&self, hostname: &str) {
|
||||||
|
let position = self.hostname.position();
|
||||||
let handler = self.hostname_change_handler.borrow();
|
let handler = self.hostname_change_handler.borrow();
|
||||||
let handler = handler.as_ref().expect("signal handler");
|
let handler = handler.as_ref().expect("signal handler");
|
||||||
self.hostname.block_signal(handler);
|
self.hostname.block_signal(handler);
|
||||||
}
|
self.client_object
|
||||||
|
.borrow_mut()
|
||||||
pub fn unblock_hostname_change(&self) {
|
.as_mut()
|
||||||
let handler = self.hostname_change_handler.borrow();
|
.expect("client object")
|
||||||
let handler = handler.as_ref().expect("signal handler");
|
.set_hostname(hostname);
|
||||||
self.hostname.unblock_signal(handler);
|
self.hostname.unblock_signal(handler);
|
||||||
|
self.hostname.set_position(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn block_port_change(&self) {
|
pub(super) fn set_port(&self, port: u16) {
|
||||||
|
let position = self.port.position();
|
||||||
let handler = self.port_change_handler.borrow();
|
let handler = self.port_change_handler.borrow();
|
||||||
let handler = handler.as_ref().expect("signal handler");
|
let handler = handler.as_ref().expect("signal handler");
|
||||||
self.port.block_signal(handler);
|
self.port.block_signal(handler);
|
||||||
}
|
self.client_object
|
||||||
|
.borrow_mut()
|
||||||
pub fn unblock_port_change(&self) {
|
.as_mut()
|
||||||
let handler = self.port_change_handler.borrow();
|
.expect("client object")
|
||||||
let handler = handler.as_ref().expect("signal handler");
|
.set_port(port as u32);
|
||||||
self.port.unblock_signal(handler);
|
self.port.unblock_signal(handler);
|
||||||
|
self.port.set_position(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn block_position_change(&self) {
|
pub(super) fn set_pos(&self, pos: Position) {
|
||||||
let handler = self.position_change_handler.borrow();
|
let handler = self.position_change_handler.borrow();
|
||||||
let handler = handler.as_ref().expect("signal handler");
|
let handler = handler.as_ref().expect("signal handler");
|
||||||
self.position.block_signal(handler);
|
self.position.block_signal(handler);
|
||||||
}
|
self.client_object
|
||||||
|
.borrow_mut()
|
||||||
pub fn unblock_position_change(&self) {
|
.as_mut()
|
||||||
let handler = self.position_change_handler.borrow();
|
.expect("client object")
|
||||||
let handler = handler.as_ref().expect("signal handler");
|
.set_position(pos.to_string());
|
||||||
self.position.unblock_signal(handler);
|
self.position.unblock_signal(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn block_active_switch(&self) {
|
pub(super) fn set_active(&self, active: bool) {
|
||||||
let handler = self.set_state_handler.borrow();
|
let handler = self.set_state_handler.borrow();
|
||||||
let handler = handler.as_ref().expect("signal handler");
|
let handler = handler.as_ref().expect("signal handler");
|
||||||
self.enable_switch.block_signal(handler);
|
self.enable_switch.block_signal(handler);
|
||||||
}
|
self.client_object
|
||||||
|
.borrow_mut()
|
||||||
pub fn unblock_active_switch(&self) {
|
.as_mut()
|
||||||
let handler = self.set_state_handler.borrow();
|
.expect("client object")
|
||||||
let handler = handler.as_ref().expect("signal handler");
|
.set_active(active);
|
||||||
self.enable_switch.unblock_signal(handler);
|
self.enable_switch.unblock_signal(handler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -298,22 +298,9 @@ impl Window {
|
|||||||
log::warn!("could not find row for handle {}", handle);
|
log::warn!("could not find row for handle {}", handle);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let Some(client_object) = self.client_object_for_handle(handle) else {
|
row.set_hostname(&client.hostname.unwrap_or("".into()));
|
||||||
log::warn!("could not find row for handle {}", handle);
|
row.set_port(client.port);
|
||||||
return;
|
row.set_position(client.pos);
|
||||||
};
|
|
||||||
|
|
||||||
row.imp().block_hostname_change();
|
|
||||||
client_object.set_hostname(client.hostname.unwrap_or("".into()));
|
|
||||||
row.imp().unblock_hostname_change();
|
|
||||||
|
|
||||||
row.imp().block_port_change();
|
|
||||||
client_object.set_port(client.port as u32);
|
|
||||||
row.imp().unblock_port_change();
|
|
||||||
|
|
||||||
row.imp().block_position_change();
|
|
||||||
client_object.set_position(client.pos.to_string());
|
|
||||||
row.imp().unblock_position_change();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_client_state(&self, handle: ClientHandle, state: ClientState) {
|
pub fn update_client_state(&self, handle: ClientHandle, state: ClientState) {
|
||||||
@@ -327,18 +314,10 @@ impl Window {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* activation state */
|
/* activation state */
|
||||||
row.imp().block_active_switch();
|
row.set_active(state.active);
|
||||||
client_object.set_active(state.active);
|
|
||||||
row.imp().unblock_active_switch();
|
|
||||||
log::info!("set active to {}", state.active);
|
|
||||||
|
|
||||||
/* dns state */
|
/* dns state */
|
||||||
client_object.set_resolving(state.resolving);
|
client_object.set_resolving(state.resolving);
|
||||||
log::info!(
|
|
||||||
"resolving {}: {}",
|
|
||||||
client_object.get_data().handle,
|
|
||||||
state.resolving
|
|
||||||
);
|
|
||||||
|
|
||||||
self.update_dns_state(handle, !state.ips.is_empty());
|
self.update_dns_state(handle, !state.ips.is_empty());
|
||||||
let ips = state
|
let ips = state
|
||||||
|
|||||||
Reference in New Issue
Block a user