ocarina: Add a sort button
I also respond to the PLAYLIST_SORTED notification so we do the right thing when loading a playlist during startup. I don't put the sort button on the library, recent list or banned list because I don't think these lists should ever be sorted. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
9933b31353
commit
21313e9b52
|
@ -40,6 +40,7 @@ void on_notify(notify_t event, void *data)
|
|||
case PLAYLIST_RENUMBER:
|
||||
case PLAYLIST_DISABLE:
|
||||
case PLAYLIST_RANDOM:
|
||||
case PLAYLIST_SORTED:
|
||||
update_tabs(event, (libsaria::Playlist *)data);
|
||||
break;
|
||||
case PLAYLIST_ADD:
|
||||
|
|
|
@ -15,6 +15,7 @@ enum ExtraWidgets {
|
|||
CLOSE_BUTTON = (1 << 0),
|
||||
DISABLE_BUTTON = (1 << 1),
|
||||
RANDOM_BUTTON = (1 << 2),
|
||||
SORT_BUTTON = (1 << 3),
|
||||
};
|
||||
|
||||
struct PlaylistWidgets {
|
||||
|
@ -29,6 +30,7 @@ struct PlaylistWidgets {
|
|||
GtkEntry *entry;
|
||||
GtkToggleButton *disable;
|
||||
GtkToggleButton *random;
|
||||
GtkToggleButton *sort;
|
||||
};
|
||||
|
||||
/* library.cpp */
|
||||
|
|
|
@ -399,6 +399,12 @@ static void playlist_random(GtkToggleButton *button, gpointer data)
|
|||
playlist->set_random(gtk_toggle_button_get_active(button));
|
||||
}
|
||||
|
||||
static void playlist_sort(GtkToggleButton *button, gpointer data)
|
||||
{
|
||||
struct libsaria::Playlist *playlist = (libsaria::Playlist *)data;
|
||||
playlist->set_sorted(gtk_toggle_button_get_active(button));
|
||||
}
|
||||
|
||||
void setup_widgets(struct PlaylistWidgets *widgets, libsaria::Playlist *playlist)
|
||||
{
|
||||
unsigned int num_columns = sizeof(types) / sizeof(GType);
|
||||
|
@ -469,6 +475,19 @@ static GtkWidget *setup_random_button(struct PlaylistWidgets *widgets)
|
|||
return GTK_WIDGET(widgets->random);
|
||||
}
|
||||
|
||||
static GtkWidget *setup_sort_button(struct PlaylistWidgets *widgets)
|
||||
{
|
||||
GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_SORT_ASCENDING, GTK_ICON_SIZE_MENU);
|
||||
widgets->sort = GTK_TOGGLE_BUTTON(gtk_toggle_button_new());
|
||||
|
||||
gtk_button_set_image(GTK_BUTTON(widgets->sort), image);
|
||||
gtk_widget_set_name(GTK_WIDGET(widgets->sort), "ocarina-small-button");
|
||||
gtk_toggle_button_set_active(widgets->sort, widgets->playlist->get_sorted());
|
||||
g_signal_connect(GTK_WIDGET(widgets->sort), "toggled", G_CALLBACK(playlist_sort), widgets->playlist);
|
||||
|
||||
return GTK_WIDGET(widgets->sort);
|
||||
}
|
||||
|
||||
static void add_column(GtkTreeView *treeview, const string &title, int index,
|
||||
GtkTreeViewColumnSizing sizing, unsigned int fixed_width)
|
||||
{
|
||||
|
@ -497,6 +516,8 @@ void setup_playlist_page(struct PlaylistWidgets *widgets, int flags)
|
|||
gtk_box_pack_start(GTK_BOX(top_box), GTK_WIDGET(widgets->entry), TRUE, TRUE, 0);
|
||||
if (flags & RANDOM_BUTTON)
|
||||
gtk_box_pack_start(GTK_BOX(top_box), setup_random_button(widgets), FALSE, FALSE, 0);
|
||||
if (flags & SORT_BUTTON)
|
||||
gtk_box_pack_start(GTK_BOX(top_box), setup_sort_button(widgets), FALSE, FALSE, 0);
|
||||
if (flags & DISABLE_BUTTON)
|
||||
gtk_box_pack_start(GTK_BOX(top_box), setup_disable_button(widgets), FALSE, FALSE, 0);
|
||||
|
||||
|
|
|
@ -214,7 +214,7 @@ static void new_playlist(libsaria::Playlist *playlist)
|
|||
dynamic_widgets.push_back(widgets);
|
||||
init_page(playlist->get_name(), widgets, playlist,
|
||||
libsaria::deck::get_playlist_index(playlist),
|
||||
CLOSE_BUTTON | DISABLE_BUTTON | RANDOM_BUTTON);
|
||||
CLOSE_BUTTON | DISABLE_BUTTON | RANDOM_BUTTON | SORT_BUTTON);
|
||||
gtk_notebook_set_tab_reorderable(tabs, GTK_WIDGET(widgets->page_box), true);
|
||||
}
|
||||
|
||||
|
@ -259,6 +259,13 @@ static void random_playlist(libsaria::Playlist *playlist)
|
|||
gtk_toggle_button_set_active(widgets->random, playlist->get_random());
|
||||
}
|
||||
|
||||
static void sort_playlist(libsaria::Playlist *playlist)
|
||||
{
|
||||
struct PlaylistWidgets *widgets = find_playlist_widgets(playlist);
|
||||
if (widgets)
|
||||
gtk_toggle_button_set_active(widgets->sort, playlist->get_sorted());
|
||||
}
|
||||
|
||||
void update_tabs(notify_t event, libsaria::Playlist *playlist)
|
||||
{
|
||||
if (event == PLAYLIST_NEW)
|
||||
|
@ -271,4 +278,6 @@ void update_tabs(notify_t event, libsaria::Playlist *playlist)
|
|||
disable_playlist(playlist);
|
||||
else if (event == PLAYLIST_RANDOM)
|
||||
random_playlist(playlist);
|
||||
else if (event == PLAYLIST_SORTED)
|
||||
sort_playlist(playlist);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue