#ifndef __LIST_H_
#define __LIST_H_

#include <time.h>

#define LIST_GET_COLUMN_DATA(list,item,column_idx)\
	list->column_data_func(item,column_idx)

#define LIST_GET_NTH_ITEM(list,row_idx) \
	g_list_nth(list->items,row_idx)->data

#define LIST_GET_NTH_ITEM_GLIST(list,row_idx) \
	g_list_nth(list->items,row_idx)

#define LIST_ADD_ITEM(list,item) \
	list->items = g_list_append(list->items,item)

#define LIST_ADD_ITEM_POSITION(list,item,_idx) \
	list->items = g_list_insert(list->items,item,_idx)

#define LIST_REMOVE_ITEM(list,_idx) \
	list->items = g_list_remove(list->items, g_list_nth(list->items, _idx)->data)

#define LAST_SELECTED_NONE -1

typedef gchar*    (*ColumnDataFunc)      (gpointer item, gint column_idx);
typedef gboolean  (*RowGetSelectedFunc)  (gpointer item);
typedef void      (*RowSetSelectedFunc)  (gpointer item, gboolean selected);
typedef void      (*ListSortFunc)        (gconstpointer data1, gconstpointer data2);
typedef void      (*OnDisplayFunc)       (gpointer item);
typedef void      (*ItemSwapFunc)        (GList    *items, gint _idx1, gint _idx2);
typedef void      (*CurrentSetFunc)      (gpointer item, gboolean current);
typedef void      (*SetDirtyFunc)        (gpointer item, gboolean current);
typedef gboolean  (*GetDirtyFunc)        (gpointer item);
typedef void      (*SetRenderedFunc)     (gpointer item, gboolean rendered);
typedef gboolean  (*GetRenderedFunc)     (gpointer item);

typedef struct _BmpListType BmpListType;

struct _BmpListType {
	gchar	    *name;
	GList       *items;

	gint         current;
	gint	     last_selected;
	gboolean     multiple_selected;

	gdouble	     adjustment;

	ColumnDataFunc     column_data_func;

	RowGetSelectedFunc row_get_selected_func;
	RowSetSelectedFunc row_set_selected_func;
	ListSortFunc	   list_sort_func;
        ItemSwapFunc       item_swap_func;

	OnDisplayFunc	   on_display_func;

	SetDirtyFunc	   set_dirty_func;
	GetDirtyFunc	   get_dirty_func;

	SetRenderedFunc	   set_rendered_func;
	GetRenderedFunc	   get_rendered_func;

	GDestroyNotify     item_destroy_func;

	time_t		   time;
};

#define BMP_LIST(list) ((BmpListType *) list)

typedef struct _BmpPlaybackHistoryItem BmpPlaybackHistoryItem;
typedef struct _BmpPlaybackHistory BmpPlaybackHistory;
typedef struct _RowGUID RowGUID;

typedef BmpPlaybackHistoryItem*  (*PlaybackHistoryGetItemFunc) (const BmpListType *playlists, gint tracklist);

struct _BmpPlaybackHistoryItem {

    gchar *list_name;
    time_t list_time;

    RowGUID *guid;
};

struct _RowGUID {
    guint   counter;
    guint   hash;
};
#define ROW_GUID(guid) ((RowGUID*)(guid))

gboolean
row_guid_equal_func (RowGUID *guid_a, RowGUID *guid_b);

guint
row_guid_hash_func (RowGUID *guid);

struct _BmpPlaybackHistory {

    GList	  *history;
    gint	   length; 
    gint	   mark;
};

typedef struct _BmpFileItem BmpFileItem;
typedef struct _BmpPlaylistItem BmpPlaylistItem;

struct _BmpFileItem {
	gchar *uri;

	RowGUID *guid;

	gboolean selected;
	gboolean dirty;
	gboolean rendered;

};
#define BMP_FILE_ITEM(item) ((BmpFileItem*)(item))

struct _BmpPlaylistItem {
	gchar *filename;
	gchar *listname;

	gboolean selected;
	gboolean dirty;
	gboolean rendered;

	BmpListType *list;

};
#define BMP_PLAYLIST_ITEM(item) ((BmpPlaylistItem*)(item))


#endif /* __LIST_H_ */
