gui/sidebar: Add a function for getting the sidebar treestore
And rename the treestore from "o_playlist_store" to "sidebar_store" Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
b3074979f7
commit
4c3405e874
|
@ -8,6 +8,7 @@
|
|||
#include <gui/filter.h>
|
||||
#include <gui/playlist.h>
|
||||
#include <gui/queue.h>
|
||||
#include <gui/sidebar.h>
|
||||
|
||||
enum playlist_sidebar_columns {
|
||||
P_SB_IMAGE,
|
||||
|
@ -15,7 +16,6 @@ enum playlist_sidebar_columns {
|
|||
P_SB_TYPE,
|
||||
};
|
||||
|
||||
static GtkTreeStore *p_store;
|
||||
static gchar *p_name = NULL;
|
||||
static bool p_filter_enable = true;
|
||||
static bool p_init_done = false;
|
||||
|
@ -32,21 +32,21 @@ static inline enum playlist_type_t __playlist_type(GtkTreeIter *iter)
|
|||
{
|
||||
enum playlist_type_t type;
|
||||
|
||||
gtk_tree_model_get(GTK_TREE_MODEL(p_store), iter, P_SB_TYPE, &type, -1);
|
||||
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,
|
||||
const gchar *image, enum playlist_type_t type)
|
||||
{
|
||||
gtk_tree_store_set(p_store, iter, P_SB_NAME, name,
|
||||
P_SB_IMAGE, image,
|
||||
P_SB_TYPE, type, -1);
|
||||
gtk_tree_store_set(gui_sidebar_store(), iter, P_SB_NAME, name,
|
||||
P_SB_IMAGE, image,
|
||||
P_SB_TYPE, type, -1);
|
||||
}
|
||||
|
||||
static void __playlist_set_size(GtkTreeIter *iter, const gchar *name)
|
||||
{
|
||||
GtkTreePath *path = gtk_tree_model_get_path(GTK_TREE_MODEL(p_store), iter);
|
||||
GtkTreePath *path = gtk_tree_model_get_path(gui_sidebar_model(), iter);
|
||||
enum playlist_type_t type = __playlist_type(iter);
|
||||
unsigned int size = playlist_size(type, name);
|
||||
const gchar *fmt = "%s\n%d track%s";
|
||||
|
@ -56,7 +56,7 @@ static void __playlist_set_size(GtkTreeIter *iter, const gchar *name)
|
|||
fmt = "<b>%s\n%d track%s</b>";
|
||||
|
||||
text = g_markup_printf_escaped(fmt, name, size, (size == 1) ? "" : "s");
|
||||
gtk_tree_store_set(p_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);
|
||||
|
@ -66,17 +66,16 @@ static void __playlist_add(GtkTreeIter *parent, const gchar *name,
|
|||
const gchar *image, enum playlist_type_t type)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
gtk_tree_store_insert(p_store, &iter, parent, -1);
|
||||
gtk_tree_store_insert(gui_sidebar_store(), &iter, parent, -1);
|
||||
__playlist_set(&iter, name, image, type);
|
||||
__playlist_set_size(&iter, name);
|
||||
}
|
||||
|
||||
static gchar *__playlist_name(GtkTreeIter *iter)
|
||||
{
|
||||
GtkTreeModel *model = GTK_TREE_MODEL(p_store);
|
||||
gchar *text, *parsed, *name, **split;
|
||||
|
||||
gtk_tree_model_get(model, iter, P_SB_NAME, &text, -1);
|
||||
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);
|
||||
|
@ -91,7 +90,7 @@ static gchar *__playlist_name(GtkTreeIter *iter)
|
|||
|
||||
void __playlist_selection_changed(GtkTreeSelection *selection, gpointer data)
|
||||
{
|
||||
GtkTreeModel *model = GTK_TREE_MODEL(p_store);
|
||||
GtkTreeModel *model = gui_sidebar_model();
|
||||
GtkTreeIter iter, child;
|
||||
struct queue *queue;
|
||||
|
||||
|
@ -127,7 +126,7 @@ bool __playlist_keypress(GtkTreeView *treeview, GdkEventKey *event,
|
|||
gpointer data)
|
||||
{
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
|
||||
GtkTreeModel *model = GTK_TREE_MODEL(p_store);
|
||||
GtkTreeModel *model = gui_sidebar_model();
|
||||
GtkTreeIter iter, child;
|
||||
gchar *name = NULL;
|
||||
GtkTreePath *path;
|
||||
|
@ -148,7 +147,7 @@ bool __playlist_keypress(GtkTreeView *treeview, GdkEventKey *event,
|
|||
goto out;
|
||||
|
||||
if (playlist_delete(__playlist_type(&child), name))
|
||||
gtk_tree_store_remove(p_store, &child);
|
||||
gtk_tree_store_remove(gui_sidebar_store(), &child);
|
||||
g_free(name);
|
||||
out:
|
||||
g_list_free_full(rows, (GDestroyNotify)gtk_tree_path_free);
|
||||
|
@ -217,23 +216,22 @@ static bool __playlist_queue_set_size(struct queue *queue, GtkTreeIter *iter)
|
|||
|
||||
static void __playlist_update_sizes(struct queue *queue)
|
||||
{
|
||||
GtkTreeModel *model = p_store ? GTK_TREE_MODEL(p_store) : NULL;
|
||||
GtkTreeModelFilter *filter;
|
||||
GtkTreeIter parent, iter;
|
||||
|
||||
if (!model || !gtk_tree_model_get_iter_first(model, &parent))
|
||||
if (!gtk_tree_model_get_iter_first(gui_sidebar_model(), &parent))
|
||||
return;
|
||||
|
||||
do {
|
||||
if (__playlist_queue_set_size(queue, &parent))
|
||||
goto out;
|
||||
if (gtk_tree_model_iter_children(model, &iter, &parent)) {
|
||||
if (gtk_tree_model_iter_children(gui_sidebar_model(), &iter, &parent)) {
|
||||
do {
|
||||
if (__playlist_queue_set_size(queue, &iter))
|
||||
goto out;
|
||||
} while (gtk_tree_model_iter_next(model, &iter));
|
||||
} while (gtk_tree_model_iter_next(gui_sidebar_model(), &iter));
|
||||
}
|
||||
} while (gtk_tree_model_iter_next(model, &parent));
|
||||
} while (gtk_tree_model_iter_next(gui_sidebar_model(), &parent));
|
||||
|
||||
out:
|
||||
filter = GTK_TREE_MODEL_FILTER(gui_builder_object("o_playlist_filter"));
|
||||
|
@ -342,34 +340,33 @@ void gui_playlist_init()
|
|||
GtkTreeIter parent;
|
||||
|
||||
filter = GTK_TREE_MODEL_FILTER(gui_builder_object("o_playlist_filter"));
|
||||
p_store = GTK_TREE_STORE(gui_builder_object("o_playlist_store"));
|
||||
treeview = GTK_TREE_VIEW(gui_builder_widget("o_playlist_view"));
|
||||
|
||||
gtk_tree_model_filter_set_visible_func(filter, __playlist_visible_func,
|
||||
NULL, NULL);
|
||||
|
||||
gtk_tree_store_insert(p_store, &parent, NULL, -1);
|
||||
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(p_store, &parent, NULL, -1);
|
||||
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(p_store, &parent, NULL, -1);
|
||||
gtk_tree_store_insert(gui_sidebar_store(), &parent, NULL, -1);
|
||||
__playlist_set(&parent, "History", "document-open-recent", PL_SYSTEM);
|
||||
__playlist_set_size(&parent, "History");
|
||||
|
||||
/* Add "Playlists" header and playlists. */
|
||||
gtk_tree_store_insert(p_store, &parent, NULL, -1);
|
||||
gtk_tree_store_insert(p_store, &parent, NULL, -1);
|
||||
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);
|
||||
__playlist_add(&parent, "Favorites", "emblem-favorite", PL_SYSTEM);
|
||||
__playlist_add(&parent, "Hidden", "window-close", PL_SYSTEM);
|
||||
|
||||
/* Add "Dynamic" header. */
|
||||
gtk_tree_store_insert(p_store, &parent, NULL, -1);
|
||||
gtk_tree_store_insert(p_store, &parent, NULL, -1);
|
||||
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. */
|
||||
|
@ -378,8 +375,8 @@ void gui_playlist_init()
|
|||
__playlist_add(&parent, "Unplayed", "audio-x-generic", PL_SYSTEM);
|
||||
|
||||
/* Add "Library" header. */
|
||||
gtk_tree_store_insert(p_store, &parent, NULL, -1);
|
||||
gtk_tree_store_insert(p_store, &parent, NULL, -1);
|
||||
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(
|
||||
|
@ -399,8 +396,8 @@ void gui_playlist_add_library(struct library *library)
|
|||
GtkTreeIter parent;
|
||||
gchar *name;
|
||||
|
||||
gtk_tree_model_get_iter_first(GTK_TREE_MODEL(p_store), &parent);
|
||||
while (gtk_tree_model_iter_next(GTK_TREE_MODEL(p_store), &parent)) {
|
||||
gtk_tree_model_get_iter_first(gui_sidebar_model(), &parent);
|
||||
while (gtk_tree_model_iter_next(gui_sidebar_model(), &parent)) {
|
||||
name = __playlist_name(&parent);
|
||||
if (string_match(name, "Library"))
|
||||
__playlist_add(&parent, library->li_path, "folder", PL_LIBRARY);
|
||||
|
@ -417,7 +414,7 @@ void gui_playlist_add_artist(struct artist *artist)
|
|||
gchar *name;
|
||||
bool match;
|
||||
|
||||
gtk_tree_model_get_iter_first(GTK_TREE_MODEL(p_store), &parent);
|
||||
gtk_tree_model_get_iter_first(gui_sidebar_model(), &parent);
|
||||
do {
|
||||
name = __playlist_name(&parent);
|
||||
match = string_match(name, "Collection");
|
||||
|
@ -425,9 +422,9 @@ void gui_playlist_add_artist(struct artist *artist)
|
|||
|
||||
if (match)
|
||||
break;
|
||||
} while (gtk_tree_model_iter_next(GTK_TREE_MODEL(p_store), &parent));
|
||||
} while (gtk_tree_model_iter_next(gui_sidebar_model(), &parent));
|
||||
|
||||
if (!gtk_tree_model_iter_children(GTK_TREE_MODEL(p_store), &sibling, &parent)) {
|
||||
if (!gtk_tree_model_iter_children(gui_sidebar_model(), &sibling, &parent)) {
|
||||
__playlist_add(&parent, artist->ar_name, "system-users", PL_ARTIST);
|
||||
return;
|
||||
}
|
||||
|
@ -438,12 +435,12 @@ void gui_playlist_add_artist(struct artist *artist)
|
|||
g_free(name);
|
||||
|
||||
if (match) {
|
||||
gtk_tree_store_insert_before(p_store, &iter, &parent, &sibling);
|
||||
gtk_tree_store_insert_before(gui_sidebar_store(), &iter, &parent, &sibling);
|
||||
__playlist_set(&iter, artist->ar_name, "system-users", PL_ARTIST);
|
||||
__playlist_set_size(&iter, artist->ar_name);
|
||||
return;
|
||||
}
|
||||
} while (gtk_tree_model_iter_next(GTK_TREE_MODEL(p_store), &sibling));
|
||||
} while (gtk_tree_model_iter_next(gui_sidebar_model(), &sibling));
|
||||
|
||||
__playlist_add(&parent, artist->ar_name, "system-users", PL_ARTIST);
|
||||
}
|
||||
|
@ -454,7 +451,7 @@ void gui_playlist_add_user(struct playlist *playlist)
|
|||
gchar *name;
|
||||
bool match;
|
||||
|
||||
gtk_tree_model_get_iter_first(GTK_TREE_MODEL(p_store), &parent);
|
||||
gtk_tree_model_get_iter_first(gui_sidebar_model(), &parent);
|
||||
do {
|
||||
name = __playlist_name(&parent);
|
||||
match = string_match(name, "Playlists");
|
||||
|
@ -462,9 +459,9 @@ void gui_playlist_add_user(struct playlist *playlist)
|
|||
|
||||
if (match)
|
||||
break;
|
||||
} while (gtk_tree_model_iter_next(GTK_TREE_MODEL(p_store), &parent));
|
||||
} while (gtk_tree_model_iter_next(gui_sidebar_model(), &parent));
|
||||
|
||||
if (!gtk_tree_model_iter_children(GTK_TREE_MODEL(p_store), &sibling, &parent)) {
|
||||
if (!gtk_tree_model_iter_children(gui_sidebar_model(), &sibling, &parent)) {
|
||||
__playlist_add(&parent, playlist->pl_name, "text-x-generic", PL_USER);
|
||||
return;
|
||||
}
|
||||
|
@ -476,12 +473,12 @@ void gui_playlist_add_user(struct playlist *playlist)
|
|||
g_free(name);
|
||||
|
||||
if (match) {
|
||||
gtk_tree_store_insert_before(p_store, &iter, &parent, &sibling);
|
||||
gtk_tree_store_insert_before(gui_sidebar_store(), &iter, &parent, &sibling);
|
||||
__playlist_set(&iter, playlist->pl_name, "text-x-generic", PL_USER);
|
||||
__playlist_set_size(&iter, playlist->pl_name);
|
||||
return;
|
||||
}
|
||||
} while (gtk_tree_model_iter_next(GTK_TREE_MODEL(p_store), &sibling));
|
||||
} while (gtk_tree_model_iter_next(gui_sidebar_model(), &sibling));
|
||||
|
||||
__playlist_add(&parent, playlist->pl_name, "text-x-generic", PL_USER);
|
||||
}
|
||||
|
|
|
@ -14,4 +14,16 @@ static inline GtkPaned *gui_sidebar()
|
|||
return GTK_PANED(gui_builder_widget("sidebar"));
|
||||
}
|
||||
|
||||
/* Called to get the sidebar treestore. */
|
||||
static inline GtkTreeStore *gui_sidebar_store()
|
||||
{
|
||||
return GTK_TREE_STORE(gui_builder_object("sidebar_store"));
|
||||
}
|
||||
|
||||
/* Called to get the sidebar treemodel. */
|
||||
static inline GtkTreeModel *gui_sidebar_model()
|
||||
{
|
||||
return GTK_TREE_MODEL(gui_builder_object("sidebar_store"));
|
||||
}
|
||||
|
||||
#endif /* OCARINA_GUI_SIDEBAR_H */
|
||||
|
|
|
@ -78,7 +78,12 @@
|
|||
<property name="can_focus">False</property>
|
||||
<property name="icon_name">folder-new</property>
|
||||
</object>
|
||||
<object class="GtkTreeStore" id="o_playlist_store">
|
||||
<object class="GtkAdjustment" id="o_progress">
|
||||
<property name="upper">100000000000</property>
|
||||
<property name="step_increment">1000000000</property>
|
||||
<property name="page_increment">10000000000</property>
|
||||
</object>
|
||||
<object class="GtkTreeStore" id="sidebar_store">
|
||||
<columns>
|
||||
<!-- column-name Image -->
|
||||
<column type="gchararray"/>
|
||||
|
@ -89,12 +94,7 @@
|
|||
</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>
|
||||
<property name="page_increment">10000000000</property>
|
||||
<property name="child_model">sidebar_store</property>
|
||||
</object>
|
||||
<object class="GtkWindow" id="window">
|
||||
<property name="visible">True</property>
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <gui/model.h>
|
||||
#include <gui/playlist.h>
|
||||
#include <gui/treeview.h>
|
||||
#include <gui/sidebar.h>
|
||||
#include <gui/view.h>
|
||||
#include <gui/window.h>
|
||||
#include <tests/test.h>
|
||||
|
@ -30,7 +31,7 @@ static void test_playlist_sidebar()
|
|||
treeview = GTK_TREE_VIEW(gui_builder_widget("o_playlist_view"));
|
||||
selection = gtk_tree_view_get_selection(treeview);
|
||||
filter = GTK_TREE_MODEL_FILTER(gui_builder_object("o_playlist_filter"));
|
||||
model = GTK_TREE_MODEL(gui_builder_object("o_playlist_store"));
|
||||
model = gui_sidebar_model();
|
||||
|
||||
playlist_add(PL_SYSTEM, "Queued Tracks", track_get(0));
|
||||
playlist_add(PL_SYSTEM, "History", track_get(0));
|
||||
|
|
|
@ -6,6 +6,15 @@
|
|||
#include <tests/test.h>
|
||||
|
||||
static void test_sidebar()
|
||||
{
|
||||
g_assert_nonnull(gui_sidebar_store());
|
||||
g_assert_true(GTK_IS_TREE_STORE(gui_sidebar_store()));
|
||||
|
||||
g_assert_nonnull(gui_sidebar_model());
|
||||
g_assert_true(GTK_IS_TREE_MODEL(gui_sidebar_model()));
|
||||
}
|
||||
|
||||
static void test_sidebar_pos()
|
||||
{
|
||||
g_assert_false(settings_has("gui.sidebar.pos"));
|
||||
|
||||
|
@ -30,6 +39,7 @@ int main(int argc, char **argv)
|
|||
|
||||
g_test_init(&argc, &argv, NULL);
|
||||
g_test_add_func("/Gui/Sidebar", test_sidebar);
|
||||
g_test_add_func("/Gui/Sidebar/Pos", test_sidebar_pos);
|
||||
ret = g_test_run();
|
||||
|
||||
gui_builder_deinit();
|
||||
|
|
Loading…
Reference in New Issue