2014-01-18 14:43:24 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
|
|
*/
|
2014-01-19 11:03:53 -05:00
|
|
|
#include <callback.h>
|
2014-02-23 17:04:39 -05:00
|
|
|
#include <deck.h>
|
2014-02-01 17:30:07 -05:00
|
|
|
#include <filter.h>
|
2014-02-17 19:15:02 -05:00
|
|
|
#include <tabs.h>
|
2014-01-18 14:43:24 -05:00
|
|
|
|
|
|
|
#include <map>
|
2014-01-19 10:34:26 -05:00
|
|
|
#include <sstream>
|
2014-02-21 22:06:42 -05:00
|
|
|
|
|
|
|
|
|
|
|
static std::map<Playqueue *, Tab *> queue_mapping;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2014-02-23 19:39:48 -05:00
|
|
|
*
|
2014-02-21 22:06:42 -05:00
|
|
|
* Tab class basics
|
2014-02-23 19:39:48 -05:00
|
|
|
*
|
2014-02-21 22:06:42 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
Tab :: Tab(Playqueue *pq)
|
|
|
|
: tab_pq(pq), tab_size(NULL)
|
|
|
|
{
|
|
|
|
tab_model = Glib::RefPtr<PlayqueueModel>(new PlayqueueModel(tab_pq));
|
|
|
|
queue_mapping[tab_pq] = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
Tab :: ~Tab() {}
|
|
|
|
|
|
|
|
void Tab :: tab_finish_init()
|
|
|
|
{
|
|
|
|
tab_filter = Gtk::TreeModelFilter::create(tab_model);
|
|
|
|
tab_filter->set_visible_func(sigc::mem_fun(*this,
|
|
|
|
&Tab::on_filter_visible));
|
|
|
|
tab_search->signal_key_release_event().connect(sigc::mem_fun(*this,
|
|
|
|
&Tab::on_entry_key_released));
|
|
|
|
tab_search->signal_changed().connect(sigc::mem_fun(*this,
|
|
|
|
&Tab::on_entry_changed));
|
|
|
|
|
|
|
|
tab_treeview->set_model(tab_filter);
|
2014-02-23 13:21:39 -05:00
|
|
|
tab_treeview->signal_row_activated().connect(sigc::mem_fun(*this,
|
|
|
|
&Tab :: on_row_activated));
|
2014-02-23 17:04:39 -05:00
|
|
|
tab_treeview->signal_key_press_event().connect(sigc::mem_fun(*this,
|
|
|
|
&Tab :: on_key_pressed));
|
2014-02-21 22:06:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2014-02-23 19:39:48 -05:00
|
|
|
*
|
2014-02-23 13:04:31 -05:00
|
|
|
* Tab internal helper functions
|
2014-02-23 19:39:48 -05:00
|
|
|
*
|
2014-02-21 22:06:42 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
void Tab :: tab_init_random()
|
|
|
|
{
|
|
|
|
tab_random->set_active(tab_pq->get_flags() & PQ_RANDOM);
|
|
|
|
tab_random->signal_toggled().connect(sigc::mem_fun(*this,
|
|
|
|
&Tab::on_random_toggled));
|
|
|
|
}
|
|
|
|
|
2014-02-23 13:04:31 -05:00
|
|
|
int Tab :: tab_page_num()
|
|
|
|
{
|
|
|
|
Gtk::Notebook *notebook = get_widget<Gtk::Notebook>("o_notebook");
|
|
|
|
return notebook->page_num(*tab_widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Tab :: tab_is_cur()
|
|
|
|
{
|
|
|
|
Gtk::Notebook *notebook = get_widget<Gtk::Notebook>("o_notebook");
|
|
|
|
return notebook->page_num(*tab_widget) == notebook->get_current_page();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Tab :: tab_runtime_changed()
|
|
|
|
{
|
|
|
|
if (tab_is_cur())
|
|
|
|
get_widget<Gtk::Label>("o_queue_time")->set_text(tab_pq->get_length_str());
|
|
|
|
}
|
|
|
|
|
2014-02-21 22:06:42 -05:00
|
|
|
void Tab :: tab_set_size()
|
|
|
|
{
|
|
|
|
if (tab_size) {
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << tab_pq->size();
|
|
|
|
tab_size->set_text(ss.str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Tab :: tab_unmap()
|
|
|
|
{
|
|
|
|
queue_mapping.erase(tab_pq);
|
|
|
|
}
|
|
|
|
|
2014-02-23 15:27:19 -05:00
|
|
|
void Tab :: tab_focus_search()
|
|
|
|
{
|
|
|
|
tab_search->grab_focus();
|
|
|
|
}
|
|
|
|
|
2014-02-23 17:04:39 -05:00
|
|
|
bool Tab :: tab_queue_selected(bool random)
|
|
|
|
{
|
|
|
|
Glib::RefPtr<Gtk::TreeSelection> sel = tab_treeview->get_selection();
|
|
|
|
if (sel->count_selected_rows() == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (deck :: size() >= 10)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
Playqueue *pq = deck :: create(random);
|
|
|
|
std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
|
|
|
|
for (unsigned int i = 0; i != rows.size(); i++) {
|
|
|
|
Gtk::TreeModel::Path path = tab_filter->convert_path_to_child_path(rows[i]);
|
|
|
|
unsigned int track_id = tab_model->path_to_id(path);
|
|
|
|
pq->add(track_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
sel->unselect_all();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-21 22:06:42 -05:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2014-02-23 19:39:48 -05:00
|
|
|
*
|
2014-02-23 13:04:31 -05:00
|
|
|
* Tab callback functions
|
2014-02-23 19:39:48 -05:00
|
|
|
*
|
2014-02-21 22:06:42 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
void Tab :: on_post_init() {}
|
|
|
|
|
|
|
|
void Tab :: on_track_added(unsigned int row)
|
|
|
|
{
|
|
|
|
tab_model->on_row_inserted(row);
|
|
|
|
tab_set_size();
|
2014-02-23 13:04:31 -05:00
|
|
|
tab_runtime_changed();
|
2014-02-21 22:06:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void Tab :: on_track_deleted(unsigned int row)
|
|
|
|
{
|
|
|
|
tab_model->on_row_deleted(row);
|
|
|
|
tab_set_size();
|
2014-02-23 13:04:31 -05:00
|
|
|
tab_runtime_changed();
|
2014-02-21 22:06:42 -05:00
|
|
|
}
|
|
|
|
|
2014-02-23 15:19:00 -05:00
|
|
|
void Tab :: on_track_changed(unsigned int row)
|
|
|
|
{
|
|
|
|
tab_model->on_row_changed(row);
|
|
|
|
tab_runtime_changed();
|
|
|
|
}
|
|
|
|
|
2014-02-23 17:04:39 -05:00
|
|
|
bool Tab :: on_key_press_event(const std::string &key)
|
|
|
|
{
|
|
|
|
if (key == "q" || key == "r")
|
|
|
|
return tab_queue_selected(key == "r");
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-21 22:06:42 -05:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2014-02-23 19:39:48 -05:00
|
|
|
*
|
2014-02-21 22:06:42 -05:00
|
|
|
* GTK-MM callback functions
|
2014-02-23 19:39:48 -05:00
|
|
|
*
|
2014-02-21 22:06:42 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
void Tab :: on_random_toggled()
|
|
|
|
{
|
|
|
|
if (tab_random->get_active())
|
|
|
|
tab_pq->set_flag(PQ_RANDOM);
|
|
|
|
else
|
|
|
|
tab_pq->unset_flag(PQ_RANDOM);
|
|
|
|
}
|
|
|
|
|
2014-02-23 13:21:39 -05:00
|
|
|
void Tab :: on_row_activated(const Gtk::TreePath &path, Gtk::TreeViewColumn *col)
|
|
|
|
{
|
|
|
|
Gtk::TreePath model_path = tab_filter->convert_path_to_child_path(path);
|
|
|
|
tab_model->on_path_selected(model_path);
|
|
|
|
}
|
|
|
|
|
2014-02-23 17:04:39 -05:00
|
|
|
bool Tab :: on_key_pressed(GdkEventKey *event)
|
|
|
|
{
|
|
|
|
std::string key = gdk_keyval_name(event->keyval);
|
|
|
|
|
|
|
|
if (key.size() >= 3) {
|
|
|
|
if (key.substr(0, 3) == "KP_")
|
|
|
|
key = key.substr(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
return on_key_press_event(key);
|
|
|
|
}
|
|
|
|
|
2014-02-21 22:06:42 -05:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2014-02-23 19:39:48 -05:00
|
|
|
*
|
2014-02-21 22:06:42 -05:00
|
|
|
* Tab filtering functions
|
2014-02-23 19:39:48 -05:00
|
|
|
*
|
2014-02-21 22:06:42 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
bool Tab :: on_filter_visible(const Gtk::TreeIter &iter)
|
|
|
|
{
|
|
|
|
unsigned int pq_id;
|
|
|
|
std::set<unsigned int>::iterator it;
|
|
|
|
|
|
|
|
if (tab_search->get_text_length() == 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
pq_id = tab_model->iter_to_id(iter);
|
|
|
|
it = visible_ids.find(tab_pq->operator[](pq_id));
|
|
|
|
return it != visible_ids.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Tab :: on_entry_key_released(GdkEventKey *event)
|
|
|
|
{
|
|
|
|
std::string key = gdk_keyval_name(event->keyval);
|
|
|
|
return key == "space";
|
|
|
|
}
|
|
|
|
|
|
|
|
void Tab :: on_entry_changed()
|
|
|
|
{
|
|
|
|
filter :: search(tab_search->get_text(), visible_ids);
|
|
|
|
tab_filter->refilter();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2014-02-23 19:39:48 -05:00
|
|
|
*
|
2014-02-21 22:06:42 -05:00
|
|
|
* Global functions
|
2014-02-23 19:39:48 -05:00
|
|
|
*
|
2014-02-21 22:06:42 -05:00
|
|
|
*/
|
|
|
|
|
2014-02-23 19:39:48 -05:00
|
|
|
Tab *find_tab(Playqueue *pq)
|
2014-02-21 22:06:42 -05:00
|
|
|
{
|
|
|
|
std::map<Playqueue *, Tab *>::iterator it;
|
|
|
|
it = queue_mapping.find(pq);
|
|
|
|
if (it != queue_mapping.end())
|
|
|
|
return it->second;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-02-23 15:27:19 -05:00
|
|
|
static Tab *find_tab(int num)
|
|
|
|
{
|
|
|
|
std::map<Playqueue *, Tab *>::iterator it;
|
|
|
|
for (it = queue_mapping.begin(); it != queue_mapping.end(); it++) {
|
|
|
|
if (it->second->tab_page_num() == num)
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void on_track_added(Playqueue *pq, unsigned int row)
|
2014-02-21 22:06:42 -05:00
|
|
|
{
|
|
|
|
Tab *tab = find_tab(pq);
|
|
|
|
if (tab)
|
|
|
|
tab->on_track_added(row);
|
|
|
|
}
|
|
|
|
|
2014-02-23 15:27:19 -05:00
|
|
|
static void on_track_deleted(Playqueue *pq, unsigned int row)
|
2014-02-21 22:06:42 -05:00
|
|
|
{
|
|
|
|
Tab *tab = find_tab(pq);
|
|
|
|
if (tab)
|
|
|
|
tab->on_track_deleted(row);
|
|
|
|
}
|
|
|
|
|
2014-02-23 15:27:19 -05:00
|
|
|
static void on_track_changed(Playqueue *pq, unsigned int row)
|
2014-02-23 15:19:00 -05:00
|
|
|
{
|
|
|
|
Tab *tab = find_tab(pq);
|
|
|
|
if (tab)
|
|
|
|
tab->on_track_changed(row);
|
|
|
|
}
|
|
|
|
|
2014-02-23 15:27:19 -05:00
|
|
|
static void on_switch_page(Gtk::Widget *page, int num)
|
2014-02-23 13:04:31 -05:00
|
|
|
{
|
2014-02-23 15:27:19 -05:00
|
|
|
Tab *tab = find_tab(num);
|
|
|
|
if (tab)
|
|
|
|
tab->tab_runtime_changed();
|
|
|
|
else
|
|
|
|
get_widget<Gtk::Label>("o_queue_time")->set_text("");
|
|
|
|
}
|
2014-02-23 13:04:31 -05:00
|
|
|
|
2014-02-23 15:27:19 -05:00
|
|
|
void tab_focus_search()
|
|
|
|
{
|
|
|
|
int page = get_widget<Gtk::Notebook>("o_notebook")->get_current_page();
|
|
|
|
Tab *tab = find_tab(page);
|
|
|
|
if (tab)
|
|
|
|
tab->tab_focus_search();
|
2014-02-23 13:04:31 -05:00
|
|
|
}
|
|
|
|
|
2014-02-21 22:06:42 -05:00
|
|
|
void init_tabs()
|
|
|
|
{
|
|
|
|
struct Callbacks *cb = get_callbacks();
|
2014-02-23 15:19:00 -05:00
|
|
|
cb->on_queue_track_add = on_track_added;
|
|
|
|
cb->on_queue_track_del = on_track_deleted;
|
|
|
|
cb->on_queue_track_changed = on_track_changed;
|
2014-02-21 22:06:42 -05:00
|
|
|
|
2014-02-23 13:04:31 -05:00
|
|
|
/* Notebook signals */
|
|
|
|
struct Gtk::Notebook *notebook = get_widget<Gtk::Notebook>("o_notebook");
|
|
|
|
notebook->signal_switch_page().connect(sigc::ptr_fun(on_switch_page));
|
|
|
|
|
2014-02-21 22:06:42 -05:00
|
|
|
/* Initialize other tabs */
|
|
|
|
init_collection_tab();
|
|
|
|
init_history_tab();
|
|
|
|
init_playlist_tab();
|
2014-02-23 17:04:39 -05:00
|
|
|
init_queue_tabs();
|
2014-02-21 22:06:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void post_init_tabs()
|
|
|
|
{
|
|
|
|
std::map<Playqueue *, Tab *>::iterator it;
|
|
|
|
for (it = queue_mapping.begin(); it != queue_mapping.end(); it++)
|
|
|
|
it->second->on_post_init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cleanup_tabs()
|
|
|
|
{
|
|
|
|
while (queue_mapping.size() > 0)
|
|
|
|
delete queue_mapping.begin()->second;
|
|
|
|
}
|
|
|
|
|
2014-01-18 14:43:24 -05:00
|
|
|
|
2014-02-17 19:15:02 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Mostly legacy code ....
|
|
|
|
*/
|
|
|
|
|
2014-02-21 22:06:42 -05:00
|
|
|
/*class OcarinaPage;
|
2014-01-24 20:01:19 -05:00
|
|
|
static std::map<Playqueue *, OcarinaPage *> tab_map;
|
2014-02-17 19:15:02 -05:00
|
|
|
static std::list<TabType *> tab_types;
|
2014-01-26 13:45:59 -05:00
|
|
|
static unsigned int sort_timeout_count = 0;
|
2014-01-18 14:43:24 -05:00
|
|
|
|
2014-02-02 14:06:27 -05:00
|
|
|
|
2014-01-19 15:19:24 -05:00
|
|
|
static class QueueColumns : public Gtk::TreeModelColumnRecord {
|
|
|
|
public:
|
|
|
|
QueueColumns()
|
|
|
|
{ add(q_col_track); add(q_col_title); add(q_col_length);
|
|
|
|
add(q_col_artist); add(q_col_album); add(q_col_year);
|
2014-01-29 22:23:07 -05:00
|
|
|
add(q_col_genre); add(q_col_count); add(q_col_played);
|
|
|
|
add(q_col_path); }
|
2014-01-19 15:19:24 -05:00
|
|
|
|
|
|
|
Gtk::TreeModelColumn<unsigned int> q_col_track;
|
|
|
|
Gtk::TreeModelColumn<std::string> q_col_title;
|
|
|
|
Gtk::TreeModelColumn<std::string> q_col_length;
|
|
|
|
Gtk::TreeModelColumn<std::string> q_col_artist;
|
|
|
|
Gtk::TreeModelColumn<std::string> q_col_album;
|
|
|
|
Gtk::TreeModelColumn<unsigned int> q_col_year;
|
|
|
|
Gtk::TreeModelColumn<std::string> q_col_genre;
|
|
|
|
Gtk::TreeModelColumn<unsigned int> q_col_count;
|
|
|
|
Gtk::TreeModelColumn<std::string> q_col_played;
|
2014-01-29 22:23:07 -05:00
|
|
|
Gtk::TreeModelColumn<std::string> q_col_path;
|
2014-01-19 15:19:24 -05:00
|
|
|
} queue_cols;
|
2014-01-24 16:49:48 -05:00
|
|
|
static unsigned int q_col_width[] = { 20, 300, 60, 100, 100, 45, 100, 60, 1 };
|
2014-01-26 13:45:59 -05:00
|
|
|
static sort_t q_col_sorts[] = {
|
|
|
|
SORT_TRACK, SORT_TITLE, SORT_LENGTH,
|
|
|
|
SORT_ARTIST, SORT_ALBUM, SORT_YEAR,
|
|
|
|
SORT_GENRE, SORT_COUNT, SORT_PLAYED
|
|
|
|
};
|
|
|
|
|
|
|
|
static void dec_sort_timeout()
|
|
|
|
{
|
|
|
|
if (sort_timeout_count > 0)
|
|
|
|
sort_timeout_count--;
|
|
|
|
if (sort_timeout_count == 0) {
|
|
|
|
Gtk::Label *label;
|
|
|
|
get_builder()->get_widget("o_sorting_indicator", label);
|
|
|
|
label->set_text("");
|
|
|
|
}
|
|
|
|
}
|
2014-01-19 15:19:24 -05:00
|
|
|
|
2014-02-06 22:14:14 -05:00
|
|
|
static Gtk::Widget *get_menu_widget(const std::string &name)
|
2014-02-06 21:45:02 -05:00
|
|
|
{
|
2014-02-06 22:14:14 -05:00
|
|
|
Gtk::Widget *widget;
|
2014-02-06 21:45:02 -05:00
|
|
|
get_builder()->get_widget(name, widget);
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void prepare_rc_menu()
|
|
|
|
{
|
|
|
|
unsigned int size = deck::size();
|
2014-02-21 22:06:42 -05:00
|
|
|
*/
|
2014-02-06 21:45:02 -05:00
|
|
|
/* Set widgets visible */
|
2014-02-21 22:06:42 -05:00
|
|
|
/* switch (size) {
|
2014-02-06 21:45:02 -05:00
|
|
|
case 10:
|
|
|
|
get_menu_widget("o_pq_9")->show();
|
|
|
|
case 9:
|
|
|
|
get_menu_widget("o_pq_8")->show();
|
|
|
|
case 8:
|
|
|
|
get_menu_widget("o_pq_7")->show();
|
|
|
|
case 7:
|
|
|
|
get_menu_widget("o_pq_6")->show();
|
|
|
|
case 6:
|
|
|
|
get_menu_widget("o_pq_5")->show();
|
|
|
|
case 5:
|
|
|
|
get_menu_widget("o_pq_4")->show();
|
|
|
|
case 4:
|
|
|
|
get_menu_widget("o_pq_3")->show();
|
|
|
|
case 3:
|
|
|
|
get_menu_widget("o_pq_2")->show();
|
|
|
|
case 2:
|
|
|
|
get_menu_widget("o_pq_1")->show();
|
|
|
|
case 1:
|
|
|
|
get_menu_widget("o_pq_0")->show();
|
|
|
|
get_menu_widget("o_add_to_pq")->show();
|
|
|
|
default:
|
|
|
|
if (size != 10)
|
|
|
|
get_menu_widget("o_new_pq")->show();
|
|
|
|
break;
|
|
|
|
}
|
2014-02-21 22:06:42 -05:00
|
|
|
*/
|
2014-02-06 21:45:02 -05:00
|
|
|
/* Set widgets invisible */
|
2014-02-21 22:06:42 -05:00
|
|
|
/* switch (size) {
|
2014-02-06 21:45:02 -05:00
|
|
|
case 0:
|
|
|
|
get_menu_widget("o_add_to_pq")->hide();
|
|
|
|
get_menu_widget("o_pq_0")->hide();
|
|
|
|
case 1:
|
|
|
|
get_menu_widget("o_pq_1")->hide();
|
|
|
|
case 2:
|
|
|
|
get_menu_widget("o_pq_2")->hide();
|
|
|
|
case 3:
|
|
|
|
get_menu_widget("o_pq_3")->hide();
|
|
|
|
case 4:
|
|
|
|
get_menu_widget("o_pq_4")->hide();
|
|
|
|
case 5:
|
|
|
|
get_menu_widget("o_pq_5")->hide();
|
|
|
|
case 6:
|
|
|
|
get_menu_widget("o_pq_6")->hide();
|
|
|
|
case 7:
|
|
|
|
get_menu_widget("o_pq_7")->hide();
|
|
|
|
case 8:
|
|
|
|
get_menu_widget("o_pq_8")->hide();
|
|
|
|
case 9:
|
|
|
|
get_menu_widget("o_pq_9")->hide();
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
get_menu_widget("o_new_pq")->hide();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-02-21 22:06:42 -05:00
|
|
|
*/
|
2014-01-24 20:01:19 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Ocarina class definition
|
|
|
|
*/
|
2014-02-21 22:06:42 -05:00
|
|
|
/*class OcarinaPage : public Gtk::VBox {
|
2014-01-18 14:43:24 -05:00
|
|
|
private:
|
2014-01-24 23:01:02 -05:00
|
|
|
unsigned int init_flags;
|
2014-01-22 21:19:18 -05:00
|
|
|
Gtk::Notebook *notebook;
|
2014-02-02 12:33:58 -05:00
|
|
|
OcarinaTab *tab;
|
2014-02-21 22:06:42 -05:00
|
|
|
*/
|
2014-02-01 17:30:07 -05:00
|
|
|
/* Filter state */
|
2014-02-21 22:06:42 -05:00
|
|
|
// std::set<unsigned int> visible_ids;
|
2014-02-01 17:30:07 -05:00
|
|
|
|
2014-01-19 15:19:24 -05:00
|
|
|
/* Page widgets */
|
2014-02-21 22:06:42 -05:00
|
|
|
/* Gtk::HBox page_toolbar;
|
2014-01-19 15:19:24 -05:00
|
|
|
Gtk::SearchEntry page_entry;
|
2014-01-30 22:38:16 -05:00
|
|
|
Gtk::ToggleButton page_repeat;
|
2014-01-19 15:19:24 -05:00
|
|
|
Gtk::ScrolledWindow page_scroll;
|
2014-02-02 14:06:27 -05:00
|
|
|
Gtk::HBox page_viewbox;
|
2014-01-19 15:19:24 -05:00
|
|
|
Gtk::TreeView page_view;
|
|
|
|
|
2014-02-17 16:57:08 -05:00
|
|
|
void setup_common(Playqueue *, unsigned int);
|
2014-01-31 21:09:31 -05:00
|
|
|
void setup_toolbar();
|
|
|
|
void setup_treeview();
|
2014-01-19 15:19:24 -05:00
|
|
|
void setup_columns();
|
2014-01-20 19:06:52 -05:00
|
|
|
void set_tab_size();
|
2014-01-19 10:34:26 -05:00
|
|
|
|
2014-01-18 14:43:24 -05:00
|
|
|
public:
|
2014-01-24 22:50:05 -05:00
|
|
|
Gtk::ToggleButton page_random;
|
2014-01-31 22:45:26 -05:00
|
|
|
Glib::RefPtr<PlayqueueModel> model;
|
2014-02-01 17:30:07 -05:00
|
|
|
Glib::RefPtr<Gtk::TreeModelFilter> filter;
|
2014-01-24 22:50:05 -05:00
|
|
|
|
2014-01-31 21:09:31 -05:00
|
|
|
OcarinaPage(Playqueue *, unsigned int, unsigned int);
|
2014-01-24 20:01:19 -05:00
|
|
|
~OcarinaPage();
|
2014-01-22 21:19:18 -05:00
|
|
|
bool is_current_tab();
|
2014-01-24 23:01:02 -05:00
|
|
|
void check_pq_flags();
|
2014-01-30 22:53:44 -05:00
|
|
|
void queue_selected(bool);
|
2014-01-20 19:06:52 -05:00
|
|
|
|
2014-01-31 21:34:34 -05:00
|
|
|
void on_close_clicked();
|
2014-01-20 19:06:52 -05:00
|
|
|
void on_row_inserted(unsigned int);
|
|
|
|
void on_row_deleted(unsigned int);
|
2014-01-26 13:45:59 -05:00
|
|
|
void on_row_changed(unsigned int);
|
2014-01-22 21:19:18 -05:00
|
|
|
void on_runtime_changed();
|
2014-01-24 22:50:05 -05:00
|
|
|
void on_random_toggled();
|
2014-01-30 22:38:16 -05:00
|
|
|
void on_repeat_toggled();
|
2014-01-26 12:44:48 -05:00
|
|
|
void on_row_activated(const Gtk::TreePath &, Gtk::TreeViewColumn *);
|
2014-01-26 13:45:59 -05:00
|
|
|
void on_column_clicked(unsigned int);
|
2014-02-01 17:30:07 -05:00
|
|
|
void on_entry_changed();
|
|
|
|
bool on_entry_key_released(GdkEventKey *);
|
|
|
|
bool on_filter_visible(const Gtk::TreeIter &);
|
2014-02-02 10:45:09 -05:00
|
|
|
void on_page_renumbered();
|
2014-02-06 21:45:02 -05:00
|
|
|
bool on_add_to_pq(unsigned int);
|
2014-02-07 20:35:40 -05:00
|
|
|
bool on_delete_selected();
|
2014-02-07 20:57:15 -05:00
|
|
|
bool on_favorite_selected();
|
2014-02-02 10:45:09 -05:00
|
|
|
bool on_view_key_pressed(GdkEventKey *);
|
2014-02-06 21:45:02 -05:00
|
|
|
bool on_view_button_pressed(GdkEventButton *);
|
2014-02-07 21:27:47 -05:00
|
|
|
void on_focus_search();
|
2014-01-18 14:43:24 -05:00
|
|
|
};
|
|
|
|
|
2014-01-31 21:09:31 -05:00
|
|
|
void OcarinaPage::setup_treeview()
|
2014-02-21 22:06:42 -05:00
|
|
|
{*/
|
2014-01-19 15:19:24 -05:00
|
|
|
/* Make page content */
|
2014-02-21 22:06:42 -05:00
|
|
|
/*page_view.append_column("#", queue_cols.q_col_track);
|
2014-01-19 15:19:24 -05:00
|
|
|
page_view.append_column("Title", queue_cols.q_col_title);
|
|
|
|
page_view.append_column("Length", queue_cols.q_col_length);
|
|
|
|
page_view.append_column("Artist", queue_cols.q_col_artist);
|
|
|
|
page_view.append_column("Album", queue_cols.q_col_album);
|
|
|
|
page_view.append_column("Year", queue_cols.q_col_year);
|
|
|
|
page_view.append_column("Genre", queue_cols.q_col_genre);
|
|
|
|
page_view.append_column("Count", queue_cols.q_col_count);
|
|
|
|
page_view.append_column("Played", queue_cols.q_col_played);
|
2014-01-29 22:23:07 -05:00
|
|
|
page_view.set_tooltip_column(9);
|
2014-01-20 19:06:52 -05:00
|
|
|
|
2014-01-26 12:44:48 -05:00
|
|
|
page_view.signal_row_activated().connect(sigc::mem_fun(*this,
|
|
|
|
&OcarinaPage::on_row_activated));
|
2014-02-02 10:45:09 -05:00
|
|
|
page_view.signal_key_press_event().connect(sigc::mem_fun(*this,
|
|
|
|
&OcarinaPage::on_view_key_pressed));
|
2014-02-06 21:45:02 -05:00
|
|
|
page_view.signal_button_press_event().connect(sigc::mem_fun(*this,
|
|
|
|
&OcarinaPage::on_view_button_pressed), false);
|
2014-02-02 10:45:09 -05:00
|
|
|
|
2014-02-01 17:30:07 -05:00
|
|
|
page_view.set_model(filter);
|
2014-01-24 20:31:33 -05:00
|
|
|
page_view.set_rules_hint();
|
2014-01-30 22:33:24 -05:00
|
|
|
page_view.set_enable_search(false);
|
|
|
|
page_view.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
|
|
|
|
page_view.set_rubber_banding();
|
2014-02-02 12:33:58 -05:00
|
|
|
|
|
|
|
page_scroll.set_shadow_type(Gtk::SHADOW_IN);
|
|
|
|
page_scroll.set_margin_left(5);
|
|
|
|
page_scroll.set_margin_right(5);
|
|
|
|
page_scroll.set_margin_bottom(5);
|
2014-01-19 15:19:24 -05:00
|
|
|
page_scroll.add(page_view);
|
|
|
|
|
2014-01-31 21:09:31 -05:00
|
|
|
setup_columns();
|
2014-02-02 14:06:27 -05:00
|
|
|
page_viewbox.pack_start(page_scroll, true, true);
|
2014-01-18 14:43:24 -05:00
|
|
|
};
|
|
|
|
|
2014-01-24 20:01:19 -05:00
|
|
|
void OcarinaPage::setup_columns()
|
2014-01-19 15:19:24 -05:00
|
|
|
{
|
|
|
|
std::vector<Gtk::TreeViewColumn *> columns = page_view.get_columns();
|
|
|
|
for (unsigned int i = 0; i < columns.size(); i++) {
|
|
|
|
columns[i]->set_resizable();
|
|
|
|
columns[i]->set_fixed_width(q_col_width[i]);
|
2014-01-20 20:14:22 -05:00
|
|
|
columns[i]->set_sizing(Gtk::TREE_VIEW_COLUMN_FIXED);
|
2014-01-26 13:45:59 -05:00
|
|
|
columns[i]->set_clickable();
|
|
|
|
columns[i]->signal_clicked().connect(sigc::bind<unsigned int> (
|
|
|
|
sigc::mem_fun(*this, &OcarinaPage::on_column_clicked),
|
|
|
|
i));
|
2014-01-19 15:19:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-24 23:01:02 -05:00
|
|
|
void OcarinaPage::check_pq_flags()
|
|
|
|
{
|
2014-01-30 22:53:44 -05:00
|
|
|
if (init_flags & PQ_REPEAT) {
|
2014-01-30 22:38:16 -05:00
|
|
|
page_repeat.set_active(model->queue->get_flags() & PQ_REPEAT);
|
|
|
|
page_repeat.signal_toggled().connect(sigc::mem_fun(*this,
|
|
|
|
&OcarinaPage::on_repeat_toggled));
|
2014-01-24 23:01:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-30 22:38:16 -05:00
|
|
|
void OcarinaPage::on_repeat_toggled()
|
|
|
|
{
|
|
|
|
if (page_repeat.get_active())
|
|
|
|
model->queue->set_flag(PQ_REPEAT);
|
|
|
|
else
|
|
|
|
model->queue->unset_flag(PQ_REPEAT);
|
|
|
|
}
|
|
|
|
|
2014-01-26 13:45:59 -05:00
|
|
|
void OcarinaPage::on_column_clicked(unsigned int col_index)
|
|
|
|
{
|
|
|
|
Gtk::Label *sorting;
|
|
|
|
get_builder()->get_widget("o_sorting_indicator", sorting);
|
|
|
|
|
2014-01-31 22:10:20 -05:00
|
|
|
if (sort_timeout_count == 0) {
|
|
|
|
sorting->set_text("Sorting within " + page_view.get_column(col_index)->get_title());
|
2014-01-26 13:45:59 -05:00
|
|
|
model->queue->reset_sort(q_col_sorts[col_index]);
|
2014-01-31 22:10:20 -05:00
|
|
|
} else
|
2014-01-26 13:45:59 -05:00
|
|
|
model->queue->add_sort(q_col_sorts[col_index]);
|
|
|
|
sort_timeout_count++;
|
|
|
|
Glib::signal_timeout().connect_seconds_once(
|
2014-01-26 14:58:30 -05:00
|
|
|
sigc::ptr_fun(dec_sort_timeout), 2);
|
2014-01-26 13:45:59 -05:00
|
|
|
}
|
|
|
|
|
2014-02-06 21:45:02 -05:00
|
|
|
bool OcarinaPage::on_add_to_pq(unsigned int n)
|
|
|
|
{
|
|
|
|
if (n >= deck :: size())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
Glib::RefPtr<Gtk::TreeSelection> sel = page_view.get_selection();
|
|
|
|
if (sel->count_selected_rows() == 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
Playqueue *pq = deck :: get(n);
|
|
|
|
std::vector<Gtk::TreeModel::Path>::iterator it;
|
|
|
|
std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
|
|
|
|
for (it = rows.begin(); it != rows.end(); it++) {
|
|
|
|
unsigned int track_id = model->path_to_id(filter->convert_path_to_child_path(*it));
|
|
|
|
pq->add(track_id);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-07 20:35:40 -05:00
|
|
|
bool OcarinaPage::on_delete_selected()
|
|
|
|
{
|
|
|
|
Glib::RefPtr<Gtk::TreeSelection> sel = page_view.get_selection();
|
|
|
|
if (sel->count_selected_rows() == 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if ((unsigned int)notebook->page_num(*this) >= deck :: size())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
std::vector<Gtk::TreeModel::Path>::reverse_iterator it;
|
|
|
|
std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
|
|
|
|
for (it = rows.rbegin(); it != rows.rend(); it++) {
|
|
|
|
unsigned int id = filter->convert_path_to_child_path(*it)[0];
|
|
|
|
model->queue->del(id);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-07 20:57:15 -05:00
|
|
|
bool OcarinaPage::on_favorite_selected()
|
|
|
|
{
|
|
|
|
Glib::RefPtr<Gtk::TreeSelection> sel = page_view.get_selection();
|
|
|
|
if (sel->count_selected_rows() == 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
std::vector<Gtk::TreeModel::Path>::iterator it;
|
|
|
|
std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
|
|
|
|
for (it = rows.begin(); it != rows.end(); it++) {
|
|
|
|
unsigned int id = model->path_to_id(filter->convert_path_to_child_path(*it));
|
|
|
|
playlist :: add("Favorites", id);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-02 10:45:09 -05:00
|
|
|
bool OcarinaPage::on_view_key_pressed(GdkEventKey *event)
|
|
|
|
{
|
|
|
|
std::string key = gdk_keyval_name(event->keyval);
|
|
|
|
|
|
|
|
if (key.size() >= 3) {
|
|
|
|
if (key.substr(0, 3) == "KP_")
|
|
|
|
key = key.substr(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (key >= "0" && key <= "9") {
|
|
|
|
unsigned int n = atoi(key.c_str());
|
2014-02-06 21:45:02 -05:00
|
|
|
return on_add_to_pq(n);
|
2014-02-07 20:57:15 -05:00
|
|
|
} else if (key == "f")
|
|
|
|
return on_favorite_selected();
|
|
|
|
else if (key == "Delete")
|
2014-02-07 20:35:40 -05:00
|
|
|
return on_delete_selected();
|
2014-02-02 10:45:09 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-06 21:45:02 -05:00
|
|
|
bool OcarinaPage::on_view_button_pressed(GdkEventButton *button)
|
|
|
|
{
|
|
|
|
Gtk::Menu *menu;
|
|
|
|
get_builder()->get_widget("o_rc_menu", menu);
|
|
|
|
|
|
|
|
if (button->button != 3)
|
|
|
|
return false;
|
|
|
|
prepare_rc_menu();
|
|
|
|
menu->popup(button->button, button->time);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-21 22:06:42 -05:00
|
|
|
*/
|
2014-01-18 14:43:24 -05:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do stuff with tabs
|
|
|
|
*/
|
2014-02-21 22:06:42 -05:00
|
|
|
/*
|
2014-02-06 21:45:02 -05:00
|
|
|
static void on_add_to_queue(unsigned int num)
|
|
|
|
{
|
|
|
|
std::map<Playqueue *, OcarinaPage *>::iterator it;
|
|
|
|
for (it = tab_map.begin(); it != tab_map.end(); it++) {
|
|
|
|
if (it->second->is_current_tab()) {
|
|
|
|
it->second->on_add_to_pq(num);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void init_menu_item(const std::string &name, unsigned int num)
|
|
|
|
{
|
2014-02-06 22:14:14 -05:00
|
|
|
Glib::RefPtr<Gtk::MenuItem>menu = Glib::RefPtr<Gtk::MenuItem>::cast_static(get_builder()->get_object(name));
|
2014-02-06 21:45:02 -05:00
|
|
|
menu->signal_activate().connect(sigc::bind<unsigned int> (
|
|
|
|
sigc::ptr_fun(on_add_to_queue), num));
|
2014-02-17 15:32:47 -05:00
|
|
|
}*/
|
2014-02-06 21:45:02 -05:00
|
|
|
|
2014-02-23 15:27:19 -05:00
|
|
|
/*
|
2014-01-19 10:34:26 -05:00
|
|
|
void init_tabs()
|
2014-01-18 14:43:24 -05:00
|
|
|
{
|
2014-01-22 21:19:18 -05:00
|
|
|
Gtk::Notebook *notebook;
|
|
|
|
get_builder()->get_widget("o_notebook", notebook);
|
|
|
|
|
2014-01-26 13:45:59 -05:00
|
|
|
get_callbacks()->on_queue_track_changed = on_track_changed;
|
2014-01-22 21:19:18 -05:00
|
|
|
|
2014-02-21 22:06:42 -05:00
|
|
|
*/
|
2014-02-17 15:32:47 -05:00
|
|
|
/*Glib::RefPtr<Gtk::MenuItem> new_pq = Glib::RefPtr<Gtk::MenuItem>::cast_static(get_builder()->get_object("o_new_pq"));
|
2014-02-06 22:14:14 -05:00
|
|
|
new_pq->signal_activate().connect(sigc::ptr_fun(on_new_queue));
|
|
|
|
|
2014-02-06 21:45:02 -05:00
|
|
|
init_menu_item("o_pq_0", 0);
|
|
|
|
init_menu_item("o_pq_1", 1);
|
|
|
|
init_menu_item("o_pq_2", 2);
|
|
|
|
init_menu_item("o_pq_3", 3);
|
|
|
|
init_menu_item("o_pq_4", 4);
|
|
|
|
init_menu_item("o_pq_5", 5);
|
|
|
|
init_menu_item("o_pq_6", 6);
|
|
|
|
init_menu_item("o_pq_7", 7);
|
|
|
|
init_menu_item("o_pq_8", 8);
|
2014-02-17 15:32:47 -05:00
|
|
|
init_menu_item("o_pq_9", 9);*/
|
2014-02-21 22:06:42 -05:00
|
|
|
/*
|
2014-02-06 21:45:02 -05:00
|
|
|
|
2014-01-31 22:45:26 -05:00
|
|
|
notebook->signal_page_reordered().connect(sigc::ptr_fun(on_page_reordered));
|
2014-01-25 14:42:56 -05:00
|
|
|
notebook->set_current_page(0);
|
2014-02-21 22:06:42 -05:00
|
|
|
}*/
|