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

Stephan Arts stephan at xfce.org
Tue Oct 3 14:45:41 UTC 2006


Author: stephan
Date: 2006-10-03 14:45:40 +0000 (Tue, 03 Oct 2006)
New Revision: 23273

Added:
   xarchiver/branches/xarchiver-psybsd/src/archive_store.c
   xarchiver/branches/xarchiver-psybsd/src/archive_store.h
Modified:
   xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.c
   xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.h
   xarchiver/branches/xarchiver-psybsd/po/nl.po
   xarchiver/branches/xarchiver-psybsd/src/Makefile.am
   xarchiver/branches/xarchiver-psybsd/src/extract_dialog.h
   xarchiver/branches/xarchiver-psybsd/src/main_window.c
Log:
Speed up library, worked around bug,(probably introduced memory leaks).

But did some neat stuff.



Modified: xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.c
===================================================================
--- xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.c	2006-10-03 13:25:30 UTC (rev 23272)
+++ xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.c	2006-10-03 14:45:40 UTC (rev 23273)
@@ -31,7 +31,9 @@
 
 #include "internals.h"
 
+#define LXA_ENTRY_CHILD_BUFFER_SIZE 300
 
+
 static void
 lxa_archive_class_init(LXAArchiveClass *archive_class);
 
@@ -43,8 +45,13 @@
 
 void
 lxa_archive_free_entry(LXAEntry *entry, LXAArchive *archive);
+
+
 gint
-lxa_archive_lookup_tree_dir(gpointer key, gconstpointer filename);
+lxa_archive_sort_entry_buffer(LXAEntry *entry1, LXAEntry *entry2)
+{
+	return strcmp(entry1->filename, entry2->filename);
+}
 
 static gint lxa_archive_signals[1];
 
@@ -97,7 +104,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);
+		archive->root_entry.children = NULL;
 }
 
 static void
@@ -181,7 +188,7 @@
 	gchar **path_items;
 	LXAEntry *tmp_entry = NULL, *parent = NULL;
 	path_items = g_strsplit_set(path, "/\n", -1);
-	tmp_entry = g_tree_lookup(archive->root_entry.children, path_items[0]);
+	tmp_entry = lxa_entry_get_child(&archive->root_entry, path_items[0]);
 	if(!tmp_entry)
 	{
 		tmp_entry= g_new0(LXAEntry, 1);
@@ -190,23 +197,25 @@
 			tmp_entry->is_folder = TRUE;
 		else
 			tmp_entry->is_folder = FALSE;
-		tmp_entry->children = g_tree_new((GCompareFunc)lxa_archive_lookup_tree_dir);
-		g_tree_insert(archive->root_entry.children, tmp_entry->filename, tmp_entry);
+		lxa_entry_add_child(&archive->root_entry, tmp_entry);
+		lxa_entry_flush_buffer(&archive->root_entry);
 	}
 	for(i = 1; path_items[i]?strlen(path_items[i]):0;i++)
 	{
 		parent = tmp_entry;
-		tmp_entry = g_tree_lookup(parent->children, path_items[i]);
+		tmp_entry = lxa_entry_get_child(parent, path_items[i]);
 		if(!tmp_entry)
 		{
 			tmp_entry = g_new0(LXAEntry, 1);
 			tmp_entry->filename = g_strdup(path_items[i]);
+			lxa_entry_add_child(parent, tmp_entry);
 			if(path[strlen(path)-1] == '/')
+			{
 				tmp_entry->is_folder = TRUE;
+				lxa_entry_flush_buffer(parent);
+			}
 			else
 				tmp_entry->is_folder = FALSE;
-			tmp_entry->children = g_tree_new((GCompareFunc)lxa_archive_lookup_tree_dir);
-			g_tree_insert(parent->children, tmp_entry->filename, tmp_entry);
 		}
 		parent = tmp_entry;
 	}
@@ -214,11 +223,6 @@
 	return tmp_entry;
 }
 
-LXAEntry *
-lxa_entry_get_child(LXAEntry *entry, const gchar *filename)
-{
-	return g_tree_lookup(entry->children, filename);
-}
 
 void
 lxa_archive_free_entry(LXAEntry *entry, LXAArchive *archive)
@@ -226,7 +230,9 @@
 	gint i = 0; 
 	gpointer props_iter = entry->props;
 
-	//g_slist_foreach(entry->children, (GFunc)lxa_archive_free_entry, archive);
+	for(i = 0; i < entry->n_children; i++)
+		lxa_archive_free_entry(entry->children[i], archive);
+
 	if(entry->props)
 	{
 		switch(archive->column_types[i])
@@ -254,8 +260,111 @@
 	return 0;
 }
 
