gui/sidebar: Add a function for adding playlists
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
4fc8c72ea8
commit
f3f8ad91c6
|
@ -81,23 +81,11 @@ void __playlist_selection_changed(GtkTreeSelection *selection, gpointer data)
|
|||
gboolean __playlist_on_select(GtkTreeSelection *selection, GtkTreeModel *model,
|
||||
GtkTreePath *path, gboolean selected, gpointer data)
|
||||
{
|
||||
struct queue *queue = NULL;
|
||||
enum playlist_type_t type;
|
||||
GtkTreeIter iter, child;
|
||||
gchar *name;
|
||||
|
||||
gtk_tree_model_get_iter(model, &iter, path);
|
||||
__playlist_filter_get_iter(&iter, &child);
|
||||
|
||||
type = gui_sidebar_iter_type(&child);
|
||||
if (type == PL_MAX_TYPE)
|
||||
return false;
|
||||
|
||||
name = gui_sidebar_iter_name(&child);
|
||||
queue = playlist_get_queue(type, name);
|
||||
g_free(name);
|
||||
|
||||
return queue != NULL;
|
||||
return gui_sidebar_iter_type(&child) != PL_MAX_TYPE;
|
||||
}
|
||||
|
||||
bool __playlist_keypress(GtkTreeView *treeview, GdkEventKey *event,
|
||||
|
@ -325,40 +313,26 @@ void gui_playlist_init()
|
|||
gtk_tree_model_filter_set_visible_func(filter, __playlist_visible_func,
|
||||
NULL, NULL);
|
||||
|
||||
gtk_tree_store_insert(gui_sidebar_store(), &parent, NULL, -1);
|
||||
__playlist_set(&parent, "Queued Tracks", "audio-x-generic", PL_SYSTEM);
|
||||
__playlist_set_size(&parent, "Queued Tracks");
|
||||
|
||||
gtk_tree_store_insert(gui_sidebar_store(), &parent, NULL, -1);
|
||||
__playlist_set(&parent, "Collection", "media-optical", PL_SYSTEM);
|
||||
__playlist_set_size(&parent, "Collection");
|
||||
|
||||
gtk_tree_store_insert(gui_sidebar_store(), &parent, NULL, -1);
|
||||
__playlist_set(&parent, "History", "document-open-recent", PL_SYSTEM);
|
||||
__playlist_set_size(&parent, "History");
|
||||
gui_sidebar_iter_first(&parent);
|
||||
gui_sidebar_iter_add(&parent, playlist_get(PL_SYSTEM, "Queued Tracks"),
|
||||
"audio-x-generic");
|
||||
gui_sidebar_iter_add(&parent, playlist_get(PL_SYSTEM, "Collection"),
|
||||
"media-optical");
|
||||
gui_sidebar_iter_add(&parent, playlist_get(PL_SYSTEM, "History"),
|
||||
"document-open-recent");
|
||||
|
||||
/* Add "Playlists" header and playlists. */
|
||||
gtk_tree_store_insert(gui_sidebar_store(), &parent, NULL, -1);
|
||||
gtk_tree_store_insert(gui_sidebar_store(), &parent, NULL, -1);
|
||||
__playlist_set(&parent, "<big>Playlists</big>", "emblem-documents", 0);
|
||||
gui_sidebar_iter_next(&parent);
|
||||
__playlist_add(&parent, "Favorites", "emblem-favorite", PL_SYSTEM);
|
||||
__playlist_add(&parent, "Hidden", "window-close", PL_SYSTEM);
|
||||
|
||||
/* Add "Dynamic" header. */
|
||||
gtk_tree_store_insert(gui_sidebar_store(), &parent, NULL, -1);
|
||||
gtk_tree_store_insert(gui_sidebar_store(), &parent, NULL, -1);
|
||||
__playlist_set(&parent, "<big>Dynamic</big>", "emblem-system", 0);
|
||||
|
||||
/* Add playlists. */
|
||||
gui_sidebar_iter_next(&parent);
|
||||
gui_sidebar_iter_next(&parent);
|
||||
__playlist_add(&parent, "Most Played", "go-up", PL_SYSTEM);
|
||||
__playlist_add(&parent, "Least Played", "go-down", PL_SYSTEM);
|
||||
__playlist_add(&parent, "Unplayed", "audio-x-generic", PL_SYSTEM);
|
||||
|
||||
/* Add "Library" header. */
|
||||
gtk_tree_store_insert(gui_sidebar_store(), &parent, NULL, -1);
|
||||
gtk_tree_store_insert(gui_sidebar_store(), &parent, NULL, -1);
|
||||
__playlist_set(&parent, "<big>Library</big>", "system-file-manager", 0);
|
||||
|
||||
gtk_tree_selection_set_select_function(
|
||||
gtk_tree_view_get_selection(treeview),
|
||||
__playlist_on_select, NULL, NULL);
|
||||
|
|
|
@ -12,17 +12,38 @@ enum sidebar_columns {
|
|||
|
||||
const gchar *SIDEBAR_SETTING = "gui.sidebar.pos";
|
||||
|
||||
static gchar *__gui_sidebar_size_str(struct playlist *playlist)
|
||||
{
|
||||
const gchar *fmt = "%s\n%d track%s";
|
||||
unsigned int size;
|
||||
|
||||
if (!playlist)
|
||||
return NULL;
|
||||
|
||||
size = playlist_size(playlist->pl_type, playlist->pl_name);
|
||||
if (playlist_cur() == playlist)
|
||||
fmt = "<b>%s\n%d track%s</b>";
|
||||
return g_markup_printf_escaped(fmt, playlist->pl_name, size,
|
||||
(size != 1) ? "s" : "");
|
||||
}
|
||||
|
||||
static void __gui_sidebar_set(GtkTreeIter *iter, const gchar *name,
|
||||
const gchar *image, enum playlist_type_t type)
|
||||
{
|
||||
gtk_tree_store_set(gui_sidebar_store(), iter, SB_NAME, name,
|
||||
SB_IMAGE, image,
|
||||
SB_TYPE, type, -1);
|
||||
}
|
||||
|
||||
static void __gui_sidebar_add_header(GtkTreeIter *iter, const gchar *name,
|
||||
const gchar *image)
|
||||
{
|
||||
gchar *formatted = g_strdup_printf("<big>%s</big>", name);
|
||||
|
||||
gtk_tree_store_insert_with_values(gui_sidebar_store(), iter, NULL, -1,
|
||||
SB_TYPE, PL_MAX_TYPE, -1);
|
||||
gtk_tree_store_insert_with_values(gui_sidebar_store(), iter, NULL, -1,
|
||||
SB_IMAGE, image,
|
||||
SB_NAME, formatted,
|
||||
SB_TYPE, PL_MAX_TYPE, -1);
|
||||
gtk_tree_store_insert(gui_sidebar_store(), iter, NULL, -1);
|
||||
__gui_sidebar_set(iter, NULL, NULL, PL_MAX_TYPE);
|
||||
gtk_tree_store_insert(gui_sidebar_store(), iter, NULL, -1);
|
||||
__gui_sidebar_set(iter, formatted, image, PL_MAX_TYPE);
|
||||
|
||||
g_free(formatted);
|
||||
}
|
||||
|
@ -84,3 +105,14 @@ enum playlist_type_t gui_sidebar_iter_type(GtkTreeIter *iter)
|
|||
gtk_tree_model_get(gui_sidebar_model(), iter, SB_TYPE, &type, -1);
|
||||
return type;
|
||||
}
|
||||
|
||||
void gui_sidebar_iter_add(GtkTreeIter *iter, struct playlist *playlist,
|
||||
const gchar *image)
|
||||
{
|
||||
gchar *text = __gui_sidebar_size_str(playlist);
|
||||
GtkTreeIter new;
|
||||
|
||||
gtk_tree_store_insert_before(gui_sidebar_store(), &new, NULL, iter);
|
||||
__gui_sidebar_set(&new, text, image, playlist->pl_type);
|
||||
g_free(text);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,9 @@ 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 add a playlist at the current iterator. */
|
||||
void gui_sidebar_iter_add(GtkTreeIter *, struct playlist *, const gchar *);
|
||||
|
||||
/* Called to get the sidebar widget. */
|
||||
static inline GtkPaned *gui_sidebar()
|
||||
{
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <gui/playlist.h>
|
||||
#include <gui/treeview.h>
|
||||
#include <gui/sidebar.h>
|
||||
#include <gui/treeview.h>
|
||||
#include <gui/view.h>
|
||||
#include <gui/window.h>
|
||||
#include <tests/test.h>
|
||||
|
@ -110,6 +111,7 @@ int main(int argc, char **argv)
|
|||
gui_model_init();
|
||||
gui_filter_init();
|
||||
gui_treeview_init();
|
||||
gui_sidebar_init();
|
||||
gui_view_init();
|
||||
gui_playlist_init();
|
||||
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
/*
|
||||
* Copyright 2015 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/core.h>
|
||||
#include <core/settings.h>
|
||||
#include <gui/sidebar.h>
|
||||
#include <tests/test.h>
|
||||
|
||||
const gchar *test_pl_names[6] = { "", "Playlists",
|
||||
"", "Dynamic",
|
||||
"", "Library" };
|
||||
const gchar *test_pl_names[8] = { "Collection",
|
||||
"History",
|
||||
"", "Playlists",
|
||||
"", "Dynamic",
|
||||
"", "Library" };
|
||||
struct core_init_data init_data;
|
||||
|
||||
static void test_sidebar()
|
||||
{
|
||||
|
@ -27,13 +31,17 @@ static void test_sidebar()
|
|||
g_assert_true(GTK_IS_TREE_VIEW(gui_sidebar_treeview()));
|
||||
|
||||
g_assert_true(gui_sidebar_iter_first(&iter));
|
||||
for (i = 0; i < 6; i++) {
|
||||
gui_sidebar_iter_add(&iter, playlist_get(PL_SYSTEM, "Collection"), NULL);
|
||||
gui_sidebar_iter_add(&iter, playlist_get(PL_SYSTEM, "History"), NULL);
|
||||
|
||||
g_assert_true(gui_sidebar_iter_first(&iter));
|
||||
for (i = 0; i < 8; i++) {
|
||||
g_assert_cmpstr_free(gui_sidebar_iter_name(&iter), ==,
|
||||
test_pl_names[i]);
|
||||
g_assert_cmpuint(gui_sidebar_iter_type(&iter), ==,
|
||||
PL_MAX_TYPE);
|
||||
(i < 2) ? PL_SYSTEM: PL_MAX_TYPE);
|
||||
|
||||
if (i < 5)
|
||||
if (i < 7)
|
||||
g_assert_true(gui_sidebar_iter_next(&iter));
|
||||
}
|
||||
g_assert_false(gui_sidebar_iter_next(&iter));
|
||||
|
@ -58,7 +66,7 @@ int main(int argc, char **argv)
|
|||
int ret;
|
||||
|
||||
gtk_init(&argc, NULL);
|
||||
settings_init();
|
||||
core_init(&argc, &argv, &init_data);
|
||||
gui_builder_init("share/ocarina/ocarina.ui");
|
||||
gui_sidebar_init();
|
||||
|
||||
|
@ -67,7 +75,7 @@ int main(int argc, char **argv)
|
|||
g_test_add_func("/Gui/Sidebar/Pos", test_sidebar_pos);
|
||||
ret = g_test_run();
|
||||
|
||||
core_deinit();
|
||||
gui_builder_deinit();
|
||||
settings_deinit();
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue