File: ConfigurationController.m

package info (click to toggle)
pcsxr 1.9.94-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 10,500 kB
  • ctags: 16,110
  • sloc: ansic: 117,276; objc: 8,159; cpp: 1,140; makefile: 316; asm: 145; pascal: 30; sh: 20
file content (257 lines) | stat: -rw-r--r-- 8,009 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#import "ConfigurationController.h"
#import "PcsxrController.h"
#import "PluginList.h"
#import "PcsxrPlugin.h"
#import "PcsxrMemCardController.h"
#import "PcsxrMemCardHandler.h"
#include "psxcommon.h"
#include "plugins.h"

NSString *const memChangeNotifier = @"PcsxrMemoryCardDidChangeNotifier";
NSString *const memCardChangeNumberKey = @"PcsxrMemoryCardThatChangedKey";

@interface ConfigurationController ()
@property (strong) NSMutableDictionary *checkBoxDefaults;
- (NSString *)keyForSender:(id)sender;
@end

@implementation ConfigurationController
@synthesize autoVTypeCell;
@synthesize bwMdecCell;
@synthesize checkBoxDefaults = _checkBoxDefaults;
@synthesize consoleOutputCell;
@synthesize enableNetPlayCell;
@synthesize noCDAudioCell;
@synthesize noFastBootCell;
@synthesize noXaAudioCell;
@synthesize rCountFixCell;
@synthesize sioIrqAlwaysCell;
@synthesize spuIrqAlwaysCell;
@synthesize usesDynarecCell;
@synthesize usesHleCell;
@synthesize vSyncWAFixCell;
@synthesize vTypePALCell;
@synthesize widescreen;

+ (void)setMemoryCard:(NSInteger)theCard toURL:(NSURL *)theURL;
{
	if (theCard == 1) {
		[[NSUserDefaults standardUserDefaults] setURL:theURL forKey:@"Mcd1"];
		strlcpy(Config.Mcd1, [[theURL path] fileSystemRepresentation], MAXPATHLEN );
	} else {
		[[NSUserDefaults standardUserDefaults] setURL:theURL forKey:@"Mcd2"];
		strlcpy(Config.Mcd2, [[theURL path] fileSystemRepresentation], MAXPATHLEN );
	}
	
	[[NSNotificationCenter defaultCenter] postNotificationName:memChangeNotifier object:nil userInfo:
	 @{memCardChangeNumberKey: @(theCard)}];
}

+ (void)setMemoryCard:(NSInteger)theCard toPath:(NSString *)theFile
{
	[self setMemoryCard:theCard toURL:[NSURL fileURLWithPath:theFile isDirectory:NO]];
}

- (IBAction)setCheckbox:(id)sender
{
	if ([sender isKindOfClass:[NSMatrix class]]) {
		sender = [sender selectedCell];
	}

	NSString *key = [self keyForSender:sender];
	if (key) {
		[[NSUserDefaults standardUserDefaults] setBool:[sender intValue] ? YES : NO forKey:key];
		[PcsxrController setConfigFromDefaults];
	}
}

- (IBAction)setCheckboxInverse:(id)sender
{
	if ([sender isKindOfClass:[NSMatrix class]]) {
		sender = [sender selectedCell];
	}

	NSString *key = [self keyForSender:sender];
	if (key) {
		[[NSUserDefaults standardUserDefaults] setBool:[sender intValue] ? NO : YES forKey:key];
		[PcsxrController setConfigFromDefaults];
	}
}

+ (void)mcdChangeClicked:(id)sender
{
	NSInteger tag = [sender tag];
	char *mcd;
	NSOpenPanel *openDlg = [NSOpenPanel openPanel];
	NSString *path;
	
	if (tag == 1) {
		mcd = Config.Mcd1;
	} else {
		mcd = Config.Mcd2;
	}
	
	[openDlg setAllowedFileTypes:[PcsxrMemCardHandler supportedUTIs]];
	
	path = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:mcd length:strlen(mcd)];
    
    [openDlg setDirectoryURL:[NSURL fileURLWithPath:[path stringByDeletingLastPathComponent] isDirectory:YES]];
    [openDlg setNameFieldStringValue:[path lastPathComponent]];
	
	if ([openDlg runModal] == NSFileHandlingPanelOKButton) {
		NSURL *mcdURL = [openDlg URLs][0];
        
		[ConfigurationController setMemoryCard:tag toURL:mcdURL];
    }
}

+ (void)mcdNewClicked:(id)sender
{
	NSInteger tag = [sender tag];
	char *mcd;
	NSSavePanel *openDlg = [NSSavePanel savePanel];
	NSString *path;
	
	if (tag == 1) {
		mcd = Config.Mcd1;
	} else {
		mcd = Config.Mcd2;
	}
	
    path = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:mcd length:strlen(mcd)];
	
    [openDlg setDirectoryURL:[NSURL fileURLWithPath:[path stringByDeletingLastPathComponent] isDirectory:YES]];
    [openDlg setNameFieldStringValue:NSLocalizedString(@"New Memory Card.mcd", nil)];
	[openDlg setAllowedFileTypes:[PcsxrMemCardHandler supportedUTIs]];
    
	if ([openDlg runModal] == NSFileHandlingPanelOKButton) {
        NSURL *mcdURL = [openDlg URL];
		
		//Workaround/kludge to make sure we create a memory card before posting a notification
		strlcpy(mcd, [[mcdURL path] fileSystemRepresentation], MAXPATHLEN);
		CreateMcd(mcd);
		
		[ConfigurationController setMemoryCard:tag toURL:mcdURL];
    }
}