-gint
-lxa_archive_lookup_tree_dir(gpointer key, gconstpointer filename)
+gboolean
+lxa_entry_add_child(LXAEntry *parent, LXAEntry *child)
 {
-	return strcmp(key, filename);
+	guint max_children = 0;
+	guint begin = 0;
+	guint pos = 0;
+	gint cmp = 0;
+	guint old_i = 0;
+	guint new_i = 0;
+	guint size = parent->n_children;
+	guint org_size = parent->n_children;
+	GSList *buffer_iter = NULL;
+	LXAEntry **children_old = (LXAEntry **)parent->children;
+	
+	parent->buffer = g_slist_insert_sorted(parent->buffer, (gpointer)child, (GCompareFunc)lxa_archive_sort_entry_buffer);
+	if(g_slist_length(parent->buffer) == LXA_ENTRY_CHILD_BUFFER_SIZE)
+		lxa_entry_flush_buffer(parent);
 }
+
+LXAEntry *
+lxa_entry_get_child(LXAEntry *entry, const gchar *filename)
+{
+	guint size = entry->n_children;
+	guint pos = 0;
+	gint cmp = 0;
+	while(size)
+	{
+		pos = (size / 2);
+
+		cmp = strcmp(filename, entry->children[pos]->filename);
+		if(!cmp)
+			return entry->children[pos];
+
+		if(cmp < 0)
+		{
+			size = pos;
+		}
+		else
+		{
+			size = size - ++pos;
+		}
+	}
+	return NULL;
+}
+
+void
+lxa_entry_flush_buffer(LXAEntry *entry)
+{
+	g_debug("Flush");
+	guint max_children = 0;
+	guint begin = 0;
+	guint pos = 0;
+	gint cmp = 1;
+	guint old_i = 0;
+	guint new_i = 0;
+	guint size = entry->n_children;
+	GSList *buffer_iter = NULL;
+	LXAEntry **children_old = (LXAEntry **)entry->children;
+
+	max_children = (entry->n_children + g_slist_length(entry->buffer));
+	
+	entry->children = g_new(LXAEntry *, max_children);
+	for(buffer_iter = entry->buffer;buffer_iter;buffer_iter = buffer_iter->next)
+	{
+		size = entry->n_children - begin;
+		while(size)
+		{
+			pos = (size / 2)+begin;
+
+			cmp = strcmp(((LXAEntry *)buffer_iter->data)->filename, children_old[pos]->filename);
+			if(!cmp)
+				break;
+
+			if(cmp < 0)
+			{
+				size = pos - begin;
+			}
+			else
+			{
+				size = size + begin - ++pos;
+				begin = pos;
+			}
+		}
+		if(!cmp)
+		{
+			/* TODO: F*** (aka merge) */
+		}
+		else
+		{
+			while(old_i < pos)
+			{
+				entry->children[new_i++] = children_old[old_i++];
+			}
+			entry->children[new_i++] = buffer_iter->data;
+		}
+	}
+	while(old_i < entry->n_children)
+	{
+		entry->children[new_i++] = children_old[old_i++];
+	}
+	entry->n_children = new_i;
+	g_debug("%d", entry->n_children);
+
+	g_slist_free(entry->buffer);
+	entry->buffer = NULL;
+
+	g_free(children_old);
+}

Modified: xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.h
===================================================================
--- xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.h	2006-10-03 13:25:30 UTC (rev 23272)
+++ xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.h	2006-10-03 14:45:40 UTC (rev 23273)
@@ -31,12 +31,17 @@
 	LXA_ARCHIVESTATUS_USERBREAK
 } LXAArchiveStatus;
 
