core/playlist: Rename pl_private -> pl_search
And change its type to gchar **. This lets the playlist code manage setting and freeing search strings. The UI is still responsible for how this string is used. This patch also lets me remove the now-unused queue_deinit() function and associated callback. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
1dd0b7c2aa
commit
cdbf8b1736
|
@ -207,3 +207,16 @@ bool playlist_sort(struct playlist *playlist, enum compare_t sort)
|
||||||
playlist_types[playlist->pl_type]->pl_save();
|
playlist_types[playlist->pl_type]->pl_save();
|
||||||
return g_slist_length(playlist->pl_sort) > 0;
|
return g_slist_length(playlist->pl_sort) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void playlist_set_search(struct playlist *playlist, const gchar *text)
|
||||||
|
{
|
||||||
|
gchar **tokens = NULL;
|
||||||
|
|
||||||
|
if (!playlist)
|
||||||
|
return;
|
||||||
|
if (playlist->pl_search)
|
||||||
|
g_strfreev(playlist->pl_search);
|
||||||
|
if (strlen(text) > 0)
|
||||||
|
tokens = g_str_tokenize_and_fold(text, NULL, NULL);
|
||||||
|
playlist->pl_search = tokens;
|
||||||
|
}
|
||||||
|
|
|
@ -44,18 +44,19 @@ void playlist_generic_init(struct playlist *playlist, struct queue_ops *ops)
|
||||||
queue_init(&playlist->pl_queue, ops, playlist);
|
queue_init(&playlist->pl_queue, ops, playlist);
|
||||||
playlist->pl_sort = NULL;
|
playlist->pl_sort = NULL;
|
||||||
playlist->pl_current = NULL;
|
playlist->pl_current = NULL;
|
||||||
|
playlist->pl_search = NULL;
|
||||||
playlist_generic_sort(playlist, COMPARE_ARTIST);
|
playlist_generic_sort(playlist, COMPARE_ARTIST);
|
||||||
playlist_generic_sort(playlist, COMPARE_YEAR);
|
playlist_generic_sort(playlist, COMPARE_YEAR);
|
||||||
playlist_generic_sort(playlist, COMPARE_TRACK);
|
playlist_generic_sort(playlist, COMPARE_TRACK);
|
||||||
playlist->pl_private = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void playlist_generic_deinit(struct playlist *playlist)
|
void playlist_generic_deinit(struct playlist *playlist)
|
||||||
{
|
{
|
||||||
if (playlist) {
|
if (playlist) {
|
||||||
queue_deinit(&playlist->pl_queue);
|
|
||||||
playlist_generic_clear(playlist);
|
playlist_generic_clear(playlist);
|
||||||
playlist_clear_sort(playlist);
|
playlist_clear_sort(playlist);
|
||||||
|
g_strfreev(playlist->pl_search);
|
||||||
|
playlist->pl_search = NULL;
|
||||||
playlist->pl_length = 0;
|
playlist->pl_length = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
11
core/queue.c
11
core/queue.c
|
@ -13,19 +13,8 @@ static inline void *__queue_init(struct queue *queue, void *data)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void __queue_deinit(struct queue *queue)
|
|
||||||
{
|
|
||||||
if (queue->q_ops)
|
|
||||||
queue->q_ops->qop_deinit(queue);
|
|
||||||
}
|
|
||||||
|
|
||||||
void queue_init(struct queue *queue, const struct queue_ops *ops, void *data)
|
void queue_init(struct queue *queue, const struct queue_ops *ops, void *data)
|
||||||
{
|
{
|
||||||
queue->q_ops = ops;
|
queue->q_ops = ops;
|
||||||
queue->q_private = __queue_init(queue, data);
|
queue->q_private = __queue_init(queue, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void queue_deinit(struct queue *queue)
|
|
||||||
{
|
|
||||||
__queue_deinit(queue);
|
|
||||||
}
|
|
||||||
|
|
26
gui/filter.c
26
gui/filter.c
|
@ -42,7 +42,7 @@ static gboolean __gui_filter_visible_func(GtkTreeModel *model,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
{
|
{
|
||||||
unsigned int i, how = gtk_combo_box_get_active(gui_filter_how());
|
unsigned int i, how = gtk_combo_box_get_active(gui_filter_how());
|
||||||
gchar **search = gui_model_get_playlist()->pl_private;
|
gchar **search = gui_model_get_playlist()->pl_search;
|
||||||
struct track *track;
|
struct track *track;
|
||||||
|
|
||||||
if (!search)
|
if (!search)
|
||||||
|
@ -58,15 +58,8 @@ static gboolean __gui_filter_visible_func(GtkTreeModel *model,
|
||||||
|
|
||||||
void __gui_filter_search_changed(GtkSearchEntry *search, gpointer data)
|
void __gui_filter_search_changed(GtkSearchEntry *search, gpointer data)
|
||||||
{
|
{
|
||||||
const gchar *text = gtk_entry_get_text(GTK_ENTRY(search));
|
playlist_set_search(gui_model_get_playlist(),
|
||||||
struct playlist *playlist = gui_model_get_playlist();
|
gtk_entry_get_text(GTK_ENTRY(search)));
|
||||||
|
|
||||||
if (!playlist)
|
|
||||||
return;
|
|
||||||
|
|
||||||
gui_filter_clear_search(playlist);
|
|
||||||
if (strlen(text) > 0)
|
|
||||||
playlist->pl_private = g_str_tokenize_and_fold(text, NULL, NULL);
|
|
||||||
gtk_tree_model_filter_refilter(gui_filter_get());
|
gtk_tree_model_filter_refilter(gui_filter_get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,20 +84,9 @@ void gui_filter_deinit()
|
||||||
g_object_unref(G_OBJECT(filter_model));
|
g_object_unref(G_OBJECT(filter_model));
|
||||||
}
|
}
|
||||||
|
|
||||||
void gui_filter_clear_search(struct playlist *playlist)
|
|
||||||
{
|
|
||||||
gchar **text;
|
|
||||||
|
|
||||||
if (playlist && playlist->pl_private) {
|
|
||||||
text = playlist->pl_private;
|
|
||||||
g_strfreev(text);
|
|
||||||
playlist->pl_private = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void gui_filter_set_playlist(struct playlist *playlist)
|
void gui_filter_set_playlist(struct playlist *playlist)
|
||||||
{
|
{
|
||||||
gchar **search = playlist ? (gchar **)playlist->pl_private : NULL;
|
gchar **search = playlist ? (gchar **)playlist->pl_search : NULL;
|
||||||
gchar *text = search ? g_strjoinv(" ", search) : g_strdup("");
|
gchar *text = search ? g_strjoinv(" ", search) : g_strdup("");
|
||||||
|
|
||||||
gui_model_set_playlist(playlist);
|
gui_model_set_playlist(playlist);
|
||||||
|
|
|
@ -37,11 +37,6 @@ static void *__gui_playlist_init(struct queue *queue, void *data)
|
||||||
return playlist;
|
return playlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __gui_playlist_deinit(struct queue *queue)
|
|
||||||
{
|
|
||||||
gui_filter_clear_search(queue->q_private);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void __gui_playlist_added(struct playlist *playlist, struct track *track)
|
static void __gui_playlist_added(struct playlist *playlist, struct track *track)
|
||||||
{
|
{
|
||||||
gui_model_add(playlist, track);
|
gui_model_add(playlist, track);
|
||||||
|
@ -58,7 +53,6 @@ static void __gui_playlist_removed(struct playlist *playlist, struct track *trac
|
||||||
|
|
||||||
struct queue_ops playlist_ops = {
|
struct queue_ops playlist_ops = {
|
||||||
.qop_init = __gui_playlist_init,
|
.qop_init = __gui_playlist_init,
|
||||||
.qop_deinit = __gui_playlist_deinit,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct playlist_callbacks playlist_cb = {
|
struct playlist_callbacks playlist_cb = {
|
||||||
|
|
|
@ -70,4 +70,8 @@ void playlist_set_random(struct playlist *, bool);
|
||||||
/* Called to change the sort order of the playlist. */
|
/* Called to change the sort order of the playlist. */
|
||||||
bool playlist_sort(struct playlist *, enum compare_t);
|
bool playlist_sort(struct playlist *, enum compare_t);
|
||||||
|
|
||||||
|
|
||||||
|
/* Called to set the playlist's search text */
|
||||||
|
void playlist_set_search(struct playlist *, const gchar *);
|
||||||
|
|
||||||
#endif /* OCARINA_CORE_PLAYLIST_H */
|
#endif /* OCARINA_CORE_PLAYLIST_H */
|
||||||
|
|
|
@ -53,7 +53,7 @@ struct playlist {
|
||||||
bool pl_random; /* This playlist's random setting. */
|
bool pl_random; /* This playlist's random setting. */
|
||||||
playlist_iter pl_current; /* This playlist's current track. */
|
playlist_iter pl_current; /* This playlist's current track. */
|
||||||
GSList *pl_sort; /* This playlist's sort order. */
|
GSList *pl_sort; /* This playlist's sort order. */
|
||||||
void *pl_private; /* This playlist's private data. */
|
gchar **pl_search; /* This playlist's search text. */
|
||||||
struct queue pl_queue; /* This playlist's queue of tracks. */
|
struct queue pl_queue; /* This playlist's queue of tracks. */
|
||||||
|
|
||||||
const struct playlist_ops *pl_ops; /* This playlist's supported operations. */
|
const struct playlist_ops *pl_ops; /* This playlist's supported operations. */
|
||||||
|
|
|
@ -17,9 +17,6 @@ struct queue;
|
||||||
struct queue_ops {
|
struct queue_ops {
|
||||||
/* Called to tell a higher layer that a queue has been initialized. */
|
/* Called to tell a higher layer that a queue has been initialized. */
|
||||||
void *(*qop_init)(struct queue *, void *);
|
void *(*qop_init)(struct queue *, void *);
|
||||||
|
|
||||||
/* Called to tell a higher layer that a queue is deinitializing. */
|
|
||||||
void (*qop_deinit)(struct queue *);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,7 +30,4 @@ struct queue {
|
||||||
/* Called to initialize a queue. */
|
/* Called to initialize a queue. */
|
||||||
void queue_init(struct queue *, const struct queue_ops *, void *);
|
void queue_init(struct queue *, const struct queue_ops *, void *);
|
||||||
|
|
||||||
/* Called to deinitialize a queue. */
|
|
||||||
void queue_deinit(struct queue *);
|
|
||||||
|
|
||||||
#endif /* OCARINA_CORE_QUEUE_H */
|
#endif /* OCARINA_CORE_QUEUE_H */
|
||||||
|
|
|
@ -20,9 +20,6 @@ void gui_filter_init();
|
||||||
/* Called to deinitialize the filter model. */
|
/* Called to deinitialize the filter model. */
|
||||||
void gui_filter_deinit();
|
void gui_filter_deinit();
|
||||||
|
|
||||||
/* Called to clear any saved search text. */
|
|
||||||
void gui_filter_clear_search(struct playlist *);
|
|
||||||
|
|
||||||
/* Called to set the current playlist. */
|
/* Called to set the current playlist. */
|
||||||
void gui_filter_set_playlist(struct playlist *);
|
void gui_filter_set_playlist(struct playlist *);
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,8 @@ static void test_null()
|
||||||
playlist_generic_resort(NULL);
|
playlist_generic_resort(NULL);
|
||||||
playlist_clear_sort(NULL);
|
playlist_clear_sort(NULL);
|
||||||
|
|
||||||
|
playlist_set_search(NULL, NULL);
|
||||||
|
|
||||||
g_assert_false(playlist_generic_add(NULL, NULL));
|
g_assert_false(playlist_generic_add(NULL, NULL));
|
||||||
g_assert_false(playlist_generic_add_front(NULL, NULL));
|
g_assert_false(playlist_generic_add_front(NULL, NULL));
|
||||||
g_assert_false(playlist_generic_remove(NULL, NULL));
|
g_assert_false(playlist_generic_remove(NULL, NULL));
|
||||||
|
@ -169,11 +171,19 @@ static void test_playlist()
|
||||||
g_assert_cmpuint(p.pl_length, ==, 0);
|
g_assert_cmpuint(p.pl_length, ==, 0);
|
||||||
g_assert_null(p.pl_current);
|
g_assert_null(p.pl_current);
|
||||||
|
|
||||||
|
/* Set search text. */
|
||||||
|
playlist_set_search(&p, "test");
|
||||||
|
g_assert_cmpstr(p.pl_search[0], ==, "test");
|
||||||
|
playlist_set_search(&p, "Test Text");
|
||||||
|
g_assert_cmpstr(p.pl_search[0], ==, "test");
|
||||||
|
g_assert_cmpstr(p.pl_search[1], ==, "text");
|
||||||
|
|
||||||
/* Deinitialize the playlist. */
|
/* Deinitialize the playlist. */
|
||||||
playlist_generic_deinit(&p);
|
playlist_generic_deinit(&p);
|
||||||
g_assert_cmpuint(playlist_size(&p), ==, 0);
|
g_assert_cmpuint(playlist_size(&p), ==, 0);
|
||||||
g_assert_cmpuint(p.pl_length, ==, 0);
|
g_assert_cmpuint(p.pl_length, ==, 0);
|
||||||
g_assert_null(p.pl_current);
|
g_assert_null(p.pl_current);
|
||||||
|
g_assert_null(p.pl_search);
|
||||||
g_assert_null(p.pl_sort);
|
g_assert_null(p.pl_sort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
|
|
||||||
unsigned int count_init = 0;
|
unsigned int count_init = 0;
|
||||||
unsigned int count_deinit = 0;
|
|
||||||
|
|
||||||
|
|
||||||
static void *queue_op_init(struct queue *queue, void *data)
|
static void *queue_op_init(struct queue *queue, void *data)
|
||||||
|
@ -17,15 +16,9 @@ static void *queue_op_init(struct queue *queue, void *data)
|
||||||
return GUINT_TO_POINTER(count_init);
|
return GUINT_TO_POINTER(count_init);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void queue_op_deinit(struct queue *queue)
|
|
||||||
{
|
|
||||||
count_deinit++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static const struct queue_ops test_ops = {
|
static const struct queue_ops test_ops = {
|
||||||
.qop_init = queue_op_init,
|
.qop_init = queue_op_init,
|
||||||
.qop_deinit = queue_op_deinit,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,17 +32,11 @@ static void test_init()
|
||||||
|
|
||||||
g_assert_null(q.q_ops);
|
g_assert_null(q.q_ops);
|
||||||
|
|
||||||
queue_deinit(&q);
|
|
||||||
g_assert_cmpuint(count_deinit, ==, 0);
|
|
||||||
|
|
||||||
queue_init(&q, &test_ops, NULL);
|
queue_init(&q, &test_ops, NULL);
|
||||||
g_assert_cmpuint(count_init, ==, 1);
|
g_assert_cmpuint(count_init, ==, 1);
|
||||||
g_assert_cmpuint(GPOINTER_TO_UINT(q.q_private), ==, 1);
|
g_assert_cmpuint(GPOINTER_TO_UINT(q.q_private), ==, 1);
|
||||||
|
|
||||||
g_assert(q.q_ops == &test_ops);
|
g_assert(q.q_ops == &test_ops);
|
||||||
|
|
||||||
queue_deinit(&q);
|
|
||||||
g_assert_cmpuint(count_deinit, ==, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
|
|
|
@ -10,12 +10,9 @@
|
||||||
|
|
||||||
void *test_queue_init(struct queue *queue, void *data)
|
void *test_queue_init(struct queue *queue, void *data)
|
||||||
{ return NULL; }
|
{ return NULL; }
|
||||||
void test_queue_deinit(struct queue *queue)
|
|
||||||
{ gui_filter_clear_search(queue->q_private); }
|
|
||||||
|
|
||||||
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,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void test_on_load(struct track *track) {}
|
void test_on_load(struct track *track) {}
|
||||||
|
|
|
@ -25,15 +25,12 @@ void on_row_changed(GtkTreeModel *model, GtkTreePath *path,
|
||||||
|
|
||||||
void *test_queue_init(struct queue *queue, void *data)
|
void *test_queue_init(struct queue *queue, void *data)
|
||||||
{ return NULL; }
|
{ return NULL; }
|
||||||
void test_queue_deinit(struct queue *queue)
|
|
||||||
{ }
|
|
||||||
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) {}
|
||||||
|
|
||||||
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,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct playlist_callbacks test_cb = {
|
struct playlist_callbacks test_cb = {
|
||||||
|
|
Loading…
Reference in New Issue