Prevent dragging groups into groups. Fixes #8706
[adiumx.git] / Source / AICoreComponentLoader.m
blob45c16377db3b63c7bf5618a4b13029848bd5da93
1 /*
2  * Adium is the legal property of its developers, whose names are listed in the copyright file included
3  * with this source distribution.
4  *
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.
8  *
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.
12  *
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.
15  */
17 /*!
18  * @class AICoreComponentLoader
19  * @brief Core - Component Loader
20  *
21  * Loads integrated plugins.  Component classes to load are determined by CoreComponents.plist
22  */
24 #import "AICoreComponentLoader.h"
25 #import <Adium/AIObject.h>
26 #import "AIPlugin.h"
28 //#define COMPONENT_LOAD_TIMING
29 #ifdef COMPONENT_LOAD_TIMING
30 NSTimeInterval aggregateComponentLoadingTime = 0.0;
31 #endif
33 @interface AICoreComponentLoader (PRIVATE)
34 - (void)loadComponents;
35 @end
37 @implementation AICoreComponentLoader
39 /*!
40  * @brief Init
41  */
42 - (id)init
44         if ((self = [super init])) {
45                 components = [[NSMutableDictionary alloc] init];
46                 
47                 [self loadComponents];
48         }
50         return self;
53 /*!
54  * @brief Deallocate
55  */
56 - (void)dealloc
58         [components release];
59         [super dealloc];
62 #pragma mark -
64 /*!
65  * @brief Load integrated components
66  */
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);
74         //Load each component
75         NSEnumerator *enumerator = [componentArray objectEnumerator];
76         NSString         *className;
78         while ((className = [enumerator nextObject])) {
79 #ifdef COMPONENT_LOAD_TIMING
80                 NSDate *start = [NSDate date];
81 #endif
82                 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
83                 Class class;
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];
93                         [object release];
94                 }
95                 [pool release];
96 #ifdef COMPONENT_LOAD_TIMING
97                 NSTimeInterval t = -[start timeIntervalSinceNow];
98                 aggregateComponentLoadingTime += t;
99                 AILog(@"Loaded component: %@ in %f seconds", className, t);
100 #endif
101         }
102 #ifdef COMPONENT_LOAD_TIMING
103         AILog(@"Total time spent loading components: %f", aggregateComponentLoadingTime);
104 #endif
107 - (void)controllerDidLoad
112  * @brief Close integreated components
113  */
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];
123         }
126 #pragma mark -
129  * @brief Retrieve a component plugin by its class name
130  */
131 - (id <AIPlugin>)pluginWithClassName:(NSString *)className {
132         return [components objectForKey:className];
135 @end