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)
27 from settings import settings
30 log = logging.getLogger(__name__)
38 def _show_banner(parent, message, timeout = 2000):
39 banner = hildon.hildon_banner_show_information(parent, '', message)
40 banner.set_timeout(2000)
42 from listbox import ListDialog
44 def add_to_playlist(wnd, track):
46 _show_banner(wnd, "Nothing to add")
49 dialog = ListDialog('Add to playlist', wnd)
50 for name,_ in settings.playlists.iteritems():
51 dialog.listbox.append(name)
52 dialog.listbox.append("New...")
55 if dialog.run() == gtk.RESPONSE_OK:
56 selected_playlist = dialog.selected
57 if selected_playlist == "New...":
59 selected_playlist = create_new_playlist(wnd)
60 if track and selected_playlist:
61 if isinstance(track, (list, tuple)):
63 settings.add_to_playlist(selected_playlist, {'id':t.ID, 'data':t.get_data()})
65 settings.add_to_playlist(selected_playlist, {'id':track.ID, 'data':track.get_data()})
67 _show_banner(wnd, "Added to playlist '%s'" % (selected_playlist))
71 def create_new_playlist(wnd):
72 dia_name = gtk.Dialog()
73 dia_name.set_title("New playlist")
74 dia_name.add_button( gtk.STOCK_OK, gtk.RESPONSE_OK )
75 entry = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
76 entry.set_placeholder("Enter name")
77 entry.set_max_length(32)
78 entry.connect('activate', lambda entry, dialog: dialog.response(gtk.RESPONSE_OK), dia_name)
79 dia_name.vbox.pack_start(entry, True, True, 0)
81 if dia_name.run() != gtk.RESPONSE_OK:
83 selected_playlist = entry.get_text()
85 if selected_playlist == '' or selected_playlist == 'New...':
87 elif settings.get_playlist(selected_playlist):
88 _show_banner(wnd, "Playlist '%s' already exists!" % (selected_playlist))
90 return selected_playlist
93 class PlaylistsWindow(hildon.StackableWindow):
95 hildon.StackableWindow.__init__(self)
96 self.set_title("Playlists")
98 self.panarea = hildon.PannableArea()
100 (self.COL_NAME, self.COL_INFO) = range(2)
101 self.store = gtk.ListStore(str, str)
102 self.treeview = gtk.TreeView()
103 self.treeview.set_model(self.store)
105 col = gtk.TreeViewColumn('Name')
106 self.treeview.append_column(col)
107 cell = gtk.CellRendererText()
108 col.pack_start(cell, True)
109 col.add_attribute(cell, 'text', self.COL_NAME)
110 self.treeview.set_search_column(self.COL_NAME)
111 col.set_sort_column_id(self.COL_NAME)
113 col = gtk.TreeViewColumn('Info')
114 self.treeview.append_column(col)
115 cell = gtk.CellRendererText()
116 cell.set_property('xalign', 1.0)
117 col.pack_start(cell, True)
118 col.add_attribute(cell, 'text', self.COL_INFO)
120 self.treeview.connect('row-activated', self.row_activated)
122 self.panarea.add(self.treeview)
124 self.add(self.panarea)
129 return "(%d tracks)"%(ln)
134 for key, lst in sorted(list(settings.playlists.iteritems())):
135 self.store.append([key, trackcount(lst)])
137 def row_activated(self, treeview, path, view_column):
138 name = self.store.get(self.store.get_iter(path), self.COL_NAME)[0]
139 pl = settings.get_playlist(name)
141 from playerwindow import open_playerwindow
142 wnd = open_playerwindow()