-typedef struct {
+typedef struct _LXAEntry LXAEntry;
+
+struct _LXAEntry {
 	gchar *filename;
-	GTree *children;
 	gboolean is_folder;
 	gpointer props;
-} LXAEntry;
+	/* */
+	LXAEntry **children;
+	guint   n_children;
+	GSList *buffer;
+};
 
 #define LXA_ARCHIVE(obj)         ( \
 		G_TYPE_CHECK_INSTANCE_CAST ((obj),    \
@@ -98,6 +103,8 @@
 LXAEntry          *lxa_archive_add_file(LXAArchive *archive, gchar *path);
 GSList            *lxa_archive_get_children(LXAArchive *archive, gchar *path);
 LXAEntry          *lxa_entry_get_child(LXAEntry *, const gchar *);
+gboolean           lxa_entry_add_child(LXAEntry *parent, LXAEntry *child);
+void               lxa_entry_flush_buffer(LXAEntry *entry);
 
 
 G_END_DECLS

Modified: xarchiver/branches/xarchiver-psybsd/po/nl.po
===================================================================
--- xarchiver/branches/xarchiver-psybsd/po/nl.po	2006-10-03 13:25:30 UTC (rev 23272)
+++ xarchiver/branches/xarchiver-psybsd/po/nl.po	2006-10-03 14:45:40 UTC (rev 23273)
@@ -7,7 +7,7 @@
 msgstr ""
 "Project-Id-Version: xarchiver 0.3.9psybsd\n"
 "Report-Msgid-Bugs-To: psybsd at gmail.com\n"
-"POT-Creation-Date: 2006-09-25 00:02+0200\n"
+"POT-Creation-Date: 2006-10-02 09:14+0200\n"
 "PO-Revision-Date: 2006-07-20 16:36+0200\n"
 "Last-Translator: Stephan Arts <psybsd at gmail.com>\n"
 "Language-Team: Dutch <vertaling at vrijschrift.org>\n"
@@ -16,12 +16,12 @@
 "Content-Transfer-Encoding: 8bit\n"
 "Plural-Forms: nplurals=2; plural=(n != 1);\n"
 
-#: ../libxarchiver/archive-support-gnu-tar.c:133
+#: ../libxarchiver/archive-support-gnu-tar.c:134
 #: ../libxarchiver/archive-support-zip.c:104
 msgid "Overwrite existing files"
 msgstr "Bestaande bestanden overschrijven"
 
-#: ../libxarchiver/archive-support-gnu-tar.c:134
+#: ../libxarchiver/archive-support-gnu-tar.c:135
 #: ../libxarchiver/archive-support-zip.c:105
 msgid "Overwrite existing files on extraction"
 msgstr "Bestaande bestanden overschrijven tijdens uitpakken"
@@ -47,11 +47,11 @@
 msgid "Version information"
 msgstr "Versie informatie"
 
-#: ../src/main.c:119
+#: ../src/main.c:120
 msgid "[archive name]"
 msgstr "[archief naam]"
 
-#: ../src/main.c:123
+#: ../src/main.c:124
 #, c-format
 msgid ""
 "%s: %s\n"
@@ -64,7 +64,7 @@
 #.
 #. * Could not create archive (mime type unsupported)
 #.
-#: ../src/main.c:196
+#: ../src/main.c:197
 msgid "Could not create archive, MIME-type unsupported"
 msgstr "Kan archief niet maken, MIME-type wordt niet ondersteund"
 
@@ -72,66 +72,70 @@
 #. * Could not open archive (mime type not supported or file did not exist)
 #. * Should be a more specific error message.
 #.
-#: ../src/main.c:213
+#: ../src/main.c:214
 msgid "Could not open archive, MIME-type unsupported or file did not exist"
 msgstr ""
 "Kan archief niet openen, MIME-type wordt niet ondersteund of bestand bestaat "
 "niet"
 
-#: ../src/main_window.c:101
+#: ../src/main_window.c:107 ../src/main_window.c:108
+msgid "Show icons"
+msgstr ""
+
+#: ../src/main_window.c:134
 msgid "_Archive"
 msgstr "_Archief"
 
-#: ../src/main_window.c:102
+#: ../src/main_window.c:135
 msgid "A_ction"
 msgstr "A_ctie"
 
-#: ../src/main_window.c:103
+#: ../src/main_window.c:136
 msgid "_Help"
 msgstr "_Help"
 
-#: ../src/main_window.c:147 ../src/main_window.c:191
+#: ../src/main_window.c:180 ../src/main_window.c:225
 msgid "Add"
 msgstr "Toevoegen"
 
-#: ../src/main_window.c:152 ../src/main_window.c:195
+#: ../src/main_window.c:185 ../src/main_window.c:229
 #: ../src/extract_dialog.c:99
 msgid "Extract"
 msgstr "Uitpakken"
 
-#: ../src/main_window.c:357
+#: ../src/main_window.c:455
 msgid "Open archive"
 msgstr "Archief openen"
 
-#: ../src/main_window.c:507
+#: ../src/main_window.c:632
 msgid "Initializing archive..."
 msgstr "Bezig met initialiseren van archief..."
 
-#: ../src/main_window.c:510
+#: ../src/main_window.c:635
 msgid "Reading archive contents..."
 msgstr "Bezig met lezen van archief..."
 
-#: ../src/main_window.c:513
+#: ../src/main_window.c:638
 msgid "Extracting archive..."
 msgstr "Archief uitpakken..."
 
-#: ../src/main_window.c:516
+#: ../src/main_window.c:641
 msgid "Adding file(s) to archive..."
 msgstr "Bestand(en) toevoegen aan archief..."
 
-#: ../src/main_window.c:519
+#: ../src/main_window.c:644
 msgid "Removing file(s) from archive..."
 msgstr "Bestand(en) toevoegen aan archief..."
 
-#: ../src/main_window.c:522
+#: ../src/main_window.c:647
 msgid "Error"
 msgstr "Fout"
 
-#: ../src/main_window.c:525
+#: ../src/main_window.c:650
 msgid "Cancelled"
 msgstr "Geannuleerd"
 
-#: ../src/main_window.c:528
+#: ../src/main_window.c:653
 msgid "Done"
 msgstr "Klaar"
 
@@ -139,14 +143,11 @@
 msgid "Create new archive"
 msgstr "Maak nieuw archief"
 
-#. * XA_ADD_DIALOG
-#. *  Frame title
-#.
-#: ../src/add_dialog.c:68
-msgid "Files and folders to add"
+#: ../src/add_dialog.c:64
+msgid "Drag Files and folders to bottom list"
 msgstr ""
 
-#: ../src/add_dialog.c:82
+#: ../src/add_dialog.c:91
 msgid "Add file(s) to archive"
 msgstr "Bestand(en) toevoegen aan archief"
 

Modified: xarchiver/branches/xarchiver-psybsd/src/Makefile.am
===================================================================
--- xarchiver/branches/xarchiver-psybsd/src/Makefile.am	2006-10-03 13:25:30 UTC (rev 23272)
+++ xarchiver/branches/xarchiver-psybsd/src/Makefile.am	2006-10-03 14:45:40 UTC (rev 23273)
@@ -5,6 +5,7 @@
 	main_window.c main_window.h \
 	new_dialog.c new_dialog.h \
 	add_dialog.c add_dialog.h \
+	archive_store.c archive_store.h \
 	preferences_dialog.c preferences_dialog.h \
 	extract_dialog.c extract_dialog.h
 

Added: xarchiver/branches/xarchiver-psybsd/src/archive_store.c
===================================================================
--- xarchiver/branches/xarchiver-psybsd/src/archive_store.c	                        (rev 0)
+++ xarchiver/branches/xarchiver-psybsd/src/archive_store.c	2006-10-03 14:45:40 UTC (rev 23273)
@@ -0,0 +1,364 @@
+/*
+ *  Copyright (c) 2006 Stephan Arts <psybsd at gmail.com>
+ *
+ *  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 Library 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 <glib.h>
+#include <gtk/gtk.h>
+#include <libxarchiver/libxarchiver.h>
+#include "archive_store.h"
+
+static void
+xa_archive_store_class_init(XAArchiveStoreClass *as_class);
+
+static void
+xa_archive_store_init(XAArchiveStore *as);
+
+static void
+xa_archive_tree_model_init(GtkTreeModelIface *tm_interface);
+
+static GtkTreeModelFlags
+xa_archive_store_get_flags(GtkTreeModel *tree_model);
+static gint
+xa_archive_store_get_n_columns(GtkTreeModel *tree_model);
+static GType
+xa_archive_store_get_column_type(GtkTreeModel *tree_model, gint index);
+static gboolean
+xa_archive_store_get_iter(GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreePath *path);
+static GtkTreePath *
+xa_archive_store_get_path (GtkTreeModel *tree_model, GtkTreeIter *iter);
+static void 
+xa_archive_store_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, gint column, GValue *value);
+static gboolean
+xa_archive_store_iter_next (GtkTreeModel *tree_model, GtkTreeIter *iter);
+static gboolean
+xa_archive_store_iter_children (GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreeIter *parent);
+static gboolean
+xa_archive_store_iter_has_child (GtkTreeModel *tree_model, GtkTreeIter *iter);
+static gint
+xa_archive_store_iter_n_children (GtkTreeModel *tree_model, GtkTreeIter *iter);
+static gboolean 
+xa_archive_store_iter_nth_child (GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreeIter *parent, gint n);
+static gboolean
+xa_archive_store_iter_parent (GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreeIter *child);
+
+GType
+xa_archive_store_get_type()
+{
+	static GType xa_archive_store_type= 0;
+
+	if(xa_archive_store_type)
+		return xa_archive_store_type;
+
+ 	if (!xa_archive_store_type)
+	{
+ 		static const GTypeInfo xa_archive_store_info = 
+		{
+			sizeof (XAArchiveStoreClass),
+			(GBaseInitFunc) NULL,
+			(GBaseFinalizeFunc) NULL,
+			(GClassInitFunc) xa_archive_store_class_init,
+			(GClassFinalizeFunc) NULL,
+			NULL,
+			sizeof (XAArchiveStore),
+			0,
+			(GInstanceInitFunc) xa_archive_store_init,
+			NULL
+		};
+
+		xa_archive_store_type = g_type_register_static (G_TYPE_OBJECT, "XAArchiveStore", &xa_archive_store_info, 0);
+	}
+	static const GInterfaceInfo tree_model_info =
+	{
+		(GInterfaceInitFunc) xa_archive_tree_model_init,
+			NULL,
+			NULL
+	};
+
+	g_type_add_interface_static (xa_archive_store_type, GTK_TYPE_TREE_MODEL, &tree_model_info);
+	return xa_archive_store_type;
+}
+
+static void
+xa_archive_tree_model_init(GtkTreeModelIface *iface)
+{
+	iface->get_flags       = xa_archive_store_get_flags;
+	iface->get_n_columns   = xa_archive_store_get_n_columns;
+  iface->get_column_type = xa_archive_store_get_column_type;
+  iface->get_iter        = xa_archive_store_get_iter;
+  iface->get_path        = xa_archive_store_get_path;
+  iface->get_value       = xa_archive_store_get_value;
+  iface->iter_next       = xa_archive_store_iter_next;
+  iface->iter_children   = xa_archive_store_iter_children;
+  iface->iter_has_child  = xa_archive_store_iter_has_child;
+  iface->iter_n_children = xa_archive_store_iter_n_children;
+  iface->iter_nth_child  = xa_archive_store_iter_nth_child;
+  iface->iter_parent     = xa_archive_store_iter_parent;
+}
+
+static void
+xa_archive_store_init(XAArchiveStore *as)
+{
+	as->stamp = g_random_int();
+}
+
+static void
+xa_archive_store_class_init(XAArchiveStoreClass *as_class)
+{
+
+}
+
+
+static gboolean
+xa_archive_store_get_iter(GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreePath *path)
+{
+	XAArchiveStore *store = XA_ARCHIVE_STORE(tree_model);
+
+  gint *indices = gtk_tree_path_get_indices(path);
+
+	if(indices[0] >= g_slist_length(store->rows) || indices[0] < 0)
+		return FALSE;
+
+	GSList *entry = g_slist_nth(store->rows, indices[0]);
+	if(!entry)
+		return FALSE;
+
+	iter->stamp = store->stamp;
+	iter->user_data = entry;
+	iter->user_data2 = NULL;
+	iter->user_data3 = NULL;
+	return TRUE;
+}
+
+static GtkTreePath *
+xa_archive_store_get_path (GtkTreeModel *tree_model, GtkTreeIter *iter)
+{
+	GtkTreePath *path = NULL;
+	XAArchiveStore *store = XA_ARCHIVE_STORE(tree_model);
+	GSList *list = g_slist_find(store->rows, iter->user_data);
+	if(list)
+	{
+		path = gtk_tree_path_new();
+		gtk_tree_path_append_index(path, g_slist_position(store->rows, list));
+	}
+	return path;
+}
+
+
+static gboolean 
+xa_archive_store_iter_nth_child (GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreeIter *parent, gint n)
+{
+	XAArchiveStore *store = XA_ARCHIVE_STORE(tree_model);
+	LXAEntry *entry = g_slist_nth_data(store->rows, n);
+	if(!entry)
+		return FALSE;
+	iter->stamp = store->stamp;
+	iter->user_data = entry;
+	return FALSE;
+}
+
+
+/* done */
+
+static void 
+xa_archive_store_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, gint column, GValue *value)
+{
+	guint i = 0;
+	g_return_if_fail (XA_IS_ARCHIVE_STORE (tree_model));
+	g_return_if_fail (iter != NULL);
+	g_return_if_fail (column < XA_ARCHIVE_STORE(tree_model)->n_columns);
+
+	g_value_init(value, XA_ARCHIVE_STORE(tree_model)->column_types[column]);
+
+	XAArchiveStore *archive_store = XA_ARCHIVE_STORE(tree_model);
+
+	LXAEntry *entry = ((GSList *)iter->user_data)->data;
+	gpointer props_iter = entry->props;
+
+	if((column == 1 && archive_store->props._show_icons) || (column == 0))
+	{
+		if(archive_store->props._show_icons && column == 0)
+			g_value_set_string(value, "unknown");
+		else
+			g_value_set_string(value, entry->filename);
+	} else
+	{
+		if(archive_store->props._show_icons)
+			i = 2;
+		else
+			i = 1;
+		for(;i<column;i++)
+		{
+			switch(archive_store->column_types[i])
+			{
+				case G_TYPE_STRING:
+					props_iter+=sizeof(gchar *);
+					break;
+				case G_TYPE_UINT64:
+					props_iter+=sizeof(guint64);
+					break;
+				case G_TYPE_UINT:
+					props_iter+=sizeof(guint);
+					break;
+			}
+		}
+		switch(archive_store->column_types[column])
+		{
+			case G_TYPE_STRING:
+				g_value_set_string(value, *(gchar **)props_iter);
+				break;
+			case G_TYPE_UINT64:
+				g_value_set_uint64(value, *(guint64 *)props_iter);
+				break;
+			case G_TYPE_UINT:
+				g_value_set_uint(value, *(guint *)props_iter);
+				break;
+		}
+	}
+}
+
+static gboolean
+xa_archive_store_iter_next (GtkTreeModel *tree_model, GtkTreeIter *iter)
+{
+	g_return_val_if_fail(XA_IS_ARCHIVE_STORE(tree_model), FALSE);
+	if(iter == NULL || iter->user_data == NULL)
+		return FALSE;
+	
+	if(!((GSList *)iter->user_data)->next)
+		return FALSE;
+	
+	iter->stamp = XA_ARCHIVE_STORE(tree_model)->stamp;
+	iter->user_data = ((GSList *)iter->user_data)->next;
+	return TRUE;
+}
+
+static gboolean
+xa_archive_store_iter_parent (GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreeIter *child)
+{
+	return FALSE;
+}
+
+
+static gboolean
+xa_archive_store_iter_children (GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreeIter *parent)
+{
+	g_return_val_if_fail(parent == NULL || parent->user_data == NULL, FALSE);
+	g_return_val_if_fail(XA_IS_ARCHIVE_STORE(tree_model), FALSE);
+	XAArchiveStore *archive_store = XA_ARCHIVE_STORE(tree_model);
+	
+	if(g_slist_length(archive_store->rows) == 0)
+		return FALSE;
+	
+	iter->stamp = archive_store->stamp;
+	iter->user_data = archive_store->rows;
+
+	return TRUE;
+}
+
+static gboolean
+xa_archive_store_iter_has_child (GtkTreeModel *tree_model, GtkTreeIter *iter)
+{
+	return FALSE;
+}
+
+static GType
+xa_archive_store_get_column_type(GtkTreeModel *tree_model, gint index)
+{
+	g_return_val_if_fail(XA_IS_ARCHIVE_STORE(tree_model), G_TYPE_INVALID);	
+	return XA_ARCHIVE_STORE(tree_model)->column_types[index];
+}
+
+static gint
+xa_archive_store_get_n_columns(GtkTreeModel *tree_model)
+{
+	g_return_val_if_fail(XA_IS_ARCHIVE_STORE(tree_model), 0);
+	
+	return XA_ARCHIVE_STORE(tree_model)->n_columns;
+}
+
+static GtkTreeModelFlags
+xa_archive_store_get_flags(GtkTreeModel *tree_model)
+{
+	g_return_val_if_fail(XA_IS_ARCHIVE_STORE(tree_model), (GtkTreeModelFlags)0);
+
+  return (GTK_TREE_MODEL_LIST_ONLY | GTK_TREE_MODEL_ITERS_PERSIST);
+}
+
+static gint
+xa_archive_store_iter_n_children (GtkTreeModel *tree_model, GtkTreeIter *iter)
+{
+	g_return_val_if_fail(XA_IS_ARCHIVE_STORE(tree_model), -1);
+	g_return_val_if_fail(iter == NULL || iter->user_data != NULL, 0);
+
+	XAArchiveStore *archive_store = XA_ARCHIVE_STORE(tree_model);
+
+	return g_slist_length(archive_store->rows);
+}
+
+GtkTreeModel *
+xa_archive_store_new(LXAArchive *archive, gboolean show_icons)
+{
+	XAArchiveStore *tree_model;
+	GType *column_types;
+	gint x;
+
+	tree_model = g_object_new(XA_TYPE_ARCHIVE_STORE, NULL);
+	if(show_icons)
+	{
+		column_types = g_new0(GType, archive->column_number+1);
+		for(x = 0; x < archive->column_number; x++)
+		{
+			column_types[x+1] = archive->column_types[x];
+		}
+		column_types[0] = G_TYPE_STRING;
+		tree_model->n_columns = archive->column_number + 1;
+	}
+	else
+	{
+		column_types = g_new0(GType, archive->column_number);
+		for(x = 0; x < archive->column_number; x++)
+		{
+			column_types[x] = archive->column_types[x];
+		}
+		tree_model->n_columns = archive->column_number;
+	}
+	tree_model->column_types = archive->column_types;
+	tree_model->props._show_icons = show_icons;
+
+
+	return GTK_TREE_MODEL(tree_model);
+}
+
+gboolean
+xa_archive_store_add_item(gpointer key, gpointer value, gpointer data)
+{
+//	GtkTreeIter iter;
+	XA_ARCHIVE_STORE(data)->rows = g_slist_prepend(XA_ARCHIVE_STORE(data)->rows, value);
+	GtkTreePath *path = gtk_tree_path_new();
+	gtk_tree_path_append_index(path, 0);
+
+//	xa_archive_store_get_iter(GTK_TREE_MODEL(data), &iter, path);
+//	gtk_tree_model_row_inserted(GTK_TREE_MODEL(data), path, &iter);
+	gtk_tree_path_free(path);
+	return FALSE;
+}
+
+void
+xa_archive_store_set_contents(XAArchiveStore *archive_store, GTree *items, gboolean is_root)
+{
+	g_tree_foreach(items, (GTraverseFunc)xa_archive_store_add_item, archive_store);
+}

