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.
17 #import <Adium/AIAccountControllerProtocol.h>
18 #import "AdiumServices.h"
19 #import <Adium/AIService.h>
20 #import <Adium/AIAccount.h>
22 @implementation AdiumServices
29 if ((self = [super init])) {
30 services = [[NSMutableDictionary alloc] init];
38 [services release]; services = nil;
43 * @brief Register an AIService instance
45 * All services should be registered before they are used
47 - (void)registerService:(AIService *)inService
49 [services setObject:inService forKey:[inService serviceCodeUniqueID]];
53 * @brief Returns an array of all available services
55 * @return NSArray of AIService instances
59 return [services allValues];
63 * @brief Returns an array of all active services
65 * "Active" services are those for which the user has an enabled account.
66 * @param includeCompatible Include services which are compatible with an enabled account but not specifically active.
67 * For example, if an AIM account is enabled, the ICQ service will be included if this is YES.
68 * @return NSArray of AIService instances
70 - (NSSet *)activeServicesIncludingCompatibleServices:(BOOL)includeCompatible
72 NSMutableSet *activeServices = [NSMutableSet set];
73 NSEnumerator *accountEnumerator = [[[adium accountController] accounts] objectEnumerator];
76 if (includeCompatible) {
77 //Scan our user's accounts and build a list of service classes that they cover
78 NSMutableSet *serviceClasses = [NSMutableSet set];
80 while ((account = [accountEnumerator nextObject])) {
81 if ([account enabled]) {
82 [serviceClasses addObject:[[account service] serviceClass]];
86 //Gather and return all services compatible with these service classes
87 NSEnumerator *serviceEnumerator = [services objectEnumerator];
90 while ((service = [serviceEnumerator nextObject])) {
91 if ([serviceClasses containsObject:[service serviceClass]]) {
92 [activeServices addObject:service];
97 while ((account = [accountEnumerator nextObject])) {
98 if ([account enabled]) {
99 [activeServices addObject:[account service]];
104 return activeServices;
108 * @brief Retrieves a service by its unique ID
110 * Unique IDs are returned by -[AIService serviceCodeUniqueID]. An example is @"libpurple-oscar-AIM".
111 * @param uniqueID The serviceCodeUniqueID of the desired service
112 * @return AIService if found, nil if not found
114 - (AIService *)serviceWithUniqueID:(NSString *)uniqueID
116 return [services objectForKey:uniqueID];
120 * @brief Retrieves a service by service ID.
122 * Service IDs may be shared by multiple services if the same service is provided by two different plugins.
123 * -[AIService serviceID] returns serviceIDs. An example is @"AIM".
124 * @return The first service with the matching service ID, or nil if none is found.
126 - (AIService *)firstServiceWithServiceID:(NSString *)serviceID
128 NSEnumerator *enumerator = [services objectEnumerator];
131 while ((service = [enumerator nextObject])) {
132 if ([[service serviceID] isEqualToString:serviceID]) break;