A thousand cuts..
[jamaendo] / jamaui / showalbum.py
index ab3371b..0818d17 100644 (file)
@@ -1,20 +1,53 @@
+#!/usr/bin/env python
+#
+# This file is part of Jamaendo.
+# Copyright (c) 2010 Kristoffer Gronlund
+#
+# Jamaendo is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Jamaendo is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Jamaendo.  If not, see <http://www.gnu.org/licenses/>.
+#
+# Player code heavily based on http://thpinfo.com/2008/panucci/:
+#  A resuming media player for Podcasts and Audiobooks
+#  Copyright (c) 2008-05-26 Thomas Perl <thpinfo.com>
+#  (based on http://pygstdocs.berlios.de/pygst-tutorial/seeking.html)
+#
 import gtk
 import hildon
 import jamaendo
 from playerwindow import open_playerwindow
 from settings import settings
+from postoffice import postoffice
 import util
+import logging
+from albumlist import TrackList
+import webbrowser
+
+log = logging.getLogger(__name__)
 
 class ShowAlbum(hildon.StackableWindow):
     def __init__(self, album):
         hildon.StackableWindow.__init__(self)
-        self.set_title("Album")
+        self.set_title(album.artist_name)
         self.album = album
 
-        top_vbox = gtk.VBox()
+        self.connect('destroy', self.on_destroy)
+
         top_hbox = gtk.HBox()
         vbox1 = gtk.VBox()
         self.cover = gtk.Image()
+        tmp = util.find_resource('album.png')
+        if tmp:
+            self.cover.set_from_file(tmp)
         self.bbox = gtk.HButtonBox()
         self.bbox.set_property('layout-style', gtk.BUTTONBOX_SPREAD)
         self.goto_artist = self.make_imagebutton('artist', self.on_goto_artist)
@@ -27,33 +60,16 @@ class ShowAlbum(hildon.StackableWindow):
         self.playbtn.connect('clicked', self.on_play)
 
         vbox2 = gtk.VBox()
-        self.albumtitle = gtk.Label()
-        self.albumtitle.set_markup('<big>%s</big>' % (album.name))
-        self.artist = gtk.Label()
-        self.artist.set_markup('<span color="#cccccc">%s</span>'%(album.artist_name))
+        self.albumname = gtk.Label()
+        self.albumname.set_markup('<big>%s</big>'%(album.name))
         self.trackarea = hildon.PannableArea()
 
-        self.album_store = gtk.ListStore(int, str, int)
-        self.album_view = gtk.TreeView(self.album_store)
-        col0 = gtk.TreeViewColumn('Num')
-        col = gtk.TreeViewColumn('Name')
-        self.album_view.append_column(col0)
-        self.album_view.append_column(col)
-        cell0 = gtk.CellRendererText()
-        col0.pack_start(cell0, True)
-        col0.add_attribute(cell0, 'text', 0)
-        cell = gtk.CellRendererText()
-        col.pack_start(cell, True)
-        col.add_attribute(cell, 'text', 1)
-        self.album_view.set_search_column(1)
-        col.set_sort_column_id(0)
-        self.album_view.connect('row-activated', self.row_activated)
+        self.tracks = TrackList(numbers=True)
+        self.tracks.connect('row-activated', self.row_activated)
 
         for track in jamaendo.get_tracks(album.ID):
-            self.album_store.append([track.numalbum, track.name, track.ID])
+            self.tracks.add_track(track)
 
-        top_vbox.pack_start(self.albumtitle, False)
-        top_vbox.pack_start(top_hbox)
         top_hbox.pack_start(vbox1, False)
         top_hbox.pack_start(vbox2, True)
         vbox1.pack_start(self.cover, True)
@@ -63,17 +79,24 @@ class ShowAlbum(hildon.StackableWindow):
         self.bbox.add(self.download)
         self.bbox.add(self.favorite)
         self.bbox.add(self.license)
-        vbox2.pack_start(self.artist, False)
+        vbox2.pack_start(self.albumname, False)
         vbox2.pack_start(self.trackarea, True)
-        self.trackarea.add(self.album_view)
+        self.trackarea.add(self.tracks)
 
-        self.add(top_vbox)
+        self.add(top_hbox)
 
-        coverfile = jamaendo.get_album_cover(self.album.ID, size=200)
-        self.cover.set_from_file(coverfile)
+        postoffice.connect('album-cover', self, self.on_album_cover)
+        postoffice.notify('request-album-cover', self.album.ID, 300)
 
         self.show_all()
 
+    def on_destroy(self, wnd):
+        postoffice.disconnect('album-cover', self)
+
+    def on_album_cover(self, albumid, size, cover):
+        if albumid == self.album.ID and size == 300:
+            self.cover.set_from_file(cover)
+
     def make_imagebutton(self, name, cb):
         btn = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
         btn.set_relief(gtk.RELIEF_NONE)
@@ -91,8 +114,10 @@ class ShowAlbum(hildon.StackableWindow):
         self.open_item(artist)
 
     def on_download(self, btn):
-        banner = hildon.hildon_banner_show_information(self, '', "Downloads disabled in this version")
+        banner = hildon.hildon_banner_show_information(self, '', "Opening in web browser")
         banner.set_timeout(2000)
+        url = self.album.torrent_url()
+        webbrowser.open_new(url)
 
     def on_favorite(self, btn):
         settings.favorite(self.album)
@@ -101,15 +126,17 @@ class ShowAlbum(hildon.StackableWindow):
 
 
     def on_license(self, btn):
+        banner = hildon.hildon_banner_show_information(self, '', "Opening in web browser")
+        banner.set_timeout(2000)
         url = self.album.license_url
-        import webbrowser
         webbrowser.open_new(url)
 
     def on_play(self, btn):
         self.open_item(self.album)
 
     def row_activated(self, treeview, path, view_column):
-        pass
+        _id = self.tracks.get_track_id(path)
+        log.debug("clicked %s", _id)
 
     def open_item(self, item):
         if isinstance(item, jamaendo.Album):