diff --git a/gui/collection_tab.cpp b/gui/collection_tab.cpp index b9f9e2c3..c3380b6c 100644 --- a/gui/collection_tab.cpp +++ b/gui/collection_tab.cpp @@ -34,20 +34,6 @@ public: { tab_unmap(); } - - bool on_key_press_event(const std::string &key) - { - std::vector ids; - - if (key != "Delete") - return Tab :: on_key_press_event(key); - - tab_selected_ids(ids); - for (unsigned int i = 0; i < ids.size(); i++) - collection_ban(track_get(ids[i])); - - return true; - } }; @@ -67,7 +53,7 @@ static void collection_added(struct queue *queue, unsigned int pos) static bool collection_erase(struct queue *queue, struct track *track) { - return false; + return playlist_add(PL_HIDDEN, track); } static void collection_removed(struct queue *queue, unsigned int pos) diff --git a/gui/playlist_tab.cpp b/gui/playlist_tab.cpp index d0d60675..d93af405 100644 --- a/gui/playlist_tab.cpp +++ b/gui/playlist_tab.cpp @@ -41,25 +41,6 @@ public: { tab_unmap(); } - - bool on_key_press_event(const std::string &key) - { - enum playlist_t cur; - std::vector ids; - - if (key != "Delete") - return Tab :: on_key_press_event(key); - - cur = gui_playlist_cur(); - - tab_selected_ids(ids); - for (unsigned int i = 0; i < ids.size(); i++) - if (cur == PL_HIDDEN) - collection_unban(track_get(ids[i])); - else - playlist_remove(cur, track_get(ids[i])); - return true; - } } *p_tab; @@ -97,6 +78,11 @@ static void playlist_added(struct queue *queue, unsigned int pos) static bool playlist_erase(struct queue *queue, struct track *track) { + /* collection_unban() and playlist_remove() handle queue changes */ + if (gui_playlist_cur() == PL_HIDDEN) + collection_unban(track); + else + playlist_remove(gui_playlist_cur(), track); return false; } diff --git a/gui/queue_tab.cpp b/gui/queue_tab.cpp index 454b1a5b..8765a216 100644 --- a/gui/queue_tab.cpp +++ b/gui/queue_tab.cpp @@ -123,31 +123,6 @@ void QueueTab :: on_track_removed(unsigned int row) * */ -bool QueueTab :: on_key_press_event(const std::string &key) -{ - std::vector ids; - - if (key != "Delete") - return Tab :: on_key_press_event(key); - - /* - * tab_selected_ids() returns track_ids and not - * playlist_ids,so we can't use it here =( - */ - Glib::RefPtr sel = tab_window->q_treeview->get_selection(); - std::vector rows = sel->get_selected_rows(); - GtkTreePath *path; - - for (unsigned int i = 0; i < rows.size(); i++) { - path = rows[i].gobj(); - ids.push_back(gtk_tree_path_get_indices(path)[0]); - } - - for (unsigned int i = ids.size(); i > 0; i--) - queue_remove(tab_pq, ids[i-1]); - return true; -} - void QueueTab :: queue_set_number(unsigned int num) { gchar *text = g_strdup_printf("%u. ", num); diff --git a/gui/sidebar.c b/gui/sidebar.c index 9b86ee23..e7c853ba 100644 --- a/gui/sidebar.c +++ b/gui/sidebar.c @@ -172,6 +172,9 @@ 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; + gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(sb_store), &sibling, NULL, tempq_index(queue->gq_queue)); diff --git a/gui/tabs.cpp b/gui/tabs.cpp index ba5be371..dd697c71 100644 --- a/gui/tabs.cpp +++ b/gui/tabs.cpp @@ -26,8 +26,12 @@ static compare_t sort_fields[] = { static void *tempq_init(struct queue *queue) { - return gui_queue_alloc(queue, "Queued Tracks", + struct gui_queue *gq = gui_queue_alloc(queue, "Queued Tracks", GQ_CAN_RANDOM | GQ_CAN_REPEAT | GQ_CAN_DISABLE); + queue->q_private = gq; + on_pq_created(queue, tempq_index(queue)); + gui_sidebar_add(gq); + return gq; } static void tempq_added(struct queue *queue, unsigned int pos) @@ -42,7 +46,7 @@ static void tempq_added(struct queue *queue, unsigned int pos) static bool tempq_erase(struct queue *queue, struct track *track) { - return false; + return true; } static void tempq_removed(struct queue *queue, unsigned int pos) @@ -80,8 +84,6 @@ Tab :: Tab(queue *pq) tab_builder->get_widget_derived("QueueWindow", tab_window); tab_window->init(tab_pq); - tab_window->q_treeview->signal_key_press_event().connect(sigc::mem_fun(*this, - &Tab :: on_key_pressed)); tab_window->q_treeview->signal_button_press_event().connect(sigc::mem_fun(*this, &Tab :: on_button_pressed), false); @@ -234,19 +236,6 @@ void Tab :: tab_ban_selected() * */ -bool Tab :: on_key_press_event(const std::string &key) -{ - if (key >= "0" && key <= "9") - return tab_add_to_queue(atoi(key.c_str())); - else if (key == "f") - return tab_favorite_selected(); - else if (key == "q" || key == "r") - return tab_queue_selected(key == "r"); - else - return false; - return true; -} - void Tab :: on_show_rc_menu() { std::string item; @@ -281,18 +270,6 @@ void Tab :: on_show_rc_menu() * */ -bool Tab :: on_key_pressed(GdkEventKey *event) -{ - std::string key = gdk_keyval_name(event->keyval); - - if (key.size() >= 3) { - if (key.substr(0, 3) == "KP_") - key = key.substr(3); - } - - return on_key_press_event(key); -} - void Tab :: on_column_clicked(unsigned int col) { if (tab_sorting_count == 0) { diff --git a/gui/view.c b/gui/view.c index 76eeeb8e..8f54dffa 100644 --- a/gui/view.c +++ b/gui/view.c @@ -2,6 +2,8 @@ * Copyright 2016 (c) Anna Schumaker. */ #include +#include +#include #include #include #include @@ -46,6 +48,15 @@ static struct track *__view_filter_get_track(GtkTreePath *orig) return track; } +static unsigned int __view_filter_get_index(GtkTreePath *orig) +{ + GtkTreePath *real = __view_filter_convert_path(orig); + unsigned int ret = gtk_tree_path_get_indices(real)[0]; + + gtk_tree_path_free(real); + return ret; +} + void __view_row_activated(GtkTreeView *treeview, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data) { @@ -68,6 +79,65 @@ void __view_column_resized(GtkTreeViewColumn *col, GParamSpec *pspec, } } +static void __view_add_to_queue(GtkTreeModel *model, GtkTreePath *path, + GtkTreeIter *iter, gpointer data) +{ + queue_add(data, __view_filter_get_track(path)); +} + +static void __view_add_to_playlist(GtkTreeModel *model, GtkTreePath *path, + GtkTreeIter *iter, gpointer data) +{ + playlist_add(GPOINTER_TO_UINT(data), __view_filter_get_track(path)); +} + +static void __view_delete_selection(GtkTreeSelection *selection) +{ + struct queue * queue = __view_filter_get_model()->gqm_queue; + GList *rows = gtk_tree_selection_get_selected_rows(selection, NULL); + GList *cur = g_list_reverse(rows); + + while (cur) { + queue_erase(queue, __view_filter_get_index(cur->data)); + cur = g_list_next(cur); + } + + g_list_free_full(rows, (GDestroyNotify) gtk_tree_path_free); +} + +void __view_keypress(GtkTreeView *treeview, GdkEventKey *event, gpointer data) +{ + GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview); + unsigned int flags = 0; + struct queue *queue; + + switch (event->keyval) { + case GDK_KEY_KP_0 ... GDK_KEY_KP_9: + event->keyval = (event->keyval - GDK_KEY_KP_0) + GDK_KEY_0; + case GDK_KEY_0 ... GDK_KEY_9: + queue = tempq_get(event->keyval - GDK_KEY_0); + if (queue) + gtk_tree_selection_selected_foreach(selection, + __view_add_to_queue, queue); + break; + case GDK_KEY_f: + gtk_tree_selection_selected_foreach(selection, + __view_add_to_playlist, + GUINT_TO_POINTER(PL_FAVORITED)); + 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); + break; + case GDK_KEY_Delete: + __view_delete_selection(selection); + break; + } +} + void gui_view_init() { GtkTreeViewColumn *col; diff --git a/include/gui/tabs.h b/include/gui/tabs.h index 5303861f..8180367b 100644 --- a/include/gui/tabs.h +++ b/include/gui/tabs.h @@ -60,14 +60,11 @@ public: /** * internal callback functions that can be overridden if necessary */ - virtual bool on_key_press_event(const std::string &); virtual void on_show_rc_menu(); /** * GTK-MM callback functions */ - void on_repeat_toggled(); - bool on_key_pressed(GdkEventKey *); void on_column_clicked(unsigned int); bool on_button_pressed(GdkEventButton *); }; diff --git a/share/ocarina/ocarina6.glade b/share/ocarina/ocarina6.glade index d1e4cc8c..ffb86059 100644 --- a/share/ocarina/ocarina6.glade +++ b/share/ocarina/ocarina6.glade @@ -1110,6 +1110,7 @@ False True 9 +