4 |
|
* |
5 |
|
* $Id$ |
6 |
|
* |
7 |
< |
* Basilisk II (C) 1997-2003 Christian Bauer |
7 |
> |
* Basilisk II (C) 1997-2005 Christian Bauer |
8 |
|
* |
9 |
|
* This program is free software; you can redistribute it and/or modify |
10 |
|
* it under the terms of the GNU General Public License as published by |
105 |
|
|
106 |
|
@end |
107 |
|
|
108 |
– |
@implementation PrefsEditor |
109 |
– |
|
108 |
|
#import <AppKit/NSImage.h> // For [NSBundle pathForImageResource:] proto |
109 |
|
|
110 |
+ |
#include <string> |
111 |
+ |
using std::string; |
112 |
+ |
extern string UserPrefsPath; // from prefs_unix.cpp |
113 |
+ |
|
114 |
|
#import "sysdeps.h" // Types used in Basilisk C++ code |
115 |
|
#import "video_macosx.h" // some items that we edit here |
116 |
|
#import "misc_macosx.h" // WarningSheet() prototype |
117 |
+ |
#import "main_macosx.h" // ChoiceAlert() prototype |
118 |
+ |
|
119 |
|
|
120 |
|
#import <prefs.h> |
121 |
|
|
122 |
|
#define DEBUG 0 |
123 |
|
#import <debug.h> |
124 |
|
|
125 |
+ |
@implementation PrefsEditor |
126 |
+ |
|
127 |
|
- (PrefsEditor *) init |
128 |
|
{ |
129 |
|
self = [super init]; |
131 |
|
edited = NO; |
132 |
|
|
133 |
|
devs = @"/dev"; |
134 |
< |
home = NSHomeDirectory(); |
134 |
> |
home = [NSHomeDirectory() retain]; |
135 |
|
volsDS = [TableDS new]; |
136 |
|
SCSIds = [TableDS new]; |
137 |
|
|
140 |
|
NSLog (@"%s - Can't create NSImageCell?", __PRETTY_FUNCTION__); |
141 |
|
|
142 |
|
blank = [NSImage new]; |
143 |
< |
locked = [NSImage alloc]; |
144 |
< |
if ( [locked initWithContentsOfFile: |
145 |
< |
[[NSBundle mainBundle] |
140 |
< |
pathForImageResource: @"nowrite.icns"]] == nil ) |
143 |
> |
locked = [[NSImage alloc] initWithContentsOfFile: |
144 |
> |
[[NSBundle mainBundle] pathForImageResource: @"nowrite.icns"]]; |
145 |
> |
if (locked == nil ) |
146 |
|
NSLog(@"%s - Couldn't open write protection image", __PRETTY_FUNCTION__); |
147 |
|
|
148 |
|
return self; |
150 |
|
|
151 |
|
- (void) dealloc |
152 |
|
{ |
153 |
< |
[volsDS dealloc]; |
154 |
< |
[SCSIds dealloc]; |
155 |
< |
[lockCell dealloc]; |
156 |
< |
[locked dealloc]; |
157 |
< |
[blank dealloc]; |
153 |
> |
[home release]; |
154 |
> |
[volsDS release]; |
155 |
> |
[SCSIds release]; |
156 |
> |
[lockCell release]; |
157 |
> |
[blank release]; |
158 |
> |
[locked release]; |
159 |
|
[super dealloc]; |
160 |
|
} |
161 |
|
|
198 |
|
{ |
199 |
|
[volsDS addObject: (NSObject *) locked |
200 |
|
withPath: [oP filename] ]; |
201 |
< |
PrefsAddString("disk", [[oP filename] cString]); |
201 |
> |
PrefsAddString("disk", [[oP filename] UTF8String]); |
202 |
|
[diskImages reloadData]; |
203 |
|
edited = YES; |
204 |
|
} |
219 |
|
types:nil] == NSOKButton ) |
220 |
|
{ |
221 |
|
[extFS setStringValue: [oP directory] ]; |
222 |
< |
PrefsReplaceString("extfs", [[oP directory] cString]); |
222 |
> |
PrefsReplaceString("extfs", [[oP directory] UTF8String]); |
223 |
|
edited = YES; |
224 |
|
} |
225 |
|
} |
226 |
|
|
227 |
+ |
- (IBAction) BrowsePrefs: (id)sender |
228 |
+ |
{ |
229 |
+ |
NSOpenPanel *oP = [NSOpenPanel openPanel]; |
230 |
+ |
|
231 |
+ |
[oP setCanChooseFiles: YES]; |
232 |
+ |
[oP setTitle: @"Select a Preferences file"]; |
233 |
+ |
D(NSLog(@"%s - home = %@", __PRETTY_FUNCTION__, home)); |
234 |
+ |
if ( [oP runModalForDirectory: ([prefsFile stringValue] ? [prefsFile stringValue] : home) |
235 |
+ |
file:nil |
236 |
+ |
types:nil] == NSOKButton ) |
237 |
+ |
{ |
238 |
+ |
[prefsFile setStringValue: [oP filename] ]; |
239 |
+ |
UserPrefsPath = [[oP filename] UTF8String]; |
240 |
+ |
} |
241 |
+ |
} |
242 |
+ |
|
243 |
|
- (IBAction) BrowseROM: (id)sender |
244 |
|
{ |
245 |
|
NSOpenPanel *oP = [NSOpenPanel openPanel]; |
252 |
|
types:nil] == NSOKButton ) |
253 |
|
{ |
254 |
|
[ROMfile setStringValue: [oP filename] ]; |
255 |
< |
PrefsReplaceString("rom", [[oP filename] cString]); |
255 |
> |
PrefsReplaceString("rom", [[oP filename] UTF8String]); |
256 |
|
edited = YES; |
257 |
|
} |
258 |
|
} |
261 |
|
|
262 |
|
- (IBAction) ChangeBootFrom: (NSMatrix *)sender |
263 |
|
{ |
264 |
< |
if ( [sender selectedCell] == bootFromCD ) |
264 |
> |
if ( [sender selectedCell] == (id)bootFromCD ) |
265 |
> |
{ |
266 |
> |
[disableCD setState: NSOffState]; |
267 |
> |
|
268 |
|
PrefsReplaceInt32("bootdriver", CDROMRefNum); |
269 |
+ |
} |
270 |
|
else |
271 |
|
PrefsReplaceInt32("bootdriver", 0); |
272 |
|
edited = YES; |
280 |
|
|
281 |
|
- (IBAction) ChangeDisableCD: (NSButton *)sender |
282 |
|
{ |
283 |
< |
PrefsReplaceBool("nocdrom", [disableCD state]); |
283 |
> |
int disabled = [disableCD state]; |
284 |
> |
|
285 |
> |
PrefsReplaceBool("nocdrom", disabled); |
286 |
> |
if ( disabled ) |
287 |
> |
{ |
288 |
> |
[bootFromAny setState: NSOnState]; |
289 |
> |
[bootFromCD setState: ![disableCD state]]; |
290 |
> |
} |
291 |
|
edited = YES; |
292 |
|
} |
293 |
|
|
308 |
|
edited = YES; |
309 |
|
} |
310 |
|
|
311 |
+ |
- (IBAction) ChangeKeyboard: (NSPopUpButton *)sender |
312 |
+ |
{ |
313 |
+ |
// Deselest current item |
314 |
+ |
int current = [keyboard indexOfItemWithTag: PrefsFindInt32("keyboardtype")]; |
315 |
+ |
if ( current != -1 ) |
316 |
+ |
[[keyboard itemAtIndex: current] setState: FALSE]; |
317 |
+ |
|
318 |
+ |
PrefsReplaceInt32("keyboardtype", [[sender selectedItem] tag]); |
319 |
+ |
edited = YES; |
320 |
+ |
} |
321 |
+ |
|
322 |
|
- (IBAction) ChangeModel: (NSMatrix *)sender |
323 |
|
{ |
324 |
|
PrefsReplaceInt32("modelid", [[sender selectedCell] tag]); |
340 |
|
#endif |
341 |
|
} |
342 |
|
|
343 |
< |
// This is called when any of the screen/openGL/window, |
343 |
> |
// This is called when the screen/window, |
344 |
|
// width, height or depth is clicked. |
345 |
|
// |
346 |
|
// Note that sender may not actually be an NSMatrix. |
355 |
|
short newtype; |
356 |
|
char str[20]; |
357 |
|
|
358 |
< |
if ( cell == openGL ) |
315 |
< |
newtype = DISPLAY_OPENGL; |
316 |
< |
else if ( cell == screen ) |
358 |
> |
if ( cell == screen ) |
359 |
|
newtype = DISPLAY_SCREEN; |
360 |
|
else if ( cell == window ) |
361 |
|
newtype = DISPLAY_WINDOW; |
415 |
|
else |
416 |
|
sprintf(str, "win/%hd/%hd", newx, newy); |
417 |
|
break; |
376 |
– |
case DISPLAY_OPENGL: |
377 |
– |
if ( newbpp ) |
378 |
– |
sprintf(str, "opengl/%hd/%hd/%hd", newx, newy, newbpp); |
379 |
– |
else |
380 |
– |
sprintf(str, "opengl/%hd/%hd", newx, newy); |
381 |
– |
break; |
418 |
|
case DISPLAY_SCREEN: |
419 |
|
if ( newbpp ) |
420 |
|
sprintf(str, "full/%hd/%hd/%hd", newx, newy, newbpp); |
447 |
|
if ( [sP runModalForDirectory:NSHomeDirectory() file:@"basilisk-II.vol"] == NSOKButton ) |
448 |
|
{ |
449 |
|
char cmd[1024]; |
450 |
< |
const char *filename = [[sP filename] cString]; |
450 |
> |
const char *filename = [[sP filename] UTF8String]; |
451 |
|
int retVal, |
452 |
|
size = [newVolumeSize intValue]; |
453 |
|
|
454 |
|
sprintf(cmd, "dd if=/dev/zero \"of=%s\" bs=1024k count=%d", filename, size); |
455 |
+ |
|
456 |
|
retVal = system(cmd); |
457 |
|
if (retVal != 0) |
458 |
|
{ |
485 |
|
|
486 |
|
- (IBAction) DeleteVolume: (id)sender |
487 |
|
{ |
451 |
– |
// const char *path = [self RemoveVolumeEntry]; |
452 |
– |
// if ( unlink(path) == -1 ) |
488 |
|
NSString *Path = [self RemoveVolumeEntry]; |
489 |
|
|
490 |
+ |
if ( ! Path ) |
491 |
+ |
return; |
492 |
+ |
|
493 |
|
if ( ! [[NSFileManager defaultManager] removeFileAtPath: Path |
494 |
|
handler: self] ) |
495 |
|
{ |
496 |
|
WarningSheet(@"Unable to delete volume", panel); |
497 |
< |
// NSLog(@"%s unlink(%s) failed - %s", __PRETTY_FUNCTION__, path, strerror(errno)); |
497 |
> |
NSLog(@"%s unlink(%s) failed - %s", __PRETTY_FUNCTION__, |
498 |
> |
[Path cString], strerror(errno)); |
499 |
|
} |
500 |
|
} |
501 |
|
|
530 |
|
{ |
531 |
|
NSString *path = [etherNet stringValue]; |
532 |
|
|
533 |
< |
PrefsReplaceString("ether", [path cString]); |
533 |
> |
PrefsReplaceString("ether", [path UTF8String]); |
534 |
|
edited = YES; |
535 |
|
} |
536 |
|
|
538 |
|
{ |
539 |
|
NSString *path = [extFS stringValue]; |
540 |
|
|
541 |
< |
PrefsReplaceString("extfs", [path cString]); |
541 |
> |
PrefsReplaceString("extfs", [path UTF8String]); |
542 |
|
edited = YES; |
543 |
|
} |
544 |
|
|
555 |
|
{ |
556 |
|
NSString *path = [modem stringValue]; |
557 |
|
|
558 |
< |
PrefsReplaceString("seriala", [path cString]); |
558 |
> |
PrefsReplaceString("seriala", [path UTF8String]); |
559 |
|
edited = YES; |
560 |
|
} |
561 |
|
|
574 |
|
{ |
575 |
|
NSString *path = [printer stringValue]; |
576 |
|
|
577 |
< |
PrefsReplaceString("serialb", [path cString]); |
577 |
> |
PrefsReplaceString("serialb", [path UTF8String]); |
578 |
|
edited = YES; |
579 |
|
} |
580 |
|
|
582 |
|
{ |
583 |
|
NSString *path = [ROMfile stringValue]; |
584 |
|
|
585 |
< |
PrefsReplaceString("rom", [path cString]); |
585 |
> |
PrefsReplaceString("rom", [path UTF8String]); |
586 |
|
} |
587 |
|
|
588 |
|
- (IBAction) RemoveSCSI: (id)sender |
595 |
|
NSLog (@"%s - [SCSIds deleteRow: %d] failed", __PRETTY_FUNCTION__, row); |
596 |
|
[SCSIdisks reloadData]; |
597 |
|
sprintf(pref, "scsi%d", SCSIid); |
598 |
< |
PrefsRemoveItem(pref,0); |
598 |
> |
//PrefsRemoveItem(pref,0); |
599 |
> |
PrefsRemoveItem(pref, 1); |
600 |
|
} |
601 |
|
|
562 |
– |
//- (const char *) RemoveVolumeEntry |
602 |
|
- (NSString *) RemoveVolumeEntry |
603 |
|
{ |
604 |
|
int row = [diskImages selectedRow]; |
606 |
|
if ( row != -1 ) |
607 |
|
{ |
608 |
|
NSString *Path = [volsDS pathAtRow: row]; |
609 |
< |
const char *path = [Path cString], |
609 |
> |
const char *path = [Path UTF8String], |
610 |
|
*str; |
611 |
|
int tmp = 0; |
612 |
|
|
613 |
+ |
NSString *prompt = [NSString stringWithFormat: @"%s\n%s", |
614 |
+ |
"Are you sure you want to delete the file", |
615 |
+ |
path]; |
616 |
+ |
|
617 |
+ |
if ( ! ChoiceAlert([prompt cString], "Delete", "Cancel") ) |
618 |
+ |
return NULL; |
619 |
+ |
|
620 |
|
while ( (str = PrefsFindString("disk", tmp) ) != NULL ) |
621 |
|
{ |
622 |
|
if ( strcmp(str, path) == 0 ) |
655 |
|
[self RemoveVolumeEntry]; |
656 |
|
} |
657 |
|
|
658 |
< |
- (IBAction) ResetPrefs: (id)sender |
658 |
> |
- (void) loadPrefs: (int) argc |
659 |
> |
args: (char **) argv |
660 |
|
{ |
614 |
– |
int argc = 0; |
615 |
– |
char **argv = NULL; |
616 |
– |
|
661 |
|
[panel close]; // Temporarily hide preferences panel |
662 |
|
|
663 |
|
PrefsExit(); // Purge all the old pref values |
673 |
|
edited = NO; |
674 |
|
} |
675 |
|
|
676 |
+ |
- (IBAction) LoadPrefs: (id)sender |
677 |
+ |
{ |
678 |
+ |
int argc = 2; |
679 |
+ |
char *argv[2]; |
680 |
+ |
|
681 |
+ |
argv[0] = "--prefs", |
682 |
+ |
argv[1] = (char *) [[prefsFile stringValue] UTF8String]; |
683 |
+ |
|
684 |
+ |
[self loadPrefs: argc |
685 |
+ |
args: argv]; |
686 |
+ |
} |
687 |
+ |
|
688 |
+ |
- (IBAction) ResetPrefs: (id)sender |
689 |
+ |
{ |
690 |
+ |
[self loadPrefs: 0 |
691 |
+ |
args: NULL]; |
692 |
+ |
} |
693 |
+ |
|
694 |
|
- (void) setStringOf: (NSTextField *) field |
695 |
< |
fromPref: (const char *) prefName |
695 |
> |
fromPref: (const char *) prefName |
696 |
|
{ |
697 |
|
const char *value = PrefsFindString(prefName, 0); |
698 |
|
|
699 |
|
if ( value ) |
700 |
< |
[field setStringValue: [NSString stringWithCString: value] ]; |
700 |
> |
[field setStringValue: [NSString stringWithUTF8String: value] ]; |
701 |
|
} |
702 |
|
|
703 |
|
- (IBAction) SavePrefs: (id)sender |
710 |
|
{ |
711 |
|
NSTableColumn *locks; |
712 |
|
const char *str; |
713 |
< |
int cpu, tmp; |
713 |
> |
int cpu, tmp, val; |
714 |
|
|
715 |
|
|
716 |
|
// Set simple single field items |
717 |
|
|
718 |
< |
tmp = PrefsFindInt32("frameskip"); |
719 |
< |
[delay setIntValue: tmp]; |
720 |
< |
if ( tmp ) |
721 |
< |
[frequency setFloatValue: 60.0 / tmp]; |
718 |
> |
val = PrefsFindInt32("frameskip"); |
719 |
> |
[delay setIntValue: val]; |
720 |
> |
if ( val ) |
721 |
> |
[frequency setFloatValue: 60.0 / val]; |
722 |
|
else |
723 |
|
[frequency setFloatValue: 60.0]; |
724 |
|
|
725 |
< |
tmp = PrefsFindInt32("ramsize"); |
726 |
< |
[bytes setIntValue: tmp]; |
727 |
< |
[MB setFloatValue: tmp / (1024.0 * 1024.0)]; |
725 |
> |
val = PrefsFindInt32("ramsize"); |
726 |
> |
[bytes setIntValue: val]; |
727 |
> |
[MB setFloatValue: val / (1024.0 * 1024.0)]; |
728 |
|
|
729 |
|
[disableCD setState: PrefsFindBool("nocdrom")]; |
730 |
|
[disableSound setState: PrefsFindBool("nosound")]; |
734 |
|
[self setStringOf: extFS fromPref: "extfs" ]; |
735 |
|
[self setStringOf: modem fromPref: "seriala"]; |
736 |
|
[self setStringOf: printer fromPref: "serialb"]; |
737 |
< |
[self setStringOf: ROMfile fromPref: "rom" ]; |
737 |
> |
[self setStringOf: ROMfile fromPref: "rom"]; |
738 |
> |
|
739 |
> |
[prefsFile setStringValue: [NSString stringWithUTF8String: UserPrefsPath.c_str()] ]; |
740 |
|
|
741 |
|
|
742 |
|
parse_screen_prefs(PrefsFindString("screen")); |
745 |
|
[height setIntValue: init_height]; |
746 |
|
[depth setIntValue: init_depth]; |
747 |
|
|
748 |
< |
[window setState: NO]; |
748 |
> |
[screen setState: NO]; |
749 |
|
switch ( display_type ) |
750 |
|
{ |
751 |
|
case DISPLAY_WINDOW: [window setState: YES]; break; |
688 |
– |
case DISPLAY_OPENGL: [openGL setState: YES]; break; |
752 |
|
case DISPLAY_SCREEN: [screen setState: YES]; break; |
753 |
|
} |
754 |
|
|
756 |
|
|
757 |
|
// Radio button groups: |
758 |
|
|
759 |
< |
tmp = PrefsFindInt32("bootdriver"); |
760 |
< |
[bootFromAny setState: tmp != CDROMRefNum]; |
761 |
< |
[bootFromCD setState: tmp == CDROMRefNum]; |
759 |
> |
val = PrefsFindInt32("bootdriver"); |
760 |
> |
[bootFromAny setState: val != CDROMRefNum]; |
761 |
> |
[bootFromCD setState: val == CDROMRefNum]; |
762 |
|
|
763 |
|
cpu = PrefsFindInt32("cpu"); |
764 |
< |
tmp = PrefsFindInt32("modelid"); |
764 |
> |
val = PrefsFindInt32("modelid"); |
765 |
|
|
766 |
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
767 |
|
puts("Current memory model does not support 24bit addressing"); |
768 |
< |
if ( tmp == [classic tag] ) |
768 |
> |
if ( val == [classic tag] ) |
769 |
|
{ |
770 |
|
// Window already created by NIB file, just display |
771 |
|
[panel makeKeyAndOrderFront:self]; |
773 |
|
@"Disabling Mac Classic emulation", nil, panel); |
774 |
|
cpu = [CPU68030 tag]; |
775 |
|
PrefsReplaceInt32("cpu", cpu); |
776 |
< |
tmp = [IIci tag]; |
777 |
< |
PrefsReplaceInt32("modelid", tmp); |
776 |
> |
val = [IIci tag]; |
777 |
> |
PrefsReplaceInt32("modelid", val); |
778 |
|
} |
779 |
|
|
780 |
|
puts("Disabling 68000 & Mac Classic buttons"); |
787 |
|
[CPU68030 setState: [CPU68030 tag] == cpu]; |
788 |
|
[CPU68040 setState: [CPU68040 tag] == cpu]; |
789 |
|
|
790 |
< |
[classic setState: [classic tag] == tmp]; |
791 |
< |
[IIci setState: [IIci tag] == tmp]; |
792 |
< |
[quadra900 setState: [quadra900 tag] == tmp]; |
790 |
> |
[classic setState: [classic tag] == val]; |
791 |
> |
[IIci setState: [IIci tag] == val]; |
792 |
> |
[quadra900 setState: [quadra900 tag] == val]; |
793 |
|
|
794 |
|
|
795 |
|
// Lists of thingies: |
796 |
|
|
797 |
+ |
val = PrefsFindInt32("keyboardtype"); |
798 |
+ |
tmp = [keyboard indexOfItemWithTag: val]; |
799 |
+ |
if ( tmp != -1 ) |
800 |
+ |
[keyboard selectItemAtIndex: tmp]; |
801 |
+ |
for ( tmp = 0; tmp < [keyboard numberOfItems]; ++tmp ) |
802 |
+ |
{ |
803 |
+ |
NSMenuItem *type = [keyboard itemAtIndex: tmp]; |
804 |
+ |
[type setState: [type tag] == val]; |
805 |
+ |
} |
806 |
+ |
|
807 |
+ |
|
808 |
|
for ( tmp = 0; tmp < 7; ++tmp) |
809 |
|
{ |
810 |
|
char pref[6]; |
829 |
|
{ |
830 |
|
if ( *str == '*' ) |
831 |
|
[volsDS addObject: (NSObject *) locked |
832 |
< |
withPath: [NSString stringWithCString: str+1]]; |
832 |
> |
withPath: [NSString stringWithUTF8String: str+1]]; |
833 |
|
else |
834 |
|
[volsDS addObject: (NSObject *) blank |
835 |
< |
withPath: [NSString stringWithCString: str]]; |
835 |
> |
withPath: [NSString stringWithUTF8String: str]]; |
836 |
|
} |
837 |
|
|
838 |
|
[diskImages setDataSource: volsDS]; |