da10c777c87d6f52b60c8576d38a0786dc79b1c4
[jamaendo] / jamaui / radios.py
1 #!/usr/bin/env python
2 #
3 # This file is part of Jamaendo.
4 # Copyright (c) 2010 Kristoffer Gronlund
5 #
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.
10 #
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.
15 #
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/>.
18 #
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)
23 #
24 import gtk
25 import hildon
26 import jamaendo
27 from playerwindow import open_playerwindow
28 from albumlist import RadioList
29
30 class RadiosWindow(hildon.StackableWindow):
31     def __init__(self):
32         hildon.StackableWindow.__init__(self)
33         self.set_title("Radios")
34
35         # Results list
36         self.panarea = hildon.PannableArea()
37         self.radiolist = RadioList()
38         self.radiolist.connect('row-activated', self.row_activated)
39
40         self.panarea.add(self.radiolist)
41
42         self.radios = {}
43         hildon.hildon_gtk_window_set_progress_indicator(self, 1)
44         radios = jamaendo.starred_radios()
45         for item in radios:
46             self.radios[item.ID] = item
47         self.radiolist.add_radios(radios)
48         hildon.hildon_gtk_window_set_progress_indicator(self, 0)
49
50         self.add(self.panarea)
51
52     def make_button(self, text, subtext, callback):
53         button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT,
54                                hildon.BUTTON_ARRANGEMENT_VERTICAL)
55         button.set_text(text, subtext)
56
57         if callback:
58             button.connect('clicked', callback)
59
60         return button
61
62     def row_activated(self, treeview, path, view_column):
63         name, _id = self.radiolist.get_radio_id(path)
64         wnd = open_playerwindow()
65         wnd.play_radio(name, _id)