Fix oops.
adium-1.5.10.4
tip
2017-04-25, Robert Vehse
* Adium is the legal property of its developers, whose names are listed in the copyright file included * with this source distribution. * This program is free software; you can redistribute it and/or modify it under the terms of the GNU * General Public License as published by the Free Software Foundation; either version 2 of the License, * or (at your option) any later version. * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * Public License for more details. * You should have received a copy of the GNU General Public License along with this program; if not, * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #import "AIURLHandlerAdvancedPreferences.h" #import "AIPreferenceWindowController.h" #import <AIUtilities/AIImageTextCell.h> #import <AIUtilities/AIImageAdditions.h> #import <AIUtilities/AIArrayAdditions.h> #import <AIUtilities/AIMenuAdditions.h> #import <AIUtilities/AIImageDrawingAdditions.h> #import <Adium/AIAccountControllerProtocol.h> #import <Adium/AIService.h> #import <Adium/AIServiceIcons.h> @interface AIURLHandlerAdvancedPreferences() - (void)configureTableView; - (void)initializeServiceInformationForSchemes:(NSArray *)schemes; - (NSMenu *)applicationMenuForScheme:(NSString *)scheme; - (NSArray *)applicationDictionaryArrayForScheme:(NSString *)scheme; - (NSImage *)serviceImageForScheme:(NSString *)scheme; - (NSString *)serviceNameForScheme:(NSString *)scheme; @implementation AIURLHandlerAdvancedPreferences #pragma mark Preference pane settings - (AIPreferenceCategory)category return AILocalizedString(@"Default Client",nil); return @"AIURLHandlerPreferences"; return [NSImage imageNamed:@"pref-defaultclient" forClass:[AIPreferenceWindowController class]]; servicesList = [((AIURLHandlerPlugin *)plugin).uniqueSchemes retain]; [self configureTableView]; [self initializeServiceInformationForSchemes:servicesList]; [button_setDefault setLocalizedString:AILocalizedString(@"Set Default for All", nil)]; [checkBox_enforceDefault setLocalizedString:AILocalizedString(@"Always set Adium as the default", nil)]; [checkBox_enforceDefault setState:[[adium.preferenceController preferenceForKey:PREF_KEY_ENFORCE_DEFAULT group:GROUP_URL_HANDLING] boolValue]]; [tableView setEnabled:![[adium.preferenceController preferenceForKey:PREF_KEY_ENFORCE_DEFAULT group:GROUP_URL_HANDLING] boolValue]]; - (IBAction)setDefault:(id)sender [plugin setAdiumAsDefault]; - (IBAction)enforceDefault:(id)sender [adium.preferenceController setPreference:[NSNumber numberWithBool:[sender state]] forKey:PREF_KEY_ENFORCE_DEFAULT group:GROUP_URL_HANDLING]; [tableView setEnabled:![sender state]]; [plugin setAdiumAsDefault]; #pragma mark Scheme information - (void)initializeServiceInformationForSchemes:(NSArray *)schemes [services release]; services = [[NSMutableDictionary alloc] init]; for (NSString *scheme in schemes) { [services setObject:[NSMutableDictionary dictionary] forKey:scheme]; - (NSMenu *)applicationMenuForScheme:(NSString *)scheme NSMutableDictionary *servicesInformation = [services objectForKey:scheme]; NSMenu *menu = [servicesInformation objectForKey:@"applicationsMenu"]; menu = [[[NSMenu alloc] init] autorelease]; for (NSDictionary *application in [self applicationDictionaryArrayForScheme:scheme]) { NSMenuItem *menuItem = [menu addItemWithTitle:[application objectForKey:@"ApplicationName"] [menuItem setImage:[[application objectForKey:@"ApplicationImage"] imageByScalingForMenuItem]]; [menuItem setRepresentedObject:[application objectForKey:@"BundleID"]]; [servicesInformation setObject:menu forKey:@"applicationsMenu"]; - (NSArray *)applicationDictionaryArrayForScheme:(NSString *)scheme NSMutableDictionary *servicesInformation = [services objectForKey:scheme]; NSArray *applications = [servicesInformation objectForKey:@"applications"]; NSArray *applicationArray = [(NSArray *)LSCopyAllHandlersForURLScheme((CFStringRef)scheme) autorelease]; NSMutableArray *mutableApplications = [NSMutableArray array]; for (NSString *bundleID in applicationArray) { // File System Ref for this bundle ID OSStatus err = LSFindApplicationForInfo(kLSUnknownCreator, (CFStringRef)bundleID, NULL, &fileSystemRef, NULL); if (err == kLSApplicationNotFoundErr) { OSErr informationError = FSGetCatalogInfo(&fileSystemRef, kFSCatInfoNone, NULL, &name, NULL, NULL); NSString *applicationName = [NSString stringWithCharacters:name.unicode length:name.length]; err = GetIconRefFromFileInfo(&fileSystemRef, 0, NULL, kFSCatInfoNone, NULL, kIconServicesNoBadgeFlag, &iconRef, NULL); NSImage *image = [[[NSImage alloc] initWithIconRef:iconRef] autorelease]; [mutableApplications addObject:[NSDictionary dictionaryWithObjectsAndKeys:bundleID.lowercaseString, @"BundleID", applicationName, @"ApplicationName", image, @"ApplicationImage", nil]]; [servicesInformation setObject:mutableApplications forKey:@"applications"]; applications = mutableApplications; - (NSImage *)serviceImageForScheme:(NSString *)scheme NSMutableDictionary *servicesInformation = [services objectForKey:scheme]; NSImage *image = [servicesInformation objectForKey:@"image"]; AIService *service = [adium.accountController firstServiceWithServiceID:[plugin serviceIDForScheme:scheme]]; image = [AIServiceIcons serviceIconForService:service type:AIServiceIconLarge direction:AIIconNormal]; if (image) [servicesInformation setObject:image forKey:@"image"]; - (NSString *)serviceNameForScheme:(NSString *)scheme NSMutableDictionary *servicesInformation = [services objectForKey:scheme]; NSString *longServiceName = [servicesInformation objectForKey:@"name"]; AIService *service = [adium.accountController firstServiceWithServiceID:[plugin serviceIDForScheme:scheme]]; longServiceName = [service longDescription]; [servicesInformation setObject:(longServiceName ?: @"(unknown)") forKey:@"name"]; #pragma mark Table view Delegate - (void)configureTableView AIImageTextCell *imageTextCell = [[AIImageTextCell alloc] init]; [imageTextCell setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; [[tableView tableColumnWithIdentifier:@"service"] setDataCell:imageTextCell]; - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView return servicesList.count; - (void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row NSString *identifier = tableColumn.identifier; NSString *scheme = [servicesList objectAtIndex:row]; if ([identifier isEqualToString:@"service"]) { // Configure to display the service icon and service name. [cell setImage:[self serviceImageForScheme:scheme]]; } else if ([identifier isEqualToString:@"applications"]) { NSMenu *menu = [self applicationMenuForScheme:scheme]; NSString *defaultApplication = [plugin defaultApplicationBundleIDForScheme:scheme]; // Letting the NSPopupButtonCell handle state causes some buggy results. Do it ourself. for (NSMenuItem *menuItem in menu.itemArray) { [menuItem setState:[menuItem.representedObject isEqualToString:defaultApplication]]; [cell setAltersStateOfSelectedItem:NO]; [cell selectItemAtIndex:[cell indexOfItemWithRepresentedObject:defaultApplication]]; - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row NSString *identifier = tableColumn.identifier; NSString *scheme = [servicesList objectAtIndex:row]; if ([identifier isEqualToString:@"service"]) { return [self serviceNameForScheme:scheme]; - (void)tableView:(NSTableView *)aTableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row NSString *identifier = tableColumn.identifier; NSString *scheme = [servicesList objectAtIndex:row]; if ([identifier isEqualToString:@"applications"]) { [plugin setDefaultForScheme:scheme toBundleID:[[[self applicationMenuForScheme:scheme] itemAtIndex:[object integerValue]] representedObject]];