# Bryan Schumaker (11/26/2010)

import libsaria
import sources
import body

playlist = libsaria.sources.playlist
playlist_page = sources.Source()
PLAYLIST_PAGE = body.add_page(playlist_page, "Playlist")
PLAYLIST_PAGE.goto = playlist_page.goto

def set_label_text():
	PLAYLIST_PAGE.label.set_text("Playlist (%s)" % playlist.num_visible())

def fill_playlist():
	songs = libsaria.sources.list_playlist(*sources.column.attrs)
	playlist_page.insert(songs)
	set_label_text()
fill_playlist()

def refresh():
	playlist_page.clear()
	fill_playlist()

def refilter():
	playlist_page.refilter()
	playlist_page.goto()
	set_label_text()

def clear():
	playlist_page.clear()
	playlist.reset()
	refresh()
PLAYLIST_PAGE.clear = clear

def add_to_playlist(menu):
	ids = menu.source.get_selected_ids()
	playlist.add_ids(ids)
	refresh()

def rm_from_playlist(menu):
	ids = menu.source.get_selected_ids()
	playlist.rm_ids(ids)
	refresh()

import queue
menu_items = [
	("Add to Queue", queue.add_to_queue),
	("Remove from Playlist", rm_from_playlist),
]
def show_menu(event):
	m = sources.Menu(playlist_page, menu_items)
	m.show(event)
playlist_page.set_right_click(show_menu)
