libsaria: Automatically rename playlists when added or removed

The one on the top is always numbered "0"

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-03-26 19:21:08 -04:00
parent 5a272ef62e
commit 2ae050fe47
5 changed files with 44 additions and 5 deletions

View File

@ -72,6 +72,7 @@ namespace libsaria
class Set : public Playlist {
public:
Set(unsigned int);
Set(string, unsigned int);
~Set();
@ -82,6 +83,7 @@ namespace libsaria
class Queue : public Playlist {
public:
Queue(unsigned int);
Queue(string, unsigned int);
~Queue();
@ -91,6 +93,7 @@ namespace libsaria
class List : public Playlist {
public:
List(unsigned int);
List(string, unsigned int);
~List();

View File

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

View File

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

View File

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

View File

@ -15,10 +15,10 @@ static void (*on_new_playlist)(libsaria::Playlist *) = NULL;
static list<libsaria::Playlist *> playlist_stack;
static libsaria::List recent_plist("Recent", PL_STATIC | PL_NO_DRAIN);
static string get_next_name()
static string itoa(unsigned int i)
{
stringstream s;
s << next_playlist;
s << i;
return s.str();
}
@ -30,6 +30,27 @@ static void list_recent_track(libsaria::Track *track)
recent_plist.reset_iterator();
}
static void rename_playlists()
{
string new_name;
list<libsaria::Playlist *>::iterator it = playlist_stack.begin();
for (unsigned int i = 0; i < (playlist_stack.size() - num_static); i++) {
switch ((*it)->get_type()) {
case PLIST_SET:
new_name = "Set [" + itoa(i) + "]";
break;
case PLIST_QUEUE:
new_name = "Queue [" + itoa(i) + "]";
break;
case PLIST_LIST:
new_name = "List [" + itoa(i) + "]";
}
(*it)->rename(new_name);
it++;
}
}
namespace libsaria
{
@ -54,6 +75,7 @@ namespace libsaria
plist->prepare_for_removal();
delete plist;
playlist_stack.pop_front();
rename_playlists();
};
}
@ -75,12 +97,13 @@ namespace libsaria
switch (type) {
case PLIST_SET:
plist = new Set("Set [" + get_next_name() + "]", PL_NONE);
plist = new Set(PL_NONE);
break;
case PLIST_QUEUE:
plist = new Queue("Queue [" + get_next_name() + "]", PL_NONE);
plist = new Queue(PL_NONE);
break;
default:
plist = new List("List [" + get_next_name() + "]", PL_NONE);
plist = new List(PL_NONE);
};
if (on_new_playlist)
@ -88,6 +111,7 @@ namespace libsaria
plist->add_tracks(tracks);
stack::push(plist);
rename_playlists();
next_playlist++;
}