2014-02-17 16:08:14 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
|
|
*/
|
2015-01-15 09:06:59 -05:00
|
|
|
#include <core/audio.h>
|
2014-06-05 10:19:22 -04:00
|
|
|
#include <core/playlist.h>
|
2014-07-27 11:24:22 -04:00
|
|
|
#include <lib/plist.h>
|
2014-06-04 13:59:15 -04:00
|
|
|
#include <gui/tabs.h>
|
2014-02-17 16:08:14 -05:00
|
|
|
|
|
|
|
|
2015-01-15 08:32:44 -05:00
|
|
|
static bool find_cur_path(Gtk::TreePath &);
|
|
|
|
|
|
|
|
|
2014-02-21 22:06:42 -05:00
|
|
|
class PlaylistTab : public Tab {
|
|
|
|
public:
|
2015-01-15 08:32:44 -05:00
|
|
|
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;
|
|
|
|
}
|
2014-02-21 22:06:42 -05:00
|
|
|
};
|
2014-02-17 16:08:14 -05:00
|
|
|
|
2015-01-15 09:06:59 -05:00
|
|
|
static Gtk::ToggleButton *o_ban;
|
|
|
|
static Gtk::ToggleButton *o_fav;
|
|
|
|
|
2014-07-27 11:52:28 -04:00
|
|
|
static PlaylistTab *p_tab;
|
|
|
|
static Gtk::TreeView *p_treeview;
|
2014-02-28 20:07:59 -05:00
|
|
|
|
2014-02-17 16:08:14 -05:00
|
|
|
|
2014-07-27 11:52:28 -04:00
|
|
|
/*
|
|
|
|
* Sidebar code
|
2014-02-17 16:08:14 -05:00
|
|
|
*/
|
2014-07-27 11:24:22 -04:00
|
|
|
static bool find_cur_path(Gtk::TreePath &path)
|
2014-02-17 16:08:14 -05:00
|
|
|
{
|
|
|
|
Gtk::TreeViewColumn *col;
|
2014-07-27 11:52:28 -04:00
|
|
|
p_treeview->get_cursor(path, col);
|
2014-07-27 11:24:22 -04:00
|
|
|
return !path.empty();
|
|
|
|
}
|
2014-02-17 16:08:14 -05:00
|
|
|
|
2014-07-27 11:39:08 -04:00
|
|
|
static void on_playlist_cursor_changed()
|
2014-07-27 11:24:22 -04:00
|
|
|
{
|
|
|
|
Gtk::TreePath path;
|
|
|
|
if (find_cur_path(path))
|
2014-07-27 11:39:08 -04:00
|
|
|
plist :: select_path(path);
|
2014-02-17 16:08:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool on_playlist_clicked(GdkEventButton *button)
|
|
|
|
{
|
|
|
|
if (button->button != 3)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-15 09:06:59 -05:00
|
|
|
|
|
|
|
static void on_ban()
|
|
|
|
{
|
|
|
|
Track *track = audio :: current_track();
|
|
|
|
if (o_ban->get_active()) {
|
|
|
|
if (!playlist :: has(track, "Banned")) {
|
|
|
|
playlist :: add(track, "Banned");
|
2015-01-16 08:21:08 -05:00
|
|
|
audio :: next();
|
2015-01-15 09:06:59 -05:00
|
|
|
}
|
|
|
|
} 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"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-27 11:52:28 -04:00
|
|
|
void init_playlist_tab()
|
|
|
|
{
|
|
|
|
plist :: init();
|
|
|
|
p_tab = new PlaylistTab;
|
|
|
|
p_treeview = lib :: get_widget<Gtk::TreeView>("plist_treeview");
|
2014-02-17 16:08:14 -05:00
|
|
|
|
2014-07-27 11:52:28 -04:00
|
|
|
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"));
|
2015-01-15 09:06:59 -05:00
|
|
|
|
|
|
|
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));
|
2014-07-27 11:52:28 -04:00
|
|
|
}
|