Add a LIBRARY_FILTER notification
I also enable filtering on the new library tab. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
b2e2404741
commit
b8f2ffdf48
|
@ -12,7 +12,8 @@ enum notify_t {
|
|||
PAUSE_TYPE, // AutoPauseType *
|
||||
PAUSE_COUNT, // unsigned int *
|
||||
PLAYLIST_ADD, // libsaria::PlaylistNotification *
|
||||
PLAYLIST_SIZE, // lisbaria::PlaylistNotification *
|
||||
PLAYLIST_SIZE, // libsaria::PlaylistNotification *
|
||||
PLAYLIST_FILTER,// libsaria::PlaylistNotification *
|
||||
NOTIFY_SIZE,
|
||||
};
|
||||
|
||||
|
|
|
@ -75,6 +75,7 @@ namespace libsaria
|
|||
{
|
||||
index.do_filter(text);
|
||||
RENDER( refilter() );
|
||||
notify_ui(PLAYLIST_FILTER, NULL, 0);
|
||||
}
|
||||
|
||||
bool Playlist::is_visible(libsaria::Track *track)
|
||||
|
|
|
@ -25,6 +25,7 @@ void on_notify(notify_t event, void *data)
|
|||
break;
|
||||
case PLAYLIST_ADD:
|
||||
case PLAYLIST_SIZE:
|
||||
case PLAYLIST_FILTER:
|
||||
update_playlist(event, (libsaria::PlaylistNotification *)data);
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -15,6 +15,7 @@ static GtkWidget *ban_button;
|
|||
static GtkWidget *open_button;
|
||||
static GtkWidget *yes_image;
|
||||
static GtkWidget *no_image;
|
||||
static GtkTreeModel *library_filter;
|
||||
|
||||
static void find_exe_path(string &res)
|
||||
{
|
||||
|
@ -88,6 +89,8 @@ GObject *get_object(const string &name)
|
|||
return G_OBJECT(yes_image);
|
||||
else if (name == "NoImage")
|
||||
return G_OBJECT(no_image);
|
||||
else if (name == "LibraryFilter")
|
||||
return G_OBJECT(library_filter);
|
||||
return gtk_builder_get_object(builder, name.c_str());
|
||||
}
|
||||
|
||||
|
@ -137,6 +140,10 @@ static void init_widgets()
|
|||
|
||||
open_button = gtk_button_new();
|
||||
gtk_button_set_image(GTK_BUTTON(open_button), image);
|
||||
|
||||
library_filter = gtk_tree_model_filter_new(
|
||||
GTK_TREE_MODEL(get_object("LibraryPlist")),
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void init(int argc, char **argv)
|
||||
|
|
|
@ -58,6 +58,22 @@ namespace ocarina
|
|||
|
||||
}; /* Namespace: ocarina */
|
||||
|
||||
static gboolean is_visible(GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
|
||||
{
|
||||
libsaria::Track *track;
|
||||
libsaria::Playlist *plist = (libsaria::Playlist *)data;
|
||||
|
||||
gtk_tree_model_get(model, iter, 0, &track, -1);
|
||||
return plist->is_visible(track);
|
||||
}
|
||||
|
||||
static void do_filter(GtkWidget *entry, gpointer d)
|
||||
{
|
||||
string text = gtk_entry_get_text(GTK_ENTRY(entry));
|
||||
libsaria::Playlist *plist = (libsaria::Playlist *)d;
|
||||
plist->set_filter_text(text);
|
||||
}
|
||||
|
||||
static void track_selected(GtkWidget *treeview, GtkTreePath *path,
|
||||
GtkTreeViewColumn *col, gpointer data)
|
||||
{
|
||||
|
@ -93,6 +109,13 @@ static GtkWidget *find_label(libsaria::Playlist *plist)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static GtkTreeModelFilter *find_filter(libsaria::Playlist *plist)
|
||||
{
|
||||
if (plist == libsaria::library::get_playlist())
|
||||
return GTK_TREE_MODEL_FILTER(get_object("LibraryFilter"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void playlist_add(libsaria::Playlist *plist, libsaria::Track *track,
|
||||
unsigned int index)
|
||||
{
|
||||
|
@ -124,16 +147,31 @@ static void set_playlist_size(libsaria::Playlist *plist)
|
|||
}
|
||||
}
|
||||
|
||||
static void playlist_refilter(libsaria::Playlist *plist)
|
||||
{
|
||||
gtk_tree_model_filter_refilter(find_filter(plist));
|
||||
}
|
||||
|
||||
void update_playlist(notify_t event, libsaria::PlaylistNotification *data)
|
||||
{
|
||||
if (event == PLAYLIST_ADD)
|
||||
playlist_add(data->plist, data->track, data->index);
|
||||
else if (event == PLAYLIST_SIZE)
|
||||
set_playlist_size(data->plist);
|
||||
else if (event == PLAYLIST_FILTER)
|
||||
playlist_refilter(data->plist);
|
||||
}
|
||||
|
||||
void init_playlist()
|
||||
{
|
||||
GtkTreeModel *library_filter = GTK_TREE_MODEL(get_object("LibraryFilter"));
|
||||
libsaria::Playlist *library = libsaria::library::get_playlist();
|
||||
|
||||
init_playlist2();
|
||||
|
||||
gtk_tree_view_set_model(GTK_TREE_VIEW(get_widget("LibraryPlistView")), library_filter);
|
||||
gtk_tree_model_filter_set_visible_func(find_filter(library), is_visible, library, NULL);
|
||||
|
||||
connect_signal("LibraryPlistView", "row-activated", G_CALLBACK(track_selected), NULL);
|
||||
connect_signal("LibraryEntry", "changed", G_CALLBACK(do_filter), library);
|
||||
}
|
||||
|
|
|
@ -197,7 +197,7 @@
|
|||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkEntry" id="LibraryFilter">
|
||||
<object class="GtkEntry" id="LibraryEntry">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="invisible_char">●</property>
|
||||
|
|
Loading…
Reference in New Issue