⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gui_engine.c

📁 linux下支持P2P的客户端程序,采用了Gnutella的方法,其中有实现Gnutella的具体源码,是一个基于p2p环境下的音乐共享软件,有助于对P2P的研究
💻 C
📖 第 1 页 / 共 2 页
字号:
}void gui_remove_upload(struct newtella_connection *ucon){	gint row = gtk_clist_find_row_from_data(GTK_CLIST(upload_list), (gpointer) ucon);	gl_options->ucons--;	gtk_clist_remove(GTK_CLIST(upload_list), row);}void gui_reset_cons(void){	GList *iter;	struct newtella_connection *con;	iter = g_list_first(gl_con);	while (iter) {		con = iter->data;				close(con->s);		newtella_free(con);		iter = g_list_next(iter);	}	g_list_free(gl_con);	gtk_clist_clear(GTK_CLIST(con_list));		gl_con                = NULL;	gl_options->cons      = 0;	gl_options->connected = 0;}int gui_reset_host_cache(void){	GList *iter;	char buf[5];	iter = g_list_first(gl_hosts_in_cache);	while (iter) {		newtella_free(iter->data);	       		iter = g_list_next(iter);	}	g_list_free(gl_hosts_in_cache);	gl_options->hosts_in_cache = 0;	gl_hosts_in_cache = NULL;	        /* gui update */	g_snprintf(buf, sizeof(buf), "%d", gl_options->hosts_in_cache);	gtk_label_set_text(GTK_LABEL(host_in_cache_label), buf);		return 1;}void gui_max_con_changed(void){	gl_options->max_con =		gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(max_con));	/* sanity check */	if (gl_options->max_con < gl_options->min_con) {		gl_options->max_con = gl_options->min_con;		gtk_spin_button_set_value(GTK_SPIN_BUTTON(max_con), gl_options->max_con);	}}void gui_min_con_changed(void){	gl_options->min_con =		gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(min_con));        /* sanity check */	if (gl_options->max_con < gl_options->min_con) {		gl_options->min_con = gl_options->max_con;		gtk_spin_button_set_value(GTK_SPIN_BUTTON(min_con), gl_options->min_con);	}}void gui_toggle_auto_connect(GtkToggleButton *toggle, gpointer data){	gl_options->auto_connect = gtk_toggle_button_get_active(toggle);}void gui_toggle_accept_in_con(GtkToggleButton *toggle, gpointer data){	gl_options->accept_in_con = gtk_toggle_button_get_active(toggle);	if (!gl_options->accept_in_con) 		newtella_kill_server();	else {		if (!newtella_init_server(gl_options->newtella_port)) { 			gtk_toggle_button_set_active(toggle, FALSE);		}	} 	}void gui_add_con(void){	guint16 port;	IP ip;	char *t, *l, *s = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(host_combo_box)->entry)));	struct hostent *host;	GList *temp_list;	GtkWidget *new_list_item; 	temp_list = GTK_LIST(GTK_COMBO(host_combo_box)->list)->children;	/* Search the list for the host just added */	while (temp_list && temp_list->data) {		/* Get the string from the label */		gtk_label_get(GTK_LABEL(GTK_BIN(temp_list->data)->child), &l);		if (!l)        		continue;      		if (!g_strcasecmp(l, s))			break;		temp_list = temp_list->next;	}	if (temp_list == NULL)	{		/* The string was not found. 		   Therefore add it to the list		*/		new_list_item = gtk_list_item_new_with_label(s);		gtk_widget_show(new_list_item);		gtk_container_add(GTK_CONTAINER(GTK_COMBO(host_combo_box)->list), new_list_item);	}	if (strchr(s, ':')) {				t = memchr(s, ':', strlen(s));      		*t++ = 0;    		port = atol(t);		host = gethostbyname(s);		if (host != NULL) {			memcpy(&ip, host->h_addr, 4);			con_add(g_htonl(ip.dword), port);		} else			perror("gethostbyname");	}	newtella_free(s);	}void gui_launch_web_site(void){	/* TODO */}void gui_about_gnewtellium(void){	/* a little credit... */	GtkWidget *about_window;	GtkWidget *label;	GtkWidget *button;	GdkPixmap *pixmap;	GtkWidget *pixmapwid;	GdkBitmap *mask;	GtkStyle  *style;	gchar     *xpm_path;			about_window = gtk_dialog_new();	gtk_container_set_border_width(GTK_CONTAINER(about_window), 10);        gtk_window_set_title(GTK_WINDOW(about_window), "About... "GNEWTELLIUM);	xpm_path = strdup(PACKAGE_DATA_DIR"/pixmaps/gnewtellium.xpm");	style = gtk_widget_get_style(window);	pixmap = gdk_pixmap_create_from_xpm(window->window, &mask, &style->white, xpm_path);					   	if (!pixmap)		pixmap = gdk_pixmap_create_from_xpm_d(window->window, &mask,						      &style->white,						      gnewtellium_xpm);			pixmapwid = gtk_pixmap_new(pixmap, mask);	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(about_window)->vbox), pixmapwid, FALSE, FALSE, 10);	gtk_widget_show(pixmapwid);	label = gtk_label_new("gnewtellium - Open Source Newtella for Unix\n"			      "Version: "GNEWTELLIUM" "RELEASE_DATE" \n"			      "Distributed under the GNU General Public License\n\n"			      "Developed by Elias Athanasopoulos\n"                              "(elathan@users.sf.net)\n\n"			      "Credits go to:\n"			      "The Newtella folks for the financial,\n"			      "psychological, technical, etc.-cal support\n"			      "(http://www.newtella.com)\n"			      "Alex, the maintainer of the official web site\n"			      "(avel@users.sf.net)\n"			      "The Gnutella community...\n\n"			      "News/Updates/Anything, please visit the official Web site\n"			      GNEW_WEBSITE"\n\n"			      "Share your love with us!...");       	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(about_window)->vbox), label, FALSE, FALSE, 10);	gtk_widget_show(label);	button = gtk_button_new_with_label("Enough!");	gtk_signal_connect_object (GTK_OBJECT (button), "clicked",				   GTK_SIGNAL_FUNC (gtk_widget_destroy),				   GTK_OBJECT (about_window));    	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(about_window)->vbox), button, FALSE, FALSE, 10);	gtk_widget_show(button);	gtk_widget_show(about_window);}void gui_button_pressed(GtkWidget *widget, gpointer data){	GList *iter;	struct newtella_connection *dcon;	struct newtella_connection *ucon;	struct squery *new_query;	time_t st;	gchar buf[255], *time_str;	gchar *query;	/* main event handler for all buttons */	switch ((int)data) {	case BTN_ADV_CONFIG:		config_draw();		break;	case BTN_STRT_SEARCH:		/* add query to list */		new_query = newtella_malloc(sizeof(struct squery));		query = newtella_malloc(strlen(gtk_entry_get_text(GTK_ENTRY(search_edit_box)))+1);		query = strcpy(query, gtk_entry_get_text(GTK_ENTRY(search_edit_box))); 				new_query->keyword = query;		guidget(new_query->guid);		gl_queries = g_slist_append(gl_queries, new_query);		/* send broadcoast query */		gnutella_send_query(new_query, NULL, 1);				/* gui update */		st = time((time_t *) NULL);		time_str = ctime(&st); time_str[strlen(time_str)-1] = '\0';		g_snprintf(buf, sizeof(buf), "Looking for: %s (%s)", 			   g_strdup(gtk_entry_get_text(GTK_ENTRY(search_edit_box))),			   time_str);		gtk_label_set_text(GTK_LABEL(status_label), buf);		break;	case BTN_SPRD_WORD:		gui_launch_web_site();		break;	case BTN_ADD_CON:		gui_add_con();		break;	case BTN_ABOUT:		gui_about_gnewtellium();		break;	case BTN_CLR_SEARCH:		gui_clean_found_results();		break;	case BTN_RESET_CON:		gui_reset_cons();		break;	case BTN_CLR_HCACHE:		gui_reset_host_cache();		break;	case BTN_EXIT: /* shutdown the application */		/* close the server if it is alive */		if (gl_options->accept_in_con)			newtella_kill_server();		/* shutdown gui */		gtk_widget_destroy(window);		/* save config/hosts */		config_save_to_file();		host_save_cache_to_file();		/* bye... */		gtk_exit(1);		break;	        /* downloads */	case BTN_DLD_START:		iter = GTK_CLIST(download_list)->selection;		if (iter) {						dcon = (struct newtella_connection *)				gtk_clist_get_row_data(GTK_CLIST(download_list),						       (gint) iter->data);			if (dcon->state == GS_RESUME)				break;			if (dcon) 				download_resume(dcon);		}		break;	case BTN_DLD_STOP:		iter = GTK_CLIST(download_list)->selection;		if (iter) {			dcon = (struct newtella_connection *)				gtk_clist_get_row_data(GTK_CLIST(download_list),						       (gint) iter->data);						if (dcon) 				download_stop(dcon, "Stopped by user");					}		break;	case BTN_DLD_KILL:		iter = GTK_CLIST(download_list)->selection; 		if (iter) {			dcon = (struct newtella_connection *)				gtk_clist_get_row_data(GTK_CLIST(download_list),						       (gint) iter->data);						if (dcon)				download_kill(dcon);		}		break;	case BTN_DLD_CLEAR:		iter = g_list_first(gl_down_con);		while (iter) {			dcon = iter->data;						if (dcon->state == GS_FAILED || dcon->state == GS_COMPLETE) {				download_kill(dcon);				iter = g_list_first(gl_down_con);			}			iter = iter->next;		}		break;	/* uploads */	case BTN_ULD_STOP:		iter = GTK_CLIST(upload_list)->selection;		if (iter) {			ucon = (struct newtella_connection *)				gtk_clist_get_row_data(GTK_CLIST(upload_list), 						       (gint) iter->data);			if (ucon) 				upload_stop(ucon);		}		break;	case BTN_ULD_KILL:		iter = GTK_CLIST(upload_list)->selection;		if (iter) {			ucon = (struct newtella_connection *)				gtk_clist_get_row_data(GTK_CLIST(upload_list), 						       (gint) iter->data);			if (ucon) 				upload_kill(ucon);		}		break;	case BTN_ULD_CLEAR:		iter = g_list_first(gl_up_con);		while (iter) {			ucon = iter->data;						if (ucon->state == GS_FAILED || ucon->state == GS_COMPLETE) {				upload_kill(ucon);				iter = g_list_first(gl_up_con);			}			iter = iter->next;		}		break;	default:		break;	}}void gui_download_file(GtkWidget *gtkclist, gint row, gint col, GdkEventButton *event, 		       gpointer gdata){	struct file_found *download_file;	GList *iter;         if (event->type != GDK_2BUTTON_PRESS) 		return;	iter = g_list_nth(gl_results, row);	download_file = iter->data;	download_add(download_file);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -