ocarina/gui/playlist.cpp

105 lines
2.1 KiB
C++

/*
* Copyright 2014 (c) Anna Schumaker.
*/
#include <core/playlist.h>
#include <gui/tabs.h>
static const std::string current_playlist();
/**
* Playlist tab stuff
*/
class PlaylistTab : public Tab {
public:
PlaylistTab();
~PlaylistTab();
bool on_key_press_event(const std::string &);
};
PlaylistTab :: PlaylistTab()
: Tab(playlist :: get_queue())
{
tab_search = get_widget<Gtk::SearchEntry>("o_playlist_entry");
tab_treeview = get_widget<Gtk::TreeView>("o_playlist_pq_treeview");
tab_widget = get_widget<Gtk::Widget>("o_playlist_page");
tab_finish_init();
}
PlaylistTab :: ~PlaylistTab()
{
tab_unmap();
}
bool PlaylistTab :: on_key_press_event(const std::string &key)
{
std::vector<unsigned int> 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());
return true;
}
/**
* Playlist "sidebar" stuff
*/
static class PlaylistColumns : public Gtk::TreeModelColumnRecord {
public:
PlaylistColumns()
{ add(plist_col_name); }
Gtk::TreeModelColumn<std::string> plist_col_name;
} plist_cols;
static Glib::RefPtr<Gtk::ListStore> playlist_ls;
static Gtk::TreeView *playlist_tv;
static const std::string current_playlist()
{
Gtk::TreePath path;
Gtk::TreeViewColumn *col;
playlist_tv->get_cursor(path, col);
Gtk::TreeModel::Row row = *(playlist_ls->get_iter(path));
std::string res = row[plist_cols.plist_col_name];
return res;
}
static void on_playlist_cursor_changed()
{
playlist::select(current_playlist());
}
static bool on_playlist_clicked(GdkEventButton *button)
{
if (button->button != 3)
return false;
return true;
}
static PlaylistTab *playlist_tab;
void init_playlist_tab()
{
playlist_tab = new PlaylistTab;
playlist_ls = get_object<Gtk::ListStore>("o_playlists");
playlist_tv = get_widget<Gtk::TreeView>("o_playlist_treeview");
playlist_tv->signal_cursor_changed().connect(sigc::ptr_fun(on_playlist_cursor_changed));
playlist_tv->signal_button_press_event().connect(sigc::ptr_fun(on_playlist_clicked));
playlist_tv->set_cursor(Gtk::TreePath("0"));
}