Added: xarchiver/branches/xarchiver-psybsd/src/archive_store.h
===================================================================
--- xarchiver/branches/xarchiver-psybsd/src/archive_store.h	                        (rev 0)
+++ xarchiver/branches/xarchiver-psybsd/src/archive_store.h	2006-10-03 14:45:40 UTC (rev 23273)
@@ -0,0 +1,70 @@
+/*
+ *  Copyright (c) 2006 Stephan Arts <psybsd at gmail.com>
+ *
+ *  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 Library 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.
+ */
+#ifndef __XARCHIVER_ARCHIVE_STORE_H__
+#define __XARCHIVER_ARCHIVE_STORE_H__
+
+#define XA_TYPE_ARCHIVE_STORE xa_archive_store_get_type()
+
+#define XA_ARCHIVE_STORE(obj)         ( \
+		G_TYPE_CHECK_INSTANCE_CAST ((obj),    \
+			XA_TYPE_ARCHIVE_STORE,      \
+			XAArchiveStore))
+
+#define XA_IS_ARCHIVE_STORE(obj)      ( \
+		G_TYPE_CHECK_INSTANCE_TYPE ((obj),    \
+			XA_TYPE_ARCHIVE_STORE))
+
+#define XA_ARCHIVE_STORE_CLASS(class) ( \
+		G_TYPE_CHECK_CLASS_CAST ((class),     \
+			XA_TYPE_ARCHIVE_STORE,      \
+			XAArchiveStoreClass))
+
+#define XA_IS_ARCHIVE_STORE_CLASS(class) ( \
+		G_TYPE_CHECK_CLASS_TYPE ((class),        \
+			XA_TYPE_ARCHIVE_STORE))
+
+typedef struct _XAArchiveStore XAArchiveStore;
+
+struct _XAArchiveStore
+{
+	GObject parent;
+	gint stamp;
+	guint n_columns;
+	GType *column_types;
+	GSList *rows;
+	struct {
+		gboolean _show_icons;
+	} props;
+};
+
+typedef struct _XAArchiveStoreClass XAArchiveStoreClass;
+
+struct _XAArchiveStoreClass
+{
+	GObjectClass parent_class;
+};
+
+
+GType
+xa_archive_store_get_type();
+GtkTreeModel *
+xa_archive_store_new(LXAArchive *archive, gboolean show_icons);
+void
+xa_archive_store_set_contents(XAArchiveStore *archive_store, GTree *items, gboolean is_root);
+
+#endif /* __XARCHIVER_ARCHIVE_STORE_H__ */

