static void add_routes_section (CEPageIP4 *page) { GtkWidget *widget; GtkWidget *frame; GtkWidget *list; gint i; widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "routes_section")); frame = gtk_frame_new (NULL); gtk_container_add (GTK_CONTAINER (widget), frame); page->routes_list = list = gtk_list_box_new (); gtk_list_box_set_selection_mode (GTK_LIST_BOX (list), GTK_SELECTION_NONE); gtk_list_box_set_header_func (GTK_LIST_BOX (list), cc_list_box_update_header_func, NULL, NULL); gtk_list_box_set_sort_func (GTK_LIST_BOX (list), (GtkListBoxSortFunc)sort_first_last, NULL, NULL); gtk_container_add (GTK_CONTAINER (frame), list); page->auto_routes = GTK_SWITCH (gtk_builder_get_object (CE_PAGE (page)->builder, "auto_routes_switch")); gtk_switch_set_active (page->auto_routes, !nm_setting_ip4_config_get_ignore_auto_routes (page->setting)); g_signal_connect (page->auto_routes, "notify::active", G_CALLBACK (switch_toggled), page); add_section_toolbar (page, widget, G_CALLBACK (add_empty_route_row)); for (i = 0; i < nm_setting_ip4_config_get_num_routes (page->setting); i++) { NMIP4Route *route; struct in_addr tmp_addr; gchar address[INET_ADDRSTRLEN + 1]; gchar netmask[INET_ADDRSTRLEN + 1]; gchar gateway[INET_ADDRSTRLEN + 1]; gint metric; route = nm_setting_ip4_config_get_route (page->setting, i); if (!route) continue; tmp_addr.s_addr = nm_ip4_route_get_dest (route); (void) inet_ntop (AF_INET, &tmp_addr, &address[0], sizeof (address)); tmp_addr.s_addr = nm_utils_ip4_prefix_to_netmask (nm_ip4_route_get_prefix (route)); (void) inet_ntop (AF_INET, &tmp_addr, &netmask[0], sizeof (netmask)); tmp_addr.s_addr = nm_ip4_route_get_next_hop (route); (void) inet_ntop (AF_INET, &tmp_addr, &gateway[0], sizeof (gateway)); metric = nm_ip4_route_get_metric (route); add_route_row (page, address, netmask, gateway, metric); } if (nm_setting_ip4_config_get_num_routes (page->setting) == 0) add_empty_route_row (page); gtk_widget_show_all (widget); }
static void add_empty_route_row (CEPageIP6 *page) { add_route_row (page, "", 0, "", 0); }