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

Stephan Arts stephan at xfce.org
Sat Oct 7 14:40:44 UTC 2006


Author: stephan
Date: 2006-10-07 14:40:42 +0000 (Sat, 07 Oct 2006)
New Revision: 23306

Added:
   xarchiver/branches/xarchiver-psybsd/src/path_bar.c
   xarchiver/branches/xarchiver-psybsd/src/path_bar.h
Modified:
   xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.c
   xarchiver/branches/xarchiver-psybsd/src/archive_store.c
   xarchiver/branches/xarchiver-psybsd/src/archive_store.h
   xarchiver/branches/xarchiver-psybsd/src/main_window.c
Log:
Add path-bar.
Clean up archive.c

Applied patch from Peter de Ridder <pc.ridder at zonnet.nl>
  Adds sortable to archive_store.


Modified: xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.c
===================================================================
--- xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.c	2006-10-07 08:34:17 UTC (rev 23305)
+++ xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.c	2006-10-07 14:40:42 UTC (rev 23306)
@@ -269,9 +269,9 @@
 	{
 		pos = (size / 2);
 
-		cmp = strcmp(filename, entry->children[pos+begin]->filename);
+		cmp = strcmp(filename, entry->children[begin+pos]->filename);
 		if(!cmp)
-			return entry->children[pos+begin];
+			return entry->children[begin+pos];
 
 		if(cmp < 0)
 		{
@@ -279,7 +279,7 @@
 		}
 		else
 		{
-			size = size - ++pos;
+			size -= ++pos;
 			begin += pos;
 		}
 	}
@@ -323,7 +323,7 @@
 		{
 			pos = (size / 2);
 
-			cmp = strcmp(buffer_iter->entry->filename, children_old[pos+begin]->filename);
+			cmp = strcmp(buffer_iter->entry->filename, children_old[begin+pos]->filename);
 			if(!cmp)
 				break;
 
@@ -333,7 +333,7 @@
 			}
 			else
 			{
-				size = size - ++pos;
+				size -= ++pos;
 				begin += pos;
 			}
 		}

Modified: xarchiver/branches/xarchiver-psybsd/src/archive_store.c
===================================================================
--- xarchiver/branches/xarchiver-psybsd/src/archive_store.c	2006-10-07 08:34:17 UTC (rev 23305)
+++ xarchiver/branches/xarchiver-psybsd/src/archive_store.c	2006-10-07 14:40:42 UTC (rev 23306)
@@ -89,6 +89,12 @@
 static gboolean
 xa_archive_store_has_default_sort_func(GtkTreeSortable *);
 
