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

📄 main.c

📁 linux下支持P2P的客户端程序,采用了Gnutella的方法,其中有实现Gnutella的具体源码,是一个基于p2p环境下的音乐共享软件,有助于对P2P的研究
💻 C
📖 第 1 页 / 共 2 页
字号:
/*-*-linux-c-*-*//* *  gnewtellium - Newtella for Unix *  Copyright (C) 2001 Elias Athanasopoulos * *  11/07/2001 - Combo box for host cache selection *               added by Kervin. * *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 2 of the License, or *  (at your option) any later version. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program; if not, write to the Free Software *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#include "../config.h"/* Include as backup */#include "../pixmaps/gnewtellium.xpm"/* These includes are needed in the specified   order by the BSD family. It maybe better to   add an #ifdef BSD or something here...*/#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <stdlib.h>#include <unistd.h>#include <netdb.h>#include <signal.h>#include <string.h>#include <gtk/gtk.h>#include "newtella.h"#include "connection.h"#include "gui.h"#include "global.h"#include "guid.h"#include "gnutella.h"#include "config.h"#include "file.h"#include "http.h"#include "hosts.h"extern struct newtella_options *gl_options;gint newtella_idle(gpointer data){	newtella_sched();	return(TRUE);}gint delete(GtkWidget *widget, GtkWidget *event, gpointer data ){    	gtk_main_quit();    	return(FALSE);}int main_init(void){	struct hostent *our_host;	char host_name[255];	IP our_ip;	GList *iter;	/* global initialization */	guidinit();      	signal(SIGPIPE, SIG_IGN);	/* global init */	gl_con         = NULL; 	gl_down_con    = NULL; 	gl_up_con      = NULL;	gl_results     = NULL; 	gl_queries     = NULL;	rmessages      = NULL;		gl_options = newtella_malloc(sizeof(struct newtella_options));	gl_options->shared_dirs = NULL;		/* reset connections */	gl_options->cons      = 0;	gl_options->dcons     = 0;	gl_options->ucons     = 0;	gl_options->connected = 0;        guidget(gl_options->gl_guid);	gl_my_host_info = newtella_malloc(sizeof(struct host_info));		gethostname(host_name, sizeof(host_name));		our_host = gethostbyname(host_name);	if (our_host) {		memcpy(&our_ip, our_host->h_addr, 4); 		gl_my_host_info->ip = ntohl(our_ip.dword);	}		gl_my_host_info->port = 6346;	gl_my_host_info->file_count = 0;	gl_my_host_info->files_total_size = 0;	if (!config_load_from_file())		config_set_default();	host_load_cache_from_file();	config_refresh_main();	/* build our file database */	if (gl_options->shared_dirs) {		iter = g_list_first(gl_options->shared_dirs);		while (iter) {			file_build_db((gchar *) iter->data);			iter = g_list_next(iter);		}	}		return 1;}int main(int argc, char *argv[]){	gtk_init(&argc, &argv);       	draw_main();	main_init();	gtk_timeout_add(1000, newtella_idle, NULL);	gtk_main();		return(0);}gint draw_main(void){	const char *button_names[20] = { "Advanced Configuration",					 "Spread the word",					 "About",					 "Exit Newtella",						 "Start",					 "Clear",					 "Clear all downloads",					 "Add",					 "Reset Connections", 					 "Clear Host Cache",					 "Resume",					 "Stop",					 "Kill",					 "Clear Finished",					 "Resume",					 "Stop",					 "Kill",					 "Clear Finished" };	gchar *search_list_titles[5] = { "File",					 "Size",					 "Speed",					 "Location",					 "Servent" };		gchar *download_list_titles[5] = { "File",					   "Size",					   "Status",					   "Speed",					   "Server" };	gchar *upload_list_titles[5] = { "File",					 "Size",					 "Status",					 "Speed",					 "Downloader" };	gchar *con_list_titles[4] = { "IP",				      "Status",				      "Packets Sent",				      "Packets Received" };					   	GtkWidget *frame;	GtkWidget *label;	GtkWidget *button;	GtkWidget *main_vbox, *frame_vbox;	GtkWidget *nb_vbox_1, *nb_vbox_2, *nb_vbox_3, *nb_vbox_4;	GtkWidget *nb_hbox_1, *nb_hbox_2;	GtkWidget *button_box, *dld_button_box, *uld_button_box, *pixmap_box;	/* GtkWidget *stree; */	GtkWidget *scrolled_window;	GtkAdjustment *adj;	GtkWidget *align;	GtkWidget *table;	GtkWidget *hscale;	GtkWidget *pixmapwid;	GtkWidget *new_list_item;	GdkPixmap *pixmap = NULL;	GdkBitmap *mask;	GtkStyle  *style;	gchar *xpm_path;	gint i;    	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);        	gtk_signal_connect(GTK_OBJECT(window), "delete_event",			   GTK_SIGNAL_FUNC(delete), NULL);    	gtk_container_set_border_width(GTK_CONTAINER(window), 10);	gtk_window_set_title(GTK_WINDOW(window), GNEWTELLIUM);	/* boxes */	main_vbox = gtk_vbox_new(FALSE, 0);	nb_vbox_1 = gtk_vbox_new(FALSE, 0);	nb_vbox_2 = gtk_vbox_new(FALSE, 0);	nb_vbox_3 = gtk_vbox_new(FALSE, 0);	nb_vbox_4 = gtk_vbox_new(FALSE, 0);	frame_vbox = gtk_vbox_new(FALSE, 0);	button_box = gtk_hbox_new(TRUE, 0);	pixmap_box = gtk_hbox_new(TRUE, 0);	dld_button_box = gtk_hbox_new(FALSE, 0);	uld_button_box = gtk_hbox_new(FALSE, 0);	/* main notebook */    	main_notebook = gtk_notebook_new();   	gtk_notebook_set_tab_pos(GTK_NOTEBOOK(main_notebook),				 GTK_POS_TOP);           	/* page 1 */	nb_hbox_1 = gtk_hbox_new(FALSE, 0);	gtk_container_set_border_width(GTK_CONTAINER(nb_hbox_1), 10);	nb_hbox_2 = gtk_hbox_new(FALSE, 0);	search_edit_box = gtk_entry_new_with_max_length(255);	gtk_signal_connect(GTK_OBJECT(search_edit_box), "activate",			   GTK_SIGNAL_FUNC(gui_button_pressed), (gpointer)BTN_STRT_SEARCH);	gtk_widget_show(search_edit_box);	gtk_box_pack_start(GTK_BOX(nb_hbox_1), search_edit_box,			   TRUE, TRUE, 2);	for (i=4; i<6; i++) {		button = gtk_button_new_with_label(button_names[i]);		gtk_box_pack_start(GTK_BOX(nb_hbox_1), button, TRUE, TRUE, 1);		gtk_signal_connect(GTK_OBJECT(button), "clicked",				   GTK_SIGNAL_FUNC(gui_button_pressed), (gpointer)i);		gtk_widget_show(button);	}	label = gtk_label_new("    Files found:");	files_found_label = gtk_label_new("0");	status_label = gtk_label_new("Idle...");		gtk_box_pack_start(GTK_BOX(nb_hbox_2), label, FALSE, FALSE, 3);	gtk_box_pack_start(GTK_BOX(nb_hbox_2), files_found_label,			   FALSE, FALSE, 3);	gtk_box_pack_start(GTK_BOX(nb_hbox_2), status_label,			   FALSE, FALSE, 10);	gtk_widget_show(label);	gtk_widget_show(files_found_label);	gtk_widget_show(status_label);	frame = gtk_frame_new("Results");	gtk_container_set_border_width(GTK_CONTAINER(frame), 10);        scrolled_window = gtk_scrolled_window_new(NULL, NULL);	gtk_widget_set_usize(scrolled_window, 100, 240);	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),				       GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);	gtk_widget_show(scrolled_window);	search_list = gtk_clist_new_with_titles(5, search_list_titles);	gtk_clist_set_column_width(GTK_CLIST(search_list), 0, 240);	gtk_clist_set_column_width(GTK_CLIST(search_list), 1, 60);	gtk_signal_connect(GTK_OBJECT(search_list), "select_row",                           GTK_SIGNAL_FUNC(gui_download_file), NULL);	gtk_container_add(GTK_CONTAINER(scrolled_window), search_list);	gtk_container_add(GTK_CONTAINER(frame), scrolled_window);	gtk_widget_show(search_list);/*	stree = gtk_tree_new();	gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),					      stree);	gtk_container_add(GTK_CONTAINER(frame), scrolled_window);	gtk_widget_show(stree);*/	gtk_widget_show(frame);	gtk_box_pack_start(GTK_BOX(nb_vbox_1), nb_hbox_1, FALSE, FALSE, 5);	gtk_box_pack_start(GTK_BOX(nb_vbox_1), nb_hbox_2, FALSE, FALSE, 1);	gtk_box_pack_start(GTK_BOX(nb_vbox_1), frame, TRUE, TRUE, 1);	label = gtk_label_new("Search");	gtk_widget_show(nb_hbox_1);	gtk_widget_show(nb_hbox_2);	gtk_widget_show(nb_vbox_1);	gtk_notebook_append_page(GTK_NOTEBOOK(main_notebook), nb_vbox_1,				 label);	/* page 1 */	/* page 2 */	nb_hbox_1 = gtk_hbox_new(FALSE, 0);	gtk_container_set_border_width(GTK_CONTAINER(nb_hbox_1), 20);	scrolled_window = gtk_scrolled_window_new(NULL, NULL);	gtk_widget_set_usize(scrolled_window, 100, 200);	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),				       GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);	gtk_widget_show(scrolled_window);	download_list = gtk_clist_new_with_titles(5, download_list_titles);	gtk_clist_set_column_width(GTK_CLIST(download_list), 0, 210);	gtk_clist_set_column_width(GTK_CLIST(download_list), 1,  70);	gtk_clist_set_column_width(GTK_CLIST(download_list), 2,  80);	gtk_clist_set_column_width(GTK_CLIST(download_list), 3,  60);	gtk_clist_set_column_width(GTK_CLIST(download_list), 4, 240);		gtk_container_add(GTK_CONTAINER(scrolled_window), download_list);	gtk_widget_show(download_list);	/* download buttons */	for (i=11; i<15; i++) {		button = gtk_button_new_with_label(button_names[i-1]);		gtk_box_pack_start(GTK_BOX(dld_button_box), button, TRUE, TRUE, 3);		gtk_signal_connect(GTK_OBJECT(button), "clicked", 				   GTK_SIGNAL_FUNC(gui_button_pressed), (gpointer)i);		gtk_widget_show(button);	}	gtk_widget_show(dld_button_box);	/* download buttons */	frame = gtk_frame_new("Limits");	gtk_container_set_border_width(GTK_CONTAINER(frame), 10);

⌨️ 快捷键说明

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