gui/model: Send tree model signals
"row-inserted", "row-deleted", and "row-changed" Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
dd2adc6307
commit
4fd370ceb6
35
gui/model.c
35
gui/model.c
|
@ -251,6 +251,41 @@ GType gui_queue_model_get_type()
|
|||
return queue_type;
|
||||
}
|
||||
|
||||
void gui_queue_model_add(GuiQueueModel *model, unsigned int row)
|
||||
{
|
||||
GtkTreePath *path = gtk_tree_path_new_from_indices(row, -1);
|
||||
GtkTreeIter iter;
|
||||
|
||||
_queue_model_get_iter(GTK_TREE_MODEL(model), &iter, path);
|
||||
gtk_tree_model_row_inserted(GTK_TREE_MODEL(model), path, &iter);
|
||||
gtk_tree_path_free(path);
|
||||
}
|
||||
|
||||
void gui_queue_model_remove(GuiQueueModel *model, unsigned int row)
|
||||
{
|
||||
GtkTreePath *path = gtk_tree_path_new_from_indices(row, -1);
|
||||
gtk_tree_model_row_deleted(GTK_TREE_MODEL(model), path);
|
||||
gtk_tree_path_free(path);
|
||||
}
|
||||
|
||||
void gui_queue_model_clear(GuiQueueModel *model, unsigned int n)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 1; i <= n; i++)
|
||||
gui_queue_model_remove(model, n - i);
|
||||
}
|
||||
|
||||
void gui_queue_model_update(GuiQueueModel *model, unsigned int row)
|
||||
{
|
||||
GtkTreePath *path = gtk_tree_path_new_from_indices(row, -1);
|
||||
GtkTreeIter iter;
|
||||
|
||||
_queue_model_get_iter(GTK_TREE_MODEL(model), &iter, path);
|
||||
gtk_tree_model_row_changed(GTK_TREE_MODEL(model), path, &iter);
|
||||
gtk_tree_path_free(path);
|
||||
}
|
||||
|
||||
|
||||
static const GTypeInfo queue_type_info = {
|
||||
.class_size = sizeof(GuiQueueModelClass),
|
||||
|
|
|
@ -46,4 +46,16 @@ GuiQueueModel *gui_queue_model_new(struct queue *);
|
|||
/* Called to find the GType of the GuiQueueModel */
|
||||
GType gui_queue_model_get_type();
|
||||
|
||||
/* Called to add a row to the model */
|
||||
void gui_queue_model_add(GuiQueueModel *, unsigned int);
|
||||
|
||||
/* Called to remove a row from the model */
|
||||
void gui_queue_model_remove(GuiQueueModel *, unsigned int);
|
||||
|
||||
/* Called to remove all rows from the model */
|
||||
void gui_queue_model_clear(GuiQueueModel *, unsigned int);
|
||||
|
||||
/* Called to update a row in the model */
|
||||
void gui_queue_model_update(GuiQueueModel *, unsigned int);
|
||||
|
||||
#endif /* OCARINA_GUI_MODEL_H */
|
||||
|
|
|
@ -7,7 +7,44 @@
|
|||
#include <gui/model.h>
|
||||
#include <tests/test.h>
|
||||
|
||||
struct core_init_data init_data;
|
||||
unsigned int count_insert = 0;
|
||||
unsigned int count_delete = 0;
|
||||
unsigned int count_update = 0;
|
||||
|
||||
void on_row_inserted(GtkTreeModel *model, GtkTreePath *path,
|
||||
GtkTreeIter *iter, gpointer data)
|
||||
{ count_insert++; }
|
||||
void on_row_deleted(GtkTreeModel *model, GtkTreePath *path, gpointer data)
|
||||
{ count_delete++; }
|
||||
void on_row_changed(GtkTreeModel *model, GtkTreePath *path,
|
||||
GtkTreeIter *iter, gpointer data)
|
||||
{ count_update++; }
|
||||
|
||||
void *test_queue_init(struct queue *queue) { return NULL; }
|
||||
void test_queue_deinit(struct queue *queue) {}
|
||||
void test_queue_added(struct queue *queue, unsigned int row)
|
||||
{ gui_queue_model_add(queue->q_private, row); }
|
||||
void test_queue_removed(struct queue *queue, unsigned int row)
|
||||
{ gui_queue_model_remove(queue->q_private, row); }
|
||||
void test_queue_cleared(struct queue *queue, unsigned int n)
|
||||
{ gui_queue_model_get_type(queue->q_private, n); }
|
||||
void test_queue_save(struct queue *queue, enum queue_flags flag) {}
|
||||
void test_queue_updated(struct queue *queue, unsigned int row)
|
||||
{ gui_queue_model_update(queue->q_private, row); }
|
||||
|
||||
struct queue_ops test_ops = {
|
||||
.qop_init = test_queue_init,
|
||||
.qop_deinit = test_queue_deinit,
|
||||
.qop_added = test_queue_added,
|
||||
.qop_removed = test_queue_removed,
|
||||
.qop_cleared = test_queue_cleared,
|
||||
.qop_save = test_queue_save,
|
||||
.qop_updated = test_queue_updated,
|
||||
};
|
||||
|
||||
struct core_init_data init_data = {
|
||||
.collection_ops = &test_ops,
|
||||
};
|
||||
|
||||
static void test_init()
|
||||
{
|
||||
|
@ -110,11 +147,19 @@ static void test_model()
|
|||
model = GTK_TREE_MODEL(gui_queue_model_new(collection_get_queue()));
|
||||
memset(&value, 0, sizeof(GValue));
|
||||
|
||||
g_signal_connect(model, "row-inserted", (GCallback)on_row_inserted, NULL);
|
||||
g_signal_connect(model, "row-deleted", (GCallback)on_row_deleted, NULL);
|
||||
g_signal_connect(model, "row-changed", (GCallback)on_row_changed, NULL);
|
||||
|
||||
/* Okay, now scan a directory ... */
|
||||
core_init(&argc, NULL, &init_data);
|
||||
collection_get_queue()->q_private = model;
|
||||
collection_add("tests/Music/Hyrule Symphony");
|
||||
while (idle_run_task() == true) {}
|
||||
test_equal(queue_size(collection_get_queue()), 13);
|
||||
test_equal(count_insert, 13);
|
||||
queue_resort(collection_get_queue());
|
||||
test_equal(count_update, 13);
|
||||
|
||||
/* ... and test again */
|
||||
test_equal(gtk_tree_model_get_iter_first(model, &iter), true);
|
||||
|
@ -176,6 +221,11 @@ static void test_model()
|
|||
|
||||
test_equal(gtk_tree_model_iter_parent(model, &iter, &iter), false);
|
||||
|
||||
while (queue_size(collection_get_queue()) > 0)
|
||||
queue_remove(collection_get_queue(), 0);
|
||||
test_equal(count_delete, 13);
|
||||
|
||||
core_deinit();
|
||||
g_object_unref(model);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue