diff --git a/gui/main.cpp b/gui/main.cpp index bc190416..45abe38b 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -12,7 +12,6 @@ Gtk::Window *ocarina_init(int *argc, char ***argv) lib :: init(argc, argv, "ocarina6.glade"); Gtk::Window *window = setup_gui(); - playlist :: select("Favorites"); post_init_tabs(); return window; } diff --git a/gui/playlist.cpp b/gui/playlist.cpp index ab8007f2..8665ddde 100644 --- a/gui/playlist.cpp +++ b/gui/playlist.cpp @@ -6,7 +6,7 @@ #include -static Glib::ustring current_playlist(); +static bool find_cur_path(Gtk::TreePath &path); /** * Playlist tab stuff @@ -37,14 +37,16 @@ PlaylistTab :: ~PlaylistTab() bool PlaylistTab :: on_key_press_event(const std::string &key) { + Gtk::TreePath path; 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++) - playlist :: del(tagdb :: lookup(ids[i]), current_playlist()); + if (find_cur_path(path)) { + tab_selected_ids(ids); + plist :: del_path_ids(path, ids); + } return true; } @@ -63,18 +65,11 @@ static bool find_cur_path(Gtk::TreePath &path) return !path.empty(); } -static Glib::ustring current_playlist() +static void on_playlist_cursor_changed() { Gtk::TreePath path; if (find_cur_path(path)) - return plist :: get_path(path); - return ""; -} - - -static void on_playlist_cursor_changed() -{ - playlist::select(current_playlist()); + plist :: select_path(path); } static bool on_playlist_clicked(GdkEventButton *button) diff --git a/include/lib/plist.h b/include/lib/plist.h index 4dfecdf8..f51b86d0 100644 --- a/include/lib/plist.h +++ b/include/lib/plist.h @@ -13,6 +13,8 @@ namespace plist void init(); Glib::ustring get_path(const Gtk::TreePath &); + void select_path(const Gtk::TreePath &); + void del_path_ids(const Gtk::TreePath &, std::vector &); } diff --git a/lib/plist.cpp b/lib/plist.cpp index 5cb3b088..d03ea498 100644 --- a/lib/plist.cpp +++ b/lib/plist.cpp @@ -1,6 +1,7 @@ /* * Copyright 2014 (c) Anna Schumaker. */ +#include #include #include @@ -30,3 +31,17 @@ Glib::ustring plist :: get_path(const Gtk::TreePath &path) Gtk::TreeModel::Row row = *(p_list->get_iter(path)); return row[p_cols.p_name]; } + +void plist :: select_path(const Gtk::TreePath &path) +{ + playlist :: select(get_path(path)); +} + +void plist :: del_path_ids(const Gtk::TreePath &path, + std::vector &ids) +{ + std::string name = plist :: get_path(path); + + for (unsigned int i = 0; i < ids.size(); i++) + playlist :: del(tagdb :: lookup(ids[i]), name); +}