diff --git a/gui/gst.cpp b/gui/gst.cpp index cad81331..53c19091 100644 --- a/gui/gst.cpp +++ b/gui/gst.cpp @@ -67,7 +67,7 @@ public: set_markup(o_title, "xx-large", track->name()); o_duration->set_text(track->length_str()); - on_track_loaded(track); + plist :: track_loaded(track); } void play() diff --git a/gui/main.cpp b/gui/main.cpp index 7dcfe736..2fe7e65c 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -18,8 +18,8 @@ Gtk::Window *ocarina_init(int *argc, char ***argv) lib :: init(argc, argv, "ocarina6.glade"); - gst :: init(argc, argv); - init_playlist_tab(); + gst :: init(argc, argv); + plist :: init(); core :: init(); diff --git a/gui/playlist.cpp b/gui/playlist.cpp index e63c4bc1..55ce2145 100644 --- a/gui/playlist.cpp +++ b/gui/playlist.cpp @@ -6,23 +6,23 @@ #include -static Glib::ustring get_path(const Gtk::TreePath &); -static bool find_cur_path(Gtk::TreePath &); -static void del_path_ids(const Gtk::TreePath &, std::vector &); +static Gtk::ToggleButton *o_ban; +static Gtk::ToggleButton *o_fav; +static Gtk::TreeView *p_treeview; +static Glib::RefPtr p_list; + +static Glib::ustring current_playlist(); static class PlaylistColumns : public Gtk::TreeModelColumnRecord { public: Gtk::TreeModelColumn p_name; - - PlaylistColumns() - { - add(p_name); - } + PlaylistColumns() { add(p_name); } } p_cols; -class PlaylistTab : public Tab { + +static class PlaylistTab : public Tab { public: PlaylistTab() : Tab(playlist :: get_queue()) { @@ -39,67 +39,46 @@ public: bool on_key_press_event(const std::string &key) { - Gtk::TreePath path; + std::string cur; std::vector ids; if (key != "Delete") return Tab :: on_key_press_event(key); - if (find_cur_path(path)) { - tab_selected_ids(ids); - del_path_ids(path, ids); - } + + cur = current_playlist(); + if (cur == "") + return true; + + tab_selected_ids(ids); + for (unsigned int i = 0; i < ids.size(); i++) + playlist :: del(tags :: get_track(ids[i]), cur); return true; } -}; - -static Gtk::ToggleButton *o_ban; -static Gtk::ToggleButton *o_fav; - -static PlaylistTab *p_tab; -static Gtk::TreeView *p_treeview; -static Glib::RefPtr p_list; +} *p_tab; -/* - * Sidebar code - */ -static Glib::ustring get_path(const Gtk::TreePath &path) + +static Glib::ustring current_playlist() { - Gtk::TreeModel::Row row = *(p_list->get_iter(path)); + Gtk::TreePath path; + Gtk::TreeModel::Row row; + Gtk::TreeViewColumn *col; + + p_treeview->get_cursor(path, col); + row = *(p_list->get_iter(path)); return row[p_cols.p_name]; } -static bool find_cur_path(Gtk::TreePath &path) +static void on_cursor_changed() { - Gtk::TreeViewColumn *col; - p_treeview->get_cursor(path, col); - return !path.empty(); + playlist :: select(current_playlist()); } -static void del_path_ids(const Gtk::TreePath &path, - std::vector &ids) +static bool on_clicked(GdkEventButton *button) { - std::string name = get_path(path); - - for (unsigned int i = 0; i < ids.size(); i++) - playlist :: del(tags :: get_track(ids[i]), name); + return button->button == 3; } -static void on_playlist_cursor_changed() -{ - Gtk::TreePath path; - if (find_cur_path(path)) - playlist :: select(get_path(path)); -} - -static bool on_playlist_clicked(GdkEventButton *button) -{ - if (button->button != 3) - return false; - return true; -} - - static void on_ban() { Track *track = audio :: current_track(); @@ -121,22 +100,22 @@ static void on_favorite() playlist :: del(track, "Favorites"); } -void on_track_loaded(Track *track) + + +void plist :: track_loaded(Track *track) { o_ban->set_active(playlist :: has(track, "Banned")); o_fav->set_active(playlist :: has(track, "Favorites")); } - -void init_playlist_tab() +void plist :: init() { p_tab = new PlaylistTab; p_list = lib :: get_object("plist_list"); p_treeview = lib :: get_widget("plist_treeview"); - p_treeview->signal_cursor_changed().connect(sigc::ptr_fun(on_playlist_cursor_changed)); - p_treeview->signal_button_press_event().connect(sigc::ptr_fun(on_playlist_clicked)); - p_treeview->set_cursor(Gtk::TreePath("0")); + p_treeview->signal_cursor_changed().connect(sigc::ptr_fun(on_cursor_changed)); + p_treeview->signal_button_press_event().connect(sigc::ptr_fun(on_clicked)); o_ban = lib :: get_widget("o_ban"); o_fav = lib :: get_widget("o_favorite"); diff --git a/include/gui/ocarina.h b/include/gui/ocarina.h index c3da2651..0722d3a6 100644 --- a/include/gui/ocarina.h +++ b/include/gui/ocarina.h @@ -18,7 +18,6 @@ void connect_button(const std::string &, void (*func)()); void on_pq_created(Queue *, unsigned int); -void on_track_loaded(Track *); void post_init_queue_tabs(); @@ -32,6 +31,14 @@ namespace gst } +/* playlist.cpp */ +namespace plist +{ + void track_loaded(Track *track); + void init(); +} + + /* window.cpp */ Gtk::Window *window_init(); diff --git a/include/gui/tabs.h b/include/gui/tabs.h index dd8287ea..cc7ab66f 100644 --- a/include/gui/tabs.h +++ b/include/gui/tabs.h @@ -104,7 +104,6 @@ void cleanup_tabs(); void init_collection_tab(); void init_history_tab(); -void init_playlist_tab(); void init_queue_tabs(); #endif /* OCARINA_TABS_H */