+static gint
+xa_archive_entry_compare(XAArchiveStore *store, LXAEntry *a, LXAEntry *b);
+
+static void
+xa_archive_store_sort(XAArchiveStore *store);
+
 GType
 xa_archive_store_get_type()
 {
@@ -307,9 +313,11 @@
 	}
 	else
 	{
-		//as long as it is a list depth is 0 other wise current_entry should be synced ?
-		//TODO: use lxa_entry_nth() or something
-		entry = lxa_entry_children_nth_data(entry, index);
+		/* as long as it is a list depth is 0 other wise current_entry should be synced ? */
+		if(store->sort_list)
+			entry = store->sort_list[index];
+		else
+			entry = lxa_entry_children_nth_data(entry, index);
 
 		g_return_val_if_fail(entry, FALSE);
 
@@ -334,7 +342,6 @@
 	g_return_val_if_fail(archive, NULL);
 
 	LXAEntry *entry = (LXAEntry*)iter->user_data2;
-//	gint pos = lxa_entry_children_index(store->current_entry, iter->user_data);
 	gint pos = GPOINTER_TO_INT(iter->user_data3);
 
 	if(store->props._show_up_dir && &archive->root_entry != entry)
@@ -370,11 +377,33 @@
 	LXAEntry *entry = ((LXAEntry *)iter->user_data);
 	gpointer props_iter = entry->props;
 	gint i = 1;
+	const gchar *icon_name = NULL;
+	ThunarVfsMimeDatabase *mime_base = NULL;
+	ThunarVfsMimeInfo *mime_info = NULL;
 
 	if(column == -1)
 	{
 		g_value_init(value, G_TYPE_STRING);
-		g_value_set_string(value, (strcmp(entry->filename, ".."))?entry->mime_type:"go-up");
+
+		if(strcmp(entry->filename, ".."))
+		{
+			if(store->icon_theme)
+			{
+				mime_base = thunar_vfs_mime_database_get_default();
+				mime_info = thunar_vfs_mime_database_get_info(mime_base, entry->mime_type);
+				icon_name = thunar_vfs_mime_info_lookup_icon_name(mime_info, store->icon_theme);
+
+				if(gtk_icon_theme_has_icon(store->icon_theme, icon_name))
+					g_value_set_string(value, icon_name);
+
+				thunar_vfs_mime_info_unref(mime_info);
+				g_object_unref(mime_base);
+			}
+		}
+		else
+		{
+			g_value_set_string(value, "gtk-go-up");
+		}
 	}
 	else if(column == 0)
 	{
@@ -382,23 +411,8 @@
 	}
 	else
 	{
-		if(!props_iter)
+		if(props_iter)
 		{
-			switch(archive->column_types[column])
-			{
-				case G_TYPE_STRING:
-					g_value_set_string(value, "");
-					break;
-				case G_TYPE_UINT64:
-					g_value_set_uint64(value, 0);
-					break;
-				case G_TYPE_UINT:
-					g_value_set_uint(value, 0);
-					break;
-			}
-		}
-		else
-		{
 			for(;i<column;i++)
 			{
 				switch(archive->column_types[i])
@@ -440,9 +454,12 @@
 	LXAEntry *entry = (LXAEntry*)iter->user_data2;
 	gint pos = GPOINTER_TO_INT(iter->user_data3);
 	pos++;
-	
-	entry = lxa_entry_children_nth_data(entry, pos);
 
+	if(store->sort_list)
+		entry = store->sort_list[pos];
+	else
+		entry = lxa_entry_children_nth_data(entry, pos);
+
 	if(!entry)
 		return FALSE;
 
@@ -475,7 +492,10 @@
 	}
 	else
 	{
-		entry = lxa_entry_children_nth_data(entry, 0);
+		if(store->sort_list)
+			entry = store->sort_list[0];
+		else
+			entry = lxa_entry_children_nth_data(entry, 0);
 	
 		g_return_val_if_fail(entry, FALSE);
 	
@@ -492,7 +512,6 @@
 static gboolean
 xa_archive_store_iter_has_child (GtkTreeModel *tree_model, GtkTreeIter *iter)
 {
-	//g_return_val_if_fail(XA_IS_ARCHIVE_STORE(tree_model), FALSE);
 	return FALSE;
 }
 
@@ -538,7 +557,10 @@
 	}
 	else
 	{
-		entry = lxa_entry_children_nth_data(entry, n);
+		if(store->sort_list)
+			entry = store->sort_list[n];
+		else
+			entry = lxa_entry_children_nth_data(entry, n);
 	
 		g_return_val_if_fail(entry, FALSE);
 	}
@@ -584,8 +606,15 @@
 	if(store->sort_column == sort_col_id && store->sort_order == order)
 		return;
 
+	if(store->props._show_icons && sort_col_id == 0)
+		return;
+
 	store->sort_column = sort_col_id;
 	store->sort_order = order;
+
+	xa_archive_store_sort(store);
+
+	gtk_tree_sortable_sort_column_changed(sortable);
 }
 
 static void
@@ -606,39 +635,146 @@
 	return TRUE;
 }
 
-
-GtkTreeModel *
-xa_archive_store_new(LXAArchive *archive, gboolean show_icons, gboolean show_up_dir)
+static gint
+xa_archive_entry_compare(XAArchiveStore *store, LXAEntry *a, LXAEntry *b)
 {
-	XAArchiveStore *tree_model;
-	GType *column_types;
-	gint x;
+	LXAEntry *swap = a;
+	if(store->sort_order == GTK_SORT_DESCENDING)
+	{
+		a = b;
+		b = swap;
+	}
+	
+	LXAArchive *archive = store->archive;
+	gint column = store->sort_column;
+	gpointer props_a = a->props;
+	gpointer props_b = b->props;
+	gint i = 0;
 
-	tree_model = g_object_new(XA_TYPE_ARCHIVE_STORE, NULL);
-	/*
-	if(show_icons)
+	if(store->props._show_icons)
+		column--;
+
+	if(column < 0)
+		return;
+
+	if(!props_a)
 	{
-		column_types = g_new0(GType, archive->column_number+1);
-		for(x = 0; x < archive->column_number; x++)
+		return props_b?-1:0;
+	}
+	if(!props_b)
+	{
+		return props_a?1:0;
+	}
+
+	if(column == 0)
+	{
+		props_a = &(a->filename);
+		props_b = &(b->filename);
+	}
+
+	for(i=1;i<column;i++)
+	{
+		switch(archive->column_types[i])
 		{
-			column_types[x+1] = archive->column_types[x];
+			case G_TYPE_STRING:
+				props_a+=sizeof(gchar *);
+				props_b+=sizeof(gchar *);
+				break;
+			case G_TYPE_UINT64:
+				props_a+=sizeof(guint64);
+				props_b+=sizeof(guint64);
+				break;
+			case G_TYPE_UINT:
+				props_a+=sizeof(guint);
+				props_b+=sizeof(guint);
+				break;
 		}
-		column_types[0] = G_TYPE_STRING;
-		tree_model->n_columns = archive->column_number + 1;
 	}
-	else
+
+	switch(archive->column_types[column])
 	{
-		column_types = g_new0(GType, archive->column_number);
-		for(x = 0; x < archive->column_number; x++)
+		case G_TYPE_STRING:
+			switch(/* string compare type */1)
+			{
+				default:
+					return strcmp(*((gchar**)props_a), *((gchar**)props_b));
+			}
+		case G_TYPE_UINT64:
+			return (*((guint64*)props_a)) - (*((guint64*)props_b));
+		case G_TYPE_UINT:
+			return (*((guint*)props_a)) - (*((guint*)props_b));
+	}
+}
+
+static void
+xa_archive_store_sort(XAArchiveStore *store)
+{
+	g_free(store->sort_list);
+	store->sort_list = NULL;
+
+	if(store->sort_column < 0)
+		return;
+
+	LXAEntry *pentry = (LXAEntry*)store->current_entry->data;
+	LXAEntry *entry = NULL;
+	gint psize = lxa_entry_children_length(pentry);
+	gint i = 0;
+	gint j = 0;
+	gint sort_size = 0;
+	gint size = 0;
+	gint pos = 0;
+	gint begin = 0;
+	gint cmp = 1;
+
+	if(psize <= 1)
+		return;
+
+	store->sort_list = g_new(LXAEntry*, psize);
+
+	for(i = 0; i < psize; i++)
+	{
+		size = sort_size;
+		begin = 0;
+
+		entry = lxa_entry_children_nth_data(pentry, i);
+		while(size)
 		{
-			column_types[x] = archive->column_types[x];
+			pos = size / 2;
+			cmp = xa_archive_entry_compare(store, entry, store->sort_list[begin+pos]);
+
+			if(cmp < 0)
+			{
+				size = pos;
+			}
+			else
+			{
+				size -= ++pos;
+				begin += pos;
+			}
 		}
-		tree_model->n_columns = archive->column_number;
+
+		for(j = sort_size; j > begin; j--)
+		{
+			store->sort_list[j] = store->sort_list[j-1];
+		}
+		store->sort_list[begin] = entry;
+
+		sort_size++;
 	}
-	tree_model->column_types = archive->column_types;
-	*/
+}
+
+GtkTreeModel *
+xa_archive_store_new(LXAArchive *archive, gboolean show_icons, gboolean show_up_dir, GtkIconTheme *icon_theme)
+{
+	XAArchiveStore *tree_model;
+	GType *column_types;
+	gint x;
+
+	tree_model = g_object_new(XA_TYPE_ARCHIVE_STORE, NULL);
+
 	tree_model->props._show_icons = show_icons;
 	tree_model->props._show_up_dir = show_up_dir;
+	tree_model->icon_theme = icon_theme;
 
 	xa_archive_store_set_contents(tree_model, archive);
 
@@ -690,7 +826,10 @@
 		gtk_tree_path_append_index(path_, i);
 
 		iter.stamp = store->stamp;
-		iter.user_data = lxa_entry_children_nth_data(entry, index);
+		if(store->sort_list)
+			iter.user_data = store->sort_list[i];
+		else
+			iter.user_data = lxa_entry_children_nth_data(&archive->root_entry, i);
 		iter.user_data2 = entry;
 		iter.user_data3 = GINT_TO_POINTER(index);
 
@@ -746,9 +885,13 @@
 	}
 	else
 	{
-		entry = lxa_entry_children_nth_data(entry, index);
+		if(store->sort_list)
+			entry = store->sort_list[index];
+		else
+			entry = lxa_entry_children_nth_data(entry, index);
 
 		g_return_if_fail(entry);
+
 		/* TODO Signal file-activated */
 		if(strcmp(entry->mime_type, "folder"))
 			return;
@@ -756,6 +899,8 @@
 		store->current_entry = g_slist_prepend(store->current_entry, entry);
 	}
 
