ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/MacOSX/Launcher/VMSettingsController.mm
(Generate patch)

Comparing SheepShaver/src/MacOSX/Launcher/VMSettingsController.mm (file contents):
Revision 1.3 by asvitkine, 2009-08-06T06:42:43Z vs.
Revision 1.9 by asvitkine, 2010-12-28T02:50:55Z

# Line 1 | Line 1
1   /*
2   *  VMSettingsController.mm - Preferences editing in Cocoa on Mac OS X
3   *
4 < *  Copyright (C) 2006-2009 Alexei Svitkine
4 > *  Copyright (C) 2006-2010 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
# Line 18 | Line 18
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 + #include <unistd.h>
30 +
31   const int CDROMRefNum = -62;                    // RefNum of driver
32  
33 + #ifdef STANDALONE_PREFS
34   void prefs_init()
35   {
36   }
# Line 32 | Line 38 | void prefs_init()
38   void prefs_exit()
39   {
40   }
41 + #endif
42  
43   @implementation VMSettingsController
44  
45   + (id) sharedInstance
46   {
47 <        static VMSettingsController *_sharedInstance = nil;
48 <        if (!_sharedInstance) {
49 <                _sharedInstance = [[VMSettingsController allocWithZone:[self zone]] init];
50 <        }
51 <        return _sharedInstance;
47 >  static VMSettingsController *_sharedInstance = nil;
48 >  if (!_sharedInstance) {
49 >    _sharedInstance = [[VMSettingsController allocWithZone:[self zone]] init];
50 >  }
51 >  return _sharedInstance;
52   }
53  
54   - (id) init
55   {
56    self = [super initWithWindowNibName:@"VMSettingsWindow"];
57  
58 <        cancelWasClicked = NO;
58 >  cancelWasClicked = NO;
59  
60 <        return self;
60 >  return self;
61   }
62  
63   - (int) numberOfRowsInTableView: (NSTableView *) table
# Line 135 | Line 142 | static NSString *getStringFromPrefs(cons
142    [useRawKeyCodes setIntValue: PrefsFindBool("keycodes") ];
143    [rawKeyCodes setStringValue: getStringFromPrefs("keycodefile") ];
144    [rawKeyCodes setEnabled:[useRawKeyCodes intValue]];
145 +  [browseRawKeyCodesButton setEnabled:[useRawKeyCodes intValue]];
146  
147    int wheelmode = PrefsFindInt32("mousewheelmode"), wheel = 0;
148    switch (wheelmode) {
# Line 159 | Line 167 | static NSString *getStringFromPrefs(cons
167  
168   - (void) editSettingsFor: (NSString *) vmdir sender: (id) sender
169   {
170 <        chdir([vmdir fileSystemRepresentation]);
170 >  chdir([vmdir fileSystemRepresentation]);
171 >  AddPrefsDefaults();
172 >  AddPlatformPrefsDefaults();
173 >  LoadPrefs([vmdir fileSystemRepresentation]);
174 >  NSWindow *window = [self window];
175 >  [self setupGUI];
176 >  [NSApp runModalForWindow:window];
177 > }
178 >
179 > - (void) editSettingsForNewVM: (NSString *) vmdir sender: (id) sender
180 > {
181 >  chdir([vmdir fileSystemRepresentation]);
182    AddPrefsDefaults();
183    AddPlatformPrefsDefaults();
184    LoadPrefs([vmdir fileSystemRepresentation]);
185 <        NSWindow *window = [self window];
186 <        [self setupGUI];
187 <        [NSApp runModalForWindow:window];
185 >  PrefsReplaceString("screen", "win/800/600");
186 >  PrefsReplaceString("extfs", "");
187 >  PrefsReplaceString("ether", "slirp");
188 >  PrefsReplaceInt32("ramsize", 64 << 20);
189 >  PrefsReplaceInt32("frameskip", 2);
190 >  PrefsReplaceBool("jit", true);
191 >  NSWindow *window = [self window];
192 >  [self setupGUI];
193 >  [NSApp runModalForWindow:window];
194   }
195  
196   static NSString *makeRelativeIfNecessary(NSString *path)
197   {
198 <        char cwd[1024], filename[1024];
199 <        int cwdlen;
200 <        strlcpy(filename, [path fileSystemRepresentation], sizeof(filename));
201 <        getcwd(cwd, sizeof(cwd));
202 <        cwdlen = strlen(cwd);
203 <        if (!strncmp(cwd, filename, cwdlen)) {
204 <                if (cwdlen >= 0 && cwd[cwdlen-1] != '/')
205 <                        cwdlen++;
206 <                return [NSString stringWithCString: filename + cwdlen];
207 <        }
208 <        return path;
198 >  char cwd[1024], filename[1024];
199 >  int cwdlen;
200 >  strlcpy(filename, [path fileSystemRepresentation], sizeof(filename));
201 >  getcwd(cwd, sizeof(cwd));
202 >  cwdlen = strlen(cwd);
203 >  if (!strncmp(cwd, filename, cwdlen)) {
204 >    if (cwdlen >= 0 && cwd[cwdlen-1] != '/')
205 >      cwdlen++;
206 >    return [NSString stringWithCString: filename + cwdlen];
207 >  }
208 >  return path;
209   }
210  
211   - (IBAction) addDisk: (id) sender
# Line 200 | Line 225 | static NSString *makeRelativeIfNecessary
225   - (void) _addDiskEnd: (NSOpenPanel *) open returnCode: (int) theReturnCode contextInfo: (void *) theContextInfo
226   {
227    if (theReturnCode == NSOKButton) {
228 <                [diskArray addObject: makeRelativeIfNecessary([open filename])];
228 >    [diskArray addObject: makeRelativeIfNecessary([open filename])];
229      [disks reloadData];
230    }
231   }
# Line 236 | Line 261 | static NSString *makeRelativeIfNecessary
261        snprintf(cmd, sizeof(cmd), "dd if=/dev/zero \"of=%s\" bs=1024k count=%d", [[save filename] UTF8String], [diskSaveSizeField intValue]);
262        int ret = system(cmd);
263        if (ret == 0) {
264 <                                [diskArray addObject: makeRelativeIfNecessary([save filename])];
264 >        [diskArray addObject: makeRelativeIfNecessary([save filename])];
265          [disks reloadData];
266        }
267      }
# Line 247 | Line 272 | static NSString *makeRelativeIfNecessary
272   - (IBAction) useRawKeyCodesClicked: (id) sender
273   {
274    [rawKeyCodes setEnabled:[useRawKeyCodes intValue]];
275 +  [browseRawKeyCodesButton setEnabled:[useRawKeyCodes intValue]];
276   }
277  
278   - (IBAction) browseForROMFileClicked: (id) sender
# Line 266 | Line 292 | static NSString *makeRelativeIfNecessary
292   - (void) _browseForROMFileEnd: (NSOpenPanel *) open returnCode: (int) theReturnCode contextInfo: (void *) theContextInfo
293   {
294    if (theReturnCode == NSOKButton) {
295 <                [romFile setStringValue: makeRelativeIfNecessary([open filename])];
296 <        }
295 >    [romFile setStringValue: makeRelativeIfNecessary([open filename])];
296 >  }
297   }
298  
299   - (IBAction) browseForUnixRootClicked: (id) sender
# Line 287 | Line 313 | static NSString *makeRelativeIfNecessary
313   - (void) _browseForUnixRootEnd: (NSOpenPanel *) open returnCode: (int) theReturnCode contextInfo: (void *) theContextInfo
314   {
315    if (theReturnCode == NSOKButton) {
316 <                [unixRoot setStringValue: makeRelativeIfNecessary([open filename])];
316 >    [unixRoot setStringValue: makeRelativeIfNecessary([open filename])];
317 >  }
318 > }
319 >
320 > - (IBAction) browseForKeyCodesFileClicked: (id) sender
321 > {
322 >  NSOpenPanel *open = [NSOpenPanel openPanel];
323 >  [open setCanChooseDirectories:NO];
324 >  [open setAllowsMultipleSelection:NO];
325 >  [open setTreatsFilePackagesAsDirectories:YES];
326 >  [open beginSheetForDirectory: @""
327 >                          file: [unixRoot stringValue]
328 >                modalForWindow: [self window]
329 >                 modalDelegate: self
330 >                didEndSelector: @selector(_browseForKeyCodesFileEnd: returnCode: contextInfo:)
331 >                   contextInfo: nil];
332 > }
333 >
334 > - (void) _browseForKeyCodesFileEnd: (NSOpenPanel *) open returnCode: (int) theReturnCode contextInfo: (void *) theContextInfo
335 > {
336 >  if (theReturnCode == NSOKButton) {
337 >    [rawKeyCodes setStringValue: makeRelativeIfNecessary([open filename])];
338    }
339   }
340  
341   - (void) cancelEdit: (id) sender
342   {
343 + #ifdef STANDALONE_PREFS
344    PrefsExit();
345 <        [[self window] close];
346 <        [NSApp stopModal];
347 <        cancelWasClicked = YES;
345 > #endif
346 >  [[self window] close];
347 >  [NSApp stopModal];
348 >  cancelWasClicked = YES;
349   }
350  
351   - (void) saveChanges: (id) sender
# Line 350 | Line 399 | static NSString *makeRelativeIfNecessary
399    PrefsReplaceString("serialb", [[printerPort stringValue] UTF8String]);
400    PrefsReplaceString("ether", [[ethernetInterface stringValue] UTF8String]);
401    SavePrefs();
402 + #ifdef STANDALONE_PREFS
403    PrefsExit();
404 + #endif
405  
406 <        [[self window] close];
407 <        [NSApp stopModal];
408 <        cancelWasClicked = NO;
406 >  [[self window] close];
407 >  [NSApp stopModal];
408 >  cancelWasClicked = NO;
409   }
410  
411   - (BOOL) cancelWasClicked

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines