gui/queue: Add a selector for filtering by different fields
Implements #63: Add field selector for filtering Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
11ef52b5de
commit
d7322c1f07
49
gui/queue.c
49
gui/queue.c
|
@ -10,6 +10,15 @@
|
||||||
|
|
||||||
static struct gui_queue *gq_queue = NULL;
|
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_set_runtime(struct gui_queue *queue)
|
static void __queue_set_runtime(struct gui_queue *queue)
|
||||||
{
|
{
|
||||||
gchar *len;
|
gchar *len;
|
||||||
|
@ -72,6 +81,7 @@ static gboolean __queue_visible_func(GtkTreeModel *model, GtkTreeIter *iter,
|
||||||
struct track *track;
|
struct track *track;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
gchar *token;
|
gchar *token;
|
||||||
|
bool match;
|
||||||
|
|
||||||
if (!gq_queue || !gq_queue->gq_search)
|
if (!gq_queue || !gq_queue->gq_search)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -81,11 +91,28 @@ static gboolean __queue_visible_func(GtkTreeModel *model, GtkTreeIter *iter,
|
||||||
for (i = 0; gq_queue->gq_search[i]; i++) {
|
for (i = 0; gq_queue->gq_search[i]; i++) {
|
||||||
token = gq_queue->gq_search[i];
|
token = gq_queue->gq_search[i];
|
||||||
|
|
||||||
if (!track_match_token(track, token) &&
|
switch (gq_queue->gq_active) {
|
||||||
!artist_match_token(track->tr_artist, token) &&
|
case GQ_FILTER_ALBUM:
|
||||||
!album_match_token(track->tr_album, token) &&
|
match = album_match_token(track->tr_album, token);
|
||||||
!genre_match_token(track->tr_genre, token))
|
break;
|
||||||
return FALSE;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -93,7 +120,8 @@ static gboolean __queue_visible_func(GtkTreeModel *model, GtkTreeIter *iter,
|
||||||
|
|
||||||
void __queue_filter(GtkSearchEntry *entry, gpointer data)
|
void __queue_filter(GtkSearchEntry *entry, gpointer data)
|
||||||
{
|
{
|
||||||
const gchar *text = gtk_entry_get_text(GTK_ENTRY(entry));
|
const gchar *text = gtk_entry_get_text(GTK_ENTRY(entry));
|
||||||
|
GtkComboBox *combo = GTK_COMBO_BOX(gui_builder_widget("filter_how"));
|
||||||
|
|
||||||
if (!gq_queue)
|
if (!gq_queue)
|
||||||
return;
|
return;
|
||||||
|
@ -101,13 +129,20 @@ void __queue_filter(GtkSearchEntry *entry, gpointer data)
|
||||||
g_strfreev(gq_queue->gq_search);
|
g_strfreev(gq_queue->gq_search);
|
||||||
gq_queue->gq_search = NULL;
|
gq_queue->gq_search = NULL;
|
||||||
}
|
}
|
||||||
if (strlen(text) > 0)
|
if (strlen(text) > 0) {
|
||||||
gq_queue->gq_search = g_str_tokenize_and_fold(text, NULL, NULL);
|
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(GTK_TREE_MODEL_FILTER(gq_queue->gq_filter));
|
gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(gq_queue->gq_filter));
|
||||||
gui_view_scroll();
|
gui_view_scroll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void __queue_filter_how_changed(int n)
|
||||||
|
{
|
||||||
|
__queue_filter(GTK_SEARCH_ENTRY(gui_builder_widget("o_search")), NULL);
|
||||||
|
}
|
||||||
|
|
||||||
struct gui_queue *gui_queue_alloc(struct playlist *playlist, struct queue *queue,
|
struct gui_queue *gui_queue_alloc(struct playlist *playlist, struct queue *queue,
|
||||||
const gchar *text, unsigned int flags)
|
const gchar *text, unsigned int flags)
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,6 +15,7 @@ enum gui_queue_flags {
|
||||||
|
|
||||||
struct gui_queue {
|
struct gui_queue {
|
||||||
unsigned int gq_flags;
|
unsigned int gq_flags;
|
||||||
|
unsigned int gq_active;
|
||||||
gchar *gq_text;
|
gchar *gq_text;
|
||||||
gchar **gq_search;
|
gchar **gq_search;
|
||||||
|
|
||||||
|
|
|
@ -996,6 +996,28 @@
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="spacing">5</property>
|
<property name="spacing">5</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkComboBoxText" id="filter_how">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="tooltip_text" translatable="yes">Controls what fields are checked during filtering. The default is to check album, artist, title, and genre fields.</property>
|
||||||
|
<property name="valign">center</property>
|
||||||
|
<property name="active">0</property>
|
||||||
|
<items>
|
||||||
|
<item translatable="yes">Default</item>
|
||||||
|
<item translatable="yes">Album</item>
|
||||||
|
<item translatable="yes">Artist</item>
|
||||||
|
<item translatable="yes">Genre</item>
|
||||||
|
<item translatable="yes">Title</item>
|
||||||
|
</items>
|
||||||
|
<signal name="changed" handler="__queue_filter_how_changed" swapped="no"/>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkSearchEntry" id="o_search">
|
<object class="GtkSearchEntry" id="o_search">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
@ -1011,7 +1033,7 @@
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">True</property>
|
<property name="expand">True</property>
|
||||||
<property name="fill">True</property>
|
<property name="fill">True</property>
|
||||||
<property name="position">0</property>
|
<property name="position">1</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
|
@ -1026,7 +1048,7 @@
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
<property name="fill">True</property>
|
<property name="fill">True</property>
|
||||||
<property name="position">1</property>
|
<property name="position">2</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
|
@ -1295,8 +1317,10 @@
|
||||||
<object class="GtkSizeGroup">
|
<object class="GtkSizeGroup">
|
||||||
<property name="mode">vertical</property>
|
<property name="mode">vertical</property>
|
||||||
<widgets>
|
<widgets>
|
||||||
|
<widget name="o_pause_after"/>
|
||||||
<widget name="buttonbox2"/>
|
<widget name="buttonbox2"/>
|
||||||
<widget name="box10"/>
|
<widget name="filter_how"/>
|
||||||
|
<widget name="o_enable"/>
|
||||||
</widgets>
|
</widgets>
|
||||||
</object>
|
</object>
|
||||||
<object class="GtkSizeGroup" id="sizegroup1">
|
<object class="GtkSizeGroup" id="sizegroup1">
|
||||||
|
|
Loading…
Reference in New Issue