| 1 | #import "PluginController.h" |
| 2 | #import "PcsxPlugin.h" |
| 3 | #import "PcsxController.h" |
| 4 | |
| 5 | @implementation PluginController |
| 6 | |
| 7 | - (IBAction)doAbout:(id)sender |
| 8 | { |
| 9 | PcsxPlugin *plugin = [plugins objectAtIndex:[pluginMenu indexOfSelectedItem]]; |
| 10 | [plugin aboutAs:pluginType]; |
| 11 | } |
| 12 | |
| 13 | - (IBAction)doConfigure:(id)sender |
| 14 | { |
| 15 | PcsxPlugin *plugin = [plugins objectAtIndex:[pluginMenu indexOfSelectedItem]]; |
| 16 | |
| 17 | [plugin configureAs:pluginType]; |
| 18 | } |
| 19 | |
| 20 | - (IBAction)selectPlugin:(id)sender |
| 21 | { |
| 22 | if (sender==pluginMenu) { |
| 23 | int index = [pluginMenu indexOfSelectedItem]; |
| 24 | if (index != -1) { |
| 25 | PcsxPlugin *plugin = [plugins objectAtIndex:index]; |
| 26 | |
| 27 | if (![[PluginList list] setActivePlugin:plugin forType:pluginType]) { |
| 28 | /* plugin won't initialize */ |
| 29 | } |
| 30 | |
| 31 | // write selection to defaults |
| 32 | [[NSUserDefaults standardUserDefaults] setObject:[plugin path] forKey:defaultKey]; |
| 33 | |
| 34 | // set button states |
| 35 | [aboutButton setEnabled:[plugin hasAboutAs:pluginType]]; |
| 36 | [configureButton setEnabled:[plugin hasConfigureAs:pluginType]]; |
| 37 | } else { |
| 38 | // set button states |
| 39 | [aboutButton setEnabled:NO]; |
| 40 | [configureButton setEnabled:NO]; |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | // must be called before anything else |
| 46 | - (void)setPluginsTo:(NSArray *)list withType:(int)type |
| 47 | { |
| 48 | NSString *sel; |
| 49 | int i; |
| 50 | |
| 51 | // remember the list |
| 52 | pluginType = type; |
| 53 | plugins = [list retain]; |
| 54 | defaultKey = [[PcsxPlugin getDefaultKeyForType:pluginType] retain]; |
| 55 | |
| 56 | // clear the previous menu items |
| 57 | [pluginMenu removeAllItems]; |
| 58 | |
| 59 | // load the currently selected plugin |
| 60 | sel = [[NSUserDefaults standardUserDefaults] stringForKey:defaultKey]; |
| 61 | |
| 62 | // add the menu entries |
| 63 | for (i = 0; i < [plugins count]; i++) { |
| 64 | [pluginMenu addItemWithTitle:[[plugins objectAtIndex:i] description]]; |
| 65 | |
| 66 | // make sure the currently selected is set as such |
| 67 | if ([sel isEqualToString:[[plugins objectAtIndex:i] path]]) { |
| 68 | [pluginMenu selectItemAtIndex:i]; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | [self selectPlugin:pluginMenu]; |
| 73 | } |
| 74 | |
| 75 | - (void)dealloc |
| 76 | { |
| 77 | if (plugins) [plugins release]; |
| 78 | if (defaultKey) [defaultKey release]; |
| 79 | } |
| 80 | |
| 81 | @end |