[Xfce4-commits] r23289 - in xarchiver/branches/xarchiver-psybsd: libxarchiver src
Stephan Arts
stephan at xfce.org
Thu Oct 5 11:07:35 UTC 2006
Author: stephan
Date: 2006-10-05 11:07:34 +0000 (Thu, 05 Oct 2006)
New Revision: 23289
Modified:
xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.c
xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.h
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:
Applied patch from Peter de Ridder <pc.ridder at zonnet.nl>
Fixed segfault.
Modified: xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.c
===================================================================
--- xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.c 2006-10-05 10:17:31 UTC (rev 23288)
+++ xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.c 2006-10-05 11:07:34 UTC (rev 23289)
@@ -31,7 +31,7 @@
#include "internals.h"
-#define LXA_ENTRY_CHILD_BUFFER_SIZE 300
+#define LXA_ENTRY_CHILD_BUFFER_SIZE 3
static void
@@ -188,6 +188,7 @@
gchar **path_items;
LXAEntry *tmp_entry = NULL, *parent = NULL;
path_items = g_strsplit_set(path, "/\n", -1);
+/*
tmp_entry = lxa_entry_get_child(&archive->root_entry, path_items[0]);
if(!tmp_entry)
{
@@ -198,11 +199,12 @@
else
tmp_entry->is_folder = FALSE;
lxa_entry_add_child(&archive->root_entry, tmp_entry);
- lxa_entry_flush_buffer(&archive->root_entry);
+// lxa_entry_flush_buffer(&archive->root_entry);
}
- for(i = 1; path_items[i]?strlen(path_items[i]):0;i++)
+*/
+ parent = &archive->root_entry;
+ for(i = 0; path_items[i]?strlen(path_items[i]):0;i++)
{
- parent = tmp_entry;
tmp_entry = lxa_entry_get_child(parent, path_items[i]);
if(!tmp_entry)
{
@@ -212,7 +214,7 @@
if(path[strlen(path)-1] == '/')
{
tmp_entry->is_folder = TRUE;
- lxa_entry_flush_buffer(parent);
+// lxa_entry_flush_buffer(parent);
}
else
tmp_entry->is_folder = FALSE;
@@ -260,21 +262,39 @@
return 0;
}
+//TODO: why does this have a return value?
gboolean
lxa_entry_add_child(LXAEntry *parent, LXAEntry *child)
{
- 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);
+ gint cmp = 1;
+ GSList *buffer_iter = parent->buffer;
+ GSList *prev_entry = NULL;
+ GSList *new_entry = NULL;
+
+ for(; buffer_iter; buffer_iter = buffer_iter->next)
+ {
+ cmp = strcmp(child->filename, ((LXAEntry*)buffer_iter->data)->filename);
+
+ if(!cmp)
+ {
+ /* TODO: merge same as in flush */
+ return;
+ }
+ if(cmp < 0)
+ break;
+
+ prev_entry = buffer_iter;
+ }
+
+ new_entry = g_new(GSList, 1);
+ new_entry->next = buffer_iter;
+ new_entry->data = child;
+
+ if(prev_entry)
+ prev_entry->next = new_entry;
+ else
+ parent->buffer = new_entry;
+
if(g_slist_length(parent->buffer) == LXA_ENTRY_CHILD_BUFFER_SIZE)
lxa_entry_flush_buffer(parent);
}
@@ -282,16 +302,18 @@
LXAEntry *
lxa_entry_get_child(LXAEntry *entry, const gchar *filename)
{
+ GSList *buffer_iter = NULL;
guint size = entry->n_children;
guint pos = 0;
+ guint begin = 0;
gint cmp = 0;
while(size)
{
pos = (size / 2);
- cmp = strcmp(filename, entry->children[pos]->filename);
+ cmp = strcmp(filename, entry->children[pos+begin]->filename);
if(!cmp)
- return entry->children[pos];
+ return entry->children[pos+begin];
if(cmp < 0)
{
@@ -300,15 +322,26 @@
else
{
size = size - ++pos;
+ begin += pos;
}
}
+
+ for(buffer_iter = entry->buffer; buffer_iter; buffer_iter = buffer_iter->next)
+ {
+ cmp = strcmp(filename, ((LXAEntry*)buffer_iter->data)->filename);
+
+ if(!cmp)
+ return buffer_iter->data;
+ if(cmp < 0)
+ break;
+ }
+
return NULL;
}
void
lxa_entry_flush_buffer(LXAEntry *entry)
{
- g_debug("Flush");
guint max_children = 0;
guint begin = 0;
guint pos = 0;
@@ -327,20 +360,20 @@
size = entry->n_children - begin;
while(size)
{
- pos = (size / 2)+begin;
+ pos = (size / 2);
- cmp = strcmp(((LXAEntry *)buffer_iter->data)->filename, children_old[pos]->filename);
+ cmp = strcmp(((LXAEntry *)buffer_iter->data)->filename, children_old[pos+begin]->filename);
if(!cmp)
break;
if(cmp < 0)
{
- size = pos - begin;
+ size = pos;
}
else
{
- size = size + begin - ++pos;
- begin = pos;
+ size = size - ++pos;
+ begin += pos;
}
}
if(!cmp)
@@ -349,7 +382,7 @@
}
else
{
- while(old_i < pos)
+ while(old_i < begin)
{
entry->children[new_i++] = children_old[old_i++];
}
@@ -361,10 +394,24 @@
entry->children[new_i++] = children_old[old_i++];
}
entry->n_children = new_i;
- g_debug("%d", entry->n_children);
-
- g_slist_free(entry->buffer);
+
+ if(entry->buffer)
+ g_slist_free(entry->buffer);
entry->buffer = NULL;
g_free(children_old);
}
+
+guint lxa_entry_children_length(LXAEntry *entry)
+{
+ g_return_val_if_fail(entry, 0);
+ return entry->n_children;
+}
+
+LXAEntry *lxa_entry_children_nth_data(LXAEntry *entry, guint n)
+{
+ g_return_val_if_fail(entry, NULL);
+ g_return_val_if_fail(n >= 0 && n < entry->n_children, NULL);
+ return entry->children[n];
+}
+
Modified: xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.h
===================================================================
--- xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.h 2006-10-05 10:17:31 UTC (rev 23288)
+++ xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.h 2006-10-05 11:07:34 UTC (rev 23289)
@@ -105,6 +105,9 @@
LXAEntry *lxa_entry_get_child(LXAEntry *, const gchar *);
gboolean lxa_entry_add_child(LXAEntry *parent, LXAEntry *child);
void lxa_entry_flush_buffer(LXAEntry *entry);
+guint lxa_entry_children_length(LXAEntry *entry);
+LXAEntry *lxa_entry_children_nth_data(LXAEntry *entry, guint n);
+//gint lxa_entry_children_index(LXAEntry *entry, LXAEntry *find);
G_END_DECLS
Modified: xarchiver/branches/xarchiver-psybsd/src/archive_store.c
===================================================================
--- xarchiver/branches/xarchiver-psybsd/src/archive_store.c 2006-10-05 10:17:31 UTC (rev 23288)
+++ xarchiver/branches/xarchiver-psybsd/src/archive_store.c 2006-10-05 11:07:34 UTC (rev 23289)
@@ -17,6 +17,7 @@
*/
#include <config.h>
+#include <string.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <libxarchiver/libxarchiver.h>
@@ -31,6 +32,10 @@
static void
xa_archive_tree_model_init(GtkTreeModelIface *tm_interface);
+static void
+xa_archive_tree_sartable_init(GtkTreeSortableIface *ts_interface);
+
+/* tree model */
static GtkTreeModelFlags
xa_archive_store_get_flags(GtkTreeModel *tree_model);
static gint
@@ -56,6 +61,16 @@
static gboolean
xa_archive_store_iter_parent (GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreeIter *child);
+static void
+cb_xa_archive_store_row_activated(GtkTreeView *treeview, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data);
+
+/* tree sortable */
+static gboolean
+xa_archive_store_get_sort_column_id(GtkTreeSortable *sortable, gint *sort_col_id, GtkSortType *order);
+static void
+xa_archive_store_set_sort_column_id(GtkTreeSortable *sortable, gint sort_col_id, GtkSortType order);
+
+
GType
xa_archive_store_get_type()
{
@@ -114,6 +129,11 @@
xa_archive_store_init(XAArchiveStore *as)
{
as->stamp = g_random_int();
+ as->archive = NULL;
+ as->current_entry = NULL;
+ as->props._show_icons = FALSE;
+ as->n_columns = 0;
+ as->column_types = NULL;
}
static void
@@ -123,52 +143,108 @@
}
+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_get_n_columns(GtkTreeModel *tree_model)
+{
+ g_return_val_if_fail(XA_IS_ARCHIVE_STORE(tree_model), 0);
+
+ XAArchiveStore *store = XA_ARCHIVE_STORE(tree_model);
+
+ return store->n_columns + store->props._show_icons?1:0;
+}
+
+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);
+
+ XAArchiveStore *store = XA_ARCHIVE_STORE(tree_model);
+
+ if(store->props._show_icons)
+ {
+ if(index == 0)
+ return G_TYPE_STRING;
+ index--;
+ }
+
+ g_return_val_if_fail(index < store->n_columns, G_TYPE_INVALID);
+
+ return store->column_types[index];
+}
+
static gboolean
xa_archive_store_get_iter(GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreePath *path)
{
+ g_return_val_if_fail(XA_IS_ARCHIVE_STORE(tree_model), FALSE);
+
XAArchiveStore *store = XA_ARCHIVE_STORE(tree_model);
+ LXAArchive *archive = store->archive;
+ LXAEntry *entry = store->current_entry->data;
+ g_return_val_if_fail(archive, FALSE);
+ g_return_val_if_fail(entry, FALSE);
+
gint *indices = gtk_tree_path_get_indices(path);
+ gint depth = gtk_tree_path_get_depth(path) - 1;
- if(indices[0] >= g_slist_length(store->rows) || indices[0] < 0)
- return FALSE;
+ /* only support list: depth is always 0 */
+ g_return_val_if_fail(depth == 0, FALSE);
- GSList *entry = g_slist_nth(store->rows, indices[0]);
- if(!entry)
- return FALSE;
+ gint index = indices[depth];
+ if(&archive->root_entry != entry)
+ index--;
+
+ if(index == -1)
+ {
+ entry = &store->up_entry;
+ }
+ 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);
+
+ g_return_val_if_fail(entry, FALSE);
+
+ }
+
iter->stamp = store->stamp;
iter->user_data = entry;
- iter->user_data2 = NULL;
- iter->user_data3 = NULL;
+ iter->user_data2 = store->current_entry->data;
+ iter->user_data3 = GINT_TO_POINTER(index);
return TRUE;
}
static GtkTreePath *
xa_archive_store_get_path (GtkTreeModel *tree_model, GtkTreeIter *iter)
{
- GtkTreePath *path = NULL;
+ g_return_val_if_fail(XA_IS_ARCHIVE_STORE(tree_model), 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;
-}
+ LXAArchive *archive = store->archive;
+ g_return_val_if_fail(archive, NULL);
-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;
+ 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(&archive->root_entry != entry)
+ pos++;
+
+ GtkTreePath *path = gtk_tree_path_new();
+ gtk_tree_path_append_index(path, pos);
+
+ return path;
}
@@ -177,57 +253,78 @@
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 *store = XA_ARCHIVE_STORE(tree_model);
+ LXAArchive *archive = store->archive;
- XAArchiveStore *archive_store = XA_ARCHIVE_STORE(tree_model);
+ g_return_if_fail(archive);
- LXAEntry *entry = ((GSList *)iter->user_data)->data;
+ if(store->props._show_icons)
+ column--;
+
+ g_return_if_fail (column < store->n_columns);
+
+ if(column >= 0)
+ g_value_init(value, store->column_types[column]);
+
+ LXAEntry *entry = ((LXAEntry *)iter->user_data);
gpointer props_iter = entry->props;
+ gint i = 1;
- if((column == 1 && archive_store->props._show_icons) || (column == 0))
+ if(strcmp(entry->filename, "..") == 0)
{
- if(archive_store->props._show_icons && column == 0)
- g_value_set_string(value, "unknown");
- else
+ if(column == -1)
+ {
+ g_value_init(value, G_TYPE_STRING);
+ g_value_set_string(value, "go-up");
+ }
+ else if(column == 0)
+ {
+ g_value_set_string(value, "..");
+ }
+ }
+ else
+ {
+ if(column == -1)
+ {
+ g_value_init(value, G_TYPE_STRING);
+ g_value_set_string(value, entry->is_folder?"folder":"unknown");
+ }
+ else if(column == 0)
+ {
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])
+ for(;i<column;i++)
{
+ switch(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(store->column_types[column])
+ {
case G_TYPE_STRING:
- props_iter+=sizeof(gchar *);
+ g_value_set_string(value, *(gchar **)props_iter);
break;
case G_TYPE_UINT64:
- props_iter+=sizeof(guint64);
+ g_value_set_uint64(value, *(guint64 *)props_iter);
break;
case G_TYPE_UINT:
- props_iter+=sizeof(guint);
+ g_value_set_uint(value, *(guint *)props_iter);
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;
- }
}
}
@@ -235,80 +332,128 @@
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;
+ XAArchiveStore *store = XA_ARCHIVE_STORE(tree_model);
+
+ LXAEntry *entry = (LXAEntry*)iter->user_data2;
+ gint pos = GPOINTER_TO_INT(iter->user_data3);
+ pos++;
- iter->stamp = XA_ARCHIVE_STORE(tree_model)->stamp;
- iter->user_data = ((GSList *)iter->user_data)->next;
+ entry = lxa_entry_children_nth_data(entry, pos);
+
+ g_return_val_if_fail(entry, FALSE);
+
+ iter->stamp = store->stamp;
+ iter->user_data = entry;
+ iter->user_data3 = GINT_TO_POINTER(pos);
return TRUE;
}
static gboolean
-xa_archive_store_iter_parent (GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreeIter *child)
+xa_archive_store_iter_children (GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreeIter *parent)
{
- return FALSE;
-}
+ g_return_val_if_fail(XA_IS_ARCHIVE_STORE(tree_model), FALSE);
+ XAArchiveStore *store = XA_ARCHIVE_STORE(tree_model);
+ LXAArchive *archive = store->archive;
+ LXAEntry *entry = store->current_entry->data;
-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);
+ g_return_val_if_fail(archive, FALSE);
+ g_return_val_if_fail(entry, FALSE);
+
+ /* only support lists: parent is always NULL */
+ g_return_val_if_fail(parent == NULL, FALSE);
+
+ if(&archive->root_entry != entry)
+ {
+ entry = &store->up_entry;
+ iter->user_data3 = GINT_TO_POINTER(-1);
+ }
+ else
+ {
+ entry = lxa_entry_children_nth_data(entry, 0);
- if(g_slist_length(archive_store->rows) == 0)
- return FALSE;
+ g_return_val_if_fail(entry, FALSE);
- iter->stamp = archive_store->stamp;
- iter->user_data = archive_store->rows;
+ iter->user_data3 = GINT_TO_POINTER(0);
+ }
+ iter->stamp = store->stamp;
+ iter->user_data = entry;
+ iter->user_data2 = store->current_entry->data;
+
return TRUE;
}
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;
}
-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)
+xa_archive_store_iter_n_children (GtkTreeModel *tree_model, GtkTreeIter *iter)
{
g_return_val_if_fail(XA_IS_ARCHIVE_STORE(tree_model), 0);
-
- return XA_ARCHIVE_STORE(tree_model)->n_columns;
+
+ XAArchiveStore *store = XA_ARCHIVE_STORE(tree_model);
+ LXAArchive *archive = store->archive;
+ LXAEntry *entry = store->current_entry->data;
+
+ g_return_val_if_fail(archive, 0);
+ g_return_val_if_fail(entry, 0);
+
+ /* only support lists: iter is always NULL */
+ g_return_val_if_fail(iter == NULL, FALSE);
+
+ return lxa_entry_children_length(entry) + (&archive->root_entry == entry)?0:1;
}
-static GtkTreeModelFlags
-xa_archive_store_get_flags(GtkTreeModel *tree_model)
+static gboolean
+xa_archive_store_iter_nth_child (GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreeIter *parent, gint n)
{
- g_return_val_if_fail(XA_IS_ARCHIVE_STORE(tree_model), (GtkTreeModelFlags)0);
+ g_return_val_if_fail(XA_IS_ARCHIVE_STORE(tree_model), FALSE);
- return (GTK_TREE_MODEL_LIST_ONLY | GTK_TREE_MODEL_ITERS_PERSIST);
+ XAArchiveStore *store = XA_ARCHIVE_STORE(tree_model);
+ LXAArchive *archive = store->archive;
+ LXAEntry *entry = store->current_entry->data;
+
+ g_return_val_if_fail(archive, FALSE);
+ g_return_val_if_fail(entry, FALSE);
+
+ /* only support lists: parent is always NULL */
+ g_return_val_if_fail(parent == NULL, FALSE);
+
+ if(&archive->root_entry != entry)
+ n--;
+
+ if(n == -1)
+ {
+ entry = &store->up_entry;
+ }
+ else
+ {
+ entry = lxa_entry_children_nth_data(entry, n);
+
+ g_return_val_if_fail(entry, FALSE);
+ }
+
+ iter->stamp = store->stamp;
+ iter->user_data = entry;
+ iter->user_data2 = store->current_entry->data;
+ iter->user_data3 = GINT_TO_POINTER(n);
+
+ return TRUE;
}
-static gint
-xa_archive_store_iter_n_children (GtkTreeModel *tree_model, GtkTreeIter *iter)
+static gboolean
+xa_archive_store_iter_parent (GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreeIter *child)
{
- g_return_val_if_fail(XA_IS_ARCHIVE_STORE(tree_model), -1);
- g_return_val_if_fail(iter == NULL || iter->user_data != NULL, 0);
+ return FALSE;
+}
- 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)
{
@@ -317,6 +462,7 @@
gint x;
tree_model = g_object_new(XA_TYPE_ARCHIVE_STORE, NULL);
+ /*
if(show_icons)
{
column_types = g_new0(GType, archive->column_number+1);
@@ -337,12 +483,111 @@
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);
}
+void
+xa_archive_store_connect_treeview(XAArchiveStore *store, GtkTreeView *treeview)
+{
+ g_signal_connect(G_OBJECT(treeview), "row-activated", G_CALLBACK(cb_xa_archive_store_row_activated), store);
+}
+
+static void
+cb_xa_archive_store_row_activated(GtkTreeView *treeview, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data)
+{
+ g_return_if_fail(XA_IS_ARCHIVE_STORE(user_data));
+
+ XAArchiveStore *store = XA_ARCHIVE_STORE(user_data);
+ LXAArchive *archive = store->archive;
+ LXAEntry *entry = store->current_entry->data;
+
+ g_return_if_fail(archive);
+ g_return_if_fail(entry);
+
+ gint *indices = gtk_tree_path_get_indices(path);
+ gint depth = gtk_tree_path_get_depth(path) - 1;
+
+ /* only support list: depth is always 0 */
+ g_return_if_fail(depth == 0);
+
+ gint prev_size = lxa_entry_children_length(entry);
+ gint new_size = 0;
+ gint index = indices[depth];
+ gint i = 0;
+ GtkTreePath *path_ = NULL;
+ GtkTreeIter *iter = NULL;
+
+ if(&archive->root_entry != entry)
+ index--;
+
+ if(index == -1)
+ {
+ store->current_entry = g_slist_delete_link(store->current_entry, store->current_entry);
+ entry = store->current_entry->data;
+ }
+ else
+ {
+ entry = lxa_entry_children_nth_data(entry, index);
+
+ g_return_if_fail(entry);
+ g_return_if_fail(entry->is_folder);
+
+ store->current_entry = g_slist_prepend(store->current_entry, entry);
+ }
+
+ new_size = lxa_entry_children_length(entry);
+
+ if(&archive->root_entry != entry)
+ {
+ path_ = gtk_tree_path_new();
+ gtk_tree_path_append_index(path_, 0);
+
+ iter = g_new(GtkTreeIter, 1);
+
+ iter->stamp = store->stamp;
+ iter->user_data = &store->up_entry;
+ iter->user_data2 = entry;
+ iter->user_data3 = GINT_TO_POINTER(-1);
+
+ if(0 < prev_size)
+ gtk_tree_model_row_changed(GTK_TREE_MODEL(store), path, iter);
+ else
+ gtk_tree_model_row_inserted(GTK_TREE_MODEL(store), path, iter);
+
+ i=1;
+ }
+
+ for(index = 0; i < new_size; i++, index++)
+ {
+ path_ = gtk_tree_path_new();
+ gtk_tree_path_append_index(path_, i);
+
+ iter = g_new(GtkTreeIter, 1);
+
+ iter->stamp = store->stamp;
+ iter->user_data = lxa_entry_children_nth_data(entry, index);
+ iter->user_data2 = entry;
+ iter->user_data3 = GINT_TO_POINTER(index);
+
+ if(i < prev_size)
+ gtk_tree_model_row_changed(GTK_TREE_MODEL(store), path_, iter);
+ else
+ gtk_tree_model_row_inserted(GTK_TREE_MODEL(store), path_, iter);
+ }
+ for(; i < prev_size; i++)
+ {
+ path_ = gtk_tree_path_new();
+ gtk_tree_path_append_index(path_, i);
+
+ gtk_tree_model_row_deleted(GTK_TREE_MODEL(store), path_);
+ }
+}
+
+/*
gboolean
xa_archive_store_add_item(gpointer key, gpointer value, gpointer data)
{
@@ -356,9 +601,43 @@
gtk_tree_path_free(path);
return FALSE;
}
+*/
void
-xa_archive_store_set_contents(XAArchiveStore *archive_store, GTree *items, gboolean is_root)
+xa_archive_store_set_contents(XAArchiveStore *store, LXAArchive *archive)
{
- g_tree_foreach(items, (GTraverseFunc)xa_archive_store_add_item, archive_store);
+ g_return_if_fail(store);
+ g_return_if_fail(archive);
+
+ gint i= 0;
+ GtkTreePath *path_ = NULL;
+ GtkTreeIter *iter = NULL;
+
+ store->archive = archive;
+ store->current_entry = g_slist_prepend(NULL, &archive->root_entry);
+
+ store->up_entry.filename = "..";
+
+ store->n_columns = archive->column_number + 1;
+
+ store->column_types = g_new(GType, store->n_columns);
+
+ store->column_types[0] = G_TYPE_STRING;
+
+ memcpy(store->column_types + 1, archive->column_types, archive->column_number);
+
+ for(; i < lxa_entry_children_length(&archive->root_entry); i++)
+ {
+ path_ = gtk_tree_path_new();
+ gtk_tree_path_append_index(path_, i);
+
+ iter = g_new(GtkTreeIter, 1);
+
+ iter->stamp = store->stamp;
+ 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);
+
+ gtk_tree_model_row_inserted(GTK_TREE_MODEL(store), path_, iter);
+ }
}
Modified: xarchiver/branches/xarchiver-psybsd/src/archive_store.h
===================================================================
--- xarchiver/branches/xarchiver-psybsd/src/archive_store.h 2006-10-05 10:17:31 UTC (rev 23288)
+++ xarchiver/branches/xarchiver-psybsd/src/archive_store.h 2006-10-05 11:07:34 UTC (rev 23289)
@@ -46,7 +46,9 @@
gint stamp;
guint n_columns;
GType *column_types;
- GSList *rows;
+ LXAArchive *archive;
+ GSList *current_entry;
+ LXAEntry up_entry;
struct {
gboolean _show_icons;
} props;
@@ -65,6 +67,6 @@
GtkTreeModel *
xa_archive_store_new(LXAArchive *archive, gboolean show_icons);
void
-xa_archive_store_set_contents(XAArchiveStore *archive_store, GTree *items, gboolean is_root);
+xa_archive_store_set_contents(XAArchiveStore *archive_store, LXAArchive *archive);
#endif /* __XARCHIVER_ARCHIVE_STORE_H__ */
Modified: xarchiver/branches/xarchiver-psybsd/src/main_window.c
===================================================================
--- xarchiver/branches/xarchiver-psybsd/src/main_window.c 2006-10-05 10:17:31 UTC (rev 23288)
+++ xarchiver/branches/xarchiver-psybsd/src/main_window.c 2006-10-05 11:07:34 UTC (rev 23289)
@@ -594,7 +594,6 @@
gtk_widget_set_sensitive(GTK_WIDGET(window->toolbar.tool_item_remove), FALSE);
gtk_widget_set_sensitive(GTK_WIDGET(window->toolbar.tool_item_extract), FALSE);
gtk_widget_set_sensitive(GTK_WIDGET(window->toolbar.tool_item_stop), FALSE);
- g_debug("AAA");
}
gint
@@ -793,7 +792,6 @@
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)
{
More information about the Xfce4-commits
mailing list