- (IBAction)setVideoType:(id)sender
{
	NSInteger tag = [[sender selectedItem] tag];
	NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
	
	if (3 == tag) {
		[defaults setBool:YES forKey:@"AutoDetectVideoType"];
	} else if (1 == tag || 2 == tag) {
		[defaults setBool:NO forKey:@"AutoDetectVideoType"];
		[defaults setBool:tag==2 forKey:@"VideoTypePAL"];
	} else {
		return;
	}
	[PcsxrController setConfigFromDefaults];

	if ([sender pullsDown]) {
		NSArray *items = [sender itemArray];
		for (id object in items) {
			[object setState:NSOffState];
		}
		
		[[sender selectedItem] setState:NSOnState];
	}
}

- (void)awakeFromNib
{
	NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

	[[self window] center];
	
	// setup checkboxes
	self.checkBoxDefaults = [[NSMutableDictionary alloc] init];

	// check that the outlets are active before adding them
	if (noXaAudioCell) _checkBoxDefaults[@"NoXaAudio"] = noXaAudioCell;
	if (enableNetPlayCell) _checkBoxDefaults[@"NetPlay"] = enableNetPlayCell;
	if (sioIrqAlwaysCell) _checkBoxDefaults[@"SioIrqAlways"] = sioIrqAlwaysCell;
	if (bwMdecCell) _checkBoxDefaults[@"BlackAndWhiteMDECVideo"] = bwMdecCell;
	if (autoVTypeCell) _checkBoxDefaults[@"AutoDetectVideoType"] = autoVTypeCell;
	if (vTypePALCell) _checkBoxDefaults[@"VideoTypePAL"] = vTypePALCell;
	if (noCDAudioCell) _checkBoxDefaults[@"NoCDAudio"] = noCDAudioCell;
	if (usesHleCell) _checkBoxDefaults[@"UseHLE"] = usesHleCell;
	if (usesDynarecCell) _checkBoxDefaults[@"NoDynarec"] = usesDynarecCell;
	if (consoleOutputCell) _checkBoxDefaults[@"ConsoleOutput"] = consoleOutputCell;
	if (spuIrqAlwaysCell) _checkBoxDefaults[@"SpuIrqAlways"] = spuIrqAlwaysCell;
	if (rCountFixCell) _checkBoxDefaults[@"RootCounterFix"] = rCountFixCell;
	if (vSyncWAFixCell) _checkBoxDefaults[@"VideoSyncWAFix"] = vSyncWAFixCell;
	if (noFastBootCell) _checkBoxDefaults[@"NoFastBoot"] = noFastBootCell;
	if (widescreen) _checkBoxDefaults[@"Widescreen"] = widescreen;

	// make the visuals match the defaults
	
	for (NSString* key in _checkBoxDefaults) {
		if ([defaults integerForKey:key]) {
			[_checkBoxDefaults[key] setNextState];
		}
	}
	
	// special cases
	if (![PcsxrController biosAvailable]) {
		// no bios means always use HLE
		[usesHleCell setState:NSOnState];
		[usesHleCell setEnabled:NO];
	}
	

	// setup labels

	NSInteger tag = [defaults integerForKey:@"AutoDetectVideoType"];
	if (tag)
		tag = 3;
	else {
		tag = [defaults integerForKey:@"VideoTypePAL"]+1;
	}
	[vTypePALCell setAutoenablesItems:NO];
	if ([vTypePALCell pullsDown]) {
		[[vTypePALCell itemAtIndex:[vTypePALCell indexOfItemWithTag:tag]] setState:NSOnState];
	} else {
		[vTypePALCell selectItemAtIndex:[vTypePALCell indexOfItemWithTag:tag]];
	}

	// setup plugin lists
	PluginList *list = [PluginList list];

	[list refreshPlugins];
	[graphicsPlugin setPluginsTo:[list pluginsForType:PSE_LT_GPU] withType: PSE_LT_GPU];
	[soundPlugin setPluginsTo:[list pluginsForType:PSE_LT_SPU] withType: PSE_LT_SPU];
	[padPlugin setPluginsTo:[list pluginsForType:PSE_LT_PAD] withType: PSE_LT_PAD];
	[cdromPlugin setPluginsTo:[list pluginsForType:PSE_LT_CDR] withType: PSE_LT_CDR];
	[netPlugin setPluginsTo:[list pluginsForType:PSE_LT_NET] withType: PSE_LT_NET];
	[sio1Plugin setPluginsTo:[list pluginsForType:PSE_LT_SIO1] withType:PSE_LT_SIO1];
    
    // Setup hotkey view
    [hkController initialize];
}

- (NSString *)keyForSender:(id)sender
{
	for (NSString *key in [self.checkBoxDefaults keyEnumerator]) {
		id object = (self.checkBoxDefaults)[key];
		if ([object isEqual:sender])
			return key;
	}
	
	return nil;
}

- (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem
{
    NSWindow *window = [self window];
    if(tabViewItem == hkTab) {
        [window makeFirstResponder:(NSView*)hkController];
    }
    else if([window firstResponder] == (NSView*)hkController) {
        [hkController resignFirstResponder];
    }
}

@end