2 * Copyright (c) 2010, Wei Mingzhi <whistler@openoffice.org>.
5 * Based on: Cdrom for Psemu Pro like Emulators
6 * By: linuzappz <linuzappz@hotmail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses>.
22 #import "PluginConfigController.h"
25 #define APP_ID @"net.pcsx.DFCdrom"
26 #define PrefsKey APP_ID @" Settings"
28 static PluginConfigController *windowController;
32 // Get parent application instance
33 NSApplication *app = [NSApplication sharedApplication];
34 NSBundle *bundle = [NSBundle bundleWithIdentifier:APP_ID];
37 NSString *path = [bundle pathForResource:@"Credits" ofType:@"rtf"];
38 NSAttributedString *credits;
40 credits = [[[NSAttributedString alloc] initWithPath: path
41 documentAttributes:NULL] autorelease];
43 credits = [[[NSAttributedString alloc] initWithString:@""] autorelease];
46 // Get Application Icon
47 NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFile:[bundle bundlePath]];
48 NSSize size = NSMakeSize(64, 64);
51 [app orderFrontStandardAboutPanelWithOptions:[NSDictionary dictionaryWithObjectsAndKeys:
52 [bundle objectForInfoDictionaryKey:@"CFBundleName"], @"ApplicationName",
53 icon, @"ApplicationIcon",
54 [bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"], @"ApplicationVersion",
55 [bundle objectForInfoDictionaryKey:@"CFBundleVersion"], @"Version",
56 [bundle objectForInfoDictionaryKey:@"NSHumanReadableCopyright"], @"Copyright",
65 if (windowController == nil) {
66 windowController = [[PluginConfigController alloc] initWithWindowNibName:@"DFCdromPluginConfig"];
68 window = [windowController window];
70 [windowController loadValues];
73 [window makeKeyAndOrderFront:nil];
78 NSDictionary *keyValues;
79 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
80 [defaults registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:
81 [[NSMutableDictionary alloc] initWithObjectsAndKeys:
82 [NSNumber numberWithBool:YES], @"Threaded",
83 [NSNumber numberWithInt:64], @"Cache Size",
84 [NSNumber numberWithInt:0], @"Speed",
85 nil], PrefsKey, nil]];
87 keyValues = [defaults dictionaryForKey:PrefsKey];
89 ReadMode = ([[keyValues objectForKey:@"Threaded"] boolValue] ? THREADED : NORMAL);
90 CacheSize = [[keyValues objectForKey:@"Cache Size"] intValue];
91 CdrSpeed = [[keyValues objectForKey:@"Speed"] intValue];
94 @implementation PluginConfigController
96 - (IBAction)cancel:(id)sender
101 - (IBAction)ok:(id)sender
103 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
105 NSMutableDictionary *writeDic = [NSMutableDictionary dictionaryWithDictionary:keyValues];
107 [writeDic setObject:[NSNumber numberWithInt:[Cached intValue]] forKey:@"Threaded"];
108 [writeDic setObject:[NSNumber numberWithInt:[CacheSize intValue]] forKey:@"Cache Size"];
110 switch ([CdSpeed indexOfSelectedItem]) {
111 case 1: [writeDic setObject:[NSNumber numberWithInt:1] forKey:@"Speed"]; break;
112 case 2: [writeDic setObject:[NSNumber numberWithInt:2] forKey:@"Speed"]; break;
113 case 3: [writeDic setObject:[NSNumber numberWithInt:4] forKey:@"Speed"]; break;
114 case 4: [writeDic setObject:[NSNumber numberWithInt:8] forKey:@"Speed"]; break;
115 case 5: [writeDic setObject:[NSNumber numberWithInt:16] forKey:@"Speed"]; break;
116 case 6: [writeDic setObject:[NSNumber numberWithInt:32] forKey:@"Speed"]; break;
117 default: [writeDic setObject:[NSNumber numberWithInt:0] forKey:@"Speed"]; break;
121 [defaults setObject:writeDic forKey:PrefsKey];
122 [defaults synchronize];
124 // and set global values accordingly
132 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
136 // load from preferences
138 keyValues = [[defaults dictionaryForKey:PrefsKey] retain];
140 [Cached setIntValue:[[keyValues objectForKey:@"Threaded"] intValue]];
141 [CacheSize setIntValue:[[keyValues objectForKey:@"Cache Size"] intValue]];
143 switch ([[keyValues objectForKey:@"Speed"] intValue]) {
144 case 1: [CdSpeed selectItemAtIndex:1]; break;
145 case 2: [CdSpeed selectItemAtIndex:2]; break;
146 case 4: [CdSpeed selectItemAtIndex:3]; break;
147 case 8: [CdSpeed selectItemAtIndex:4]; break;
148 case 16: [CdSpeed selectItemAtIndex:5]; break;
149 case 32: [CdSpeed selectItemAtIndex:6]; break;
150 default: [CdSpeed selectItemAtIndex:0]; break;