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),
41 ("Top 50 tags", lambda: jamaendo.top_tags(count=50)),
42 ("Top 50 albums", lambda: jamaendo.top_albums(count=50)),
43 ("Top 50 tracks", lambda: jamaendo.top_tracks(count=50)),
46 def __init__(self, feature):
47 hildon.StackableWindow.__init__(self)
48 self.set_title("Featured")
50 self.featurefn = _alist(self.features, feature)
53 self.panarea = hildon.PannableArea()
54 self.result_store = gtk.ListStore(str, int)
55 #self.result_store.append(['red'])
56 self.result_view = gtk.TreeView(self.result_store)
57 col = gtk.TreeViewColumn('Name')
58 self.result_view.append_column(col)
59 cell = gtk.CellRendererText()
60 col.pack_start(cell, True)
61 col.add_attribute(cell, 'text', 0)
62 self.result_view.set_search_column(0)
63 col.set_sort_column_id(0)
64 self.result_view.connect('row-activated', self.row_activated)
66 self.panarea.add(self.result_view)
69 for item in self.featurefn():
70 self.idmap[item.ID] = item
71 self.result_store.append([self.get_item_text(item), item.ID])
73 self.add(self.panarea)
77 def create_menu(self):
79 from playerwindow import open_playerwindow
81 self.menu = hildon.AppMenu()
82 player = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
83 player.set_label("Open player")
84 player.connect("clicked", on_player)
85 self.menu.append(player)
87 self.set_app_menu(self.menu)
89 def get_item_text(self, item):
90 if isinstance(item, jamaendo.Album):
91 return "%s - %s" % (item.artist_name, item.name)
92 elif isinstance(item, jamaendo.Track):
93 return "%s - %s" % (item.artist_name, item.name)
97 def make_button(self, text, subtext, callback):
98 button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT,
99 hildon.BUTTON_ARRANGEMENT_VERTICAL)
100 button.set_text(text, subtext)
103 button.connect('clicked', callback)
105 #image = gtk.image_new_from_stock(gtk.STOCK_INFO, gtk.ICON_SIZE_BUTTON)
106 #button.set_image(image)
107 #button.set_image_position(gtk.POS_RIGHT)
111 def row_activated(self, treeview, path, view_column):
112 treeiter = self.result_store.get_iter(path)
113 title, _id = self.result_store.get(treeiter, 0, 1)
114 item = self.idmap[_id]
118 def open_item(self, item):
119 if isinstance(item, jamaendo.Album):
120 wnd = ShowAlbum(item)
122 elif isinstance(item, jamaendo.Artist):
123 wnd = ShowArtist(item)
125 elif isinstance(item, jamaendo.Track):
126 wnd = open_playerwindow()
127 wnd.play_tracks([item])
128 elif isinstance(item, jamaendo.Tag):
129 wnd = open_playerwindow()
130 wnd.play_tracks(jamaendo.get_tag_tracks(item.ID))