gui/model: Store a GList in the GtkTreeIter
Storing the current link from the playlist should give us immediate access to the track, rather than needing to use playlist_at() all the time. Additionally, we can now use g_list_next() whenever we need to do a gtk_tree_model_iter_next() Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
1c6305e24e
commit
a808cac04c
29
gui/model.c
29
gui/model.c
|
@ -61,23 +61,25 @@ static gboolean __gui_model_get_iter(GtkTreeModel *model, GtkTreeIter *iter,
|
||||||
static GtkTreePath *__gui_model_get_path(GtkTreeModel *model, GtkTreeIter *iter)
|
static GtkTreePath *__gui_model_get_path(GtkTreeModel *model, GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
GtkTreePath *path;
|
GtkTreePath *path;
|
||||||
|
unsigned int pos;
|
||||||
|
|
||||||
g_return_val_if_fail(iter != NULL, FALSE);
|
g_return_val_if_fail(iter != NULL, FALSE);
|
||||||
g_return_val_if_fail(iter->user_data2, FALSE);
|
g_return_val_if_fail(iter->user_data, FALSE);
|
||||||
|
|
||||||
path = gtk_tree_path_new();
|
path = gtk_tree_path_new();
|
||||||
gtk_tree_path_append_index(path, GPOINTER_TO_UINT(iter->user_data));
|
pos = playlist_iter_index(cur_playlist, iter->user_data);
|
||||||
|
gtk_tree_path_append_index(path, pos);
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __gui_model_get_value(GtkTreeModel *model, GtkTreeIter *iter,
|
static void __gui_model_get_value(GtkTreeModel *model, GtkTreeIter *iter,
|
||||||
gint column, GValue *value)
|
gint column, GValue *value)
|
||||||
{
|
{
|
||||||
struct track *track = iter->user_data2;
|
struct track *track = playlist_iter_track(iter->user_data);
|
||||||
gchar *str;
|
gchar *str;
|
||||||
|
|
||||||
g_return_if_fail(iter != NULL);
|
g_return_if_fail(iter != NULL);
|
||||||
g_return_if_fail(iter->user_data2 != NULL);
|
g_return_if_fail(iter->user_data != NULL);
|
||||||
g_return_if_fail(column < GUI_MODEL_N_COLUMNS);
|
g_return_if_fail(column < GUI_MODEL_N_COLUMNS);
|
||||||
|
|
||||||
g_value_init(value, gui_model_columns[column]);
|
g_value_init(value, gui_model_columns[column]);
|
||||||
|
@ -124,13 +126,11 @@ static void __gui_model_get_value(GtkTreeModel *model, GtkTreeIter *iter,
|
||||||
|
|
||||||
static gboolean __gui_model_iter_next(GtkTreeModel *model, GtkTreeIter *iter)
|
static gboolean __gui_model_iter_next(GtkTreeModel *model, GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
unsigned int pos;
|
g_return_val_if_fail(iter != NULL, FALSE);
|
||||||
|
g_return_val_if_fail(iter->user_data, FALSE);
|
||||||
|
|
||||||
g_return_val_if_fail(iter != NULL, FALSE);
|
iter->user_data = playlist_iter_next(iter->user_data);
|
||||||
g_return_val_if_fail(iter->user_data2, FALSE);
|
return iter->user_data != NULL;
|
||||||
|
|
||||||
pos = GPOINTER_TO_UINT(iter->user_data) + 1;
|
|
||||||
return __gui_model_iter_nth_child(model, iter, NULL, pos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean __gui_model_iter_children(GtkTreeModel *model, GtkTreeIter *iter,
|
static gboolean __gui_model_iter_children(GtkTreeModel *model, GtkTreeIter *iter,
|
||||||
|
@ -159,10 +159,9 @@ static gboolean __gui_model_iter_nth_child(GtkTreeModel *model,
|
||||||
if (parent || !cur_playlist || n >= playlist_size(cur_playlist))
|
if (parent || !cur_playlist || n >= playlist_size(cur_playlist))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
iter->stamp = gui_model->gm_stamp;
|
iter->stamp = gui_model->gm_stamp;
|
||||||
iter->user_data = GUINT_TO_POINTER(n);
|
iter->user_data = playlist_iter_get(cur_playlist, n);
|
||||||
iter->user_data2 = playlist_at(cur_playlist, n);
|
return iter->user_data != NULL;
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean __gui_model_iter_parent(GtkTreeModel *model, GtkTreeIter *iter,
|
static gboolean __gui_model_iter_parent(GtkTreeModel *model, GtkTreeIter *iter,
|
||||||
|
|
|
@ -74,8 +74,8 @@ struct playlist *gui_model_get_playlist(void);
|
||||||
static inline struct track *gui_model_iter_get_track(GtkTreeIter *iter)
|
static inline struct track *gui_model_iter_get_track(GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail(iter != NULL, NULL);
|
g_return_val_if_fail(iter != NULL, NULL);
|
||||||
g_return_val_if_fail(iter->user_data2 != NULL, NULL);
|
g_return_val_if_fail(iter->user_data != NULL, NULL);
|
||||||
return (struct track *)iter->user_data2;
|
return playlist_iter_track(iter->user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Called to convert a GtkTreePath into a struct track */
|
/* Called to convert a GtkTreePath into a struct track */
|
||||||
|
|
Loading…
Reference in New Issue