Anna Schumaker
010969c7b3
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>
177 lines
4.1 KiB
C
177 lines
4.1 KiB
C
/*
|
|
* Copyright 2016 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/playlist.h>
|
|
#include <core/string.h>
|
|
#include <gui/builder.h>
|
|
#include <gui/model.h>
|
|
#include <gui/queue.h>
|
|
#include <gui/view.h>
|
|
|
|
static struct gui_queue *gq_queue = NULL;
|
|
|
|
enum gq_filter_how {
|
|
GQ_FILTER_DEFAULT,
|
|
GQ_FILTER_ALBUM,
|
|
GQ_FILTER_ARTIST,
|
|
GQ_FILTER_GENRE,
|
|
GQ_FILTER_TITLE,
|
|
};
|
|
|
|
|
|
static void __queue_toggle_flag(bool active, GtkWidget *widget,
|
|
enum queue_flags flag)
|
|
{
|
|
if (gq_queue == NULL)
|
|
return;
|
|
|
|
if (active)
|
|
queue_set_flag(gq_queue->gq_queue, flag);
|
|
else
|
|
queue_unset_flag(gq_queue->gq_queue, flag);
|
|
}
|
|
|
|
void __queue_random(GtkToggleButton *button, gpointer data)
|
|
{
|
|
__queue_toggle_flag(gtk_toggle_button_get_active(button),
|
|
gtk_button_get_image(GTK_BUTTON(button)),
|
|
Q_RANDOM);
|
|
if (gq_queue && gq_queue->gq_playlist) {
|
|
playlist_set_random(gq_queue->gq_playlist->pl_type,
|
|
gq_queue->gq_playlist->pl_name,
|
|
gtk_toggle_button_get_active(button));
|
|
}
|
|
}
|
|
|
|
static gboolean __queue_visible_func(GtkTreeModel *model, GtkTreeIter *iter,
|
|
gpointer data)
|
|
{
|
|
struct track *track;
|
|
unsigned int i;
|
|
gchar *token;
|
|
bool match;
|
|
|
|
if (!gq_queue || !gq_queue->gq_search)
|
|
return TRUE;
|
|
|
|
track = gui_model_iter_get_track(iter);
|
|
|
|
for (i = 0; gq_queue->gq_search[i]; i++) {
|
|
token = gq_queue->gq_search[i];
|
|
|
|
switch (gq_queue->gq_active) {
|
|
case GQ_FILTER_ALBUM:
|
|
match = album_match_token(track->tr_album, token);
|
|
break;
|
|
case GQ_FILTER_ARTIST:
|
|
match = artist_match_token(track->tr_album->al_artist, token);
|
|
break;
|
|
case GQ_FILTER_GENRE:
|
|
match = genre_match_token(track->tr_album->al_genre, token);
|
|
break;
|
|
case GQ_FILTER_TITLE:
|
|
match = track_match_token(track, token);
|
|
break;
|
|
default: /* GQ_FILTER_DEFAULT */
|
|
match = track_match_token(track, token) ||
|
|
album_match_token(track->tr_album, token) ||
|
|
artist_match_token(track->tr_album->al_artist, token) ||
|
|
genre_match_token(track->tr_album->al_genre, token);
|
|
}
|
|
|
|
if (!match)
|
|
return false;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void __queue_filter(GtkSearchEntry *entry, gpointer data)
|
|
{
|
|
const gchar *text = gtk_entry_get_text(GTK_ENTRY(entry));
|
|
GtkComboBox *combo = GTK_COMBO_BOX(gui_builder_widget("filter_how"));
|
|
|
|
if (!gq_queue)
|
|
return;
|
|
if (gq_queue->gq_search) {
|
|
g_strfreev(gq_queue->gq_search);
|
|
gq_queue->gq_search = NULL;
|
|
}
|
|
if (strlen(text) > 0) {
|
|
gq_queue->gq_search = g_str_tokenize_and_fold(text, NULL, NULL);
|
|
gq_queue->gq_active = gtk_combo_box_get_active(combo);
|
|
}
|
|
|
|
gtk_tree_model_filter_refilter(gui_view_get_filter());
|
|
gui_view_scroll();
|
|
}
|
|
|
|
void __queue_filter_how_changed(int n)
|
|
{
|
|
__queue_filter(GTK_SEARCH_ENTRY(gui_builder_widget("o_search")), NULL);
|
|
}
|
|
|
|
void gui_queue_init(void)
|
|
{
|
|
gtk_tree_model_filter_set_visible_func(gui_view_get_filter(),
|
|
__queue_visible_func,
|
|
gui_builder_object("o_search"),
|
|
NULL);
|
|
}
|
|
|
|
struct gui_queue *gui_queue_alloc(struct playlist *playlist, struct queue *queue,
|
|
const gchar *text, unsigned int flags)
|
|
{
|
|
struct gui_queue *gq = g_malloc(sizeof(struct gui_queue));
|
|
|
|
gq->gq_flags = flags;
|
|
gq->gq_text = g_strdup(text);
|
|
gq->gq_search = NULL;
|
|
gq->gq_playlist = playlist;
|
|
gq->gq_queue = queue;
|
|
|
|
return gq;
|
|
}
|
|
|
|
void gui_queue_free(struct queue *queue)
|
|
{
|
|
struct gui_queue *gq = gui_queue(queue);
|
|
|
|
queue->q_private = NULL;
|
|
|
|
if (gq_queue == gq)
|
|
gui_view_set_playlist(NULL);
|
|
if (gq->gq_search)
|
|
g_strfreev(gq->gq_search);
|
|
g_free(gq->gq_text);
|
|
g_free(gq);
|
|
}
|
|
|
|
void gui_queue_show(struct gui_queue *queue)
|
|
{
|
|
GtkButton *random = GTK_BUTTON(gui_builder_widget("o_random"));
|
|
GtkEntry *search = GTK_ENTRY(gui_builder_widget("o_search"));
|
|
bool has_random = false;
|
|
gchar *text;
|
|
|
|
gq_queue = queue;
|
|
|
|
gtk_widget_set_sensitive(GTK_WIDGET(random), gui_queue_can_random(queue));
|
|
|
|
if (queue) {
|
|
has_random = queue_has_flag(queue->gq_queue, Q_RANDOM);
|
|
gui_view_set_playlist(queue->gq_playlist);
|
|
} else
|
|
gui_view_set_playlist(NULL);
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(random), has_random);
|
|
gtk_widget_set_sensitive(GTK_WIDGET(search), queue != NULL);
|
|
|
|
if (queue && queue->gq_search) {
|
|
text = g_strjoinv(" ", queue->gq_search);
|
|
gtk_entry_set_text(search, text);
|
|
g_free(text);
|
|
} else
|
|
gtk_entry_set_text(search, "");
|
|
}
|