📄 interface.c
字号:
//gtk_clist_set_selection_mode(GTK_CLIST (route_list), GTK_SELECTION_NONE); /* no selections */ /* *The routes stats frame */ route_stats_frame = gtk_frame_new ("Stats:"); gtk_widget_ref (route_stats_frame); gtk_object_set_data_full (GTK_OBJECT (main_window), "route_stats_frame", route_stats_frame, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (route_stats_frame); //gtk_container_add (GTK_CONTAINER (notebook1), route_frame); gtk_box_pack_start (GTK_BOX (route_hbox1), route_stats_frame, TRUE, TRUE, 1); /* *The "routes" notebook */ label_routes = gtk_label_new ("Routes"); gtk_widget_ref (label_routes); gtk_object_set_data_full (GTK_OBJECT (main_window), "label_routes", label_routes, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (label_routes); gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook1), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook1), 2), label_routes); empty1 = gtk_vbox_new (FALSE, 0); gtk_widget_show (empty1); gtk_container_add (GTK_CONTAINER (notebook1), empty1); /* *The "traffic" notebook */ traffic_label = gtk_label_new ("Traffic"); gtk_widget_ref (traffic_label); gtk_object_set_data_full (GTK_OBJECT (main_window), "traffic_label", traffic_label, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (traffic_label); gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook1), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook1), 3), traffic_label); /* *The settings hbox */ settings_hbox1 = gtk_hbox_new (FALSE, 0); gtk_widget_ref (settings_hbox1); gtk_object_set_data_full (GTK_OBJECT (main_window), "settings_hbox1", settings_hbox1, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (settings_hbox1); //gtk_box_pack_start (GTK_BOX (hbox1), vbox1, TRUE, TRUE, 1); gtk_container_add (GTK_CONTAINER (notebook1), settings_hbox1); /* *The settings-info label field */ info_label = gtk_label_new(NULL); gtk_widget_ref (info_label); gtk_misc_set_alignment((GtkMisc *)info_label, 0, 0); //gtk_label_set_justify((GtkLabel *)net_label,GTK_JUSTIFY_LEFT); gtk_object_set_data_full (GTK_OBJECT (main_window), "info_label", info_label, (GtkDestroyNotify) gtk_widget_unref); //set_net_info("Not connected..."); gtk_widget_show (info_label); gtk_box_pack_start (GTK_BOX (settings_hbox1), info_label, TRUE, TRUE, 0); /* *The "settings" notebook */ settings_label = gtk_label_new ("Settings"); gtk_widget_ref (settings_label); gtk_object_set_data_full (GTK_OBJECT (main_window), "settings_label", settings_label, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (settings_label); gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook1), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook1), 4), settings_label); /* *The "about" hbox */ about_hbox1 = gtk_hbox_new (FALSE, 0); gtk_widget_ref (about_hbox1); gtk_object_set_data_full (GTK_OBJECT (main_window), "about_hbox1", about_hbox1, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (about_hbox1); //gtk_box_pack_start (GTK_BOX (hbox1), vbox1, TRUE, TRUE, 1); gtk_container_add (GTK_CONTAINER (notebook1), about_hbox1); gtk_container_set_border_width (GTK_CONTAINER (about_hbox1), 10); /* *The about label field */ about_label = gtk_label_new(NULL); gtk_widget_ref (about_label); gtk_misc_set_alignment((GtkMisc *)about_label, 0, 0); gtk_label_set_justify((GtkLabel *)about_label,GTK_JUSTIFY_CENTER); gtk_object_set_data_full (GTK_OBJECT (main_window), "about_label", about_label, (GtkDestroyNotify) gtk_widget_unref); //set_net_info("Not connected..."); gtk_widget_show (about_label); gtk_box_pack_start (GTK_BOX (about_hbox1), unik_logo, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (about_hbox1), about_label, TRUE, TRUE, 0); gtk_widget_show (unik_logo); gtk_label_set_text((GtkLabel *)about_label, "OLSRD-GUI by Andreas Tonnesen (andreto@ifi.uio.no)"); /* *The "about" notebook */ label3 = gtk_label_new ("About"); gtk_widget_ref (label3); gtk_object_set_data_full (GTK_OBJECT (main_window), "About", label3, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (label3); gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook1), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook1), 5), label3); return main_window;}/* *Add a node to the node list */voidroute_list_add(char *dest, char *gw, char *metric, char *dev){ gchar *tmp[4] = {dest, gw, dev, metric}; route_list_size++; gtk_clist_freeze(GTK_CLIST(route_list)); gtk_clist_append(GTK_CLIST(route_list), tmp); gtk_clist_thaw(GTK_CLIST(route_list));}/* *Update the entyr with IP 'addr' */voidroute_list_update(char *addr){}/* *Delete a node from the node list */introute_list_del(char *dest){ int i = 0; char *ip; gtk_clist_freeze(GTK_CLIST(route_list)); for(i = 0; i < route_list_size; i++) { gtk_clist_get_text(GTK_CLIST(route_list), i, 0, (gchar **) &ip); if(strcmp(dest, ip) == 0) { //printf("Found %d\n", i); gtk_clist_remove(GTK_CLIST(route_list), i); route_list_size--; gtk_clist_thaw(GTK_CLIST(route_list)); return 1; } } gtk_clist_thaw(GTK_CLIST(route_list)); return 0; }/* *Remove a node from the list */intremove_nodes_list(union olsr_ip_addr *node){ char *ip; char *in_ip = ip_to_string(node); int i; for(i = 0; i < node_list_size; i++) { gtk_clist_get_text(GTK_CLIST(node_list), i, 0, (gchar **) &ip); if(strcmp(in_ip, ip) == 0) { //printf("Found entry!\n"); gtk_clist_remove(GTK_CLIST(node_list), i); node_list_size--; return 1; } } return 0;}/* *If the node passed as a parameter exists then *update it. If not add it to the list */voidupdate_nodes_list(struct node *node){ int i = 0; char *ip; int found = 0; char *dest; char *tmp[9] = {"","","","","","","","",""}; char timer[20]; struct tm *time_st; char itoa_buf[10]; if(memcmp(&node->addr, &main_addr, ipsize) == 0) dest = "local"; else dest = ip_to_string(&node->addr); gtk_clist_freeze(GTK_CLIST(node_list)); while((i < node_list_size) && !found) { gtk_clist_get_text(GTK_CLIST(node_list), i, 0, (gchar **) &ip); if(strcmp(dest, ip) == 0) found = 1; i++; } /* Update node */ if(found) { i--; /* Go backt to the right row */ //printf("Updating %s\n\n", ip_to_string(&node->addr)); /* don't update main addr */ /* Gateway */ if(memcmp(&node->addr, &main_addr, ipsize) != 0) { if(memcmp(&node->gw_addr, &null_addr, ipsize) != 0) gtk_clist_set_text(GTK_CLIST(node_list), i, 1, ip_to_string(&node->gw_addr)); /* Weigth */ if(node->hopcount != 0) { gui_itoa(node->hopcount, itoa_buf); gtk_clist_set_text(GTK_CLIST(node_list), i, 2, itoa_buf); } /* Device */ gtk_clist_set_text(GTK_CLIST(node_list), i, 3, &node->dev[0]); } /* Timer */ if(node->timer.tv_usec) { memset(&timer[0], 0, 20); time_st = localtime((time_t *)&node->timer.tv_sec); sprintf(&timer[0], "%02d:%02d:%02d", time_st->tm_hour, time_st->tm_min, time_st->tm_sec); gtk_clist_set_text(GTK_CLIST(node_list), i, 4, &timer[0]); } /* MID */ if(node->mid.next != &node->mid) gtk_clist_set_text(GTK_CLIST(node_list), i, 5, "yes"); else gtk_clist_set_text(GTK_CLIST(node_list), i, 5, "no"); /* HNA */ if(node->hna.next != &node->hna) gtk_clist_set_text(GTK_CLIST(node_list), i, 6, "yes"); else gtk_clist_set_text(GTK_CLIST(node_list), i, 6, "no"); } /* Add new node */ else { i = node_list_size; /* Create entry */ gtk_clist_insert(GTK_CLIST(node_list), i, tmp); /* Main address */ gtk_clist_set_text(GTK_CLIST(node_list), i, 0, dest); if(memcmp(&node->addr, &main_addr, ipsize) == 0) { if(memcmp(&node->gw_addr, &null_addr, ipsize) != 0) gtk_clist_set_text(GTK_CLIST(node_list), i, 1, ip_to_string(&node->gw_addr)); /* Weigth */ if(node->hopcount != 0) { gui_itoa(node->hopcount, itoa_buf); gtk_clist_set_text(GTK_CLIST(node_list), i, 2, itoa_buf); } /* Device */ gtk_clist_set_text(GTK_CLIST(node_list), i, 3, &node->dev[0]); } /* MID */ if(node->mid.next != &node->mid) gtk_clist_set_text(GTK_CLIST(node_list), i, 5, "yes"); else gtk_clist_set_text(GTK_CLIST(node_list), i, 5, "no"); /* HNA */ if(node->hna.next != &node->hna) gtk_clist_set_text(GTK_CLIST(node_list), i, 6, "yes"); else gtk_clist_set_text(GTK_CLIST(node_list), i, 6, "no"); node_list_size++; } gtk_clist_thaw(GTK_CLIST(node_list));}/* *Add a packet to the packet list */voidpacket_list_add(char *type, char *from, char *length){ gchar *nfo[3] = {type, from, length}; //if(!freeze_packets) //{ if(packet_list_size >= MAXPACKS) gtk_clist_remove(GTK_CLIST(packet_list), MAXPACKS-1); else packet_list_size++; gtk_clist_prepend(GTK_CLIST(packet_list), nfo ); //}}voidset_net_info(gchar *info, int disp_button){ gchar title[255]; memset(&title[0], 0, 255); gtk_label_set_text((GtkLabel *)info_label, info); gtk_label_set_text((GtkLabel *)net_label, "Connected"); strcat(title, olsrd_version); strcat(title, " - "); strcat(title, ip_to_string(&main_addr)); gtk_window_set_title (GTK_WINDOW (main_window), title); if(disp_button) gtk_widget_show(connect_button); else gtk_widget_hide(connect_button);}voidset_net_info_offline(){ gtk_label_set_text((GtkLabel *)net_label, "Connection refused..."); gtk_widget_show(connect_button);}voidset_net_info_connecting(){ gtk_label_set_text((GtkLabel *)net_label, "Connecting..."); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -