| 1 |
/* |
| 2 |
* Copyright (c) 2004-2005 The Lupin Project. All rights reserved. |
| 3 |
* |
| 4 |
* Redistribution and use in source and binary forms, with or without modification, are permitted |
| 5 |
* provided that the following conditions are met: |
| 6 |
* |
| 7 |
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions |
| 8 |
* and the following disclaimer. |
| 9 |
* |
| 10 |
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of |
| 11 |
* conditions and the following disclaimer in the documentation and/or other materials provided |
| 12 |
* with the distribution. |
| 13 |
* |
| 14 |
* THIS SOFTWARE IS PROVIDED BY THE LUPIN PROJECT ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, |
| 15 |
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LUPIN PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
| 17 |
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 18 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 19 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 20 |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 21 |
* POSSIBILITY OF SUCH DAMAGE. |
| 22 |
*/ |
| 23 |
|
| 24 |
#import "LPPluginsController.h" |
| 25 |
|
| 26 |
@implementation LPPluginsController |
| 27 |
|
| 28 |
- (LPPluginsController*)initWithWindowNibName:(NSString *)windowNibName { |
| 29 |
[self loadPlugins]; |
| 30 |
return [super initWithWindowNibName:windowNibName]; |
| 31 |
} |
| 32 |
|
| 33 |
- (void)dealloc { |
| 34 |
[_plugins release]; |
| 35 |
[_compresses release]; |
| 36 |
[super dealloc]; |
| 37 |
} |
| 38 |
|
| 39 |
- (void)loadPlugins { |
| 40 |
_plugins = [[NSMutableArray array] retain]; |
| 41 |
_compresses = [[NSMutableArray array] retain]; |
| 42 |
NSString *folderPath = [NSString stringWithString:@"/Library/Application Support/Lupin/Plugins"]; |
| 43 |
[self loadPlugins:folderPath]; |
| 44 |
folderPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/Lupin/Plugins"]; |
| 45 |
[self loadPlugins:folderPath]; |
| 46 |
folderPath = [[NSBundle mainBundle] builtInPlugInsPath]; |
| 47 |
[self loadPlugins:folderPath]; |
| 48 |
folderPath = [[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Plugins"]; |
| 49 |
[self loadPlugins:folderPath]; |
| 50 |
} |
| 51 |
|
| 52 |
//load plugin at folderPath. |
| 53 |
- (void)loadPlugins:(NSString*)folderPath { |
| 54 |
NSString *pluginPath; |
| 55 |
NSEnumerator* enumerator = [[NSBundle pathsForResourcesOfType:@"lpplugin" inDirectory:folderPath] objectEnumerator]; |
| 56 |
NSMutableArray* pluginNameArray = [NSMutableArray array]; |
| 57 |
|
| 58 |
while ((pluginPath = [enumerator nextObject])) { |
| 59 |
NSBundle *pluginBundle = [NSBundle bundleWithPath:pluginPath]; |
| 60 |
if (pluginBundle) { |
| 61 |
Class pluginClass = [pluginBundle principalClass]; |
| 62 |
if ([pluginClass conformsToProtocol:@protocol(LupinPluginProtocol)]) { |
| 63 |
NSObject<LupinPluginProtocol>* plugin = [[[pluginClass alloc] init] autorelease]; |
| 64 |
if ([pluginNameArray containsObject:[plugin className]]) { |
| 65 |
NSRunAlertPanel(NSLocalizedString(@"DialogAlreadyLoadSameNamePluginTitle",nil), |
| 66 |
[NSString stringWithFormat:NSLocalizedString(@"DialogAlreadyLoadSameNamePluginInfo",nil),[plugin className],pluginPath], |
| 67 |
NSLocalizedString(@"DialogAgree",nil), |
| 68 |
NULL, |
| 69 |
NULL); |
| 70 |
} else { |
| 71 |
[pluginNameArray addObject:[plugin className]]; |
| 72 |
[_plugins addObject:plugin]; |
| 73 |
[_compresses addObjectsFromArray:[plugin compressInfo:[_plugins count]-1]]; |
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
- (int)numberOfRowsInTableView:(NSTableView *)aTableView { |
| 81 |
return [_plugins count]; |
| 82 |
} |
| 83 |
|
| 84 |
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex { |
| 85 |
id identifier = [aTableColumn identifier]; |
| 86 |
if ([identifier isEqualToString:@"name"]) { |
| 87 |
return [[_plugins objectAtIndex:rowIndex] pluginName]; |
| 88 |
} else if ([identifier isEqualToString:@"author"]) { |
| 89 |
return [[_plugins objectAtIndex:rowIndex] pluginAuthorName]; |
| 90 |
} else if ([identifier isEqualToString:@"version"]) { |
| 91 |
return [[_plugins objectAtIndex:rowIndex] pluginVersion]; |
| 92 |
} else |
| 93 |
return nil; |
| 94 |
} |
| 95 |
|
| 96 |
- (void)tableViewSelectionDidChange:(NSNotification *)notification { |
| 97 |
int rowIndex = [pluginsTable selectedRow]; |
| 98 |
[[infoCopyright textStorage] setAttributedString:[[NSMutableAttributedString alloc] initWithString:@""]]; |
| 99 |
[[infoCopyright window] resetCursorRects]; |
| 100 |
if (rowIndex >= 0) { |
| 101 |
[[infoForm cellAtIndex:0] setStringValue:[[_plugins objectAtIndex:rowIndex] pluginName]]; |
| 102 |
[[infoForm cellAtIndex:1] setStringValue:[[_plugins objectAtIndex:rowIndex] pluginAuthorName]]; |
| 103 |
[[infoForm cellAtIndex:2] setStringValue:[[_plugins objectAtIndex:rowIndex] pluginVersion]]; |
| 104 |
[[infoForm cellAtIndex:3] setStringValue:[[_plugins objectAtIndex:rowIndex] pluginEmail]]; |
| 105 |
[[infoForm cellAtIndex:4] setStringValue:[[_plugins objectAtIndex:rowIndex] pluginURI]]; |
| 106 |
[[infoCopyright textStorage] appendAttributedString:[[_plugins objectAtIndex:rowIndex] pluginCopyright]]; |
| 107 |
[[infoCopyright window] resetCursorRects]; |
| 108 |
} else { |
| 109 |
//Empty information. |
| 110 |
int i; |
| 111 |
for (i=0;i<5;i++) |
| 112 |
[[infoForm cellAtIndex:i] setStringValue:@""]; |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
- (NSMutableArray*)acceptablePlugins:(NSString*)filePath |
| 117 |
{ |
| 118 |
if (!_plugins) |
| 119 |
return nil; |
| 120 |
if ([_plugins count] <= 0) |
| 121 |
return nil; |
| 122 |
|
| 123 |
NSMutableArray* singleExtensionPlugins = [NSMutableArray array]; |
| 124 |
NSMutableArray* multipleExtensionPlugins = [NSMutableArray array]; |
| 125 |
NSEnumerator* enumerator = [_plugins objectEnumerator]; |
| 126 |
NSObject<LupinPluginProtocol>* plugin; |
| 127 |
while (plugin = [enumerator nextObject]) { |
| 128 |
NSArray* extensions = [plugin acceptableExtensions]; |
| 129 |
NSEnumerator* extensionsEnumerator = [extensions objectEnumerator]; |
| 130 |
NSString* extension; |
| 131 |
while (extension = [extensionsEnumerator nextObject]) { |
| 132 |
if ([filePath hasSuffix:extension]) { |
| 133 |
[(([[extension componentsSeparatedByString:@"."] count] < 3) ? singleExtensionPlugins : multipleExtensionPlugins) addObject:[[[[plugin class] alloc] initWithFile:filePath] autorelease]]; |
| 134 |
} |
| 135 |
} |
| 136 |
} |
| 137 |
[singleExtensionPlugins addObjectsFromArray:multipleExtensionPlugins]; |
| 138 |
return singleExtensionPlugins; |
| 139 |
} |
| 140 |
|
| 141 |
- (NSObject<LupinPluginProtocol>*)initPlugin:(NSString*)filePath index:(int)index |
| 142 |
{ |
| 143 |
return [[[[_plugins objectAtIndex:index] class] alloc] initWithFile:filePath]; |
| 144 |
} |
| 145 |
|
| 146 |
// ������������������������������������������ |
| 147 |
- (NSArray*)compressess |
| 148 |
{ |
| 149 |
return [NSArray arrayWithArray:_compresses]; |
| 150 |
} |
| 151 |
|
| 152 |
@end |