@ -11,8 +11,8 @@ void on_autohostname_check(GtkWidget *, main_window *widgets){
}
}
void on_autohostname_sensitiveness_check ( GtkWidget * , main_window * widgets ) {
if ( gtk_switch_get_active ( GTK_SWITCH ( widgets - > HostnameSensitiveSwitch ) ) ) {
void on_autohostname_sensitiveness_check ( GtkWidget * , int status , main_window * widgets ) {
if ( status ) {
gtk_widget_set_sensitive ( widgets - > AutoHostnameCheck , 1 ) ;
if ( gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON ( widgets - > AutoHostnameCheck ) ) ) {
gtk_widget_set_sensitive ( widgets - > HotnameEntry , 0 ) ;
@ -29,6 +29,21 @@ void on_hostname_entry_changed (GtkWidget *, main_window *widgets){
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( widgets - > AutoHostnameCheck ) , 0 ) ;
}
void on_type_changed ( GtkComboBox * self , network_info * info ) {
gtk_combo_box_text_remove_all ( GTK_COMBO_BOX_TEXT ( info - > ConnectionCombo ) ) ;
gtk_combo_box_text_append_text ( GTK_COMBO_BOX_TEXT ( info - > ConnectionCombo ) , DEFAULT_LABEL ) ;
const char * id = gtk_combo_box_get_active_id ( self ) ;
GHashTable * table = g_hash_table_lookup ( main_config . network_types , id ) ;
if ( table ) {
GList * list = g_hash_table_get_keys ( table ) ;
GList * iter ;
for ( iter = list ; iter ; iter = iter - > next ) {
gtk_combo_box_text_append ( GTK_COMBO_BOX_TEXT ( info - > ConnectionCombo ) , iter - > data , iter - > data ) ;
}
g_list_free ( list ) ;
}
}
network_info * yon_network_info_new ( ) {
network_info * info = new ( network_info ) ;
GtkBuilder * builder = gtk_builder_new_from_resource ( glade_path_network_info ) ;
@ -39,6 +54,7 @@ network_info *yon_network_info_new(){
info - > EnabledSwitch = yon_gtk_builder_get_widget ( builder , " EnabledSwitch " ) ;
info - > RemoveButton = yon_gtk_builder_get_widget ( builder , " RemoveButton " ) ;
info - > AutoGetIPSwitch = yon_gtk_builder_get_widget ( builder , " AutoGetIPSwitch " ) ;
info - > IpRevealer = yon_gtk_builder_get_widget ( builder , " IpRevealer " ) ;
info - > IpAdressEntry = yon_gtk_builder_get_widget ( builder , " IpAdressEntry " ) ;
info - > GatewayEntry = yon_gtk_builder_get_widget ( builder , " GatewayEntry " ) ;
info - > MaskEntry = yon_gtk_builder_get_widget ( builder , " MaskEntry " ) ;
@ -61,7 +77,16 @@ network_info *yon_network_info_new(){
g_signal_connect ( G_OBJECT ( info - > AutoGetIPSwitch ) , " state-set " , G_CALLBACK ( yon_gtk_widget_set_sensitive_from_switch_inversed ) , info - > GatewayEntry ) ;
g_signal_connect ( G_OBJECT ( info - > AutoGetIPSwitch ) , " state-set " , G_CALLBACK ( yon_gtk_widget_set_sensitive_from_switch_inversed ) , info - > MaskEntry ) ;
g_signal_connect ( G_OBJECT ( info - > AutoGetIPSwitch ) , " state-set " , G_CALLBACK ( yon_gtk_widget_set_sensitive_from_switch_inversed ) , info - > DNSEntry ) ;
g_signal_connect ( G_OBJECT ( info - > TypeCombo ) , " changed " , G_CALLBACK ( on_type_changed ) , info ) ;
yon_gtk_revealer_set_from_switch_inversed ( GTK_REVEALER ( info - > IpRevealer ) , GTK_SWITCH ( info - > AutoGetIPSwitch ) ) ;
GList * list = g_hash_table_get_keys ( main_config . network_types ) ;
GList * iter ;
for ( iter = list ; iter ; iter = iter - > next ) {
gtk_combo_box_text_append ( GTK_COMBO_BOX_TEXT ( info - > TypeCombo ) , iter - > data , iter - > data ) ;
}
g_list_free ( list ) ;
gtk_widget_show ( info - > MainBox ) ;
return info ;
@ -190,12 +215,16 @@ int yon_network_save(main_window *widgets){
network_info * info = g_object_get_data ( G_OBJECT ( iter - > data ) , " network_info " ) ;
// char *type = gtk_combo_box_get_active_id(GTK_COMBO_BOX(info->TypeCombo));
char * connection = ( char * ) gtk_entry_get_text ( GTK_ENTRY ( info - > ConnectionEntry ) ) ;
// int active = gtk_switch_get_active(GTK_SWITCH(info->EnabledSwitch));
int active = gtk_switch_get_active ( GTK_SWITCH ( info - > EnabledSwitch ) ) ;
int parameters_size = 0 ;
config_str parameters = NULL ;
if ( ! gtk_switch_get_active ( GTK_SWITCH ( info - > AutoGetIPSwitch ) ) ) {
char * ip = ( char * ) gtk_entry_get_text ( GTK_ENTRY ( info - > IpAdressEntry ) ) ;
char * mask = ( char * ) gtk_entry_get_text ( GTK_ENTRY ( info - > MaskEntry ) ) ;
char * gateway = ( char * ) gtk_entry_get_text ( GTK_ENTRY ( info - > GatewayEntry ) ) ;
char * dns = ( char * ) gtk_entry_get_text ( GTK_ENTRY ( info - > DNSEntry ) ) ;
yon_char_parsed_add_or_create_if_exists ( parameters , & parameters_size , " ipv4.method manual " ) ;
if ( ! yon_ip_check ( ip ) ) {
yon_ubl_status_box_spawn ( GTK_CONTAINER ( widgets - > StatusBox ) , WRONG_IP_LABEL , 5 , BACKGROUND_IMAGE_FAIL_TYPE ) ;
yon_ubl_status_highlight_incorrect ( info - > IpAdressEntry ) ;
@ -205,26 +234,98 @@ int yon_network_save(main_window *widgets){
yon_ubl_status_box_spawn ( GTK_CONTAINER ( widgets - > StatusBox ) , WRONG_IP_LABEL , 5 , BACKGROUND_IMAGE_FAIL_TYPE ) ;
yon_ubl_status_highlight_incorrect ( info - > MaskEntry ) ;
return 0 ;
} else {
int bitmask = yon_ip_mask_get_bits ( mask ) ;
mask = yon_char_from_int ( bitmask ) ;
char * ip_param = yon_char_unite ( " ipv4.addr " , ip , " / " , mask , NULL ) ;
yon_char_parsed_add_or_create_if_exists ( parameters , & parameters_size , ip_param ) ;
free ( ip_param ) ;
}
if ( ! yon_ip_check ( gateway ) ) {
yon_ubl_status_box_spawn ( GTK_CONTAINER ( widgets - > StatusBox ) , WRONG_IP_LABEL , 5 , BACKGROUND_IMAGE_FAIL_TYPE ) ;
yon_ubl_status_highlight_incorrect ( info - > GatewayEntry ) ;
return 0 ;
if ( yon_ip_check ( gateway ) ) {
char * ip_param = yon_char_append ( " ipv4.gateway " , gateway ) ;
yon_ char_parsed_add_or_create_if_exists( parameters , & parameters_size , ip_param ) ;
free ( ip_param ) ;
}
if ( ! yon_ip_check ( dns ) ) {
yon_ubl_status_box_spawn ( GTK_CONTAINER ( widgets - > StatusBox ) , WRONG_IP_LABEL , 5 , BACKGROUND_IMAGE_FAIL_TYPE ) ;
yon_ubl_status_highlight_incorrect ( info - > DNSEntry ) ;
return 0 ;
if ( yon_ip_check ( dns ) ) {
char * ip_param = yon_char_append ( " ipv4.dns " , dns ) ;
yon_char_parsed_add_or_create_if_exists ( parameters , & parameters_size , ip_param ) ;
free ( ip_param ) ;
}
if ( ! active ) {
yon_char_parsed_add_or_create_if_exists ( parameters , & parameters_size , " " ) ;
}
int bitmask = yon_ip_mask_get_bits ( mask ) ;
mask = yon_char_from_int ( bitmask ) ;
char * value = network_value ( ip , mask , gateway , dns ) ;
yon_config_register ( NETWORK_parameter ( connection ) , NETWORK_parameter_command ( connection ) , value ) ;
char * value = yon_char_parsed_to_string ( parameters , parameters_size , " yes " ) ;
yon_config_register ( NETWORK_devdown_parameter ( connection ) , NETWORK_devdown_parameter_command ( connection ) , value ) ;
} else {
yon_config_register ( NETWORK_parameter ( connection ) , NETWORK_parameter_command ( connection ) , network_value_auto ) ;
}
}
return 1 ;
}
}
void yon_network_init ( main_window * widgets ) {
int size ;
config_str network_types = yon_resource_open_file ( network_path , & size ) ;
for ( int i = 1 ; i < size ; i + + ) {
yon_char_remove_last_symbol ( network_types [ i ] , ' \n ' ) ;
int parsed_size ;
config_str parsed = yon_char_parse ( network_types [ i ] , & parsed_size , " ; " ) ;
if ( ! g_hash_table_contains ( main_config . network_types , parsed [ 0 ] ) ) {
GHashTable * table = g_hash_table_new ( g_str_hash , g_str_equal ) ;
g_hash_table_insert ( main_config . network_types , yon_char_new ( parsed [ 0 ] ) , table ) ;
}
g_hash_table_add ( g_hash_table_lookup ( main_config . network_types , parsed [ 0 ] ) , yon_char_new ( parsed [ 1 ] ) ) ;
yon_char_parsed_free ( parsed , parsed_size ) ;
}
yon_char_parsed_free ( network_types , size ) ;
config_str parameters = yon_config_get_all_by_key ( NETWORK_parameter_search , & size ) ;
for ( int i = 0 ; i < size ; i + + ) {
char * parameter = yon_char_new ( parameters [ i ] ) ;
char * parameter_name = yon_char_divide_search ( parameter , " = " , - 1 ) ;
char * key = yon_config_parameter_get_key ( parameter_name ) ;
char * key_type = yon_char_divide_search ( key , " @ " , - 1 ) ;
if ( ! strcmp ( key_type , " connmod " ) ) {
network_info * info = yon_network_info_new ( ) ;
gtk_box_pack_start ( GTK_BOX ( widgets - > NetworkConnectionsBox ) , info - > MainBox , 0 , 0 , 0 ) ;
gtk_widget_show ( info - > MainBox ) ;
int connection_size ;
config_str connection = yon_char_parse ( parameter , & connection_size , " " ) ;
for ( int k = 0 ; k < connection_size ; k + + ) {
if ( ! strcmp ( connection [ k ] , " ipv4.method " ) ) {
gtk_switch_set_active ( GTK_SWITCH ( info - > AutoGetIPSwitch ) , 0 ) ;
} else if ( ! strcmp ( connection [ k ] , " ipv4.addr " ) ) {
char * mask = yon_char_new ( connection [ + + k ] ) ;
char * ip = yon_char_divide_search ( mask , " / " , - 1 ) ;
gtk_entry_set_text ( GTK_ENTRY ( info - > MaskEntry ) , mask ) ;
gtk_entry_set_text ( GTK_ENTRY ( info - > IpAdressEntry ) , ip ) ;
free ( mask ) ;
free ( ip ) ;
} else if ( ! strcmp ( connection [ k ] , " ipv4.gateway " ) ) {
gtk_entry_set_text ( GTK_ENTRY ( info - > GatewayEntry ) , connection [ + + k ] ) ;
} else if ( ! strcmp ( connection [ k ] , " ipv4.dns " ) ) {
gtk_entry_set_text ( GTK_ENTRY ( info - > DNSEntry ) , connection [ + + k ] ) ;
}
}
GList * list = g_hash_table_get_keys ( main_config . network_types ) ;
GList * iter ;
for ( iter = list ; iter ; iter = iter - > next ) {
if ( g_hash_table_contains ( g_hash_table_lookup ( main_config . network_types , ( char * ) iter - > data ) , key ) ) {
gtk_combo_box_set_active_id ( GTK_COMBO_BOX ( info - > TypeCombo ) , ( char * ) iter - > data ) ;
gtk_combo_box_set_active_id ( GTK_COMBO_BOX ( info - > ConnectionCombo ) , key ) ;
break ;
}
}
}
}
}