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
30 from settings import settings
33 from albumlist import AlbumList
35 log = logging.getLogger(__name__)
43 class FavoritesWindow(hildon.StackableWindow):
45 hildon.StackableWindow.__init__(self)
46 self.set_title("Favorites")
50 self.panarea = hildon.PannableArea()
51 self.results = AlbumList()
52 self.results.connect('row-activated', self.row_activated)
53 self.panarea.add(self.results)
57 def add_album(ID, album_factory):
58 if ID not in self.idmap:
59 album = album_factory()
60 self.idmap[ID] = album
61 self.results.add_album(album)
64 for item in jamaendo.favorite_albums(settings.user):
65 add_album(item.ID, lambda: item)
66 except jamaendo.JamendoAPIException, e:
67 msg = "Query failed, is the user name '%s' correct?" % (settings.user)
68 banner = hildon.hildon_banner_show_information(self, '',
70 banner.set_timeout(3000)
72 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]
74 for album in jamaendo.get_albums(favorite_albums):
75 add_album(album.ID, lambda: album)
77 except jamaendo.JamendoAPIException, e:
78 log.exception("jamaendo.get_albums(%s)"%(favorite_albums))
80 self.add(self.panarea)
85 lbl.set_markup("""<span size="xx-large">jamendo.com
86 in the settings dialog
87 enter your username</span>
89 lbl.set_single_line_mode(False)
90 vbox.pack_start(lbl, True, False)
93 def get_item_text(self, item):
94 if isinstance(item, jamaendo.Album):
95 return "%s - %s" % (item.artist_name, item.name)
96 elif isinstance(item, jamaendo.Track):
97 return "%s - %s" % (item.artist_name, item.name)
101 def make_button(self, text, subtext, callback):
102 button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT,
103 hildon.BUTTON_ARRANGEMENT_VERTICAL)
104 button.set_text(text, subtext)
107 button.connect('clicked', callback)
109 #image = gtk.image_new_from_stock(gtk.STOCK_INFO, gtk.ICON_SIZE_BUTTON)
110 #button.set_image(image)
111 #button.set_image_position(gtk.POS_RIGHT)
115 def row_activated(self, treeview, path, view_column):
116 _id = self.results.get_album_id(path)
117 item = self.idmap[_id]
121 def open_item(self, item):
122 if isinstance(item, jamaendo.Album):
123 wnd = ShowAlbum(item)
125 elif isinstance(item, jamaendo.Artist):
126 wnd = ShowArtist(item)
128 elif isinstance(item, jamaendo.Track):
129 wnd = open_playerwindow()
130 wnd.play_tracks([item])