Author: peter
Date: 2007-02-25 19:23:21 +0000 (Sun, 25 Feb 2007)
New Revision: 25033
Modified:
squeeze/trunk/libsqueeze/archive-iter.c
squeeze/trunk/libsqueeze/libsqueeze-archive.h
squeeze/trunk/libsqueeze/libsqueeze-view.h
squeeze/trunk/src/archive_store.c
squeeze/trunk/src/archive_store.h
Log:
archive store can sort, has icon function, should ref correctly
Modified: squeeze/trunk/libsqueeze/archive-iter.c
===================================================================
--- squeeze/trunk/libsqueeze/archive-iter.c 2007-02-25 02:28:37 UTC (rev
25032)
+++ squeeze/trunk/libsqueeze/archive-iter.c 2007-02-25 19:23:21 UTC (rev
25033)
@@ -242,7 +242,7 @@
* LSQArchiveIter stuff *
************************/
-static LSQArchiveIter*
+static LSQArchiveIter *
lsq_archive_iter_new(LSQArchiveEntry *entry, LSQArchiveIter *parent,
LSQArchive *archive)
{
#ifdef DEBUG
@@ -288,8 +288,7 @@
/* iter has been found */
if(lsq_archive_iter_pool_find_iter(archive->pool, path->data, &iter,
&pos))
{
- lsq_archive_iter_ref(iter);
- return iter;
+ return lsq_archive_iter_ref(iter);
}
/* create a new iter */
@@ -304,7 +303,7 @@
return iter;
}
-static LSQArchiveIter*
+static LSQArchiveIter *
lsq_archive_iter_get_with_parent(LSQArchiveEntry *entry, LSQArchiveIter
*parent)
{
#ifdef DEBUG
@@ -317,8 +316,7 @@
/* iter has been found */
if(lsq_archive_iter_pool_find_iter(parent->archive->pool, entry, &iter,
&pos))
{
- lsq_archive_iter_ref(iter);
- return iter;
+ return lsq_archive_iter_ref(iter);
}
#ifdef DEBUG
@@ -372,15 +370,17 @@
}
}
-void
+LSQArchiveIter *
lsq_archive_iter_ref(LSQArchiveIter* iter)
{
#ifdef DEBUG
- g_return_if_fail(iter);
+ g_return_val_if_fail(iter, iter);
#endif
- g_return_if_fail(iter->ref_count);
+ g_return_val_if_fail(iter->ref_count, iter);
iter->ref_count++;
+
+ return iter;
}
gboolean
@@ -422,7 +422,7 @@
return TRUE;
}
-LSQArchiveIter*
+LSQArchiveIter *
lsq_archive_iter_get_real_parent(LSQArchiveIter *iter)
{
#ifdef DEBUG
@@ -437,7 +437,7 @@
back_stack = g_slist_prepend(back_stack, parent);
parent = parent->parent;
}
- /* the root entry is archive root entry */
+ /* the root entry is not archive root entry */
if(((LSQArchiveIter*)back_stack->data)->entry !=
iter->archive->root_entry)
{
g_slist_free(back_stack);
@@ -458,8 +458,7 @@
}
}
g_slist_free(back_stack);
- lsq_archive_iter_ref(iter);
- return iter;
+ return lsq_archive_iter_ref(iter);
}
gboolean
@@ -476,6 +475,18 @@
return FALSE;
}
+gboolean
+lsq_archive_iter_has_parent(const LSQArchiveIter *iter)
+{
+ return iter->parent?TRUE:FALSE;
+}
+
+LSQArchiveIter *
+lsq_archive_iter_get_parent(LSQArchiveIter *iter)
+{
+ return lsq_archive_iter_ref(iter->parent);
+}
+
guint
lsq_archive_iter_n_children(const LSQArchiveIter *iter)
{
@@ -485,7 +496,7 @@
return lsq_archive_entry_n_children(iter->entry);
}
-LSQArchiveIter*
+LSQArchiveIter *
lsq_archive_iter_nth_child(LSQArchiveIter *parent, guint n)
{
#ifdef DEBUG
@@ -617,6 +628,15 @@
return lsq_archive_entry_get_filename(iter->entry);
}
+const gchar*
+lsq_archive_iter_get_mime(const LSQArchiveIter *iter)
+{
+#ifdef debug
+ g_return_val_if_fail(iter, FALSE);
+#endif
+ return lsq_archive_entry_get_mimetype(iter->entry);
+}
+
gboolean
lsq_archive_iter_get_prop_value(const LSQArchiveIter *iter, guint n, GValue
*value)
{
Modified: squeeze/trunk/libsqueeze/libsqueeze-archive.h
===================================================================
--- squeeze/trunk/libsqueeze/libsqueeze-archive.h 2007-02-25 02:28:37 UTC
(rev 25032)
+++ squeeze/trunk/libsqueeze/libsqueeze-archive.h 2007-02-25 19:23:21 UTC
(rev 25033)
@@ -51,8 +51,8 @@
GType lsq_archive_get_type(void);
-void lsq_archive_iter_ref(LSQArchiveIter *);
-void lsq_archive_iter_unref(LSQArchiveIter *);
+LSQArchiveIter *lsq_archive_iter_ref(LSQArchiveIter *);
+void lsq_archive_iter_unref(LSQArchiveIter *);
G_END_DECLS
Modified: squeeze/trunk/libsqueeze/libsqueeze-view.h
===================================================================
--- squeeze/trunk/libsqueeze/libsqueeze-view.h 2007-02-25 02:28:37 UTC (rev
25032)
+++ squeeze/trunk/libsqueeze/libsqueeze-view.h 2007-02-25 19:23:21 UTC (rev
25033)
@@ -28,9 +28,12 @@
LSQArchiveIter *lsq_archive_iter_nth_child(LSQArchiveIter *, guint);
LSQArchiveIter *lsq_archive_iter_get_child(LSQArchiveIter *, const gchar
*);
guint lsq_archive_iter_get_depth(const LSQArchiveIter *);
+gboolean lsq_archive_iter_has_parent(const LSQArchiveIter *);
+LSQArchiveIter *lsq_archive_iter_get_parent(LSQArchiveIter *);
gboolean lsq_archive_iter_get_prop_value(const LSQArchiveIter
*iter, guint n, GValue *value);
const gchar *lsq_archive_iter_get_filename(const LSQArchiveIter *);
+const gchar *lsq_archive_iter_get_mime(const LSQArchiveIter *);
gchar *lsq_archive_iter_get_path(const LSQArchiveIter *archive);
LSQArchiveIter *lsq_archive_get_iter(LSQArchive *archive, const gchar
*path);
Modified: squeeze/trunk/src/archive_store.c
===================================================================
--- squeeze/trunk/src/archive_store.c 2007-02-25 02:28:37 UTC (rev 25032)
+++ squeeze/trunk/src/archive_store.c 2007-02-25 19:23:21 UTC (rev 25033)
@@ -16,10 +16,8 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
-/* TODO: archive iter referencing */
-/* TODO: archive signaling */
-/* TODO: sorting */
-/* TODO: icon */
+/* archive iter referencing needs testing */
+/* TODO: archive signaling */
#include <config.h>
#include <string.h>
@@ -44,8 +42,8 @@
static void
sq_archive_tree_model_init(GtkTreeModelIface *tm_interface);
-/* static void */
-/* sq_archive_tree_sortable_init(GtkTreeSortableIface *ts_interface); */
+static void
+sq_archive_tree_sortable_init(GtkTreeSortableIface *ts_interface);
static void
sq_archive_store_dispose(GObject *object);
@@ -100,6 +98,11 @@
static gboolean
sq_archive_store_iter_parent (GtkTreeModel *tree_model, GtkTreeIter *iter,
GtkTreeIter *child);
static void
+sq_archive_store_ref_node (GtkTreeModel *tree_model, GtkTreeIter *iter);
+static void
+sq_archive_store_unref_node (GtkTreeModel *tree_model, GtkTreeIter *iter);
+
+static void
sq_archive_store_refresh(SQArchiveStore *store);
static void
@@ -109,27 +112,30 @@
cb_sq_archive_store_row_activated(GtkTreeView *treeview, GtkTreePath *path,
GtkTreeViewColumn *column, gpointer user_data);
/* tree sortable */
-/* static gboolean
*/
-/* sq_archive_store_get_sort_column_id(GtkTreeSortable *sortable, gint
*sort_col_id, GtkSortType *order); */
-/* static void
*/
-/* sq_archive_store_set_sort_column_id(GtkTreeSortable *sortable, gint
sort_col_id, GtkSortType order); */
-/* static void
*/
-/* sq_archive_store_set_sort_func(GtkTreeSortable *, gint,
GtkTreeIterCompareFunc, gpointer, GtkDestroyNotify); */
-/* static void
*/
-/* sq_archive_store_set_default_sort_func(GtkTreeSortable *,
GtkTreeIterCompareFunc, gpointer, GtkDestroyNotify); */
-/* static gboolean
*/
-/* sq_archive_store_has_default_sort_func(GtkTreeSortable *);
*/
+static gboolean
+sq_archive_store_get_sort_column_id(GtkTreeSortable *sortable, gint
*sort_col_id, GtkSortType *order);
+static void
+sq_archive_store_set_sort_column_id(GtkTreeSortable *sortable, gint
sort_col_id, GtkSortType order);
+static void
+sq_archive_store_set_sort_func(GtkTreeSortable *, gint,
GtkTreeIterCompareFunc, gpointer, GtkDestroyNotify);
+static void
+sq_archive_store_set_default_sort_func(GtkTreeSortable *,
GtkTreeIterCompareFunc, gpointer, GtkDestroyNotify);
+static gboolean
+sq_archive_store_has_default_sort_func(GtkTreeSortable *);
-/* static gint
*/
-/* sq_archive_entry_compare(SQArchiveStore *store, LSQArchiveIter *a,
LSQArchiveIter *b); */
-/* static void */
-/* sq_archive_quicksort(SQArchiveStore *store, gint left, gint right); */
-/* static void */
-/* sq_archive_insertionsort(SQArchiveStore *store, gint left, gint right); */
+static gint
+sq_archive_entry_compare(SQArchiveStore *store, LSQArchiveIter *a,
LSQArchiveIter *b);
+static void
+sq_archive_quicksort(SQArchiveStore *store, gint left, gint right);
+static void
+sq_archive_insertionsort(SQArchiveStore *store, gint left, gint right);
-/* static void */
-/* sq_archive_store_sort(SQArchiveStore *store); */
+static void
+sq_archive_store_sort(SQArchiveStore *store);
+static const gchar *
+sq_archive_store_get_icon_name_for_iter(SQArchiveStore *store, LSQArchiveIter
*iter);
+
static void
sq_archive_store_append_history(SQArchiveStore *store, LSQArchiveIter *entry);
@@ -176,14 +182,14 @@
g_type_add_interface_static (sq_archive_store_type,
GTK_TYPE_TREE_MODEL, &tree_model_info);
- /* static const GInterfaceInfo tree_sort_info =
*/
- /* {
*/
- /* (GInterfaceInitFunc) sq_archive_tree_sortable_init,
*/
- /* NULL,
*/
- /* NULL
*/
- /* };
*/
+ static const GInterfaceInfo tree_sort_info =
+ {
+ (GInterfaceInitFunc) sq_archive_tree_sortable_init,
+ NULL,
+ NULL
+ };
- /* g_type_add_interface_static (sq_archive_store_type,
GTK_TYPE_TREE_SORTABLE, &tree_sort_info); */
+ g_type_add_interface_static (sq_archive_store_type,
GTK_TYPE_TREE_SORTABLE, &tree_sort_info);
return sq_archive_store_type;
}
@@ -203,17 +209,19 @@
iface->iter_n_children = sq_archive_store_iter_n_children;
iface->iter_nth_child = sq_archive_store_iter_nth_child;
iface->iter_parent = sq_archive_store_iter_parent;
+ iface->ref_node = sq_archive_store_ref_node;
+ iface->unref_node = sq_archive_store_unref_node;
}
-/* static void
*/
-/* sq_archive_tree_sortable_init(GtkTreeSortableIface *iface)
*/
-/* {
*/
- /* iface->get_sort_column_id = sq_archive_store_get_sort_column_id;
*/
- /* iface->set_sort_column_id = sq_archive_store_set_sort_column_id;
*/
- /* iface->set_sort_func = sq_archive_store_set_sort_func;
|+NOT SUPPORTED+| */
- /* iface->set_default_sort_func =
sq_archive_store_set_default_sort_func; |+NOT SUPPORTED+| */
- /* iface->has_default_sort_func =
sq_archive_store_has_default_sort_func; */
-/* }
*/
+static void
+sq_archive_tree_sortable_init(GtkTreeSortableIface *iface)
+{
+ iface->get_sort_column_id = sq_archive_store_get_sort_column_id;
+ iface->set_sort_column_id = sq_archive_store_set_sort_column_id;
+ iface->set_sort_func = sq_archive_store_set_sort_func;
/*NOT SUPPORTED*/
+ iface->set_default_sort_func = sq_archive_store_set_default_sort_func;
/*NOT SUPPORTED*/
+ iface->has_default_sort_func = sq_archive_store_has_default_sort_func;
+}
static void
sq_archive_store_init(SQArchiveStore *as)
@@ -221,9 +229,9 @@
as->stamp = g_random_int();
as->archive = NULL;
as->support = NULL;
- /* as->sort_column = GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID; */
- /* as->sort_order = GTK_SORT_ASCENDING; */
- /* as->sort_list = NULL; */
+ as->sort_column = GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID;
+ as->sort_order = GTK_SORT_ASCENDING;
+ as->sort_list = NULL;
as->icon_theme = NULL;
as->props._show_icons = 0;
as->props._show_up_dir = 1;
@@ -424,7 +432,7 @@
gint index = indices[depth];
/* if this is the root entry we don't need the ".." */
- if(store->props._show_up_dir && lsq_archive_iter_get_parent(entry))
+ if(store->props._show_up_dir && lsq_archive_iter_has_parent(entry))
index--;
if(index == -1)
@@ -435,9 +443,9 @@
else
{
/* 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 */
+ if(store->sort_list)
+ entry = lsq_archive_iter_ref(store->sort_list[index]);
+ else
entry = lsq_archive_iter_nth_child(entry, index);
if(!entry)
@@ -470,7 +478,7 @@
LSQArchiveIter *entry = (LSQArchiveIter*)iter->user_data;
gint pos = GPOINTER_TO_INT(iter->user_data3);
- if(store->props._show_up_dir && lsq_archive_get_iter(archive, NULL) !=
lsq_archive_iter_get_parent(entry))
+ if(store->props._show_up_dir && lsq_archive_iter_has_parent(entry))
pos++;
GtkTreePath *path = gtk_tree_path_new();
@@ -497,10 +505,10 @@
{
if(column == -1)
{
- /* if(store->props._show_icons)
*/
- /* FIXME:
lsq_archive_iter_get_icon_name(archive, entry, value, store->icon_theme); */
- /* else
*/
- g_value_init(value, G_TYPE_STRING);
+ g_value_init(value, G_TYPE_STRING);
+
+ if(store->props._show_icons)
+ g_value_set_string(value,
sq_archive_store_get_icon_name_for_iter(store, entry));
}
else
{
@@ -540,15 +548,23 @@
if(iter->stamp != store->stamp)
return FALSE;
- LSQArchiveIter *entry =
lsq_archive_iter_get_parent((LSQArchiveIter*)iter->user_data);
+ LSQArchiveIter *entry = iter->user_data;
+ LSQArchiveIter *parent;
gint pos = GPOINTER_TO_INT(iter->user_data3);
pos++;
- /* if(store->sort_list) */
- /* entry = store->sort_list[pos]; */
- /* else */
- entry = lsq_archive_iter_nth_child(entry, pos);
+ if(store->sort_list)
+ entry = lsq_archive_iter_ref(store->sort_list[pos]);
+ else
+ {
+ parent = lsq_archive_iter_get_parent(entry);
+ entry = lsq_archive_iter_nth_child(parent, pos);
+ lsq_archive_iter_unref(parent);
+ }
+ /* is this correct? */
+ lsq_archive_iter_unref(iter->user_data);
+
if(!entry)
return FALSE;
@@ -584,16 +600,16 @@
/* only support lists: parent is always NULL */
g_return_val_if_fail(parent == NULL, FALSE);
- if(store->props._show_up_dir && lsq_archive_iter_get_parent(entry))
+ if(store->props._show_up_dir && lsq_archive_iter_has_parent(entry))
{
entry = NULL;
iter->user_data3 = GINT_TO_POINTER(-1);
}
else
{
- /* if(store->sort_list) */
- /* entry = store->sort_list[0]; */
- /* else */
+ if(store->sort_list)
+ entry = lsq_archive_iter_ref(store->sort_list[0]);
+ else
entry = lsq_archive_iter_nth_child(entry, 0);
g_return_val_if_fail(entry, FALSE);
@@ -638,7 +654,7 @@
/* only support lists: iter is always NULL */
g_return_val_if_fail(iter == NULL, FALSE);
- return lsq_archive_iter_n_children(entry) +
(lsq_archive_iter_get_parent(entry)?1:0);
+ return lsq_archive_iter_n_children(entry) +
(lsq_archive_iter_has_parent(entry)?1:0);
}
static gboolean
@@ -667,7 +683,7 @@
/* only support lists: parent is always NULL */
g_return_val_if_fail(parent == NULL, FALSE);
- if(store->props._show_up_dir && lsq_archive_iter_get_parent(entry))
+ if(store->props._show_up_dir && lsq_archive_iter_has_parent(entry))
n--;
if(n == -1)
@@ -676,9 +692,9 @@
}
else
{
- /* if(store->sort_list) */
- /* entry = store->sort_list[n]; */
- /* else */
+ if(store->sort_list)
+ entry = lsq_archive_iter_ref(store->sort_list[n]);
+ else
entry = lsq_archive_iter_nth_child(entry, n);
if(!entry)
@@ -703,231 +719,262 @@
return FALSE;
}
+static void
+sq_archive_store_ref_node (GtkTreeModel *tree_model, GtkTreeIter *iter)
+{
+ lsq_archive_iter_ref(iter->user_data);
+}
-/* static gboolean
*/
-/* sq_archive_store_get_sort_column_id(GtkTreeSortable *sortable, gint
*sort_col_id, GtkSortType *order) */
-/* {
*/
- /* g_return_val_if_fail(SQ_IS_ARCHIVE_STORE(sortable), FALSE);
*/
+static void
+sq_archive_store_unref_node (GtkTreeModel *tree_model, GtkTreeIter *iter)
+{
+ lsq_archive_iter_unref(iter->user_data);
+}
- /* SQArchiveStore *store = SQ_ARCHIVE_STORE(sortable);
*/
- /* if(sort_col_id)
*/
- /* *sort_col_id = store->sort_column;
*/
-
/* */
- /* if(order)
*/
- /* *order = store->sort_order;
*/
+static gboolean
+sq_archive_store_get_sort_column_id(GtkTreeSortable *sortable, gint
*sort_col_id, GtkSortType *order)
+{
+ g_return_val_if_fail(SQ_IS_ARCHIVE_STORE(sortable), FALSE);
- /* return store->sort_order >= 0;
*/
-/* }
*/
+ SQArchiveStore *store = SQ_ARCHIVE_STORE(sortable);
-/* static void
*/
-/* sq_archive_store_set_sort_column_id(GtkTreeSortable *sortable, gint
sort_col_id, GtkSortType order) */
-/* {
*/
- /* g_return_if_fail(SQ_IS_ARCHIVE_STORE(sortable));
*/
+ if(sort_col_id)
+ *sort_col_id = store->sort_column;
- /* SQArchiveStore *store = SQ_ARCHIVE_STORE(sortable);
*/
+ if(order)
+ *order = store->sort_order;
- /* if(store->sort_column == sort_col_id && store->sort_order == order)
*/
- /* return;
*/
+ return store->sort_order >= 0;
+}
- /* if(sort_col_id == 0)
*/
- /* return;
*/
+static void
+sq_archive_store_set_sort_column_id(GtkTreeSortable *sortable, gint
sort_col_id, GtkSortType order)
+{
+ g_return_if_fail(SQ_IS_ARCHIVE_STORE(sortable));
- /* store->sort_column = sort_col_id;
*/
- /* store->sort_order = order;
*/
+ SQArchiveStore *store = SQ_ARCHIVE_STORE(sortable);
- /* sq_archive_store_sort(store);
*/
- /* sq_archive_store_refresh(store);
*/
+ if(store->sort_column == sort_col_id && store->sort_order == order)
+ return;
- /* gtk_tree_sortable_sort_column_changed(sortable);
*/
-/* }
*/
+ if(sort_col_id == 0)
+ return;
-/* static void
*/
-/* sq_archive_store_set_sort_func(GtkTreeSortable *s, gint i,
GtkTreeIterCompareFunc f, gpointer p, GtkDestroyNotify d) */
-/* {
*/
- /* g_warning("%s is not supported by the SQArchiveStore model",
__FUNCTION__); */
-/* }
*/
+ store->sort_column = sort_col_id;
+ store->sort_order = order;
-/* static void
*/
-/* sq_archive_store_set_default_sort_func(GtkTreeSortable *s,
GtkTreeIterCompareFunc f, gpointer p, GtkDestroyNotify d) */
-/* {
*/
- /* g_warning("%s is not supported by the SQArchiveStore model",
__FUNCTION__); */
-/* }
*/
+ sq_archive_store_sort(store);
+ sq_archive_store_refresh(store);
-/* static gboolean
*/
-/* sq_archive_store_has_default_sort_func(GtkTreeSortable *s)
*/
-/* {
*/
- /* return SQ_ARCHIVE_STORE(s)->props._sort_folders_first?FALSE:TRUE;
*/
-/* }
*/
+ gtk_tree_sortable_sort_column_changed(sortable);
+}
-/* static gint
*/
-/* sq_archive_entry_compare(SQArchiveStore *store, LSQArchiveIter *a,
LSQArchiveIter *b) */
-/* {
*/
- /* gint retval = 0;
*/
- /* gint column = 0;
*/
- /* gboolean cmp_a = 0;
*/
- /* gboolean cmp_b = 0;
*/
- /* GValue prop_a;
*/
- /* GValue prop_b;
*/
- /* memset(&prop_a, 0, sizeof(GValue));
*/
- /* memset(&prop_b, 0, sizeof(GValue));
*/
- /* if(store->props._sort_folders_first)
*/
- /* {
*/
- /* cmp_a = lsq_archive_iter_is_directory(store->archive, a);
*/
- /* cmp_b = lsq_archive_iter_is_directory(store->archive, b);
*/
+static void
+sq_archive_store_set_sort_func(GtkTreeSortable *s, gint i,
GtkTreeIterCompareFunc f, gpointer p, GtkDestroyNotify d)
+{
+ g_warning("%s is not supported by the SQArchiveStore model",
__FUNCTION__);
+}
- /* if(cmp_a && !cmp_b)
*/
- /* return -1;
*/
- /* if(cmp_b && !cmp_a)
*/
- /* return 1;
*/
- /* }
*/
+static void
+sq_archive_store_set_default_sort_func(GtkTreeSortable *s,
GtkTreeIterCompareFunc f, gpointer p, GtkDestroyNotify d)
+{
+ g_warning("%s is not supported by the SQArchiveStore model",
__FUNCTION__);
+}
- /* LSQArchiveIter *swap = b;
*/
- /* if(store->sort_order == GTK_SORT_DESCENDING)
*/
- /* {
*/
- /* b = a;
*/
- /* a = swap;
*/
- /* }
*/
+static gboolean
+sq_archive_store_has_default_sort_func(GtkTreeSortable *s)
+{
+ return SQ_ARCHIVE_STORE(s)->props._sort_folders_first?FALSE:TRUE;
+}
- /* LSQArchive *archive = store->archive;
*/
- /* column = store->sort_column - 1;
*/
+static gint
+sq_archive_entry_compare(SQArchiveStore *store, LSQArchiveIter *a,
LSQArchiveIter *b)
+{
+ gint retval = 0;
+ gint column = 0;
+ gboolean cmp_a = 0;
+ gboolean cmp_b = 0;
+ GValue prop_a;
+ GValue prop_b;
+ memset(&prop_a, 0, sizeof(GValue));
+ memset(&prop_b, 0, sizeof(GValue));
+ if(store->props._sort_folders_first)
+ {
+ cmp_a = lsq_archive_iter_is_directory(a);
+ cmp_b = lsq_archive_iter_is_directory(b);
- /* lsq_archive_iter_get_prop_value(archive, a, column, &prop_a);
*/
- /* lsq_archive_iter_get_prop_value(archive, b, column, &prop_b);
*/
+ if(cmp_a && !cmp_b)
+ return -1;
+ if(cmp_b && !cmp_a)
+ return 1;
+ }
- /* switch(lsq_archive_get_entry_property_type(archive, column))
*/
- /* {
*/
- /* case G_TYPE_STRING:
*/
- /* if(g_value_get_string(&prop_a) == NULL)
*/
- /* {
*/
- /* retval = -1;
*/
- /* break;
*/
- /* }
*/
- /* if(g_value_get_string(&prop_b) == NULL)
*/
- /* {
*/
- /* retval = 1;
*/
- /* break;
*/
- /* }
*/
- /* switch(store->props._sort_case_sensitive)
*/
- /* {
*/
- /* case 0: |+ case insensitive +|
*/
- /* retval =
g_ascii_strcasecmp(g_value_get_string(&prop_a), g_value_get_string(&prop_b)); */
- /* break;
*/
- /* case 1: |+ case sensitive +|
*/
- /* retval =
strcmp(g_value_get_string(&prop_a), g_value_get_string(&prop_b)); */
- /* break;
*/
- /* }
*/
- /* break;
*/
- /* case G_TYPE_UINT64:
*/
- /* retval = g_value_get_uint64(&prop_a) -
g_value_get_uint64(&prop_b); */
- /* break;
*/
- /* case G_TYPE_UINT:
*/
- /* retval = g_value_get_uint(&prop_a) -
g_value_get_uint(&prop_b); */
- /* break;
*/
- /* }
*/
- /* g_value_unset(&prop_a);
*/
- /* g_value_unset(&prop_b);
*/
- /* return retval;
*/
-/* }
*/
+ LSQArchiveIter *swap = b;
+ if(store->sort_order == GTK_SORT_DESCENDING)
+ {
+ b = a;
+ a = swap;
+ }
-/* static void
*/
-/* sq_archive_store_sort(SQArchiveStore *store)
*/
-/* {
*/
- /* if(store->sort_list)
*/
- /* {
*/
- /* g_free(store->sort_list);
*/
- /* store->sort_list = NULL;
*/
- /* }
*/
+ LSQArchive *archive = store->archive;
+ column = store->sort_column - 1;
- /* if(store->sort_column < 0)
*/
- /* return;
*/
+ lsq_archive_iter_get_prop_value(a, column, &prop_a);
+ lsq_archive_iter_get_prop_value(b, column, &prop_b);
-/* #ifdef DEBUG
*/
- /* g_return_if_fail(store->navigation.present);
*/
- /* g_return_if_fail(store->navigation.present->data);
*/
-/* #endif
*/
+ switch(lsq_archive_get_entry_property_type(archive, column))
+ {
+ case G_TYPE_STRING:
+ if(g_value_get_string(&prop_a) == NULL)
+ {
+ retval = -1;
+ break;
+ }
+ if(g_value_get_string(&prop_b) == NULL)
+ {
+ retval = 1;
+ break;
+ }
+ switch(store->props._sort_case_sensitive)
+ {
+ case 0: /* case insensitive */
+ retval =
g_ascii_strcasecmp(g_value_get_string(&prop_a), g_value_get_string(&prop_b));
+ break;
+ case 1: /* case sensitive */
+ retval =
strcmp(g_value_get_string(&prop_a), g_value_get_string(&prop_b));
+ break;
+ }
+ break;
+ case G_TYPE_UINT64:
+ retval = g_value_get_uint64(&prop_a) -
g_value_get_uint64(&prop_b);
+ break;
+ case G_TYPE_UINT:
+ retval = g_value_get_uint(&prop_a) -
g_value_get_uint(&prop_b);
+ break;
+ }
+ g_value_unset(&prop_a);
+ g_value_unset(&prop_b);
+ return retval;
+}
- /* LSQArchiveIter *pentry = store->navigation.present->data; */
- /* gint psize = lsq_archive_iter_n_children(store->archive, pentry);
*/
- /* gint i = 0;
*/
+static void
+sq_archive_store_sort(SQArchiveStore *store)
+{
+ if(store->sort_list)
+ {
+ LSQArchiveIter **iter;
+ for(iter = store->sort_list; *iter; iter++)
+ {
+ lsq_archive_iter_unref(*iter);
+ }
+ g_free(store->sort_list);
+ store->sort_list = NULL;
+ }
- /* if(psize <= 1)
*/
- /* return;
*/
+ if(store->sort_column < 0)
+ return;
- /* store->sort_list = g_new(LSQArchiveIter*, psize+1);
*/
+#ifdef DEBUG
+ g_return_if_fail(store->navigation.present);
+ g_return_if_fail(store->navigation.present->data);
+#endif
- /* for(i = 0; i < psize; ++i)
*/
- /* {
*/
- /* store->sort_list[i] =
lsq_archive_iter_nth_child(store->archive, pentry, i); */
- /* }
*/
- /* sq_archive_quicksort(store, 0, psize-1);
*/
- /* sq_archive_insertionsort(store, 0, psize-1);
*/
- /* store->sort_list[psize] = NULL;
*/
-/* }
*/
+ LSQArchiveIter *pentry = store->navigation.present->data;
+ gint psize = lsq_archive_iter_n_children(pentry);
+ gint i = 0;
-/* inline void
*/
-/* swap(LSQArchiveIter **left, LSQArchiveIter **right)
*/
-/* {
*/
- /* LSQArchiveIter *tmp = *right;
*/
- /* *right = *left;
*/
- /* *left = tmp;
*/
-/* }
*/
+ if(psize <= 1)
+ return;
-/* static void
*/
-/* sq_archive_quicksort(SQArchiveStore *store, gint left, gint right)
*/
-/* {
*/
- /* if(right-left < 30) return;
*/
+ store->sort_list = g_new(LSQArchiveIter*, psize+1);
- /* gint i = (left+right)/2;
*/
- /* gint j = right-1;
*/
- /* LSQArchiveIter *value = NULL;
*/
- /* LSQArchiveIter **list = store->sort_list;
*/
+ for(i = 0; i < psize; ++i)
+ {
+ store->sort_list[i] = lsq_archive_iter_nth_child(pentry, i);
+ }
+ sq_archive_quicksort(store, 0, psize-1);
+ sq_archive_insertionsort(store, 0, psize-1);
+ store->sort_list[psize] = NULL;
+}
- /* if(sq_archive_entry_compare(store, list[left], list[i]) > 0)
*/
- /* swap(list+left, list+i);
*/
- /* if(sq_archive_entry_compare(store, list[left], list[right]) > 0)
*/
- /* swap(list+left, list+right);
*/
- /* if(sq_archive_entry_compare(store, list[i], list[right]) > 0)
*/
- /* swap(list+i, list+right);
*/
-
/* */
- /* swap(list+i, list+j);
*/
- /* i = left;
*/
- /* value = list[j];
*/
+static inline void
+swap(LSQArchiveIter **left, LSQArchiveIter **right)
+{
+ LSQArchiveIter *tmp = *right;
+ *right = *left;
+ *left = tmp;
+}
- /* for(;;)
*/
- /* {
*/
- /* while(sq_archive_entry_compare(store, list[++i], value) <
0); */
- /* while(sq_archive_entry_compare(store, list[--j], value) >
0); */
- /* if(j<i) break;
*/
+static void
+sq_archive_quicksort(SQArchiveStore *store, gint left, gint right)
+{
+ if(right-left < 30) return;
- /* swap(list+i, list+j);
*/
- /* }
*/
- /* swap(list+i, list+right-1);
*/
- /* sq_archive_quicksort(store, left, j);
*/
- /* sq_archive_quicksort(store, i+1, right);
*/
-/* }
*/
+ gint i = (left+right)/2;
+ gint j = right-1;
+ LSQArchiveIter *value = NULL;
+ LSQArchiveIter **list = store->sort_list;
-/* static void
*/
-/* sq_archive_insertionsort(SQArchiveStore *store, gint left, gint right)
*/
-/* {
*/
- /* gint i = 0;
*/
- /* gint j = 0;
*/
- /* LSQArchiveIter *value = NULL;
*/
- /* LSQArchiveIter **list = store->sort_list;
*/
+ if(sq_archive_entry_compare(store, list[left], list[i]) > 0)
+ swap(list+left, list+i);
+ if(sq_archive_entry_compare(store, list[left], list[right]) > 0)
+ swap(list+left, list+right);
+ if(sq_archive_entry_compare(store, list[i], list[right]) > 0)
+ swap(list+i, list+right);
- /* for(i = left+1; i <= right; ++i)
*/
- /* {
*/
- /* j = i;
*/
- /* value = list[i];
*/
- /* while(j > left && sq_archive_entry_compare(store, list[j-1],
value) > 0) */
- /* {
*/
- /* list[j] = list[j-1];
*/
- /* j--;
*/
- /* }
*/
- /* list[j] = value;
*/
- /* }
*/
-/* }
*/
+ swap(list+i, list+j);
+ i = left;
+ value = list[j];
+ for(;;)
+ {
+ while(sq_archive_entry_compare(store, list[++i], value) < 0);
+ while(sq_archive_entry_compare(store, list[--j], value) > 0);
+ if(j<i) break;
+
+ swap(list+i, list+j);
+ }
+ swap(list+i, list+right-1);
+ sq_archive_quicksort(store, left, j);
+ sq_archive_quicksort(store, i+1, right);
+}
+
+static void
+sq_archive_insertionsort(SQArchiveStore *store, gint left, gint right)
+{
+ gint i = 0;
+ gint j = 0;
+ LSQArchiveIter *value = NULL;
+ LSQArchiveIter **list = store->sort_list;
+
+ for(i = left+1; i <= right; ++i)
+ {
+ j = i;
+ value = list[i];
+ while(j > left && sq_archive_entry_compare(store, list[j-1],
value) > 0)
+ {
+ list[j] = list[j-1];
+ j--;
+ }
+ list[j] = value;
+ }
+}
+
+static const gchar *
+sq_archive_store_get_icon_name_for_iter(SQArchiveStore *store, LSQArchiveIter
*iter)
+{
+ ThunarVfsMimeDatabase *mimedb = thunar_vfs_mime_database_get_default();
+ ThunarVfsMimeInfo *mime_info =
thunar_vfs_mime_database_get_info(mimedb, lsq_archive_iter_get_mime(iter));
+ const gchar *icon_name =
thunar_vfs_mime_info_lookup_icon_name(mime_info, store->icon_theme);
+ if(icon_name && !gtk_icon_theme_has_icon(store->icon_theme, icon_name))
+ icon_name = NULL;
+ /* may we do this? */
+ thunar_vfs_mime_info_unref(mime_info);
+ g_object_unref(mimedb);
+ return icon_name;
+}
+
GtkTreeModel *
sq_archive_store_new(LSQArchive *archive, gboolean show_icons, gboolean
show_up_dir, GtkIconTheme *icon_theme)
{
@@ -939,8 +986,8 @@
tree_model->props._show_up_dir = show_up_dir?1:0;
tree_model->icon_theme = icon_theme;
- /* if(tree_model->props._sort_folders_first) */
- /* tree_model->sort_column = 1; */
+ if(tree_model->props._sort_folders_first)
+ tree_model->sort_column = 1;
sq_archive_store_set_archive(tree_model, archive);
@@ -979,7 +1026,7 @@
if(store->treeview)
{
/* we need to add up dir .. */
- if(store->props._show_up_dir &&
lsq_archive_iter_get_parent(entry))
+ if(store->props._show_up_dir &&
lsq_archive_iter_has_parent(entry))
{
path_ = gtk_tree_path_new();
gtk_tree_path_append_index(path_, 0);
@@ -1005,9 +1052,9 @@
gtk_tree_path_append_index(path_, i);
iter.stamp = store->stamp;
- /* if(store->sort_list) */
- /* iter.user_data = store->sort_list[i]; */
- /* else */
+ if(store->sort_list)
+ iter.user_data =
lsq_archive_iter_ref(store->sort_list[i]);
+ else
iter.user_data =
lsq_archive_iter_nth_child(entry, i);
iter.user_data3 = GINT_TO_POINTER(i);
@@ -1016,6 +1063,8 @@
else
gtk_tree_model_row_inserted(GTK_TREE_MODEL(store), path_, &iter);
+ lsq_archive_iter_unref(iter.user_data);
+
gtk_tree_path_free(path_);
}
@@ -1062,7 +1111,7 @@
gint index = indices[depth];
- if(store->props._show_up_dir && lsq_archive_iter_get_parent(entry))
+ if(store->props._show_up_dir && lsq_archive_iter_has_parent(entry))
index--;
if(index == -1)
@@ -1072,9 +1121,9 @@
}
else
{
- /* if(store->sort_list) */
- /* entry = store->sort_list[index]; */
- /* else */
+ if(store->sort_list)
+ entry = lsq_archive_iter_ref(store->sort_list[index]);
+ else
entry = lsq_archive_iter_nth_child(entry, index);
g_return_if_fail(entry);
@@ -1086,13 +1135,14 @@
g_debug("file clicked");
#endif
g_signal_emit(store,
sq_archive_store_signals[SQ_ARCHIVE_STORE_SIGNAL_FILE_ACTIVATED], 0,
lsq_archive_iter_get_filename(entry), NULL);
+ lsq_archive_iter_unref(entry);
return;
}
sq_archive_store_append_history(store, entry);
}
- /* sq_archive_store_sort(store); */
+ sq_archive_store_sort(store);
sq_archive_store_refresh(store);
g_signal_emit(store,
sq_archive_store_signals[SQ_ARCHIVE_STORE_SIGNAL_PWD_CHANGED], 0,NULL);
}
@@ -1116,7 +1166,7 @@
sq_archive_store_append_history(store, entry);
- /* sq_archive_store_sort(store); */
+ sq_archive_store_sort(store);
sq_archive_store_refresh(store);
g_signal_emit(store,
sq_archive_store_signals[SQ_ARCHIVE_STORE_SIGNAL_PWD_CHANGED], 0,NULL);
}
@@ -1136,11 +1186,16 @@
LSQArchiveIter *root_entry;
/* free the sort data */
- /* if(store->sort_list) */
- /* { */
- /* g_free(store->sort_list); */
- /* store->sort_list = NULL; */
- /* } */
+ if(store->sort_list)
+ {
+ LSQArchiveIter **iter;
+ for(iter = store->sort_list; *iter; iter++)
+ {
+ lsq_archive_iter_unref(*iter);
+ }
+ g_free(store->sort_list);
+ store->sort_list = NULL;
+ }
/* notify the tree view, all rows are gone */
i = store->list_size;
@@ -1195,7 +1250,7 @@
sq_archive_store_append_history(store, root_entry);
- /* sq_archive_store_sort(store); */
+ sq_archive_store_sort(store);
/* lets notify the tree view we have new rows */
store->list_size = lsq_archive_iter_n_children(root_entry);
@@ -1206,14 +1261,16 @@
gtk_tree_path_append_index(path_, i);
iter.stamp = store->stamp;
- /* if(store->sort_list) */
- /* iter.user_data = store->sort_list[i]; */
- /* else */
+ if(store->sort_list)
+ iter.user_data =
lsq_archive_iter_ref(store->sort_list[i]);
+ else
iter.user_data =
lsq_archive_iter_nth_child(root_entry, i);
iter.user_data3 = GINT_TO_POINTER(i);
gtk_tree_model_row_inserted(GTK_TREE_MODEL(store),
path_, &iter);
+ lsq_archive_iter_unref(iter.user_data);
+
gtk_tree_path_free(path_);
}
}
@@ -1251,19 +1308,22 @@
return NULL;
const gchar *basename;
- LSQArchiveIter *iter = store->navigation.present->data;
+ LSQArchiveIter *child = NULL, *iter = store->navigation.present->data;
GSList *path = NULL;
if(!iter)
return NULL;
/* we don't want to include de archive rootentry */
- while(lsq_archive_iter_get_parent(iter))
+ while(lsq_archive_iter_has_parent(iter))
{
basename = lsq_archive_iter_get_filename(iter);
path = g_slist_prepend(path, g_strdup(basename));
iter = lsq_archive_iter_get_parent(iter);
+ lsq_archive_iter_unref(child);
+ child = iter;
}
+ lsq_archive_iter_unref(child);
return path;
}
@@ -1287,7 +1347,7 @@
{
sq_archive_store_append_history(store, iter);
- /* sq_archive_store_sort(store); */
+ sq_archive_store_sort(store);
sq_archive_store_refresh(store);
g_signal_emit(store,
sq_archive_store_signals[SQ_ARCHIVE_STORE_SIGNAL_PWD_CHANGED], 0,NULL);
@@ -1344,12 +1404,12 @@
if(store->props._sort_case_sensitive != sort)
{
store->props._sort_case_sensitive = sort;
- /* if(store->sort_column < 0) */
- /* store->sort_column = 1; */
+ if(store->sort_column <= 0)
+ store->sort_column = 1;
if(store->archive)
{
- /* sq_archive_store_sort(store); */
+ sq_archive_store_sort(store);
sq_archive_store_refresh(store);
}
}
@@ -1363,32 +1423,17 @@
if(store->props._sort_folders_first != sort)
{
store->props._sort_folders_first = sort;
- /* if(store->sort_column < 0) */
- /* store->sort_column = 1; */
+ if(store->sort_column <= 0)
+ store->sort_column = 1;
if(store->archive)
{
- /* sq_archive_store_sort(store); */
+ sq_archive_store_sort(store);
sq_archive_store_refresh(store);
}
}
}
-gchar *
-sq_archive_store_get_filename(SQArchiveStore *store, GtkTreeIter *iter)
-{
- LSQArchiveIter *entry = iter->user_data;
-
- const gchar *basename;
-
- basename = lsq_archive_iter_get_filename(entry);
-
- if(lsq_archive_iter_is_directory(entry))
- return g_strconcat(basename, "/", NULL);
- else
- return g_strdup(basename);
-}
-
gboolean
sq_archive_store_has_history(SQArchiveStore *store)
{
@@ -1420,7 +1465,7 @@
if(sq_archive_store_has_history(store))
store->navigation.present = store->navigation.present->prev;
- /* sq_archive_store_sort(store); */
+ sq_archive_store_sort(store);
sq_archive_store_refresh(store);
sq_archive_store_check_trailing(store);
@@ -1443,7 +1488,7 @@
if(sq_archive_store_has_future(store))
store->navigation.present = store->navigation.present->next;
- /* sq_archive_store_sort(store); */
+ sq_archive_store_sort(store);
sq_archive_store_refresh(store);
sq_archive_store_check_trailing(store);
@@ -1489,16 +1534,23 @@
{
LSQArchiveIter *piter = store->navigation.present->data;
LSQArchiveIter *titer = store->navigation.trailing;
+ LSQArchiveIter *child = NULL;
if(titer)
{
while(titer)
{
if(titer == piter)
+ {
+ lsq_archive_iter_unref(child);
return;
+ }
titer = lsq_archive_iter_get_parent(titer);
+ lsq_archive_iter_unref(child);
+ child = titer;
}
+ lsq_archive_iter_unref(child);
}
lsq_archive_iter_unref(store->navigation.trailing);
@@ -1514,19 +1566,22 @@
#endif
const gchar *basename;
- LSQArchiveIter *iter = store->navigation.trailing;
+ LSQArchiveIter *child = NULL, *iter = store->navigation.trailing;
GSList *path = NULL;
if(!iter)
return NULL;
/* we don't want to include de archive rootentry */
- while(lsq_archive_iter_get_parent(iter))
+ while(lsq_archive_iter_has_parent(iter))
{
basename = lsq_archive_iter_get_filename(iter);
path = g_slist_prepend(path, &basename);
iter = lsq_archive_iter_get_parent(iter);
+ lsq_archive_iter_unref(child);
+ child = iter;
}
+ lsq_archive_iter_unref(child);
return path;
}
Modified: squeeze/trunk/src/archive_store.h
===================================================================
--- squeeze/trunk/src/archive_store.h 2007-02-25 02:28:37 UTC (rev 25032)
+++ squeeze/trunk/src/archive_store.h 2007-02-25 19:23:21 UTC (rev 25033)
@@ -46,9 +46,9 @@
gint stamp;
LSQArchive *archive;
LSQArchiveSupport *support;
- // gint sort_column;
- // GtkSortType sort_order;
- // LSQArchiveIter **sort_list;
+ gint sort_column;
+ GtkSortType sort_order;
+ LSQArchiveIter **sort_list;
guint list_size;
GtkIconTheme *icon_theme;
GtkTreeView *treeview;
@@ -93,16 +93,6 @@
void sq_archive_store_set_sort_case_sensitive(SQArchiveStore *, gboolean);
void sq_archive_store_set_sort_folders_first(SQArchiveStore *, gboolean);
-gchar *
-sq_archive_store_get_filename(SQArchiveStore *store, GtkTreeIter *iter);
-
-/* want to depricate these */
-/*void
-sq_archive_store_set_history(SQArchiveStore *store, GList *history, GList
*pwd);
-void
-sq_archive_store_get_history(SQArchiveStore *store, GList **history, GList
**pwd);
-*/
-/* these replace them */
gboolean
sq_archive_store_has_history(SQArchiveStore *store);
gboolean
_______________________________________________
Xfce4-commits mailing list
[email protected]
http://foo-projects.org/mailman/listinfo/xfce4-commits