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 for item in settings.favorites:
74 if isinstance(item, tuple) and len(item) == 2:
77 add_album(fid, lambda: jamaendo.get_album(fid))
79 except jamaendo.JamendoAPIException, e:
80 log.exception("jamaendo.get_album(%s)"%(fid))
82 self.add(self.panarea)
87 lbl.set_markup("""<span size="xx-large">jamendo.com
88 in the settings dialog
89 enter your username</span>
91 lbl.set_single_line_mode(False)
92 vbox.pack_start(lbl, True, False)
95 def get_item_text(self, item):
96 if isinstance(item, jamaendo.Album):
97 return "%s - %s" % (item.artist_name, item.name)
98 elif isinstance(item, jamaendo.Track):
99 return "%s - %s" % (item.artist_name, item.name)
103 def make_button(self, text, subtext, callback):
104 button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT,
105 hildon.BUTTON_ARRANGEMENT_VERTICAL)
106 button.set_text(text, subtext)
109 button.connect('clicked', callback)
111 #image = gtk.image_new_from_stock(gtk.STOCK_INFO, gtk.ICON_SIZE_BUTTON)
112 #button.set_image(image)
113 #button.set_image_position(gtk.POS_RIGHT)
117 def row_activated(self, treeview, path, view_column):
118 _id = self.results.get_album_id(path)
119 item = self.idmap[_id]
123 def open_item(self, item):
124 if isinstance(item, jamaendo.Album):
125 wnd = ShowAlbum(item)
127 elif isinstance(item, jamaendo.Artist):
128 wnd = ShowArtist(item)
130 elif isinstance(item, jamaendo.Track):
131 wnd = open_playerwindow()
132 wnd.play_tracks([item])