gui/model: Add support for gtk_tree_model_iter_nth_child()
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
ba59d6bd29
commit
ccf6e4c61f
48
gui/model.c
48
gui/model.c
|
@ -22,6 +22,20 @@ static GType queue_columns[Q_MODEL_N_COLUMNS] = {
|
||||||
[Q_MODEL_FILE_PATH] = G_TYPE_STRING,
|
[Q_MODEL_FILE_PATH] = G_TYPE_STRING,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static gboolean __queue_model_iter_nth(GuiQueueModel *model,
|
||||||
|
GtkTreeIter *iter,
|
||||||
|
gint n)
|
||||||
|
{
|
||||||
|
if (n >= queue_size(model->gqm_queue))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
_q_iter_set(&model->gqm_queue->q_tracks, &model->gqm_iter, n);
|
||||||
|
iter->stamp = model->gqm_stamp;
|
||||||
|
iter->user_data = &model->gqm_iter;
|
||||||
|
iter->user_data2 = _q_iter_val(&model->gqm_iter);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static GtkTreeModelFlags _queue_model_get_flags(GtkTreeModel *model)
|
static GtkTreeModelFlags _queue_model_get_flags(GtkTreeModel *model)
|
||||||
{
|
{
|
||||||
|
@ -43,22 +57,13 @@ static GType _queue_model_get_column_type(GtkTreeModel *model, gint index)
|
||||||
static gboolean _queue_model_get_iter(GtkTreeModel *model, GtkTreeIter *iter,
|
static gboolean _queue_model_get_iter(GtkTreeModel *model, GtkTreeIter *iter,
|
||||||
GtkTreePath *path)
|
GtkTreePath *path)
|
||||||
{
|
{
|
||||||
GuiQueueModel *gqm = GUI_QUEUE_MODEL(model);
|
|
||||||
gint *indices, depth;
|
gint *indices, depth;
|
||||||
|
|
||||||
g_assert(path != NULL);
|
g_assert(path != NULL);
|
||||||
|
|
||||||
indices = gtk_tree_path_get_indices_with_depth(path, &depth);
|
indices = gtk_tree_path_get_indices_with_depth(path, &depth);
|
||||||
g_assert(depth == 1);
|
g_assert(depth == 1);
|
||||||
|
|
||||||
if (indices[0] >= queue_size(gqm->gqm_queue))
|
return __queue_model_iter_nth(GUI_QUEUE_MODEL(model), iter, indices[0]);
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
_q_iter_set(&gqm->gqm_queue->q_tracks, &gqm->gqm_iter, indices[0]);
|
|
||||||
iter->stamp = gqm->gqm_stamp;
|
|
||||||
iter->user_data = &gqm->gqm_iter;
|
|
||||||
iter->user_data2 = _q_iter_val(&gqm->gqm_iter);
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GtkTreePath *_queue_model_get_path(GtkTreeModel *model, GtkTreeIter *iter)
|
static GtkTreePath *_queue_model_get_path(GtkTreeModel *model, GtkTreeIter *iter)
|
||||||
|
@ -146,19 +151,9 @@ static gboolean _queue_model_iter_children(GtkTreeModel *model,
|
||||||
GtkTreeIter *iter,
|
GtkTreeIter *iter,
|
||||||
GtkTreeIter *parent)
|
GtkTreeIter *parent)
|
||||||
{
|
{
|
||||||
GuiQueueModel *gqm = GUI_QUEUE_MODEL(model);
|
|
||||||
|
|
||||||
if (parent)
|
if (parent)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
return __queue_model_iter_nth(GUI_QUEUE_MODEL(model), iter, 0);
|
||||||
if (queue_size(gqm->gqm_queue) == 0)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
_q_iter_init(&gqm->gqm_queue->q_tracks, &gqm->gqm_iter);
|
|
||||||
iter->stamp = gqm->gqm_stamp;
|
|
||||||
iter->user_data = &gqm->gqm_iter;
|
|
||||||
iter->user_data2 = _q_iter_val(&gqm->gqm_iter);
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean _queue_model_iter_has_child(GtkTreeModel *model,
|
static gboolean _queue_model_iter_has_child(GtkTreeModel *model,
|
||||||
|
@ -175,6 +170,16 @@ static gint _queue_model_iter_n_children(GtkTreeModel *model,
|
||||||
return queue_size(GUI_QUEUE_MODEL(model)->gqm_queue);
|
return queue_size(GUI_QUEUE_MODEL(model)->gqm_queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean _queue_model_iter_nth_child(GtkTreeModel *model,
|
||||||
|
GtkTreeIter *iter,
|
||||||
|
GtkTreeIter *parent,
|
||||||
|
gint n)
|
||||||
|
{
|
||||||
|
if (parent)
|
||||||
|
return FALSE;
|
||||||
|
return __queue_model_iter_nth(GUI_QUEUE_MODEL(model), iter, n);
|
||||||
|
}
|
||||||
|
|
||||||
static void _queue_model_init(GuiQueueModel *model)
|
static void _queue_model_init(GuiQueueModel *model)
|
||||||
{
|
{
|
||||||
model->gqm_stamp = g_random_int();
|
model->gqm_stamp = g_random_int();
|
||||||
|
@ -207,6 +212,7 @@ static void _queue_tree_model_init(GtkTreeModelIface *iface)
|
||||||
iface->iter_children = _queue_model_iter_children;
|
iface->iter_children = _queue_model_iter_children;
|
||||||
iface->iter_has_child = _queue_model_iter_has_child;
|
iface->iter_has_child = _queue_model_iter_has_child;
|
||||||
iface->iter_n_children = _queue_model_iter_n_children;
|
iface->iter_n_children = _queue_model_iter_n_children;
|
||||||
|
iface->iter_nth_child = _queue_model_iter_nth_child;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -92,6 +92,7 @@ static void test_empty()
|
||||||
test_equal(gtk_tree_model_iter_has_child(model, &iter), false);
|
test_equal(gtk_tree_model_iter_has_child(model, &iter), false);
|
||||||
test_equal(gtk_tree_model_iter_n_children(model, &iter), 0);
|
test_equal(gtk_tree_model_iter_n_children(model, &iter), 0);
|
||||||
test_equal(gtk_tree_model_iter_n_children(model, NULL), 0);
|
test_equal(gtk_tree_model_iter_n_children(model, NULL), 0);
|
||||||
|
test_equal(gtk_tree_model_iter_nth_child(model, &iter, NULL, 3), false);
|
||||||
|
|
||||||
g_object_unref(model);
|
g_object_unref(model);
|
||||||
}
|
}
|
||||||
|
@ -168,6 +169,10 @@ static void test_model()
|
||||||
test_equal(gtk_tree_model_iter_n_children(model, &iter), 0);
|
test_equal(gtk_tree_model_iter_n_children(model, &iter), 0);
|
||||||
test_equal(gtk_tree_model_iter_n_children(model, NULL), 13);
|
test_equal(gtk_tree_model_iter_n_children(model, NULL), 13);
|
||||||
|
|
||||||
|
test_equal(gtk_tree_model_iter_nth_child(model, &iter, NULL, 3), true);
|
||||||
|
track = iter.user_data2;
|
||||||
|
test_equal(track->tr_track, 4);
|
||||||
|
|
||||||
g_object_unref(model);
|
g_object_unref(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue