Remove empty playlists when picking next song
Hopefully with fewer problems than 5.7 had... Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
15aabfcff0
commit
3f665712a1
|
@ -50,6 +50,9 @@ namespace libsaria
|
|||
~Playlist();
|
||||
void set_renderer(PlaylistRenderer *);
|
||||
|
||||
bool is_static();
|
||||
void prepare_for_removal();
|
||||
|
||||
virtual Track *next() = 0;
|
||||
string &get_name();
|
||||
unsigned int get_size();
|
||||
|
|
|
@ -15,9 +15,11 @@ namespace libsaria
|
|||
public:
|
||||
PlaylistRenderer(unsigned int);
|
||||
~PlaylistRenderer();
|
||||
|
||||
void set_playlist(Playlist *);
|
||||
|
||||
bool is_static();
|
||||
virtual void prepare_for_removal();
|
||||
|
||||
virtual void insert_prepare();
|
||||
virtual void insert(Track *, unsigned int);
|
||||
virtual void insert_done();
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace ocarina
|
|||
|
||||
void init();
|
||||
void push_page(GtkWidget *, GtkWidget *);
|
||||
void remove_page(GtkWidget *);
|
||||
|
||||
void set_idle_progress(float);
|
||||
void hide_idle_progress();
|
||||
|
|
|
@ -28,6 +28,7 @@ namespace ocarina
|
|||
void list_selected_tracks(list<libsaria::Track *> &);
|
||||
|
||||
void set_playlist(libsaria::Playlist *);
|
||||
void prepare_for_removal();
|
||||
|
||||
void insert_prepare();
|
||||
void insert(libsaria::Track *, unsigned int);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include <libsaria/index.h>
|
||||
#include <libsaria/library.h>
|
||||
#include <libsaria/playlist.h>
|
||||
//#include <libsaria/renderer.h>
|
||||
#include <libsaria/renderer.h>
|
||||
|
||||
/*static bool compare_tracks(libsaria::Track *one, libsaria::Track *two)
|
||||
{*/
|
||||
|
@ -51,6 +51,26 @@ namespace libsaria
|
|||
{
|
||||
}
|
||||
|
||||
bool Playlist::is_static()
|
||||
{
|
||||
return (flags & PL_STATIC) == PL_STATIC;
|
||||
}
|
||||
|
||||
void Playlist::prepare_for_removal()
|
||||
{
|
||||
/*
|
||||
* I could do this in the destructor, but I think it could
|
||||
* lead to double-free errors with static playlists
|
||||
*/
|
||||
if (renderer) {
|
||||
renderer->prepare_for_removal();
|
||||
if (!renderer->is_static()) {
|
||||
delete renderer;
|
||||
renderer = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string &Playlist::get_name()
|
||||
{
|
||||
return name;
|
||||
|
|
|
@ -20,6 +20,15 @@ namespace libsaria
|
|||
playlist->set_renderer(this);
|
||||
}
|
||||
|
||||
bool PlaylistRenderer::is_static()
|
||||
{
|
||||
return (flags & PL_STATIC) == PL_STATIC;
|
||||
}
|
||||
|
||||
void PlaylistRenderer::prepare_for_removal()
|
||||
{
|
||||
}
|
||||
|
||||
void PlaylistRenderer::insert_prepare()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <libsaria/playlist.h>
|
||||
#include <libsaria/stack.h>
|
||||
#include <libsaria/track.h>
|
||||
#include <libsaria/print.h>
|
||||
|
||||
#include <list>
|
||||
#include <sstream>
|
||||
|
@ -38,6 +39,13 @@ namespace libsaria
|
|||
Track *track = plist->next();
|
||||
if (track)
|
||||
track->play_now();
|
||||
|
||||
if ((plist->get_size() == 0) && (plist->is_static() == false)) {
|
||||
println("Removing non-static playlist");
|
||||
plist->prepare_for_removal();
|
||||
delete plist;
|
||||
playlist_stack.pop_front();
|
||||
};
|
||||
}
|
||||
|
||||
void set_on_new_playlist(void (*func)(Playlist *))
|
||||
|
|
|
@ -46,4 +46,10 @@ namespace ocarina
|
|||
gtk_notebook_prepend_page(GTK_NOTEBOOK(tabs), page, label);
|
||||
}
|
||||
|
||||
void body::remove_page(GtkWidget *page)
|
||||
{
|
||||
int pg = gtk_notebook_page_num(GTK_NOTEBOOK(tabs), page);
|
||||
gtk_notebook_remove_page(GTK_NOTEBOOK(tabs), pg);
|
||||
}
|
||||
|
||||
}; /* Namespace: ocarina */
|
||||
|
|
|
@ -67,4 +67,9 @@ namespace ocarina
|
|||
body::push_page(box, label);
|
||||
}
|
||||
|
||||
void Playlist::prepare_for_removal()
|
||||
{
|
||||
body::remove_page(box);
|
||||
};
|
||||
|
||||
}; /* Namespace: ocarina */
|
||||
|
|
Loading…
Reference in New Issue