2016-01-12 08:19:05 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2016 (c) Anna Schumaker.
|
|
|
|
*/
|
2016-08-28 09:06:33 -04:00
|
|
|
#include <core/playlist.h>
|
2016-01-20 08:33:24 -05:00
|
|
|
#include <core/string.h>
|
2016-01-14 08:59:26 -05:00
|
|
|
#include <gui/builder.h>
|
2016-01-18 09:07:00 -05:00
|
|
|
#include <gui/model.h>
|
2016-01-12 08:19:05 -05:00
|
|
|
#include <gui/queue.h>
|
2016-01-21 15:18:37 -05:00
|
|
|
#include <gui/view.h>
|
2016-01-12 08:19:05 -05:00
|
|
|
|
2016-01-14 10:24:10 -05:00
|
|
|
static struct gui_queue *gq_queue = NULL;
|
|
|
|
|
2016-05-19 15:31:17 -04:00
|
|
|
enum gq_filter_how {
|
|
|
|
GQ_FILTER_DEFAULT,
|
|
|
|
GQ_FILTER_ALBUM,
|
|
|
|
GQ_FILTER_ARTIST,
|
|
|
|
GQ_FILTER_GENRE,
|
|
|
|
GQ_FILTER_TITLE,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-01-19 08:39:44 -05:00
|
|
|
static void __queue_toggle_flag(bool active, GtkWidget *widget,
|
|
|
|
enum queue_flags flag)
|
2016-01-14 10:24:10 -05:00
|
|
|
{
|
|
|
|
if (gq_queue == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some GTK themes have trouble with toggle buttons,
|
|
|
|
* so let's help users by changing image sensitivity.
|
|
|
|
*/
|
2016-01-19 08:39:44 -05:00
|
|
|
if (active)
|
2016-01-14 10:24:10 -05:00
|
|
|
queue_set_flag(gq_queue->gq_queue, flag);
|
2016-01-19 08:39:44 -05:00
|
|
|
else
|
2016-01-14 10:24:10 -05:00
|
|
|
queue_unset_flag(gq_queue->gq_queue, flag);
|
2016-01-19 08:39:44 -05:00
|
|
|
|
|
|
|
gtk_widget_set_sensitive(widget, active);
|
2016-01-14 10:24:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void __queue_random(GtkToggleButton *button, gpointer data)
|
|
|
|
{
|
2016-01-19 08:39:44 -05:00
|
|
|
__queue_toggle_flag(gtk_toggle_button_get_active(button),
|
|
|
|
gtk_button_get_image(GTK_BUTTON(button)),
|
|
|
|
Q_RANDOM);
|
2016-08-29 07:55:15 -04:00
|
|
|
if (gq_queue && gq_queue->gq_playlist) {
|
2016-08-28 09:06:33 -04:00
|
|
|
playlist_set_random(gq_queue->gq_playlist->pl_type,
|
|
|
|
gq_queue->gq_playlist->pl_name,
|
|
|
|
gtk_toggle_button_get_active(button));
|
|
|
|
}
|
2016-01-14 10:24:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void __queue_repeat(GtkToggleButton *button, gpointer data)
|
|
|
|
{
|
2016-01-19 08:39:44 -05:00
|
|
|
__queue_toggle_flag(gtk_toggle_button_get_active(button),
|
|
|
|
gtk_button_get_image(GTK_BUTTON(button)),
|
|
|
|
Q_REPEAT);
|
2016-01-14 10:24:10 -05:00
|
|
|
}
|
|
|
|
|
2016-01-15 12:12:12 -05:00
|
|
|
void __queue_disabled(GtkSwitch *enabled, GParamSpec *pspec, gpointer data)
|
|
|
|
{
|
2016-01-19 08:39:44 -05:00
|
|
|
__queue_toggle_flag(gtk_switch_get_active(enabled),
|
|
|
|
gui_builder_widget("o_treeview"),
|
|
|
|
Q_ENABLED);
|
2016-01-15 12:12:12 -05:00
|
|
|
}
|
|
|
|
|
2016-01-20 08:33:24 -05:00
|
|
|
static gboolean __queue_visible_func(GtkTreeModel *model, GtkTreeIter *iter,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
struct track *track;
|
2016-05-19 12:29:04 -04:00
|
|
|
unsigned int i;
|
|
|
|
gchar *token;
|
2016-05-19 15:31:17 -04:00
|
|
|
bool match;
|
2016-01-20 08:33:24 -05:00
|
|
|
|
2016-05-19 12:29:04 -04:00
|
|
|
if (!gq_queue || !gq_queue->gq_search)
|
2016-01-20 08:33:24 -05:00
|
|
|
return TRUE;
|
|
|
|
|
2016-08-02 11:39:09 -04:00
|
|
|
track = gui_queue_model_iter_get_track(iter);
|
2016-05-19 12:29:04 -04:00
|
|
|
|
|
|
|
for (i = 0; gq_queue->gq_search[i]; i++) {
|
|
|
|
token = gq_queue->gq_search[i];
|
|
|
|
|
2016-05-19 15:31:17 -04:00
|
|
|
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_artist, token);
|
|
|
|
break;
|
|
|
|
case GQ_FILTER_GENRE:
|
|
|
|
match = genre_match_token(track->tr_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_artist, token) ||
|
|
|
|
genre_match_token(track->tr_genre, token);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!match)
|
|
|
|
return false;
|
2016-05-19 12:29:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2016-01-20 08:33:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void __queue_filter(GtkSearchEntry *entry, gpointer data)
|
|
|
|
{
|
2016-05-19 15:31:17 -04:00
|
|
|
const gchar *text = gtk_entry_get_text(GTK_ENTRY(entry));
|
|
|
|
GtkComboBox *combo = GTK_COMBO_BOX(gui_builder_widget("filter_how"));
|
2016-01-20 08:33:24 -05:00
|
|
|
|
|
|
|
if (!gq_queue)
|
|
|
|
return;
|
2016-08-13 08:26:00 -04:00
|
|
|
if (gq_queue->gq_search) {
|
2016-05-19 12:29:04 -04:00
|
|
|
g_strfreev(gq_queue->gq_search);
|
2016-08-13 08:26:00 -04:00
|
|
|
gq_queue->gq_search = NULL;
|
|
|
|
}
|
2016-05-19 15:31:17 -04:00
|
|
|
if (strlen(text) > 0) {
|
2016-05-19 12:29:04 -04:00
|
|
|
gq_queue->gq_search = g_str_tokenize_and_fold(text, NULL, NULL);
|
2016-05-19 15:31:17 -04:00
|
|
|
gq_queue->gq_active = gtk_combo_box_get_active(combo);
|
|
|
|
}
|
2016-04-29 11:10:48 -04:00
|
|
|
|
2016-08-03 07:48:17 -04:00
|
|
|
gtk_tree_model_filter_refilter(gui_view_get_filter());
|
2016-01-22 14:16:51 -05:00
|
|
|
gui_view_scroll();
|
2016-01-20 08:33:24 -05:00
|
|
|
}
|
|
|
|
|
2016-05-19 15:31:17 -04:00
|
|
|
void __queue_filter_how_changed(int n)
|
|
|
|
{
|
|
|
|
__queue_filter(GTK_SEARCH_ENTRY(gui_builder_widget("o_search")), NULL);
|
|
|
|
}
|
|
|
|
|
2016-08-02 11:46:42 -04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-05-15 11:04:13 -04:00
|
|
|
struct gui_queue *gui_queue_alloc(struct playlist *playlist, struct queue *queue,
|
|
|
|
const gchar *text, unsigned int flags)
|
2016-01-12 08:19:05 -05:00
|
|
|
{
|
|
|
|
struct gui_queue *gq = g_malloc(sizeof(struct gui_queue));
|
|
|
|
|
2016-01-20 08:33:24 -05:00
|
|
|
gq->gq_flags = flags;
|
|
|
|
gq->gq_text = g_strdup(text);
|
2016-08-10 07:31:03 -04:00
|
|
|
gq->gq_search = NULL;
|
2016-05-15 11:04:13 -04:00
|
|
|
gq->gq_playlist = playlist;
|
|
|
|
gq->gq_queue = queue;
|
2016-01-20 08:33:24 -05:00
|
|
|
|
2016-01-12 08:19:05 -05:00
|
|
|
return gq;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gui_queue_free(struct queue *queue)
|
|
|
|
{
|
2016-01-19 08:39:44 -05:00
|
|
|
struct gui_queue *gq = gui_queue(queue);
|
2016-01-12 08:19:05 -05:00
|
|
|
|
|
|
|
queue->q_private = NULL;
|
2016-01-13 16:48:43 -05:00
|
|
|
|
2016-01-21 15:18:37 -05:00
|
|
|
if (gq_queue == gq)
|
2016-08-02 11:46:42 -04:00
|
|
|
gui_view_set_queue(NULL);
|
2016-08-10 07:31:03 -04:00
|
|
|
if (gq->gq_search)
|
2016-05-19 12:29:04 -04:00
|
|
|
g_strfreev(gq->gq_search);
|
2016-01-13 16:48:43 -05:00
|
|
|
g_free(gq->gq_text);
|
2016-01-12 08:19:05 -05:00
|
|
|
g_free(gq);
|
|
|
|
}
|
2016-01-14 08:59:26 -05:00
|
|
|
|
|
|
|
void gui_queue_show(struct gui_queue *queue)
|
|
|
|
{
|
2016-01-19 08:39:44 -05:00
|
|
|
GtkTreeView *view = GTK_TREE_VIEW(gui_builder_widget("o_treeview"));
|
2016-01-15 12:12:12 -05:00
|
|
|
GtkButton *random = GTK_BUTTON(gui_builder_widget("o_random"));
|
|
|
|
GtkButton *repeat = GTK_BUTTON(gui_builder_widget("o_repeat"));
|
|
|
|
GtkSwitch *enabled = GTK_SWITCH(gui_builder_widget("o_enable"));
|
|
|
|
GtkEntry *search = GTK_ENTRY(gui_builder_widget("o_search"));
|
|
|
|
bool has_random = false, has_repeat = false, is_enabled = false;;
|
2016-05-19 12:29:04 -04:00
|
|
|
gchar *text;
|
2016-01-14 08:59:26 -05:00
|
|
|
|
2016-01-14 10:24:10 -05:00
|
|
|
gq_queue = queue;
|
|
|
|
|
2016-01-15 12:12:12 -05:00
|
|
|
gtk_widget_set_sensitive(GTK_WIDGET(random), gui_queue_can_random(queue));
|
|
|
|
gtk_widget_set_sensitive(GTK_WIDGET(repeat), gui_queue_can_repeat(queue));
|
|
|
|
gtk_widget_set_sensitive(GTK_WIDGET(enabled), gui_queue_can_disable(queue));
|
2016-01-14 08:59:26 -05:00
|
|
|
|
|
|
|
if (queue) {
|
|
|
|
has_random = queue_has_flag(queue->gq_queue, Q_RANDOM);
|
|
|
|
has_repeat = queue_has_flag(queue->gq_queue, Q_REPEAT);
|
2016-01-15 12:12:12 -05:00
|
|
|
is_enabled = queue_has_flag(queue->gq_queue, Q_ENABLED);
|
2016-08-02 11:46:42 -04:00
|
|
|
gui_view_set_queue(queue->gq_queue);
|
2016-01-20 16:49:37 -05:00
|
|
|
} else
|
2016-08-02 11:46:42 -04:00
|
|
|
gui_view_set_queue(NULL);
|
2016-01-14 08:59:26 -05:00
|
|
|
|
2016-01-15 12:12:12 -05:00
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(random), has_random);
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(repeat), has_repeat);
|
|
|
|
gtk_switch_set_active(GTK_SWITCH(enabled), is_enabled);
|
2016-01-14 08:59:26 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Some GTK themes have trouble with toggle buttons,
|
|
|
|
* so let's help users know what the current state is.
|
|
|
|
*/
|
|
|
|
gtk_widget_set_sensitive(gtk_button_get_image(random), has_random);
|
|
|
|
gtk_widget_set_sensitive(gtk_button_get_image(repeat), has_repeat);
|
2016-01-19 08:39:44 -05:00
|
|
|
gtk_widget_set_sensitive(GTK_WIDGET(view), is_enabled);
|
2016-01-15 09:35:25 -05:00
|
|
|
|
|
|
|
gtk_widget_set_sensitive(GTK_WIDGET(search), queue != NULL);
|
2016-05-19 12:29:04 -04:00
|
|
|
|
|
|
|
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, "");
|
2016-01-14 08:59:26 -05:00
|
|
|
}
|