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)
28 import helldon as hildon
30 from playerwindow import open_playerwindow
31 from showartist import ShowArtist
32 from showalbum import ShowAlbum
33 from settings import settings
36 from albumlist import AlbumList
38 log = logging.getLogger(__name__)
46 class FavoritesWindow(hildon.StackableWindow):
48 hildon.StackableWindow.__init__(self)
49 self.set_title("Favorites")
53 self.panarea = hildon.PannableArea()
54 self.results = AlbumList()
55 self.results.connect('row-activated', self.row_activated)
56 self.panarea.add(self.results)
60 def add_album(ID, album_factory):
61 if ID not in self.idmap:
62 album = album_factory()
63 self.idmap[ID] = album
64 self.results.add_album(album)
67 for item in jamaendo.favorite_albums(settings.user):
68 add_album(item.ID, lambda: item)
69 except jamaendo.JamendoAPIException, e:
70 msg = "Query failed, is the user name '%s' correct?" % (settings.user)
71 banner = hildon.hildon_banner_show_information(self, '',
73 banner.set_timeout(3000)
75 favorite_albums = [f[1] for f in settings.favorites if isinstance(f, tuple) and len(f) == 2 and f[0] == 'album' and f[1] not in self.idmap]
77 for album in jamaendo.get_albums(favorite_albums):
78 add_album(album.ID, lambda: album)
80 except jamaendo.JamendoAPIException, e:
81 log.exception("jamaendo.get_albums(%s)"%(favorite_albums))
83 self.add(self.panarea)
88 lbl.set_markup("""<span size="xx-large">jamendo.com
89 in the settings dialog
90 enter your username</span>
92 lbl.set_single_line_mode(False)
93 vbox.pack_start(lbl, True, False)
96 def get_item_text(self, item):
97 if isinstance(item, jamaendo.Album):
98 return "%s - %s" % (item.artist_name, item.name)
99 elif isinstance(item, jamaendo.Track):
100 return "%s - %s" % (item.artist_name, item.name)
104 def make_button(self, text, subtext, callback):
105 button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT,
106 hildon.BUTTON_ARRANGEMENT_VERTICAL)
107 button.set_text(text, subtext)
110 button.connect('clicked', callback)
112 #image = gtk.image_new_from_stock(gtk.STOCK_INFO, gtk.ICON_SIZE_BUTTON)
113 #button.set_image(image)
114 #button.set_image_position(gtk.POS_RIGHT)
118 def row_activated(self, treeview, path, view_column):
119 _id = self.results.get_album_id(path)
120 item = self.idmap[_id]
124 def open_item(self, item):
125 if isinstance(item, jamaendo.Album):
126 wnd = ShowAlbum(item)
128 elif isinstance(item, jamaendo.Artist):
129 wnd = ShowArtist(item)
131 elif isinstance(item, jamaendo.Track):
132 wnd = open_playerwindow()
133 wnd.play_tracks([item])