~ubuntu-branches/ubuntu/gutsy/serpentine/gutsy

« back to all changes in this revision

Viewing changes to serpentine/recording.py

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-08-16 21:15:55 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070816211555-t0h0nugk2kn1tb61
Tags: 0.9-0ubuntu1
* New upstream version
* debian/control:
  - updated XS-Python-Version value

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import gst
25
25
 
26
26
from nautilusburn import AudioTrack
 
27
from weakref import ref
27
28
from operations import OperationsQueueListener, MeasurableOperation
28
29
from converting import FetchMusicList
29
30
from gettext import gettext as _
30
31
 
31
 
class ConvertingError:
 
32
class ConvertingError(object):
32
33
    def __init__ (self, win):
33
34
        self.win= win
34
35
    
35
36
    def on_finished (self, evt):
36
 
        if evt.id != operations.ERROR:
 
37
        if not evt.is_error:
37
38
            return
38
39
        err = evt.error
39
40
        
40
41
        # Handle missing files
41
 
        if isinstance(err, gst.GError) and err.code == gst.RESOURCE_ERROR_NOT_FOUND:
 
42
        if isinstance(err, gst.GError) \
 
43
               and err.code == gst.RESOURCE_ERROR_NOT_FOUND:
42
44
            gtkutil.dialog_error(
43
45
                _("Converting files failed"),
44
46
                _("Some of the files were missing. The disc is still usable."),
52
54
            parent = self.win
53
55
        )
54
56
 
55
 
class WritingError:
 
57
class WritingError(object):
56
58
    def __init__ (self, win):
57
59
        self.win= win
58
60
 
59
61
    def on_finished (self, evt):
60
 
        if evt.id == operations.SUCCESSFUL:
 
62
        if evt.is_successful:
61
63
            return
62
64
        
63
 
        if evt.id == operations.ERROR:
 
65
        if evt.is_error:
64
66
            title = _("Writing to disc failed")
65
67
        else:
66
68
            title = _("Writing to disc canceled")
75
77
 
76
78
################################################################################
77
79
 
78
 
class ConvertAndWrite (MeasurableOperation, OperationsQueueListener):
 
