OSDN Git Service

Patch from huevos_rancheros to restore 2-pass functionality, which broke when the...
[handbrake-jp/handbrake-jp-git.git] / macosx / ScanController.mm
1 /*  $Id: ScanController.mm,v 1.10 2005/04/27 21:05:24 titer Exp $
2
3    This file is part of the HandBrake source code.
4    Homepage: <http://handbrake.m0k.org/>.
5    It may be used under the terms of the GNU General Public License. */
6 /* These are now called in DriveDetector.h
7 #include <paths.h>
8 #include <IOKit/IOKitLib.h>
9 #include <IOKit/IOBSD.h>
10 #include <IOKit/storage/IOMedia.h>
11 #include <IOKit/storage/IODVDMedia.h>
12 */
13
14 #include "ScanController.h"
15 #include "DriveDetector.h"
16
17 #define _(a) NSLocalizedString(a,nil)
18 #define INSERT_STRING @"Insert a DVD"
19
20 @implementation ScanController
21
22
23
24 - (void) SetHandle: (hb_handle_t *) handle
25 {
26     fHandle    = handle;
27 }
28
29 - (void) Show
30 {
31
32         [self Browse: NULL];
33 }
34
35 - (void) Browse: (id) sender
36 {
37     NSOpenPanel * panel;
38         
39     panel = [NSOpenPanel openPanel];
40     [panel setAllowsMultipleSelection: NO];
41     [panel setCanChooseFiles: YES];
42     [panel setCanChooseDirectories: YES ];
43     NSString * sourceDirectory;
44         if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastSourceDirectory"])
45         {
46                 sourceDirectory = [[NSUserDefaults standardUserDefaults] stringForKey:@"LastSourceDirectory"];
47         }
48         else
49         {
50                 sourceDirectory = @"~/Desktop";
51                 sourceDirectory = [sourceDirectory stringByExpandingTildeInPath];
52         }
53    [panel beginSheetForDirectory: sourceDirectory file: nil types: nil
54                                    modalForWindow: fWindow modalDelegate: self
55                                    didEndSelector: @selector( BrowseDone:returnCode:contextInfo: )
56                                           contextInfo: nil];
57 }
58
59 - (void) BrowseDone: (NSOpenPanel *) sheet
60                  returnCode: (int) returnCode contextInfo: (void *) contextInfo
61 {
62     /* User selected a file to open */
63         if( returnCode == NSOKButton )
64     {
65         [fStatusField setStringValue: _( @"Opening a new source ..." )];
66                 [fIndicator setHidden: NO];
67             [fIndicator setIndeterminate: YES];
68         [fIndicator startAnimation: nil];
69                 [fDriveDetector stop];
70                 
71                 /* we set the last source directory in the prefs here */
72                 NSString *sourceDirectory = [[[sheet filenames] objectAtIndex: 0] stringByDeletingLastPathComponent];
73                 [[NSUserDefaults standardUserDefaults] setObject:sourceDirectory forKey:@"LastSourceDirectory"];
74                 
75                 hb_scan( fHandle, [[[sheet filenames] objectAtIndex: 0] UTF8String], 0 );
76                 
77                 [self Cancel: nil];
78     }
79         else // User clicked Cancel in browse window
80         {
81                 
82                 [self Cancel: nil];
83                 
84         }
85     
86     
87         
88 }
89
90
91 - (IBAction) Cancel: (id) sender
92 {
93    [NSApp endSheet:fPanel];
94         [fPanel orderOut:self];
95 }
96
97 @end