2 * Adium is the legal property of its developers, whose names are listed in the copyright file included
3 * with this source distribution.
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11 * Public License for more details.
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 * @class AICoreComponentLoader
19 * @brief Core - Component Loader
21 * Loads integrated plugins. Component classes to load are determined by CoreComponents.plist
24 #import "AICoreComponentLoader.h"
25 #import <Adium/AIObject.h>
28 //#define COMPONENT_LOAD_TIMING
29 #ifdef COMPONENT_LOAD_TIMING
30 NSTimeInterval aggregateComponentLoadingTime = 0.0;
33 @interface AICoreComponentLoader (PRIVATE)
34 - (void)loadComponents;
37 @implementation AICoreComponentLoader
44 if ((self = [super init])) {
45 components = [[NSMutableDictionary alloc] init];
47 [self loadComponents];
65 * @brief Load integrated components
67 - (void)loadComponents
69 //Fetch the list of components to load
70 NSString *propertyList = [[NSBundle mainBundle] pathForResource:@"CoreComponents" ofType:@"plist"];
71 NSArray *componentArray = [NSArray arrayWithContentsOfFile:propertyList];
72 NSParameterAssert(componentArray != nil);
75 NSEnumerator *enumerator = [componentArray objectEnumerator];
78 while ((className = [enumerator nextObject])) {
79 #ifdef COMPONENT_LOAD_TIMING
80 NSDate *start = [NSDate date];
82 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
85 if (className && (class = NSClassFromString(className))) {
86 id <AIPlugin> object = [[class alloc] init];
88 NSAssert1(object, @"Failed to load %@", className);
90 [object installPlugin];
92 [components setObject:object forKey:className];
96 #ifdef COMPONENT_LOAD_TIMING
97 NSTimeInterval t = -[start timeIntervalSinceNow];
98 aggregateComponentLoadingTime += t;
99 AILog(@"Loaded component: %@ in %f seconds", className, t);
102 #ifdef COMPONENT_LOAD_TIMING
103 AILog(@"Total time spent loading components: %f", aggregateComponentLoadingTime);
107 - (void)controllerDidLoad
112 * @brief Close integreated components
114 - (void)controllerWillClose
116 NSEnumerator *enumerator = [components objectEnumerator];
117 id <AIPlugin> plugin;
119 while ((plugin = [enumerator nextObject])) {
120 [[[AIObject sharedAdiumInstance] notificationCenter] removeObserver:plugin];
121 [[NSNotificationCenter defaultCenter] removeObserver:plugin];
122 [plugin uninstallPlugin];
129 * @brief Retrieve a component plugin by its class name
131 - (id <AIPlugin>)pluginWithClassName:(NSString *)className {
132 return [components objectForKey:className];