Modified: xarchiver/branches/xarchiver-psybsd/src/extract_dialog.h
===================================================================
--- xarchiver/branches/xarchiver-psybsd/src/extract_dialog.h	2006-10-03 13:25:30 UTC (rev 23272)
+++ xarchiver/branches/xarchiver-psybsd/src/extract_dialog.h	2006-10-03 14:45:40 UTC (rev 23273)
@@ -58,6 +58,7 @@
 	GtkFileChooserDialogClass parent_class;
 };
 
+GType      xa_extract_archive_dialog_get_type();
 GtkWidget *xa_extract_archive_dialog_new(LXAArchiveSupport *, LXAArchive *, gboolean);
 
 G_END_DECLS

Modified: xarchiver/branches/xarchiver-psybsd/src/main_window.c
===================================================================
--- xarchiver/branches/xarchiver-psybsd/src/main_window.c	2006-10-03 13:25:30 UTC (rev 23272)
+++ xarchiver/branches/xarchiver-psybsd/src/main_window.c	2006-10-03 14:45:40 UTC (rev 23273)
@@ -30,6 +30,7 @@
 #include "extract_dialog.h"
 #include "add_dialog.h"
 #include "preferences_dialog.h"
+#include "archive_store.h"
 
 #include "main.h"
 
@@ -48,9 +49,9 @@
 static void
 cb_xa_main_window_style_set(XAMainWindow *window, gpointer userdata);
 gboolean
