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
29 from postoffice import postoffice
32 from albumlist import TrackList
35 log = logging.getLogger(__name__)
37 class ShowAlbum(hildon.StackableWindow):
38 def __init__(self, album):
39 hildon.StackableWindow.__init__(self)
40 self.set_title(album.artist_name)
43 self.connect('destroy', self.on_destroy)
47 self.cover = gtk.Image()
48 self.bbox = gtk.HButtonBox()
49 self.bbox.set_property('layout-style', gtk.BUTTONBOX_SPREAD)
50 self.goto_artist = self.make_imagebutton('artist', self.on_goto_artist)
51 self.download = self.make_imagebutton('download', self.on_download)
52 self.favorite = self.make_imagebutton('favorite', self.on_favorite)
53 self.license = self.make_imagebutton('license', self.on_license)
54 self.playbtn = hildon.GtkButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
55 self.playbtn.set_label("Play album")
56 self.playbtn.set_border_width(0)
57 self.playbtn.connect('clicked', self.on_play)
60 self.albumname = gtk.Label()
61 self.albumname.set_markup('<big>%s</big>'%(album.name))
62 self.trackarea = hildon.PannableArea()
64 self.tracks = TrackList(numbers=True)
65 self.tracks.connect('row-activated', self.row_activated)
67 for track in jamaendo.get_tracks(album.ID):
68 self.tracks.add_track(track)
70 top_hbox.pack_start(vbox1, False)
71 top_hbox.pack_start(vbox2, True)
72 vbox1.pack_start(self.cover, True)
73 vbox1.pack_start(self.playbtn, False)
74 vbox1.pack_start(self.bbox, False)
75 self.bbox.add(self.goto_artist)
76 self.bbox.add(self.download)
77 self.bbox.add(self.favorite)
78 self.bbox.add(self.license)
79 vbox2.pack_start(self.albumname, False)
80 vbox2.pack_start(self.trackarea, True)
81 self.trackarea.add(self.tracks)
85 postoffice.connect('album-cover', self.on_album_cover)
86 postoffice.notify('request-album-cover', self.album.ID, 300)
90 def on_destroy(self, wnd):
91 postoffice.disconnect('album-cover', self.on_album_cover)
93 def on_album_cover(self, albumid, size, cover):
94 if albumid == self.album.ID and size == 300:
95 self.cover.set_from_file(cover)
97 def make_imagebutton(self, name, cb):
98 btn = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
99 btn.set_relief(gtk.RELIEF_NONE)
100 img = util.find_resource('icon_%s.png'%(name))
102 btn.set_image(gtk.image_new_from_file(img))
104 btn.set_image(gtk.image_new_from_stock(gtk.STOCK_MEDIA_STOP, gtk.ICON_SIZE_SMALL_TOOLBAR))
105 btn.set_border_width(0)
106 btn.connect('clicked', cb)
109 def on_goto_artist(self, btn):
110 artist = jamaendo.get_artist(int(self.album.artist_id))
111 self.open_item(artist)
113 def on_download(self, btn):
114 banner = hildon.hildon_banner_show_information(self, '', "Opening in web browser")
115 banner.set_timeout(2000)
116 url = self.album.torrent_url()
117 webbrowser.open_new(url)
119 def on_favorite(self, btn):
120 settings.favorite(self.album)
121 banner = hildon.hildon_banner_show_information(self, '', "Favorite added")
122 banner.set_timeout(2000)
125 def on_license(self, btn):
126 banner = hildon.hildon_banner_show_information(self, '', "Opening in web browser")
127 banner.set_timeout(2000)
128 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):
135 _id = self.tracks.get_track_id(path)
136 log.debug("clicked %s", _id)
138 def open_item(self, item):
139 if isinstance(item, jamaendo.Album):
140 tracks = jamaendo.get_tracks(item.ID)
142 wnd = open_playerwindow()
143 wnd.play_tracks(tracks)
144 elif isinstance(item, jamaendo.Artist):
145 from showartist import ShowArtist
146 wnd = ShowArtist(item)
148 elif isinstance(item, jamaendo.Track):
149 wnd = open_playerwindow()
150 wnd.play_tracks([item])