return self.items[self._current]
return None
+ def prev(self):
+ if self.has_prev():
+ self._current = self._current - 1
+ return self.items[self._current]
+ return None
+
def has_next(self):
return self._current < (len(self.items)-1)
+ def has_prev(self):
+ return self._current > 0
+
def current(self):
if self._current >= 0:
return self.items[self._current]
def current_index(self):
return self._current
- def __len__(self):
+ def size(self):
+ print type(self)
return len(self.items)
+ def __repr__(self):
+ return "Playlist(%s)"%(", ".join([str(item) for item in self.items]))
+
class Player(Playlist):
def __init__(self):
self.backend = PlayerBackend()
self.backend.set_eos_callback(self._on_eos)
- self.playlist = None
+ self.playlist = Playlist()
def play(self, playlist = None):
if playlist:
self.playlist = playlist
- if self.playlist is not None:
+ elif self.playlist is None:
+ self.playlist = Playlist()
+ if self.playlist.size():
if self.playlist.has_next():
entry = self.playlist.next()
log.debug("playing %s", entry)
self.stop()
def prev(self):
- pass
+ if self.playlist.has_prev():
+ entry = self.playlist.prev()
+ log.debug("playing %s", entry)
+ self.backend.play_url('mp3', entry.mp3_url())
def _on_eos(self):
log.debug("EOS!")
DBusGMainLoop(set_as_default=True)
+_the_playerwindow = None
+
class PlayerWindow(hildon.StackableWindow):
def __init__(self, playlist=None):
hildon.StackableWindow.__init__(self)
self.set_title("jamaendo")
+ self.connect('hide', self.on_hide)
+ self.connect('destroy', self.on_destroy)
+
self.playlist = Playlist(playlist)
self.player = Player()
hbox = gtk.HBox()
self.cover = gtk.Image()
- self.cover.set_size_request(160, 160)
+ self.cover.set_size_request(200, 200)
self.cover.set_from_stock(gtk.STOCK_CDROM, gtk.ICON_SIZE_DIALOG)
vbox2 = gtk.VBox()
self.set_labels('track name', 'artist', 'album', 0, 0)
- vbox2.pack_start(self.playlist_pos, False)
- vbox2.pack_start(self.track, False)
- vbox2.pack_start(self.progress, True, True)
+ vbox2.pack_start(self.track, True)
vbox2.pack_start(self.artist, False)
vbox2.pack_start(self.album, False)
+ vbox2.pack_start(self.playlist_pos, False)
+ vbox2.pack_start(self.progress, False)
hbox.pack_start(self.cover, True, True, 0)
hbox.pack_start(vbox2, True, True, 0)
self.add(vbox)
+ print "Created player window, playlist: %s" % (self.playlist)
+
+ def on_hide(self, wnd):
+ print "Hiding player window"
+
+ def on_destroy(self, wnd):
+ print "Destroying player window"
+ if self.player:
+ self.player.stop()
+ global _the_playerwindow
+ _the_playerwindow = None
+
def add_stock_button(self, btns, stock, cb):
btn = hildon.GtkButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
btn.set_relief(gtk.RELIEF_NONE)
def set_labels(self, track, artist, album, playlist_pos, playlist_size):
self.playlist_pos.set_markup('<span size="small">%s/%s songs</span>'%(playlist_pos, playlist_size))
- self.track.set_markup('<span size="large">%s</span>'%(track))
- self.artist.set_markup(artist)
- self.album.set_markup('<span foreground="#cccccc">%s</span>'%(album))
+ self.track.set_markup('<span size="x-large">%s</span>'%(track))
+ self.artist.set_markup('<span size="large">%s</span>'%(artist))
+ self.album.set_markup('<span foreground="#aaaaaa">%s</span>'%(album))
def update_state(self):
item = self.playlist.current()
item.load()
print "current:", item
self.set_labels(item.name, item.artist_name, item.album_name,
- self.playlist.current_index(), len(self.playlist))
- self.cover.set_from_file(jamaendo.get_album_cover(item.album_id, size=160))
+ self.playlist.current_index(), self.playlist.size())
+ coverfile = jamaendo.get_album_cover(int(item.album_id), size=200)
+ print "coverfile:", coverfile
+ self.cover.set_from_file(coverfile)
+
+ def play_tracks(self, tracks):
+ self.playlist = Playlist(playlist)
+ self.player.play(self.playlist)
+ self.update_state()
def on_play(self, button):
self.player.play(self.playlist)
def on_stop(self, button):
self.player.stop()
+def open_playerwindow(tracks):
+ global _the_playerwindow
+ if _the_playerwindow:
+ hildon.WindowStack.push_1(_the_playerwindow)
+ _the_playerwindow.play_tracks(tracks)
+ else:
+ _the_playerwindow = PlayerWindow(tracks)
+ _the_playerwindow.show_all()
+ return _the_playerwindow
+
class SearchWindow(hildon.StackableWindow):
def __init__(self):
hildon.StackableWindow.__init__(self)
album = self.idmap[current_selection]
tracks = jamaendo.get_tracks(album.ID)
if tracks:
- self.pwnd = PlayerWindow(tracks)
- self.pwnd.show_all()
+ wnd = open_playerwindow(tracks)
+ wnd.on_play(None)
class RadiosWindow(hildon.StackableWindow):
def __init__(self):
self.favoriteswnd.show_all()
def on_player(self, button):
- self.playerwnd = PlayerWindow()
- self.playerwnd.show_all()
+ open_playerwindow([])
'''
def on_search(self, button):