libsaria: Check the top of the stack through a function

The UI shortcuts may remove songs from the queue with no way of
notifying the stack layer.  The UI should call the stack_top_pop()
function to check if the top playlist is empty and ready for removal.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-03-05 08:23:00 -05:00
parent ed3254813c
commit 37bcb47de2
3 changed files with 12 additions and 3 deletions

View File

@ -13,6 +13,7 @@ namespace libsaria
Playlist *new_playlist(string, unsigned int);
void add_to_playlist(list<sid_t> &);
Playlist *stack_top();
void stack_top_pop();
string next_file();
void stack_init();

View File

@ -34,8 +34,8 @@ namespace libsaria
/* Only allow one queue and one library (for now) */
if (playlist_stack.size() == 1) {
plist = new_playlist("queue.q", PL_QUEUE);
plist->add_ids(ids);
trigger_callback(NEW_PLAYLIST);
plist->add_ids(ids);
} else {
plist = playlist_stack.front();
plist->add_ids(ids);
@ -47,15 +47,21 @@ namespace libsaria
return playlist_stack.front();
}
string next_file()
void stack_top_pop()
{
Playlist *plist = playlist_stack.front();
Track *track = plist->next();
if (plist->size() == 0) {
plist->delete_renderer();
delete plist;
playlist_stack.pop_front();
}
}
string next_file()
{
Playlist *plist = playlist_stack.front();
Track *track = plist->next();
stack_top_pop();
return track->get_filepath();
}

View File

@ -4,6 +4,7 @@
#include <ocarina/gtk.h>
#include <ocarina/songlist.h>
#include <ocarina/shortcut.h>
#include <libsaria/stack.h>
#include <list>
using namespace std;
@ -15,6 +16,7 @@ GtkWidget *queue_page;
static void rm_from_queue()
{
queue_list->rm_selected_indices();
libsaria::stack_top_pop();
}
static void rm_from_queue_event(GtkMenuItem *menu, gpointer data)