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 import helldon as hildon
29 from playerwindow import open_playerwindow
30 from showartist import ShowArtist
31 from showalbum import ShowAlbum
32 from settings import settings
34 from fetcher import Fetcher
37 from albumlist import MusicList
39 log = logging.getLogger(__name__)
47 class FavoritesWindow(hildon.StackableWindow):
49 hildon.StackableWindow.__init__(self)
50 self.set_title("Favorites")
51 self.connect('destroy', self.on_destroy)
55 self.panarea = hildon.PannableArea()
56 self.favorites = MusicList()
57 self.favorites.connect('row-activated', self.row_activated)
58 self.panarea.add(self.favorites)
59 self.add(self.panarea)
62 self.favorites.loading_message = """give your username
63 to the settings dialog
67 self.favorites.loading_message = """Loading favorites"""
69 self.start_favorites_fetcher()
71 def on_destroy(self, wnd):
76 def start_favorites_fetcher(self):
83 for item in jamaendo.favorite_albums(settings.user):
84 generated.append(item.ID)
86 fav = [f[1] for f in settings.favorites \
87 if isinstance(f, tuple) and \
90 f[1] not in generated]
91 for item in jamaendo.get_albums(fav):
94 self.fetcher = Fetcher(gen,
96 on_item = self.on_favorites_result,
97 on_ok = self.on_favorites_complete,
98 on_fail = self.on_favorites_complete)
101 def on_favorites_result(self, wnd, item):
103 if item.ID not in self.idmap:
104 self.idmap[item.ID] = item
105 self.favorites.add_items([item])
107 def on_favorites_complete(self, wnd, error=None):
112 def get_item_text(self, item):
113 if isinstance(item, jamaendo.Album):
114 return "%s - %s" % (item.artist_name, item.name)
115 elif isinstance(item, jamaendo.Track):
116 return "%s - %s" % (item.artist_name, item.name)
120 def row_activated(self, treeview, path, view_column):
121 _id = self.favorites.get_item_id(path)
122 item = self.idmap.get(_id)
126 def open_item(self, item):
127 if isinstance(item, jamaendo.Album):
128 wnd = ShowAlbum(item)
130 elif isinstance(item, jamaendo.Artist):
131 wnd = ShowArtist(item)
133 elif isinstance(item, jamaendo.Track):
134 wnd = open_playerwindow()
135 wnd.play_tracks([item])