@@ -3,7 +3,7 @@ use async_channel::Sender;
3
3
use gtk:: {
4
4
glib:: { self , clone} ,
5
5
prelude:: * ,
6
- Align , ButtonsType , DialogFlags , MessageType , Orientation , ResponseType , WindowPosition ,
6
+ Align , ButtonsType , DialogFlags , MessageType , Orientation , ResponseType , Widget , WindowPosition ,
7
7
} ;
8
8
use ipnet:: Ipv4Net ;
9
9
use std:: net:: Ipv4Addr ;
@@ -27,6 +27,18 @@ const CSS_ERROR: &str = r"label {
27
27
}
28
28
" ;
29
29
30
+ fn set_container_visible ( widget : & Widget , flag : bool ) {
31
+ if let Some ( parent) = widget. parent ( ) {
32
+ if let Some ( parent) = parent. parent ( ) {
33
+ if flag {
34
+ parent. show_all ( ) ;
35
+ } else {
36
+ parent. hide ( ) ;
37
+ }
38
+ }
39
+ }
40
+ }
41
+
30
42
struct SettingsDialog {
31
43
params : Arc < TunnelParams > ,
32
44
dialog : gtk:: Dialog ,
@@ -136,6 +148,9 @@ impl MyWidgets {
136
148
}
137
149
138
150
impl SettingsDialog {
151
+ const DEFAULT_WIDTH : i32 = 700 ;
152
+ const DEFAULT_HEIGHT : i32 = 370 ;
153
+
139
154
pub fn new ( params : Arc < TunnelParams > ) -> Self {
140
155
let dialog = gtk:: Dialog :: with_buttons (
141
156
Some ( "VPN settings" ) ,
@@ -148,8 +163,8 @@ impl SettingsDialog {
148
163
] ,
149
164
) ;
150
165
151
- dialog. set_default_width ( 700 ) ;
152
- dialog. set_default_height ( 370 ) ;
166
+ dialog. set_default_width ( Self :: DEFAULT_WIDTH ) ;
167
+ dialog. set_default_height ( Self :: DEFAULT_HEIGHT ) ;
153
168
dialog. set_position ( WindowPosition :: CenterAlways ) ;
154
169
155
170
let server_name = gtk:: Entry :: builder ( ) . text ( & params. server_name ) . hexpand ( true ) . build ( ) ;
@@ -273,14 +288,15 @@ impl SettingsDialog {
273
288
error. style_context ( ) . add_provider ( & provider, 100 ) ;
274
289
275
290
auth_type. connect_active_notify (
276
- clone ! ( @weak auth_type, @weak user_name, @weak password, @weak tunnel_type => move |widget| {
291
+ clone ! ( @weak dialog , @weak auth_type, @weak user_name, @weak password, @weak tunnel_type, @weak cert_path => move |widget| {
277
292
if let Some ( id) = widget. active_id( ) {
278
293
let factors = unsafe { auth_type. data:: <Vec <String >>( & id) . map( |p| p. as_ref( ) ) } ;
279
294
if let Some ( factors) = factors {
280
295
let is_saml = factors. iter( ) . any( |f| f == "identity_provider" ) ;
281
296
let is_cert = factors. iter( ) . any( |f| f == "certificate" ) ;
282
- user_name. set_sensitive( !is_saml && !is_cert) ;
283
- password. set_sensitive( !is_saml && !is_cert) ;
297
+ set_container_visible( user_name. as_ref( ) , !is_saml && !is_cert) ;
298
+ set_container_visible( cert_path. as_ref( ) , is_cert) ;
299
+ dialog. resize( SettingsDialog :: DEFAULT_WIDTH , SettingsDialog :: DEFAULT_HEIGHT ) ;
284
300
if is_saml {
285
301
tunnel_type. set_active( Some ( 0 ) ) ;
286
302
tunnel_type. set_sensitive( false ) ;
@@ -663,21 +679,6 @@ impl SettingsDialog {
663
679
. margin_end ( 16 )
664
680
. build ( ) ;
665
681
666
- let cert_type_box = self . cert_type_box ( ) ;
667
- certs_box. pack_start ( & cert_type_box, false , true , 6 ) ;
668
-
669
- let cert_path = self . form_box ( "Client certificate or driver path (.pem, .pfx/.p12, .so)" ) ;
670
- cert_path. pack_start ( & self . widgets . cert_path , false , true , 0 ) ;
671
- certs_box. pack_start ( & cert_path, false , true , 6 ) ;
672
-
673
- let cert_password = self . form_box ( "PFX password or PKCS11 pin" ) ;
674
- cert_password. pack_start ( & self . widgets . cert_password , false , true , 0 ) ;
675
- certs_box. pack_start ( & cert_password, false , true , 6 ) ;
676
-
677
- let cert_id = self . form_box ( "Hex ID of PKCS11 certificate" ) ;
678
- cert_id. pack_start ( & self . widgets . cert_id , false , true , 0 ) ;
679
- certs_box. pack_start ( & cert_id, false , true , 6 ) ;
680
-
681
682
let ca_cert = self . form_box ( "Server CA root certificates" ) ;
682
683
ca_cert. pack_start ( & self . widgets . ca_cert , false , true , 0 ) ;
683
684
certs_box. pack_start ( & ca_cert, false , true , 6 ) ;
@@ -766,13 +767,53 @@ impl SettingsDialog {
766
767
routing_box
767
768
}
768
769
770
+ fn user_auth_box ( & self ) -> gtk:: Box {
771
+ let user_auth_box = gtk:: Box :: builder ( )
772
+ . orientation ( Orientation :: Vertical )
773
+ . margin ( 0 )
774
+ . margin_start ( 0 )
775
+ . margin_end ( 0 )
776
+ . build ( ) ;
777
+ user_auth_box. pack_start ( & self . user_box ( ) , false , true , 6 ) ;
778
+ user_auth_box. pack_start ( & self . password_box ( ) , false , true , 6 ) ;
779
+
780
+ user_auth_box
781
+ }
782
+
783
+ fn cert_auth_box ( & self ) -> gtk:: Box {
784
+ let certs_box = gtk:: Box :: builder ( )
785
+ . orientation ( Orientation :: Vertical )
786
+ . margin ( 0 )
787
+ . margin_start ( 0 )
788
+ . margin_end ( 0 )
789
+ . build ( ) ;
790
+
791
+ let cert_type_box = self . cert_type_box ( ) ;
792
+ certs_box. pack_start ( & cert_type_box, false , true , 6 ) ;
793
+
794
+ let cert_path = self . form_box ( "Client certificate or driver path (.pem, .pfx/.p12, .so)" ) ;
795
+ cert_path. pack_start ( & self . widgets . cert_path , false , true , 0 ) ;
796
+ certs_box. pack_start ( & cert_path, false , true , 6 ) ;
797
+
798
+ let cert_password = self . form_box ( "PFX password or PKCS11 pin" ) ;
799
+ cert_password. pack_start ( & self . widgets . cert_password , false , true , 0 ) ;
800
+ certs_box. pack_start ( & cert_password, false , true , 6 ) ;
801
+
802
+ let cert_id = self . form_box ( "Hex ID of PKCS11 certificate" ) ;
803
+ cert_id. pack_start ( & self . widgets . cert_id , false , true , 0 ) ;
804
+ certs_box. pack_start ( & cert_id, false , true , 6 ) ;
805
+
806
+ certs_box
807
+ }
808
+
769
809
fn general_tab ( & self ) -> gtk:: Box {
770
810
let tab = gtk:: Box :: builder ( ) . orientation ( Orientation :: Vertical ) . margin ( 6 ) . build ( ) ;
771
811
tab. pack_start ( & self . server_box ( ) , false , true , 6 ) ;
772
812
tab. pack_start ( & self . auth_box ( ) , false , true , 6 ) ;
773
813
tab. pack_start ( & self . tunnel_box ( ) , false , true , 6 ) ;
774
- tab. pack_start ( & self . user_box ( ) , false , true , 6 ) ;
775
- tab. pack_start ( & self . password_box ( ) , false , true , 6 ) ;
814
+ tab. show_all ( ) ;
815
+ tab. pack_start ( & self . user_auth_box ( ) , false , true , 6 ) ;
816
+ tab. pack_start ( & self . cert_auth_box ( ) , false , true , 6 ) ;
776
817
tab
777
818
}
778
819
@@ -800,6 +841,7 @@ impl SettingsDialog {
800
841
801
842
let scrolled_win = gtk:: ScrolledWindow :: builder ( ) . build ( ) ;
802
843
scrolled_win. add ( & viewport) ;
844
+ scrolled_win. show_all ( ) ;
803
845
scrolled_win
804
846
}
805
847
@@ -812,7 +854,7 @@ impl SettingsDialog {
812
854
notebook. append_page ( & self . general_tab ( ) , Some ( & gtk:: Label :: new ( Some ( "General" ) ) ) ) ;
813
855
notebook. append_page ( & self . advanced_tab ( ) , Some ( & gtk:: Label :: new ( Some ( "Advanced" ) ) ) ) ;
814
856
815
- notebook. show_all ( ) ;
857
+ notebook. show ( ) ;
816
858
}
817
859
}
818
860
0 commit comments