gui/sidebar: Add useful iterator functions
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
bbac5e23be
commit
18e76a7dca
|
@ -27,13 +27,6 @@ static inline void __playlist_filter_get_iter(GtkTreeIter *iter, GtkTreeIter *ch
|
||||||
gtk_tree_model_filter_convert_iter_to_child_iter(gui_sidebar_filter(),
|
gtk_tree_model_filter_convert_iter_to_child_iter(gui_sidebar_filter(),
|
||||||
child, iter);
|
child, iter);
|
||||||
}
|
}
|
||||||
static inline enum playlist_type_t __playlist_type(GtkTreeIter *iter)
|
|
||||||
{
|
|
||||||
enum playlist_type_t type;
|
|
||||||
|
|
||||||
gtk_tree_model_get(gui_sidebar_model(), iter, P_SB_TYPE, &type, -1);
|
|
||||||
return (type < PL_MAX_TYPE) ? type : PL_SYSTEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void __playlist_set(GtkTreeIter *iter, const gchar *name,
|
static void __playlist_set(GtkTreeIter *iter, const gchar *name,
|
||||||
const gchar *image, enum playlist_type_t type)
|
const gchar *image, enum playlist_type_t type)
|
||||||
|
@ -45,8 +38,7 @@ static void __playlist_set(GtkTreeIter *iter, const gchar *name,
|
||||||
|
|
||||||
static void __playlist_set_size(GtkTreeIter *iter, const gchar *name)
|
static void __playlist_set_size(GtkTreeIter *iter, const gchar *name)
|
||||||
{
|
{
|
||||||
GtkTreePath *path = gtk_tree_model_get_path(gui_sidebar_model(), iter);
|
enum playlist_type_t type = gui_sidebar_iter_type(iter);
|
||||||
enum playlist_type_t type = __playlist_type(iter);
|
|
||||||
unsigned int size = playlist_size(type, name);
|
unsigned int size = playlist_size(type, name);
|
||||||
const gchar *fmt = "%s\n%d track%s";
|
const gchar *fmt = "%s\n%d track%s";
|
||||||
gchar *text;
|
gchar *text;
|
||||||
|
@ -57,7 +49,6 @@ static void __playlist_set_size(GtkTreeIter *iter, const gchar *name)
|
||||||
text = g_markup_printf_escaped(fmt, name, size, (size == 1) ? "" : "s");
|
text = g_markup_printf_escaped(fmt, name, size, (size == 1) ? "" : "s");
|
||||||
gtk_tree_store_set(gui_sidebar_store(), iter, P_SB_NAME, text, -1);
|
gtk_tree_store_set(gui_sidebar_store(), iter, P_SB_NAME, text, -1);
|
||||||
|
|
||||||
gtk_tree_path_free(path);
|
|
||||||
g_free(text);
|
g_free(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,23 +61,6 @@ static void __playlist_add(GtkTreeIter *parent, const gchar *name,
|
||||||
__playlist_set_size(&iter, name);
|
__playlist_set_size(&iter, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gchar *__playlist_name(GtkTreeIter *iter)
|
|
||||||
{
|
|
||||||
gchar *text, *parsed, *name, **split;
|
|
||||||
|
|
||||||
gtk_tree_model_get(gui_sidebar_model(), iter, P_SB_NAME, &text, -1);
|
|
||||||
if (!text)
|
|
||||||
return NULL;
|
|
||||||
pango_parse_markup(text, -1, 0, NULL, &parsed, NULL, NULL);
|
|
||||||
split = g_strsplit(parsed, "\n", 2);
|
|
||||||
name = g_strdup(split[0]);
|
|
||||||
|
|
||||||
g_strfreev(split);
|
|
||||||
g_free(text);
|
|
||||||
g_free(parsed);
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
void __playlist_selection_changed(GtkTreeSelection *selection, gpointer data)
|
void __playlist_selection_changed(GtkTreeSelection *selection, gpointer data)
|
||||||
{
|
{
|
||||||
GtkTreeModel *model = gui_sidebar_model();
|
GtkTreeModel *model = gui_sidebar_model();
|
||||||
|
@ -98,8 +72,8 @@ void __playlist_selection_changed(GtkTreeSelection *selection, gpointer data)
|
||||||
if (p_name)
|
if (p_name)
|
||||||
g_free(p_name);
|
g_free(p_name);
|
||||||
|
|
||||||
p_name = __playlist_name(&child);
|
p_name = gui_sidebar_iter_name(&child);
|
||||||
queue = playlist_get_queue(__playlist_type(&child), p_name);
|
queue = playlist_get_queue(gui_sidebar_iter_type(&child), p_name);
|
||||||
gui_queue_show(gui_queue(queue));
|
gui_queue_show(gui_queue(queue));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,8 +88,8 @@ gboolean __playlist_on_select(GtkTreeSelection *selection, GtkTreeModel *model,
|
||||||
gtk_tree_model_get_iter(model, &iter, path);
|
gtk_tree_model_get_iter(model, &iter, path);
|
||||||
__playlist_filter_get_iter(&iter, &child);
|
__playlist_filter_get_iter(&iter, &child);
|
||||||
|
|
||||||
name = __playlist_name(&child);
|
name = gui_sidebar_iter_name(&child);
|
||||||
queue = playlist_get_queue(__playlist_type(&child), name);
|
queue = playlist_get_queue(gui_sidebar_iter_type(&child), name);
|
||||||
g_free(name);
|
g_free(name);
|
||||||
|
|
||||||
return queue != NULL;
|
return queue != NULL;
|
||||||
|
@ -141,11 +115,11 @@ bool __playlist_keypress(GtkTreeView *treeview, GdkEventKey *event,
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
__playlist_filter_get_iter(&iter, &child);
|
__playlist_filter_get_iter(&iter, &child);
|
||||||
name = __playlist_name(&child);
|
name = gui_sidebar_iter_name(&child);
|
||||||
if (!name)
|
if (!name)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (playlist_delete(__playlist_type(&child), name))
|
if (playlist_delete(gui_sidebar_iter_type(&child), name))
|
||||||
gtk_tree_store_remove(gui_sidebar_store(), &child);
|
gtk_tree_store_remove(gui_sidebar_store(), &child);
|
||||||
g_free(name);
|
g_free(name);
|
||||||
out:
|
out:
|
||||||
|
@ -170,8 +144,8 @@ void __playlist_row_activated(GtkTreeView *treeview, GtkTreePath *path,
|
||||||
gtk_tree_model_get_iter(model, &iter, path);
|
gtk_tree_model_get_iter(model, &iter, path);
|
||||||
__playlist_filter_get_iter(&iter, &child);
|
__playlist_filter_get_iter(&iter, &child);
|
||||||
|
|
||||||
name = __playlist_name(&child);
|
name = gui_sidebar_iter_name(&child);
|
||||||
playlist_select(__playlist_type(&child), name);
|
playlist_select(gui_sidebar_iter_type(&child), name);
|
||||||
__playlist_set_size(&child, name);
|
__playlist_set_size(&child, name);
|
||||||
g_free(name);
|
g_free(name);
|
||||||
|
|
||||||
|
@ -189,11 +163,13 @@ static gboolean __playlist_visible_func(GtkTreeModel *model, GtkTreeIter *iter,
|
||||||
|
|
||||||
if (!p_filter_enable)
|
if (!p_filter_enable)
|
||||||
return true;
|
return true;
|
||||||
|
if (gui_sidebar_iter_type(iter) == PL_MAX_TYPE)
|
||||||
|
return true;
|
||||||
|
|
||||||
name = __playlist_name(iter);
|
name = gui_sidebar_iter_name(iter);
|
||||||
show = __playlist_type(iter) == PL_USER ||
|
show = gui_sidebar_iter_type(iter) == PL_USER ||
|
||||||
!playlist_get_queue(__playlist_type(iter), name) ||
|
!playlist_get_queue(gui_sidebar_iter_type(iter), name) ||
|
||||||
(playlist_size(__playlist_type(iter), name) > 0);
|
(playlist_size(gui_sidebar_iter_type(iter), name) > 0);
|
||||||
g_free(name);
|
g_free(name);
|
||||||
return show;
|
return show;
|
||||||
}
|
}
|
||||||
|
@ -201,8 +177,8 @@ static gboolean __playlist_visible_func(GtkTreeModel *model, GtkTreeIter *iter,
|
||||||
static bool __playlist_queue_set_size(struct queue *queue, GtkTreeIter *iter)
|
static bool __playlist_queue_set_size(struct queue *queue, GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
struct gui_queue *gq = gui_queue(queue);
|
struct gui_queue *gq = gui_queue(queue);
|
||||||
bool match = (__playlist_type(iter) == gq->gq_playlist->pl_type);
|
bool match = (gui_sidebar_iter_type(iter) == gq->gq_playlist->pl_type);
|
||||||
gchar *name = __playlist_name(iter);
|
gchar *name = gui_sidebar_iter_name(iter);
|
||||||
|
|
||||||
if (match)
|
if (match)
|
||||||
match = string_match(name, gq->gq_text);
|
match = string_match(name, gq->gq_text);
|
||||||
|
@ -218,7 +194,7 @@ static void __playlist_update_sizes(struct queue *queue)
|
||||||
GtkTreeModelFilter *filter;
|
GtkTreeModelFilter *filter;
|
||||||
GtkTreeIter parent, iter;
|
GtkTreeIter parent, iter;
|
||||||
|
|
||||||
if (!gtk_tree_model_get_iter_first(gui_sidebar_model(), &parent))
|
if (!gui_sidebar_iter_first(&parent))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
@ -228,9 +204,9 @@ static void __playlist_update_sizes(struct queue *queue)
|
||||||
do {
|
do {
|
||||||
if (__playlist_queue_set_size(queue, &iter))
|
if (__playlist_queue_set_size(queue, &iter))
|
||||||
goto out;
|
goto out;
|
||||||
} while (gtk_tree_model_iter_next(gui_sidebar_model(), &iter));
|
} while (gui_sidebar_iter_next(&iter));
|
||||||
}
|
}
|
||||||
} while (gtk_tree_model_iter_next(gui_sidebar_model(), &parent));
|
} while (gui_sidebar_iter_next(&parent));
|
||||||
|
|
||||||
out:
|
out:
|
||||||
filter = gui_sidebar_filter();
|
filter = gui_sidebar_filter();
|
||||||
|
@ -397,7 +373,7 @@ void gui_playlist_add_library(struct library *library)
|
||||||
|
|
||||||
gtk_tree_model_get_iter_first(gui_sidebar_model(), &parent);
|
gtk_tree_model_get_iter_first(gui_sidebar_model(), &parent);
|
||||||
while (gtk_tree_model_iter_next(gui_sidebar_model(), &parent)) {
|
while (gtk_tree_model_iter_next(gui_sidebar_model(), &parent)) {
|
||||||
name = __playlist_name(&parent);
|
name = gui_sidebar_iter_name(&parent);
|
||||||
if (string_match(name, "Library"))
|
if (string_match(name, "Library"))
|
||||||
__playlist_add(&parent, library->li_path, "folder", PL_LIBRARY);
|
__playlist_add(&parent, library->li_path, "folder", PL_LIBRARY);
|
||||||
g_free(name);
|
g_free(name);
|
||||||
|
@ -414,7 +390,7 @@ void gui_playlist_add_artist(struct artist *artist)
|
||||||
|
|
||||||
gtk_tree_model_get_iter_first(gui_sidebar_model(), &parent);
|
gtk_tree_model_get_iter_first(gui_sidebar_model(), &parent);
|
||||||
do {
|
do {
|
||||||
name = __playlist_name(&parent);
|
name = gui_sidebar_iter_name(&parent);
|
||||||
match = string_match(name, "Collection");
|
match = string_match(name, "Collection");
|
||||||
g_free(name);
|
g_free(name);
|
||||||
|
|
||||||
|
@ -428,7 +404,7 @@ void gui_playlist_add_artist(struct artist *artist)
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
name = __playlist_name(&sibling);
|
name = gui_sidebar_iter_name(&parent);
|
||||||
match = g_utf8_collate(name, artist->ar_name) >= 0;
|
match = g_utf8_collate(name, artist->ar_name) >= 0;
|
||||||
g_free(name);
|
g_free(name);
|
||||||
|
|
||||||
|
@ -451,7 +427,7 @@ void gui_playlist_add_user(struct playlist *playlist)
|
||||||
|
|
||||||
gtk_tree_model_get_iter_first(gui_sidebar_model(), &parent);
|
gtk_tree_model_get_iter_first(gui_sidebar_model(), &parent);
|
||||||
do {
|
do {
|
||||||
name = __playlist_name(&parent);
|
name = gui_sidebar_iter_name(&parent);
|
||||||
match = string_match(name, "Playlists");
|
match = string_match(name, "Playlists");
|
||||||
g_free(name);
|
g_free(name);
|
||||||
|
|
||||||
|
@ -465,9 +441,9 @@ void gui_playlist_add_user(struct playlist *playlist)
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
name = __playlist_name(&sibling);
|
name = gui_sidebar_iter_name(&parent);
|
||||||
match = g_utf8_collate(name, playlist->pl_name) >= 0;
|
match = g_utf8_collate(name, playlist->pl_name) >= 0;
|
||||||
match = match && !(__playlist_type(&sibling) == PL_SYSTEM);
|
match = match && !(gui_sidebar_iter_type(&sibling) == PL_SYSTEM);
|
||||||
g_free(name);
|
g_free(name);
|
||||||
|
|
||||||
if (match) {
|
if (match) {
|
||||||
|
|
|
@ -4,6 +4,12 @@
|
||||||
#include <core/settings.h>
|
#include <core/settings.h>
|
||||||
#include <gui/sidebar.h>
|
#include <gui/sidebar.h>
|
||||||
|
|
||||||
|
enum sidebar_columns {
|
||||||
|
SB_IMAGE,
|
||||||
|
SB_NAME,
|
||||||
|
SB_TYPE,
|
||||||
|
};
|
||||||
|
|
||||||
const gchar *SIDEBAR_SETTING = "gui.sidebar.pos";
|
const gchar *SIDEBAR_SETTING = "gui.sidebar.pos";
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,3 +24,41 @@ void gui_sidebar_init()
|
||||||
if (pos > 0)
|
if (pos > 0)
|
||||||
gtk_paned_set_position(gui_sidebar(), pos);
|
gtk_paned_set_position(gui_sidebar(), pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean gui_sidebar_iter_first(GtkTreeIter *iter)
|
||||||
|
{
|
||||||
|
return gtk_tree_model_get_iter_first(gui_sidebar_model(), iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean gui_sidebar_iter_next(GtkTreeIter *iter)
|
||||||
|
{
|
||||||
|
return gtk_tree_model_iter_next(gui_sidebar_model(), iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
gchar *gui_sidebar_iter_name(GtkTreeIter *iter)
|
||||||
|
{
|
||||||
|
gchar *text = NULL, *parsed = NULL, *name, **split;
|
||||||
|
|
||||||
|
gtk_tree_model_get(gui_sidebar_model(), iter, SB_NAME, &text, -1);
|
||||||
|
if (!text)
|
||||||
|
return g_strdup("");
|
||||||
|
|
||||||
|
pango_parse_markup(text, -1, 0, NULL, &parsed, NULL, NULL);
|
||||||
|
if (!parsed)
|
||||||
|
return g_strdup("");
|
||||||
|
|
||||||
|
split = g_strsplit(parsed, "\n", 2);
|
||||||
|
name = g_strdup(split[0]);
|
||||||
|
|
||||||
|
g_strfreev(split);
|
||||||
|
g_free(parsed);
|
||||||
|
g_free(text);
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum playlist_type_t gui_sidebar_iter_type(GtkTreeIter *iter)
|
||||||
|
{
|
||||||
|
enum playlist_type_t type;
|
||||||
|
gtk_tree_model_get(gui_sidebar_model(), iter, SB_TYPE, &type, -1);
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
|
@ -3,11 +3,27 @@
|
||||||
*/
|
*/
|
||||||
#ifndef OCARINA_GUI_SIDEBAR_H
|
#ifndef OCARINA_GUI_SIDEBAR_H
|
||||||
#define OCARINA_GUI_SIDEBAR_H
|
#define OCARINA_GUI_SIDEBAR_H
|
||||||
|
#include <core/playlist.h>
|
||||||
#include <gui/builder.h>
|
#include <gui/builder.h>
|
||||||
|
|
||||||
/* Called to initialize the sidebar. */
|
/* Called to initialize the sidebar. */
|
||||||
void gui_sidebar_init();
|
void gui_sidebar_init();
|
||||||
|
|
||||||
|
/* Called to set an iterator to the first playlist. */
|
||||||
|
gboolean gui_sidebar_iter_first(GtkTreeIter *);
|
||||||
|
|
||||||
|
/* Called to advance the iterator to the next playlist. */
|
||||||
|
gboolean gui_sidebar_iter_next(GtkTreeIter *);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Called to find the name of the playlist at the given iterator.
|
||||||
|
* NOTE: This function returns a new string that must be freed with g_free().
|
||||||
|
*/
|
||||||
|
gchar *gui_sidebar_iter_name(GtkTreeIter *);
|
||||||
|
|
||||||
|
/* Called to find the type of the playlist at the given iterator. */
|
||||||
|
enum playlist_type_t gui_sidebar_iter_type(GtkTreeIter *);
|
||||||
|
|
||||||
/* Called to get the sidebar widget. */
|
/* Called to get the sidebar widget. */
|
||||||
static inline GtkPaned *gui_sidebar()
|
static inline GtkPaned *gui_sidebar()
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
static void test_sidebar()
|
static void test_sidebar()
|
||||||
{
|
{
|
||||||
|
GtkTreeIter iter;
|
||||||
|
|
||||||
g_assert_nonnull(gui_sidebar_store());
|
g_assert_nonnull(gui_sidebar_store());
|
||||||
g_assert_true(GTK_IS_TREE_STORE(gui_sidebar_store()));
|
g_assert_true(GTK_IS_TREE_STORE(gui_sidebar_store()));
|
||||||
|
|
||||||
|
@ -18,6 +20,8 @@ static void test_sidebar()
|
||||||
|
|
||||||
g_assert_nonnull(gui_sidebar_treeview());
|
g_assert_nonnull(gui_sidebar_treeview());
|
||||||
g_assert_true(GTK_IS_TREE_VIEW(gui_sidebar_treeview()));
|
g_assert_true(GTK_IS_TREE_VIEW(gui_sidebar_treeview()));
|
||||||
|
|
||||||
|
g_assert_false(gui_sidebar_iter_first(&iter));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_sidebar_pos()
|
static void test_sidebar_pos()
|
||||||
|
|
Loading…
Reference in New Issue