ac3e2ed4c4414ff15007eef3703563e6dbf000b5
[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 try:
26     import hildon
27 except:
28     import helldon as hildon
29 import jamaendo
30 from playerwindow import open_playerwindow
31 from albumlist import RadioList
32 from fetcher import Fetcher
33
34 class RadiosWindow(hildon.StackableWindow):
35     def __init__(self):
36         hildon.StackableWindow.__init__(self)
37         self.fetcher = None
38         self.radios = {}
39
40         self.set_title("Radios")
41         self.connect('destroy', self.on_destroy)
42
43         # Results list
44         self.panarea = hildon.PannableArea()
45         self.radiolist = RadioList()
46         self.radiolist.connect('row-activated', self.row_activated)
47         self.panarea.add(self.radiolist)
48         self.add(self.panarea)
49
50         self.start_radio_fetcher()
51
52     def on_destroy(self, wnd):
53         if self.fetcher:
54             self.fetcher.stop()
55             self.fetcher = None
56
57     def row_activated(self, treeview, path, view_column):
58         name, _id = self.radiolist.get_radio_id(path)
59         wnd = open_playerwindow()
60         wnd.play_radio(name, _id)
61
62     def start_radio_fetcher(self):
63         if self.fetcher:
64             self.fetcher.stop()
65             self.fetcher = None
66         self.fetcher = Fetcher(jamaendo.starred_radios, self,
67                                on_item = self.on_radio_result,
68                                on_ok = self.on_radio_complete,
69                                on_fail = self.on_radio_complete)
70         self.fetcher.start()
71
72     def on_radio_result(self, wnd, item):
73         if wnd is self:
74             self.radios[item.ID] = item
75             self.radiolist.add_radios([item])
76
77     def on_radio_complete(self, wnd, error=None):
78         if wnd is self:
79             self.fetcher.stop()
80             self.fetcher = None