[9fed25d] | 1 | from __future__ import division |
---|
[61c5043] | 2 | |
---|
| 3 | import rb |
---|
[9fed25d] | 4 | import gtk, gtk.glade, gconf |
---|
| 5 | import gobject |
---|
| 6 | import sys, os |
---|
| 7 | import locale, datetime, time |
---|
[7e6a613] | 8 | import subprocess |
---|
[61c5043] | 9 | import urllib |
---|
| 10 | import urlparse |
---|
[7e6a613] | 11 | |
---|
[9fed25d] | 12 | #fade_steps = 50 |
---|
| 13 | |
---|
| 14 | ui_str = ''' |
---|
[7e6a613] | 15 | <ui> |
---|
| 16 | <popup name="BrowserSourceViewPopup"> |
---|
[9fed25d] | 17 | <menuitem name="Gutenbach" action="GutenbachDialog"/> |
---|
[7e6a613] | 18 | </popup> |
---|
| 19 | </ui> |
---|
[9fed25d] | 20 | ''' |
---|
| 21 | |
---|
[0159c0a] | 22 | class GutenbachPlugin(rb.Plugin): |
---|
[9fed25d] | 23 | def __init__ (self): |
---|
| 24 | rb.Plugin.__init__ (self) |
---|
[7e6a613] | 25 | |
---|
[9fed25d] | 26 | def activate (self, shell): |
---|
| 27 | data = dict() |
---|
| 28 | manager = shell.get_player().get_property('ui-manager') |
---|
[7e6a613] | 29 | self.shell = shell |
---|
[9fed25d] | 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 | |
---|
[0159c0a] | 40 | |
---|
[7e6a613] | 41 | |
---|
| 42 | def deactivate(self, shell): |
---|
[9fed25d] | 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 |
---|
[7e6a613] | 50 | del self.shell |
---|
| 51 | |
---|
[9fed25d] | 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: |
---|
[e541733] | 72 | memf = open(os.path.expanduser('~/.gnome2/gutenbach-rhythmbox'),'r+') |
---|
[9fed25d] | 73 | except IOError: |
---|
[e541733] | 74 | memf = file(os.path.expanduser('~/.gnome2/gutenbach-rhythmbox'), 'wt') |
---|
[9fed25d] | 75 | memf.close() |
---|
[e541733] | 76 | memf = open(os.path.expanduser('~/.gnome2/gutenbach-rhythmbox'),'r+') |
---|
[9fed25d] | 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): |
---|
[e541733] | 88 | memf = open(os.path.expanduser('~/.gnome2/gutenbach-rhythmbox'),'r+') |
---|
[9fed25d] | 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") |
---|
[0159c0a] | 100 | # For each track currently selected in the song browser |
---|
[7e6a613] | 101 | for entry in source.get_entry_view().get_selected_entries(): |
---|
[0159c0a] | 102 | # Only play files that are stored on the user's computer |
---|
[7e6a613] | 103 | uri = entry.get_playback_uri() |
---|
| 104 | p = urlparse.urlparse(urllib.unquote(uri)) |
---|
| 105 | if p.scheme == "file": |
---|
| 106 | path = p.path |
---|
[9fed25d] | 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) |
---|
[61c5043] | 114 | print "About to run command '%s'" % command |
---|
[7e6a613] | 115 | subprocess.Popen(command, shell=True) |
---|
[9fed25d] | 116 | def quit(self, widget): |
---|
| 117 | return |
---|
| 118 | |
---|