Add a PLAYLIST_SIZE notification

Used to notify the UI that the playlist size has changed.  Other options
include: Set the size automatically when responding to PLAYLIST_ADD (and
evenutally "PLAYLIST_RM")

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-08-25 16:15:47 -04:00
parent 9b6665030a
commit 8583ac01d9
4 changed files with 25 additions and 1 deletions

View File

@ -12,6 +12,7 @@ enum notify_t {
PAUSE_TYPE, // AutoPauseType *
PAUSE_COUNT, // unsigned int *
PLAYLIST_ADD, // libsaria::PlaylistNotification *
PLAYLIST_SIZE, // lisbaria::PlaylistNotification *
NOTIFY_SIZE,
};

View File

@ -19,7 +19,8 @@ namespace libsaria
index.add_track(track);
track->add_playlist(this);
RENDER( insert(track, ins_index) );
notify_ui(PLAYLIST_ADD, track, ins_index);
notify_ui(PLAYLIST_ADD, track, ins_index);
notify_ui(PLAYLIST_SIZE, NULL, 0);
data_state = DIRTY;
}
@ -32,6 +33,7 @@ namespace libsaria
(*it)->rm_playlist(this);
it = plist.erase(it);
RENDER( remove_index(rm_index) );
notify_ui(PLAYLIST_SIZE, NULL, 0);
if (rm_index != 0) {
rm_index--;
it--;

View File

@ -24,6 +24,7 @@ void on_notify(notify_t event, void *data)
update_autopause_count((unsigned int *)data);
break;
case PLAYLIST_ADD:
case PLAYLIST_SIZE:
update_playlist(event, (libsaria::PlaylistNotification *)data);
default:
break;

View File

@ -7,6 +7,8 @@
#include <libsaria/deck.h>
#include <libsaria/ban.h>
#include <cstdio>
static ocarina::Playlist library_renderer(PL_STATIC);
static ocarina::Playlist recent_renderer(PL_STATIC);
static ocarina::Playlist banned_renderer(PL_STATIC);
@ -71,6 +73,13 @@ static GtkListStore *find_list(libsaria::Playlist *plist)
return NULL;
}
static GtkWidget *find_label(libsaria::Playlist *plist)
{
if (plist == libsaria::library::get_playlist())
return get_widget("LibrarySize");
return NULL;
}
static void playlist_add(libsaria::Playlist *plist, libsaria::Track *track,
unsigned int index)
{
@ -90,11 +99,22 @@ static void playlist_add(libsaria::Playlist *plist, libsaria::Track *track,
8, track->get_last_played().c_str(),
9, formatted(track->get_filepath()).c_str(),
-1);
}
static void set_playlist_size(libsaria::Playlist *plist)
{
char buf[11];
GtkWidget *label = find_label(plist);
if (label) {
sprintf(buf, "%u", plist->get_size());
gtk_label_set_text(GTK_LABEL(label), buf);
}
}
void update_playlist(notify_t event, libsaria::PlaylistNotification *data)
{
if (event == PLAYLIST_ADD)
playlist_add(data->plist, data->track, data->index);
else if (event == PLAYLIST_SIZE)
set_playlist_size(data->plist);
}