problem with GtkTreeView!



I have a problem with the use of GtkTreeView ,just want to add some data to the GtkTreeView but failed.Attach is the source code and the makefile,please help me!
#include<stdio.h>
#include<dirent.h>
#include<stdlib.h>
#include<string.h>
#include<sys/stat.h>
#include<gtk/gtk.h>
#include<glade/glade.h>

const char *column_headers[15] = {"ID","Item Name","Address","<->","Size","Progress","Local","Remote","Start Time","Finished Time","Elapsed","Left","Speed","Multi-part","Status"};
const char *column_headers_local[3] = {"Name","Size","Type"};
const char *column_headers_remote[8] = {"Name","Size","Type","Modified","Attributes","Description","Owner"," "};

static gint destroy_event(GtkWidget *widget,GdkEvent *event,gpointer data)
{	
	g_printf("destroy event occurred!\n");
	gtk_main_quit();
	return TRUE;
}

int main(int argc,char *argv[])
{
	int i;
	gint result;
	struct dirent *direntp;
	DIR *dirp;
	GladeXML *xml;
	GtkWidget *MainFrame;
	GtkComboBoxEntry *comboboxentry;
	GtkCombo *combo;
	GtkTreeView *task_list_tree,*local_directory_tree,*site_manage_tree,*remote_directory_tree;
	GtkCellRenderer *renderer;
	GtkTreeViewColumn *column;
	GtkTreeModel *model;	
	GtkTreeIter iter;
	/*GtkListStore*/GtkTreeStore *local_list_store,*site_manage_list_store,*remote_list_store,*task_list_store;
	
	gtk_init(&argc,&argv);
	xml = glade_xml_new("glade/glade.glade",NULL,NULL);
	g_assert(xml != NULL);
//	glade_xml_signal_autoconnect(xml);

	/*the following codes to extract the Widgets described in the XML*/
	MainFrame = glade_xml_get_widget(xml,"MainFrame");
	task_list_tree = (GtkTreeView *)glade_xml_get_widget(xml,"task_list_tree");
	local_directory_tree = (GtkTreeView *)glade_xml_get_widget(xml,"local_directory_tree");
	site_manage_tree = (GtkTreeView *)glade_xml_get_widget(xml,"site_manage_tree");
	remote_directory_tree = (GtkTreeView *)glade_xml_get_widget(xml,"remote_directory_tree");
	combo = (GtkCombo *)glade_xml_get_widget(xml,"combo");
	
	g_assert(MainFrame != NULL);
	g_assert(task_list_tree != NULL);
	g_assert(local_directory_tree != NULL);
	g_assert(site_manage_tree != NULL);
	g_assert(combo != NULL);
	/*extracting ends*/
	
	/*following codes to set widgets' attributions*/	
	enum {TEXT_COLUMN};
//	local_list_store = gtk_list_store_new(3,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING);
	local_list_store = gtk_tree_store_new(3,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING);
	
	g_assert(local_list_store != NULL);
	/**********************************************************************************
	GList *glist;
	glist = g_list_append(glist,"/");
	if( (dirp = opendir("/")) == NULL)
		perror("Fail to open root directory!");
	else{
		char temp_path[100];
		struct stat statbuf;
		memset(temp_path,0,100);

		while( (direntp=readdir(dirp)) != NULL){
			glist = g_list_append(glist,direntp->d_name);
			sprintf(temp_path,"/%s",direntp->d_name);
//			printf("%s\n",temp_path);
			if(stat(temp_path,&statbuf) == -1)
				perror("fail to access directory!");
			else{
				gtk_list_store_append(local_list_store,&iter);
				if(S_ISDIR(statbuf.st_mode))
					gtk_list_store_set(local_list_store,&iter,0,direntp->d_name,1,"",2,"æ??件夹",-1);
				else
					gtk_list_store_set(local_list_store,&iter,0,direntp->d_name,1,"1M",2,"æ??件",-1);
			}		
		}
	}
	gtk_combo_set_popdown_strings(combo, glist);
	**********************************************************************************/
	
	model = GTK_TREE_MODEL(local_list_store);
	gtk_tree_view_set_model(task_list_tree,model);		
	gtk_tree_view_set_model(remote_directory_tree,model);
	gtk_tree_view_set_model(GTK_TREE_VIEW(local_directory_tree),GTK_TREE_MODEL(local_list_store));
//	renderer = gtk_cell_renderer_text_new();
	
	for(i = 1;i <= 15;i++){
		renderer = gtk_cell_renderer_text_new();
		column = gtk_tree_view_column_new_with_attributes(column_headers[i-1],renderer,/*"text",TEXT_COLUMN,*/NULL);
		gtk_tree_view_append_column(task_list_tree, column);
		gtk_tree_view_column_set_expand(column,TRUE);
	}
	printf("***********************************************\n");
	for(i = 1;i <= 3;i++){		
		renderer = gtk_cell_renderer_text_new();
		column = gtk_tree_view_column_new_with_attributes(column_headers_local[i-1],renderer,NULL);
//		column = gtk_tree_view_column_new();
		gtk_tree_view_append_column(local_directory_tree, column);
		gtk_tree_view_column_set_expand(column,TRUE);		
//		if( i == 1)
//			gtk_tree_view_column_pack_start(column,renderer,TRUE);
			
//		gtk_tree_view_column_set_attributes(column, renderer, column_headers_local[i-1], i-1, NULL);
	}
	printf("***********************************************\n");
	for(i = 1;i <= 8;i++){
		renderer = gtk_cell_renderer_text_new();
		column = gtk_tree_view_column_new_with_attributes(column_headers_remote[i-1],renderer,NULL);
		gtk_tree_view_append_column(remote_directory_tree, column);
		gtk_tree_view_column_set_expand(column,TRUE);
	}
	gtk_tree_view_columns_autosize(task_list_tree);
	gtk_tree_view_columns_autosize(local_directory_tree);
	gtk_tree_view_columns_autosize(remote_directory_tree);
	
	gtk_tree_view_set_headers_visible(task_list_tree,TRUE);
	gtk_tree_view_set_headers_clickable(task_list_tree,TRUE);
	
//	column = gtk_tree_view_column_new();
// 	gtk_tree_view_append_column(GTK_TREE_VIEW(local_directory_tree), column);
 	 
	gtk_tree_view_set_model(GTK_TREE_VIEW(local_directory_tree),GTK_TREE_MODEL(local_list_store));
	GList *glist;
	glist = g_list_append(glist,"/");
	if( (dirp = opendir("/")) == NULL)
		perror("Fail to open root directory!");
	else{
		char temp_path[100];
		struct stat statbuf;
		memset(temp_path,0,100);

		while( (direntp=readdir(dirp)) != NULL){
			glist = g_list_append(glist,direntp->d_name);
			sprintf(temp_path,"/%s",direntp->d_name);
			if(stat(temp_path,&statbuf) == -1)
				perror("fail to access directory!");
			else{
//				gtk_list_store_append(local_list_store,&iter);
				gtk_tree_store_append(local_list_store,&iter,NULL);
				if(S_ISDIR(statbuf.st_mode))
//					gtk_list_store_set(local_list_store,&iter,0,direntp->d_name/*,1," ",2,"æ??件夹"*/,-1);
					gtk_tree_store_set(local_list_store,&iter,0,direntp->d_name,1," ",2,"æ??件夹",-1);
				else
//					gtk_list_store_set(local_list_store,&iter,0,direntp->d_name/*,1,"1M",2,"æ??件"*/,-1);
					gtk_tree_store_set(local_list_store,&iter,0,direntp->d_name,1,"1M",2,"æ??件",-1);
				printf("add a new row!\n");
			}		
		}
	}
	gtk_combo_set_popdown_strings(combo, glist);
	/*set attribution ends*/
	
	g_signal_connect(G_OBJECT(MainFrame),"destroy",G_CALLBACK(destroy_event),NULL);
	
	gtk_widget_show((GtkWidget *)local_directory_tree);
	gtk_widget_show_all(MainFrame);
	gtk_main();
	return 0;
}
CC = gcc
ftp_client:ftp_client.c
	$(CC) `pkg-config --cflags --libs gtk+-2.0` -I/usr/include/libglade-2.0 -lglade-2.0 -ggdb ftp_client.c -o ftp_client
all:ftp_client
clean:
	rm -f *.o temp


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]