-xa_main_window_add_item(gpointer key, gpointer value, gpointer data);
+xa_main_window_add_item(LXAEntry *entry, gpointer data);
 void 
-xa_main_window_set_contents(XAMainWindow *, LXAArchive *, GTree *);
+xa_main_window_set_contents(XAMainWindow *, LXAArchive *);
 
 void
 xa_main_window_reset_columns(XAMainWindow *window);
@@ -328,20 +329,18 @@
 static void
 cb_xa_main_window_style_set(XAMainWindow *window, gpointer userdata)
 {
-	GTree *items = NULL;
-
-	if(window->working_node)
-		items = ((LXAEntry *)window->working_node->data)->children;
-
 	if(!(gtk_icon_theme_has_icon(window->icon_theme, "folder") && gtk_icon_theme_has_icon(window->icon_theme, "unknown") && gtk_icon_theme_has_icon(window->icon_theme, "go-up")))
 		window->props._show_icons = FALSE;
 	else
 		window->props._show_icons = TRUE;
 
-	if(items)
+	if(window->working_node)
 	{
-		xa_main_window_reset_columns(window);
-		xa_main_window_set_contents(window, window->lp_xa_archive, items);
+		if(((LXAEntry *)window->working_node->data)->children)
+		{
+			xa_main_window_reset_columns(window);
+			xa_main_window_set_contents(window, window->lp_xa_archive);
+		}
 	}
 	
 }
@@ -659,7 +658,7 @@
 					xa_main_window_reset_columns(main_window);
 
 					main_window->working_node = g_slist_prepend(main_window->working_node, &(archive->root_entry));
-					xa_main_window_set_contents(main_window, archive, archive->root_entry.children);
+					xa_main_window_set_contents(main_window, archive);
 				case(LXA_ARCHIVESTATUS_EXTRACT):
 					gtk_widget_set_sensitive(GTK_WIDGET(main_window->menubar.menu_item_add), TRUE);
 					gtk_widget_set_sensitive(GTK_WIDGET(main_window->menubar.menu_item_remove), TRUE);
@@ -710,6 +709,7 @@
 	GtkCellRenderer *renderer = NULL;
 	GtkTreeViewColumn *column = NULL;
 	GtkListStore *liststore = NULL;
+	//GtkTreeModel *liststore = NULL;
 	LXAArchive *archive = window->lp_xa_archive;
 	gint x = 0;
 	GList *columns = gtk_tree_view_get_columns(GTK_TREE_VIEW(window->treeview));
@@ -729,6 +729,7 @@
 		}
 		column_types[0] = G_TYPE_STRING;
 		liststore = gtk_list_store_newv(archive->column_number+1, column_types); 
+//		liststore = xa_archive_store_new(archive, TRUE);
 
 		renderer = gtk_cell_renderer_pixbuf_new();
 		column = gtk_tree_view_column_new_with_attributes("", renderer, "icon-name", 0, NULL);
