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)
28 import helldon as hildon
30 from settings import settings
33 log = logging.getLogger(__name__)
41 def _show_banner(parent, message, timeout = 2000):
42 banner = hildon.hildon_banner_show_information(parent, '', message)
43 banner.set_timeout(2000)
45 from listbox import ListDialog
47 def add_to_playlist(wnd, track):
49 _show_banner(wnd, "Nothing to add")
52 dialog = ListDialog('Add to playlist', wnd)
53 for name,_ in settings.playlists.iteritems():
54 dialog.listbox.append(name)
55 dialog.listbox.append("New...")
58 if dialog.run() == gtk.RESPONSE_OK:
59 selected_playlist = dialog.selected
60 if selected_playlist == "New...":
62 selected_playlist = create_new_playlist(wnd)
63 if track and selected_playlist:
64 if isinstance(track, (list, tuple)):
66 settings.add_to_playlist(selected_playlist, {'id':t.ID, 'data':t.get_data()})
68 settings.add_to_playlist(selected_playlist, {'id':track.ID, 'data':track.get_data()})
70 _show_banner(wnd, "Added to playlist '%s'" % (selected_playlist))
74 def create_new_playlist(wnd):
75 dia_name = gtk.Dialog()
76 dia_name.set_title("New playlist")
77 dia_name.add_button( gtk.STOCK_OK, gtk.RESPONSE_OK )
78 entry = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
79 entry.set_placeholder("Enter name")
80 entry.set_max_length(32)
81 entry.connect('activate', lambda entry, dialog: dialog.response(gtk.RESPONSE_OK), dia_name)
82 dia_name.vbox.pack_start(entry, True, True, 0)
84 if dia_name.run() != gtk.RESPONSE_OK:
86 selected_playlist = entry.get_text()
88 if selected_playlist == '' or selected_playlist == 'New...':
90 elif settings.get_playlist(selected_playlist):
91 _show_banner(wnd, "Playlist '%s' already exists!" % (selected_playlist))
93 return selected_playlist
96 class PlaylistsWindow(hildon.StackableWindow):
98 hildon.StackableWindow.__init__(self)
99 self.set_title("Playlists")
101 self.panarea = hildon.PannableArea()
103 (self.COL_NAME, self.COL_INFO) = range(2)
104 self.store = gtk.ListStore(str, str)
105 self.treeview = gtk.TreeView()
106 self.treeview.set_model(self.store)
108 col = gtk.TreeViewColumn('Name')
109 self.treeview.append_column(col)
110 cell = gtk.CellRendererText()
111 col.pack_start(cell, True)
112 col.add_attribute(cell, 'text', self.COL_NAME)
113 self.treeview.set_search_column(self.COL_NAME)
114 col.set_sort_column_id(self.COL_NAME)
116 col = gtk.TreeViewColumn('Info')
117 self.treeview.append_column(col)
118 cell = gtk.CellRendererText()
119 cell.set_property('xalign', 1.0)
120 col.pack_start(cell, True)
121 col.add_attribute(cell, 'text', self.COL_INFO)
123 self.treeview.connect('row-activated', self.row_activated)
125 self.panarea.add(self.treeview)
127 self.add(self.panarea)
132 return "(%d tracks)"%(ln)
137 for key, lst in sorted(list(settings.playlists.iteritems())):
138 self.store.append([key, trackcount(lst)])
140 def row_activated(self, treeview, path, view_column):
141 name = self.store.get(self.store.get_iter(path), self.COL_NAME)[0]
142 pl = settings.get_playlist(name)
144 from playerwindow import open_playerwindow
145 wnd = open_playerwindow()