1 | from __future__ import division |
---|
2 | |
---|
3 | import rb |
---|
4 | import gtk, gtk.glade, gconf |
---|
5 | import gobject |
---|
6 | import sys, os |
---|
7 | import locale, datetime, time |
---|
8 | import subprocess |
---|
9 | import urllib |
---|
10 | import urlparse |
---|
11 | |
---|
12 | #fade_steps = 50 |
---|
13 | |
---|
14 | ui_str = ''' |
---|
15 | <ui> |
---|
16 | <popup name="BrowserSourceViewPopup"> |
---|
17 | <menuitem name="Gutenbach" action="GutenbachDialog"/> |
---|
18 | </popup> |
---|
19 | </ui> |
---|
20 | ''' |
---|
21 | |
---|
22 | class GutenbachPlugin(rb.Plugin): |
---|
23 | def __init__ (self): |
---|
24 | rb.Plugin.__init__ (self) |
---|
25 | |
---|
26 | def activate (self, shell): |
---|
27 | data = dict() |
---|
28 | manager = shell.get_player().get_property('ui-manager') |
---|
29 | self.shell = shell |
---|
30 | action = gtk.Action('GutenbachDialog', _('_Send to gutenbach'), _('Spool song to gutenbach server'), None); |
---|
31 | action.connect('activate', self.show_conf_dialog) |
---|
32 | data['action_group'] = gtk.ActionGroup('GutenbachGroup') |
---|
33 | data['action_group'].add_action(action) |
---|
34 | manager.insert_action_group(data['action_group'], 0) |
---|
35 | |
---|
36 | data['ui_id'] = manager.add_ui_from_string(ui_str) |
---|
37 | manager.ensure_update() |
---|
38 | shell.set_data('GutenbachInfo', data) |
---|
39 | |
---|
40 | |
---|
41 | |
---|
42 | def deactivate(self, shell): |
---|
43 | self.toolbar.remove(self.separator) |
---|
44 | data = shell.get_data('GutenbachInfo') |
---|
45 | manager = shell.get_player().get_property('ui-manager') |
---|
46 | manager.remove_ui(data['ui_id']) |
---|
47 | del self.player |
---|
48 | del self.separator |
---|
49 | del self.toolbar |
---|
50 | del self.shell |
---|
51 | |
---|
52 | def show_conf_dialog(self, action): |
---|
53 | self.wTree = gtk.glade.XML(self.find_file('gutenbach-rhythmbox-2.glade')) |
---|
54 | widgets = {} |
---|
55 | widgets['gutenbach-dialog'] = self.wTree.get_widget('gutenbach-dialog') |
---|
56 | dic = { |
---|
57 | "on_gutenbach-ok_clicked" : self.process, |
---|
58 | "on_windowMain_destroy" : self.quit, |
---|
59 | } |
---|
60 | |
---|
61 | self.wTree.signal_autoconnect( dic ) |
---|
62 | |
---|
63 | # Fix proper Dialog placements |
---|
64 | widgets['gutenbach-dialog'].set_transient_for(self.shell.props.window) |
---|
65 | |
---|
66 | def gconf_path(key): |
---|
67 | return '%s%s' % (gconf_plugin_path, key) |
---|
68 | |
---|
69 | |
---|
70 | widget = None |
---|
71 | try: |
---|
72 | memf = open(os.path.expanduser('~/.gnome2/gutenbach-rhythmbox'),'r+') |
---|
73 | except IOError: |
---|
74 | memf = file(os.path.expanduser('~/.gnome2/gutenbach-rhythmbox'), 'wt') |
---|
75 | memf.close() |
---|
76 | memf = open(os.path.expanduser('~/.gnome2/gutenbach-rhythmbox'),'r+') |
---|
77 | memLine = memf.readline() |
---|
78 | if memLine != "": |
---|
79 | left = memLine |
---|
80 | right = memf.readline() |
---|
81 | self.wTree.get_widget("gutenbach-printer-entry").set_text(left.rstrip('\n')) |
---|
82 | self.wTree.get_widget("gutenbach-host-entry").set_text(right.rstrip('\n')) |
---|
83 | memf.close() |
---|
84 | widgets['gutenbach-dialog'].run() |
---|
85 | self.process(widget) |
---|
86 | widgets['gutenbach-dialog'].destroy() |
---|
87 | def process(self, widget): |
---|
88 | memf = open(os.path.expanduser('~/.gnome2/gutenbach-rhythmbox'),'r+') |
---|
89 | printerMem = (self.wTree.get_widget("gutenbach-printer-entry").get_text()) |
---|
90 | hostMem = (self.wTree.get_widget("gutenbach-host-entry").get_text()) |
---|
91 | memf.write(printerMem) |
---|
92 | memf.write("\n") |
---|
93 | memf.write(hostMem) |
---|
94 | memf.write("\n") |
---|
95 | memf.close(); |
---|
96 | self.process_songs(printerMem, hostMem) |
---|
97 | # stuff that does things |
---|
98 | def process_songs(self, printer, host): |
---|
99 | source = self.shell.get_property("selected-source") |
---|
100 | # For each track currently selected in the song browser |
---|
101 | for entry in source.get_entry_view().get_selected_entries(): |
---|
102 | # Only play files that are stored on the user's computer |
---|
103 | uri = entry.get_playback_uri() |
---|
104 | p = urlparse.urlparse(urllib.unquote(uri)) |
---|
105 | if p.scheme == "file": |
---|
106 | path = p.path |
---|
107 | if host: |
---|
108 | print "there is a host" |
---|
109 | # printer = '@'.join([printer, printer_host]) |
---|
110 | |
---|
111 | printer = printer |
---|
112 | #command = 'gbr "%s"' % (path) |
---|
113 | command = 'lpr -H%s -P%s "%s"' % (host,printer, path) |
---|
114 | print "About to run command '%s'" % command |
---|
115 | subprocess.Popen(command, shell=True) |
---|
116 | def quit(self, widget): |
---|
117 | return |
---|
118 | |
---|