6a8e73375e
So we don't segfault while removing banned tracks. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
80 lines
1.6 KiB
C++
80 lines
1.6 KiB
C++
/*
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/library.h>
|
|
#include <core/playlist.h>
|
|
#include <gui/tabs.h>
|
|
#include <gui/queue/label.h>
|
|
|
|
|
|
class CollectionTab : public Tab {
|
|
private:
|
|
CollectionLabel *collection_label;
|
|
|
|
public:
|
|
CollectionTab() : Tab(collection :: get_queue())
|
|
{
|
|
tab_builder->add_from_file(gui :: share_file("QueueLabel.ui"));
|
|
tab_builder->get_widget_derived("CollectionLabel", collection_label);
|
|
tab_toolbar->init(tab_pq, collection_label, tab_window, T_RANDOM);
|
|
|
|
collection_label->init(tab_pq);
|
|
tab_label = collection_label;
|
|
|
|
tab_vbox.pack_start(*tab_window, true, true);
|
|
gui :: get_widget<Gtk::Notebook>("o_notebook")->insert_page(tab_vbox, *collection_label, 0);
|
|
}
|
|
|
|
~CollectionTab()
|
|
{
|
|
tab_unmap();
|
|
}
|
|
|
|
bool 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 :: add(track_get(ids[i]), "Banned");
|
|
|
|
return true;
|
|
}
|
|
};
|
|
|
|
|
|
static CollectionTab *collection_tab;
|
|
|
|
static void collection_added(struct queue *queue, unsigned int pos)
|
|
{
|
|
if (collection_tab)
|
|
collection_tab->on_track_added(pos);
|
|
}
|
|
|
|
static void collection_removed(struct queue *queue, unsigned int pos)
|
|
{
|
|
if (collection_tab)
|
|
collection_tab->on_track_removed(pos);
|
|
}
|
|
|
|
static void collection_updated(struct queue *queue, unsigned int pos)
|
|
{
|
|
if (collection_tab)
|
|
collection_tab->on_track_updated(pos);
|
|
}
|
|
|
|
struct queue_ops collection_ops = {
|
|
collection_added,
|
|
collection_removed,
|
|
collection :: save,
|
|
collection_updated,
|
|
};
|
|
|
|
void init_collection_tab()
|
|
{
|
|
collection_tab = new CollectionTab;
|
|
}
|