ocarina/gui/playlist.cpp

119 lines
2.5 KiB
C++

/*
* Copyright 2014 (c) Anna Schumaker.
*/
#include <core/audio.h>
#include <core/playlist.h>
#include <lib/plist.h>
#include <gui/tabs.h>
static bool find_cur_path(Gtk::TreePath &);
class PlaylistTab : public Tab {
public:
PlaylistTab() : Tab(playlist :: get_queue())
{
tab_search = lib :: get_widget<Gtk::SearchEntry>("o_playlist_entry");
tab_treeview = lib :: get_widget<Gtk::TreeView>("o_playlist_pq_treeview");
tab_widget = lib :: get_widget<Gtk::Widget>("o_playlist_page");
tab_finish_init();
}
~PlaylistTab()
{
tab_unmap();
}
bool on_key_press_event(const std::string &key)
{
Gtk::TreePath path;
std::vector<unsigned int> ids;
if (key != "Delete")
return Tab :: on_key_press_event(key);
if (find_cur_path(path)) {
tab_selected_ids(ids);
plist :: del_path_ids(path, ids);
}
return true;
}
};
static Gtk::ToggleButton *o_ban;
static Gtk::ToggleButton *o_fav;
static PlaylistTab *p_tab;
static Gtk::TreeView *p_treeview;
/*
* Sidebar code
*/
static bool find_cur_path(Gtk::TreePath &path)
{
Gtk::TreeViewColumn *col;
p_treeview->get_cursor(path, col);
return !path.empty();
}
static void on_playlist_cursor_changed()
{
Gtk::TreePath path;
if (find_cur_path(path))
plist :: select_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();
if (o_ban->get_active()) {
if (!playlist :: has(track, "Banned")) {
playlist :: add(track, "Banned");
audio :: next();
}
} else
playlist :: del(track, "Banned");
}
static void on_favorite()
{
Track *track = audio :: current_track();
if (o_fav->get_active())
playlist :: add(track, "Favorites");
else
playlist :: del(track, "Favorites");
}
void on_track_loaded(Track *track)
{
o_ban->set_active(playlist :: has(track, "Banned"));
o_fav->set_active(playlist :: has(track, "Favorites"));
}
void init_playlist_tab()
{
plist :: init();
p_tab = new PlaylistTab;
p_treeview = lib :: get_widget<Gtk::TreeView>("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"));
o_ban = lib :: get_widget<Gtk::ToggleButton>("o_ban");
o_fav = lib :: get_widget<Gtk::ToggleButton>("o_favorite");
o_ban->signal_toggled().connect(sigc::ptr_fun(on_ban));
o_fav->signal_toggled().connect(sigc::ptr_fun(on_favorite));
}