82d1da491b
I replace it with calls to g_strdup_printf(). This has the additional benefit that I can do uint conversions at the same time as other formatting options, so this seems like a win. The only downside is that I have to manually free the memory that glib allocates, but that's easy enough. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
229 lines
4.7 KiB
C++
229 lines
4.7 KiB
C++
/*
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/deck.h>
|
|
#include <core/string.h>
|
|
#include <gui/tabs.h>
|
|
#include <gui/queue/label.h>
|
|
|
|
|
|
static void renumber_queues();
|
|
|
|
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);
|
|
add(q_col_genre); add(q_col_count); add(q_col_played);
|
|
add(q_col_path); }
|
|
|
|
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;
|
|
Gtk::TreeModelColumn<std::string> q_col_path;
|
|
} queue_cols;
|
|
|
|
|
|
|
|
class QueueTab : public Tab {
|
|
private:
|
|
/**
|
|
* Queue tab widgets
|
|
*/
|
|
TempLabel *q_label;
|
|
|
|
public:
|
|
QueueTab(Queue *, unsigned int num);
|
|
~QueueTab();
|
|
|
|
void on_track_removed(unsigned int);
|
|
|
|
/**
|
|
* Helper functions
|
|
*/
|
|
bool on_key_press_event(const std::string &);
|
|
void queue_set_number(unsigned int);
|
|
void on_tab_reordered();
|
|
void on_move_queue(int);
|
|
|
|
/**
|
|
* GTK-MM Callbacks
|
|
*/
|
|
void on_close_clicked();
|
|
};
|
|
|
|
static std::map<Gtk::Widget *, QueueTab *> queue_mapping;
|
|
|
|
|
|
QueueTab :: QueueTab(Queue *pq, unsigned int num)
|
|
: Tab(pq)
|
|
{
|
|
tab_builder->add_from_file(gui :: share_file("QueueLabel.ui"));
|
|
|
|
/*
|
|
* Create our tab widget
|
|
*/
|
|
tab_builder->get_widget_derived("TempLabel", q_label);
|
|
|
|
q_label->temp_close->signal_clicked().connect(sigc::mem_fun(*this,
|
|
&QueueTab::on_close_clicked));
|
|
q_label->init(tab_pq);
|
|
tab_label = q_label;
|
|
|
|
queue_set_number(num);
|
|
|
|
|
|
/*
|
|
* Now set up the toolbar
|
|
*/
|
|
tab_toolbar->init(pq, q_label, tab_window, T_RANDOM | T_REPEAT | T_SWITCH);
|
|
|
|
|
|
/*
|
|
* Fill in the page!
|
|
*/
|
|
|
|
tab_vbox.pack_start(*tab_window, true, true);
|
|
|
|
queue_mapping[&tab_vbox] = this;
|
|
|
|
gui :: get_widget<Gtk::Notebook>("o_notebook")->insert_page(tab_vbox, *q_label, num);
|
|
gui :: get_widget<Gtk::Notebook>("o_notebook")->set_tab_reorderable(tab_vbox);
|
|
}
|
|
|
|
QueueTab :: ~QueueTab()
|
|
{
|
|
queue_mapping.erase(&tab_vbox);
|
|
tab_unmap();
|
|
gui :: get_widget<Gtk::Notebook>("o_notebook")->remove_page(tab_vbox);
|
|
renumber_queues();
|
|
}
|
|
|
|
void QueueTab :: on_track_removed(unsigned int row)
|
|
{
|
|
this->Tab :: on_track_removed(row);
|
|
if (tab_pq->size() == 0)
|
|
delete this;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
*
|
|
* Queue tab helper functions
|
|
*
|
|
*/
|
|
|
|
bool QueueTab :: 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() returns track_ids and not
|
|
* playlist_ids,so we can't use it here =(
|
|
*/
|
|
Glib::RefPtr<Gtk::TreeSelection> sel = tab_window->q_treeview->get_selection();
|
|
std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
|
|
Gtk::TreeModel::Path path;
|
|
|
|
for (unsigned int i = 0; i < rows.size(); i++) {
|
|
path = tab_window->q_filter->convert_path_to_child_path(rows[i]);
|
|
ids.push_back(path[0]);
|
|
}
|
|
|
|
for (unsigned int i = ids.size(); i > 0; i--)
|
|
tab_pq->del(ids[i-1]);
|
|
return true;
|
|
}
|
|
|
|
void QueueTab :: queue_set_number(unsigned int num)
|
|
{
|
|
gchar *text = g_strdup_printf("%u. ", num);
|
|
q_label->temp_number->set_text(text);
|
|
g_free(text);
|
|
}
|
|
|
|
void QueueTab :: on_tab_reordered()
|
|
{
|
|
queue_set_number(tab_page_num());
|
|
}
|
|
|
|
void QueueTab :: on_move_queue(int num)
|
|
{
|
|
deck :: move(tab_pq, num);
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
*
|
|
* Gtk-MM Callback Functions
|
|
*
|
|
*/
|
|
|
|
void QueueTab :: on_close_clicked()
|
|
{
|
|
deck :: destroy(tab_pq);
|
|
delete this;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
*
|
|
* Global functions
|
|
*
|
|
*/
|
|
static void renumber_queues()
|
|
{
|
|
std::map<Gtk::Widget *, QueueTab *>::iterator it;
|
|
for (it = queue_mapping.begin(); it != queue_mapping.end(); it++)
|
|
it->second->on_tab_reordered();
|
|
}
|
|
|
|
void on_pq_created(Queue *pq, unsigned int num)
|
|
{
|
|
new QueueTab(pq, num);
|
|
}
|
|
|
|
static void on_page_reordered(Gtk::Widget *page, int num)
|
|
{
|
|
Gtk::Notebook *notebook = gui :: get_widget<Gtk::Notebook>("o_notebook");
|
|
|
|
if ((unsigned int)num >= deck :: get_queues().size()) {
|
|
notebook->reorder_child(*page, deck::get_queues().size() - 1);
|
|
return;
|
|
}
|
|
|
|
std::map<Gtk::Widget *, QueueTab *>::iterator it;
|
|
it = queue_mapping.find(page);
|
|
if (it != queue_mapping.end()) {
|
|
it->second->on_move_queue(num);
|
|
renumber_queues();
|
|
}
|
|
}
|
|
|
|
void init_queue_tabs()
|
|
{
|
|
Gtk::Notebook *notebook = gui :: get_widget<Gtk::Notebook>("o_notebook");
|
|
notebook->signal_page_reordered().connect(sigc::ptr_fun(on_page_reordered));
|
|
}
|
|
|
|
void post_init_queue_tabs()
|
|
{
|
|
std::list<TempQueue>::iterator it;
|
|
unsigned int i = 0;
|
|
|
|
for (it = deck :: get_queues().begin(); it != deck :: get_queues().end(); it++)
|
|
on_pq_created(&(*it), i++);
|
|
}
|