Reorder playlists in the playlist deck
This allows me to change playback order without having to delete old playlists and make new ones. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
874f999adf
commit
36bd2c2b66
|
@ -27,6 +27,7 @@ namespace libsaria
|
|||
|
||||
void new_playlist(list<Track *> &, PlaylistType, bool);
|
||||
void delete_playlist(Playlist *);
|
||||
unsigned int move_playlist(Playlist *, unsigned int);
|
||||
|
||||
Playlist *get_playlist(unsigned int);
|
||||
Playlist *get_recent_plist();
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define OCARINA_BODY_H
|
||||
|
||||
#include <ocarina/ocarina.h>
|
||||
#include <libsaria/playlist.h>
|
||||
|
||||
GtkWidget *get_tabs();
|
||||
GtkWidget *make_page(GtkWidget *);
|
||||
|
@ -16,7 +17,7 @@ namespace ocarina
|
|||
{
|
||||
|
||||
void init();
|
||||
void add_page(int, GtkWidget *, GtkWidget *);
|
||||
void add_page(int, GtkWidget *, GtkWidget *, libsaria::Playlist *);
|
||||
void remove_page(GtkWidget *);
|
||||
void switch_to_page(GtkWidget *);
|
||||
|
||||
|
|
|
@ -144,6 +144,25 @@ namespace libsaria
|
|||
garbage_collect();
|
||||
}
|
||||
|
||||
unsigned int deck::move_playlist(Playlist *plist, unsigned int index)
|
||||
{
|
||||
list<Playlist *>::iterator it;
|
||||
|
||||
if (index >= playlist_deck.size())
|
||||
index = playlist_deck.size() - 1;
|
||||
|
||||
playlist_deck.remove(plist);
|
||||
|
||||
it = playlist_deck.begin();
|
||||
for (unsigned int i = 0; i < index; i++)
|
||||
it++;
|
||||
|
||||
playlist_deck.insert(it, plist);
|
||||
garbage_collect();
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
void deck::init()
|
||||
{
|
||||
app::mkdir("playlist");
|
||||
|
|
|
@ -5,10 +5,15 @@
|
|||
#include <ocarina/body.h>
|
||||
|
||||
#include <libsaria/libsaria.h>
|
||||
#include <libsaria/deck.h>
|
||||
|
||||
#include <map>
|
||||
using namespace std;
|
||||
|
||||
static GtkWidget *tabs;
|
||||
static GtkWidget *action_box;
|
||||
static GtkWidget *open_button;
|
||||
static map<GtkWidget *, libsaria::Playlist *> tab_mapping;
|
||||
|
||||
static void on_click_open_file(GtkWidget *b, gpointer d)
|
||||
{
|
||||
|
@ -19,6 +24,14 @@ static void on_click_open_file(GtkWidget *b, gpointer d)
|
|||
}
|
||||
}
|
||||
|
||||
static void on_page_reordered(GtkWidget *t, GtkWidget *page, guint num, gpointer d)
|
||||
{
|
||||
libsaria::Playlist *plist = tab_mapping[page];
|
||||
unsigned int n = libsaria::deck::move_playlist(plist, num);
|
||||
if (n != num)
|
||||
gtk_notebook_reorder_child(GTK_NOTEBOOK(tabs), page, n);
|
||||
}
|
||||
|
||||
namespace ocarina
|
||||
{
|
||||
|
||||
|
@ -33,6 +46,7 @@ namespace ocarina
|
|||
gtk_notebook_set_scrollable(GTK_NOTEBOOK(tabs), true);
|
||||
gtk_notebook_set_tab_pos(GTK_NOTEBOOK(tabs), GTK_POS_LEFT);
|
||||
gtk_notebook_set_action_widget(GTK_NOTEBOOK(tabs), action_box, GTK_PACK_END);
|
||||
g_signal_connect(tabs, "page-reordered", G_CALLBACK(on_page_reordered), NULL);
|
||||
g_object_set(tabs, "tab-border", 0, NULL);
|
||||
|
||||
gtk_widget_show(tabs);
|
||||
|
@ -42,17 +56,20 @@ namespace ocarina
|
|||
return tabs;
|
||||
};
|
||||
|
||||
void body::add_page(int pg, GtkWidget *page, GtkWidget *label)
|
||||
void body::add_page(int pg, GtkWidget *page, GtkWidget *label, libsaria::Playlist *p)
|
||||
{
|
||||
if (pg == -1)
|
||||
pg = 0;
|
||||
gtk_notebook_insert_page(GTK_NOTEBOOK(tabs), page, label, pg);
|
||||
gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(tabs), page, !p->is_static());
|
||||
tab_mapping[page] = p;
|
||||
}
|
||||
|
||||
void body::remove_page(GtkWidget *page)
|
||||
{
|
||||
int pg = gtk_notebook_page_num(GTK_NOTEBOOK(tabs), page);
|
||||
gtk_notebook_remove_page(GTK_NOTEBOOK(tabs), pg);
|
||||
tab_mapping.erase(page);
|
||||
}
|
||||
|
||||
void body::switch_to_page(GtkWidget *page)
|
||||
|
|
|
@ -187,7 +187,7 @@ namespace ocarina
|
|||
|
||||
set_label_text();
|
||||
renumbered(p->get_number());
|
||||
body::add_page(p->get_number(), box, label_box);
|
||||
body::add_page(p->get_number(), box, label_box, p);
|
||||
}
|
||||
|
||||
void Playlist::renumbered(int n)
|
||||
|
|
Loading…
Reference in New Issue