@@ -753,6 +754,7 @@
 	} else
 	{
 		liststore = gtk_list_store_newv(archive->column_number, archive->column_types); 
+		//liststore = xa_archive_store_new(archive, FALSE);
 		for(x = 0; x < archive->column_number; x++)
 		{
 			switch(archive->column_types[x])
@@ -774,9 +776,9 @@
 }
 
 void
-xa_main_window_set_contents(XAMainWindow *main_window, LXAArchive *archive, GTree *item_tree)
+xa_main_window_set_contents(XAMainWindow *main_window, LXAArchive *archive)
 {
-	gint i = 0;
+	guint i = 0;
 	GtkTreeModel *liststore = main_window->treemodel;
 	g_object_ref(liststore);
 	GtkTreeIter iter;
@@ -786,9 +788,13 @@
 
 	gtk_list_store_clear(GTK_LIST_STORE(liststore));
 
+	lxa_entry_flush_buffer(((LXAEntry *)main_window->working_node->data));
 
-	g_tree_foreach(item_tree, (GTraverseFunc)xa_main_window_add_item, main_window);
+	for(i=0;i<((LXAEntry *)main_window->working_node->data)->n_children; i++)
+		xa_main_window_add_item(((LXAEntry *)main_window->working_node->data)->children[i], main_window);
 
+	g_debug("Nodes: %d\n", ((LXAEntry *)main_window->working_node->data)->n_children);
+
 	if(g_slist_length(main_window->working_node) > 1)
 	{
 		gtk_list_store_prepend(GTK_LIST_STORE(liststore), &iter);
@@ -803,18 +809,23 @@
 		else
 			gtk_list_store_set_value(GTK_LIST_STORE(liststore), &iter, 0, main_window->parent_node);
 	}
+/*
+	if(g_slist_length(main_window->working_node) > 1)
+		xa_archive_store_set_contents(XA_ARCHIVE_STORE(liststore), item_tree, FALSE);
+	else
+		xa_archive_store_set_contents(XA_ARCHIVE_STORE(liststore), item_tree, TRUE);
+*/
 	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)
+xa_main_window_add_item(LXAEntry *entry, 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 = main_window->treemodel;
 	gtk_list_store_append(GTK_LIST_STORE(liststore), &iter);
@@ -822,7 +833,7 @@
 	{
 		tmp_value = g_new0(GValue, 1);
 		tmp_value = g_value_init(tmp_value, G_TYPE_STRING);
-		if(((LXAEntry*)value)->is_folder)
+		if(entry->is_folder)
 			g_value_set_string(tmp_value, "folder");
 		else
 			g_value_set_string(tmp_value, "unknown");
@@ -833,12 +844,12 @@
 	}
 	tmp_value = g_new0(GValue, 1);
 	tmp_value = g_value_init(tmp_value, G_TYPE_STRING);
-	g_value_set_string(tmp_value, (gchar *)key);
+	g_value_set_string(tmp_value, entry->filename);
 	gtk_list_store_set_value(GTK_LIST_STORE(liststore), &iter, i, tmp_value);
 	g_value_unset(tmp_value);
 	g_free(tmp_value);
 
-	props = ((LXAEntry *)value)->props;
+	props = entry->props;
 	if(props)
 	{
 		props_iter = props;
@@ -875,12 +886,10 @@
 
 
 
-
 void
 cb_xa_main_item_activated(GtkTreeView *treeview, GtkTreePath *treepath, GtkTreeViewColumn *column, gpointer userdata)
 {
 	GtkTreeIter iter;
-	GTree *items = NULL;
 	GValue *value = g_new0(GValue, 1);
 	XAMainWindow *main_window = userdata;
 
@@ -893,11 +902,10 @@
 		gtk_tree_model_get_value(tree_model, &iter, 0, value);
 
 	const gchar *item_filename = (gchar *)g_value_get_string(value);
-	if(!strcmp(item_filename, "..")) /* pop */
+	if(!strcmp(item_filename, ".."))
 	{
 		main_window->working_node = g_slist_delete_link(main_window->working_node, main_window->working_node);
-		items = ((LXAEntry *)main_window->working_node->data)->children;
-		xa_main_window_set_contents(main_window, main_window->lp_xa_archive, items);
+		xa_main_window_set_contents(main_window, main_window->lp_xa_archive);
 	}
 	else
 	{
@@ -907,8 +915,7 @@
 			if(entry->is_folder)
 			{
 				main_window->working_node = g_slist_prepend(main_window->working_node, entry);
-				items = ((LXAEntry *)main_window->working_node->data)->children;
-				xa_main_window_set_contents(main_window, main_window->lp_xa_archive, items);
+				xa_main_window_set_contents(main_window, main_window->lp_xa_archive);
 			}
 			else
 			{ 



More information about the Xfce4-commits mailing list