| 1 | /* |
| 2 | * Copyright (c) 2010, Wei Mingzhi <whistler@openoffice.org>. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * Based on: Cdrom for Psemu Pro like Emulators |
| 6 | * By: linuzappz <linuzappz@hotmail.com> |
| 7 | * |
| 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. |
| 12 | * |
| 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. |
| 17 | * |
| 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>. |
| 20 | */ |
| 21 | |
| 22 | #import "PluginConfigController.h" |
| 23 | #include "cdr.h" |
| 24 | |
| 25 | #define APP_ID @"net.pcsx.DFCdrom" |
| 26 | #define PrefsKey APP_ID @" Settings" |
| 27 | |
| 28 | static PluginConfigController *windowController; |
| 29 | |
| 30 | void AboutDlgProc() |
| 31 | { |
| 32 | // Get parent application instance |
| 33 | NSApplication *app = [NSApplication sharedApplication]; |
| 34 | NSBundle *bundle = [NSBundle bundleWithIdentifier:APP_ID]; |
| 35 | |
| 36 | // Get Credits.rtf |
| 37 | NSString *path = [bundle pathForResource:@"Credits" ofType:@"rtf"]; |
| 38 | NSAttributedString *credits; |
| 39 | if (path) { |
| 40 | credits = [[[NSAttributedString alloc] initWithPath: path |
| 41 | documentAttributes:NULL] autorelease]; |
| 42 | } else { |
| 43 | credits = [[[NSAttributedString alloc] initWithString:@""] autorelease]; |
| 44 | } |
| 45 | |
| 46 | // Get Application Icon |
| 47 | NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFile:[bundle bundlePath]]; |
| 48 | NSSize size = NSMakeSize(64, 64); |
| 49 | [icon setSize:size]; |
| 50 | |
| 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", |
| 57 | credits, @"Credits", |
| 58 | nil]]; |
| 59 | } |
| 60 | |
| 61 | void ConfDlgProc() |
| 62 | { |
| 63 | NSWindow *window; |
| 64 | |
| 65 | if (windowController == nil) { |
| 66 | windowController = [[PluginConfigController alloc] initWithWindowNibName:@"DFCdromPluginConfig"]; |
| 67 | } |
| 68 | window = [windowController window]; |
| 69 | |
| 70 | [windowController loadValues]; |
| 71 | |
| 72 | [window center]; |
| 73 | [window makeKeyAndOrderFront:nil]; |
| 74 | } |
| 75 | |
| 76 | void ReadConfig() |
| 77 | { |
| 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]]; |
| 86 | |
| 87 | keyValues = [defaults dictionaryForKey:PrefsKey]; |
| 88 | |
| 89 | ReadMode = ([[keyValues objectForKey:@"Threaded"] boolValue] ? THREADED : NORMAL); |
| 90 | CacheSize = [[keyValues objectForKey:@"Cache Size"] intValue]; |
| 91 | CdrSpeed = [[keyValues objectForKey:@"Speed"] intValue]; |
| 92 | } |
| 93 | |
| 94 | @implementation PluginConfigController |
| 95 | |
| 96 | - (IBAction)cancel:(id)sender |
| 97 | { |
| 98 | [self close]; |
| 99 | } |
| 100 | |
| 101 | - (IBAction)ok:(id)sender |
| 102 | { |
| 103 | NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; |
| 104 | |
| 105 | NSMutableDictionary *writeDic = [NSMutableDictionary dictionaryWithDictionary:keyValues]; |
| 106 | |
| 107 | [writeDic setObject:[NSNumber numberWithInt:[Cached intValue]] forKey:@"Threaded"]; |
| 108 | [writeDic setObject:[NSNumber numberWithInt:[CacheSize intValue]] forKey:@"Cache Size"]; |
| 109 | |
| 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; |
| 118 | } |
| 119 | |
| 120 | // write to defaults |
| 121 | [defaults setObject:writeDic forKey:PrefsKey]; |
| 122 | [defaults synchronize]; |
| 123 | |
| 124 | // and set global values accordingly |
| 125 | ReadConfig(); |
| 126 | |
| 127 | [self close]; |
| 128 | } |
| 129 | |
| 130 | - (void)loadValues |
| 131 | { |
| 132 | NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; |
| 133 | |
| 134 | ReadConfig(); |
| 135 | |
| 136 | // load from preferences |
| 137 | [keyValues release]; |
| 138 | keyValues = [[defaults dictionaryForKey:PrefsKey] retain]; |
| 139 | |
| 140 | [Cached setIntValue:[[keyValues objectForKey:@"Threaded"] intValue]]; |
| 141 | [CacheSize setIntValue:[[keyValues objectForKey:@"Cache Size"] intValue]]; |
| 142 | |
| 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; |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | - (void)awakeFromNib |
| 155 | { |
| 156 | } |
| 157 | |
| 158 | @end |