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 log = logging.getLogger(__name__)
41 class FavoritesWindow(hildon.StackableWindow):
43 hildon.StackableWindow.__init__(self)
44 self.set_title("Favorites")
48 self.panarea = hildon.PannableArea()
49 self.result_store = gtk.ListStore(str, int)
50 #self.result_store.append(['red'])
51 self.result_view = gtk.TreeView(self.result_store)
52 col = gtk.TreeViewColumn('Name')
53 self.result_view.append_column(col)
54 cell = gtk.CellRendererText()
55 col.pack_start(cell, True)
56 col.add_attribute(cell, 'text', 0)
57 self.result_view.set_search_column(0)
58 col.set_sort_column_id(0)
59 self.result_view.connect('row-activated', self.row_activated)
61 self.panarea.add(self.result_view)
65 for item in jamaendo.favorite_albums(settings.user):
66 self.idmap[item.ID] = item
67 self.result_store.append([self.get_item_text(item), item.ID])
68 except jamaendo.JamendoAPIException, e:
69 msg = "Query failed, is the user name '%s' correct?" % (settings.user)
70 banner = hildon.hildon_banner_show_information(self, '',
72 banner.set_timeout(3000)
75 def add_album(albumid):
76 album = jamaendo.get_album(albumid)
77 self.idmap[albumid] = album
78 self.result_store.append([self.get_item_text(album), albumid])
80 for item in settings.favorites:
82 if isinstance(item, tuple) and len(item) == 2:
87 except jamaendo.JamendoAPIException, e:
88 log.exception("jamaendo.get_album(%s)"%(fid))
90 self.add(self.panarea)
95 lbl.set_markup("""<span size="xx-large">jamendo.com
96 in the settings dialog
97 enter your username</span>
99 lbl.set_single_line_mode(False)
100 vbox.pack_start(lbl, True, False)
103 def get_item_text(self, item):
104 if isinstance(item, jamaendo.Album):
105 return "%s - %s" % (item.artist_name, item.name)
106 elif isinstance(item, jamaendo.Track):
107 return "%s - %s" % (item.artist_name, item.name)
111 def make_button(self, text, subtext, callback):
112 button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT,
113 hildon.BUTTON_ARRANGEMENT_VERTICAL)
114 button.set_text(text, subtext)
117 button.connect('clicked', callback)
119 #image = gtk.image_new_from_stock(gtk.STOCK_INFO, gtk.ICON_SIZE_BUTTON)
120 #button.set_image(image)
121 #button.set_image_position(gtk.POS_RIGHT)
125 def row_activated(self, treeview, path, view_column):
126 treeiter = self.result_store.get_iter(path)
127 title, _id = self.result_store.get(treeiter, 0, 1)
128 item = self.idmap[_id]
132 def open_item(self, item):
133 if isinstance(item, jamaendo.Album):
134 wnd = ShowAlbum(item)
136 elif isinstance(item, jamaendo.Artist):
137 wnd = ShowArtist(item)
139 elif isinstance(item, jamaendo.Track):
140 wnd = open_playerwindow()
141 wnd.play_tracks([item])