1 |
asvitkine |
1.1 |
/* |
2 |
|
|
* VMListController.mm - SheepShaver VM manager in Cocoa on Mac OS X |
3 |
|
|
* |
4 |
|
|
* Copyright (C) 2009 Alexei Svitkine |
5 |
|
|
* |
6 |
|
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
|
* it under the terms of the GNU General Public License as published by |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with this program; if not, write to the Free Software |
18 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
|
|
*/ |
20 |
|
|
|
21 |
|
|
#import "VMListController.h" |
22 |
|
|
#import "VMSettingsController.h" |
23 |
|
|
|
24 |
|
|
@implementation VMListController |
25 |
|
|
|
26 |
|
|
+ (id) sharedInstance |
27 |
|
|
{ |
28 |
|
|
static VMListController *_sharedInstance = nil; |
29 |
|
|
if (!_sharedInstance) { |
30 |
|
|
_sharedInstance = [[VMListController allocWithZone:[self zone]] init]; |
31 |
|
|
} |
32 |
|
|
return _sharedInstance; |
33 |
|
|
} |
34 |
|
|
|
35 |
|
|
- (id) init |
36 |
|
|
{ |
37 |
|
|
self = [super initWithWindowNibName:@"VMListWindow"]; |
38 |
|
|
|
39 |
|
|
NSArray *vms = [[NSUserDefaults standardUserDefaults] stringArrayForKey:@"vm_list"]; |
40 |
|
|
vmArray = [[NSMutableArray alloc] initWithCapacity:[vms count]]; |
41 |
|
|
[vmArray addObjectsFromArray:vms]; |
42 |
|
|
|
43 |
|
|
return self; |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
- (void) awakeFromNib |
47 |
|
|
{ |
48 |
asvitkine |
1.2 |
[vmList setDataSource: self]; |
49 |
asvitkine |
1.1 |
//[vmList setDelegate: self]; |
50 |
asvitkine |
1.2 |
[vmList reloadData]; |
51 |
asvitkine |
1.1 |
} |
52 |
|
|
|
53 |
|
|
- (int) numberOfRowsInTableView: (NSTableView *) table |
54 |
|
|
{ |
55 |
asvitkine |
1.2 |
return [vmArray count]; |
56 |
asvitkine |
1.1 |
} |
57 |
|
|
|
58 |
|
|
- (id) tableView: (NSTableView *) table objectValueForTableColumn: (NSTableColumn *) c row: (int) r |
59 |
|
|
{ |
60 |
asvitkine |
1.2 |
return [vmArray objectAtIndex: r]; // [[vmArray objectAtIndex: r] lastPathComponent]; |
61 |
asvitkine |
1.1 |
} |
62 |
|
|
|
63 |
|
|
//- (NSString *) tableView: (NSTableView *) table toolTipForCell: (NSCell *) cell rect: (NSRectPointer) rect |
64 |
|
|
// tableColumn: (NSTableColumn *) c row: (int) r mouseLocation: (NSPoint) loc |
65 |
|
|
//{ |
66 |
|
|
// return [vmArray objectAtIndex: r]; |
67 |
|
|
//} |
68 |
|
|
|
69 |
|
|
- (IBAction) newVirtualMachine: (id) sender |
70 |
|
|
{ |
71 |
|
|
NSSavePanel *save = [NSSavePanel savePanel]; |
72 |
|
|
[save setMessage: @"New SheepShaver Virtual Machine:"]; |
73 |
|
|
[save setRequiredFileType: @"sheepvm"]; |
74 |
|
|
[save setCanSelectHiddenExtension: YES]; |
75 |
|
|
[save setExtensionHidden: NO]; |
76 |
|
|
[save beginSheetForDirectory: nil |
77 |
|
|
file: @"New.sheepvm" |
78 |
|
|
modalForWindow: [self window] |
79 |
|
|
modalDelegate: self |
80 |
|
|
didEndSelector: @selector(_newVirtualMachineDone: returnCode: contextInfo:) |
81 |
|
|
contextInfo: nil]; |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
- (IBAction) _newVirtualMachineDone: (NSSavePanel *) save returnCode: (int) returnCode contextInfo: (void *) contextInfo |
85 |
|
|
{ |
86 |
|
|
if (returnCode == NSOKButton) { |
87 |
|
|
// make dir. |
88 |
|
|
// create prefs file in there |
89 |
|
|
// edit said prefs file |
90 |
|
|
// advanced: show sub-panel in save dialog that says "Create Disk:" |
91 |
|
|
} |
92 |
|
|
} |
93 |
|
|
|
94 |
|
|
- (IBAction) importVirtualMachine: (id) sender |
95 |
|
|
{ |
96 |
|
|
NSOpenPanel *open = [NSOpenPanel openPanel]; |
97 |
|
|
[open setMessage:@"Import SheepShaver Virtual Machine:"]; |
98 |
|
|
[open setResolvesAliases:YES]; |
99 |
|
|
// Curiously, bundles are treated as "files" not "directories" by NSOpenPanel. |
100 |
|
|
[open setCanChooseDirectories:NO]; |
101 |
|
|
[open setCanChooseFiles:YES]; |
102 |
|
|
[open setAllowsMultipleSelection:NO]; |
103 |
|
|
[open beginSheetForDirectory: nil |
104 |
|
|
file: nil |
105 |
|
|
types: [NSArray arrayWithObject:@"sheepvm"] |
106 |
|
|
modalForWindow: [self window] |
107 |
|
|
modalDelegate: self |
108 |
|
|
didEndSelector: @selector(_importVirtualMachineDone: returnCode: contextInfo:) |
109 |
|
|
contextInfo: nil]; |
110 |
|
|
} |
111 |
|
|
|
112 |
|
|
- (void) _importVirtualMachineDone: (NSOpenPanel *) open returnCode: (int) returnCode contextInfo: (void *) contextInfo |
113 |
|
|
{ |
114 |
|
|
if (returnCode == NSOKButton) { |
115 |
|
|
[vmArray addObject:[open filename]]; |
116 |
|
|
[vmList reloadData]; |
117 |
|
|
[[NSUserDefaults standardUserDefaults] setObject:vmArray forKey:@"vm_list"]; |
118 |
|
|
} |
119 |
|
|
} |
120 |
|
|
|
121 |
|
|
- (IBAction) editVirtualMachineSettings:(id)sender |
122 |
|
|
{ |
123 |
|
|
int selectedRow = [vmList selectedRow]; |
124 |
asvitkine |
1.2 |
if (selectedRow >= 0) { |
125 |
asvitkine |
1.1 |
[[VMSettingsController sharedInstance] editSettingsFor:[vmArray objectAtIndex:selectedRow] sender:sender]; |
126 |
asvitkine |
1.2 |
} |
127 |
asvitkine |
1.1 |
} |
128 |
|
|
|
129 |
asvitkine |
1.2 |
- (IBAction) launchVirtualMachine:(id)sender |
130 |
asvitkine |
1.1 |
{ |
131 |
asvitkine |
1.2 |
int selectedRow = [vmList selectedRow]; |
132 |
|
|
if (selectedRow >= 0) { |
133 |
|
|
NSTask *sheep = [[NSTask alloc] init]; |
134 |
|
|
[sheep setLaunchPath:[[NSBundle mainBundle] pathForAuxiliaryExecutable:@"SheepShaver"]]; |
135 |
|
|
[sheep setArguments:[NSArray arrayWithObject:[vmArray objectAtIndex:selectedRow]]]; |
136 |
|
|
[sheep launch]; |
137 |
|
|
} |
138 |
asvitkine |
1.1 |
} |
139 |
|
|
|
140 |
|
|
@end |