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 showartist import ShowArtist
29 from showalbum import ShowAlbum
37 class FeaturedWindow(hildon.StackableWindow):
38 features = (("Albums of the week",jamaendo.albums_of_the_week),
39 ("Tracks of the week",jamaendo.tracks_of_the_week),
40 ("New releases",jamaendo.new_releases)
43 def __init__(self, feature):
44 hildon.StackableWindow.__init__(self)
45 self.set_title("Featured")
47 self.featurefn = _alist(self.features, feature)
50 self.panarea = hildon.PannableArea()
51 self.result_store = gtk.ListStore(str, int)
52 #self.result_store.append(['red'])
53 self.result_view = gtk.TreeView(self.result_store)
54 col = gtk.TreeViewColumn('Name')
55 self.result_view.append_column(col)
56 cell = gtk.CellRendererText()
57 col.pack_start(cell, True)
58 col.add_attribute(cell, 'text', 0)
59 self.result_view.set_search_column(0)
60 col.set_sort_column_id(0)
61 self.result_view.connect('row-activated', self.row_activated)
63 self.panarea.add(self.result_view)
66 for item in self.featurefn():
67 self.idmap[item.ID] = item
68 self.result_store.append([self.get_item_text(item), item.ID])
70 self.add(self.panarea)
72 def get_item_text(self, item):
73 if isinstance(item, jamaendo.Album):
74 return "%s - %s" % (item.artist_name, item.name)
75 elif isinstance(item, jamaendo.Track):
76 return "%s - %s" % (item.artist_name, item.name)
80 def make_button(self, text, subtext, callback):
81 button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT,
82 hildon.BUTTON_ARRANGEMENT_VERTICAL)
83 button.set_text(text, subtext)
86 button.connect('clicked', callback)
88 #image = gtk.image_new_from_stock(gtk.STOCK_INFO, gtk.ICON_SIZE_BUTTON)
89 #button.set_image(image)
90 #button.set_image_position(gtk.POS_RIGHT)
94 def row_activated(self, treeview, path, view_column):
95 treeiter = self.result_store.get_iter(path)
96 title, _id = self.result_store.get(treeiter, 0, 1)
97 item = self.idmap[_id]
101 def open_item(self, item):
102 if isinstance(item, jamaendo.Album):
103 wnd = ShowAlbum(item)
105 elif isinstance(item, jamaendo.Artist):
106 wnd = ShowArtist(item)
108 elif isinstance(item, jamaendo.Track):
109 wnd = open_playerwindow()
110 wnd.play_tracks([item])