+- (NSString *)bundleIdentifierForApplicationName:(NSString *)appName
+{
+ NSWorkspace * workspace = [NSWorkspace sharedWorkspace];
+ NSString * appPath = [workspace fullPathForApplication:appName];
+ if (appPath) {
+ NSBundle * appBundle = [NSBundle bundleWithPath:appPath];
+ return [appBundle bundleIdentifier];
+ }
+ return nil;
+}
+
+- (NSString *)applicationNameForBundleIdentifier:(NSString *)bundleIdentifier
+{
+ return [[[NSFileManager defaultManager] displayNameAtPath:[[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:bundleIdentifier]] stringByDeletingPathExtension];
+}
+
+- (NSImage *)iconForBundleIdentifier:(NSString *)bundleIdentifier
+{
+ NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
+ NSSize iconSize = NSMakeSize(16., 16.);
+ NSImage *icon = [workspace iconForFile:[workspace absolutePathForAppBundleWithIdentifier:bundleIdentifier]];
+ [icon setSize:iconSize];
+ return icon;
+}
+
+- (IBAction)urlHandlerAction:(id)sender
+{
+ NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
+
+ if (sender == o_input_urlhandler_btn) {
+ NSArray *handlers;
+ NSString *handler;
+ NSString *rawhandler;
+ NSMutableArray *rawHandlers;
+ NSUInteger count;
+
+#define fillUrlHandlerPopup( protocol, object ) \
+ handlers = (NSArray *)LSCopyAllHandlersForURLScheme(CFSTR( protocol )); \
+ rawHandlers = [[NSMutableArray alloc] init]; \
+ [object removeAllItems]; \
+ count = [handlers count]; \
+ for (NSUInteger x = 0; x < count; x++) { \
+ rawhandler = [handlers objectAtIndex:x]; \
+ handler = [self applicationNameForBundleIdentifier:rawhandler]; \
+ if (handler && ![handler isEqualToString:@""]) { \
+ [object addItemWithTitle:handler]; \
+ [[object lastItem] setImage: [self iconForBundleIdentifier:[handlers objectAtIndex:x]]]; \
+ [rawHandlers addObject: rawhandler]; \
+ } \
+ } \
+ [object selectItemAtIndex: [rawHandlers indexOfObject:(id)LSCopyDefaultHandlerForURLScheme(CFSTR( protocol ))]]; \
+ [rawHandlers release]
+
+ fillUrlHandlerPopup( "ftp", o_urlhandler_ftp_pop);
+ fillUrlHandlerPopup( "mms", o_urlhandler_mms_pop);
+ fillUrlHandlerPopup( "rtmp", o_urlhandler_rtmp_pop);
+ fillUrlHandlerPopup( "rtp", o_urlhandler_rtp_pop);
+ fillUrlHandlerPopup( "rtsp", o_urlhandler_rtsp_pop);
+ fillUrlHandlerPopup( "sftp", o_urlhandler_sftp_pop);
+ fillUrlHandlerPopup( "smb", o_urlhandler_smb_pop);
+ fillUrlHandlerPopup( "udp", o_urlhandler_udp_pop);
+
+#undef fillUrlHandlerPopup
+
+ [NSApp beginSheet:o_urlhandler_win modalForWindow:o_sprefs_win modalDelegate:self didEndSelector:NULL contextInfo:nil];
+ } else {
+ [o_urlhandler_win orderOut:sender];
+ [NSApp endSheet: o_urlhandler_win];
+
+ if (sender == o_urlhandler_save_btn) {
+ LSSetDefaultHandlerForURLScheme(CFSTR("ftp"), (CFStringRef)[self bundleIdentifierForApplicationName:[[o_urlhandler_ftp_pop selectedItem] title]]);
+ LSSetDefaultHandlerForURLScheme(CFSTR("mms"), (CFStringRef)[self bundleIdentifierForApplicationName:[[o_urlhandler_mms_pop selectedItem] title]]);
+ LSSetDefaultHandlerForURLScheme(CFSTR("mmsh"), (CFStringRef)[self bundleIdentifierForApplicationName:[[o_urlhandler_mms_pop selectedItem] title]]);
+ LSSetDefaultHandlerForURLScheme(CFSTR("rtmp"), (CFStringRef)[self bundleIdentifierForApplicationName:[[o_urlhandler_rtmp_pop selectedItem] title]]);
+ LSSetDefaultHandlerForURLScheme(CFSTR("rtp"), (CFStringRef)[self bundleIdentifierForApplicationName:[[o_urlhandler_rtp_pop selectedItem] title]]);
+ LSSetDefaultHandlerForURLScheme(CFSTR("rtsp"), (CFStringRef)[self bundleIdentifierForApplicationName:[[o_urlhandler_rtsp_pop selectedItem] title]]);
+ LSSetDefaultHandlerForURLScheme(CFSTR("sftp"), (CFStringRef)[self bundleIdentifierForApplicationName:[[o_urlhandler_sftp_pop selectedItem] title]]);
+ LSSetDefaultHandlerForURLScheme(CFSTR("smb"), (CFStringRef)[self bundleIdentifierForApplicationName:[[o_urlhandler_smb_pop selectedItem] title]]);
+ LSSetDefaultHandlerForURLScheme(CFSTR("udp"), (CFStringRef)[self bundleIdentifierForApplicationName:[[o_urlhandler_udp_pop selectedItem] title]]);
+ }
+ }
+}
+
+#pragma mark -
+#pragma mark Hotkey actions
+
+- (void)hotkeyTableDoubleClick:(id)object
+{
+ // -1 is header
+ if ([o_hotkeys_listbox clickedRow] >= 0)
+ [self hotkeySettingChanged:o_hotkeys_listbox];
+}
+