From 69b39ea717f38700c284987b29055e21de3887b9 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Wed, 18 May 2016 07:54:18 -0400 Subject: [PATCH] gui/sidebar: Remove unused sidebar liststore Signed-off-by: Anna Schumaker --- gui/ocarina.c | 2 + gui/playlist.c | 4 +- gui/sidebar.c | 159 +---------------------------------- gui/tempq.c | 10 +-- gui/view.c | 7 +- include/gui/sidebar.h | 23 ----- share/ocarina/ocarina6.glade | 131 ++++++----------------------- 7 files changed, 36 insertions(+), 300 deletions(-) diff --git a/gui/ocarina.c b/gui/ocarina.c index 0acd4319..28b4cc84 100644 --- a/gui/ocarina.c +++ b/gui/ocarina.c @@ -6,7 +6,9 @@ #include #include #include +#include #include +#include #include #include #include diff --git a/gui/playlist.c b/gui/playlist.c index 87608261..e98095e3 100644 --- a/gui/playlist.c +++ b/gui/playlist.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include enum playlist_sidebar_columns { P_SB_IMAGE, @@ -90,7 +90,7 @@ void __playlist_selection_changed(GtkTreeSelection *selection, gpointer data) p_name = __playlist_name(&iter); queue = playlist_get_queue(__playlist_type(&iter), p_name); - gui_sidebar_selected(SB_PLAYLIST, gui_queue(queue)); + gui_queue_show(gui_queue(queue)); } } diff --git a/gui/sidebar.c b/gui/sidebar.c index 2570d944..d366cce3 100644 --- a/gui/sidebar.c +++ b/gui/sidebar.c @@ -1,180 +1,23 @@ /* * Copyright 2015 (c) Anna Schumaker. */ -#include #include -#include #include -#include #include const gchar *SIDEBAR_SETTING = "gui.sidebar.pos"; -const gchar *COLLECTION_FMT = "Collection\n%d track%s"; -const gchar *HISTORY_FMT = "History\n%d track%s"; -static GtkListStore *sb_store; - -enum sidebar_columns { - SB_IMAGE, - SB_IMAGE_SZ, - SB_TEXT, - SB_QUEUE, -}; - -static void __sidebar_set_size(GtkTreeIter *iter, const gchar *name, - unsigned int size) -{ - const gchar *fmt = "%s\n%d track%s"; - gchar *text; - - text = g_strdup_printf(fmt, name, size, (size == 1) ? "" : "s"); - gtk_list_store_set(sb_store, iter, SB_TEXT, text, -1); - g_free(text); -} - -static struct gui_queue *__sidebar_get_queue(GtkTreeIter *iter) -{ - struct gui_queue *queue; - - gtk_tree_model_get(GTK_TREE_MODEL(sb_store), iter, SB_QUEUE, &queue, -1); - return queue; -} - -static bool __sidebar_find_queue(struct gui_queue *queue, GtkTreeIter *iter) -{ - gtk_tree_model_get_iter_first(GTK_TREE_MODEL(sb_store), iter); - - do { - if (__sidebar_get_queue(iter) == queue) - return true; - } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(sb_store), iter)); - - return false; -} void __sidebar_resize(GtkPaned *pane, GParamSpec *pspec, gpointer data) { settings_set(SIDEBAR_SETTING, gtk_paned_get_position(pane)); } -bool __sidebar_keypress(GtkTreeView *treeview, GdkEventKey *event, gpointer data) -{ - GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview); - GtkTreeModel *model = GTK_TREE_MODEL(sb_store); - struct gui_queue *queue; - GtkTreePath *path; - GtkTreeIter iter; - GList *rows; - - if (event->keyval != GDK_KEY_Delete) - return false; - - rows = gtk_tree_selection_get_selected_rows(selection, &model); - path = rows->data; - - if (gtk_tree_model_get_iter(model, &iter, path)) - queue = __sidebar_get_queue(&iter); - if (tempq_index(queue->gq_queue) == -1) - goto out; - - tempq_free(queue->gq_queue); - -out: - g_list_free_full(rows, (GDestroyNotify)gtk_tree_path_free); - return true; -} - -void __sidebar_selection_changed(GtkTreeSelection *selection, gpointer data) -{ - GtkTreeModel *model = GTK_TREE_MODEL(sb_store); - GtkTreeIter iter; - - if (gtk_tree_selection_get_selected(selection, &model, &iter)) { - GtkTreePath *path = gtk_tree_model_get_path(model, &iter); - - gui_sidebar_selected(SB_SIDEBAR, __sidebar_get_queue(&iter)); - gtk_tree_path_free(path); - } -} - -void __sidebar_deselect(const gchar *widget) -{ - GtkTreeView *treeview = GTK_TREE_VIEW(gui_builder_widget(widget)); - GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview); - - gtk_tree_selection_unselect_all(selection); -} - void gui_sidebar_init() { GtkPaned *pane = GTK_PANED(gui_builder_widget("o_sidebar")); - int pos; + int pos = settings_get(SIDEBAR_SETTING); - /* Set up entries in the liststore. */ - sb_store = GTK_LIST_STORE(gui_builder_object("o_sidebar_store")); - - /* Set sidebar width. */ - pos = settings_get(SIDEBAR_SETTING); if (pos > 0) gtk_paned_set_position(pane, pos); } - -gboolean gui_sidebar_on_select(GtkTreeSelection *selection, - GtkTreeModel *model, GtkTreePath *path, - gboolean selected, gpointer data) -{ - return gtk_tree_path_get_depth(path) != 1; -} - -void gui_sidebar_selected(enum sidebar_selection_t selected, - struct gui_queue *queue) -{ - if (selected != SB_PLAYLIST) - __sidebar_deselect("o_playlist_view"); - if (selected != SB_SIDEBAR) - __sidebar_deselect("o_sidebar_view"); - - gui_queue_show(queue); -} - -void gui_sidebar_add(struct gui_queue *queue) -{ - const gchar *text = "Queued Tracks\n0 tracks"; - GtkTreeIter iter, sibling; - - if (!GTK_IS_TREE_MODEL(sb_store)) - return; - - if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(sb_store), - &sibling, NULL, - tempq_index(queue->gq_queue))) - gtk_list_store_insert_before(sb_store, &iter, &sibling); - else - gtk_list_store_insert(sb_store, &iter, -1); - - gtk_list_store_set(sb_store, &iter, SB_IMAGE, "audio-x-generic", - SB_IMAGE_SZ, GTK_ICON_SIZE_BUTTON, - SB_TEXT, text, - SB_QUEUE, queue, -1); - __sidebar_set_size(&iter, queue->gq_text, queue_size(queue->gq_queue)); -} - -void gui_sidebar_remove(struct gui_queue *queue) -{ - GtkTreeIter iter; - - if (__sidebar_find_queue(queue, &iter)) - gtk_list_store_remove(sb_store, &iter); -} - -void gui_sidebar_set_size(struct gui_queue *queue) -{ - GtkTreeIter iter; - - if (!GTK_IS_TREE_MODEL(sb_store)) - return; - - if (__sidebar_find_queue(queue, &iter)) - __sidebar_set_size(&iter, queue->gq_text, - queue_size(queue->gq_queue)); -} diff --git a/gui/tempq.c b/gui/tempq.c index 89ddb62a..424e7312 100644 --- a/gui/tempq.c +++ b/gui/tempq.c @@ -9,23 +9,17 @@ static void *__tempq_init(struct queue *queue, void *data) { - struct gui_queue *gq; - - gq = gui_queue_alloc(NULL, queue, "Queued Tracks", TEMPQ_FLAGS); - gui_sidebar_add(gq); - return gq; + return gui_queue_alloc(NULL, queue, "Queued Tracks", TEMPQ_FLAGS); } static void __tempq_deinit(struct queue *queue) { - gui_sidebar_remove(gui_queue(queue)); gui_queue_free(queue); } static void __tempq_added(struct queue *queue, unsigned int pos) { gui_queue_model_add(queue, pos); - gui_sidebar_set_size(gui_queue(queue)); tempq_save(queue, Q_ENABLED); } @@ -37,14 +31,12 @@ static bool __tempq_erase(struct queue *queue, struct track *track) static void __tempq_removed(struct queue *queue, unsigned int pos) { gui_queue_model_remove(queue, pos); - gui_sidebar_set_size(gui_queue(queue)); tempq_save(queue, Q_ENABLED); } static void __tempq_cleared(struct queue *queue, unsigned int n) { gui_queue_model_clear(queue, n); - gui_sidebar_set_size(gui_queue(queue)); } struct queue_ops tempq_ops = { diff --git a/gui/view.c b/gui/view.c index 9c2c9b47..2b472aad 100644 --- a/gui/view.c +++ b/gui/view.c @@ -204,7 +204,6 @@ static void __view_delete_selection(GtkTreeSelection *selection) static void __view_process_selection(GtkTreeView *treeview, unsigned int keyval) { GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview); - unsigned int flags = 0; struct queue *queue; switch (keyval) { @@ -221,12 +220,10 @@ static void __view_process_selection(GtkTreeView *treeview, unsigned int keyval) __view_add_to_playlist, "Favorites"); break; - case GDK_KEY_r: - flags = Q_RANDOM; case GDK_KEY_q: - queue = tempq_alloc(flags); gtk_tree_selection_selected_foreach(selection, - __view_add_to_queue, queue); + __view_add_to_playlist, + "Queued Tracks"); break; case GDK_KEY_Delete: __view_delete_selection(selection); diff --git a/include/gui/sidebar.h b/include/gui/sidebar.h index 5a4dd06b..1ee813af 100644 --- a/include/gui/sidebar.h +++ b/include/gui/sidebar.h @@ -4,31 +4,8 @@ #ifndef OCARINA_GUI_SIDEBAR_H #define OCARINA_GUI_SIDEBAR_H -#include -#include - -enum sidebar_selection_t { - SB_PLAYLIST, - SB_SIDEBAR, -}; /* Called to initialize the sidebar. */ void gui_sidebar_init(); -/* Called when a row in the sidebar is selected. */ -gboolean gui_sidebar_on_select(GtkTreeSelection *, GtkTreeModel *, - GtkTreePath *path, gboolean, gpointer); - -/* Called to tell the sidebar that the selection has changed. */ -void gui_sidebar_selected(enum sidebar_selection_t, struct gui_queue *); - -/* Called to add a queue to the sidebar. */ -void gui_sidebar_add(struct gui_queue *); - -/* Called to remove a queue from the sidebar. */ -void gui_sidebar_remove(struct gui_queue *); - -/* Called to set the size of sidebar entries. */ -void gui_sidebar_set_size(struct gui_queue *); - #endif /* OCARINA_GUI_SIDEBAR_H */ diff --git a/share/ocarina/ocarina6.glade b/share/ocarina/ocarina6.glade index 30a1d348..49c42d18 100644 --- a/share/ocarina/ocarina6.glade +++ b/share/ocarina/ocarina6.glade @@ -225,18 +225,6 @@ 1000000000 10000000000 - - - - - - - - - - - - True True @@ -853,103 +841,40 @@ 1 in - + True - False + True + o_playlist_store + False + 1 + True + + + + + + - - True - False - vertical + + Image - - True - True - o_sidebar_store - False - False - 10 - True - - - - - - - - - Image - - - - 0 - 1 - - - - - - - Text - - - - 2 - - - - + + 1 - - False - True - 0 - + + 0 + + + + + + column - - True - True - o_playlist_store - False - 1 - True - - - - - - - - - Image - - - 1 - - - 0 - - - - - - - column - - - - 1 - - - - - - - True - True - 1 - + + + 1 +