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)
27 from playerwindow import open_playerwindow
28 from settings import settings
31 class ShowAlbum(hildon.StackableWindow):
32 def __init__(self, album):
33 hildon.StackableWindow.__init__(self)
34 self.set_title("Album")
40 self.cover = gtk.Image()
41 self.bbox = gtk.HButtonBox()
42 self.bbox.set_property('layout-style', gtk.BUTTONBOX_SPREAD)
43 self.goto_artist = self.make_imagebutton('artist', self.on_goto_artist)
44 self.download = self.make_imagebutton('download', self.on_download)
45 self.favorite = self.make_imagebutton('favorite', self.on_favorite)
46 self.license = self.make_imagebutton('license', self.on_license)
47 self.playbtn = hildon.GtkButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
48 self.playbtn.set_label("Play album")
49 self.playbtn.set_border_width(0)
50 self.playbtn.connect('clicked', self.on_play)
53 self.albumtitle = gtk.Label()
54 self.albumtitle.set_markup('<big>%s</big>' % (album.name))
55 self.artist = gtk.Label()
56 self.artist.set_markup('<span color="#cccccc">%s</span>'%(album.artist_name))
57 self.trackarea = hildon.PannableArea()
59 self.album_store = gtk.ListStore(int, str, int)
60 self.album_view = gtk.TreeView(self.album_store)
61 col0 = gtk.TreeViewColumn('Num')
62 col = gtk.TreeViewColumn('Name')
63 self.album_view.append_column(col0)
64 self.album_view.append_column(col)
65 cell0 = gtk.CellRendererText()
66 col0.pack_start(cell0, True)
67 col0.add_attribute(cell0, 'text', 0)
68 cell = gtk.CellRendererText()
69 col.pack_start(cell, True)
70 col.add_attribute(cell, 'text', 1)
71 self.album_view.set_search_column(1)
72 col.set_sort_column_id(0)
73 self.album_view.connect('row-activated', self.row_activated)
75 for track in jamaendo.get_tracks(album.ID):
76 self.album_store.append([track.numalbum, track.name, track.ID])
78 top_vbox.pack_start(self.albumtitle, False)
79 top_vbox.pack_start(top_hbox)
80 top_hbox.pack_start(vbox1, False)
81 top_hbox.pack_start(vbox2, True)
82 vbox1.pack_start(self.cover, True)
83 vbox1.pack_start(self.playbtn, False)
84 vbox1.pack_start(self.bbox, False)
85 self.bbox.add(self.goto_artist)
86 self.bbox.add(self.download)
87 self.bbox.add(self.favorite)
88 self.bbox.add(self.license)
89 vbox2.pack_start(self.artist, False)
90 vbox2.pack_start(self.trackarea, True)
91 self.trackarea.add(self.album_view)
95 coverfile = jamaendo.get_album_cover(self.album.ID, size=200)
96 self.cover.set_from_file(coverfile)
100 def make_imagebutton(self, name, cb):
101 btn = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
102 btn.set_relief(gtk.RELIEF_NONE)
103 img = util.find_resource('icon_%s.png'%(name))
105 btn.set_image(gtk.image_new_from_file(img))
107 btn.set_image(gtk.image_new_from_stock(gtk.STOCK_MEDIA_STOP, gtk.ICON_SIZE_SMALL_TOOLBAR))
108 btn.set_border_width(0)
109 btn.connect('clicked', cb)
112 def on_goto_artist(self, btn):
113 artist = jamaendo.get_artist(int(self.album.artist_id))
114 self.open_item(artist)
116 def on_download(self, btn):
117 banner = hildon.hildon_banner_show_information(self, '', "Downloads disabled in this version")
118 banner.set_timeout(2000)
120 def on_favorite(self, btn):
121 settings.favorite(self.album)
122 banner = hildon.hildon_banner_show_information(self, '', "Favorite added")
123 banner.set_timeout(2000)
126 def on_license(self, btn):
127 url = self.album.license_url
129 webbrowser.open_new(url)
131 def on_play(self, btn):
132 self.open_item(self.album)
134 def row_activated(self, treeview, path, view_column):
137 def open_item(self, item):
138 if isinstance(item, jamaendo.Album):
139 tracks = jamaendo.get_tracks(item.ID)
141 wnd = open_playerwindow()
142 wnd.play_tracks(tracks)
143 elif isinstance(item, jamaendo.Artist):
144 from showartist import ShowArtist
145 wnd = ShowArtist(item)
147 elif isinstance(item, jamaendo.Track):
148 wnd = open_playerwindow()
149 wnd.play_tracks([item])