18 |
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
|
*/ |
20 |
|
|
21 |
– |
#import "VMSettingsController.h" |
22 |
– |
|
21 |
|
#import "sysdeps.h" |
22 |
|
#import "prefs.h" |
23 |
|
|
24 |
+ |
// The _UINT64 define is needed to guard against a typedef mismatch with Snow Leopard headers. |
25 |
+ |
#define _UINT64 |
26 |
+ |
|
27 |
+ |
#import "VMSettingsController.h" |
28 |
+ |
|
29 |
|
const int CDROMRefNum = -62; // RefNum of driver |
30 |
|
|
31 |
+ |
#ifdef STANDALONE_PREFS |
32 |
|
void prefs_init() |
33 |
|
{ |
34 |
|
} |
36 |
|
void prefs_exit() |
37 |
|
{ |
38 |
|
} |
39 |
+ |
#endif |
40 |
|
|
41 |
|
@implementation VMSettingsController |
42 |
|
|
43 |
|
+ (id) sharedInstance |
44 |
|
{ |
45 |
< |
static VMSettingsController *_sharedInstance = nil; |
46 |
< |
if (!_sharedInstance) { |
47 |
< |
_sharedInstance = [[VMSettingsController allocWithZone:[self zone]] init]; |
48 |
< |
} |
49 |
< |
return _sharedInstance; |
45 |
> |
static VMSettingsController *_sharedInstance = nil; |
46 |
> |
if (!_sharedInstance) { |
47 |
> |
_sharedInstance = [[VMSettingsController allocWithZone:[self zone]] init]; |
48 |
> |
} |
49 |
> |
return _sharedInstance; |
50 |
|
} |
51 |
|
|
52 |
|
- (id) init |
53 |
|
{ |
54 |
|
self = [super initWithWindowNibName:@"VMSettingsWindow"]; |
55 |
|
|
56 |
< |
cancelWasClicked = NO; |
56 |
> |
cancelWasClicked = NO; |
57 |
|
|
58 |
< |
return self; |
58 |
> |
return self; |
59 |
|
} |
60 |
|
|
61 |
|
- (int) numberOfRowsInTableView: (NSTableView *) table |
140 |
|
[useRawKeyCodes setIntValue: PrefsFindBool("keycodes") ]; |
141 |
|
[rawKeyCodes setStringValue: getStringFromPrefs("keycodefile") ]; |
142 |
|
[rawKeyCodes setEnabled:[useRawKeyCodes intValue]]; |
143 |
+ |
[browseRawKeyCodesButton setEnabled:[useRawKeyCodes intValue]]; |
144 |
|
|
145 |
|
int wheelmode = PrefsFindInt32("mousewheelmode"), wheel = 0; |
146 |
|
switch (wheelmode) { |
165 |
|
|
166 |
|
- (void) editSettingsFor: (NSString *) vmdir sender: (id) sender |
167 |
|
{ |
168 |
< |
chdir([vmdir fileSystemRepresentation]); |
168 |
> |
chdir([vmdir fileSystemRepresentation]); |
169 |
> |
AddPrefsDefaults(); |
170 |
> |
AddPlatformPrefsDefaults(); |
171 |
> |
LoadPrefs([vmdir fileSystemRepresentation]); |
172 |
> |
NSWindow *window = [self window]; |
173 |
> |
[self setupGUI]; |
174 |
> |
[NSApp runModalForWindow:window]; |
175 |
> |
} |
176 |
> |
|
177 |
> |
- (void) editSettingsForNewVM: (NSString *) vmdir sender: (id) sender |
178 |
> |
{ |
179 |
> |
chdir([vmdir fileSystemRepresentation]); |
180 |
|
AddPrefsDefaults(); |
181 |
|
AddPlatformPrefsDefaults(); |
182 |
|
LoadPrefs([vmdir fileSystemRepresentation]); |
183 |
< |
NSWindow *window = [self window]; |
184 |
< |
[self setupGUI]; |
185 |
< |
[NSApp runModalForWindow:window]; |
183 |
> |
PrefsReplaceString("screen", "win/800/600"); |
184 |
> |
PrefsReplaceString("extfs", ""); |
185 |
> |
PrefsReplaceString("ether", "slirp"); |
186 |
> |
PrefsReplaceInt32("ramsize", 64 << 20); |
187 |
> |
PrefsReplaceInt32("frameskip", 2); |
188 |
> |
PrefsReplaceBool("jit", true); |
189 |
> |
NSWindow *window = [self window]; |
190 |
> |
[self setupGUI]; |
191 |
> |
[NSApp runModalForWindow:window]; |
192 |
|
} |
193 |
|
|
194 |
|
static NSString *makeRelativeIfNecessary(NSString *path) |
195 |
|
{ |
196 |
< |
char cwd[1024], filename[1024]; |
197 |
< |
int cwdlen; |
198 |
< |
strlcpy(filename, [path fileSystemRepresentation], sizeof(filename)); |
199 |
< |
getcwd(cwd, sizeof(cwd)); |
200 |
< |
cwdlen = strlen(cwd); |
201 |
< |
if (!strncmp(cwd, filename, cwdlen)) { |
202 |
< |
if (cwdlen >= 0 && cwd[cwdlen-1] != '/') |
203 |
< |
cwdlen++; |
204 |
< |
return [NSString stringWithCString: filename + cwdlen]; |
205 |
< |
} |
206 |
< |
return path; |
196 |
> |
char cwd[1024], filename[1024]; |
197 |
> |
int cwdlen; |
198 |
> |
strlcpy(filename, [path fileSystemRepresentation], sizeof(filename)); |
199 |
> |
getcwd(cwd, sizeof(cwd)); |
200 |
> |
cwdlen = strlen(cwd); |
201 |
> |
if (!strncmp(cwd, filename, cwdlen)) { |
202 |
> |
if (cwdlen >= 0 && cwd[cwdlen-1] != '/') |
203 |
> |
cwdlen++; |
204 |
> |
return [NSString stringWithCString: filename + cwdlen]; |
205 |
> |
} |
206 |
> |
return path; |
207 |
|
} |
208 |
|
|
209 |
|
- (IBAction) addDisk: (id) sender |
223 |
|
- (void) _addDiskEnd: (NSOpenPanel *) open returnCode: (int) theReturnCode contextInfo: (void *) theContextInfo |
224 |
|
{ |
225 |
|
if (theReturnCode == NSOKButton) { |
226 |
< |
[diskArray addObject: makeRelativeIfNecessary([open filename])]; |
226 |
> |
[diskArray addObject: makeRelativeIfNecessary([open filename])]; |
227 |
|
[disks reloadData]; |
228 |
|
} |
229 |
|
} |
259 |
|
snprintf(cmd, sizeof(cmd), "dd if=/dev/zero \"of=%s\" bs=1024k count=%d", [[save filename] UTF8String], [diskSaveSizeField intValue]); |
260 |
|
int ret = system(cmd); |
261 |
|
if (ret == 0) { |
262 |
< |
[diskArray addObject: makeRelativeIfNecessary([save filename])]; |
262 |
> |
[diskArray addObject: makeRelativeIfNecessary([save filename])]; |
263 |
|
[disks reloadData]; |
264 |
|
} |
265 |
|
} |
270 |
|
- (IBAction) useRawKeyCodesClicked: (id) sender |
271 |
|
{ |
272 |
|
[rawKeyCodes setEnabled:[useRawKeyCodes intValue]]; |
273 |
+ |
[browseRawKeyCodesButton setEnabled:[useRawKeyCodes intValue]]; |
274 |
|
} |
275 |
|
|
276 |
|
- (IBAction) browseForROMFileClicked: (id) sender |
290 |
|
- (void) _browseForROMFileEnd: (NSOpenPanel *) open returnCode: (int) theReturnCode contextInfo: (void *) theContextInfo |
291 |
|
{ |
292 |
|
if (theReturnCode == NSOKButton) { |
293 |
< |
[romFile setStringValue: makeRelativeIfNecessary([open filename])]; |
294 |
< |
} |
293 |
> |
[romFile setStringValue: makeRelativeIfNecessary([open filename])]; |
294 |
> |
} |
295 |
|
} |
296 |
|
|
297 |
|
- (IBAction) browseForUnixRootClicked: (id) sender |
311 |
|
- (void) _browseForUnixRootEnd: (NSOpenPanel *) open returnCode: (int) theReturnCode contextInfo: (void *) theContextInfo |
312 |
|
{ |
313 |
|
if (theReturnCode == NSOKButton) { |
314 |
< |
[unixRoot setStringValue: makeRelativeIfNecessary([open filename])]; |
314 |
> |
[unixRoot setStringValue: makeRelativeIfNecessary([open filename])]; |
315 |
> |
} |
316 |
> |
} |
317 |
> |
|
318 |
> |
- (IBAction) browseForKeyCodesFileClicked: (id) sender |
319 |
> |
{ |
320 |
> |
NSOpenPanel *open = [NSOpenPanel openPanel]; |
321 |
> |
[open setCanChooseDirectories:NO]; |
322 |
> |
[open setAllowsMultipleSelection:NO]; |
323 |
> |
[open setTreatsFilePackagesAsDirectories:YES]; |
324 |
> |
[open beginSheetForDirectory: @"" |
325 |
> |
file: [unixRoot stringValue] |
326 |
> |
modalForWindow: [self window] |
327 |
> |
modalDelegate: self |
328 |
> |
didEndSelector: @selector(_browseForKeyCodesFileEnd: returnCode: contextInfo:) |
329 |
> |
contextInfo: nil]; |
330 |
> |
} |
331 |
> |
|
332 |
> |
- (void) _browseForKeyCodesFileEnd: (NSOpenPanel *) open returnCode: (int) theReturnCode contextInfo: (void *) theContextInfo |
333 |
> |
{ |
334 |
> |
if (theReturnCode == NSOKButton) { |
335 |
> |
[rawKeyCodes setStringValue: makeRelativeIfNecessary([open filename])]; |
336 |
|
} |
337 |
|
} |
338 |
|
|
339 |
|
- (void) cancelEdit: (id) sender |
340 |
|
{ |
341 |
+ |
#ifdef STANDALONE_PREFS |
342 |
|
PrefsExit(); |
343 |
< |
[[self window] close]; |
344 |
< |
[NSApp stopModal]; |
345 |
< |
cancelWasClicked = YES; |
343 |
> |
#endif |
344 |
> |
[[self window] close]; |
345 |
> |
[NSApp stopModal]; |
346 |
> |
cancelWasClicked = YES; |
347 |
|
} |
348 |
|
|
349 |
|
- (void) saveChanges: (id) sender |
397 |
|
PrefsReplaceString("serialb", [[printerPort stringValue] UTF8String]); |
398 |
|
PrefsReplaceString("ether", [[ethernetInterface stringValue] UTF8String]); |
399 |
|
SavePrefs(); |
400 |
+ |
#ifdef STANDALONE_PREFS |
401 |
|
PrefsExit(); |
402 |
+ |
#endif |
403 |
|
|
404 |
< |
[[self window] close]; |
405 |
< |
[NSApp stopModal]; |
406 |
< |
cancelWasClicked = NO; |
404 |
> |
[[self window] close]; |
405 |
> |
[NSApp stopModal]; |
406 |
> |
cancelWasClicked = NO; |
407 |
|
} |
408 |
|
|
409 |
|
- (BOOL) cancelWasClicked |