libsaria: Playlists know their own type

Useful for dynamically renaming them (see next patch).

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-03-26 18:50:26 -04:00
parent 3cbeb85828
commit 5a272ef62e
8 changed files with 31 additions and 5 deletions

View File

@ -15,6 +15,7 @@ enum PlaylistFlags {
enum PlaylistType {
PLIST_SET,
PLIST_QUEUE,
PLIST_LIST,
};
#define RENDER(x) \
@ -32,6 +33,7 @@ namespace libsaria
class Playlist {
private:
unsigned int flags;
PlaylistType type;
list<Track *>::iterator cur;
void incr_iter();
@ -50,7 +52,7 @@ namespace libsaria
void add_to_front(list<Track *> &);
public:
Playlist(string, unsigned int);
Playlist(string, unsigned int, PlaylistType);
~Playlist();
void set_renderer(PlaylistRenderer *);
@ -60,7 +62,9 @@ namespace libsaria
virtual Track *next() = 0;
string &get_name();
void rename(string &);
unsigned int get_size();
PlaylistType get_type();
virtual void add_tracks(list<Track *> &) = 0;
};

View File

@ -16,6 +16,7 @@ namespace libsaria
PlaylistRenderer(unsigned int);
~PlaylistRenderer();
void set_playlist(Playlist *);
virtual void renamed(string &);
bool is_static();
virtual void prepare_for_removal();

View File

@ -4,7 +4,7 @@
namespace libsaria
{
List::List(string name, unsigned int flags) : Playlist(name, flags)
List::List(string name, unsigned int flags) : Playlist(name, flags, PLIST_LIST)
{
}

View File

@ -7,10 +7,11 @@
namespace libsaria
{
Playlist::Playlist(string n, unsigned int f)
Playlist::Playlist(string n, unsigned int f, PlaylistType t)
{
name = n;
flags = f;
type = t;
renderer = NULL;
cur = plist.begin();
}
@ -44,11 +45,22 @@ namespace libsaria
return name;
}
void Playlist::rename(string &s)
{
name = s;
RENDER( renamed(name) );
}
unsigned int Playlist::get_size()
{
return plist.size();
}
PlaylistType Playlist::get_type()
{
return type;
}
void Playlist::set_renderer(PlaylistRenderer *r)
{
renderer = r;

View File

@ -4,7 +4,7 @@
namespace libsaria
{
Queue::Queue(string name, unsigned int flags) : Playlist(name, flags)
Queue::Queue(string name, unsigned int flags) : Playlist(name, flags, PLIST_QUEUE)
{
}

View File

@ -20,6 +20,10 @@ namespace libsaria
playlist->set_renderer(this);
}
void PlaylistRenderer::renamed(string &s)
{
}
bool PlaylistRenderer::is_static()
{
return (flags & PL_STATIC) == PL_STATIC;

View File

@ -4,7 +4,7 @@
namespace libsaria
{
Set::Set(string name, unsigned int flags) : Playlist(name, flags)
Set::Set(string name, unsigned int flags) : Playlist(name, flags, PLIST_SET)
{
}

View File

@ -9,6 +9,7 @@
using namespace std;
static unsigned int next_playlist = 0;
static unsigned int num_static = 0;
static void (*on_new_playlist)(libsaria::Playlist *) = NULL;
static list<libsaria::Playlist *> playlist_stack;
@ -35,6 +36,8 @@ namespace libsaria
void stack::push(Playlist *plist)
{
playlist_stack.push_front(plist);
if (plist->is_static())
num_static++;
}
void stack::next()
@ -76,6 +79,8 @@ namespace libsaria
break;
case PLIST_QUEUE:
plist = new Queue("Queue [" + get_next_name() + "]", PL_NONE);
default:
plist = new List("List [" + get_next_name() + "]", PL_NONE);
};
if (on_new_playlist)