Add a PLAYLIST_DELETE notification
Triggered when a playlist is garbage collected so the UI can remove the tab. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
95d8d83fa0
commit
5bce295251
|
@ -13,6 +13,7 @@ enum notify_t {
|
|||
PAUSE_TYPE, // AutoPauseType *
|
||||
PAUSE_COUNT, // unsigned int *
|
||||
PLAYLIST_NEW, // libsaria::Playlist *
|
||||
PLAYLIST_DELETE, // libsaria::Playlist *
|
||||
PLAYLIST_RENUMBER, // libsaria::Playlist *
|
||||
PLAYLIST_ADD, // libsaria::PlaylistNotification *
|
||||
PLAYLIST_RM, // libsaria::PlaylistNotification *
|
||||
|
|
|
@ -19,7 +19,6 @@ namespace libsaria
|
|||
Playlist *get_playlist();
|
||||
|
||||
bool is_static();
|
||||
virtual void prepare_for_removal();
|
||||
|
||||
virtual void on_disable(bool);
|
||||
|
||||
|
|
|
@ -37,7 +37,6 @@ namespace ocarina
|
|||
void list_selected_indices(list<unsigned int> &);
|
||||
|
||||
void set_playlist(libsaria::Playlist *);
|
||||
void prepare_for_removal();
|
||||
void on_disable(bool);
|
||||
|
||||
void goto_index(unsigned int);
|
||||
|
|
|
@ -77,6 +77,7 @@ namespace libsaria
|
|||
for (it = playlist_deck.begin(); it != playlist_deck.end(); it++) {
|
||||
if ((*it)->get_size() == 0) {
|
||||
(*it)->prepare_for_removal();
|
||||
notify(PLAYLIST_DELETE, *it);
|
||||
delete (*it);
|
||||
it = playlist_deck.erase(it);
|
||||
it--;
|
||||
|
|
|
@ -52,18 +52,6 @@ namespace libsaria
|
|||
{
|
||||
list<libsaria::Track *>::iterator it;
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
||||
/* Remove playlist from tracks */
|
||||
for (it = plist.begin(); it != plist.end(); it++)
|
||||
(*it)->rm_playlist(this);
|
||||
|
|
|
@ -30,10 +30,6 @@ namespace libsaria
|
|||
return (flags & PL_STATIC) == PL_STATIC;
|
||||
}
|
||||
|
||||
void PlaylistRenderer::prepare_for_removal()
|
||||
{
|
||||
}
|
||||
|
||||
void PlaylistRenderer::on_disable(bool disabled)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ void on_notify(notify_t event, void *data)
|
|||
update_autopause_count((unsigned int *)data);
|
||||
break;
|
||||
case PLAYLIST_NEW:
|
||||
case PLAYLIST_DELETE:
|
||||
case PLAYLIST_RENUMBER:
|
||||
update_tabs(event, (libsaria::Playlist *)data);
|
||||
break;
|
||||
|
|
|
@ -191,11 +191,6 @@ namespace ocarina
|
|||
//body::add_page(p->get_number(), box, label_box, p);
|
||||
}
|
||||
|
||||
void Playlist::prepare_for_removal()
|
||||
{
|
||||
//body::remove_page(box);
|
||||
}
|
||||
|
||||
void Playlist::on_disable(bool disabled)
|
||||
{
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(disable_button), disabled);
|
||||
|
|
|
@ -33,15 +33,9 @@ struct PlaylistWidgets *find_playlist_widgets(libsaria::Playlist *plist)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static unsigned int tabs_size()
|
||||
{
|
||||
GtkNotebook *tabs = GTK_NOTEBOOK(get_widget("PlaylistTabs"));
|
||||
return gtk_notebook_get_n_pages(tabs) - 3;
|
||||
}
|
||||
|
||||
static struct PlaylistWidgets *find_nth_widgets(unsigned int n)
|
||||
{
|
||||
unsigned int size = tabs_size();
|
||||
unsigned int size = dynamic_widgets.size();
|
||||
|
||||
/* Dynamic playlists */
|
||||
if (n < size)
|
||||
|
@ -72,7 +66,7 @@ libsaria::Playlist *current_playlist()
|
|||
void playlist_switch_to(string &key)
|
||||
{
|
||||
GtkNotebook *tabs = GTK_NOTEBOOK(get_widget("PlaylistTabs"));
|
||||
unsigned int size = tabs_size();
|
||||
unsigned int size = dynamic_widgets.size();
|
||||
|
||||
if (key == "l")
|
||||
gtk_notebook_set_current_page(tabs, size);
|
||||
|
@ -85,7 +79,7 @@ void playlist_switch_to(string &key)
|
|||
void playlist_switch_to_n(unsigned int n)
|
||||
{
|
||||
GtkNotebook *tabs = GTK_NOTEBOOK(get_widget("PlaylistTabs"));
|
||||
unsigned int size = tabs_size();
|
||||
unsigned int size = dynamic_widgets.size();
|
||||
if (size <= n)
|
||||
return;
|
||||
gtk_notebook_set_current_page(tabs, n);
|
||||
|
@ -195,6 +189,20 @@ static void new_playlist(libsaria::Playlist *playlist)
|
|||
add_page(GTK_WIDGET(widgets->page_box), make_tab_label(playlist->get_name(), widgets), 0);
|
||||
}
|
||||
|
||||
static void delete_playlist(libsaria::Playlist *playlist)
|
||||
{
|
||||
struct PlaylistWidgets *widgets = find_playlist_widgets(playlist);
|
||||
int page_num = gtk_notebook_page_num(GTK_NOTEBOOK(get_widget("PlaylistTabs")),
|
||||
GTK_WIDGET(widgets->page_box));
|
||||
int cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(get_widget("PlaylistTabs")));
|
||||
|
||||
if (cur_page == page_num)
|
||||
gtk_notebook_set_current_page(GTK_NOTEBOOK(get_widget("PlaylistTabs")), cur_page + 1);
|
||||
|
||||
dynamic_widgets.remove(widgets);
|
||||
gtk_notebook_remove_page(GTK_NOTEBOOK(get_widget("PlaylistTabs")), page_num);
|
||||
}
|
||||
|
||||
static void renumber_playlist(libsaria::Playlist *playlist)
|
||||
{
|
||||
stringstream s;
|
||||
|
@ -210,6 +218,8 @@ void update_tabs(notify_t event, libsaria::Playlist *playlist)
|
|||
{
|
||||
if (event == PLAYLIST_NEW)
|
||||
new_playlist(playlist);
|
||||
else if (event == PLAYLIST_DELETE)
|
||||
delete_playlist(playlist);
|
||||
else if (event == PLAYLIST_RENUMBER)
|
||||
renumber_playlist(playlist);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue