changeset 18564:36257cac2b11

Anoter patch from Javeed Shaikh to introduce a utility function for a tree. I changed it a bit, but hopefully I didn't break the patch in the process.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Thu, 19 Jul 2007 21:34:35 +0000
parents dba4edbde4a7
children 980d6e1b2d21 44e07aa8386a
files finch/libgnt/gnttree.c finch/libgnt/gnttree.h
diffstat 2 files changed, 33 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/finch/libgnt/gnttree.c	Thu Jul 19 21:11:37 2007 +0000
+++ b/finch/libgnt/gnttree.c	Thu Jul 19 21:34:35 2007 +0000
@@ -1363,24 +1363,30 @@
 	return NULL;
 }
 
-GList *gnt_tree_get_selection_text_list(GntTree *tree)
+GList *gnt_tree_get_row_text_list(GntTree *tree, gpointer key)
 {
 	GList *list = NULL, *iter;
+	GntTreeRow *row = key ? g_hash_table_lookup(tree->hash, key) : tree->current;
 	int i;
 
-	if (!tree->current)
+	if (!row)
 		return NULL;
 
-	for (i = 0, iter = tree->current->columns; i < tree->ncol && iter;
+	for (i = 0, iter = row->columns; i < tree->ncol && iter;
 			i++, iter = iter->next)
 	{
 		GntTreeCol *col = iter->data;
-		list = g_list_append(list, g_strdup(col->text));
+		list = g_list_append(list, BINARY_DATA(tree, i) ? col->text : g_strdup(col->text));
 	}
 
 	return list;
 }
 
+GList *gnt_tree_get_selection_text_list(GntTree *tree)
+{
+	return gnt_tree_get_row_text_list(tree, NULL);
+}
+
 void gnt_tree_remove(GntTree *tree, gpointer key)
 {
 	GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
--- a/finch/libgnt/gnttree.h	Thu Jul 19 21:11:37 2007 +0000
+++ b/finch/libgnt/gnttree.h	Thu Jul 19 21:34:35 2007 +0000
@@ -200,16 +200,38 @@
  * @param tree  The tree
  *
  * @return  The text, which needs to be freed by the caller
+ * @see gnt_tree_get_row_text_list
+ * @see gnt_tree_get_selection_text_list
  */
 char * gnt_tree_get_selection_text(GntTree *tree);
 
 /**
+ * Get a list of text for a row.
+ *
+ * @param tree  The tree
+ * @param key   A key corresponding to the row in question. If key
+ *              is @c NULL, the text list for the selected row will
+ *              be returned.
+ *
+ * @return A list of texts of a row. The list and its data should be
+ *         freed by the caller. The caller should make sure that if
+ *         any column of the tree contains binary data, it's not freed.
+ * @see gnt_tree_get_selection_text_list 
+ * @see gnt_tree_get_selection_text
+ */
+GList * gnt_tree_get_row_text_list(GntTree *tree, gpointer key);
+
+/**
  * Get a list of text of the current row.
  *
  * @param tree  The tree
  *
  * @return A list of texts of the currently selected row. The list
- *         and its data should be freed by the caller.
+ *         and its data should be freed by the caller. The caller
+ *         should make sure that if any column of the tree contains
+ *         binary data, it's not freed.
+ * @see gnt_tree_get_row_text_list
+ * @see gnt_tree_get_selection_text
  */
 GList * gnt_tree_get_selection_text_list(GntTree *tree);