Added 'helldon' to transparently port the thing to the desktop :P
[jamaendo] / jamaui / showartist.py
1 #!/usr/bin/env python
2 #
3 # This file is part of Jamaendo.
4 # Copyright (c) 2010 Kristoffer Gronlund
5 #
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.
10 #
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.
15 #
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/>.
18 #
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)
23 #
24 import gtk
25 try:
26     import hildon
27 except:
28     import helldon as hildon
29 import jamaendo
30 from playerwindow import open_playerwindow
31 from albumlist import AlbumList
32
33 class ShowArtist(hildon.StackableWindow):
34     def __init__(self, artist):
35         hildon.StackableWindow.__init__(self)
36         self.set_title(artist.name)
37         self.artist = artist
38
39         self.panarea = hildon.PannableArea()
40         vbox = gtk.VBox(False, 0)
41
42         self.albums = AlbumList()
43         self.albums.show_artist(False)
44         self.albums.connect('row-activated', self.row_activated)
45
46         self.panarea.add(self.albums)
47         vbox.pack_start(self.panarea, True, True, 0)
48         self.add(vbox)
49
50         for album in jamaendo.get_albums(artist.ID):
51             self.albums.add_album(album)
52
53     def row_activated(self, treeview, path, view_column):
54         _id = self.albums.get_album_id(path)
55         album = jamaendo.get_album(_id)
56         if isinstance(album, list):
57             album = album[0]
58         self.open_item(album)
59
60     def open_item(self, item):
61         if isinstance(item, jamaendo.Album):
62             from showalbum import ShowAlbum
63             wnd = ShowAlbum(item)
64             wnd.show_all()
65         elif isinstance(item, jamaendo.Artist):
66             wnd = ShowArtist(item)
67             wnd.show_all()
68         elif isinstance(item, jamaendo.Track):
69             wnd = open_playerwindow()
70             wnd.play_tracks([item])