gui/model: Convert set_queue() -> set_playlist()

Ocarina is moving in a playlist oriented direction, so move away from
using the queue directly in favor of using the playlist.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2016-08-20 21:01:19 -04:00
parent 82da46365f
commit 010969c7b3
9 changed files with 98 additions and 75 deletions

View File

@ -2,7 +2,7 @@
* Copyright 2016 (c) Anna Schumaker. * Copyright 2016 (c) Anna Schumaker.
*/ */
#include <core/audio.h> #include <core/audio.h>
#include <core/queue.h> #include <core/playlist.h>
#include <core/string.h> #include <core/string.h>
#include <gui/builder.h> #include <gui/builder.h>
#include <gui/model.h> #include <gui/model.h>
@ -10,9 +10,10 @@
static gboolean __gui_model_iter_nth_child(GtkTreeModel *, GtkTreeIter *, static gboolean __gui_model_iter_nth_child(GtkTreeModel *, GtkTreeIter *,
GtkTreeIter *, gint); GtkTreeIter *, gint);
static GObjectClass *parent_class = NULL; static struct playlist *cur_playlist = NULL;
static GuiModel *queue_model = NULL; static GObjectClass *parent_class = NULL;
static GType gui_model_type = 0; static GuiModel *queue_model = NULL;
static GType gui_model_type = 0;
static GType gui_model_columns[GUI_MODEL_N_COLUMNS] = { static GType gui_model_columns[GUI_MODEL_N_COLUMNS] = {
[GUI_MODEL_TRACK_NR] = G_TYPE_UINT, [GUI_MODEL_TRACK_NR] = G_TYPE_UINT,
@ -155,9 +156,9 @@ static gboolean __gui_model_iter_has_child(GtkTreeModel *model, GtkTreeIter *ite
static gint __gui_model_iter_n_children(GtkTreeModel *model, GtkTreeIter *iter) static gint __gui_model_iter_n_children(GtkTreeModel *model, GtkTreeIter *iter)
{ {
if (iter != NULL || !queue_model->gm_queue) if (iter != NULL || !cur_playlist)
return 0; return 0;
return queue_size(GUI_MODEL(model)->gm_queue); return queue_size(&cur_playlist->pl_queue);
} }
static gboolean __gui_model_iter_nth_child(GtkTreeModel *model, static gboolean __gui_model_iter_nth_child(GtkTreeModel *model,
@ -165,11 +166,11 @@ static gboolean __gui_model_iter_nth_child(GtkTreeModel *model,
GtkTreeIter *parent, GtkTreeIter *parent,
gint n) gint n)
{ {
if (parent || !queue_model->gm_queue || if (parent || !cur_playlist ||
n >= queue_size(queue_model->gm_queue)) n >= queue_size(&cur_playlist->pl_queue))
return FALSE; return FALSE;
queue_iter_set(queue_model->gm_queue, &queue_model->gm_iter, n); queue_iter_set(&cur_playlist->pl_queue, &queue_model->gm_iter, n);
iter->stamp = queue_model->gm_stamp; iter->stamp = queue_model->gm_stamp;
iter->user_data = &queue_model->gm_iter; iter->user_data = &queue_model->gm_iter;
iter->user_data2 = queue_iter_val(&queue_model->gm_iter); iter->user_data2 = queue_iter_val(&queue_model->gm_iter);
@ -245,7 +246,6 @@ void gui_model_init(void)
queue_model = g_object_new(gui_model_type, NULL); queue_model = g_object_new(gui_model_type, NULL);
g_assert(queue_model != NULL); g_assert(queue_model != NULL);
queue_model->gm_queue = NULL;
} }
void gui_model_deinit(void) void gui_model_deinit(void)
@ -253,14 +253,15 @@ void gui_model_deinit(void)
g_object_unref(queue_model); g_object_unref(queue_model);
gui_model_type = 0; gui_model_type = 0;
queue_model = NULL; queue_model = NULL;
cur_playlist = NULL;
} }
static void __gui_model_set_runtime(void) static void __gui_model_set_runtime(void)
{ {
gchar *len = NULL; gchar *len = NULL;
if (queue_model->gm_queue) if (cur_playlist)
len = string_sec2str_long(queue_model->gm_queue->q_length); len = string_sec2str_long(cur_playlist->pl_queue.q_length);
gtk_label_set_text(GTK_LABEL(gui_builder_widget("o_runtime")), len); gtk_label_set_text(GTK_LABEL(gui_builder_widget("o_runtime")), len);
g_free(len); g_free(len);
@ -276,12 +277,12 @@ GType gui_model_get_type()
return gui_model_type; return gui_model_type;
} }
void gui_model_add(struct queue *queue, unsigned int row) void gui_model_add(struct playlist *playlist, unsigned int row)
{ {
GtkTreePath *path; GtkTreePath *path;
GtkTreeIter iter; GtkTreeIter iter;
if (!queue_model || queue != queue_model->gm_queue) if (cur_playlist != playlist)
return; return;
path = gtk_tree_path_new_from_indices(row, -1); path = gtk_tree_path_new_from_indices(row, -1);
@ -291,11 +292,11 @@ void gui_model_add(struct queue *queue, unsigned int row)
gtk_tree_path_free(path); gtk_tree_path_free(path);
} }
void gui_model_remove(struct queue *queue, unsigned int row) void gui_model_remove(struct playlist *playlist, unsigned int row)
{ {
GtkTreePath *path; GtkTreePath *path;
if (queue != queue_model->gm_queue) if (cur_playlist != playlist)
return; return;
path = gtk_tree_path_new_from_indices(row, -1); path = gtk_tree_path_new_from_indices(row, -1);
@ -304,12 +305,12 @@ void gui_model_remove(struct queue *queue, unsigned int row)
gtk_tree_path_free(path); gtk_tree_path_free(path);
} }
void gui_model_clear(struct queue *queue, unsigned int n) void gui_model_clear(struct playlist *playlist, unsigned int n)
{ {
GtkTreePath *path; GtkTreePath *path;
unsigned int i; unsigned int i;
if (!queue_model || queue != queue_model->gm_queue) if (!queue_model || cur_playlist != playlist)
return; return;
path = gtk_tree_path_new_from_indices(n - 1, -1); path = gtk_tree_path_new_from_indices(n - 1, -1);
@ -322,12 +323,12 @@ void gui_model_clear(struct queue *queue, unsigned int n)
gtk_tree_path_free(path); gtk_tree_path_free(path);
} }
void gui_model_update(struct queue *queue, unsigned int row) void gui_model_update(struct playlist *playlist, unsigned int row)
{ {
GtkTreePath *path; GtkTreePath *path;
GtkTreeIter iter; GtkTreeIter iter;
if (queue != queue_model->gm_queue) if (cur_playlist != playlist)
return; return;
path = gtk_tree_path_new_from_indices(row, -1); path = gtk_tree_path_new_from_indices(row, -1);
@ -337,23 +338,21 @@ void gui_model_update(struct queue *queue, unsigned int row)
gtk_tree_path_free(path); gtk_tree_path_free(path);
} }
void gui_model_set_queue(struct queue *queue) void gui_model_set_playlist(struct playlist *playlist)
{ {
struct queue *cur = queue_model->gm_queue; if (cur_playlist)
gui_model_clear(cur_playlist, queue_size(&cur_playlist->pl_queue));
if (cur) cur_playlist = playlist;
gui_model_clear(cur, queue_size(cur));
queue_model->gm_queue = queue;
__gui_model_set_runtime(); __gui_model_set_runtime();
if (queue && queue_size(queue) > 0) if (playlist && queue_size(&playlist->pl_queue) > 0)
gui_model_add(queue, 0); gui_model_add(playlist, 0);
} }
struct queue *gui_model_get_queue(void) struct playlist *gui_model_get_playlist(void)
{ {
return queue_model ? queue_model->gm_queue : NULL; return cur_playlist;
} }
struct track * gui_model_path_get_track(GtkTreePath *path) struct track * gui_model_path_get_track(GtkTreePath *path)

View File

@ -259,22 +259,27 @@ static void *__playlist_init(struct queue *queue, void *data)
static void __playlist_added(struct queue *queue, unsigned int row) static void __playlist_added(struct queue *queue, unsigned int row)
{ {
gui_model_add(queue, row); gui_model_add(gui_queue(queue)->gq_playlist, row);
__playlist_update_sizes(queue); __playlist_update_sizes(queue);
} }
static void __playlist_removed(struct queue *queue, unsigned int row) static void __playlist_removed(struct queue *queue, unsigned int row)
{ {
gui_model_remove(queue, row); gui_model_remove(gui_queue(queue)->gq_playlist, row);
__playlist_update_sizes(queue); __playlist_update_sizes(queue);
} }
static void __playlist_cleared(struct queue *queue, unsigned int n) static void __playlist_cleared(struct queue *queue, unsigned int n)
{ {
gui_model_clear(queue, n); gui_model_clear(gui_queue(queue)->gq_playlist, n);
__playlist_update_sizes(queue); __playlist_update_sizes(queue);
} }
static void __playlist_updated(struct queue *queue, unsigned int n)
{
gui_model_update(gui_queue(queue)->gq_playlist, n);
}
static bool __playlist_erase(struct queue *queue, struct track *track) static bool __playlist_erase(struct queue *queue, struct track *track)
{ {
enum playlist_type_t type = gui_queue(queue)->gq_playlist->pl_type; enum playlist_type_t type = gui_queue(queue)->gq_playlist->pl_type;
@ -481,5 +486,5 @@ struct queue_ops playlist_ops = {
.qop_erase = __playlist_erase, .qop_erase = __playlist_erase,
.qop_removed = __playlist_removed, .qop_removed = __playlist_removed,
.qop_cleared = __playlist_cleared, .qop_cleared = __playlist_cleared,
.qop_updated = gui_model_update, .qop_updated = __playlist_updated,
}; };

View File

@ -140,7 +140,7 @@ void gui_queue_free(struct queue *queue)
queue->q_private = NULL; queue->q_private = NULL;
if (gq_queue == gq) if (gq_queue == gq)
gui_view_set_queue(NULL); gui_view_set_playlist(NULL);
if (gq->gq_search) if (gq->gq_search)
g_strfreev(gq->gq_search); g_strfreev(gq->gq_search);
g_free(gq->gq_text); g_free(gq->gq_text);
@ -160,9 +160,9 @@ void gui_queue_show(struct gui_queue *queue)
if (queue) { if (queue) {
has_random = queue_has_flag(queue->gq_queue, Q_RANDOM); has_random = queue_has_flag(queue->gq_queue, Q_RANDOM);
gui_view_set_queue(queue->gq_queue); gui_view_set_playlist(queue->gq_playlist);
} else } else
gui_view_set_queue(NULL); gui_view_set_playlist(NULL);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(random), has_random); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(random), has_random);
gtk_widget_set_sensitive(GTK_WIDGET(search), queue != NULL); gtk_widget_set_sensitive(GTK_WIDGET(search), queue != NULL);

View File

@ -95,8 +95,8 @@ static int __view_dec_sort(gpointer data)
static void __view_set_column_sort_indicator(GtkTreeViewColumn *col, static void __view_set_column_sort_indicator(GtkTreeViewColumn *col,
unsigned int index) unsigned int index)
{ {
struct queue *queue = gui_model_get_queue(); struct playlist *playlist = gui_model_get_playlist();
GSList *cur = queue ? queue->q_sort : NULL; GSList *cur = playlist ? playlist->pl_queue.q_sort : NULL;
unsigned int order = GTK_SORT_ASCENDING; unsigned int order = GTK_SORT_ASCENDING;
bool show = false; bool show = false;
int field; int field;
@ -135,7 +135,7 @@ void __view_row_activated(GtkTreeView *treeview, GtkTreePath *path,
{ {
view_no_scroll = true; view_no_scroll = true;
audio_load(__view_filter_get_track(path)); audio_load(__view_filter_get_track(path));
queue_selected(gui_model_get_queue(), queue_selected(&gui_model_get_playlist()->pl_queue,
gtk_tree_path_get_indices(path)[0]); gtk_tree_path_get_indices(path)[0]);
view_no_scroll = false; view_no_scroll = false;
} }
@ -150,7 +150,8 @@ void __view_column_resized(GtkTreeViewColumn *col, GParamSpec *pspec,
void __view_column_clicked(GtkTreeViewColumn *col, gpointer data) void __view_column_clicked(GtkTreeViewColumn *col, gpointer data)
{ {
struct queue *queue = gui_model_get_queue(); struct playlist *playlist = gui_model_get_playlist();
struct queue *queue = playlist ? &playlist->pl_queue : NULL;
unsigned int index = __view_get_column_index(col); unsigned int index = __view_get_column_index(col);
bool reset = view_sort_count == 0; bool reset = view_sort_count == 0;
gchar *text; gchar *text;
@ -190,7 +191,8 @@ static void __view_add_to_playlist(GtkTreeModel *model, GtkTreePath *path,
static void __view_delete_selection(GtkTreeSelection *selection) static void __view_delete_selection(GtkTreeSelection *selection)
{ {
struct queue *queue = gui_model_get_queue(); struct playlist *playlist = gui_model_get_playlist();
struct queue *queue = playlist ? &playlist->pl_queue : NULL;
GList *rows = gtk_tree_selection_get_selected_rows(selection, NULL); GList *rows = gtk_tree_selection_get_selected_rows(selection, NULL);
GList *cur = g_list_reverse(rows); GList *cur = g_list_reverse(rows);
@ -422,9 +424,9 @@ GtkTreeModelFilter *gui_view_get_filter(void)
return view_filter; return view_filter;
} }
void gui_view_set_queue(struct queue *queue) void gui_view_set_playlist(struct playlist *playlist)
{ {
gui_model_set_queue(queue); gui_model_set_playlist(playlist);
view_sort_count = 0; view_sort_count = 0;
__view_display_sorting(""); __view_display_sorting("");
@ -435,7 +437,8 @@ void gui_view_set_queue(struct queue *queue)
void gui_view_scroll() void gui_view_scroll()
{ {
struct queue *queue = gui_model_get_queue(); struct playlist *playlist = gui_model_get_playlist();
struct queue *queue = playlist ? &playlist->pl_queue : NULL;
GtkTreePath *real, *path; GtkTreePath *real, *path;
if (!queue || (int)queue->q_cur.it_pos < 0 || view_no_scroll) if (!queue || (int)queue->q_cur.it_pos < 0 || view_no_scroll)

View File

@ -3,7 +3,7 @@
*/ */
#ifndef OCARINA_GUI_MODEL_H #ifndef OCARINA_GUI_MODEL_H
#define OCARINA_GUI_MODEL_H #define OCARINA_GUI_MODEL_H
#include <core/queue.h> #include <core/playlist.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#define GUI_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \ #define GUI_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
@ -29,7 +29,6 @@ struct gui_model {
GObject gm_parent; /* This MUST be the first member. */ GObject gm_parent; /* This MUST be the first member. */
gint gm_stamp; /* This is used to check iter validity. */ gint gm_stamp; /* This is used to check iter validity. */
struct queue *gm_queue; /* The model's associated queue. */
struct queue_iter gm_iter; /* The current _q_iter. */ struct queue_iter gm_iter; /* The current _q_iter. */
}; };
typedef struct gui_model GuiModel; typedef struct gui_model GuiModel;
@ -54,22 +53,22 @@ GuiModel *gui_model_get(void);
GType gui_model_get_type(); GType gui_model_get_type();
/* Called to add a row to the model */ /* Called to add a row to the model */
void gui_model_add(struct queue *, unsigned int); void gui_model_add(struct playlist *, unsigned int);
/* Called to remove a row from the model */ /* Called to remove a row from the model */
void gui_model_remove(struct queue *, unsigned int); void gui_model_remove(struct playlist *, unsigned int);
/* Called to remove all rows from the model */ /* Called to remove all rows from the model */
void gui_model_clear(struct queue *, unsigned int); void gui_model_clear(struct playlist *, unsigned int);
/* Called to update a row in the model */ /* Called to update a row in the model */
void gui_model_update(struct queue *, unsigned int); void gui_model_update(struct playlist *, unsigned int);
/* Called to change the queue represented by the model. */ /* Called to change the queue represented by the model. */
void gui_model_set_queue(struct queue *); void gui_model_set_playlist(struct playlist *);
/* Called to get the queue currently attached to the model. */ /* Called to get the queue currently attached to the model. */
struct queue *gui_model_get_queue(void); struct playlist *gui_model_get_playlist(void);
/* Called to convert a GtkTreeIter into a struct track */ /* Called to convert a GtkTreeIter into a struct track */

View File

@ -16,6 +16,6 @@ void gui_view_scroll();
GtkTreeModelFilter *gui_view_get_filter(void); GtkTreeModelFilter *gui_view_get_filter(void);
/* Called to set the currently displayed model. */ /* Called to set the currently displayed model. */
void gui_view_set_queue(struct queue *); void gui_view_set_playlist(struct playlist *);
#endif /* OCARINA_GUI_VIEW_H */ #endif /* OCARINA_GUI_VIEW_H */

View File

@ -27,7 +27,15 @@ void *test_queue_init(struct queue *queue, void *data)
{ return NULL; } { return NULL; }
void test_queue_deinit(struct queue *queue) void test_queue_deinit(struct queue *queue)
{ } { }
void test_queue_add(struct queue *queue, unsigned int n)
{ gui_model_add(queue->q_private, n); }
void test_queue_remove(struct queue *queue, unsigned int n)
{ gui_model_remove(queue->q_private, n); }
void test_queue_clear(struct queue *queue, unsigned int n)
{ gui_model_clear(queue->q_private, n); }
void test_queue_save(struct queue *queue, enum queue_flags flag) {} void test_queue_save(struct queue *queue, enum queue_flags flag) {}
void test_queue_update(struct queue *queue, unsigned int n)
{ gui_model_update(queue->q_private, n); }
void test_on_load(struct track *track) {} void test_on_load(struct track *track) {}
void test_on_state_change(GstState state) {} void test_on_state_change(GstState state) {}
void test_on_config_pause(int count) {} void test_on_config_pause(int count) {}
@ -35,11 +43,11 @@ void test_on_config_pause(int count) {}
struct queue_ops test_ops = { struct queue_ops test_ops = {
.qop_init = test_queue_init, .qop_init = test_queue_init,
.qop_deinit = test_queue_deinit, .qop_deinit = test_queue_deinit,
.qop_added = gui_model_add, .qop_added = test_queue_add,
.qop_removed = gui_model_remove, .qop_removed = test_queue_remove,
.qop_cleared = gui_model_clear, .qop_cleared = test_queue_clear,
.qop_save = test_queue_save, .qop_save = test_queue_save,
.qop_updated = gui_model_update, .qop_updated = test_queue_update,
}; };
struct audio_ops test_audio_ops = { struct audio_ops test_audio_ops = {
@ -59,11 +67,11 @@ static void test_init()
GtkTreeModel *treemodel = GTK_TREE_MODEL(model); GtkTreeModel *treemodel = GTK_TREE_MODEL(model);
GType type; GType type;
g_assert_null(gui_model_get_queue()); g_assert_null(gui_model_get_playlist());
gui_model_set_queue(playlist_get_queue(PL_SYSTEM, "Collection")); gui_model_set_playlist(playlist_get(PL_SYSTEM, "Collection"));
g_assert_nonnull(model); g_assert_nonnull(model);
g_assert_true(GTK_IS_TREE_MODEL(model)); g_assert_true(GTK_IS_TREE_MODEL(model));
g_assert(gui_model_get_queue() == playlist_get_queue(PL_SYSTEM, "Collection")); g_assert(gui_model_get_playlist() == playlist_get(PL_SYSTEM, "Collection"));
g_assert_cmpuint(gtk_tree_model_get_flags(treemodel), ==, g_assert_cmpuint(gtk_tree_model_get_flags(treemodel), ==,
GTK_TREE_MODEL_LIST_ONLY); GTK_TREE_MODEL_LIST_ONLY);
@ -100,7 +108,7 @@ static void __test_empty_subprocess()
GValue value; GValue value;
GType type; GType type;
gui_model_set_queue(playlist_get_queue(PL_SYSTEM, "Collection")); gui_model_set_playlist(playlist_get(PL_SYSTEM, "Collection"));
memset(&value, 0, sizeof(GValue)); memset(&value, 0, sizeof(GValue));
g_assert_false(gtk_tree_model_get_iter_first(model, &iter)); g_assert_false(gtk_tree_model_get_iter_first(model, &iter));
@ -164,7 +172,7 @@ static void test_model()
GtkTreeIter iter; GtkTreeIter iter;
GValue value; GValue value;
gui_model_set_queue(playlist_get_queue(PL_SYSTEM, "Collection")); gui_model_set_playlist(playlist_get(PL_SYSTEM, "Collection"));
g_assert_cmpstr(gtk_label_get_text(label), ==, ""); g_assert_cmpstr(gtk_label_get_text(label), ==, "");
memset(&value, 0, sizeof(GValue)); memset(&value, 0, sizeof(GValue));
@ -173,7 +181,8 @@ static void test_model()
g_signal_connect(model, "row-changed", (GCallback)on_row_changed, NULL); g_signal_connect(model, "row-changed", (GCallback)on_row_changed, NULL);
/* Okay, now scan a directory ... */ /* Okay, now scan a directory ... */
playlist_get_queue(PL_SYSTEM, "Collection")->q_private = model; playlist_get_queue(PL_SYSTEM, "Collection")->q_private =
playlist_get(PL_SYSTEM, "Collection");
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony"); playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
while (idle_run_task() == true) {} while (idle_run_task() == true) {}
g_assert_cmpuint(playlist_size(PL_SYSTEM, "Collection"), ==, 13); g_assert_cmpuint(playlist_size(PL_SYSTEM, "Collection"), ==, 13);
@ -248,19 +257,19 @@ static void test_model()
g_assert_cmpuint(gtk_tree_model_iter_n_children(model, &iter), ==, 0); g_assert_cmpuint(gtk_tree_model_iter_n_children(model, &iter), ==, 0);
g_assert_cmpuint(gtk_tree_model_iter_n_children(model, NULL), ==, 13); g_assert_cmpuint(gtk_tree_model_iter_n_children(model, NULL), ==, 13);
gui_model_set_queue(playlist_get_queue(PL_SYSTEM, "Favorites")); gui_model_set_playlist(playlist_get(PL_SYSTEM, "Favorites"));
g_assert_cmpuint(count_delete, ==, 13); g_assert_cmpuint(count_delete, ==, 13);
g_assert_cmpuint(count_insert, ==, 14); g_assert_cmpuint(count_insert, ==, 14);
g_assert_cmpuint(gtk_tree_model_iter_n_children(model, NULL), ==, 3); g_assert_cmpuint(gtk_tree_model_iter_n_children(model, NULL), ==, 3);
g_assert_cmpstr(gtk_label_get_text(label), ==, "10 minutes, 46 seconds"); g_assert_cmpstr(gtk_label_get_text(label), ==, "10 minutes, 46 seconds");
gui_model_set_queue(NULL); gui_model_set_playlist(NULL);
g_assert_cmpuint(count_delete, ==, 16); g_assert_cmpuint(count_delete, ==, 16);
g_assert_cmpuint(count_insert, ==, 14); g_assert_cmpuint(count_insert, ==, 14);
g_assert_cmpuint(gtk_tree_model_iter_n_children(model, NULL), ==, 0); g_assert_cmpuint(gtk_tree_model_iter_n_children(model, NULL), ==, 0);
g_assert_cmpstr(gtk_label_get_text(label), ==, ""); g_assert_cmpstr(gtk_label_get_text(label), ==, "");
gui_model_set_queue(playlist_get_queue(PL_SYSTEM, "Collection")); gui_model_set_playlist(playlist_get(PL_SYSTEM, "Collection"));
g_assert_cmpuint(count_delete, ==, 16); g_assert_cmpuint(count_delete, ==, 16);
g_assert_cmpuint(count_insert, ==, 15); g_assert_cmpuint(count_insert, ==, 15);
g_assert_cmpstr(gtk_label_get_text(label), ==, "42 minutes, 45 seconds"); g_assert_cmpstr(gtk_label_get_text(label), ==, "42 minutes, 45 seconds");
@ -297,7 +306,7 @@ int main(int argc, char **argv)
core_deinit(); core_deinit();
g_assert_false(G_IS_OBJECT(gui_model_get())); g_assert_false(G_IS_OBJECT(gui_model_get()));
g_assert_null(gui_model_get_queue()); g_assert_null(gui_model_get_playlist());
g_assert_cmpuint(gui_model_get_type(), ==, 0); g_assert_cmpuint(gui_model_get_type(), ==, 0);
return ret; return ret;
} }

View File

@ -11,19 +11,27 @@
static void *test_queue_init(struct queue *queue, void *data) static void *test_queue_init(struct queue *queue, void *data)
{ {
return gui_queue_alloc(NULL, queue, "Test Queue", GQ_CAN_RANDOM); return gui_queue_alloc(data, queue, "Test Queue", GQ_CAN_RANDOM);
} }
void test_queue_add(struct queue *queue, unsigned int n)
{ gui_model_add(gui_queue(queue)->gq_playlist, n); }
void test_queue_remove(struct queue *queue, unsigned int n)
{ gui_model_remove(gui_queue(queue)->gq_playlist, n); }
void test_queue_clear(struct queue *queue, unsigned int n)
{ gui_model_clear(gui_queue(queue)->gq_playlist, n); }
static void test_queue_save(struct queue *queue, unsigned int row) {} static void test_queue_save(struct queue *queue, unsigned int row) {}
void test_queue_update(struct queue *queue, unsigned int n)
{ gui_model_update(gui_queue(queue)->gq_playlist, n); }
static struct queue_ops test_ops = { static struct queue_ops test_ops = {
.qop_init = test_queue_init, .qop_init = test_queue_init,
.qop_deinit = gui_queue_free, .qop_deinit = gui_queue_free,
.qop_cleared = gui_model_clear, .qop_cleared = test_queue_clear,
.qop_added = gui_model_add, .qop_added = test_queue_add,
.qop_removed = gui_model_remove, .qop_removed = test_queue_remove,
.qop_save = test_queue_save, .qop_save = test_queue_save,
.qop_updated = gui_model_update, .qop_updated = test_queue_update,
}; };
struct core_init_data init_data = { struct core_init_data init_data = {

View File

@ -53,7 +53,7 @@ static void test_treeview()
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony"); playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
while (idle_run_task() == true) {} while (idle_run_task() == true) {}
gui_model_set_queue(playlist_get_queue(PL_SYSTEM, "Collection")); gui_model_set_playlist(playlist_get(PL_SYSTEM, "Collection"));
filter = GTK_TREE_MODEL(gui_view_get_filter()); filter = GTK_TREE_MODEL(gui_view_get_filter());
treeview = GTK_TREE_VIEW(gui_builder_widget("o_treeview")); treeview = GTK_TREE_VIEW(gui_builder_widget("o_treeview"));
@ -98,7 +98,7 @@ static void test_treeview()
g_assert_cmpuint(load_count, ==, 1); g_assert_cmpuint(load_count, ==, 1);
gtk_tree_path_free(path); gtk_tree_path_free(path);
gui_view_set_queue(NULL); gui_view_set_playlist(NULL);
gui_test_deinit(); gui_test_deinit();
} }