X-Git-Url: http://git.maemo.org/git/?p=jamaendo;a=blobdiff_plain;f=jamaui%2Fplayerwindow.py;h=65fe075124da0ad0d8b1d2dea8015a79bc441d2d;hp=23e684cfcddf3d7b804895337714d21f2c4a4577;hb=8a3c7548a482e76d6d29fa4c2968984eba3d6c7d;hpb=075b350ccd54818888b4149962de512489c42b0c diff --git a/jamaui/playerwindow.py b/jamaui/playerwindow.py index 23e684c..65fe075 100644 --- a/jamaui/playerwindow.py +++ b/jamaui/playerwindow.py @@ -1,13 +1,48 @@ +#!/usr/bin/env python +# +# This file is part of Jamaendo. +# Copyright (c) 2010 Kristoffer Gronlund +# +# Jamaendo is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Jamaendo is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Jamaendo. If not, see . +# +# Player code heavily based on http://thpinfo.com/2008/panucci/: +# A resuming media player for Podcasts and Audiobooks +# Copyright (c) 2008-05-26 Thomas Perl +# (based on http://pygstdocs.berlios.de/pygst-tutorial/seeking.html) +# import gtk import hildon import jamaendo +from settings import settings from player import Playlist, the_player +_player_window = None + +def album_cover_receiver(albumid, size, cover): + if _player_window: + playing = _player_window.get_album_id() + if int(playing) == int(albumid): + _player_window.set_album_cover(cover) + class PlayerWindow(hildon.StackableWindow): def __init__(self, playlist=None): hildon.StackableWindow.__init__(self) self.set_title("jamaendo") + global _player_window + _player_window = self + self.connect('hide', self.on_hide) self.connect('destroy', self.on_destroy) @@ -35,7 +70,7 @@ class PlayerWindow(hildon.StackableWindow): track = pl.current() self.set_labels(track.name, track.artist_name, track.album_name, pl.current_index(), pl.size()) else: - self.set_labels('track name', 'artist', 'album', 0, 0) + self.set_labels('', '', '', 0, 0) vbox2.pack_start(self.track, True) vbox2.pack_start(self.artist, False) @@ -59,15 +94,29 @@ class PlayerWindow(hildon.StackableWindow): self.add_stock_button(btns, gtk.STOCK_MEDIA_STOP, self.on_stop) self.add_stock_button(btns, gtk.STOCK_MEDIA_NEXT, self.on_next) + self.volume = hildon.VVolumebar() + self.volume.set_property('can-focus', False) + self.volume.connect('level_changed', self.volume_changed_hildon) + self.volume.connect('mute_toggled', self.mute_toggled) + #self.__gui_root.main_window.connect( 'key-press-event', + # self.on_key_press ) + hbox.pack_start(self.volume, False) self.add(vbox) print "Created player window, playlist: %s" % (self.playlist) + def get_album_id(self): + if self.playlist and self.playlist.current_index() > -1: + return self.playlist.current().album_id + return None + def on_hide(self, wnd): print "Hiding player window" def on_destroy(self, wnd): print "Destroying player window" + global _player_window + _player_window = None if self.player: self.player.stop() @@ -84,6 +133,16 @@ class PlayerWindow(hildon.StackableWindow): self.artist.set_markup('%s'%(artist)) self.album.set_markup('%s'%(album)) + + def volume_changed_hildon(self, widget): + settings.volume = widget.get_level()/100.0 + + def mute_toggled(self, widget): + if widget.get_mute(): + settings.volume = 0 + else: + settings.volume = widget.get_level()/100.0 + def update_state(self): item = self.playlist.current() if item: @@ -92,9 +151,13 @@ class PlayerWindow(hildon.StackableWindow): print "current:", item self.set_labels(item.name, item.artist_name, item.album_name, 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) + jamaendo.get_album_cover_async(album_cover_receiver, int(item.album_id), size=200) + #coverfile = jamaendo.get_album_cover(int(item.album_id), size=200) + #print "coverfile:", coverfile + #self.cover.set_from_file(coverfile) + + def set_album_cover(self, cover): + self.cover.set_from_file(cover) def play_tracks(self, tracks): self.playlist = Playlist(tracks) @@ -115,7 +178,7 @@ class PlayerWindow(hildon.StackableWindow): def on_stop(self, button): self.player.stop() -def open_playerwindow(tracks): +def open_playerwindow(tracks=None): player = PlayerWindow(tracks) player.show_all() return player