Some licensing stuff
[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
29 class RadiosWindow(hildon.StackableWindow):
30     def __init__(self):
31         hildon.StackableWindow.__init__(self)
32         self.set_title("Radios")
33
34         # Results list
35         self.panarea = hildon.PannableArea()
36         self.result_store = gtk.ListStore(str, int)
37         #self.result_store.append(['red'])
38         self.result_view = gtk.TreeView(self.result_store)
39         col = gtk.TreeViewColumn('Name')
40         self.result_view.append_column(col)
41         cell = gtk.CellRendererText()
42         col.pack_start(cell, True)
43         col.add_attribute(cell, 'text', 0)
44         self.result_view.set_search_column(0)
45         col.set_sort_column_id(0)
46         self.result_view.connect('row-activated', self.row_activated)
47
48         self.panarea.add(self.result_view)
49
50         self.radios = {}
51         hildon.hildon_gtk_window_set_progress_indicator(self, 1)
52         for item in jamaendo.starred_radios():
53             self.radios[item.ID] = item
54             self.result_store.append([self.radio_text(item), item.ID])
55         hildon.hildon_gtk_window_set_progress_indicator(self, 0)
56
57         self.add(self.panarea)
58
59     def radio_text(self, radio):
60         if radio.name and radio.idstr:
61             return "%s (%s)" % (radio.name, radio.idstr)
62         elif radio.name:
63             return radio.name
64         elif radio.idstr:
65             return radio.idstr
66         else:
67             return "Radio #%s" % (radio.ID)
68
69     def make_button(self, text, subtext, callback):
70         button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT,
71                                hildon.BUTTON_ARRANGEMENT_VERTICAL)
72         button.set_text(text, subtext)
73
74         if callback:
75             button.connect('clicked', callback)
76
77         #image = gtk.image_new_from_stock(gtk.STOCK_INFO, gtk.ICON_SIZE_BUTTON)
78         #button.set_image(image)
79         #button.set_image_position(gtk.POS_RIGHT)
80
81         return button
82
83     def row_activated(self, treeview, path, view_column):
84         treeiter = self.result_store.get_iter(path)
85         title, _id = self.result_store.get(treeiter, 0, 1)
86         item = self.radios[_id]
87         print _id, item
88         self.open_item(item)
89
90     def open_item(self, item):
91         hildon.hildon_gtk_window_set_progress_indicator(self, 1)
92         tracks = jamaendo.get_radio_tracks(item.ID)
93         hildon.hildon_gtk_window_set_progress_indicator(self, 0)
94         if tracks:
95             wnd = open_playerwindow()
96             wnd.play_tracks(tracks)