blob: 01aa0026e86fd1aca852bd3091a6b6ab62958adc (
plain)
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
|
/* $Id: ScanController.mm,v 1.10 2005/04/27 21:05:24 titer Exp $
This file is part of the HandBrake source code.
Homepage: <http://handbrake.m0k.org/>.
It may be used under the terms of the GNU General Public License. */
/* These are now called in DriveDetector.h
#include <paths.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/IOBSD.h>
#include <IOKit/storage/IOMedia.h>
#include <IOKit/storage/IODVDMedia.h>
*/
#include <IOKit/IOKitLib.h>
#include <IOKit/storage/IOMedia.h>
#include <IOKit/storage/IODVDMedia.h>
#include "HBDVDDetector.h"
#include "ScanController.h"
#include "dvdread/dvd_reader.h"
#define _(a) NSLocalizedString(a,nil)
#define INSERT_STRING @"Insert a DVD"
@implementation ScanController
- (void) SetHandle: (hb_handle_t *) handle
{
fHandle = handle;
}
- (void) Show
{
[self Browse: NULL];
}
- (void) Browse: (id) sender
{
NSOpenPanel * panel;
panel = [NSOpenPanel openPanel];
[panel setAllowsMultipleSelection: NO];
[panel setCanChooseFiles: YES];
[panel setCanChooseDirectories: YES ];
NSString * sourceDirectory;
if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastSourceDirectory"])
{
sourceDirectory = [[NSUserDefaults standardUserDefaults] stringForKey:@"LastSourceDirectory"];
}
else
{
sourceDirectory = @"~/Desktop";
sourceDirectory = [sourceDirectory stringByExpandingTildeInPath];
}
[panel beginSheetForDirectory: sourceDirectory file: nil types: nil
modalForWindow: fWindow modalDelegate: self
didEndSelector: @selector( BrowseDone:returnCode:contextInfo: )
contextInfo: nil];
}
- (void) BrowseDone: (NSOpenPanel *) sheet
returnCode: (int) returnCode contextInfo: (void *) contextInfo
{
/* User selected a file to open */
if( returnCode == NSOKButton )
{
[fStatusField setStringValue: _( @"Opening a new source ..." )];
[fIndicator setHidden: NO];
[fIndicator setIndeterminate: YES];
[fIndicator startAnimation: nil];
/* we set the last source directory in the prefs here */
NSString *sourceDirectory = [[[sheet filenames] objectAtIndex: 0] stringByDeletingLastPathComponent];
[[NSUserDefaults standardUserDefaults] setObject:sourceDirectory forKey:@"LastSourceDirectory"];
NSString *path = [[sheet filenames] objectAtIndex: 0];
HBDVDDetector *detector = [HBDVDDetector detectorForPath:path];
if( [detector isVideoDVD] )
{
// The chosen path was actually on a DVD, so use the raw block
// device path instead.
path = [detector devicePath];
}
hb_scan( fHandle, [path UTF8String], 0 );
[self Cancel: nil];
}
else // User clicked Cancel in browse window
{
/* use the outlets to the main menu bar to determine what to
enable and disable */
[fMainMenuOpenSource setEnabled: YES];
/* if we have a title loaded up */
if ([[fMainWindowSrcName stringValue] length] > 0)
{
[fMainMenuAddToQueue setEnabled: YES];
[fMainMenuStartEncode setEnabled: YES];
//[fMainMenuPauseEncode setEnabled: YES];
[fMenuQueuePanelShow setEnabled: YES];
[fMenuPicturePanelShow setEnabled: YES];
}
[self Cancel: nil];
}
}
- (IBAction) Cancel: (id) sender
{
[NSApp endSheet:fPanel];
[fPanel orderOut:self];
}
@end
|