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
36 from playlists import add_to_playlist, show_banner
40 log = logging.getLogger(__name__)
42 class ShowArtist(hildon.StackableWindow):
45 def __init__(self, artist):
46 hildon.StackableWindow.__init__(self)
47 self.connect('destroy', self.on_destroy)
48 self.set_title(artist.name)
52 self.image = gtk.Image()
53 self.default_pixbuf = util.find_resource('album.png')
54 self.image.set_from_pixbuf(self.get_default_pixbuf())
56 self.panarea = hildon.PannableArea()
57 vbox = gtk.VBox(False, 0)
59 self.albums = AlbumList()
60 self.albums.loading_message = "No albums"
61 self.albums.empty_message = "No albums"
62 self.albums.show_artist(False)
63 self.albums.connect('row-activated', self.row_activated)
65 self.panarea.add(self.albums)
66 vbox.pack_start(self.panarea, True, True, 0)
69 #imgalign = gtk.Alignment(xalign=0.2, yalign=0.4, xscale=1.0)
72 self.image.set_alignment(0.5, 0.0)
74 top_hbox.pack_start(self.image, False)
75 top_hbox.pack_start(vbox)
80 self.albumlist = jamaendo.get_albums(artist.ID)
81 for album in self.albumlist:
82 self.albums.add_album(album)
83 except jamaendo.JamendoAPIException:
84 log.exception("Failed in get_albums(%s)"%(artist.ID))
86 postoffice.connect('images', self, self.on_images)
89 postoffice.notify('request-images', [self.artist.image])
93 def create_menu(self):
95 from playerwindow import open_playerwindow
97 self.menu = hildon.AppMenu()
98 player = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
99 player.set_label("Open player")
100 player.connect("clicked", on_player)
101 self.menu.append(player)
102 player = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
103 player.set_label("Add to playlist")
104 player.connect("clicked", self.on_add_to_playlist)
105 self.menu.append(player)
107 self.set_app_menu(self.menu)
109 def on_add_to_playlist(self, button, user_data=None):
113 for album in self.albumlist:
114 tracklist.extend(jamaendo.get_tracks(album.ID))
115 add_to_playlist(self, tracklist)
116 except jamaendo.JamendoAPIException:
117 log.exception("Failed to get track list for artist %s", self.artist.ID)
119 show_banner(self, "Error when opening track list")
121 def get_pixbuf(self, img):
123 return gtk.gdk.pixbuf_new_from_file_at_size(img,
126 except gobject.GError:
127 log.error("Broken image in cache: %s", img)
131 log.warning("Failed to unlink broken image.")
132 if img != self.default_pixbuf:
133 return self.get_default_pixbuf()
137 def get_default_pixbuf(self):
138 if self.default_pixbuf:
139 return self.get_pixbuf(self.default_pixbuf)
141 def on_images(self, images):
142 for url, image in images:
143 if url == self.artist.image:
144 pb = self.get_pixbuf(image)
146 self.image.set_from_pixbuf(pb)
148 def on_destroy(self, wnd):
149 postoffice.disconnect('images', self)
151 def row_activated(self, treeview, path, view_column):
152 _id = self.albums.get_album_id(path)
153 album = jamaendo.get_album(_id)
154 if isinstance(album, list):
156 self.open_item(album)
158 def open_item(self, item):
159 if isinstance(item, jamaendo.Album):
160 from showalbum import ShowAlbum
161 wnd = ShowAlbum(item)
163 elif isinstance(item, jamaendo.Artist):
164 wnd = ShowArtist(item)
166 elif isinstance(item, jamaendo.Track):
167 wnd = open_playerwindow()
168 wnd.play_tracks([item])