Debian Codegraph @

xlgui/widgets/queue.py

raw
1 # Copyright (C) 2008-2010 Adam Olsen
2 #
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2, or (at your option)
6 # any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 #
18 # The developers of the Exaile media player hereby grant permission
19 # for non-GPL compatible GStreamer and Exaile plugins to be used and
20 # distributed together with GStreamer and Exaile. This permission is
21 # above and beyond the permissions granted by the GPL license by which
22 # Exaile is covered. If you modify this code, you may extend this
23 # exception to your version of the code, but you are not obligated to
24 # do so. If you do not wish to do so, delete this exception statement
25 # from your version.
26
27 from gi.repository import Gtk
28
29 from xl.nls import gettext as _
30 from xl import main, playlist, event
31 from xlgui.widgets import dialogs
32
33 from xlgui.widgets.playlist import PlaylistPageBase, PlaylistView
34
35
36 class QueuePage(PlaylistPageBase):
37 def __init__(self, container, player):
38 PlaylistPageBase.__init__(self, player.queue, player)
39 self.plcontainer = container
40
41 self.swindow = Gtk.ScrolledWindow()
42 self.swindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
43 self.pack_start(self.swindow, True, True, 0)
44
45 self.view = PlaylistView(self.player.queue, self.player)
46 self.view.dragdrop_copyonly = True
47 self.swindow.add(self.view)
48
49 event.add_ui_callback(
50 self.on_length_changed,
51 'playlist_current_position_changed',
52 self.player.queue,
53 )
54 event.add_ui_callback(
55 self.on_length_changed, "playlist_tracks_added", self.player.queue
56 )
57 event.add_ui_callback(
58 self.on_length_changed, "playlist_tracks_removed", self.player.queue
59 )
60
61 self.show_all()
62
63 def on_length_changed(self, *args):
64 self.name_changed()
65 if len(self.player.queue) == 0:
66 self.tab.set_closable(True)
67 else:
68 self.plcontainer.show_queue(switch=False)
69 self.tab.set_closable(False)
70
71 ## NotebookPage API ##
72
73 def focus(self):
74 self.view.grab_focus()
75
76 def get_page_name(self):
77 qlen = self.player.queue.queue_length()
78 if qlen == -1:
79 return _("Queue")
80 else:
81 return _("Queue (%d)") % qlen
82
83 def set_tab(self, tab):
84 super(QueuePage, self).set_tab(tab)
85 tab.set_closable(not self.do_closing())
86
87 def do_closing(self):
88 """
89 Allows closing only if the queue is empty
90 """
91 return len(self.player.queue) != 0
92
93 ## End NotebookPage ##
94
95 def on_saveas(self):
96 exaile = main.exaile()
97 name = dialogs.ask_for_playlist_name(exaile.gui.main.window, exaile.playlists)
98 if name is not None:
99 pl = playlist.Playlist(name, self.playlist[:])
100 exaile.playlists.save_playlist(pl)
101 self.plcontainer.create_tab_from_playlist(pl)
102
103
104 # vim: et sw=4 st=4