+	xa_archive_store_sort(store);
+
 	xa_archive_store_refresh(store, prev_size);
 }
 
@@ -775,31 +920,17 @@
 		prev_size++;
 	}
 
+	/* TODO: signal or something */
+	g_return_if_fail(store->current_entry->next);
+
 	store->current_entry = g_slist_delete_link(store->current_entry, store->current_entry);
 	entry = store->current_entry->data;
 
-	// TODO: signal or something
-	g_return_if_fail(entry);
+	xa_archive_store_sort(store);
 
 	xa_archive_store_refresh(store, prev_size);
 }
 
-/*
-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 *store, LXAArchive *archive)
 {
@@ -842,13 +973,18 @@
 	store->archive = archive;
 	store->current_entry = g_slist_prepend(NULL, &archive->root_entry);
 
+	xa_archive_store_sort(store);
+
 	for(i = 0; i < lxa_entry_children_length(&archive->root_entry); i++)
 	{
 		path_ = gtk_tree_path_new();
 		gtk_tree_path_append_index(path_, i);
 
 		iter.stamp = store->stamp;
-		iter.user_data = lxa_entry_children_nth_data(&archive->root_entry, i);
+		if(store->sort_list)
+			iter.user_data = store->sort_list[i];
+		else
+			iter.user_data = lxa_entry_children_nth_data(&archive->root_entry, i);
 		iter.user_data2 = &archive->root_entry;
 		iter.user_data3 = GINT_TO_POINTER(i);
 

Modified: xarchiver/branches/xarchiver-psybsd/src/archive_store.h
===================================================================
--- xarchiver/branches/xarchiver-psybsd/src/archive_store.h	2006-10-07 08:34:17 UTC (rev 23305)
+++ xarchiver/branches/xarchiver-psybsd/src/archive_store.h	2006-10-07 14:40:42 UTC (rev 23306)
@@ -50,6 +50,7 @@
 	gint sort_column;
 	GtkSortType sort_order;
 	LXAEntry **sort_list;
+	GtkIconTheme *icon_theme;
 	struct {
 		gboolean _show_icons;
 		gboolean _show_up_dir;
@@ -67,7 +68,7 @@
 GType
 xa_archive_store_get_type();
 GtkTreeModel *
-xa_archive_store_new(LXAArchive *archive, gboolean show_icons, gboolean show_up_dir);
+xa_archive_store_new(LXAArchive *archive, gboolean show_icons, gboolean show_up_dir, GtkIconTheme *icon_theme);
 void
 xa_archive_store_set_contents(XAArchiveStore *archive_store, LXAArchive *archive);
 void

Modified: xarchiver/branches/xarchiver-psybsd/src/main_window.c
===================================================================
--- xarchiver/branches/xarchiver-psybsd/src/main_window.c	2006-10-07 08:34:17 UTC (rev 23305)
+++ xarchiver/branches/xarchiver-psybsd/src/main_window.c	2006-10-07 14:40:42 UTC (rev 23306)
@@ -692,7 +692,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, TRUE);
+		liststore = xa_archive_store_new(archive, TRUE, TRUE, window->icon_theme);
 
 		renderer = gtk_cell_renderer_pixbuf_new();
 		column = gtk_tree_view_column_new_with_attributes("", renderer, "icon-name", 0, NULL);
@@ -717,7 +717,7 @@
 	} else
 	{
 		//liststore = gtk_list_store_newv(archive->column_number, archive->column_types); 
-		liststore = xa_archive_store_new(archive, FALSE, TRUE);
+		liststore = xa_archive_store_new(archive, FALSE, TRUE, window->icon_theme);
 		for(x = 0; x < archive->column_number; x++)
 		{
 			switch(archive->column_types[x])

Added: xarchiver/branches/xarchiver-psybsd/src/path_bar.c
===================================================================
--- xarchiver/branches/xarchiver-psybsd/src/path_bar.c	                        (rev 0)
+++ xarchiver/branches/xarchiver-psybsd/src/path_bar.c	2006-10-07 14:40:42 UTC (rev 23306)
@@ -0,0 +1,80 @@
+/*
+ *  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 <string.h>
+#include <glib.h>
+#include <gtk/gtk.h>
+#include <libxarchiver/libxarchiver.h>
+#include "archive_store.h"
+#include "path_bar.h"
+
+
+static void
+xa_path_bar_class_init(XAPathBarClass *archive_class);
+
+static void
+xa_path_bar_init(XAPathBar *archive);
+
+GType
+xa_path_bar_get_type ()
+{
+	static GType xa_path_bar_type = 0;
+
+ 	if (!xa_path_bar_type)
+	{
+ 		static const GTypeInfo xa_path_bar_info = 
+		{
+			sizeof (XAPathBarClass),
+			(GBaseInitFunc) NULL,
+			(GBaseFinalizeFunc) NULL,
+			(GClassInitFunc) xa_path_bar_class_init,
+			(GClassFinalizeFunc) NULL,
+			NULL,
+			sizeof (XAPathBar),
+			0,
+			(GInstanceInitFunc) xa_path_bar_init,
+			NULL
+		};
+
+		xa_path_bar_type = g_type_register_static (GTK_TYPE_TOOLBAR, "XAPathBar", &xa_path_bar_info, 0);
+	}
+	return xa_path_bar_type;
+}
+
+static void
+xa_path_bar_class_init(XAPathBarClass *dialog_class)
+{
+}
+
+static void
+xa_path_bar_init(XAPathBar *dialog)
+{
+}
+
+GtkWidget *
+xa_path_bar_new(XAArchiveStore *store)
+{
+	XAPathBar *bar;
+
+	bar = g_object_new(XA_TYPE_PATH_BAR, NULL);
+
+	bar->store = store;
+
+	return GTK_WIDGET(bar);
+}

Added: xarchiver/branches/xarchiver-psybsd/src/path_bar.h
===================================================================
--- xarchiver/branches/xarchiver-psybsd/src/path_bar.h	                        (rev 0)
+++ xarchiver/branches/xarchiver-psybsd/src/path_bar.h	2006-10-07 14:40:42 UTC (rev 23306)
@@ -0,0 +1,62 @@
+/*
+ *  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_PATH_BAR_H__
+#define __XARCHIVER_PATH_BAR_H__
+G_BEGIN_DECLS
+
+#define XA_TYPE_PATH_BAR xa_path_bar_get_type()
+
+#define XA_PATH_BAR(obj)(                \
+		G_TYPE_CHECK_INSTANCE_CAST ((obj),  \
+			XA_TYPE_PATH_BAR,                  \
+			XAPathBar))
+
+#define XA_IS_PATH_BAR(obj)      ( \
+		G_TYPE_CHECK_INSTANCE_TYPE ((obj),    \
+			XA_TYPE_PATH_BAR))
+
+#define XA_PATH_BAR_CLASS(klass) ( \
+		G_TYPE_CHECK_CLASS_CAST ((klass),     \
+			XA_TYPE_PATH_BAR,      \
+			XAPathBarClass))
+
+#define XA_IS_PATH_BAR_CLASS(class) ( \
+		G_TYPE_CHECK_CLASS_TYPE ((class),        \
+			XA_TYPE_PATH_BAR()))	
+
+typedef struct _XAPathBar XAPathBar;
+
+struct _XAPathBar
+{
+	GtkToolbar parent;
+	XAArchiveStore *store;
+};
+
+typedef struct _XAPathBarClass XAPathBarClass;
+
+struct _XAPathBarClass
+{
+	GtkToolbarClass parent_class;
+};
+
+GType      xa_path_bar_get_type();
+GtkWidget *xa_path_bar_new();
+
+G_END_DECLS
+#endif /* __XARCHIVER_EXTRACT_ARCHIVE_DIALOG_H__ */



More information about the Xfce4-commits mailing list