예제 #1
0
static gboolean
packet_list_iter_children(GtkTreeModel *tree_model, GtkTreeIter *iter,
			  GtkTreeIter *parent)
{
	PacketList *packet_list;

	g_return_val_if_fail(parent == NULL || parent->user_data != NULL,
				 FALSE);

	/* This is a list, nodes have no children. */
	if(parent)
		return FALSE;

	/* parent == NULL is a special case; we need to return the first top-
	 * level row */

	g_return_val_if_fail(PACKETLIST_IS_LIST(tree_model), FALSE);

	packet_list = PACKET_LIST(tree_model);

	/* No rows => no first row */
	if(PACKET_LIST_RECORD_COUNT(packet_list->rows) == 0)
		return FALSE;

	/* Set iter to first item in list */
	iter->stamp = packet_list->stamp;
	iter->user_data = PACKET_LIST_RECORD_GET(packet_list->rows, 0);

	return TRUE;
}
예제 #2
0
/* Takes an iter structure and sets it to point to the next row. */
static gboolean
packet_list_iter_next(GtkTreeModel *tree_model, GtkTreeIter *iter)
{
	PacketListRecord *record, *nextrecord;
	PacketList *packet_list;

	g_return_val_if_fail(PACKETLIST_IS_LIST(tree_model), FALSE);

	if(iter == NULL || iter->user_data == NULL)
		return FALSE;

	packet_list = PACKET_LIST(tree_model);

	record = (PacketListRecord*) iter->user_data;

	/* Is this the last record in the list? */
	if((record->pos + 1) >= PACKET_LIST_RECORD_COUNT(packet_list->rows))
		return FALSE;

	nextrecord = PACKET_LIST_RECORD_GET(packet_list->rows, (record->pos + 1));

	g_assert(nextrecord != NULL);
	g_assert(nextrecord->pos == (record->pos + 1));

	iter->stamp = packet_list->stamp;
	iter->user_data = nextrecord;

	return TRUE;
}
예제 #3
0
static gboolean
packet_list_get_iter(GtkTreeModel *tree_model, GtkTreeIter *iter,
			 GtkTreePath *path)
{
	PacketList *packet_list;
	PacketListRecord *record;
	gint *indices, depth;
	gint n;

	g_assert(PACKETLIST_IS_LIST(tree_model));
	g_assert(path != NULL);

	indices = gtk_tree_path_get_indices(path);
	depth = gtk_tree_path_get_depth(path);

	/* we do not allow children since it's just a list */
	g_assert(depth == 1);

	n = indices[0]; /* the n-th top level row */

	packet_list = PACKET_LIST(tree_model);
	if(PACKET_LIST_RECORD_COUNT(packet_list->visible_rows) == 0)
		return FALSE;

	if(!PACKET_LIST_RECORD_INDEX_VALID(packet_list->visible_rows, n))
		return FALSE;

	record = PACKET_LIST_RECORD_GET(packet_list->visible_rows, n);

	g_assert(record->visible_pos == n);

	/* We simply store a pointer to our custom record in the iter */
	iter->stamp = packet_list->stamp;
	iter->user_data = record;
	iter->user_data2 = NULL;
	iter->user_data3 = NULL;

	return TRUE;
}
예제 #4
0
static void
packet_list_get_value(GtkTreeModel *tree_model, GtkTreeIter *iter, gint column,
			  GValue *value)
{
	PacketListRecord *record;
	PacketList *packet_list;
	GType type;

	g_return_if_fail(PACKETLIST_IS_LIST(tree_model));
	g_return_if_fail(iter != NULL);
	packet_list = PACKET_LIST(tree_model);
	g_return_if_fail(column < packet_list->n_columns);

	type = packet_list->column_types[column];
	g_value_init(value, type);

	record = (PacketListRecord*) iter->user_data;

	g_return_if_fail(record->pos < PACKET_LIST_RECORD_COUNT(packet_list->rows));

	/* XXX Probably the switch should be on column or 
	 * should we allways return the pointer and read the data as required??
	 * If we use FOREGROUND_COLOR_COL etc we'll need a couple of "internal" columns
	 */ 
	switch(type){
		case G_TYPE_POINTER:
			g_value_set_pointer(value, iter->user_data);
			break;
		case G_TYPE_STRING:
			g_value_set_string(value, record->fdata->col_text[column]);
			break;
		default:
			g_warning ("%s: Unsupported type (%s) retrieved.", G_STRLOC, g_type_name (value->g_type));
			break;
	}
}