gui/playlist: Add a GtkTreeFilter to the playlist treeview
I intend to use this to hide empty playlists, but it could potentially also be used to search for a specific playlist. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
c6e9c176d8
commit
278a54f7ec
|
@ -20,6 +20,12 @@ static bool p_init_done = false;
|
|||
|
||||
static void __playlist_update_sizes(struct queue *);
|
||||
|
||||
static inline void __playlist_filter_get_iter(GtkTreeIter *iter, GtkTreeIter *child)
|
||||
{
|
||||
gtk_tree_model_filter_convert_iter_to_child_iter(
|
||||
GTK_TREE_MODEL_FILTER(gui_builder_object("o_playlist_filter")),
|
||||
child, iter);
|
||||
}
|
||||
static inline enum playlist_type_t __playlist_type(GtkTreeIter *iter)
|
||||
{
|
||||
enum playlist_type_t type;
|
||||
|
@ -85,15 +91,16 @@ static gchar *__playlist_name(GtkTreeIter *iter)
|
|||
void __playlist_selection_changed(GtkTreeSelection *selection, gpointer data)
|
||||
{
|
||||
GtkTreeModel *model = GTK_TREE_MODEL(p_store);
|
||||
GtkTreeIter iter, child;
|
||||
struct queue *queue;
|
||||
GtkTreeIter iter;
|
||||
|
||||
if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
|
||||
__playlist_filter_get_iter(&iter, &child);
|
||||
if (p_name)
|
||||
g_free(p_name);
|
||||
p_name = __playlist_name(&iter);
|
||||
|
||||
queue = playlist_get_queue(__playlist_type(&iter), p_name);
|
||||
p_name = __playlist_name(&child);
|
||||
queue = playlist_get_queue(__playlist_type(&child), p_name);
|
||||
gui_queue_show(gui_queue(queue));
|
||||
}
|
||||
}
|
||||
|
@ -102,13 +109,14 @@ gboolean __playlist_on_select(GtkTreeSelection *selection, GtkTreeModel *model,
|
|||
GtkTreePath *path, gboolean selected, gpointer data)
|
||||
{
|
||||
struct queue *queue = NULL;
|
||||
GtkTreeIter iter;
|
||||
GtkTreeIter iter, child;
|
||||
gchar *name;
|
||||
|
||||
gtk_tree_model_get_iter(model, &iter, path);
|
||||
__playlist_filter_get_iter(&iter, &child);
|
||||
|
||||
name = __playlist_name(&iter);
|
||||
queue = playlist_get_queue(__playlist_type(&iter), name);
|
||||
name = __playlist_name(&child);
|
||||
queue = playlist_get_queue(__playlist_type(&child), name);
|
||||
g_free(name);
|
||||
|
||||
return queue != NULL;
|
||||
|
@ -119,9 +127,9 @@ bool __playlist_keypress(GtkTreeView *treeview, GdkEventKey *event,
|
|||
{
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
|
||||
GtkTreeModel *model = GTK_TREE_MODEL(p_store);
|
||||
GtkTreeIter iter, child;
|
||||
gchar *name = NULL;
|
||||
GtkTreePath *path;
|
||||
GtkTreeIter iter;
|
||||
GList *rows;
|
||||
|
||||
if (event->keyval != GDK_KEY_Delete)
|
||||
|
@ -130,13 +138,16 @@ bool __playlist_keypress(GtkTreeView *treeview, GdkEventKey *event,
|
|||
rows = gtk_tree_selection_get_selected_rows(selection, &model);
|
||||
path = rows->data;
|
||||
|
||||
if (gtk_tree_model_get_iter(model, &iter, path))
|
||||
name = __playlist_name(&iter);
|
||||
if (!gtk_tree_model_get_iter(model, &iter, path))
|
||||
return false;
|
||||
|
||||
__playlist_filter_get_iter(&iter, &child);
|
||||
name = __playlist_name(&child);
|
||||
if (!name)
|
||||
goto out;
|
||||
|
||||
if (playlist_delete(__playlist_type(&iter), name))
|
||||
gtk_tree_store_remove(GTK_TREE_STORE(model), &iter);
|
||||
if (playlist_delete(__playlist_type(&child), name))
|
||||
gtk_tree_store_remove(GTK_TREE_STORE(model), &child);
|
||||
g_free(name);
|
||||
out:
|
||||
g_list_free_full(rows, (GDestroyNotify)gtk_tree_path_free);
|
||||
|
@ -147,19 +158,22 @@ void __playlist_row_activated(GtkTreeView *treeview, GtkTreePath *path,
|
|||
GtkTreeViewColumn *col, gpointer data)
|
||||
{
|
||||
enum playlist_type_t type;
|
||||
GtkTreeIter iter, child;
|
||||
GtkTreeModel *model;
|
||||
struct queue *queue;
|
||||
GtkTreeIter iter;
|
||||
unsigned int id;
|
||||
gchar *name;
|
||||
|
||||
type = settings_get("core.playlist.cur.type");
|
||||
id = settings_get("core.playlist.cur.id");
|
||||
|
||||
gtk_tree_model_get_iter(GTK_TREE_MODEL(p_store), &iter, path);
|
||||
model = GTK_TREE_MODEL(gui_builder_object("o_playlist_filter"));
|
||||
gtk_tree_model_get_iter(model, &iter, path);
|
||||
__playlist_filter_get_iter(&iter, &child);
|
||||
|
||||
name = __playlist_name(&iter);
|
||||
playlist_select(__playlist_type(&iter), name);
|
||||
__playlist_set_size(&iter, name);
|
||||
name = __playlist_name(&child);
|
||||
playlist_select(__playlist_type(&child), name);
|
||||
__playlist_set_size(&child, name);
|
||||
g_free(name);
|
||||
|
||||
name = playlist_get_name(type, id);
|
||||
|
|
|
@ -93,6 +93,9 @@
|
|||
<column type="guint"/>
|
||||
</columns>
|
||||
</object>
|
||||
<object class="GtkTreeModelFilter" id="o_playlist_filter">
|
||||
<property name="child_model">o_playlist_store</property>
|
||||
</object>
|
||||
<object class="GtkAdjustment" id="o_progress">
|
||||
<property name="upper">100000000000</property>
|
||||
<property name="step_increment">1000000000</property>
|
||||
|
@ -717,7 +720,7 @@
|
|||
<object class="GtkTreeView" id="o_playlist_view">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="model">o_playlist_store</property>
|
||||
<property name="model">o_playlist_filter</property>
|
||||
<property name="headers_visible">False</property>
|
||||
<property name="search_column">1</property>
|
||||
<property name="enable_tree_lines">True</property>
|
||||
|
|
Loading…
Reference in New Issue