Browse Source

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>
keep-around/0211f7161cf3ba82cd4f04d9864e313da9889f6d
Anna Schumaker 6 years ago committed by Anna Schumaker
parent
commit
d7322c1f07
  1. 49
      gui/queue.c
  2. 1
      include/gui/queue.h
  3. 30
      share/ocarina/ocarina6.glade

49
gui/queue.c

@ -10,6 +10,15 @@
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)
{
gchar *len;
@ -72,6 +81,7 @@ static gboolean __queue_visible_func(GtkTreeModel *model, GtkTreeIter *iter,
struct track *track;
unsigned int i;
gchar *token;
bool match;
if (!gq_queue || !gq_queue->gq_search)
return TRUE;
@ -81,11 +91,28 @@ static gboolean __queue_visible_func(GtkTreeModel *model, GtkTreeIter *iter,
for (i = 0; gq_queue->gq_search[i]; i++) {
token = gq_queue->gq_search[i];
if (!track_match_token(track, token) &&
!artist_match_token(track->tr_artist, token) &&
!album_match_token(track->tr_album, token) &&
!genre_match_token(track->tr_genre, token))
return FALSE;
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;
}
return TRUE;
@ -93,7 +120,8 @@ static gboolean __queue_visible_func(GtkTreeModel *model, GtkTreeIter *iter,
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)
return;
@ -101,13 +129,20 @@ void __queue_filter(GtkSearchEntry *entry, gpointer data)
g_strfreev(gq_queue->gq_search);
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_active = gtk_combo_box_get_active(combo);
}
gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(gq_queue->gq_filter));
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,
const gchar *text, unsigned int flags)
{

1
include/gui/queue.h

@ -15,6 +15,7 @@ enum gui_queue_flags {
struct gui_queue {
unsigned int gq_flags;
unsigned int gq_active;
gchar *gq_text;
gchar **gq_search;

30
share/ocarina/ocarina6.glade

@ -996,6 +996,28 @@
<property name="visible">True</property>
<property name="can_focus">False</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>
<object class="GtkSearchEntry" id="o_search">
<property name="visible">True</property>
@ -1011,7 +1033,7 @@
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
<property name="position">1</property>
</packing>
</child>
<child>
@ -1026,7 +1048,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="position">2</property>
</packing>
</child>
</object>
@ -1295,8 +1317,10 @@
<object class="GtkSizeGroup">
<property name="mode">vertical</property>
<widgets>
<widget name="o_pause_after"/>
<widget name="buttonbox2"/>
<widget name="box10"/>
<widget name="filter_how"/>
<widget name="o_enable"/>
</widgets>
</object>
<object class="GtkSizeGroup" id="sizegroup1">

Loading…
Cancel
Save