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> |
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] |
144 |
< |
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 |
|
} |
236 |
|
types:nil] == NSOKButton ) |
237 |
|
{ |
238 |
|
[prefsFile setStringValue: [oP filename] ]; |
239 |
< |
UserPrefsPath = [[oP filename] cString]; |
239 |
> |
UserPrefsPath = [[oP filename] UTF8String]; |
240 |
|
} |
241 |
|
} |
242 |
|
|
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]); |
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 |
|
{ |
463 |
– |
// const char *path = [self RemoveVolumeEntry]; |
464 |
– |
// 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 |
|
|
574 |
– |
//- (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 ) |
679 |
|
char *argv[2]; |
680 |
|
|
681 |
|
argv[0] = "--prefs", |
682 |
< |
argv[1] = (char *) [[prefsFile stringValue] cString]; |
682 |
> |
argv[1] = (char *) [[prefsFile stringValue] UTF8String]; |
683 |
|
|
684 |
|
[self loadPrefs: argc |
685 |
|
args: argv]; |
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 stringWithCString: UserPrefsPath.c_str()] ]; |
739 |
> |
[prefsFile setStringValue: [NSString stringWithUTF8String: UserPrefsPath.c_str()] ]; |
740 |
|
|
741 |
|
|
742 |
|
parse_screen_prefs(PrefsFindString("screen")); |
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]; |