Major list upgrade - now images in most places, and when selecting a featured track...
[jamaendo] / jamaui / featured.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 from showartist import ShowArtist
29 from showalbum import ShowAlbum
30 from albumlist import MusicList
31 from player import Playlist
32
33 def _alist(l, match):
34     for key, value in l:
35         if key == match:
36             return value
37     return None
38
39 class FeaturedWindow(hildon.StackableWindow):
40     features = (("Albums of the week",jamaendo.albums_of_the_week),
41                 ("Tracks of the week",jamaendo.tracks_of_the_week),
42                 ("New releases",jamaendo.new_releases),
43                 ("Top 50 tags", lambda: jamaendo.top_tags(count=50)),
44                 ("Top 50 albums", lambda: jamaendo.top_albums(count=50)),
45                 ("Top 50 tracks", lambda: jamaendo.top_tracks(count=50)),
46                 )
47
48     def __init__(self, feature):
49         hildon.StackableWindow.__init__(self)
50         self.set_title(feature)
51
52         self.featurefn = _alist(self.features, feature)
53
54         # Results list
55         self.panarea = hildon.PannableArea()
56         self.musiclist = MusicList()
57         self.musiclist.connect('row-activated', self.row_activated)
58         self.panarea.add(self.musiclist)
59
60         self.idmap = {}
61         self.items = self.featurefn()
62         for item in self.items:
63             self.idmap[item.ID] = item
64         self.musiclist.add_items(self.items)
65
66         self.add(self.panarea)
67
68         self.create_menu()
69
70     def create_menu(self):
71         def on_player(*args):
72             from playerwindow import open_playerwindow
73             open_playerwindow()
74         self.menu = hildon.AppMenu()
75         player = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
76         player.set_label("Open player")
77         player.connect("clicked", on_player)
78         self.menu.append(player)
79         self.menu.show_all()
80         self.set_app_menu(self.menu)
81
82     def row_activated(self, treeview, path, view_column):
83         _id = self.musiclist.get_item_id(path)
84         item = self.idmap[_id]
85         self.open_item(item)
86
87     def open_item(self, item):
88         if isinstance(item, jamaendo.Album):
89             wnd = ShowAlbum(item)
90             wnd.show_all()
91         elif isinstance(item, jamaendo.Artist):
92             wnd = ShowArtist(item)
93             wnd.show_all()
94         elif isinstance(item, jamaendo.Track):
95             playlist = Playlist(self.items)
96             playlist.jump_to(item.ID)
97             wnd = open_playerwindow()
98             wnd.play_tracks(playlist)
99         elif isinstance(item, jamaendo.Tag):
100             wnd = open_playerwindow()
101             wnd.play_tracks(jamaendo.get_tag_tracks(item.ID))