1 | import rb |
---|
2 | import gtk |
---|
3 | import urlparse |
---|
4 | import urllib |
---|
5 | import subprocess |
---|
6 | |
---|
7 | # UI Change is an extra item added to right-click menu when clicking on tracks |
---|
8 | popup_ui = """ |
---|
9 | <ui> |
---|
10 | <popup name="BrowserSourceViewPopup"> |
---|
11 | <menuitem name="Gutenbach" action="SendToGutenbach"/> |
---|
12 | </popup> |
---|
13 | </ui> |
---|
14 | """ |
---|
15 | class GutenbachPlugin(rb.Plugin): |
---|
16 | def __init__(self): |
---|
17 | rb.Plugin.__init__(self) |
---|
18 | |
---|
19 | def activate(self, shell): |
---|
20 | self.shell = shell |
---|
21 | # Create action for sending a track to gutenbach |
---|
22 | action = gtk.Action('SendToGutenbach', _('Send to gutenbach'), |
---|
23 | _("Queue selected tracks to the gutenbach server."), |
---|
24 | "") |
---|
25 | action.connect('activate', self.gutenbach_action, shell) |
---|
26 | action_group = gtk.ActionGroup('GutenbachActionGroup') |
---|
27 | action_group.add_action(action) |
---|
28 | manager = shell.get_ui_manager() |
---|
29 | manager.insert_action_group(action_group) |
---|
30 | manager.add_ui_from_string(popup_ui) |
---|
31 | |
---|
32 | # Default configuration options |
---|
33 | self.printer = "pikamp3" |
---|
34 | self.printer_host = "lbsg.mit.edu" |
---|
35 | |
---|
36 | def deactivate(self, shell): |
---|
37 | del self.shell |
---|
38 | |
---|
39 | def gutenbach_action(self, action, shell): |
---|
40 | source = shell.get_property("selected-source") |
---|
41 | # For each track currently selected in the song browser |
---|
42 | for entry in source.get_entry_view().get_selected_entries(): |
---|
43 | # Only play files that are stored on the user's computer |
---|
44 | uri = entry.get_playback_uri() |
---|
45 | p = urlparse.urlparse(urllib.unquote(uri)) |
---|
46 | if p.scheme == "file": |
---|
47 | path = p.path |
---|
48 | if self.printer_host: |
---|
49 | printer = '@'.join([self.printer, self.printer_host]) |
---|
50 | else: |
---|
51 | printer = self.printer |
---|
52 | command = 'lpr -P %s "%s"' % (printer, path) |
---|
53 | print command |
---|
54 | subprocess.Popen(command, shell=True) |
---|
55 | |
---|