777
class TransferQueue(object):
779
def __init__(self, library):
780
self.library = library
782
self.current_pos = -1
783
self.transferring = False
786
def enqueue(self, tracks):
787
self.queue.extend(tracks)
789
def dequeue(self, tracks):
790
if self.transferring:
791
# FIXME: use a proper exception, and make this only error on
792
# tracks that have already been transferred
793
raise Exception, "Cannot remove tracks while transferring"
803
Tranfer the queued tracks to the library.
805
This is NOT asynchronous
807
self.transferring = True
808
self.current_pos += 1
810
while self.current_pos + 1 < len(self.queue) and not self._stop:
811
track = self.queue[self.current_pos]
812
loc = track.get_loc()
813
self.library.add(loc)
815
# TODO: make this be based on filesize not count
816
progress = self.current_pos / float(len(self.queue))
817
event.log_event('track_transfer_progress', self, progress)
819
self.current_pos += 1
821
self.transferring = False
822
self.current_pos = -1
824
event.log_event('track_transfer_progress', self, 1)
828
Cancel the current transfer
830
# TODO: make this stop mid-file as well?
777
834
# vim: et sts=4 sw=4