Send a PLAYLIST_RENUMBER notification
I do this when playlists are renumbered, I also move tabs around to match their new numbers. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
d27a1fb7ba
commit
26e818cc21
|
@ -3,21 +3,22 @@
|
|||
#define LIBSARIA_NOTIFY_H
|
||||
|
||||
enum notify_t {
|
||||
IDLE_ADD, // NULL
|
||||
TRACK_CHANGED, // libsaria::Track *
|
||||
PATH_ADDED, // libsaria::library::Path *
|
||||
PATH_DELETED, // libsaria::library::Path *
|
||||
PATH_UPDATED, // libsaria::library::Path *
|
||||
PLAYING, // NULL
|
||||
PAUSED, // NULL
|
||||
PAUSE_TYPE, // AutoPauseType *
|
||||
PAUSE_COUNT, // unsigned int *
|
||||
PLAYLIST_NEW, // libsaria::Playlist *
|
||||
PLAYLIST_ADD, // libsaria::PlaylistNotification *
|
||||
PLAYLIST_RM, // libsaria::PlaylistNotification *
|
||||
PLAYLIST_UPDATE,// libsaria::PlaylistNotification *
|
||||
PLAYLIST_SIZE, // libsaria::PlaylistNotification *
|
||||
PLAYLIST_FILTER,// libsaria::PlaylistNotification *
|
||||
IDLE_ADD, // NULL
|
||||
TRACK_CHANGED, // libsaria::Track *
|
||||
PATH_ADDED, // libsaria::library::Path *
|
||||
PATH_DELETED, // libsaria::library::Path *
|
||||
PATH_UPDATED, // libsaria::library::Path *
|
||||
PLAYING, // NULL
|
||||
PAUSED, // NULL
|
||||
PAUSE_TYPE, // AutoPauseType *
|
||||
PAUSE_COUNT, // unsigned int *
|
||||
PLAYLIST_NEW, // libsaria::Playlist *
|
||||
PLAYLIST_RENUMBER, // libsaria::Playlist *
|
||||
PLAYLIST_ADD, // libsaria::PlaylistNotification *
|
||||
PLAYLIST_RM, // libsaria::PlaylistNotification *
|
||||
PLAYLIST_UPDATE, // libsaria::PlaylistNotification *
|
||||
PLAYLIST_SIZE, // libsaria::PlaylistNotification *
|
||||
PLAYLIST_FILTER, // libsaria::PlaylistNotification *
|
||||
NOTIFY_SIZE,
|
||||
};
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@ namespace libsaria
|
|||
virtual ~PlaylistRenderer();
|
||||
void set_playlist(Playlist *);
|
||||
Playlist *get_playlist();
|
||||
virtual void renumbered(int);
|
||||
|
||||
bool is_static();
|
||||
virtual void prepare_for_removal();
|
||||
|
|
|
@ -13,9 +13,11 @@ using namespace std;
|
|||
struct PlaylistWidgets {
|
||||
libsaria::Playlist *playlist;
|
||||
GtkListStore *liststore;
|
||||
GtkBox *page_box;
|
||||
GtkTreeView *treeview;
|
||||
GtkTreeModel *filter;
|
||||
GtkLabel *label;
|
||||
GtkLabel *size_label;
|
||||
GtkLabel *page_label;
|
||||
GtkEntry *entry;
|
||||
};
|
||||
|
||||
|
@ -37,7 +39,7 @@ string run_chooser(const string &);
|
|||
/* playlist.cpp */
|
||||
void update_playlist(notify_t, libsaria::PlaylistNotification *);
|
||||
void setup_widgets(struct PlaylistWidgets *, libsaria::Playlist *);
|
||||
GtkWidget *make_playlist_page(struct PlaylistWidgets *);
|
||||
void setup_playlist_page(struct PlaylistWidgets *);
|
||||
|
||||
/* status.cpp */
|
||||
bool update_idle_bar(int);
|
||||
|
@ -58,7 +60,7 @@ void playlist_focus_treeview();
|
|||
void playlist_switch_to(string &);
|
||||
void playlist_switch_to_n(unsigned int);
|
||||
void init_tabs();
|
||||
void new_playlist(libsaria::Playlist *);
|
||||
void update_tabs(notify_t, libsaria::Playlist *);
|
||||
|
||||
/* window.cpp */
|
||||
void init_window();
|
||||
|
|
|
@ -37,7 +37,6 @@ namespace ocarina
|
|||
void list_selected_indices(list<unsigned int> &);
|
||||
|
||||
void set_playlist(libsaria::Playlist *);
|
||||
void renumbered(int);
|
||||
void prepare_for_removal();
|
||||
void on_disable(bool);
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ namespace libsaria
|
|||
rm_file();
|
||||
number = n;
|
||||
schedule_save();
|
||||
RENDER( renumbered(number) );
|
||||
notify(PLAYLIST_RENUMBER, this);
|
||||
}
|
||||
|
||||
unsigned int Playlist::get_number()
|
||||
|
|
|
@ -25,10 +25,6 @@ namespace libsaria
|
|||
return playlist;
|
||||
}
|
||||
|
||||
void PlaylistRenderer::renumbered(int)
|
||||
{
|
||||
}
|
||||
|
||||
bool PlaylistRenderer::is_static()
|
||||
{
|
||||
return (flags & PL_STATIC) == PL_STATIC;
|
||||
|
|
|
@ -36,7 +36,8 @@ void on_notify(notify_t event, void *data)
|
|||
update_autopause_count((unsigned int *)data);
|
||||
break;
|
||||
case PLAYLIST_NEW:
|
||||
new_playlist((libsaria::Playlist *)data);
|
||||
case PLAYLIST_RENUMBER:
|
||||
update_tabs(event, (libsaria::Playlist *)data);
|
||||
break;
|
||||
case PLAYLIST_ADD:
|
||||
case PLAYLIST_RM:
|
||||
|
|
|
@ -78,7 +78,7 @@ static void set_playlist_size(libsaria::Playlist *plist)
|
|||
return;
|
||||
|
||||
sprintf(buf, "%u", plist->get_size());
|
||||
gtk_label_set_text(widgets->label, buf);
|
||||
gtk_label_set_text(widgets->size_label, buf);
|
||||
update_length_label();
|
||||
}
|
||||
|
||||
|
@ -173,13 +173,15 @@ void setup_widgets(struct PlaylistWidgets *widgets, libsaria::Playlist *playlist
|
|||
unsigned int num_columns = sizeof(types) / sizeof(GType);
|
||||
GtkTreeSelection *selection;
|
||||
|
||||
widgets->playlist = playlist;
|
||||
widgets->liststore = gtk_list_store_newv(num_columns, types);
|
||||
widgets->treeview = GTK_TREE_VIEW(gtk_tree_view_new());
|
||||
widgets->filter = gtk_tree_model_filter_new(
|
||||
widgets->playlist = playlist;
|
||||
widgets->liststore = gtk_list_store_newv(num_columns, types);
|
||||
widgets->page_box = GTK_BOX(gtk_vbox_new(FALSE, 0));
|
||||
widgets->treeview = GTK_TREE_VIEW(gtk_tree_view_new());
|
||||
widgets->filter = gtk_tree_model_filter_new(
|
||||
GTK_TREE_MODEL(widgets->liststore), NULL);
|
||||
widgets->label = GTK_LABEL(gtk_label_new("0"));
|
||||
widgets->entry = GTK_ENTRY(gtk_entry_new());
|
||||
widgets->size_label = GTK_LABEL(gtk_label_new("0"));
|
||||
widgets->page_label = GTK_LABEL(gtk_label_new(""));
|
||||
widgets->entry = GTK_ENTRY(gtk_entry_new());
|
||||
|
||||
selection = gtk_tree_view_get_selection(widgets->treeview);
|
||||
gtk_tree_selection_set_mode(selection,GTK_SELECTION_MULTIPLE);
|
||||
|
@ -211,17 +213,16 @@ static void add_column(GtkTreeView *treeview, const string &title, int index,
|
|||
gtk_tree_view_append_column(treeview, column);
|
||||
}
|
||||
|
||||
GtkWidget *make_playlist_page(struct PlaylistWidgets *widgets)
|
||||
void setup_playlist_page(struct PlaylistWidgets *widgets)
|
||||
{
|
||||
GtkWidget *box = gtk_vbox_new(FALSE, 0);
|
||||
GtkWidget *window = gtk_scrolled_window_new(NULL, NULL);
|
||||
|
||||
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(window),
|
||||
GTK_POLICY_AUTOMATIC,
|
||||
GTK_POLICY_AUTOMATIC);
|
||||
|
||||
gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(widgets->entry), FALSE, FALSE, 0);
|
||||
gtk_box_pack_start(GTK_BOX(box), window, TRUE, TRUE, 0);
|
||||
gtk_box_pack_start(widgets->page_box, GTK_WIDGET(widgets->entry), FALSE, FALSE, 0);
|
||||
gtk_box_pack_start(widgets->page_box, window, TRUE, TRUE, 0);
|
||||
|
||||
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(widgets->treeview));
|
||||
add_column(widgets->treeview, "#", 1, GTK_TREE_VIEW_COLUMN_FIXED, 20);
|
||||
|
@ -233,6 +234,5 @@ GtkWidget *make_playlist_page(struct PlaylistWidgets *widgets)
|
|||
add_column(widgets->treeview, "Count", 7, GTK_TREE_VIEW_COLUMN_GROW_ONLY, 1);
|
||||
add_column(widgets->treeview, "Played", 8, GTK_TREE_VIEW_COLUMN_GROW_ONLY, 1);
|
||||
|
||||
gtk_widget_show_all(box);
|
||||
return box;
|
||||
gtk_widget_show_all(GTK_WIDGET(widgets->page_box));
|
||||
}
|
||||
|
|
|
@ -188,19 +188,9 @@ namespace ocarina
|
|||
gtk_widget_show_all(entry_box);
|
||||
|
||||
set_label_text();
|
||||
renumbered(p->get_number());
|
||||
//body::add_page(p->get_number(), box, label_box, p);
|
||||
}
|
||||
|
||||
void Playlist::renumbered(int n)
|
||||
{
|
||||
stringstream s;
|
||||
if (n == -1)
|
||||
return;
|
||||
s << "<span size='x-large'>" << n << " </span>";
|
||||
gtk_label_set_markup(GTK_LABEL(number), s.str().c_str());
|
||||
}
|
||||
|
||||
void Playlist::prepare_for_removal()
|
||||
{
|
||||
//body::remove_page(box);
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
|
||||
#include <ocarina/ocarina.h>
|
||||
|
||||
#include <sstream>
|
||||
using namespace std;
|
||||
|
||||
static PlaylistWidgets library_widgets;
|
||||
static PlaylistWidgets recent_widgets;
|
||||
static PlaylistWidgets banned_widgets;
|
||||
|
@ -152,21 +155,27 @@ static void add_page(GtkWidget *page, GtkWidget *tab_label, int page_num)
|
|||
|
||||
static GtkWidget *make_tab_label(const string &name, struct PlaylistWidgets *widgets)
|
||||
{
|
||||
GtkWidget *tab = gtk_hbox_new(FALSE, 0);
|
||||
GtkWidget *box = gtk_vbox_new(FALSE, 0);
|
||||
GtkWidget *label = gtk_label_new(name.c_str());
|
||||
|
||||
gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.0);
|
||||
gtk_misc_set_alignment(GTK_MISC(widgets->label), 1.0, 0.0);
|
||||
gtk_misc_set_alignment(GTK_MISC(widgets->size_label), 1.0, 0.0);
|
||||
|
||||
gtk_box_pack_start(GTK_BOX(tab), GTK_WIDGET(widgets->page_label), FALSE, FALSE, 0);
|
||||
gtk_box_pack_start(GTK_BOX(tab), box, TRUE, TRUE, 0);
|
||||
|
||||
gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0);
|
||||
gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(widgets->label), FALSE, FALSE, 0);
|
||||
gtk_widget_show_all(box);
|
||||
return box;
|
||||
gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(widgets->size_label), FALSE, FALSE, 0);
|
||||
|
||||
gtk_widget_show_all(tab);
|
||||
return tab;
|
||||
}
|
||||
|
||||
static void init_widgets(struct PlaylistWidgets *widgets, libsaria::Playlist *playlist)
|
||||
{
|
||||
setup_widgets(widgets, playlist);
|
||||
setup_playlist_page(widgets);
|
||||
g_signal_connect(widgets->entry, "focus-in-event", G_CALLBACK(on_focus_change), NULL);
|
||||
}
|
||||
|
||||
|
@ -174,7 +183,7 @@ static void add_static_page(const string &name, struct PlaylistWidgets *widgets,
|
|||
libsaria::Playlist *playlist)
|
||||
{
|
||||
init_widgets(widgets, playlist);
|
||||
add_page(make_playlist_page(widgets), make_tab_label(name, widgets), -1);
|
||||
add_page(GTK_WIDGET(widgets->page_box), make_tab_label(name, widgets), -1);
|
||||
}
|
||||
|
||||
void init_tabs()
|
||||
|
@ -188,11 +197,30 @@ void init_tabs()
|
|||
connect_signal("PlaylistTabs", "switch-page", G_CALLBACK(on_switch_page), NULL);
|
||||
}
|
||||
|
||||
void new_playlist(libsaria::Playlist *playlist)
|
||||
static void new_playlist(libsaria::Playlist *playlist)
|
||||
{
|
||||
struct PlaylistWidgets *widgets = new struct PlaylistWidgets;
|
||||
dynamic_widgets.push_back(widgets);
|
||||
|
||||
init_widgets(widgets, playlist);
|
||||
add_page(make_playlist_page(widgets), make_tab_label(playlist->get_name(), widgets), 0);
|
||||
add_page(GTK_WIDGET(widgets->page_box), make_tab_label(playlist->get_name(), widgets), 0);
|
||||
}
|
||||
|
||||
static void renumber_playlist(libsaria::Playlist *playlist)
|
||||
{
|
||||
stringstream s;
|
||||
struct PlaylistWidgets *widgets = find_playlist_widgets(playlist);
|
||||
s << "<span size='x-large'>" << playlist->get_number() << " </span>";
|
||||
gtk_label_set_markup(widgets->page_label, s.str().c_str());
|
||||
gtk_notebook_reorder_child(GTK_NOTEBOOK(get_widget("PlaylistTabs")),
|
||||
GTK_WIDGET(widgets->page_box),
|
||||
playlist->get_number());
|
||||
}
|
||||
|
||||
void update_tabs(notify_t event, libsaria::Playlist *playlist)
|
||||
{
|
||||
if (event == PLAYLIST_NEW)
|
||||
new_playlist(playlist);
|
||||
else if (event == PLAYLIST_RENUMBER)
|
||||
renumber_playlist(playlist);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue