Author: stephan Date: 2006-10-05 13:44:18 +0000 (Thu, 05 Oct 2006) New Revision: 23290
Added: xarchiver/branches/xarchiver-psybsd/libxarchiver/slist.c xarchiver/branches/xarchiver-psybsd/libxarchiver/slist.h Modified: xarchiver/branches/xarchiver-psybsd/libxarchiver/Makefile.am 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/main_window.c Log: Added custom (not working) treemodel Modified: xarchiver/branches/xarchiver-psybsd/libxarchiver/Makefile.am =================================================================== --- xarchiver/branches/xarchiver-psybsd/libxarchiver/Makefile.am 2006-10-05 11:07:34 UTC (rev 23289) +++ xarchiver/branches/xarchiver-psybsd/libxarchiver/Makefile.am 2006-10-05 13:44:18 UTC (rev 23290) @@ -3,6 +3,7 @@ libxarchiver_a_SOURCES = \ libxarchiver.c libxarchiver.h \ internals.c internals.h \ + slist.c slist.h \ archive.c archive.h \ archive-support.c archive-support.h \ archive-support-zip.c archive-support-zip.h \ Modified: xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.c =================================================================== --- xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.c 2006-10-05 11:07:34 UTC (rev 23289) +++ xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.c 2006-10-05 13:44:18 UTC (rev 23290) @@ -31,7 +31,7 @@ #include "internals.h" -#define LXA_ENTRY_CHILD_BUFFER_SIZE 3 +#define LXA_ENTRY_CHILD_BUFFER_SIZE 300 static void @@ -266,43 +266,16 @@ gboolean lxa_entry_add_child(LXAEntry *parent, LXAEntry *child) { - gint cmp = 1; - GSList *buffer_iter = parent->buffer; - GSList *prev_entry = NULL; - GSList *new_entry = NULL; + parent->buffer = lxa_slist_insert_sorted_single(parent->buffer, child); - 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) + if(lxa_slist_length(parent->buffer) == LXA_ENTRY_CHILD_BUFFER_SIZE) lxa_entry_flush_buffer(parent); } LXAEntry * lxa_entry_get_child(LXAEntry *entry, const gchar *filename) { - GSList *buffer_iter = NULL; + LXASList *buffer_iter = NULL; guint size = entry->n_children; guint pos = 0; guint begin = 0; @@ -328,10 +301,10 @@ for(buffer_iter = entry->buffer; buffer_iter; buffer_iter = buffer_iter->next) { - cmp = strcmp(filename, ((LXAEntry*)buffer_iter->data)->filename); + cmp = strcmp(filename, buffer_iter->entry->filename); if(!cmp) - return buffer_iter->data; + return buffer_iter->entry; if(cmp < 0) break; } @@ -342,6 +315,9 @@ void lxa_entry_flush_buffer(LXAEntry *entry) { + if(!entry->buffer) + return; + guint max_children = 0; guint begin = 0; guint pos = 0; @@ -349,10 +325,10 @@ guint old_i = 0; guint new_i = 0; guint size = entry->n_children; - GSList *buffer_iter = NULL; + LXASList *buffer_iter = NULL; LXAEntry **children_old = (LXAEntry **)entry->children; - max_children = (entry->n_children + g_slist_length(entry->buffer)); + max_children = (entry->n_children + lxa_slist_length(entry->buffer)); entry->children = g_new(LXAEntry *, max_children); for(buffer_iter = entry->buffer;buffer_iter;buffer_iter = buffer_iter->next) @@ -362,7 +338,7 @@ { pos = (size / 2); - cmp = strcmp(((LXAEntry *)buffer_iter->data)->filename, children_old[pos+begin]->filename); + cmp = strcmp(buffer_iter->entry->filename, children_old[pos+begin]->filename); if(!cmp) break; @@ -386,7 +362,7 @@ { entry->children[new_i++] = children_old[old_i++]; } - entry->children[new_i++] = buffer_iter->data; + entry->children[new_i++] = buffer_iter->entry; } } while(old_i < entry->n_children) @@ -395,8 +371,7 @@ } entry->n_children = new_i; - if(entry->buffer) - g_slist_free(entry->buffer); + lxa_slist_free(entry->buffer); entry->buffer = NULL; g_free(children_old); @@ -405,12 +380,13 @@ guint lxa_entry_children_length(LXAEntry *entry) { g_return_val_if_fail(entry, 0); - return entry->n_children; + return entry->n_children + lxa_slist_length(entry->buffer); } LXAEntry *lxa_entry_children_nth_data(LXAEntry *entry, guint n) { g_return_val_if_fail(entry, NULL); + lxa_entry_flush_buffer(entry); 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 11:07:34 UTC (rev 23289) +++ xarchiver/branches/xarchiver-psybsd/libxarchiver/archive.h 2006-10-05 13:44:18 UTC (rev 23290) @@ -31,8 +31,11 @@ LXA_ARCHIVESTATUS_USERBREAK } LXAArchiveStatus; + typedef struct _LXAEntry LXAEntry; +#include "slist.h" + struct _LXAEntry { gchar *filename; gboolean is_folder; @@ -40,7 +43,7 @@ /* */ LXAEntry **children; guint n_children; - GSList *buffer; + LXASList *buffer; }; #define LXA_ARCHIVE(obj) ( \ Added: xarchiver/branches/xarchiver-psybsd/libxarchiver/slist.c =================================================================== --- xarchiver/branches/xarchiver-psybsd/libxarchiver/slist.c (rev 0) +++ xarchiver/branches/xarchiver-psybsd/libxarchiver/slist.c 2006-10-05 13:44:18 UTC (rev 23290) @@ -0,0 +1,60 @@ + +#include <glib.h> +#include <glib-object.h> + +#include "archive.h" + +LXASList * +lxa_slist_insert_sorted_single(LXASList *list, LXAEntry *entry) +{ + gint cmp = 1; + LXASList *iter = list; + LXASList *prev_entry = NULL; + LXASList *new_entry = NULL; + + for(; iter; iter = iter->next) + { + cmp = strcmp(entry->filename, ((LXAEntry*)iter->entry)->filename); + + if(!cmp) + { + /* TODO: merge same as in flush */ + return; + } + if(cmp < 0) + break; + + prev_entry = iter; + } + + new_entry = g_new(LXASList, 1); + new_entry->next = iter; + new_entry->entry = entry; + + if(!prev_entry) + return new_entry; + + prev_entry->next = new_entry; + return list; +} + +guint +lxa_slist_length(LXASList *list) +{ + guint size = 0; + for(; list; list = list->next) + size++; + return size; +} + +void +lxa_slist_free(LXASList *list) +{ + LXASList *next; + for(; list; list = next) + { + next = list->next; + g_free(list); + } +} + Added: xarchiver/branches/xarchiver-psybsd/libxarchiver/slist.h =================================================================== --- xarchiver/branches/xarchiver-psybsd/libxarchiver/slist.h (rev 0) +++ xarchiver/branches/xarchiver-psybsd/libxarchiver/slist.h 2006-10-05 13:44:18 UTC (rev 23290) @@ -0,0 +1,17 @@ + +typedef struct _LXASList LXASList; + +struct _LXASList { + LXAEntry *entry; + LXASList *next; +}; + +LXASList * +lxa_slist_insert_sorted_single(LXASList *list, LXAEntry *entry); + +guint +lxa_slist_length(LXASList *list); + +void +lxa_slist_free(LXASList *list); + Modified: xarchiver/branches/xarchiver-psybsd/src/archive_store.c =================================================================== --- xarchiver/branches/xarchiver-psybsd/src/archive_store.c 2006-10-05 11:07:34 UTC (rev 23289) +++ xarchiver/branches/xarchiver-psybsd/src/archive_store.c 2006-10-05 13:44:18 UTC (rev 23290) @@ -1,20 +1,20 @@ -/* - * Copyright (c) 2006 Stephan Arts <[EMAIL PROTECTED]> - * - * 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. - */ + /* + * Copyright (c) 2006 Stephan Arts <[EMAIL PROTECTED]> + * + * 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> @@ -79,9 +79,9 @@ if(xa_archive_store_type) return xa_archive_store_type; - if (!xa_archive_store_type) + if (!xa_archive_store_type) { - static const GTypeInfo xa_archive_store_info = + static const GTypeInfo xa_archive_store_info = { sizeof (XAArchiveStoreClass), (GBaseInitFunc) NULL, @@ -113,16 +113,16 @@ { 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; + 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 @@ -148,7 +148,7 @@ { g_return_val_if_fail(XA_IS_ARCHIVE_STORE(tree_model), (GtkTreeModelFlags)0); - return (GTK_TREE_MODEL_LIST_ONLY | GTK_TREE_MODEL_ITERS_PERSIST); + return (GTK_TREE_MODEL_LIST_ONLY | GTK_TREE_MODEL_ITERS_PERSIST); } static gint @@ -177,6 +177,8 @@ g_return_val_if_fail(index < store->n_columns, G_TYPE_INVALID); + g_debug("xa_archive_store_get_column_type {%i} = %i", index, store->column_types[index]); + return store->column_types[index]; } @@ -187,12 +189,15 @@ 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); + LXAEntry *entry = NULL; + if(!store->current_entry) + return FALSE; + else + entry = store->current_entry->data; - gint *indices = gtk_tree_path_get_indices(path); + + gint *indices = gtk_tree_path_get_indices(path); gint depth = gtk_tree_path_get_depth(path) - 1; /* only support list: depth is always 0 */ @@ -221,6 +226,9 @@ iter->user_data = entry; iter->user_data2 = store->current_entry->data; iter->user_data3 = GINT_TO_POINTER(index); + + g_debug("xa_archive_store_get_iter {%i, %s}", index, entry->filename); + return TRUE; } @@ -244,6 +252,8 @@ GtkTreePath *path = gtk_tree_path_new(); gtk_tree_path_append_index(path, pos); + g_debug("xa_archive_store_get_path = %i", pos); + return path; } @@ -253,6 +263,8 @@ static void xa_archive_store_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, gint column, GValue *value) { + g_debug("xa_archive_store_get_value (%i)", column); + g_return_if_fail (XA_IS_ARCHIVE_STORE (tree_model)); XAArchiveStore *store = XA_ARCHIVE_STORE(tree_model); @@ -341,17 +353,22 @@ entry = lxa_entry_children_nth_data(entry, pos); - g_return_val_if_fail(entry, FALSE); + if(!entry) + return FALSE; iter->stamp = store->stamp; iter->user_data = entry; iter->user_data3 = GINT_TO_POINTER(pos); + + g_debug("xa_archive_store_iter_next {%i, %s}", pos, entry->filename); return TRUE; } static gboolean xa_archive_store_iter_children (GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreeIter *parent) { + g_debug("xa_archive_store_iter_children (%x)", parent); + g_return_val_if_fail(XA_IS_ARCHIVE_STORE(tree_model), FALSE); XAArchiveStore *store = XA_ARCHIVE_STORE(tree_model); @@ -407,6 +424,7 @@ /* only support lists: iter is always NULL */ g_return_val_if_fail(iter == NULL, FALSE); + g_debug("xa_archive_store_iter_n_children = %i", lxa_entry_children_length(entry) + (&archive->root_entry == entry)?0:1); return lxa_entry_children_length(entry) + (&archive->root_entry == entry)?0:1; } @@ -444,6 +462,7 @@ iter->user_data2 = store->current_entry->data; iter->user_data3 = GINT_TO_POINTER(n); + g_debug("xa_archive_store_iter_nth_child {%i}", n); return TRUE; } @@ -486,6 +505,7 @@ */ tree_model->props._show_icons = show_icons; + xa_archive_store_set_contents(tree_model, archive); return GTK_TREE_MODEL(tree_model); } @@ -508,7 +528,7 @@ g_return_if_fail(archive); g_return_if_fail(entry); - gint *indices = gtk_tree_path_get_indices(path); + gint *indices = gtk_tree_path_get_indices(path); gint depth = gtk_tree_path_get_depth(path) - 1; /* only support list: depth is always 0 */ @@ -522,7 +542,10 @@ GtkTreeIter *iter = NULL; if(&archive->root_entry != entry) + { + prev_size++; index--; + } if(index == -1) { @@ -541,8 +564,7 @@ new_size = lxa_entry_children_length(entry); - if(&archive->root_entry != entry) - { + if(&archive->root_entry != entry) { path_ = gtk_tree_path_new(); gtk_tree_path_append_index(path_, 0); @@ -606,13 +628,40 @@ void xa_archive_store_set_contents(XAArchiveStore *store, LXAArchive *archive) { - g_return_if_fail(store); - g_return_if_fail(archive); - - gint i= 0; + gint i = 0; GtkTreePath *path_ = NULL; GtkTreeIter *iter = NULL; + g_return_if_fail(store); + LXAEntry *entry = NULL; + gint prev_size = 0; + + if(store->current_entry) + { + entry = store->current_entry->data; + prev_size = lxa_entry_children_length(entry); + + + if(&store->archive->root_entry != entry) + prev_size++; + + } + + if(!archive) + { + + for(i = 0; 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_); + } + + store->archive = NULL; + store->current_entry = NULL; + return; + } store->archive = archive; store->current_entry = g_slist_prepend(NULL, &archive->root_entry); @@ -626,7 +675,7 @@ memcpy(store->column_types + 1, archive->column_types, archive->column_number); - for(; i < lxa_entry_children_length(&archive->root_entry); i++) + for(i = 0; i < lxa_entry_children_length(&archive->root_entry); i++) { path_ = gtk_tree_path_new(); gtk_tree_path_append_index(path_, i); Modified: xarchiver/branches/xarchiver-psybsd/src/main_window.c =================================================================== --- xarchiver/branches/xarchiver-psybsd/src/main_window.c 2006-10-05 11:07:34 UTC (rev 23289) +++ xarchiver/branches/xarchiver-psybsd/src/main_window.c 2006-10-05 13:44:18 UTC (rev 23290) @@ -569,7 +569,8 @@ GtkTreeModel *liststore = window->treemodel; GList *columns = gtk_tree_view_get_columns(GTK_TREE_VIEW(window->treeview)); - gtk_list_store_clear(GTK_LIST_STORE(liststore)); + //gtk_list_store_clear(GTK_LIST_STORE(liststore)); + xa_archive_store_set_contents(XA_ARCHIVE_STORE(liststore), NULL); while(columns) { @@ -707,8 +708,8 @@ { GtkCellRenderer *renderer = NULL; GtkTreeViewColumn *column = NULL; - GtkListStore *liststore = NULL; - //GtkTreeModel *liststore = 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)); @@ -727,8 +728,8 @@ column_types[x+1] = archive->column_types[x]; } column_types[0] = G_TYPE_STRING; - liststore = gtk_list_store_newv(archive->column_number+1, column_types); -// liststore = xa_archive_store_new(archive, TRUE); + //liststore = gtk_list_store_newv(archive->column_number+1, column_types); + liststore = xa_archive_store_new(NULL /*archive*/, TRUE); renderer = gtk_cell_renderer_pixbuf_new(); column = gtk_tree_view_column_new_with_attributes("", renderer, "icon-name", 0, NULL); @@ -752,8 +753,8 @@ gtk_tree_view_set_search_column(GTK_TREE_VIEW(window->treeview), 1); } else { - liststore = gtk_list_store_newv(archive->column_number, archive->column_types); - //liststore = xa_archive_store_new(archive, FALSE); + //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]) @@ -772,6 +773,7 @@ } gtk_tree_view_set_model(GTK_TREE_VIEW(window->treeview), GTK_TREE_MODEL(liststore)); window->treemodel = GTK_TREE_MODEL(liststore); + xa_archive_store_set_contents(XA_ARCHIVE_STORE(liststore), archive); } void @@ -785,10 +787,10 @@ gtk_tree_view_set_model(GTK_TREE_VIEW(main_window->treeview), NULL); - gtk_list_store_clear(GTK_LIST_STORE(liststore)); + //gtk_list_store_clear(GTK_LIST_STORE(liststore)); + xa_archive_store_set_contents(XA_ARCHIVE_STORE(liststore), NULL); - lxa_entry_flush_buffer(((LXAEntry *)main_window->working_node->data)); - +/* 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); @@ -807,6 +809,7 @@ 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); _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org http://foo-projects.org/mailman/listinfo/xfce4-commits