@@ -6,8 +6,11 @@ use glib::{subclass::InitializingObject, Binding};
6
6
use gtk:: glib:: subclass:: Signal ;
7
7
use gtk:: glib:: { clone, SignalHandlerId } ;
8
8
use gtk:: { glib, Button , CompositeTemplate , Entry , Switch } ;
9
+ use lan_mouse_ipc:: Position ;
9
10
use std:: sync:: OnceLock ;
10
11
12
+ use crate :: client_object:: ClientObject ;
13
+
11
14
#[ derive( CompositeTemplate , Default ) ]
12
15
#[ template( resource = "/de/feschber/LanMouse/client_row.ui" ) ]
13
16
pub struct ClientRow {
@@ -28,10 +31,11 @@ pub struct ClientRow {
28
31
#[ template_child]
29
32
pub dns_loading_indicator : TemplateChild < gtk:: Spinner > ,
30
33
pub bindings : RefCell < Vec < Binding > > ,
31
- pub hostname_change_handler : RefCell < Option < SignalHandlerId > > ,
32
- pub port_change_handler : RefCell < Option < SignalHandlerId > > ,
33
- pub position_change_handler : RefCell < Option < SignalHandlerId > > ,
34
- pub set_state_handler : RefCell < Option < SignalHandlerId > > ,
34
+ hostname_change_handler : RefCell < Option < SignalHandlerId > > ,
35
+ port_change_handler : RefCell < Option < SignalHandlerId > > ,
36
+ position_change_handler : RefCell < Option < SignalHandlerId > > ,
37
+ set_state_handler : RefCell < Option < SignalHandlerId > > ,
38
+ pub client_object : RefCell < Option < ClientObject > > ,
35
39
}
36
40
37
41
#[ glib:: object_subclass]
@@ -87,7 +91,6 @@ impl ObjectImpl for ClientRow {
87
91
}
88
92
) ) ;
89
93
self . position_change_handler . replace ( Some ( handler) ) ;
90
- // <signal name="state_set" handler="handle_activate_switch" swapped="true"/>
91
94
let handler = self . enable_switch . connect_state_set ( clone ! (
92
95
#[ weak( rename_to = row) ]
93
96
self ,
@@ -150,7 +153,6 @@ impl ClientRow {
150
153
}
151
154
152
155
fn handle_hostname_changed ( & self , hostname_entry : & Entry ) {
153
- log:: error!( "hostname changed: {}" , hostname_entry. text( ) ) ;
154
156
self . obj ( )
155
157
. emit_by_name :: < ( ) > ( "request-hostname-change" , & [ & hostname_entry. text ( ) ] ) ;
156
158
}
@@ -160,51 +162,55 @@ impl ClientRow {
160
162
. emit_by_name ( "request-position-change" , & [ & position. selected ( ) ] )
161
163
}
162
164
163
- pub fn block_hostname_change ( & self ) {
165
+ pub ( super ) fn set_hostname ( & self , hostname : & str ) {
166
+ let position = self . hostname . position ( ) ;
164
167
let handler = self . hostname_change_handler . borrow ( ) ;
165
168
let handler = handler. as_ref ( ) . expect ( "signal handler" ) ;
166
169
self . hostname . block_signal ( handler) ;
167
- }
168
-
169
- pub fn unblock_hostname_change ( & self ) {
170
- let handler = self . hostname_change_handler . borrow ( ) ;
171
- let handler = handler . as_ref ( ) . expect ( "signal handler" ) ;
170
+ self . client_object
171
+ . borrow_mut ( )
172
+ . as_mut ( )
173
+ . expect ( "client object" )
174
+ . set_hostname ( hostname ) ;
172
175
self . hostname . unblock_signal ( handler) ;
176
+ self . hostname . set_position ( position) ;
173
177
}
174
178
175
- pub fn block_port_change ( & self ) {
179
+ pub ( super ) fn set_port ( & self , port : u16 ) {
180
+ let position = self . port . position ( ) ;
176
181
let handler = self . port_change_handler . borrow ( ) ;
177
182
let handler = handler. as_ref ( ) . expect ( "signal handler" ) ;
178
183
self . port . block_signal ( handler) ;
179
- }
180
-
181
- pub fn unblock_port_change ( & self ) {
182
- let handler = self . port_change_handler . borrow ( ) ;
183
- let handler = handler . as_ref ( ) . expect ( "signal handler" ) ;
184
+ self . client_object
185
+ . borrow_mut ( )
186
+ . as_mut ( )
187
+ . expect ( "client object" )
188
+ . set_port ( port as u32 ) ;
184
189
self . port . unblock_signal ( handler) ;
190
+ self . port . set_position ( position) ;
185
191
}
186
192
187
- pub fn block_position_change ( & self ) {
193
+ pub ( super ) fn set_pos ( & self , pos : Position ) {
188
194
let handler = self . position_change_handler . borrow ( ) ;
189
195
let handler = handler. as_ref ( ) . expect ( "signal handler" ) ;
190
196
self . position . block_signal ( handler) ;
191
- }
192
-
193
- pub fn unblock_position_change ( & self ) {
194
- let handler = self . position_change_handler . borrow ( ) ;
195
- let handler = handler . as_ref ( ) . expect ( "signal handler" ) ;
197
+ self . client_object
198
+ . borrow_mut ( )
199
+ . as_mut ( )
200
+ . expect ( "client object" )
201
+ . set_position ( pos . to_string ( ) ) ;
196
202
self . position . unblock_signal ( handler) ;
197
203
}
198
204
199
- pub fn block_active_switch ( & self ) {
205
+ pub ( super ) fn set_active ( & self , active : bool ) {
200
206
let handler = self . set_state_handler . borrow ( ) ;
201
207
let handler = handler. as_ref ( ) . expect ( "signal handler" ) ;
202
208
self . enable_switch . block_signal ( handler) ;
203
- }
204
-
205
- pub fn unblock_active_switch ( & self ) {
206
- let handler = self . set_state_handler . borrow ( ) ;
207
- let handler = handler . as_ref ( ) . expect ( "signal handler" ) ;
209
+ self . client_object
210
+ . borrow_mut ( )
211
+ . as_mut ( )
212
+ . expect ( "client object" )
213
+ . set_active ( active ) ;
208
214
self . enable_switch . unblock_signal ( handler) ;
209
215
}
210
216
}
0 commit comments