Merged [15040]: Trying some magic: 5 seconds after the last unreachable host is repor...
[adiumx.git] / Source / AICoreComponentLoader.m
blobf3d800e9c15b80b7dcc85060b652e76d63ce047e
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
21  * Loads integrated plugins.  All integrated plugins require a _loadComponentClass statement below and their class name
22  * in the @class list.  In situations where the load order of plugins is important, please make note.
23  */
25 #import "AICoreComponentLoader.h"
26 #import <Adium/AIPlugin.h>
28 #define VERSION_KEY                     @"Version"
29 #define COMPONENTS_KEY          @"Components"
31 #define COMPONENT_DISABLED      @"Disabled"
32 #define COMPONENT_CLASS         @"Class"
33 #define COMPONENT_HEADER        @"Header"
34 #define COMPONENT_LOCATION      @"Location"
36 @implementation AICoreComponentLoader
38 - (id)init
40         if((self = [super init])){
41                 components = [[NSMutableDictionary alloc] init];
42         }
44         return self;
47 /*!
48  * @brief Deallocate
49  */
50 - (void)dealloc
52         [components release];
54         [super dealloc];
57 #pragma mark -
59 /*!
60  * @brief Load integrated components
61  */
62 - (void)initController
64         NSString *propertyList = [[NSBundle mainBundle] pathForResource:@"CoreComponents" ofType:@"plist"];
65         NSDictionary *componentDict = [NSDictionary dictionaryWithContentsOfFile:propertyList];
66         NSArray *componentArray = [componentDict objectForKey:COMPONENTS_KEY];
68         if(!componentArray){
69                 return;
70         }
72         NSEnumerator *compEnumerator = [componentArray objectEnumerator];
73         NSDictionary *dict;
75         while((dict = [compEnumerator nextObject])){
76                 if([[dict objectForKey:COMPONENT_DISABLED] boolValue]){
77                         continue;
78                 }
80                 NSString *className = [dict objectForKey:COMPONENT_CLASS];
81                 Class class;
83                 if(className && (class = NSClassFromString(className))){
84                         id object = [[class alloc] init];
85 #ifdef TRACK_COMPONENTS
86                         NSLog(@"%@: adding component: %@", [self class], object);
87 #endif
89                         NSAssert1(object, @"Failed to load %@", className);
91                         [components setObject:object forKey:className];
92                         [object release];
93                 }
94         }
97 /*!
98  * @brief Give all components a chance to close
99  */
100 - (void)closeController
102         NSArray                 *keys = [components allKeys];
103         NSEnumerator    *enumerator = [keys objectEnumerator];
104         NSString                *className;
106         while (className = [enumerator nextObject]) {
107                 AIPlugin        *plugin = [components objectForKey:className];
108 #ifdef TRACK_COMPONENTS
109                 NSLog(@"%@: removing component: %@", [self class], plugin);
110 #endif
111                 [plugin uninstallPlugin];
112         }
115 #pragma mark -
117 - (AIPlugin *)pluginWithClassName:(NSString *)className {
118         return [components objectForKey:className];
121 @end