80
class ConvertAndWrite(MeasurableOperation, OperationsQueueListener):
79
81
    """
80
82
    ConvertAndWrite class is yet another operation. When this operation is
81
83
    started it will show the user the dialog for the recording operation.
84
86
    def __init__ (self, music_list, preferences, parent = None):
85
87
        MeasurableOperation.__init__ (self)
86
88
        self.__queue = operations.OperationsQueue ()
87
 
        self.__queue.listeners.append (self)
 
89
        self.__queue.add_listener(self)
88
90
        self.__parent = parent
89
91
        self.__prog = gtkutil.HigProgress ()
90
92
        self.__prog.primary_text = _("Writing Audio Disc")
97
99
        self.__prog.cancel_button.connect ("clicked", self.__on_cancel)
98
100
        self.__prog.close_button.connect ("clicked", self.__on_close)
99
101
        self.__prog.set_icon_name ("gnome-dev-cdrom-audio")
100
 
        self.__music_list = music_list
 
102
        self.__music_list = tuple(row['location'] for row in music_list)
101
103
        self.__preferences = preferences
102
104
        self.__drive = preferences.drive
103
105
        self.__can_start = True
110
112
    running = property (lambda self: self.__queue.running)
111
113
    progress = property (lambda self: self.__queue.progress)
112
114
    drive = property (lambda self: self.__drive)
 
115
    pool = property(lambda self: self.preferences.pool)
113
116
    
114
117
    def __on_prog_destroyed (self, *args):
115
118
        if self.cancel_button.is_sensitive ():
126
129
                                   "preserve it's contents."),
127
130
                                 parent = self.__prog)
128
131
        self.__blocked = False
129
 
        self.preferences.pool.temporary_dir = self.preferences.temporary_dir
 
132
        self.pool.temporary_dir = self.preferences.temporary_dir
130
133
        oper = FetchMusicList(self.__music_list, self.preferences.pool)
131
134
        # Fill filenames after retrieving stuff
132
135
        self.__filenames = []
133
 
        oper.listeners.append (MusicListToFilenames (self.__music_list, self.__filenames))
134
 
        
135
 
        oper.listeners.append (ConvertingError(self.__prog))
 
136
        oper.add_listener(MusicListToFilenames(self.pool,
 
137
                                               self.__music_list,
 
138
                                               self.__filenames))
 
139
       
 
140
        oper.add_listener(ConvertingError(self.__prog))
136
141
        
137
142
        self.__fetching = oper
138
143
        self.__queue.append (oper)
142
147
                                
143
148
        oper.recorder.connect ("progress-changed", self.__tick)
144
149
        oper.recorder.connect ("action-changed", self.__on_action_changed)
145
 
        oper.listeners.append (WritingError(self.__prog))
 
150
        oper.add_listener(WritingError(self.__prog))
146
151
        
147
152
        self.__queue.append (oper)
148
153
        self.__recording = oper
190
195
            self.__blocked = True
191
196
    
192
197
    def on_finished (self, evt):
193
 
        # self.__prog.cancel_button.hide ()
194
 
        # self.__prog.close_button.show ()
195
198
        gobject.source_remove (self.__source)
196
199
        
197
 
        if evt.id == operations.SUCCESSFUL:
 
200
        if evt.is_successful:
198
201
            gtkutil.dialog_info (
199
202
                _("Writing to disc finished"),
200
203
                _("Disc writing was successful."),
206
209
 
207
210
        self.__on_close ()
208
211
 
209
 
class MusicListToFilenames:
210
 
    def __init__ (self, music_list, filenames):
 
212
class MusicListToFilenames(object):
 
213
    def __init__ (self, pool, music_list, filenames):
 
214
        self.pool = pool
211
215
        self.music_list = music_list
212
216
        self.filenames = filenames
213
217
        
214
218
    def on_finished (self, evt):
215
 
        for row in self.music_list:
216
 
            self.filenames.append (row["cache_location"])
 
219
        for music in self.music_list:
 
220
            self.filenames.append(self.pool.get_filename(music))
217
221
        
218
222
 
219
223
################################################################################
220
 
class WriteAudioDisc (MeasurableOperation):
 
224
class WriteAudioDisc(MeasurableOperation):
221
225
    
222
 
    def __init__ (self, music_list, preferences, parent = None):
 
226
    def __init__(self, music_list, preferences, parent = None):
223
227
        MeasurableOperation.__init__(self)
224
228
        self.music_list = music_list
225
229
        self.__progress = 0.0
230
234
    
231
235
    title = _("Writing Files to Disc")
232
236
 
233
 
    progress = property (lambda self: self.__progress)
234
 
    running = property (lambda self: self.__running)
235
 
    recorder = property (lambda self: self.__recorder)
236
 
    preferences = property (lambda self: self.__preferences)
 
237
    progress = property(lambda self: self.__progress)
 
238
    running = property(lambda self: self.__running)
 
239
    recorder = property(lambda self: self.__recorder)
 
240
    preferences = property(lambda self: self.__preferences)
237
241
    
238
242
    def start (self):
239
243
        # TODO: Compare media size with music list duration
243
247
 
244
248
        for filename in self.music_list:
245
249
            tracks.append (AudioTrack (filename))
246
 
        
 
250
 
247
251
        if len (tracks) == 0:
248
252
            self._send_finished_event (
249
253
                operations.ERROR,
332
336
    d = nautilusburn.get_drives_list (False)[0]
333
337
    music_lst = [{'filename': sys.argv[1]}]
334
338
    r = RecordMusicList (music_lst, d, d.get_max_speed_write(), 0) #nautilusburn.RECORDER_WRITE_DUMMY_WRITE
335
 
    r.listeners.append (MyListener())
 
339
    r.add_listener(MyListener())
336
340
    gobject.timeout_add (250, print_progress, r)
337
341
    r.start()
338
342
    gtk.main()