-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBurnProgressController.m
492 lines (425 loc) · 12.2 KB
/
BurnProgressController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
/* vim: set ft=objc ts=4 et sw=4 nowrap: */
/*
* BurnProgressController.m
*
* Copyright (c) 2002-2005, 2011
*
* Author: Andreas Schik <andreas@schik.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "BurnProgressController.h"
#include "Constants.h"
#include "Functions.h"
#include "Track.h"
#include "Project.h"
#include "AppController.h"
#include "ConvertAudioHelper.h"
#include "CreateISOHelper.h"
#include "BurnCDHelper.h"
#include "ConsolePanel.h"
enum BurnStage {
None,
ConvertAudio,
GrabCD,
CreateISO,
BurnCD
};
@interface BurnProgressController (Private)
- (void) setMiniwindowImage;
- (void) drawImageRep;
- (void) drawArc: (double) radius Percent: (double) percent Entire: (BOOL) entire;
@end
@implementation BurnProgressController (Private)
- (void) setMiniwindowImage
{
NSImageRep *rep;
NSImage *image;
if (![[self window] isMiniaturized])
return;
if (mwTrack < 0)
mwTrack = 0;
if (mwEntire < 0)
mwEntire = 0;
image = [[NSImage alloc] initWithSize: NSMakeSize(48,48)];
rep = [[NSCustomImageRep alloc] initWithDrawSelector: @selector(drawImageRep)
delegate: self];
[rep setSize: NSMakeSize(48,48)];
[image addRepresentation: rep];
[[self window] setMiniwindowImage: image];
DESTROY(image);
}
-(void) drawImageRep
{
PSsetlinewidth(1.0);
PSsetalpha(1.0);
PSsetrgbcolor(0.58, 0.58, 0.58);
PSmoveto(24, 24);
PSarcn(24, 24, 22, 90, -270);
PSfill();
[self drawArc: 22.0 Percent: mwEntire Entire: YES];
PSsetrgbcolor(0.58, 0.58, 0.58);
PSmoveto(24, 24);
PSarcn(24, 24, 16, 90, -270);
PSfill();
[self drawArc: 15.0 Percent: mwTrack Entire: NO];
PSsetrgbcolor(0.58, 0.58, 0.58);
PSmoveto(24, 24);
PSarcn(24, 24, 9, 90, -270);
PSfill();
}
- (void) drawArc: (double) radius Percent: (double) percent Entire: (BOOL) entire
{
if (entire) {
PSsetrgbcolor(0.14, 0.58, 0.95); // blue
} else {
PSsetrgbcolor(0.10, 1.03, 1.81); // blue
}
PSmoveto(24, 24);
PSarcn(24, 24, radius, 90, 90 - percent * 360);
PSfill();
}
@end
@implementation BurnProgressController
- (id) init
{
self = [self initWithWindowNibName: @"BurnProgress"];
return self;
}
- (id) initWithVolumeId: (NSString *)volId
dataTracks: (NSArray *)dTracks
audioTracks: (NSArray *)aTracks
cdList: (NSDictionary *)cds
isoOnly: (BOOL) isoOnly
{
self = [self init];
if (self != nil) {
ASSIGN(volumeId, volId);
ASSIGN(dataTracks, dTracks);
ASSIGN(audioTracks, aTracks);
ASSIGN(cdList, cds);
isoImageOnly=isoOnly;
}
return self;
}
- (id) initWithIsoImage: (NSString *)isoImage
{
self = [self init];
if (self != nil) {
ASSIGN(isoImageFile, isoImage);
}
return self;
}
- (id) initWithWindowNibName: (NSString *) nibName
{
self = [super initWithWindowNibName: nibName];
if (![NSBundle loadNibNamed: nibName owner: self]) {
logToConsole(MessageStatusError, [NSString stringWithFormat:
_(@"Common.loadNibFail"), nibName]);
} else {
NSDictionary *params = nil;
BOOL openConsole = NO;
[[self window] setExcludedFromWindowsMenu: YES];
[trackProgress setDoubleValue: 0];
[entireProgress setDoubleValue: 0];
stage = None;
convertHelper = nil;
createIsoHelper = nil;
burnHelper = nil;
/*
* We take a snap shot of the current parameter set. Thus,
* another session may already override the parameters while
* this process is taking place.
* autoreleased!!!
*/
burnParameters = [NSMutableDictionary new];
[burnParameters setDictionary: [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]];
// check whether the console should be opened
params = [burnParameters objectForKey: @"SessionParameters"];
openConsole = [[params objectForKey: @"OpenConsole"] boolValue];
if (YES == openConsole) {
[[ConsolePanel consolePanel] showWindow: self];
}
isoImageFile = nil;
[[self window] setFrameAutosaveName: @"BurnProgress"];
[[self window] setFrameUsingName: @"BurnProgress"];
}
return self;
}
- (void) awakeFromNib
{
[abortButton setTitle: _(@"Common.cancel")];
[closeButton setTitle: _(@"Common.close")];
[closeButton setEnabled: NO];
}
- (void) dealloc
{
RELEASE(volumeId);
RELEASE(dataTracks);
RELEASE(audioTracks);
RELEASE(isoImageFile);
RELEASE(cdList);
RELEASE(burnParameters);
RELEASE(convertHelper);
RELEASE(burnHelper);
RELEASE(createIsoHelper);
[super dealloc];
}
//
// access methods
//
- (NSDictionary *) burnParameters
{
return burnParameters;
}
- (NSString *)isoImageFile
{
return isoImageFile;
}
- (NSDictionary *) cdList
{
return cdList;
}
- (void) setTitle: (NSString *)title
{
if (title && [title length]) {
[[self window] setTitle: title];
}
}
- (void) setTrackProgress: (double) value andLabel: (NSString *) label
{
if (value >= 0) {
[trackProgress setDoubleValue: value];
}
if (label != nil) {
[trackLabel setStringValue: label];
}
}
- (void) hideTrackProgress: (BOOL) hide
{
[trackProgress setHidden: hide];
[trackLabel setHidden: hide];
}
- (void) setEntireProgress: (double) value andLabel: (NSString *) label
{
if (value >= 0) {
[entireProgress setDoubleValue: value];
}
if (label != nil) {
[entireLabel setStringValue: label];
}
}
- (void) hideEntireProgress: (BOOL) hide
{
[entireProgress setHidden: hide];
[entireLabel setHidden: hide];
}
- (void) makeEntireProgressIndeterminate: (BOOL) ind
{
if (YES == ind) {
[entireProgress setIndeterminate: YES];
[entireProgress startAnimation: self];
} else {
[entireProgress stopAnimation: self];
[entireProgress setIndeterminate: NO];
}
}
- (void) setAbortEnabled: (BOOL) enabled
{
[abortButton setEnabled: enabled];
}
//
// delegate methods
//
- (void) windowDidMiniaturize: (NSNotification *)not
{
[self setMiniwindowImage];
}
//
// action methods
//
- (void) closeClicked: (id)sender
{
[self close];
RELEASE(self);
logToConsole(MessageStatusInfo, @"Burning finished.");
[[AppController appController] unlockBurner];
}
- (void) abortClicked: (id)sender
{
if (NSRunAlertPanel(APP_NAME, _(@"BurnProgressController.reallyStop"),
_(@"Common.no"), _(@"Common.yes"), nil) == NSAlertDefaultReturn) {
return;
}
if (convertHelper != nil) {
[convertHelper stop: YES];
}
if (createIsoHelper != nil) {
[createIsoHelper stop: YES];
}
if (burnHelper != nil) {
[burnHelper stop: YES];
}
[self cleanUp: NO];
}
- (void) startProcess
{
// no tracks -> nothing to do
if ((audioTracks == nil) && (dataTracks == nil) && (isoImageFile == nil)) {
[self close];
return;
}
// create the temp path if it does not exist
if (![self createTempDirectory]) {
logToConsole(MessageStatusError, @"Could not create directory for temporary files.");
return;
}
stage = None;
[self nextStage: YES];
}
- (void) nextStage: (BOOL) success
{
enum StartHelperStatus result;
if (!success) {
[self cleanUp: NO];
} else {
switch (stage) {
case None:
stage = ConvertAudio;
convertHelper = [[ConvertAudioHelper alloc] initWithController: self];
result = [convertHelper start: audioTracks];
if (Done == result) {
/*
* Fall through to CD grabbing
*/
} else {
if (Failed == result)
[self cleanUp: NO];
break;
}
case ConvertAudio:
stage = CreateISO;
createIsoHelper = [[CreateISOHelper alloc] initWithController: self];
result = [createIsoHelper start: dataTracks volumeId: volumeId];
if (Done == result) {
/*
* Fall through to burning
*/
} else {
if (Failed == result)
[self cleanUp: NO];
break;
}
case CreateISO:
{
stage = BurnCD;
if (isoImageOnly == YES) {
/*
* Simply fall through, as we not have anything to burn.
*/
} else {
/*
* If we have not been passed the name of an ISO
* image file, we try to get the one created by the
* helper.
*/
if (isoImageFile == nil) {
isoImageFile = RETAIN([createIsoHelper isoImageFile]);
}
burnHelper = [[BurnCDHelper alloc] initWithController: self];
result = [burnHelper start: isoImageFile audioTracks: audioTracks];
if (Failed == result)
[self cleanUp: NO];
break;
}
}
case BurnCD:
[self cleanUp: YES];
break;
}
}
}
- (void) cleanUp: (BOOL)success
{
[convertHelper cleanUp: success];
[burnHelper cleanUp: success];
[createIsoHelper cleanUp: success];
[[self window] setTitle: _(@"Common.finished")];
[closeButton setEnabled: YES];
[abortButton setEnabled: NO];
[self hideTrackProgress: YES];
[self makeEntireProgressIndeterminate: NO];
[entireProgress setDoubleValue: 0.];
if (success == NO) {
[entireLabel setStringValue: _(@"BurnProgressController.noSuccess")];
logToConsole(MessageStatusError, _(@"BurnProgressController.noSuccess"));
} else {
[entireLabel setStringValue: _(@"BurnProgressController.success")];
logToConsole(MessageStatusInfo, _(@"BurnProgressController.success"));
}
}
- (BOOL) createTempDirectory
{
int i, count;
BOOL isDir = YES;
NSFileManager *fileMan = [NSFileManager defaultManager];
NSDictionary *params = [burnParameters objectForKey: @"SessionParameters"];
NSString *tempDir = [params objectForKey: @"TempDirectory"];
if (!tempDir || ![tempDir length]) {
NSRunInformationalAlertPanel(APP_NAME,
[NSString stringWithFormat: @"%@\n%@",
_(@"BurnProgressController.provideTempDir"),
_(@"Common.stopProcess")],
_(@"Common.OK"), nil, nil);
return NO;
}
if (![fileMan fileExistsAtPath: tempDir isDirectory: &isDir]) {
NSMutableString *createDir = [[NSMutableString alloc] init];
NSArray *pathComponents = [tempDir pathComponents];
count = [pathComponents count];
// try to create the directories along out temp path
for (i = 0; i < count; i++) {
createDir = [[createDir stringByAppendingPathComponent: [pathComponents objectAtIndex: i]] copy];
if (![fileMan fileExistsAtPath: createDir]) {
if (![fileMan createDirectoryAtPath: createDir attributes: nil]) {
NSRunAlertPanel(APP_NAME,
[NSString stringWithFormat: @"%@ %@.\n%@",
_(@"BurnProgressController.createDirFail"), createDir,
_(@"Common.stopProcess")],
_(@"Common.OK"), nil, nil);
return NO;
}
}
}
} else if (!isDir) {
NSRunAlertPanel(APP_NAME,
[NSString stringWithFormat: @"%@ %@\n%@",
tempDir,
_(@"BurnProgressController.existsNoDir"),
_(@"Common.stopProcess")],
_(@"Common.OK"), nil, nil);
return NO;
}
return YES;
}
- (void) setMiniwindowToTrack: (double) track Entire: (double) entire
{
if (track >= 0)
mwTrack = track/100.;
if (entire >= 0)
mwEntire = entire/100.;
[self setMiniwindowImage];
}
@end