f95a6d02ed
I moved the location of buttons and text boxes, and also resized some of the widgets. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
198 lines
4.3 KiB
C++
198 lines
4.3 KiB
C++
/*
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
*/
|
|
extern "C" {
|
|
#include <core/audio.h>
|
|
#include <core/collection.h>
|
|
#include <core/playlist.h>
|
|
#include <gui/builder.h>
|
|
}
|
|
#include <gui/tabs.h>
|
|
#include <gui/queue/label.h>
|
|
|
|
|
|
static Gtk::ToggleButton *o_ban;
|
|
static Gtk::ToggleButton *o_fav;
|
|
|
|
|
|
|
|
static class PlaylistColumns : public Gtk::TreeModelColumnRecord {
|
|
public:
|
|
Gtk::TreeModelColumn<Glib::ustring> p_name;
|
|
PlaylistColumns() { add(p_name); }
|
|
} p_cols;
|
|
|
|
|
|
|
|
class PlaylistWindow : public Gtk::ScrolledWindow {
|
|
private:
|
|
Glib::RefPtr<Gtk::Builder> _builder;
|
|
|
|
public:
|
|
Gtk::TreeView *p_treeview;
|
|
Glib::RefPtr<Gtk::ListStore> p_list;
|
|
|
|
PlaylistWindow(BaseObjectType *cobject,
|
|
const Glib::RefPtr<Gtk::Builder> builder)
|
|
: Gtk::ScrolledWindow(cobject), _builder(builder)
|
|
{
|
|
_builder->get_widget("p_treeview", p_treeview);
|
|
p_list = Glib::RefPtr<Gtk::ListStore>::cast_static(_builder->get_object("p_list"));
|
|
|
|
p_treeview->signal_cursor_changed().connect(sigc::mem_fun(*this,
|
|
&PlaylistWindow::on_cursor_changed));
|
|
p_treeview->signal_button_press_event().connect(sigc::mem_fun(*this,
|
|
&PlaylistWindow::on_clicked));
|
|
}
|
|
|
|
~PlaylistWindow() {}
|
|
|
|
enum playlist_t current_playlist()
|
|
{
|
|
Gtk::TreePath path;
|
|
Gtk::TreeModel::Row row;
|
|
Gtk::TreeViewColumn *col;
|
|
|
|
p_treeview->get_cursor(path, col);
|
|
row = *(p_list->get_iter(path));
|
|
|
|
if (row[p_cols.p_name] == "Favorites")
|
|
return PL_FAVORITED;
|
|
else if (row[p_cols.p_name] == "Banned")
|
|
return PL_HIDDEN;
|
|
else if (row[p_cols.p_name] == "Most Played")
|
|
return PL_MOST_PLAYED;
|
|
else if (row[p_cols.p_name] == "Least Played")
|
|
return PL_LEAST_PLAYED;
|
|
return PL_UNPLAYED;
|
|
}
|
|
|
|
void on_cursor_changed()
|
|
{
|
|
playlist_select(current_playlist());
|
|
}
|
|
|
|
bool on_clicked(GdkEventButton *button)
|
|
{
|
|
return button->button == 3;
|
|
}
|
|
};
|
|
|
|
|
|
|
|
static class PlaylistTab : public Tab {
|
|
private:
|
|
Gtk::HBox playlist_hbox;
|
|
|
|
PlaylistLabel *playlist_label;
|
|
PlaylistWindow *playlist_window;
|
|
|
|
public:
|
|
PlaylistTab() : Tab(playlist_get_queue())
|
|
{
|
|
tab_builder->add_from_file(gui :: share_file("QueueLabel.ui"));
|
|
tab_builder->add_from_file(gui :: share_file("PlaylistWindow.ui"));
|
|
|
|
tab_builder->get_widget_derived("PlaylistLabel", playlist_label);
|
|
tab_builder->get_widget_derived("PlaylistWindow", playlist_window);
|
|
|
|
tab_toolbar->init(tab_pq, playlist_label, tab_window, 0);
|
|
playlist_label->init(tab_pq);
|
|
tab_label = playlist_label;
|
|
|
|
playlist_hbox.pack_start(*playlist_window, false, true);
|
|
playlist_hbox.pack_start(*tab_window, true, true);
|
|
playlist_hbox.show();
|
|
|
|
tab_vbox.pack_start(playlist_hbox, true, true);
|
|
|
|
Glib :: wrap(GTK_NOTEBOOK(gui_builder_widget("o_notebook")),
|
|
false)->insert_page(tab_vbox, *playlist_label, 0);
|
|
}
|
|
|
|
~PlaylistTab()
|
|
{
|
|
tab_unmap();
|
|
}
|
|
|
|
bool on_key_press_event(const std::string &key)
|
|
{
|
|
enum playlist_t cur;
|
|
std::vector<unsigned int> ids;
|
|
|
|
if (key != "Delete")
|
|
return Tab :: on_key_press_event(key);
|
|
|
|
cur = playlist_window->current_playlist();
|
|
|
|
tab_selected_ids(ids);
|
|
for (unsigned int i = 0; i < ids.size(); i++)
|
|
if (cur == PL_HIDDEN)
|
|
collection_unban(track_get(ids[i]));
|
|
else
|
|
playlist_remove(cur, track_get(ids[i]));
|
|
return true;
|
|
}
|
|
} *p_tab;
|
|
|
|
|
|
|
|
static void on_ban()
|
|
{
|
|
struct track *track = audio_cur_track();
|
|
if (o_ban->get_active()) {
|
|
if (collection_ban(track))
|
|
audio_next();
|
|
} else
|
|
collection_unban(track);
|
|
}
|
|
|
|
static void on_favorite()
|
|
{
|
|
struct track *track = audio_cur_track();
|
|
if (o_fav->get_active())
|
|
playlist_add(PL_FAVORITED, track);
|
|
else
|
|
playlist_remove(PL_FAVORITED, track);
|
|
}
|
|
|
|
static void playlist_added(struct queue *queue, unsigned int pos)
|
|
{
|
|
if (p_tab)
|
|
p_tab->on_track_added(pos);
|
|
}
|
|
|
|
static void playlist_removed(struct queue *queue, unsigned int pos)
|
|
{
|
|
p_tab->on_track_removed(pos);
|
|
}
|
|
|
|
static void playlist_cleared(struct queue *queue, unsigned int n)
|
|
{
|
|
p_tab->on_tracks_cleared(n);
|
|
}
|
|
|
|
static void playlist_updated(struct queue *queue, unsigned int pos)
|
|
{
|
|
p_tab->on_track_updated(pos);
|
|
}
|
|
|
|
struct queue_ops playlist_ops = {
|
|
playlist_added,
|
|
playlist_removed,
|
|
playlist_cleared,
|
|
NULL,
|
|
playlist_updated,
|
|
};
|
|
|
|
void plist :: init()
|
|
{
|
|
p_tab = new PlaylistTab;
|
|
|
|
o_ban = Glib :: wrap(GTK_TOGGLE_BUTTON(gui_builder_widget("o_hide")), false);
|
|
o_fav = Glib :: wrap(GTK_TOGGLE_BUTTON(gui_builder_widget("o_favorite")), false);
|
|
|
|
o_ban->signal_toggled().connect(sigc::ptr_fun(on_ban));
|
|
o_fav->signal_toggled().connect(sigc::ptr_fun(on_favorite));
|
|
}
|