1# Copyright 2005 Joe Wreschnig, 2# 2009,2012 Christoph Reiter 3# 2016 Nick Boultbee 4# 5# This program is free software; you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by 7# the Free Software Foundation; either version 2 of the License, or 8# (at your option) any later version. 9 10from gi.repository import Gtk 11 12from quodlibet import _ 13from quodlibet import util 14from quodlibet.plugins.songsmenu import SongsMenuPlugin 15from quodlibet.plugins.songshelpers import is_a_file, each_song 16from quodlibet.util.path import iscommand 17from quodlibet.qltk import Icons 18from quodlibet.util import connect_obj 19 20 21class BurnCD(SongsMenuPlugin): 22 PLUGIN_ID = 'Burn CD' 23 PLUGIN_NAME = _('Burn CD') 24 PLUGIN_DESC = _('Burns CDs with K3b, Brasero or xfburn.') 25 PLUGIN_ICON = Icons.MEDIA_OPTICAL 26 27 plugin_handles = each_song(is_a_file) 28 29 burn_programs = { 30 # args, reverse order 31 'K3b': (['k3b', '--audiocd'], False), 32 'Brasero': (['brasero', '--audio'], False), 33 'Xfburn': (['xfburn', '--audio-composition'], True), 34 } 35 36 def __init__(self, *args, **kwargs): 37 super(BurnCD, self).__init__(*args, **kwargs) 38 self.prog_name = None 39 40 items = self.burn_programs.items() 41 progs = [(iscommand(x[1][0][0]), x) for x in items] 42 progs.sort(reverse=True) 43 44 submenu = Gtk.Menu() 45 for (is_cmd, (name, (args, reverse))) in progs: 46 item = Gtk.MenuItem(label=name) 47 if not is_cmd: 48 item.set_sensitive(False) 49 else: 50 connect_obj(item, 'activate', self.__set, name) 51 submenu.append(item) 52 self.set_submenu(submenu) 53 54 def __set(self, name): 55 self.prog_name = name 56 57 def plugin_songs(self, songs): 58 if self.prog_name is None: 59 return 60 61 args, reverse = self.burn_programs[self.prog_name] 62 songs = sorted(songs, key=lambda s: s.sort_key, reverse=reverse) 63 util.spawn(args + [song['~filename'] for song in songs]) 64