[Xfce4-commits] r23239 - in xarchiver/branches/xarchiver-psybsd: libxarchiver src

Stephan Arts stephan at xfce.org
Fri Sep 29 15:56:43 UTC 2006


Author: stephan
Date: 2006-09-29 15:56:41 +0000 (Fri, 29 Sep 2006)
New Revision: 23239

Modified:
   xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.c
   xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.h
   xarchiver/branches/xarchiver-psybsd/src/main_window.c
Log:
Fixed speed


Modified: xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.c
===================================================================
--- xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.c	2006-09-29 08:50:15 UTC (rev 23238)
+++ xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.c	2006-09-29 15:56:41 UTC (rev 23239)
@@ -43,6 +43,8 @@
 
 void
 lxa_archive_free_entry(LXAEntry *entry, LXAArchive *archive);
+gint
+lxa_archive_lookup_tree_dir(gpointer key, gconstpointer filename);
 
 static gint lxa_archive_signals[1];
 
@@ -95,6 +97,7 @@
 lxa_archive_init(LXAArchive *archive)
 {
 		archive->root_entry.filename = g_strdup("/");
+		archive->root_entry.children = g_tree_new((GCompareFunc)lxa_archive_lookup_tree_dir);
 }
 
 static void
@@ -175,27 +178,26 @@
 lxa_archive_add_file(LXAArchive *archive, gchar *path)
 {
 	gint i = 0;
-	GSList *tmp_list;
-	GSList *tmp_list_children;
 	gchar **path_items;
-	LXAEntry *tmp_entry = NULL;
+	LXAEntry *tmp_entry = NULL, *parent = NULL;
 	path_items = g_strsplit_set(path, "/\n", -1);
-	tmp_list = g_slist_find_custom(archive->root_entry.children, path_items[0], (GCompareFunc)lxa_archive_lookup_dir);
-	if(!tmp_list)
+	tmp_entry = g_tree_lookup(archive->root_entry.children, path_items[0]);
+	if(!tmp_entry)
 	{
-		tmp_entry = g_new0(LXAEntry, 1);
+		tmp_entry= g_new0(LXAEntry, 1);
 		tmp_entry->filename = g_strdup(path_items[0]);
 		if(path[strlen(path)-1] == '/')
 			tmp_entry->is_folder = TRUE;
 		else
 			tmp_entry->is_folder = FALSE;
-		archive->root_entry.children = g_slist_prepend(archive->root_entry.children, tmp_entry);
-		tmp_list = archive->root_entry.children;
+		tmp_entry->children = g_tree_new((GCompareFunc)lxa_archive_lookup_tree_dir);
+		g_tree_insert(archive->root_entry.children, tmp_entry->filename, tmp_entry);
 	}
 	for(i = 1; path_items[i]?strlen(path_items[i]):0;i++)
 	{
-		tmp_list_children = g_slist_find_custom(((LXAEntry *)tmp_list->data)->children, path_items[i], (GCompareFunc)lxa_archive_lookup_dir);
-		if(!tmp_list_children)
+		parent = tmp_entry;
+		tmp_entry = g_tree_lookup(parent->children, path_items[i]);
+		if(!tmp_entry)
 		{
 			tmp_entry = g_new0(LXAEntry, 1);
 			tmp_entry->filename = g_strdup(path_items[i]);
@@ -203,10 +205,10 @@
 				tmp_entry->is_folder = TRUE;
 			else
 				tmp_entry->is_folder = FALSE;
-			((LXAEntry *)tmp_list->data)->children = g_slist_prepend(((LXAEntry *)tmp_list->data)->children, tmp_entry);
-			tmp_list_children = ((LXAEntry *)tmp_list->data)->children;
+			tmp_entry->children = g_tree_new((GCompareFunc)lxa_archive_lookup_tree_dir);
+			g_tree_insert(parent->children, tmp_entry->filename, tmp_entry);
 		}
-		tmp_list = tmp_list_children;
+		parent = tmp_entry;
 	}
 	g_strfreev(path_items);
 	return tmp_entry;
@@ -215,8 +217,7 @@
 LXAEntry *
 lxa_entry_get_child(LXAEntry *entry, const gchar *filename)
 {
-	GSList *list = g_slist_find_custom(entry->children, filename,(GCompareFunc)lxa_archive_lookup_dir);
-	return (LXAEntry *)list->data;
+	return g_tree_lookup(entry->children, filename);
 }
 
 void
@@ -225,7 +226,7 @@
 	gint i = 0; 
 	gpointer props_iter = entry->props;
 
-	g_slist_foreach(entry->children, (GFunc)lxa_archive_free_entry, archive);
+	//g_slist_foreach(entry->children, (GFunc)lxa_archive_free_entry, archive);
 	if(entry->props)
 	{
 		switch(archive->column_types[i])
@@ -252,3 +253,9 @@
 	lxa_archive_set_status(archive, LXA_ARCHIVESTATUS_USERBREAK);
 	return 0;
 }
+
+gint
+lxa_archive_lookup_tree_dir(gpointer key, gconstpointer filename)
+{
+	return strcmp(key, filename);
+}

Modified: xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.h
===================================================================
--- xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.h	2006-09-29 08:50:15 UTC (rev 23238)
+++ xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.h	2006-09-29 15:56:41 UTC (rev 23239)
@@ -33,7 +33,7 @@
 
 typedef struct {
 	gchar *filename;
-	GSList *children;
+	GTree *children;
 	gboolean is_folder;
 	gpointer props;
 } LXAEntry;

Modified: xarchiver/branches/xarchiver-psybsd/src/main_window.c
===================================================================
--- xarchiver/branches/xarchiver-psybsd/src/main_window.c	2006-09-29 08:50:15 UTC (rev 23238)
+++ xarchiver/branches/xarchiver-psybsd/src/main_window.c	2006-09-29 15:56:41 UTC (rev 23239)
@@ -47,6 +47,10 @@
 xa_main_window_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
 static void
 cb_xa_main_window_style_set(XAMainWindow *window, gpointer userdata);
+gboolean
+xa_main_window_add_item(gpointer key, gpointer value, gpointer data);
+void 
+xa_main_window_set_contents(XAMainWindow *, LXAArchive *, GTree *);
 
 void
 xa_main_window_reset_columns(XAMainWindow *window);
@@ -57,8 +61,6 @@
 void
 xa_main_window_archive_destroyed(LXAArchive *archive, XAMainWindow *window);
 
-void 
-xa_main_window_set_contents(XAMainWindow *, LXAArchive *, GSList *);
 
 void
 cb_xa_main_close_archive(GtkWidget *widget, gpointer userdata);
@@ -326,7 +328,7 @@
 static void
 cb_xa_main_window_style_set(XAMainWindow *window, gpointer userdata)
 {
-	GSList *items = NULL;
+	GTree *items = NULL;
 
 	if(window->working_node)
 		items = ((LXAEntry *)window->working_node->data)->children;
@@ -771,72 +773,18 @@
 }
 
 void
-xa_main_window_set_contents(XAMainWindow *main_window, LXAArchive *archive, GSList *items)
+xa_main_window_set_contents(XAMainWindow *main_window, LXAArchive *archive, GTree *item_tree)
 {
 	gint i = 0;
+	GtkTreeModel *liststore = gtk_tree_view_get_model(GTK_TREE_VIEW(main_window->treeview));
 	GtkTreeIter iter;
-	GtkTreeModel *liststore = gtk_tree_view_get_model(GTK_TREE_VIEW(main_window->treeview));
 	GValue *tmp_value;
-	gpointer props;
-	gpointer props_iter;
-	gint column_number;
 
 	gtk_list_store_clear(GTK_LIST_STORE(liststore));
 
 
-	while(items)
-	{
-		i = 0;
-		gtk_list_store_append(GTK_LIST_STORE(liststore), &iter);
-		if(main_window->props._show_icons)
-		{
-			tmp_value = g_new0(GValue, 1);
-			tmp_value = g_value_init(tmp_value, G_TYPE_STRING);
-			if(((LXAEntry *)items->data)->is_folder)
-				g_value_set_string(tmp_value, "folder");
-			else
-				g_value_set_string(tmp_value, "unknown");
-			gtk_list_store_set_value(GTK_LIST_STORE(liststore), &iter, i, tmp_value);
-			i++;
-		}
-		tmp_value = g_new0(GValue, 1);
-		tmp_value = g_value_init(tmp_value, G_TYPE_STRING);
-		g_value_set_string(tmp_value, ((LXAEntry *)items->data)->filename);
-		gtk_list_store_set_value(GTK_LIST_STORE(liststore), &iter, i, tmp_value);
+	g_tree_foreach(item_tree, (GTraverseFunc)xa_main_window_add_item, main_window);
 
-		props = ((LXAEntry *)items->data)->props;
-		if(props)
-		{
-			props_iter = props;
-
-			for(i=1; i < archive->column_number; i++)
-			{
-				tmp_value = g_new0(GValue, 1);
-				tmp_value = g_value_init(tmp_value, archive->column_types[i]);
-				switch(archive->column_types[i])
-				{
-					case(G_TYPE_UINT):
-						g_value_set_uint(tmp_value, *(guint *)props_iter);
-						props_iter += sizeof(guint);
-						break;
-					case(G_TYPE_STRING):
-						g_value_set_string(tmp_value, *(gchar **)props_iter);
-						props_iter += sizeof(gchar *);
-						break;
-					case(G_TYPE_UINT64):
-						g_value_set_uint64(tmp_value, *(guint64 *)props_iter);
-						props_iter += sizeof(guint64);
-						break;
-				}
-				if(main_window->props._show_icons)
-					gtk_list_store_set_value(GTK_LIST_STORE(liststore), &iter, i+1, tmp_value);
-				else
-					gtk_list_store_set_value(GTK_LIST_STORE(liststore), &iter, i, tmp_value);
-				g_free(tmp_value);
-			}
-		}
-		items = items->next;
-	}
 	if(g_slist_length(main_window->working_node) > 1)
 	{
 		gtk_list_store_prepend(GTK_LIST_STORE(liststore), &iter);
@@ -854,11 +802,76 @@
 	gtk_tree_view_set_model(GTK_TREE_VIEW(main_window->treeview), GTK_TREE_MODEL(liststore));
 }
 
+gboolean
+xa_main_window_add_item(gpointer key, gpointer value, gpointer data)
+{
+	gint i = 0;
+	GtkTreeIter iter;
+	gpointer props;
+	gpointer props_iter;
+	GValue *tmp_value;
+	gint column_number;
+	XAMainWindow *main_window= XA_MAIN_WINDOW(data);
+	GtkTreeModel *liststore = gtk_tree_view_get_model(GTK_TREE_VIEW(main_window->treeview));
+	gtk_list_store_append(GTK_LIST_STORE(liststore), &iter);
+	if(main_window->props._show_icons)
+	{
+		tmp_value = g_new0(GValue, 1);
+		tmp_value = g_value_init(tmp_value, G_TYPE_STRING);
+		if(((LXAEntry*)value)->is_folder)
+			g_value_set_string(tmp_value, "folder");
+		else
+			g_value_set_string(tmp_value, "unknown");
+		gtk_list_store_set_value(GTK_LIST_STORE(liststore), &iter, i, tmp_value);
+		i++;
+	}
+	tmp_value = g_new0(GValue, 1);
+	tmp_value = g_value_init(tmp_value, G_TYPE_STRING);
+	g_value_set_string(tmp_value, (gchar *)key);
+	gtk_list_store_set_value(GTK_LIST_STORE(liststore), &iter, i, tmp_value);
+
+	props = ((LXAEntry *)value)->props;
+	if(props)
+	{
+		props_iter = props;
+
+		for(i=1; i < main_window->lp_xa_archive->column_number; i++)
+		{
+			tmp_value = g_new0(GValue, 1);
+			tmp_value = g_value_init(tmp_value, main_window->lp_xa_archive->column_types[i]);
+			switch(main_window->lp_xa_archive->column_types[i])
+			{
+				case(G_TYPE_UINT):
+					g_value_set_uint(tmp_value, *(guint *)props_iter);
+					props_iter += sizeof(guint);
+					break;
+				case(G_TYPE_STRING):
+					g_value_set_string(tmp_value, *(gchar **)props_iter);
+					props_iter += sizeof(gchar *);
+					break;
+				case(G_TYPE_UINT64):
+					g_value_set_uint64(tmp_value, *(guint64 *)props_iter);
+					props_iter += sizeof(guint64);
+					break;
+			}
+			if(main_window->props._show_icons)
+				gtk_list_store_set_value(GTK_LIST_STORE(liststore), &iter, i+1, tmp_value);
+			else
+				gtk_list_store_set_value(GTK_LIST_STORE(liststore), &iter, i, tmp_value);
+			g_free(tmp_value);
+		}
+	}
+	return FALSE;
+}
+
+
+
+
 void
 cb_xa_main_item_activated(GtkTreeView *treeview, GtkTreePath *treepath, GtkTreeViewColumn *column, gpointer userdata)
 {
 	GtkTreeIter iter;
-	GSList *items = NULL;
+	GTree *items = NULL;
 	GValue *value = g_new0(GValue, 1);
 	XAMainWindow *main_window = userdata;
 



More information about the Xfce4-commits mailing list