ocarina: Allocate SongLists when they are needed
Right now it's just for a single queue, but I should be able to expand this once I enable more stacking in the backend. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
c23c4a2740
commit
d7725d9068
|
@ -45,6 +45,7 @@ class SongList : public libsaria::PlaylistRenderer
|
|||
void thaw();
|
||||
|
||||
void list_selected_indices(list<int> &);
|
||||
void on_playlist_empty();
|
||||
|
||||
public:
|
||||
SongList();
|
||||
|
|
|
@ -40,12 +40,18 @@ static void on_click_play(GtkWidget *b, GdkEvent *e, gpointer d)
|
|||
libsaria::audio::play();
|
||||
}
|
||||
|
||||
static void destroyed(GtkWidget *button, list<GtkWidget *> *widget_list)
|
||||
{
|
||||
widget_list->remove(button);
|
||||
}
|
||||
|
||||
GtkWidget *make_play_button()
|
||||
{
|
||||
GtkWidget *b = make_button(GTK_STOCK_MEDIA_PLAY,
|
||||
on_click_play,
|
||||
true);
|
||||
play_buttons.push_back(b);
|
||||
GTK_CONNECT(b, "destroy", destroyed, &play_buttons);
|
||||
return b;
|
||||
}
|
||||
|
||||
|
@ -60,6 +66,7 @@ GtkWidget *make_pause_button()
|
|||
on_click_pause,
|
||||
false);
|
||||
pause_buttons.push_back(b);
|
||||
GTK_CONNECT(b, "destroy", destroyed, &pause_buttons);
|
||||
return b;
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,17 @@ static GtkWidget *setup_window(GtkWidget *box)
|
|||
return window;
|
||||
}
|
||||
|
||||
static void destroyed(GtkWidget *title, gpointer data)
|
||||
{
|
||||
list<NowPlayingWidgets>::iterator it;
|
||||
for (it = nowplaying_widgets.begin(); it != nowplaying_widgets.end(); it++) {
|
||||
if ((*it).title == title) {
|
||||
nowplaying_widgets.erase(it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GtkWidget *get_nowplaying()
|
||||
{
|
||||
struct NowPlayingWidgets widgets;
|
||||
|
@ -68,6 +79,7 @@ GtkWidget *get_nowplaying()
|
|||
widgets.artist = gtk_label_new("");
|
||||
widgets.album = gtk_label_new("");
|
||||
|
||||
GTK_CONNECT(widgets.title, "destroy", destroyed, NULL);
|
||||
set_now_playing(&widgets, "", "", "");
|
||||
|
||||
box_pack_start(box, align(widgets.title), TRUE, FALSE, 0);
|
||||
|
|
|
@ -62,6 +62,17 @@ static GtkWidget *make_scale()
|
|||
return scale;
|
||||
}
|
||||
|
||||
void destroyed(GtkWidget *position, gpointer data)
|
||||
{
|
||||
list<ProgressWidgets>::iterator it;
|
||||
for (it = widget_list.begin(); it != widget_list.end(); it++) {
|
||||
if ((*it).position == position) {
|
||||
widget_list.erase(it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GtkWidget *get_progress()
|
||||
{
|
||||
struct ProgressWidgets widgets;
|
||||
|
@ -70,6 +81,8 @@ GtkWidget *get_progress()
|
|||
widgets.duration = gtk_label_new("");
|
||||
widgets.progress = make_scale();
|
||||
|
||||
GTK_CONNECT(widgets.position, "destroy", destroyed, NULL);
|
||||
|
||||
box_pack_start(box, widgets.position, FALSE, FALSE, 0);
|
||||
box_pack_start(box, widgets.progress, TRUE, TRUE, 0);
|
||||
box_pack_start(box, widgets.duration, FALSE, FALSE, 0);
|
||||
|
|
|
@ -33,10 +33,16 @@ static void do_filter(GtkWidget *entry)
|
|||
libsaria::index::filter(text);
|
||||
}
|
||||
|
||||
static void destroyed(GtkWidget *entry)
|
||||
{
|
||||
entries.remove(entry);
|
||||
}
|
||||
|
||||
GtkWidget *get_entry()
|
||||
{
|
||||
GtkWidget *entry = gtk_entry_new();
|
||||
GTK_CONNECT(entry, "changed", do_filter, NULL);
|
||||
GTK_CONNECT(entry, "destroy", destroyed, NULL);
|
||||
entries.push_back(entry);
|
||||
return entry;
|
||||
}
|
||||
|
|
|
@ -10,15 +10,13 @@
|
|||
#include <list>
|
||||
using namespace std;
|
||||
|
||||
static SongList queue_list;
|
||||
static SongList *queue_list;
|
||||
static list <MenuItem> queue_menu;
|
||||
GtkWidget *queue_page;
|
||||
|
||||
static void rm_from_queue()
|
||||
{
|
||||
queue_list.rm_selected_indices();
|
||||
if (libsaria::queue::size() == 0)
|
||||
gtk_widget_hide(queue_page);
|
||||
queue_list->rm_selected_indices();
|
||||
}
|
||||
|
||||
static void rm_from_queue_event(GtkMenuItem *menu, gpointer data)
|
||||
|
@ -31,21 +29,21 @@ namespace ocarina
|
|||
|
||||
void queue::refresh()
|
||||
{
|
||||
queue_list.clear();
|
||||
if (libsaria::queue::size() > 0) {
|
||||
queue_list.fill();
|
||||
gtk_widget_show(queue_page);
|
||||
} else
|
||||
gtk_widget_hide(queue_page);
|
||||
if (!queue_list) {
|
||||
queue_list = new SongList();
|
||||
queue_list->set_playlist(libsaria::queue::get_playlist());
|
||||
queue_list->init("Queue", &queue_menu, false);
|
||||
}
|
||||
queue_list->fill();
|
||||
} else if (queue_list)
|
||||
delete queue_list;
|
||||
}
|
||||
|
||||
void queue::init()
|
||||
{
|
||||
queue_menu.push_back(MenuItem("Remove from Queue", rm_from_queue_event));
|
||||
register_shortcut("Delete", rm_from_queue);
|
||||
|
||||
queue_list.set_playlist(libsaria::queue::get_playlist());
|
||||
queue_page = queue_list.init("Queue", &queue_menu, false);
|
||||
ocarina::queue::refresh();
|
||||
}
|
||||
|
||||
|
|
|
@ -147,3 +147,10 @@ GtkWidget *SongList::init(string text, list <MenuItem> *menu, bool enable_filter
|
|||
push_page(page, label, true);
|
||||
return page;
|
||||
}
|
||||
|
||||
void SongList::on_playlist_empty()
|
||||
{
|
||||
if (page)
|
||||
remove_page(page);
|
||||
page = NULL;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue