From a529d569f6fcf11a06f665507f0ff64b5d9eb534 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sat, 1 Mar 2014 19:33:41 -0500 Subject: [PATCH] gui: Implement add to {favorites, banned} menu items Signed-off-by: Anna Schumaker --- gui/tabs.cpp | 66 ++++++++++++++++++++++++++++++- include/tabs.h | 10 +++-- share/ocarina/ocarina6.glade | 75 ++++++++++++++++++++++++++++++------ 3 files changed, 134 insertions(+), 17 deletions(-) diff --git a/gui/tabs.cpp b/gui/tabs.cpp index 872079b0..c26fe20d 100644 --- a/gui/tabs.cpp +++ b/gui/tabs.cpp @@ -51,6 +51,8 @@ void Tab :: tab_finish_init() &Tab :: on_row_activated)); tab_treeview->signal_key_press_event().connect(sigc::mem_fun(*this, &Tab :: on_key_pressed)); + tab_treeview->signal_button_press_event().connect(sigc::mem_fun(*this, + &Tab :: on_button_pressed), false); std::vector columns = tab_treeview->get_columns(); for (unsigned int i = 0; i < columns.size(); i++) { @@ -150,6 +152,7 @@ void Tab :: tab_selected_ids(std::vector &ids) path = tab_filter->convert_path_to_child_path(rows[i]); ids.push_back(tab_model->path_to_id(path)); } + sel->unselect_all(); } void Tab :: tab_queue_add(Playqueue *pq) @@ -181,17 +184,27 @@ bool Tab :: tab_add_to_queue(unsigned int n) return true; } -bool Tab :: tab_favorite_selected() +bool Tab :: tab_add_to_playlist(const std::string &playlist) { std::vector ids; tab_selected_ids(ids); for (unsigned int i = 0; i < ids.size(); i++) - playlist :: add("Favorites", ids[i]); + playlist :: add(playlist, ids[i]); return true; } +bool Tab :: tab_favorite_selected() +{ + return tab_add_to_playlist("Favorites"); +} + +void Tab :: tab_ban_selected() +{ + tab_add_to_playlist("Banned"); +} + /** @@ -235,6 +248,10 @@ bool Tab :: on_key_press_event(const std::string &key) return true; } +void Tab :: on_show_rc_menu() +{ +} + /** @@ -285,6 +302,20 @@ void Tab :: on_column_clicked(unsigned int col) sigc::mem_fun(*this, &Tab::tab_dec_sort_count), 2); } +bool Tab :: on_button_pressed(GdkEventButton *button) +{ + if (button->button != 3) + return false; + + Gtk::TreeModel::Path path; + if (tab_treeview->get_path_at_pos(button->x, button->y, path)) + tab_treeview->get_selection()->select(path); + + on_show_rc_menu(); + get_widget("o_rc_menu")->popup(button->button, button->time); + return true; +} + /** @@ -345,6 +376,16 @@ static Tab *find_tab(int num) return NULL; } +static Tab *cur_tab() +{ + std::map::iterator it; + for (it = queue_mapping.begin(); it != queue_mapping.end(); it++) { + if (it->second->tab_is_cur()) + return it->second; + } + return NULL; +} + static void on_track_added(Playqueue *pq, unsigned int row) { Tab *tab = find_tab(pq); @@ -384,6 +425,20 @@ void tab_focus_search() tab->tab_focus_search(); } +static void on_add_to_favs() +{ + Tab *tab = cur_tab(); + if (tab) + tab->tab_favorite_selected(); +} + +static void on_add_to_banned() +{ + Tab *tab = cur_tab(); + if (tab) + tab->tab_ban_selected(); +} + void init_tabs() { struct Callbacks *cb = get_callbacks(); @@ -395,6 +450,13 @@ void init_tabs() struct Gtk::Notebook *notebook = get_widget("o_notebook"); notebook->signal_switch_page().connect(sigc::ptr_fun(on_switch_page)); + /* Menu signals */ + get_widget("o_rc_menu")->show_all(); + get_widget("o_add_to_favorites")->signal_activate().connect( + sigc::ptr_fun(on_add_to_favs)); + get_widget("o_add_to_banned")->signal_activate().connect( + sigc::ptr_fun(on_add_to_banned)); + /* Initialize other tabs */ init_collection_tab(); init_history_tab(); diff --git a/include/tabs.h b/include/tabs.h index 41b45c7e..73bba0df 100644 --- a/include/tabs.h +++ b/include/tabs.h @@ -41,7 +41,6 @@ protected: void tab_init_random(); void tab_init_repeat(); void tab_toggle_button(Gtk::ToggleButton *, playqueue_flags); - bool tab_is_cur(); void tab_dec_sort_count(); virtual void tab_set_size(); void tab_unmap(); @@ -55,6 +54,7 @@ public: */ void tab_finish_init(); int tab_page_num(); + bool tab_is_cur(); void tab_runtime_changed(); void tab_display_sorting(); void tab_focus_search(); @@ -62,7 +62,9 @@ public: void tab_queue_add(Playqueue *); bool tab_queue_selected(bool); bool tab_add_to_queue(unsigned int); + bool tab_add_to_playlist(const std::string &); bool tab_favorite_selected(); + void tab_ban_selected(); /** * internal callback functions that can be overridden if necessary @@ -72,7 +74,7 @@ public: virtual void on_track_deleted(unsigned int); virtual void on_track_changed(unsigned int); virtual bool on_key_press_event(const std::string &); - virtual void on_column_clicked(unsigned int); + virtual void on_show_rc_menu(); /** * GTK-MM callback functions @@ -80,7 +82,9 @@ public: void on_random_toggled(); void on_repeat_toggled(); void on_row_activated(const Gtk::TreePath &, Gtk::TreeViewColumn *); - bool on_key_pressed(GdkEventKey *key); + bool on_key_pressed(GdkEventKey *); + void on_column_clicked(unsigned int); + bool on_button_pressed(GdkEventButton *); /* Filtering functions */ bool on_filter_visible(const Gtk::TreeIter &); diff --git a/share/ocarina/ocarina6.glade b/share/ocarina/ocarina6.glade index ba1f61a9..84e81fc6 100644 --- a/share/ocarina/ocarina6.glade +++ b/share/ocarina/ocarina6.glade @@ -19,12 +19,30 @@ gtk-add 1 + + True + False + emblem-documents + 1 + + + True + False + face-sad + 1 + + + True + False + emblem-favorite + 1 + True False - New Playqueue + New Queue True False image12 @@ -33,7 +51,7 @@ - Add to Playqueue + Add to Queue True False image13 @@ -46,7 +64,7 @@ True False - Playqueue 0 + Queue 0 True @@ -54,7 +72,7 @@ True False - Playqueue 1 + Queue 1 True @@ -62,7 +80,7 @@ True False - Playqueue 2 + Queue 2 True @@ -70,7 +88,7 @@ True False - Playqueue 3 + Queue 3 True @@ -78,7 +96,7 @@ True False - Playqueue 4 + Queue 4 True @@ -86,7 +104,7 @@ True False - Playqueue 5 + Queue 5 True @@ -94,7 +112,7 @@ True False - Playqueue 6 + Queue 6 True @@ -102,7 +120,7 @@ True False - Playqueue 7 + Queue 7 True @@ -110,7 +128,7 @@ True False - Playqueue 8 + Queue 8 True @@ -118,7 +136,7 @@ True False - Playqueue 9 + Queue 9 True @@ -126,6 +144,39 @@ + + + Add to Playlist + True + False + image18 + False + + + True + False + + + Favorites + True + False + image20 + False + + + + + Banned + True + False + image19 + False + + + + + +