545d0aec954e5a77f8d7fef1dce745ccc8e5f29b
[jamaendo] / jamaui / radios.py
1 import gtk
2 import hildon
3 import jamaendo
4 from playerwindow import open_playerwindow
5
6 class RadiosWindow(hildon.StackableWindow):
7     def __init__(self):
8         hildon.StackableWindow.__init__(self)
9         self.set_title("Radios")
10
11         # Results list
12         self.panarea = hildon.PannableArea()
13         self.result_store = gtk.ListStore(str, int)
14         #self.result_store.append(['red'])
15         self.result_view = gtk.TreeView(self.result_store)
16         col = gtk.TreeViewColumn('Name')
17         self.result_view.append_column(col)
18         cell = gtk.CellRendererText()
19         col.pack_start(cell, True)
20         col.add_attribute(cell, 'text', 0)
21         self.result_view.set_search_column(0)
22         col.set_sort_column_id(0)
23         self.result_view.connect('row-activated', self.row_activated)
24
25         self.panarea.add(self.result_view)
26
27         self.radios = {}
28         hildon.hildon_gtk_window_set_progress_indicator(self, 1)
29         for item in jamaendo.starred_radios():
30             self.radios[item.ID] = item
31             self.result_store.append([self.radio_text(item), item.ID])
32         hildon.hildon_gtk_window_set_progress_indicator(self, 0)
33
34         self.add(self.panarea)
35
36     def radio_text(self, radio):
37         if radio.name and radio.idstr:
38             return "%s (%s)" % (radio.name, radio.idstr)
39         elif radio.name:
40             return radio.name
41         elif radio.idstr:
42             return radio.idstr
43         else:
44             return "Radio #%s" % (radio.ID)
45
46     def make_button(self, text, subtext, callback):
47         button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT,
48                                hildon.BUTTON_ARRANGEMENT_VERTICAL)
49         button.set_text(text, subtext)
50
51         if callback:
52             button.connect('clicked', callback)
53
54         #image = gtk.image_new_from_stock(gtk.STOCK_INFO, gtk.ICON_SIZE_BUTTON)
55         #button.set_image(image)
56         #button.set_image_position(gtk.POS_RIGHT)
57
58         return button
59
60     def row_activated(self, treeview, path, view_column):
61         treeiter = self.result_store.get_iter(path)
62         title, _id = self.result_store.get(treeiter, 0, 1)
63         item = self.radios[_id]
64         print _id, item
65         self.open_item(item)
66
67     def open_item(self, item):
68         hildon.hildon_gtk_window_set_progress_indicator(self, 1)
69         tracks = jamaendo.get_radio_tracks(item.ID)
70         hildon.hildon_gtk_window_set_progress_indicator(self, 0)
71         if tracks:
72             wnd = open_playerwindow()
73             wnd.play_tracks(tracks)