3 # This file is part of Jamaendo.
4 # Copyright (c) 2010 Kristoffer Gronlund
6 # Jamaendo is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # Jamaendo is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with Jamaendo. If not, see <http://www.gnu.org/licenses/>.
19 # Player code heavily based on http://thpinfo.com/2008/panucci/:
20 # A resuming media player for Podcasts and Audiobooks
21 # Copyright (c) 2008-05-26 Thomas Perl <thpinfo.com>
22 # (based on http://pygstdocs.berlios.de/pygst-tutorial/seeking.html)
29 import helldon as hildon
31 from playerwindow import open_playerwindow
32 from albumlist import AlbumList
33 from postoffice import postoffice
39 log = logging.getLogger(__name__)
41 class ShowArtist(hildon.StackableWindow):
44 def __init__(self, artist):
45 hildon.StackableWindow.__init__(self)
46 self.connect('destroy', self.on_destroy)
47 self.set_title(artist.name)
51 self.image = gtk.Image()
52 self.default_pixbuf = util.find_resource('album.png')
53 self.image.set_from_pixbuf(self.get_default_pixbuf())
55 self.panarea = hildon.PannableArea()
56 vbox = gtk.VBox(False, 0)
58 self.albums = AlbumList()
59 self.albums.loading_message = "No albums"
60 self.albums.empty_message = "No albums"
61 self.albums.show_artist(False)
62 self.albums.connect('row-activated', self.row_activated)
64 self.panarea.add(self.albums)
65 vbox.pack_start(self.panarea, True, True, 0)
68 #imgalign = gtk.Alignment(xalign=0.2, yalign=0.4, xscale=1.0)
71 self.image.set_alignment(0.5, 0.0)
73 top_hbox.pack_start(self.image, False)
74 top_hbox.pack_start(vbox)
79 for album in jamaendo.get_albums(artist.ID):
80 self.albums.add_album(album)
81 except jamaendo.JamendoAPIException:
82 log.exception("Failed in get_albums(%s)"%(artist.ID))
84 postoffice.connect('images', self, self.on_images)
87 postoffice.notify('request-images', [self.artist.image])
89 def get_pixbuf(self, img):
91 return gtk.gdk.pixbuf_new_from_file_at_size(img,
94 except gobject.GError:
95 log.error("Broken image in cache: %s", img)
99 log.warning("Failed to unlink broken image.")
100 if img != self.default_pixbuf:
101 return self.get_default_pixbuf()
105 def get_default_pixbuf(self):
106 if self.default_pixbuf:
107 return self.get_pixbuf(self.default_pixbuf)
109 def on_images(self, images):
110 for url, image in images:
111 if url == self.artist.image:
112 pb = self.get_pixbuf(image)
114 self.image.set_from_pixbuf(pb)
116 def on_destroy(self, wnd):
117 postoffice.disconnect('images', self)
119 def row_activated(self, treeview, path, view_column):
120 _id = self.albums.get_album_id(path)
121 album = jamaendo.get_album(_id)
122 if isinstance(album, list):
124 self.open_item(album)
126 def open_item(self, item):
127 if isinstance(item, jamaendo.Album):
128 from showalbum import ShowAlbum
129 wnd = ShowAlbum(item)
131 elif isinstance(item, jamaendo.Artist):
132 wnd = ShowArtist(item)
134 elif isinstance(item, jamaendo.Track):
135 wnd = open_playerwindow()
136 wnd.play_tracks([item])