Some licensing stuff
[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 import hildon
26 import jamaendo
27 from playerwindow import open_playerwindow
28
29 class ShowArtist(hildon.StackableWindow):
30     def __init__(self, artist):
31         hildon.StackableWindow.__init__(self)
32         self.set_title("Artist")
33         self.artist = artist
34
35         self.panarea = hildon.PannableArea()
36         vbox = gtk.VBox(False, 0)
37
38         name = gtk.Label()
39         name.set_markup('<big>%s</big>'%(artist.name))
40         vbox.pack_start(name, False)
41
42         self.album_store = gtk.ListStore(str, int)
43         self.album_view = gtk.TreeView(self.album_store)
44         col = gtk.TreeViewColumn('Name')
45         self.album_view.append_column(col)
46         cell = gtk.CellRendererText()
47         col.pack_start(cell, True)
48         col.add_attribute(cell, 'text', 0)
49         self.album_view.set_search_column(0)
50         col.set_sort_column_id(0)
51         self.album_view.connect('row-activated', self.row_activated)
52
53
54         self.panarea.add(self.album_view)
55         vbox.pack_start(self.panarea, True, True, 0)
56         self.add(vbox)
57
58         for album in jamaendo.get_albums(artist.ID):
59             self.album_store.append([album.name, album.ID])
60
61     def row_activated(self, treeview, path, view_column):
62         treeiter = self.album_store.get_iter(path)
63         title, _id = self.album_store.get(treeiter, 0, 1)
64         album = jamaendo.get_album(_id)
65         if isinstance(album, list):
66             album = album[0]
67         self.open_item(album)
68
69     def open_item(self, item):
70         if isinstance(item, jamaendo.Album):
71             from showalbum import ShowAlbum
72             wnd = ShowAlbum(item)
73             wnd.show_all()
74         elif isinstance(item, jamaendo.Artist):
75             wnd = ShowArtist(item)
76             wnd.show_all()
77         elif isinstance(item, jamaendo.Track):
78             wnd = open_playerwindow()
79             wnd.play_tracks([item])